diff options
-rw-r--r-- | src/rebar_file_utils.erl | 52 | ||||
-rw-r--r-- | test/rebar_test_utils.erl | 20 |
2 files changed, 58 insertions, 14 deletions
diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 32abd4b..735ab49 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -75,14 +75,40 @@ symlink_or_copy(Source, Target) -> {error, eexist} -> ok; {error, _} -> - Target2 = case is_binary(Target) of - true -> unicode:characters_to_list(Target); - false -> Target - end, - rm_rf(Target2), - cp_r([Source], Target) + case os:type() of + {win32, _} -> + S = unicode:characters_to_list(Source), + T = unicode:characters_to_list(Target), + case filelib:is_dir(S) of + true -> + win32_symlink(S, T); + false -> + ok + end; + _ -> + case filelib:is_dir(Target) of + true -> + ok; + false -> + cp_r([Source], Target) + end + end end. +win32_symlink(Source, Target) -> + Res = rebar_utils:sh( + ?FMT("cmd /c mklink /j \"~s\" \"~s\"", + [filename:nativename(Target), filename:nativename(Source)]), + [{use_stdout, false}, return_on_error]), + case win32_ok(Res) of + true -> ok; + false -> + {error, lists:flatten( + io_lib:format("Failed to sumlink ~s to ~s~n", + [Source, Target]))} + end. + + %% @doc Remove files and directories. %% Target is a single filename, directoryname or wildcard expression. -spec rm_rf(string()) -> 'ok'. @@ -130,11 +156,11 @@ mv(Source, Dest) -> ok; {win32, _} -> Res = rebar_utils:sh( - ?FMT("robocopy /move /e \"~s\" \"~s\" 1> nul", + ?FMT("robocopy /move /s \"~s\" \"~s\" 1> nul", [filename:nativename(Source), filename:nativename(Dest)]), [{use_stdout, false}, return_on_error]), - case win32_robocopy_ok(Res) of + case win32_ok(Res) of true -> ok; false -> {error, lists:flatten( @@ -143,9 +169,9 @@ mv(Source, Dest) -> end end. -win32_robocopy_ok({ok, _}) -> true; -win32_robocopy_ok({error, {Rc, _}}) when Rc<9; Rc=:=16 -> true; -win32_robocopy_ok(_) -> false. +win32_ok({ok, _}) -> true; +win32_ok({error, {Rc, _}}) when Rc<9; Rc=:=16 -> true; +win32_ok(_) -> false. delete_each([]) -> ok; @@ -224,10 +250,10 @@ xcopy_win32(Source,Dest)-> %% "xcopy \"~s\" \"~s\" /q /y /e 2> nul", Chanegd to robocopy to %% handle long names. May have issues with older windows. Res = rebar_utils:sh( - ?FMT("robocopy \"~s\" \"~s\" /e /is 2> nul", + ?FMT("robocopy \"~s\" \"~s\" /e /is /purge 2> nul", [filename:nativename(Source), filename:nativename(Dest)]), [{use_stdout, false}, return_on_error]), - case win32_robocopy_ok(Res) of + case win32_ok(Res) of true -> ok; false -> {error, lists:flatten( diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 2f4d532..b210bc2 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -214,6 +214,7 @@ check_results(AppDir, Expected) -> ?assertNotEqual(false, lists:keyfind(Name, 1, DepsNames)) ; ({dep, Name, Vsn}) -> ct:pal("Dep Name: ~p, Vsn: ~p", [Name, Vsn]), + ct:pal("DepNames: ~p~n", [DepsNames]), case lists:keyfind(Name, 1, DepsNames) of false -> error({dep_not_found, Name}); @@ -273,11 +274,28 @@ check_results(AppDir, Expected) -> LibDir = filename:join([ReleaseDir, Name, "lib"]), {ok, RelLibs} = file:list_dir(LibDir), + ct:pal("RelLibs: ~p~n", [RelLibs]), IsSymLinkFun = fun(X) -> ec_file:is_symlink(filename:join(LibDir, X)) end, - DevMode = lists:all(IsSymLinkFun, RelLibs), + IsDirFun = + fun(X) -> + filelib:is_dir(filename:join([LibDir, X])) + end, + DevMode = + case os:type() of + {unix, _} -> + lists:all(IsSymLinkFun, RelLibs); + {win32, _} -> + Bool = lists:all(IsDirFun, RelLibs), + case ExpectedDevMode of + true -> + Bool; + false -> + not Bool + end + end, ?assertEqual(ExpectedDevMode, DevMode), %% throws not_found if it doesn't exist |