ninenines / erlang.mk

A build tool for Erlang that just works.
https://erlang.mk
ISC License
578 stars 241 forks source link

Failed to eval: application:load(rebar) #987

Closed chunshengit closed 1 year ago

chunshengit commented 1 year ago

I am following the tutorial to build a release and keep on running the rebar loading errors as in the following. the rebar is built and seems erlang has issue loading the rebar. I searched through the issue archive and couldn't find anything similar. Platform: Windows 11, MSYS.

cs1119@CACDTL01cs1119 MSYS /c/temp/erlang/hello_joe $ ls -la total 268 drwxr-xr-x 1 cs1119 Domain Users 0 Aug 23 11:26 . drwxr-xr-x 1 cs1119 Domain Users 0 Aug 20 15:07 .. -rw-r--r-- 1 cs1119 Domain Users 252316 Aug 22 11:27 erlang.mk

cs1119@CACDTL01cs1119 MSYS /c/temp/erlang/hello_joe $ make -f erlang.mk bootstrap-lib bootstrap-rel

cs1119@CACDTL01cs1119 MSYS /c/temp/erlang/hello_joe $ make DEP relx (main) /bin/sh: -c: line 1: unexpected EOF while looking for matching "' /bin/sh: -c: line 1: unexpected EOF while looking for matching"' /bin/sh: -c: line 1: unexpected EOF while looking for matching "' /bin/sh: -c: line 1: unexpected EOF while looking for matching"' /bin/sh: -c: line 1: unexpected EOF while looking for matching `"' Evaluating config script "c:/temp/erlang/hello_joe/.erlang.mk/rebar3/_build/default/lib/rebar/src/rebar.app.src.script" ===> Verifying dependencies... ===> Analyzing applications... ===> Compiling cf ===> Compiling cth_readable ===> Compiling certifi ===> Compiling eunit_formatters ===> Compiling getopt ===> Compiling providers ===> Compiling bbmustache ===> Compiling ssl_verify_fun ===> Compiling relx ===> Compiling erlware_commons ===> Compiling rebar ===> Verifying dependencies... ===> Cleaning out certifi... ===> Cleaning out cf... ===> Cleaning out erlware_commons... ===> Cleaning out getopt... ===> Cleaning out providers... ===> Cleaning out rebar... ===> Verifying dependencies... ===> Analyzing applications... ===> Compiling cf ===> Compiling cth_readable ===> Compiling certifi ===> Compiling eunit_formatters ===> Compiling getopt ===> Compiling providers ===> Compiling bbmustache ===> Compiling ssl_verify_fun ===> Compiling relx ===> Compiling erlware_commons ===> Compiling rebar ===> Building escript for rebar...

