From 73500d2a456023ca36172f5af896d0b1f10853b7 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 26 Sep 2017 13:25:50 +0200 Subject: Do not load .erlang from current dir It may be confusing that "hidden" .erlang is loaded from the current working directory. Use c:erlangrc([Dir1,..]) to search and load .erlang from other places than "$HOME/.erlang". Implies that c:erlangrc() needs to be documented. --- erts/doc/src/erl.xml | 3 +-- lib/sasl/test/release_handler_SUITE.erl | 40 +++++++++++++++++++++------------ lib/stdlib/doc/src/c.xml | 9 ++++++++ lib/stdlib/src/c.erl | 18 +++++++++------ 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/erts/doc/src/erl.xml b/erts/doc/src/erl.xml index 71fe08d4e6..ae52d92a89 100644 --- a/erts/doc/src/erl.xml +++ b/erts/doc/src/erl.xml @@ -1633,8 +1633,7 @@ The .erlang startup file

When Erlang/OTP is started, the system searches for a file named - .erlang in the directory where Erlang/OTP is started. If not - found, the user's home directory is searched for an .erlang + .erlang in the user's home directory is searched for an .erlang file.

If an .erlang file is found, it is assumed to contain valid Erlang expressions. These expressions are evaluated as if they were diff --git a/lib/sasl/test/release_handler_SUITE.erl b/lib/sasl/test/release_handler_SUITE.erl index 50932e89e4..63b48e7a4e 100644 --- a/lib/sasl/test/release_handler_SUITE.erl +++ b/lib/sasl/test/release_handler_SUITE.erl @@ -1835,24 +1835,32 @@ otp_10463_upgrade_script_regexp(cleanup,Config) -> code:del_path(filename:join([DataDir,regexp_appup,app1,ebin])), ok. -no_dot_erlang(Conf) -> - PrivDir = ?config(data_dir,Conf), - {ok, OrigWd} = file:get_cwd(), - try - ok = file:set_cwd(PrivDir), - - {ok, Wd} = file:get_cwd(), - io:format("Dir ~ts~n", [Wd]), +no_dot_erlang(_Conf) -> + case init:get_argument(home) of + {ok,[[Home]]} when is_list(Home) -> + no_dot_erlang_1(Home); + _ -> ok + end. +no_dot_erlang_1(Home) -> + DotErlang = filename:join(Home, ".erlang"), + BupErlang = filename:join(Home, ".erlang_testbup"), + try + {ok, Wd} = file:get_cwd(), + case filelib:is_file(DotErlang) of + true -> {ok, _} = file:copy(DotErlang, BupErlang); + false -> ok + end, Erl0 = filename:join([code:root_dir(),"bin","erl"]), Erl = filename:nativename(Erl0), Quote = "\"", Args = " -noinput -run c pwd -run erlang halt", - ok = file:write_file(".erlang", <<"io:put_chars(\"DOT_ERLANG_READ\\n\").\n">>), + ok = file:write_file(DotErlang, <<"io:put_chars(\"DOT_ERLANG_READ\\n\").\n">>), CMD1 = Quote ++ Erl ++ Quote ++ Args , case os:cmd(CMD1) of - "DOT_ERLANG_READ" ++ _ -> ok; + "DOT_ERLANG_READ" ++ _ -> + io:format("~p: Success~n", [?LINE]); Other1 -> io:format("Failed: ~ts~n",[CMD1]), io:format("Expected: ~s ++ _~n",["DOT_ERLANG_READ "]), @@ -1862,7 +1870,7 @@ no_dot_erlang(Conf) -> NO_DOT_ERL = " -boot no_dot_erlang", CMD2 = Quote ++ Erl ++ Quote ++ NO_DOT_ERL ++ Args, case lists:prefix(Wd, Other2 = os:cmd(CMD2)) of - true -> ok; + true -> io:format("~p: Success~n", [?LINE]); false -> io:format("Failed: ~ts~n",[CMD2]), io:format("Expected: ~s~n",["TESTOK"]), @@ -1870,9 +1878,13 @@ no_dot_erlang(Conf) -> exit({failed_to_start, no_dot_erlang}) end after - _ = file:delete(".erlang"), - ok = file:set_cwd(OrigWd), - ok + case filelib:is_file(BupErlang) of + true -> + {ok, _} = file:copy(BupErlang, DotErlang), + _ = file:delete(BupErlang); + false -> + _ = file:delete(DotErlang) + end end. %%%----------------------------------------------------------------- diff --git a/lib/stdlib/doc/src/c.xml b/lib/stdlib/doc/src/c.xml index 7666699183..697e1715e7 100644 --- a/lib/stdlib/doc/src/c.xml +++ b/lib/stdlib/doc/src/c.xml @@ -93,6 +93,15 @@ + + + Load an erlang resource file. + +

