diff options
Diffstat (limited to 'bootstrap')
-rwxr-xr-x | bootstrap | 80 |
1 files changed, 66 insertions, 14 deletions
@@ -11,6 +11,10 @@ main(_) -> inets:start(httpc, [{profile, rebar}]), set_httpc_options(), + %% Clear directories for builds since bootstrapping may require + %% a changed structure from an older one + rm_rf("_build/bootstrap"), + %% Fetch and build deps required to build rebar3 BaseDeps = [{providers, []} ,{getopt, []} @@ -27,7 +31,7 @@ main(_) -> bootstrap_rebar3(), %% Build rebar.app from rebar.app.src - {ok, App} = rebar_app_info:new(rebar, "3.7.5", filename:absname("_build/default/lib/rebar/")), + {ok, App} = rebar_app_info:new(rebar, "3.8.0", filename:absname("_build/default/lib/rebar/")), rebar_otp_app:compile(rebar_state:new(), App), %% Because we are compiling files that are loaded already we want to silence @@ -135,13 +139,23 @@ compile(App, FirstFiles) -> filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])), code:add_path(filename:join(Dir, "ebin")), FirstFilesPaths = [filename:join([Dir, "src", Module]) || Module <- FirstFiles], + LeexFiles = filelib:wildcard(filename:join([Dir, "src", "*.xrl"])), + [compile_xrl_file(X) || X <- LeexFiles], + YeccFiles = filelib:wildcard(filename:join([Dir, "src", "*.yrl"])), + [compile_yrl_file(X) || X <- YeccFiles], Sources = FirstFilesPaths ++ filelib:wildcard(filename:join([Dir, "src", "*.erl"])), - [compile_file(X, [{i, filename:join(Dir, "include")} + [compile_erl_file(X, [{i, filename:join(Dir, "include")} ,debug_info ,{outdir, filename:join(Dir, "ebin")} ,return | additional_defines()]) || X <- Sources]. -compile_file(File, Opts) -> +compile_xrl_file(File) -> + {ok, _} = leex:file(File). + +compile_yrl_file(File) -> + {ok, _} = yecc:file(File). + +compile_erl_file(File, Opts) -> case compile:file(File, Opts) of {ok, _Mod} -> ok; @@ -162,7 +176,7 @@ bootstrap_rebar3() -> filename:absname("_build/default/lib/rebar/src")), true = Res == ok orelse Res == exists, Sources = ["src/rebar_resource_v2.erl", "src/rebar_resource.erl" | filelib:wildcard("src/*.erl")], - [compile_file(X, [{outdir, "_build/default/lib/rebar/ebin/"} + [compile_erl_file(X, [{outdir, "_build/default/lib/rebar/ebin/"} ,return | additional_defines()]) || X <- Sources], code:add_patha(filename:absname("_build/default/lib/rebar/ebin")). @@ -205,6 +219,23 @@ symlink_or_copy(Source, Target) -> end end. +-spec rm_rf(string()) -> 'ok'. +rm_rf(Target) -> + case os:type() of + {unix, _} -> + EscTarget = escape_chars(Target), + {ok, []} = sh(?FMT("rm -rf ~ts", [EscTarget]), + [{use_stdout, false}, abort_on_error]), + ok; + {win32, _} -> + Filelist = filelib:wildcard(Target), + Dirs = [F || F <- Filelist, filelib:is_dir(F)], + Files = Filelist -- Dirs, + ok = delete_each(Files), + ok = delete_each_dir_win32(Dirs), + ok + end. + -spec cp_r(list(string()), file:filename()) -> 'ok'. cp_r([], _Dest) -> ok; @@ -335,6 +366,27 @@ win32_ok({ok, _}) -> true; win32_ok({error, {Rc, _}}) when Rc<9; Rc=:=16 -> true; win32_ok(_) -> false. +%% @private windows rm_rf helpers +delete_each([]) -> + ok; +delete_each([File | Rest]) -> + case file:delete(File) of + ok -> + delete_each(Rest); + {error, enoent} -> + delete_each(Rest); + {error, Reason} -> + io:format("Failed to delete file ~ts: ~p\n", [File, Reason]), + error + end. + +delete_each_dir_win32([]) -> ok; +delete_each_dir_win32([Dir | Rest]) -> + {ok, []} = sh(?FMT("rd /q /s \"~ts\"", + [escape_double_quotes(filename:nativename(Dir))]), + [{use_stdout, false}, return_on_error]), + delete_each_dir_win32(Rest). + %%/rebar_file_utils %%rebar_utils @@ -398,7 +450,14 @@ expand_sh_flag(return_on_error) -> end}; expand_sh_flag(abort_on_error) -> {error_handler, - fun log_and_abort/2}; + %% moved log_and_abort/2 here because some versions somehow had trouble + %% interpreting it and thought `fun log_and_abort/2' was in `erl_eval' + fun(Command, {Rc, Output}) -> + io:format("sh(~ts)~n" + "failed with return code ~w and the following output:~n" + "~ts", [Command, Rc, Output]), + throw(bootstrap_abort) + end}; expand_sh_flag({use_stdout, false}) -> {output_handler, fun(Line, Acc) -> @@ -443,13 +502,6 @@ expand_env_variable(InStr, VarName, RawVarValue) -> re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts) end. --spec log_and_abort(string(), {integer(), string()}) -> no_return(). -log_and_abort(Command, {Rc, Output}) -> - io:format("sh(~ts)~n" - "failed with return code ~w and the following output:~n" - "~ts", [Command, Rc, Output]), - throw(bootstrap_abort). - %%/rebar_utils %%rebar_dir @@ -471,7 +523,7 @@ make_normalized_path(Path) -> AbsPath = make_absolute_path(Path), Components = filename:split(AbsPath), make_normalized_path(Components, []). - + make_absolute_path(Path) -> case filename:pathtype(Path) of absolute -> @@ -636,7 +688,7 @@ join([], Sep) when is_list(Sep) -> join([H|T], Sep) -> H ++ lists:append([Sep ++ X || X <- T]). -%% Same for chr; no non-deprecated equivalent in OTP20+ +%% Same for chr; no non-deprecated equivalent in OTP20+ chr(S, C) when is_integer(C) -> chr(S, C, 1). chr([C|_Cs], C, I) -> I; chr([_|Cs], C, I) -> chr(Cs, C, I+1); |