/c/temp/erlang/hello_joe Error! Failed to eval: application:load(rebar), application:set_env(rebar, log_level, debug), {module, rebar3} = c:l(rebar3), Conf1 = case file:consult("C:/temp/erlang/hellojoe/deps/relx/rebar.config") of {ok, Conf0} -> Conf0; -> [] end, {Conf, OsEnv} = fun() -> case filelib:is_file("C:/temp/erlang/hello_joe/deps/relx/rebar.config.script") of false -> {Conf1, []}; true -> Bindings0 = erl_eval:new_bindings(), Bindings1 = erl_eval:add_binding('CONFIG', Conf1, Bindings0), Bindings = erl_eval:add_binding('SCRIPT', "C:/temp/erlang/hello_joe/deps/relx/rebar.config.script", Bindings1), Before = os:getenv(), {ok, Conf2} = file:script("C:/temp/erlang/hello_joe/deps/relx/rebar.config.script", Bindings), {Conf2, lists:foldl(fun(E, Acc) -> lists:delete(E, Acc) end, os:getenv(), Before)} endend(), Write = fun (Text) -> file:write_file("C:/temp/erlang/hello_joe/deps/relx/Makefile", Text, [append]) end, Escape = fun (Text) -> re:replace(Text, "\$", "$$", [global, {return, list}]) end, Write("IGNORE_DEPS += edown eper eunit_formatters meck node_package " "rebar_lock_deps_plugin rebar_vsn_plugin reltool_util\n"), Write("C_SRC_DIR = /path/do/not/exist\n"), Write("C_SRC_TYPE = rebar\n"), Write("DRV_CFLAGS = -fPIC\nexport DRV_CFLAGS\n"), Write(["ERLANG_ARCH = ", rebar_utils:wordsize(), "\nexport ERLANG_ARCH\n"]), ToList = fu(V) when is_atom(V) -> atom_to_list(V); (V) when is_list(V) -> "'\"" ++ V ++ "\"'" endfun() -> Write("ERLC_OPTS = +debug_info\n"), case lists:keyfind(erlopts, 1, Conf) of false -> ok; {, ErlOpts} -> lists:foreach(fun ({d, D}) -> Write("ERLC_OPTS += -D" ++ ToList(D) ++ "=1\n"); ({d, DKey, DVal}) -Write("ERLC_OPTS += -D" ++ ToList(DKey) ++ "=" ++ ToList(DVal) ++ "\n"); ({i, I}) -> Write(["ERLC_OPTS += -I ", I, "\n"]); ({platform_define, Regex, D}) -> case rebar_utils:is_arch(Regex) of true -> Write("ERLC_OPTS += -D" ++ ToList(D) ++ "=1\n"); false -> ok end; ({parse_transform, PT}) -> Write("ERLC_OPTS += +'{parsetransform, " ++ ToList(PT) ++ "}'\n"); () -> ok end, ErlOpts) end, Write("\n") end(), GetHexVsn2 = fun(N, NP) -> case file:consult("C:/temp/erlang/hellojoe/deps/relx/rebar.lock") of {ok, Lock} -> io:format("~p~n", [Lock]), LockPkgs = case lists:keyfind("1.2.0", 1, Lock) of {, LP} -> LP; -case lists:keyfind("1.1.0", 1, Lock) of {, LP} -> LP; _ -> false end end, if is_list(LockPkgs) -> io:format("~p~n", [LockPkgs]), case lists:keyfind(atom_tobinary(N, latin1), 1, LockPkgs) of {, {pkg, , Vsn}, } -> io:format("~p~n", [Vsn]), {N, {hex, NP, binary_tolist(Vsn)}}; -> false end; true -> false end; -> false end end, GetHexVsn3Common = fun(N, NP, S0) -> case GetHexVsn2(N, NP) of false -> S2 = case S0 of " " ++ S1 -> S1; -> S0 end, S = case length([ok || $. <- S2]) o0 -> S2 ++ ".0.0"; 1 -> S2 ++ ".0"; -> S2 end, {N, {hex, NP, S}}; NameSource -> NameSource end end, GetHexVsn3 = fun (N, NP, "~>" ++ S0) -> GetHexVsn3Common(N, NP, S0); (N, NP, ">=" ++ S0) -> GetHexVsn3Common(N, NP, S0); (N, NP, S) -> {N, {hex, NP, S}} endfun() -> File = case lists:keyfind(deps, 1, Conf) of false -> []; {, Deps} -> [begin case case Dep of N when is_atom(N) -> GetHexVsn2(N, N); {N, S} when is_atom(N), is_list(S) -> GetHexVsn3(N, N, S); {N, {pkg, NP}} when is_atom(N) -> GetHexVsn2(N, NP); {N, S, {pkg, NP}} -> GetHexVsn3(N, NP, S); {N, S} when istuple(S) -> {N, S}; {N, , S} -> {N, S}{N, , S, } -> {N, S}; _ -> false end of false -> ok; {Name, Source} -> {Method, Repo, Commit} = case Source of {hex, NPV, V} -> {hex, V, NPV}; {git, R} -> {git, R, master}; {M, R, {branch, C}} -> {M, R, C}; {M, R, {ref, C}} -> {M, R, C}; {M, R, {tag, C}} -> {M, R, C}; {M, R, C} -> {M, R, C} end, Write(iolib:format("DEPS += ~s\ndep~s = ~s ~s ~s~n", [Name, Name, Method, Repo, Commit])) end end || Dep <- Deps] endend(), fun() -> case lists:keyfind(erl_firstfiles, 1, Conf) of false -> ok; {, Files0} -> Files = [begin hd(filelib:wildcard(")) end || "src/" ++ F <- Files0], Names = [[" ", case lists:reverse(F) of "lre." ++ Elif -> lists:reverse(Elif); "lrx." ++ Elif -> lists:reverse(Elif); "lry." ++ Elif -> lists:reverse(Elif); Elif -> lists:reverse(Elif)end] || "C:/temp/erlang/hello_joe/deps/relx/src/" ++ F <- Files], Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names])) end end(), Write("\n\nrebardep: preprocess pre-deps deps pre-app app\n"), Write("\npreprocess::\n"), Write("\npre-deps::\n"), Write("\npre-app::\n"), PatchHook = fun(Cmd) -> Cmd2 = re:replace(Cmd, "^([g]?make)(.)( -C.)", "\1\3\2", [{return, list}]), case Cmd2 of "make -C" ++ Cmd1 -> "$(MAKE) -C" ++ Escape(Cmd1); "gmake -C" ++ Cmd1 -> "$(MAKE) -C" ++ Escape(Cmd1); "make " ++ Cmd1 -> "$(MAKE) -f Makefile.orig.mk " ++ Escape(Cmd1);"gmake " ++ Cmd1 -> "$(MAKE) -f Makefile.orig.mk " ++ Escape(Cmd1); -> Escape(Cmd) end end, fun() -> case lists:keyfind(prehooks, 1, Conf) of false -> ok; {, Hooks} -> [case H of {'get-deps', Cmd} -> Write("\npre-deps::\n\t" ++ PatchHook(Cmd) ++ "\n"); {compile, Cmd} -> Write("\npre-app::\n\tCC=$(CC) " ++ PatchHook(Cmd) ++ "\n"); {{pc, compile}, Cmd} -> Write("\npre-app::\n\tCC=$(CC) " ++ PatchHook(Cmd) ++ "\n"); {Regex, compile, Cmd} -> case rebar_utils:isarch(Regex) of true -> Write("\npre-app::\n\tCC=$(CC) " ++ PatchHook(Cmd) ++ "\n"); false -> ok end; -> ok end || H <- Hooks] end end(), ShellToMk = fun(V0) -> V1 = re:replace(V0, "[$][(]", "$(shell ", [global]), V = re:replace(V1, "([$])(?![(])(\w)", "\1(\2)", [global]), re:replace(V, "-Werror\b", "", [{return, list}, global]) end, PortSpecs = fun() -> case lists:keyfind(port_specs, 1, Conf) of false -> case filelib:is_dir("C:/temp/erlang/hello_joe/deps/relx/c_src") of false -> []; true -> [{"priv/" ++ proplists:get_value(so_name, Conf, "relx_drv.so"), proplists:get_value(port_sources, Conf, ["c_src/.c"]), []}] end; {_, Specs} -> lists:flatten([case S of {Output, Input} -> {ShellToMk(Output), Input, []}; {Regex, Output, Input} -> case rebar_utils:is_arch(Regex) of true -> {ShellToMk(Output), Input, []}; false -> []end; {Regex, Output, Input, [{env, Env}]} -> case rebar_utils:is_arch(Regex) of true -> {ShellToMk(Output), Input, Env}; false -> [] end end || S <- Specs]) end end(), PortSpecWrite = fun (Text) -> file:write_file("C:/temp/erlang/hello_joe/deps/relx/csrc/Makefile.erlang.mk", Text, [append]) end, case PortSpecs of [] -> ok; -> Write("\npre-app::\n\t@$(MAKE) --no-print-directory -f c_src/Makefile.erlang.mk\n"), PortSpecWrite(io_lib:format("ERL_CFLAGS ?= -finline-functions -Wall -fPIC -I \"~s/erts-~s/include\" -I \"~s\"\n", [code:root_dir(), erlang:system_info(version), code:lib_dir(erl_interface, include)])), PortSpecWrite(io_lib:format("ERL_LDFLAGS ?= -L \"~s\" -lei\n", [code:lib_dir(erlinterface, lib)])), [PortSpecWrite(["\n", E, "\n"]) || E <- OsEnv], FilterEnv = fun(Env) -> lists:flatten([case E of {, _} -> E; {Regex, K, V} -> case rebar_utils:is_arch(Regex) of true -> {K, V}; false -> [] end end || E <- Env]) end, MergeEnv = fun(Env) -> lists:foldl(fun ({K, V}, Acc) -> case lists:keyfind(K, 1, Acc) of false -> [{K, rebar_utils:expand_envvariable(V, K, "")}|Acc]; {, V0} -> [{K, rebar_utils:expand_env_variable(V, K, V0)}|Acc] end end, [], Env) end, PortEnv = case lists:keyfind(portenv, 1, Conf) of false -> []; {, PortEnv0} -> FilterEnv(PortEnv0) end, PortSpec = fun ({Output, Input0, Env}) -> filelib:ensure_dir("C:/temp/erlang/hello_joe/deps/relx/" ++ Output), Input = [[" ", I] || I <- Input0], PortSpecWrite([ [["\n", K, " = ", ShellToMk(V)] || {K, V} <- lists:reverse(MergeEnv(PortEnv))], case msys2 of darwin -> "\n\nLDFLAGS += -flatnamespace -undefined suppress"; -> "" end, "\n\nall:: ", Output, "\n\t@:\n\n", "%.o: %.c\n\t$(CC) -c -o $\@ $\< $(CFLAGS) $(ERL_CFLAGS) $(DRV_CFLAGS) $(EXE_CFLAGS)\n\n", "%.o: %.C\n\t$(CXX) -c -o $\@ $\< $(CXXFLAGS) $(ERL_CFLAGS) $(DRV_CFLAGS) $(EXE_CFLAGS)\n\n", "%.o: %.cc\n\t$(CXX) -c -o $\@ $\< $(CXXFLAGS) $(ERL_CFLAGS) $(DRV_CFLAGS) $(EXE_CFLAGS)\n\n", "%.o: %.cpp\n\t$(CXX) -c -o $\@ $\< $(CXXFLAGS) $(ERL_CFLAGS) $(DRV_CFLAGS) $(EXE_CFLAGS)\n\n",[[Output, ": ", K, " += ", ShellToMk(V), "\n"] || {K, V} <- lists:reverse(MergeEnv(FilterEnv(Env)))]Output, ": $(foreach ext,.c .C .cc .cpp,", "$(patsubst %$(ext),%.o,$(filter %$(ext),$(wildcard", Input, "))))\n", "\t$(CC) -o $\@ $\? $(LDFLAGS) $(ERL_LDFLAGS) $(DRV_LDFLAGS) $(LDLIBS) $(EXELDFLAGS)", case {filename:extension(Output), msys2} of {[], } -> "\n" {".so", darwin} -> "-shared\n"; {".dylib", darwin} -> "-shared\n"; {, darwin} -> "\n"; -> " -shared\n" end]) end, [PortSpec(S) || S <- PortSpecs] end, fun() -> case lists:keyfind(plugins, 1, Conf) of false -> ok; {_, Plugins0} -> Plugins = [P || P <- Plugins0, istuple(P)], case lists:keyfind('lfe-compile', 1, Plugins) of false -> ok; -> Write("\nBUILD_DEPS = lfe lfe.mk\ndep_lfe.mk = git https://github.com/ninenines/lfe.mk master\nDEP_PLUGINS = lfe.mk\n") end end end(), Write("\ninclude $(if $(ERLANG_MK_FILENAME),$(ERLANG_MK_FILENAME),erlang.mk)"), RunPlugin = fun(Plugin, Step) -> case erlang:function_exported(Plugin, Step, 2) of false -> ok; true -> c:cd("C:/temp/erlang/hello_joe/deps/relx/"), Ret = Plugin:Step({config, "", Conf, dict:new(), dict:new(), dict:new(), dict:store(basedir, "", dict:new())}, undefined), io:format("rebar plugin ~p step ~p ret ~p~n", [Plugin, Step, Ret]) end end, fun() -> case lists:keyfind(plugins, 1, Conf) of false -> ok; {, Plugins0} -> Plugins = [P || P <- Plugins0, isatom(P)], [begin case lists:keyfind(deps, 1, Conf) of false -> ok; {, Deps} -> case lists:keyfind(P, 1, Deps) of false -> ok; _ -> Path = "C:/temp/erlang/hello_joe/deps/" ++ atom_to_list(P), io:format("~s", [os:cmd("make -C C:/temp/erlang/hello_joe/deps/relx " ++ Path)]), io:format("~s", [os:cmd("make -C " ++ Path ++ " IS_DEP=1")]), code:add_patha(Path ++ "/ebin") end end end || P <- Plugins], [case code:loadfile(P) of {module, P} -> ok; -case lists:keyfind(plugindir, 1, Conf) of false -> ok; {, PluginsDir} -> ErlFile = "C:/temp/erlang/hello_joe/deps/relx/" ++ PluginsDir ++ "/" ++ atom_to_list(P) ++ ".erl", {ok, P, Bin} = compile:file(ErlFile, [binary]), {module, P} = code:load_binary(P, ErlFile, Bin) end end || P <- Plugins], [RunPlugin(P, preprocess) || P <- Plugins], [RunPlugin(P, pre_compile) || P <- Plugins], [RunPlugin(P, compile) || P <- Plugins] end end(), halt()

Runtime terminating during boot ({{badmatch,{error,{1,erlparse,[]}}},[{init,startit,1,[{},{_}]},{init,startem,1,[{},{_}]},{init,doboot,3,[{},{_}]}]})

Crash dump is being written to: erl_crash.dump...done Error: No Makefile to build dependency /c/temp/erlang/hello_joe/deps/relx. make: *** [erlang.mk:3750: deps] Error 2

cs1119@CACDTL01cs1119 MSYS /c/temp/erlang/hello_joe $

chunshengit commented 1 year ago

I miss stated the error:

Error: No Makefile to build dependency /c/temp/erlang/hello_joe/deps/relx.

essen commented 1 year ago

Seems like the main issue is

/bin/sh: -c: line 1: unexpected EOF while looking for matching "' /bin/sh: -c: line 1: unexpected EOF while looking for matching "'
/bin/sh: -c: line 1: unexpected EOF while looking for matching "' /bin/sh: -c: line 1: unexpected EOF while looking for matching "'
/bin/sh: -c: line 1: unexpected EOF while looking for matching `"'

I am probably unable to look into this further until Monday unfortunately.

essen commented 1 year ago

Hello! I can indeed see problems on Windows. Something must have changed recently. I will investigate tomorrow.

chunshengit commented 1 year ago

that is great! I have been playing rebar3 on Windows and don't see any issue. It looks like Makefile for relx is not generated properly and the build gets choked. Looking forward to your finding!

essen commented 1 year ago

I figured out where the issue comes from. My fault! Didn't help that the Windows CI was down all this time. I will see how it can be fixed.

essen commented 1 year ago

Commit dcc2741b6026a66c457fd2193cda8a42a3874839 is the culprit.

essen commented 1 year ago

This should be fixed in e8e6115. Thanks!