Search PathList and load .erlang resource file if + found.

+ + + Flush any messages sent to the shell. diff --git a/lib/stdlib/src/c.erl b/lib/stdlib/src/c.erl index c04a201ce1..9a447af5b7 100644 --- a/lib/stdlib/src/c.erl +++ b/lib/stdlib/src/c.erl @@ -668,19 +668,23 @@ lm() -> [l(M) || M <- mm()]. %% erlangrc(Home) -%% Try to run a ".erlang" file, first in the current directory -%% else in home directory. +%% Try to run a ".erlang" file in home directory. + +-spec erlangrc() -> {ok, file:filename()} | {error, term()}. erlangrc() -> case init:get_argument(home) of {ok,[[Home]]} -> erlangrc([Home]); _ -> - f_p_e(["."], ".erlang") + {error, enoent} end. -erlangrc([Home]) -> - f_p_e([".",Home], ".erlang"). +-spec erlangrc(PathList) -> {ok, file:filename()} | {error, term()} + when PathList :: [Dir :: file:name()]. + +erlangrc([Home|_]=Paths) when is_list(Home) -> + f_p_e(Paths, ".erlang"). error(Fmt, Args) -> error_logger:error_msg(Fmt, Args). @@ -692,11 +696,11 @@ f_p_e(P, F) -> {error, E={Line, _Mod, _Term}} -> error("file:path_eval(~tp,~tp): error on line ~p: ~ts~n", [P, F, Line, file:format_error(E)]), - ok; + {error, E}; {error, E} -> error("file:path_eval(~tp,~tp): ~ts~n", [P, F, file:format_error(E)]), - ok; + {error, E}; Other -> Other end. -- cgit v1.2.3 From ee0da31d00a7bd3375b66cf905cb2811d868f21b Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 26 Sep 2017 15:32:56 +0200 Subject: Enable usage of no_dot_erlang in bootstrap --- bootstrap/bin/no_dot_erlang.boot | Bin 0 -> 5555 bytes erts/start_scripts/Makefile | 5 ++++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 bootstrap/bin/no_dot_erlang.boot diff --git a/bootstrap/bin/no_dot_erlang.boot b/bootstrap/bin/no_dot_erlang.boot new file mode 100644 index 0000000000..e259dc6ffd Binary files /dev/null and b/bootstrap/bin/no_dot_erlang.boot differ diff --git a/erts/start_scripts/Makefile b/erts/start_scripts/Makefile index 20fea99016..e730422ed8 100644 --- a/erts/start_scripts/Makefile +++ b/erts/start_scripts/Makefile @@ -171,7 +171,6 @@ $(ERL_TOP)/bin/no_dot_erlang.script: $(ERLC) $(SCRIPT_PATH) +no_warn_sasl +otp_build +no_dot_erlang -o $@ $(SS_ROOT)/no_dot_erlang.rel ) ## Special target used from system/build/Makefile for source code release bootstrap. -## Add no_dot_erlang after next release bootstrap_scripts: $(SS_ROOT)/start_clean.rel $(V_at)$(INSTALL_DIR) $(TESTROOT)/bin $(V_at)$(INSTALL_DIR) $(SS_TMP) @@ -181,6 +180,10 @@ bootstrap_scripts: $(SS_ROOT)/start_clean.rel $(V_at)( cd $(SS_TMP) && \ $(ERLC) $(BOOTSTRAP_SCRIPT_PATH) +otp_build +no_module_tests \ -o $(TESTROOT)/bin/start_clean.script $(SS_ROOT)/start_clean.rel ) + $(V_at)( cd $(SS_TMP) && \ + $(ERLC) $(BOOTSTRAP_SCRIPT_PATH) +otp_build +no_module_tests \ + -o $(TESTROOT)/bin/no_dot_erlang.script $(SS_ROOT)/no_dot_erlang.rel ) + clean: $(V_at)$(RM) $(REL_SCRIPTS) $(INSTALL_SCRIPTS) -- cgit v1.2.3 From 52ca88f1c23657713946e22e0910f2cb7f2f601e Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Wed, 27 Sep 2017 16:00:42 +0200 Subject: reltool: Add no_dot_erlang bootfiles Needed by escript and tools --- lib/reltool/src/reltool.hrl | 4 +++- lib/reltool/src/reltool_target.erl | 8 +++++--- lib/reltool/src/reltool_utils.erl | 7 ++++++- lib/reltool/test/reltool_server_SUITE.erl | 4 ++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/reltool/src/reltool.hrl b/lib/reltool/src/reltool.hrl index 9c8aae6b7e..d133762818 100644 --- a/lib/reltool/src/reltool.hrl +++ b/lib/reltool/src/reltool.hrl @@ -220,7 +220,8 @@ { name :: rel_name(), vsn :: rel_vsn(), - rel_apps :: [#rel_app{}] + rel_apps :: [#rel_app{}], + load_dot_erlang = true :: boolean() }). -record(sys, @@ -300,6 +301,7 @@ -define(STANDALONE_INCL_SYS_FILTERS, ["^bin/(erl|epmd)(|\\.exe|\\.ini)\$", "^bin/start(|_clean).boot\$", + "^bin/no_dot_erlang\\.boot\$", "^erts.*/bin", "^lib\$"]). -define(STANDALONE_EXCL_SYS_FILTERS, diff --git a/lib/reltool/src/reltool_target.erl b/lib/reltool/src/reltool_target.erl index 676ce70aea..503e1971b9 100644 --- a/lib/reltool/src/reltool_target.erl +++ b/lib/reltool/src/reltool_target.erl @@ -424,7 +424,7 @@ gen_script(Rel, Sys, PathFlag, Variables) -> {error, Text} end. -do_gen_script(#rel{name = RelName, vsn = RelVsn}, +do_gen_script(#rel{name = RelName, vsn = RelVsn, load_dot_erlang=LoadErlangRc}, #sys{apps = Apps}, MergedApps, PathFlag, @@ -474,9 +474,11 @@ do_gen_script(#rel{name = RelName, vsn = RelVsn}, Type =/= none, Type =/= load, not lists:member(Name, InclApps)], - %% Apply user specific customizations - {apply, {c, erlangrc, []}}, + case LoadErlangRc of + true -> {apply, {c, erlangrc, []}}; + false -> [] + end, {progress, started} ], {ok, {script, {RelName, RelVsn}, lists:flatten(DeepList)}}. diff --git a/lib/reltool/src/reltool_utils.erl b/lib/reltool/src/reltool_utils.erl index 1a00671f13..060a0912f9 100644 --- a/lib/reltool/src/reltool_utils.erl +++ b/lib/reltool/src/reltool_utils.erl @@ -154,7 +154,12 @@ default_rels() -> rel_apps = []}, #rel{name = "start_sasl", vsn = "1.0", - rel_apps = [#rel_app{name = sasl}]} + rel_apps = [#rel_app{name = sasl}]}, + #rel{name = "no_dot_erlang", %% Needed by escript and erlc + vsn = "1.0", + rel_apps = [], + load_dot_erlang = false + } ]. choose_default(Tag, Profile, InclDefs) diff --git a/lib/reltool/test/reltool_server_SUITE.erl b/lib/reltool/test/reltool_server_SUITE.erl index db13c56238..3622f6650c 100644 --- a/lib/reltool/test/reltool_server_SUITE.erl +++ b/lib/reltool/test/reltool_server_SUITE.erl @@ -247,6 +247,7 @@ get_config(_Config) -> {app,stdlib,[{incl_cond,include},{vsn,undefined}, {lib_dir,StdLibDir}]}, {boot_rel,"start_clean"}, + {rel,"no_dot_erlang","1.0",[]}, {rel,"start_clean","1.0",[]}, {rel,"start_sasl","1.0",[sasl]}, {emu_name,"beam"}, @@ -277,6 +278,7 @@ get_config(_Config) -> {app,stdlib,[{incl_cond,include},{vsn,StdVsn}, {lib_dir,StdLibDir},{mod,_,[]}|_]}, {boot_rel,"start_clean"}, + {rel,"no_dot_erlang","1.0",[]}, {rel,"start_clean","1.0",[]}, {rel,"start_sasl","1.0",[sasl]}, {emu_name,"beam"}, @@ -2104,6 +2106,7 @@ save_config(Config) -> {app,stdlib,[{incl_cond,include},{vsn,undefined}, {lib_dir,undefined}]}, {boot_rel,"start_clean"}, + {rel,"no_dot_erlang","1.0",[]}, {rel,"start_clean","1.0",[]}, {rel,"start_sasl","1.0",[sasl]}, {emu_name,"beam"}, @@ -2144,6 +2147,7 @@ save_config(Config) -> {app,stdlib,[{incl_cond,include},{vsn,StdVsn}, {lib_dir,StdLibDir},{mod,_,[]}|_]}, {boot_rel,"start_clean"}, + {rel,"no_dot_erlang","1.0",[]}, {rel,"start_clean","1.0",[]}, {rel,"start_sasl","1.0",[sasl]}, {emu_name,"beam"}, -- cgit v1.2.3 From c4015fbe39a2b76f9746f91eb705a59ac59b06f4 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 26 Sep 2017 14:05:12 +0200 Subject: dialyzer: Do not load .erlang Use 'no_dot_erlang' start script for tools. Options and paths should be stated on the command line. --- erts/etc/common/dialyzer.c | 2 +- erts/etc/common/typer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erts/etc/common/dialyzer.c b/erts/etc/common/dialyzer.c index 0e74eb065b..b45d5c7ca7 100644 --- a/erts/etc/common/dialyzer.c +++ b/erts/etc/common/dialyzer.c @@ -255,7 +255,7 @@ int main(int argc, char** argv) } PUSH("+B"); - PUSH2("-boot", "start_clean"); + PUSH2("-boot", "no_dot_erlang"); PUSH3("-run", "dialyzer", "plain_cl"); PUSH("-extra"); diff --git a/erts/etc/common/typer.c b/erts/etc/common/typer.c index b64cbb4a92..f13135d883 100644 --- a/erts/etc/common/typer.c +++ b/erts/etc/common/typer.c @@ -177,7 +177,7 @@ main(int argc, char** argv) } PUSH("+B"); - PUSH2("-boot", "start_clean"); + PUSH2("-boot", "no_dot_erlang"); PUSH3("-run", "typer", "start"); PUSH("-extra"); -- cgit v1.2.3 From 20824528602d921716ed373ee266175e62c09421 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 26 Sep 2017 13:55:57 +0200 Subject: escript: Do not load .erlang Previously you could not opt out on loading .erlang, change the default to not load the resource file. The escript author can invoke c:erlangrc(PathList) to find and load .erlang if needed. --- erts/etc/common/escript.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 8241675200..d739d21f12 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -521,7 +521,7 @@ main(int argc, char** argv) free_env_val(env); PUSH("+B"); - PUSH2("-boot", "start_clean"); + PUSH2("-boot", "no_dot_erlang"); PUSH("-noshell"); /* -- cgit v1.2.3 From b93f1cd08c540c27ac49b8078fbb3102029979f8 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 26 Sep 2017 14:09:05 +0200 Subject: erlc: Do not load .erlang Use 'no_dot_erlang' start script for tools. Options and paths should be stated on the command line, via a Makefile, rebar.config etc. --- erts/etc/common/erlc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erts/etc/common/erlc.c b/erts/etc/common/erlc.c index 8cfd98bcc4..aa99c69100 100644 --- a/erts/etc/common/erlc.c +++ b/erts/etc/common/erlc.c @@ -234,7 +234,7 @@ int main(int argc, char** argv) PUSH("+A0"); PUSH("-noinput"); PUSH2("-mode", "minimal"); - PUSH2("-boot", "start_clean"); + PUSH2("-boot", "no_dot_erlang"); PUSH3("-s", "erl_compile", "compile_cmdline"); PUSH("-extra"); -- cgit v1.2.3 From baf53defc90c4aa8a4caa6b2c6ead6a1b58df199 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Mon, 2 Oct 2017 19:16:19 +0200 Subject: fixup! Do not load .erlang from current dir --- erts/doc/src/erl.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erts/doc/src/erl.xml b/erts/doc/src/erl.xml index ae52d92a89..823ca9544f 100644 --- a/erts/doc/src/erl.xml +++ b/erts/doc/src/erl.xml @@ -1633,8 +1633,7 @@ The .erlang startup file

When Erlang/OTP is started, the system searches for a file named - .erlang in the user's home directory is searched for an .erlang - file.

+ .erlang in the user's home directory.

If an .erlang file is found, it is assumed to contain valid Erlang expressions. These expressions are evaluated as if they were input to the shell.

-- cgit v1.2.3