diff options
-rwxr-xr-x | bootstrap | 58 | ||||
-rw-r--r-- | src/rebar_compiler_erl.erl | 2 | ||||
-rw-r--r-- | src/rebar_file_utils.erl | 17 | ||||
-rw-r--r-- | src/rebar_git_resource.erl | 5 |
4 files changed, 68 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, []} @@ -215,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; @@ -345,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 @@ -408,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) -> @@ -453,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 diff --git a/src/rebar_compiler_erl.erl b/src/rebar_compiler_erl.erl index 0a560cd..759305c 100644 --- a/src/rebar_compiler_erl.erl +++ b/src/rebar_compiler_erl.erl @@ -317,7 +317,7 @@ expand_file_names(Files, Dirs) -> true -> [Incl]; false -> - rebar_utils:find_files_in_dirs(Dirs, Incl, true) + rebar_utils:find_files_in_dirs(Dirs, [$^, Incl, $$], true) end end, Files). diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index a51a557..0e0dfe3 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -189,16 +189,27 @@ cp_r([], _Dest) -> ok; cp_r(Sources, Dest) -> case os:type() of - {unix, _} -> + {unix, Os} -> EscSources = [rebar_utils:escape_chars(Src) || Src <- Sources], SourceStr = rebar_string:join(EscSources, " "), + % On darwin the following cp command will cp everything inside + % target vs target and everything inside, so we chop the last char + % off if it is a '/' + Source = case {Os == darwin, lists:last(SourceStr) == $/} of + {true, true} -> + rebar_string:trim(SourceStr, trailing, "/"); + {true, false} -> + SourceStr; + {false, _} -> + SourceStr + end, % ensure destination exists before copying files into it {ok, []} = rebar_utils:sh(?FMT("mkdir -p ~ts", [rebar_utils:escape_chars(Dest)]), [{use_stdout, false}, abort_on_error]), {ok, []} = rebar_utils:sh(?FMT("cp -Rp ~ts \"~ts\"", - [SourceStr, rebar_utils:escape_double_quotes(Dest)]), - [{use_stdout, false}, abort_on_error]), + [Source, rebar_utils:escape_double_quotes(Dest)]), + [{use_stdout, true}, abort_on_error]), ok; {win32, _} -> lists:foreach(fun(Src) -> ok = cp_r_win32(Src,Dest) end, Sources), diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index b2db6ca..c5031df 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -36,10 +36,11 @@ lock_(AppDir, {git, Url}) -> {ok, VsnString} = case os:type() of {win32, _} -> - rebar_utils:sh("git --git-dir=\"" ++ Dir ++ "/.git\" --work-tree=\"" ++ Dir ++ "\" rev-parse --verify HEAD", + rebar_utils:sh("git --git-dir='" ++ Dir ++ "/.git' " + "--work-tree='" ++ Dir ++ "' rev-parse --verify HEAD", [{use_stdout, false}, {debug_abort_on_error, AbortMsg}]); _ -> - rebar_utils:sh("git --git-dir=\"" ++ Dir ++ "/.git\" rev-parse --verify HEAD", + rebar_utils:sh("git --git-dir='" ++ Dir ++ "/.git' rev-parse --verify HEAD", [{use_stdout, false}, {debug_abort_on_error, AbortMsg}]) end, Ref = rebar_string:trim(VsnString, both, "\n"), |