summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2018-04-27 11:10:35 -0400
committerGitHub <noreply@github.com>2018-04-27 11:10:35 -0400
commita908284b112ff77dbf0ae9b9f946bc7b739faf29 (patch)
treef40b11f47c1d57cd9614582d36b89b6f423227e4
parentd3efb4708cd2303b506988c71ee3671a743b1da2 (diff)
parent0af9aba244dd10d8fdcb8520057cf8a4dcdd90bf (diff)
Merge pull request #1770 from ferd/danikp-feature_long_src_paths
ensure dest exists before copying to it and fix src_dirs symlinking
-rw-r--r--src/rebar_file_utils.erl4
-rw-r--r--src/rebar_prv_compile.erl14
-rw-r--r--test/rebar_dir_SUITE.erl21
3 files changed, 36 insertions, 3 deletions
diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl
index bb3ca71..492d690 100644
--- a/src/rebar_file_utils.erl
+++ b/src/rebar_file_utils.erl
@@ -191,6 +191,10 @@ cp_r(Sources, Dest) ->
{unix, _} ->
EscSources = [rebar_utils:escape_chars(Src) || Src <- Sources],
SourceStr = rebar_string:join(EscSources, " "),
+ % 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]),
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index 72320fb..0b4fa5f 100644
--- a/src/rebar_prv_compile.erl
+++ b/src/rebar_prv_compile.erl
@@ -225,7 +225,11 @@ copy_app_dirs(AppInfo, OldAppDir, AppDir) ->
end,
{SrcDirs, ExtraDirs} = resolve_src_dirs(rebar_app_info:opts(AppInfo)),
%% link to src_dirs to be adjacent to ebin is needed for R15 use of cover/xref
- [symlink_or_copy(OldAppDir, AppDir, Dir) || Dir <- ["priv", "include"] ++ SrcDirs],
+ %% priv/ and include/ are symlinked unconditionally to allow hooks
+ %% to write to them _after_ compilation has taken place when the
+ %% initial directory did not, and still work
+ [symlink_or_copy(OldAppDir, AppDir, Dir) || Dir <- ["priv", "include"]],
+ [symlink_or_copy_existing(OldAppDir, AppDir, Dir) || Dir <- SrcDirs],
%% copy all extra_src_dirs as they build into themselves and linking means they
%% are shared across profiles
[copy(OldAppDir, AppDir, Dir) || Dir <- ExtraDirs];
@@ -238,6 +242,14 @@ symlink_or_copy(OldAppDir, AppDir, Dir) ->
Target = filename:join([AppDir, Dir]),
rebar_file_utils:symlink_or_copy(Source, Target).
+symlink_or_copy_existing(OldAppDir, AppDir, Dir) ->
+ Source = filename:join([OldAppDir, Dir]),
+ Target = filename:join([AppDir, Dir]),
+ case ec_file:is_dir(Source) of
+ true -> rebar_file_utils:symlink_or_copy(Source, Target);
+ false -> ok
+ end.
+
copy(OldAppDir, AppDir, Dir) ->
Source = filename:join([OldAppDir, Dir]),
Target = filename:join([AppDir, Dir]),
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 0eda5bf..81051e6 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -3,7 +3,7 @@
-export([all/0, init_per_testcase/2, end_per_testcase/2]).
-export([default_src_dirs/1, default_extra_src_dirs/1, default_all_src_dirs/1]).
--export([src_dirs/1, src_dirs_with_opts/1, extra_src_dirs/1, all_src_dirs/1]).
+-export([src_dirs/1, alt_src_dir_nested/1, src_dirs_with_opts/1, extra_src_dirs/1, all_src_dirs/1]).
-export([src_dir_opts/1, recursive/1]).
-export([top_src_dirs/1]).
-export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]).
@@ -17,7 +17,7 @@
all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs,
- src_dirs, extra_src_dirs, all_src_dirs, src_dir_opts, recursive,
+ src_dirs, alt_src_dir_nested, extra_src_dirs, all_src_dirs, src_dir_opts, recursive,
profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs,
profile_src_dir_opts, top_src_dirs,
retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir,
@@ -75,6 +75,23 @@ src_dirs(Config) ->
[".", "..", "../..", "bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)).
+alt_src_dir_nested(Config) ->
+ RebarConfig = [{src_dirs, ["src", "alt/nested"]}],
+ AppsDir = ?config(apps, Config),
+ Name1 = ?config(app_one, Config),
+ ModDir = filename:join([AppsDir, "apps", Name1, "alt", "nested"]),
+ Mod = "-module(altmod). -export([main/0]). main() -> ok.",
+
+ ec_file:mkdir_path(ModDir),
+ ok = file:write_file(filename:join([ModDir, "altmod.erl"]), Mod),
+
+ Ebin = filename:join([AppsDir, "_build", "default", "lib", Name1, "ebin", "altmod.beam"]),
+ {ok, State} = rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["compile"],
+ {ok, [{file, Ebin}]}
+ ),
+ ["alt/nested", "src"] = rebar_dir:src_dirs(rebar_state:opts(State)).
+
src_dirs_with_opts(Config) ->
RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]},
{src_dirs, [{"foo",[{recursive,false}]}, "qux"]}]}],