diff options
author | Francis Joanis <francis.joanis@gmail.com> | 2011-12-16 15:25:08 -0500 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2012-01-17 16:54:27 +0100 |
commit | b498e86ef79a37d2779a63d97fd6ee4336d03422 (patch) | |
tree | dd6402e5f1329adf79ab019585d4b614f47871e8 /src | |
parent | 41d6abc64d2e0e84106115cff32f5f7b8af0f8ad (diff) |
Delete existing erl files in ?EUNIT_DIR
Before copying the .erl files to the .eunit directory ensure that they
are deleted if they already exist. This prevents EACCES errors to happen
when trying to re-copy .erl files that are read-only.
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_eunit.erl | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index 2743b0e..410d1f5 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -85,6 +85,27 @@ eunit(Config, _AppFile) -> %% in src but in a subdirectory of src. Cover only looks in cwd and ../src %% for source files. SrcErls = rebar_utils:find_files("src", ".*\\.erl\$"), + + %% If it is not the first time rebar eunit is executed, there will be source + %% files already present in ?EUNIT_DIR. Since some SCMs (like Perforce) set + %% the source files as being read only (unless they are checked out), we + %% need to be sure that the files already present in ?EUNIT_DIR are writable + %% before doing the copy. This is done here by removing any file that was + %% already present before calling rebar_file_utils:cp_r. + + %% Get the full path to a file that was previously copied in ?EUNIT_DIR + ToCleanUp = fun(F, Acc) -> + F2 = filename:basename(F), + F3 = filename:join([?EUNIT_DIR, F2]), + case filelib:is_regular(F3) of + true -> [F3|Acc]; + false -> Acc + end + end, + + ok = rebar_file_utils:delete_each(lists:foldl(ToCleanUp, [], TestErls)), + ok = rebar_file_utils:delete_each(lists:foldl(ToCleanUp, [], SrcErls)), + ok = rebar_file_utils:cp_r(SrcErls ++ TestErls, ?EUNIT_DIR), %% Compile erlang code to ?EUNIT_DIR, using a tweaked config |