aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2011-11-11 16:36:45 +0100
committerBjörn Gustavsson <[email protected]>2011-11-24 15:46:15 +0100
commitf939cf61d13fe2d753f4c6ec7a47880db083a45f (patch)
treec3ecfa05569fb68156eee0c64af0566129307bdb /lib
parentbc1f3ce3b707f25397a1ff484d34ee406e0db73b (diff)
downloadotp-f939cf61d13fe2d753f4c6ec7a47880db083a45f.tar.gz
otp-f939cf61d13fe2d753f4c6ec7a47880db083a45f.tar.bz2
otp-f939cf61d13fe2d753f4c6ec7a47880db083a45f.zip
Teach filename:find_src/1,2 to handle slim or stripped BEAM files
filename:find_src/1,2 will crash when asked to find the source corresponding to a BEAM with no compilation options. A BEAM file can be missing compilation options if it has been stripped using beam_lib:strip/1 or compiled using the undocumented 'slim' option. Why this matters: If ERL_COMPILE_OPTIONS is set to +slim before building Erlang/OTP, there will be a crash in 'igor' during the building of the public_key application. ('igor' merges several source code files, and uses filename:find_src/1,2 to find the source code.) Change filename:find_src/1,2 to return an empty option list if there are no options in the BEAM file. Noticed-by: Per Hedeland
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/src/filename.erl7
-rw-r--r--lib/stdlib/test/filename_SUITE.erl16
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/stdlib/src/filename.erl b/lib/stdlib/src/filename.erl
index 7144781843..dbfcbea4f7 100644
--- a/lib/stdlib/src/filename.erl
+++ b/lib/stdlib/src/filename.erl
@@ -836,8 +836,11 @@ try_file(undefined, ObjFilename, Mod, Rules) ->
Error -> Error
end;
try_file(Src, _ObjFilename, Mod, _Rules) ->
- List = Mod:module_info(compile),
- {options, Options} = lists:keyfind(options, 1, List),
+ List = case Mod:module_info(compile) of
+ none -> [];
+ List0 -> List0
+ end,
+ Options = proplists:get_value(options, List, []),
{ok, Cwd} = file:get_cwd(),
AbsPath = make_abs_path(Cwd, Src),
{AbsPath, filter_options(dirname(AbsPath), Options, [])}.
diff --git a/lib/stdlib/test/filename_SUITE.erl b/lib/stdlib/test/filename_SUITE.erl
index 70b0d413dc..4cfa589660 100644
--- a/lib/stdlib/test/filename_SUITE.erl
+++ b/lib/stdlib/test/filename_SUITE.erl
@@ -483,6 +483,22 @@ find_src(Config) when is_list(Config) ->
%% Try to find the source for a preloaded module.
?line {error,{preloaded,init}} = filename:find_src(init),
+
+ %% Make sure that find_src works for a slim BEAM file.
+ OldPath = code:get_path(),
+ try
+ PrivDir = ?config(priv_dir, Config),
+ code:add_patha(PrivDir),
+ Src = "simple",
+ SrcPath = filename:join(PrivDir, Src) ++ ".erl",
+ SrcContents = "-module(simple).\n",
+ ok = file:write_file(SrcPath, SrcContents),
+ {ok,simple} = compile:file(SrcPath, [slim,{outdir,PrivDir}]),
+ BeamPath = filename:join(PrivDir, Src),
+ {BeamPath,[]} = filename:find_src(simple)
+ after
+ code:set_path(OldPath)
+ end,
ok.
%%