From b3f99aa42fcbeffa8751df308cb194a470cd0e80 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sun, 22 Apr 2018 09:09:01 +0300 Subject: ensure Dest exists before copying to it --- src/rebar_file_utils.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index bb3ca71..0dbc40a 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -191,8 +191,8 @@ cp_r(Sources, Dest) -> {unix, _} -> EscSources = [rebar_utils:escape_chars(Src) || Src <- Sources], SourceStr = rebar_string:join(EscSources, " "), - {ok, []} = rebar_utils:sh(?FMT("cp -Rp ~ts \"~ts\"", - [SourceStr, rebar_utils:escape_double_quotes(Dest)]), + {ok, []} = rebar_utils:sh(?FMT("mkdir -p \"~ts\" && cp -Rp ~ts $_", + [rebar_utils:escape_double_quotes(Dest), SourceStr]), [{use_stdout, false}, abort_on_error]), ok; {win32, _} -> -- cgit v1.1 From c22fde17a7a30cee5e3e5e04fab187eed2ecfe42 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 23 Apr 2018 22:34:40 +0300 Subject: fix & test --- src/rebar_file_utils.erl | 8 ++++++-- test/rebar_dir_SUITE.erl | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 0dbc40a..492d690 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -191,8 +191,12 @@ cp_r(Sources, Dest) -> {unix, _} -> EscSources = [rebar_utils:escape_chars(Src) || Src <- Sources], SourceStr = rebar_string:join(EscSources, " "), - {ok, []} = rebar_utils:sh(?FMT("mkdir -p \"~ts\" && cp -Rp ~ts $_", - [rebar_utils:escape_double_quotes(Dest), SourceStr]), + % 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]), ok; {win32, _} -> diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index 4743865..e544410 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([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]). -export([profile_src_dir_opts/1]). @@ -16,7 +16,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, retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir, @@ -74,6 +74,26 @@ 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), + Name2 = ?config(app_two, Config), + ModDir = filename:join([AppsDir, "apps", Name1, "alt", "nested"]), + ModDir2 = filename:join([AppsDir, "apps", Name2, "alt", "nested"]), + Mod = "-module(altmod). -export([main/0]). main() -> ok.", + + ec_file:mkdir_path(ModDir), + ec_file:mkdir_path(ModDir2), + 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"]}]}], -- cgit v1.1 From 775261dd0b24d74e48f5873ef1ffff56c0c4829a Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 27 Apr 2018 09:32:39 -0400 Subject: Prevent copying or symlink non-existing src_dirs This would cause crashes on linux and force people to have a src_dirs config that is strictly matching what is on the file system rather than acting as a specification of those that are valid. To compare, if lib_dirs worked the same, then any repo that did not both have apps/ and lib/ would crash, as the spec mentions both options as valid. --- src/rebar_prv_compile.erl | 5 ++++- test/rebar_dir_SUITE.erl | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 72320fb..1748118 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -236,7 +236,10 @@ copy_app_dirs(AppInfo, OldAppDir, AppDir) -> symlink_or_copy(OldAppDir, AppDir, Dir) -> Source = filename:join([OldAppDir, Dir]), Target = filename:join([AppDir, Dir]), - rebar_file_utils:symlink_or_copy(Source, Target). + 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]), diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl index f5ac0fc..81051e6 100644 --- a/test/rebar_dir_SUITE.erl +++ b/test/rebar_dir_SUITE.erl @@ -79,13 +79,10 @@ alt_src_dir_nested(Config) -> RebarConfig = [{src_dirs, ["src", "alt/nested"]}], AppsDir = ?config(apps, Config), Name1 = ?config(app_one, Config), - Name2 = ?config(app_two, Config), ModDir = filename:join([AppsDir, "apps", Name1, "alt", "nested"]), - ModDir2 = filename:join([AppsDir, "apps", Name2, "alt", "nested"]), Mod = "-module(altmod). -export([main/0]). main() -> ok.", ec_file:mkdir_path(ModDir), - ec_file:mkdir_path(ModDir2), ok = file:write_file(filename:join([ModDir, "altmod.erl"]), Mod), Ebin = filename:join([AppsDir, "_build", "default", "lib", Name1, "ebin", "altmod.beam"]), -- cgit v1.1 From 0af9aba244dd10d8fdcb8520057cf8a4dcdd90bf Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 27 Apr 2018 10:22:07 -0400 Subject: Fix symlink/copying logic in compiler for priv Priv and include dirs need the virtual symlink in order to preserve hook functionality in some edge cases. --- src/rebar_prv_compile.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 1748118..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]; @@ -236,6 +240,11 @@ copy_app_dirs(AppInfo, OldAppDir, AppDir) -> symlink_or_copy(OldAppDir, AppDir, Dir) -> Source = filename:join([OldAppDir, 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 -- cgit v1.1