aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler/src/compile.erl18
-rw-r--r--lib/compiler/test/compile_SUITE.erl12
-rw-r--r--lib/stdlib/test/escript_SUITE.erl69
-rw-r--r--lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl29
4 files changed, 91 insertions, 37 deletions
diff --git a/lib/compiler/src/compile.erl b/lib/compiler/src/compile.erl
index 7911f51a73..7365706b94 100644
--- a/lib/compiler/src/compile.erl
+++ b/lib/compiler/src/compile.erl
@@ -146,10 +146,17 @@ env_default_opts() ->
do_compile(Input, Opts0) ->
Opts = expand_opts(Opts0),
- Self = self(),
- Serv = spawn_link(fun() -> internal(Self, Input, Opts) end),
+ {Pid,Ref} =
+ spawn_monitor(fun() ->
+ exit(try
+ internal(Input, Opts)
+ catch
+ error:Reason ->
+ {error,Reason}
+ end)
+ end),
receive
- {Serv,Rep} -> Rep
+ {'DOWN',Ref,process,Pid,Rep} -> Rep
end.
expand_opts(Opts0) ->
@@ -242,11 +249,6 @@ format_error({module_name,Mod,Filename}) ->
errors=[],
warnings=[]}).
-internal(Master, Input, Opts) ->
- Master ! {self(), try internal(Input, Opts)
- catch error:Reason -> {error, Reason}
- end}.
-
internal({forms,Forms}, Opts0) ->
{_,Ps} = passes(forms, Opts0),
Source = proplists:get_value(source, Opts0, ""),
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index 9dbfb5883b..da53a6ba9c 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -76,6 +76,9 @@ app_test(Config) when is_list(Config) ->
file_1(Config) when is_list(Config) ->
?line Dog = test_server:timetrap(test_server:minutes(5)),
+
+ process_flag(trap_exit, true),
+
?line {Simple, Target} = files(Config, "file_1"),
?line {ok, Cwd} = file:get_cwd(),
?line ok = file:set_cwd(filename:dirname(Target)),
@@ -102,6 +105,15 @@ file_1(Config) when is_list(Config) ->
%% Cleanup.
?line ok = file:delete(Target),
?line ok = file:del_dir(filename:dirname(Target)),
+
+ %% There should not be any messages in the messages.
+ receive
+ Any ->
+ ?t:fail({unexpected,Any})
+ after 10 ->
+ ok
+ end,
+
?line test_server:timetrap_cancel(Dog),
ok.
diff --git a/lib/stdlib/test/escript_SUITE.erl b/lib/stdlib/test/escript_SUITE.erl
index 7b03fdafe3..38c085616d 100644
--- a/lib/stdlib/test/escript_SUITE.erl
+++ b/lib/stdlib/test/escript_SUITE.erl
@@ -469,22 +469,23 @@ archive_script(Config) when is_list(Config) ->
%% Test the correction of OTP-10071
%% The errors identified are
%%
-%% * If primary archive was named "xxx", then a file in the same
-%% directory named "xxxyyy" would be interpreted as a file named yyy
-%% inside the archive.
+%% a) If primary archive was named "xxx", then a file in the same
+%% directory named "xxxyyy" would be interpreted as a file named yyy
+%% inside the archive.
%%
-%% * erl_prim_loader did not correctly create and normalize absolute
-%% paths for primary archive and files inside it, so unless given
-%% with exact same path files inside the archive would not be
-%% found. E.g. if escript was started as ./xxx then "xxx/file" would
-%% not be found since erl_prim_loader would try to match
-%% /full/path/to/xxx with /full/path/to/./xxx. Same problem with
-%% ../
+%% b) erl_prim_loader did not correctly create and normalize absolute
+%% paths for primary archive and files inside it, so unless given
+%% with exact same path files inside the archive would not be
+%% found. E.g. if escript was started as ./xxx then "xxx/file"
+%% would not be found since erl_prim_loader would try to match
+%% /full/path/to/xxx with /full/path/to/./xxx. Same problem with
+%% ../. Also, the use of symlinks in the path to the archive would
+%% cause problems.
%%
-%% * Depending on how the primary archive was built,
-%% erl_prim_loader:list_dir/1 would sometimes return an empty string
-%% inside the file list. This was a virtual element representing the
-%% top directory of the archive. This shall not occur.
+%% c) Depending on how the primary archive was built,
+%% erl_prim_loader:list_dir/1 would sometimes return an empty string
+%% inside the file list. This was a virtual element representing the
+%% top directory of the archive. This shall not occur.
%%
archive_script_file_access(Config) when is_list(Config) ->
%% Copy the orig files to priv_dir
@@ -542,18 +543,22 @@ archive_script_file_access(Config) when is_list(Config) ->
ok = escript:create(Script1,[shebang,{emu_args,Flags},{archive,Bin1}]),
ok = file:change_mode(Script1,8#00744),
+ %% If supported, create a symlink to the script. This is used to
+ %% test error b) described above this test case.
+ SymlinkName1 = "symlink_to_"++ScriptName1,
+ Symlink1 = filename:join([PrivDir, SymlinkName1]),
+ file:make_symlink(ScriptName1,Symlink1), % will fail if not supported
+
%% Also add a dummy file in the same directory with the same name
%% as the script except is also has an extension. This used to
- %% cause erl_prim_loader to believe it was a file inside the
- %% script.
+ %% test error a) described above this test case.
ok = file:write_file(Script1 ++ ".extension",
<<"same name as script, but with extension">>),
%% Change to script's directory and run it as "./<script_name>"
ok = file:set_cwd(PrivDir),
- do_run(PrivDir, "./" ++ ScriptName1,
- [<<"file_access:[]\n",
- "ExitCode:0">>]),
+ run(PrivDir, "./" ++ ScriptName1 ++ " " ++ ScriptName1,
+ [<<"ExitCode:0">>]),
ok = file:set_cwd(TopDir),
@@ -574,18 +579,34 @@ archive_script_file_access(Config) when is_list(Config) ->
%% Also add a dummy file in the same directory with the same name
%% as the script except is also has an extension. This used to
- %% cause erl_prim_loader to believe it was a file inside the
- %% script.
+ %% test error a) described above this test case.
ok = file:write_file(Script2 ++ ".extension",
<<"same name as script, but with extension">>),
+ %% If supported, create a symlink to the script. This is used to
+ %% test error b) described above this test case.
+ SymlinkName2 = "symlink_to_"++ScriptName2,
+ Symlink2 = filename:join([PrivDir, SymlinkName2]),
+ file:make_symlink(ScriptName2,Symlink2), % will fail if not supported
+
%% Change to script's directory and run it as "./<script_name>"
ok = file:set_cwd(PrivDir),
- do_run(PrivDir, "./" ++ ScriptName2,
- [<<"file_access:[]\n",
- "ExitCode:0">>]),
+ run(PrivDir, "./" ++ ScriptName2 ++ " " ++ ScriptName2,
+ [<<"ExitCode:0">>]),
+
+ %% 3. If symlinks are supported, run one of the scripts via a symlink.
+ %%
+ %% This is in order to test error b) described above this test case.
+ case file:read_link(Symlink2) of
+ {ok,_} ->
+ run(PrivDir, "./" ++ SymlinkName2 ++ " " ++ ScriptName2,
+ [<<"ExitCode:0">>]);
+ _ -> % not supported
+ ok
+ end,
ok = file:set_cwd(OldDir).
+
compile_app(TopDir, AppName) ->
AppDir = filename:join([TopDir, AppName]),
SrcDir = filename:join([AppDir, "src"]),
diff --git a/lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl b/lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl
index 226a8675db..b03c8ba70d 100644
--- a/lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl
+++ b/lib/stdlib/test/escript_SUITE_data/archive_script_file_access/archive_script_file_access.erl
@@ -23,12 +23,9 @@
-include_lib("kernel/include/file.hrl").
-main(MainArgs) ->
- io:format("file_access:~p\n", [MainArgs]),
- ArchiveFile = escript:script_name(),
+main([RelArchiveFile]) ->
- AbsArchiveFile = filename:absname(ArchiveFile),
- RelArchiveFile = filename:basename(ArchiveFile),
+ AbsArchiveFile = filename:absname(RelArchiveFile),
DotSlashArchiveFile = "./" ++ RelArchiveFile,
Beam = atom_to_list(?MODULE) ++ ".beam",
@@ -39,6 +36,10 @@ main(MainArgs) ->
AbsDir = filename:join(AbsArchiveFile,Dir),
RelDir = filename:join(RelArchiveFile,Dir),
DotSlashDir = filename:join(DotSlashArchiveFile,Dir),
+ SubDir = "subdir1",
+ AbsSubDir = filename:join(AbsDir,SubDir),
+ RelSubDir = filename:join(RelDir,SubDir),
+ DotSlashSubDir = filename:join(DotSlashDir,SubDir),
{ok,List1} = erl_prim_loader:list_dir(AbsArchiveFile),
{ok,List1} = erl_prim_loader:list_dir(RelArchiveFile),
@@ -48,8 +49,26 @@ main(MainArgs) ->
{ok,List1} = erl_prim_loader:list_dir(filename:join([AbsDir,".."])),
{ok,List1} = erl_prim_loader:list_dir(filename:join([RelDir,".."])),
{ok,List1} = erl_prim_loader:list_dir(filename:join([DotSlashDir,".."])),
+ {ok,List1} = erl_prim_loader:list_dir(filename:join([AbsSubDir,"..",".."])),
+ {ok,List1} = erl_prim_loader:list_dir(filename:join([RelSubDir,"..",".."])),
+ {ok,List1} = erl_prim_loader:list_dir(filename:join([DotSlashSubDir,"..",".."])),
false = lists:member([],List1),
+ %% If symlinks are supported on this platform...
+ RelSymlinkArchiveFile = "symlink_to_" ++ RelArchiveFile,
+ case file:read_link(RelSymlinkArchiveFile) of
+ {ok,_} ->
+ DotSlashSymlinkArchiveFile = "./" ++ RelSymlinkArchiveFile,
+ AbsSymlinkArchiveFile=filename:join(filename:dirname(AbsArchiveFile),
+ RelSymlinkArchiveFile),
+ {ok,List1} = erl_prim_loader:list_dir(AbsSymlinkArchiveFile),
+ {ok,List1} = erl_prim_loader:list_dir(RelSymlinkArchiveFile),
+ {ok,List1} = erl_prim_loader:list_dir(DotSlashSymlinkArchiveFile);
+ _ -> % not supported
+ ok
+ end,
+
+
{ok,List2} = erl_prim_loader:list_dir(AbsDir),
{ok,List2} = erl_prim_loader:list_dir(RelDir),
{ok,List2} = erl_prim_loader:list_dir(DotSlashDir),