diff options
-rw-r--r-- | src/rebar_dir.erl | 12 | ||||
-rw-r--r-- | src/rebar_file_utils.erl | 21 | ||||
-rw-r--r-- | src/rebar_prv_compile.erl | 8 |
3 files changed, 36 insertions, 5 deletions
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index acf79cd..fd80fa7 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -15,7 +15,8 @@ template_globals/1, template_dir/1, processing_base_dir/1, - processing_base_dir/2]). + processing_base_dir/2, + make_relative_path/2]). -include("rebar.hrl"). @@ -86,3 +87,12 @@ processing_base_dir(State) -> processing_base_dir(State, Dir) -> AbsDir = filename:absname(Dir), AbsDir =:= rebar_state:get(State, base_dir). + +make_relative_path(Source, Target) -> + do_make_relative_path(filename:split(Source), filename:split(Target)). + +do_make_relative_path([H|T1], [H|T2]) -> + do_make_relative_path(T1, T2); +do_make_relative_path(Source, Target) -> + Base = lists:duplicate(max(length(Target) - 1, 0), ".."), + filename:join(Base ++ Source). diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 8fe8965..ef2c70f 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -26,7 +26,8 @@ %% ------------------------------------------------------------------- -module(rebar_file_utils). --export([rm_rf/1, +-export([symlink_or_copy/2, + rm_rf/1, cp_r/2, mv/2, delete_each/1, @@ -41,6 +42,22 @@ %% Public API %% =================================================================== +symlink_or_copy(Source, Target) -> + Link = case os:type() of + {win32, _} -> + Source; + _ -> + rebar_dir:make_relative_path(Source, Target) + end, + case file:make_symlink(Link, Target) of + ok -> + ok; + {error, eexist} -> + ok; + {error, _} -> + cp_r([Source], Target) + end. + %% @doc Remove files and directories. %% Target is a single filename, directoryname or wildcard expression. -spec rm_rf(string()) -> 'ok'. @@ -127,7 +144,7 @@ write_file_if_contents_differ(Filename, Bytes) -> end. %% returns an os appropriate tmpdir given a path --spec system_tmpdir() -> file:filename(). +-spec system_tmpdir() -> file:filename(). -spec system_tmpdir(PathComponents) -> file:filename() when PathComponents :: [file:name()]. diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 001ea68..0c6f40b 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -123,8 +123,12 @@ copy_app_dirs(AppName, OldAppDir, AppDir) -> end, filelib:ensure_dir(filename:join(AppDir, "dummy")), %% link to src to be adjacent to ebin is needed for R15 use of cover/xref - [file:make_symlink(filename:join(OldAppDir, Dir), filename:join(AppDir, Dir)) - || Dir <- ["priv", "include", "src"]]; + [symlink_or_copy(OldAppDir, AppDir, Dir) || Dir <- ["priv", "include", "src"]]; false -> ok end. + +symlink_or_copy(OldAppDir, AppDir, Dir) -> + Source = filename:join(OldAppDir, Dir), + Target = filename:join(AppDir, Dir), + rebar_file_utils:symlink_or_copy(Source, Target). |