From 04d1fc553183c020bee29db6d3e2af8dc5b7053a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 5 Sep 2011 09:17:14 +0200 Subject: filename.erl:filter_options/1: Remove handling of dead options The 'trace' and 'fast' options are no longer supported. While at it, correct the comment about option filtering. --- lib/stdlib/src/filename.erl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'lib/stdlib') diff --git a/lib/stdlib/src/filename.erl b/lib/stdlib/src/filename.erl index 2fc9128e4e..acd7985c16 100644 --- a/lib/stdlib/src/filename.erl +++ b/lib/stdlib/src/filename.erl @@ -844,8 +844,7 @@ try_file(Src, _ObjFilename, Mod, _Rules) -> %% Filters the options. %% -%% 1) Remove options that have no effect on the generated code, -%% such as report and verbose. +%% 1) Only keep options that have any effect on code generation. %% %% 2) The paths found in {i, Path} and {outdir, Path} are converted %% to absolute paths. When doing this, it is assumed that relatives @@ -857,14 +856,10 @@ filter_options(Base, [{outdir, Path}|Rest], Result) -> filter_options(Base, Rest, [{outdir, make_abs_path(Base, Path)}|Result]); filter_options(Base, [{i, Path}|Rest], Result) -> filter_options(Base, Rest, [{i, make_abs_path(Base, Path)}|Result]); -filter_options(Base, [Option|Rest], Result) when Option =:= trace -> - filter_options(Base, Rest, [Option|Result]); filter_options(Base, [Option|Rest], Result) when Option =:= export_all -> filter_options(Base, Rest, [Option|Result]); filter_options(Base, [Option|Rest], Result) when Option =:= binary -> filter_options(Base, Rest, [Option|Result]); -filter_options(Base, [Option|Rest], Result) when Option =:= fast -> - filter_options(Base, Rest, [Option|Result]); filter_options(Base, [Tuple|Rest], Result) when element(1, Tuple) =:= d -> filter_options(Base, Rest, [Tuple|Result]); filter_options(Base, [Tuple|Rest], Result) -- cgit v1.2.3 From bc1f3ce3b707f25397a1ff484d34ee406e0db73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 5 Sep 2011 09:21:11 +0200 Subject: filename: Eliminate failing call to Mod:module_info(source_file) Mod:module_info(source_file) is no longer supported (and have not been for a long time), so calling it will always fail. --- lib/stdlib/src/filename.erl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'lib/stdlib') diff --git a/lib/stdlib/src/filename.erl b/lib/stdlib/src/filename.erl index acd7985c16..7144781843 100644 --- a/lib/stdlib/src/filename.erl +++ b/lib/stdlib/src/filename.erl @@ -873,12 +873,7 @@ filter_options(_Base, [], Result) -> %% Gets the source file given path of object code and module name. get_source_file(Obj, Mod, Rules) -> - case catch Mod:module_info(source_file) of - {'EXIT', _Reason} -> - source_by_rules(dirname(Obj), packages:last(Mod), Rules); - File -> - {ok, File} - end. + source_by_rules(dirname(Obj), packages:last(Mod), Rules). source_by_rules(Dir, Base, [{From, To}|Rest]) -> case try_rule(Dir, Base, From, To) of -- cgit v1.2.3 From f939cf61d13fe2d753f4c6ec7a47880db083a45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 11 Nov 2011 16:36:45 +0100 Subject: 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 --- lib/stdlib/src/filename.erl | 7 +++++-- lib/stdlib/test/filename_SUITE.erl | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'lib/stdlib') 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. %% -- cgit v1.2.3 From 9ac7e19e35b02c02e15abd3abc4e7b5c8b62752d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 11 Nov 2011 16:57:10 +0100 Subject: filename documentation: Recommend against using filename:find_src/1,2 --- lib/stdlib/doc/src/filename.xml | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/stdlib') diff --git a/lib/stdlib/doc/src/filename.xml b/lib/stdlib/doc/src/filename.xml index bc3a616d39..9296319b83 100644 --- a/lib/stdlib/doc/src/filename.xml +++ b/lib/stdlib/doc/src/filename.xml @@ -295,6 +295,12 @@

Finds the source filename and compiler options for a module. The result can be fed to compile:file/2 in order to compile the file again.

+ +

We don't recommend using this function. If possible, + use beam_lib(3) to extract + the abstract code format from the BEAM file and compile that + instead.

+

The Beam argument, which can be a string or an atom, specifies either the module name or the path to the source code, with or without the ".erl" extension. In either -- cgit v1.2.3