Fix #267 (code path regression)

Since the introduction of -r/--recursive, deps were not properly added
to the code path when running ct, eunit, etc.

To fix that, pass a flag down to process_dir1 and conditionalize
execution of the command. This moves the decision into process_dir1
where we can decide to invoke preprocess/2 and postprocess/2 but not
execute the command.

Without this fix, you'd have to, for example, invoke 'rebar -r ct
skip_deps=true', if you wanted to run base_dir's ct suites with deps on
the code path (while skipping all non-base_dir ct suites).

So, with this patch applied, if you run
$ rebar ct
deps will be on the code path, and only base_dir's ct suites will be
tested.

If you want to test ct suites in base_dir and sub_dirs, you have to run
$ rebar -r ct skip_deps=true

If you want to test ct suites in all dirs, you have to run
$ rebar -r ct

The fix is not specific to ct and applies to all commands.

To be able to add inttest/code_path_no_recurse/deps, I had to fix
.gitignore. While at it, I've updated and fixed all entries.
This commit is contained in:
Tuncer Ayaz 2014-04-20 11:59:41 +02:00
parent b037f6c076
commit 99fe270e59
16 changed files with 177 additions and 53 deletions

17
.gitignore vendored
View file

@ -1,12 +1,11 @@
*.beam /ebin/*.beam
rebar /rebar
*~ *~
*.orig *.orig
.*.swp .*.swp
rt.work /rt.work
.test /dialyzer_warnings
dialyzer_warnings /rebar.cmd
rebar.cmd /.eunit
.eunit /deps
deps /.rebar
.rebar/*

View file

@ -0,0 +1,19 @@
-module(code_path_no_recurse_rt).
-export([files/0,
run/1]).
files() ->
[
{copy, "../../rebar", "rebar"},
{copy, "rebar.config", "rebar.config"},
{copy, "src", "src"},
{copy, "test", "test"},
{copy, "deps", "deps"}
].
run(_Dir) ->
retest:log(info, "Compile project~n"),
{ok, _} = retest:sh("./rebar -v compile"),
retest:log(info, "Run eunit with referenced deps on the code path~n"),
{ok, _} = retest:sh("./rebar -v eunit"),
ok.

View file

@ -0,0 +1,12 @@
{application, bazdep,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{mod, {bazdep, []}},
{env, []}
]}.

View file

@ -0,0 +1,6 @@
-module(bazdep).
-export([bazdep/0]).
bazdep() ->
bazdep.

View file

@ -0,0 +1,5 @@
-module(bazdep_tests).
-include_lib("eunit/include/eunit.hrl").
bazdep_test() ->
?assert(bazdep:bazdep() =:= bazdep).

View file

@ -0,0 +1 @@
{deps, [{bazdep, "1"}]}.

View file

@ -0,0 +1,12 @@
{application, foodep,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{mod, {foodep, []}},
{env, []}
]}.

View file

@ -0,0 +1,6 @@
-module(foodep).
-export([foodep/0]).
foodep() ->
bazdep:bazdep() =:= bazdep.

View file

@ -0,0 +1,5 @@
-module(foodep_tests).
-include_lib("eunit/include/eunit.hrl").
foodep_test() ->
?assert(foodep:foodep()).

View file

@ -0,0 +1,12 @@
{application, unuseddep,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{mod, {unuseddep, []}},
{env, []}
]}.

View file

@ -0,0 +1,6 @@
-module(unuseddep).
-export([unuseddep/0]).
unuseddep() ->
unuseddep.

View file

@ -0,0 +1 @@
{deps, [{foodep, "1"}]}.

View file

@ -0,0 +1,12 @@
{application, codepath,
[
{description, ""},
{vsn, "1"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{mod, {codepath, []}},
{env, []}
]}.

View file

@ -0,0 +1,6 @@
-module(codepath).
-export([codepath/0]).
codepath() ->
foodep:foodep().

View file

@ -0,0 +1,12 @@
-module(codepath_tests).
-include_lib("eunit/include/eunit.hrl").
codepath_test() ->
?assertEqual({module, codepath}, code:ensure_loaded(codepath)),
?assertEqual({module, foodep}, code:ensure_loaded(foodep)),
?assertEqual({module, bazdep}, code:ensure_loaded(bazdep)),
?assert(codepath:codepath()).
unuseddep_test() ->
?assertEqual(non_existing, code:which(unuseddep)),
?assertEqual({error, nofile}, code:ensure_loaded(unuseddep)).

View file

@ -123,12 +123,7 @@ process_dir(Dir, Command, ParentConfig, DirSet) ->
?WARN("Skipping non-existent sub-dir: ~p\n", [Dir]), ?WARN("Skipping non-existent sub-dir: ~p\n", [Dir]),
{ParentConfig, DirSet}; {ParentConfig, DirSet};
true -> true ->
maybe_process_dir(Dir, Command, ParentConfig, DirSet) WouldCd = would_cd_into_dir(Dir, Command, ParentConfig),
end.
maybe_process_dir(Dir, Command, ParentConfig, DirSet) ->
case should_cd_into_dir(Dir, Command, ParentConfig) of
true ->
ok = file:set_cwd(Dir), ok = file:set_cwd(Dir),
Config = maybe_load_local_config(Dir, ParentConfig), Config = maybe_load_local_config(Dir, ParentConfig),
@ -144,12 +139,18 @@ maybe_process_dir(Dir, Command, ParentConfig, DirSet) ->
{ok, AvailModuleSets} = application:get_env(rebar, modules), {ok, AvailModuleSets} = application:get_env(rebar, modules),
ModuleSet = choose_module_set(AvailModuleSets, Dir), ModuleSet = choose_module_set(AvailModuleSets, Dir),
skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath, skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath,
ModuleSet); ModuleSet, WouldCd)
false ->
{ParentConfig, DirSet}
end. end.
should_cd_into_dir(Dir, Command, Config) -> would_cd_into_dir(Dir, Command, Config) ->
case would_cd_into_dir1(Dir, Command, Config) of
true ->
would_cd;
false ->
would_not_cd
end.
would_cd_into_dir1(Dir, Command, Config) ->
rebar_utils:processing_base_dir(Config, Dir) orelse rebar_utils:processing_base_dir(Config, Dir) orelse
rebar_config:is_recursive(Config) orelse rebar_config:is_recursive(Config) orelse
is_recursive_command(Command, Config) orelse is_recursive_command(Command, Config) orelse
@ -181,24 +182,25 @@ is_generate_in_rel_dir(_, _) ->
false. false.
skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath, skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath,
{[], undefined}=ModuleSet) -> {[], undefined}=ModuleSet, WouldCd) ->
process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, ModuleSet); process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, ModuleSet,
WouldCd);
skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath, skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath,
{_, File}=ModuleSet) -> {_, File}=ModuleSet, WouldCd) ->
case lists:suffix(".app.src", File) case lists:suffix(".app.src", File)
orelse lists:suffix(".app", File) of orelse lists:suffix(".app", File) of
true -> true ->
%% .app or .app.src file, check if is_skipped_app %% .app or .app.src file, check if is_skipped_app
skip_or_process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, skip_or_process_dir1(Dir, Command, Config, DirSet, CurrentCodePath,
ModuleSet, File); ModuleSet, WouldCd, File);
false -> false ->
%% not an app dir, no need to consider apps=/skip_apps= %% not an app dir, no need to consider apps=/skip_apps=
process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, process_dir1(Dir, Command, Config, DirSet, CurrentCodePath,
ModuleSet) ModuleSet, WouldCd)
end. end.
skip_or_process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, ModuleSet, skip_or_process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, ModuleSet,
AppFile) -> WouldCd, AppFile) ->
case rebar_app_utils:is_skipped_app(Config, AppFile) of case rebar_app_utils:is_skipped_app(Config, AppFile) of
{Config1, {true, _SkippedApp}} when Command == 'update-deps' -> {Config1, {true, _SkippedApp}} when Command == 'update-deps' ->
%% update-deps does its own app skipping. Unfortunately there's no %% update-deps does its own app skipping. Unfortunately there's no
@ -206,18 +208,19 @@ skip_or_process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, ModuleSet,
%% here... Otherwise if you use app=, it'll skip the toplevel %% here... Otherwise if you use app=, it'll skip the toplevel
%% directory and nothing will be updated. %% directory and nothing will be updated.
process_dir1(Dir, Command, Config1, DirSet, CurrentCodePath, process_dir1(Dir, Command, Config1, DirSet, CurrentCodePath,
ModuleSet); ModuleSet, WouldCd);
{Config1, {true, SkippedApp}} -> {Config1, {true, SkippedApp}} ->
?DEBUG("Skipping app: ~p~n", [SkippedApp]), ?DEBUG("Skipping app: ~p~n", [SkippedApp]),
{increment_operations(Config1), DirSet}; {increment_operations(Config1), DirSet};
{Config1, false} -> {Config1, false} ->
process_dir1(Dir, Command, Config1, DirSet, CurrentCodePath, process_dir1(Dir, Command, Config1, DirSet, CurrentCodePath,
ModuleSet) ModuleSet, WouldCd)
end. end.
process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, process_dir1(Dir, Command, Config, DirSet, CurrentCodePath,
{DirModules, File}) -> {DirModules, File}, WouldCd) ->
Config0 = rebar_config:set_xconf(Config, current_command, Command), Config0 = rebar_config:set_xconf(Config, current_command, Command),
%% Get the list of modules for "any dir". This is a catch-all list %% Get the list of modules for "any dir". This is a catch-all list
%% of modules that are processed in addition to modules associated %% of modules that are processed in addition to modules associated
%% with this directory type. These any_dir modules are processed %% with this directory type. These any_dir modules are processed
@ -251,38 +254,18 @@ process_dir1(Dir, Command, Config, DirSet, CurrentCodePath,
%% caused it to change %% caused it to change
ok = file:set_cwd(Dir), ok = file:set_cwd(Dir),
%% Check that this directory is not on the skip list %% Maybe apply command to Dir
Config7 = case rebar_config:is_skip_dir(Config3, Dir) of Config4 = maybe_execute(Dir, Command, Config3, Modules, PluginModules,
true -> AllModules, File, WouldCd),
%% Do not execute the command on the directory, as some
%% module has requested a skip on it.
?INFO("Skipping ~s in ~s\n", [Command, Dir]),
Config3;
false ->
%% Check for and get command specific environments
{Config4, Env} = setup_envs(Config3, Modules),
%% Execute any before_command plugins on this directory
Config5 = execute_pre(Command, PluginModules, Config4,
File, Env),
%% Execute the current command on this directory
Config6 = execute(Command, AllModules, Config5, File,
Env),
%% Execute any after_command plugins on this directory
execute_post(Command, PluginModules, Config6, File, Env)
end,
%% Mark the current directory as processed %% Mark the current directory as processed
DirSet3 = sets:add_element(Dir, DirSet2), DirSet3 = sets:add_element(Dir, DirSet2),
%% Invoke 'postprocess' on the modules. This yields a list of other %% Invoke 'postprocess' on the modules. This yields a list of other
%% directories that should be processed _after_ the current one. %% directories that should be processed _after_ the current one.
{Config8, Postdirs} = acc_modules(AllModules, postprocess, Config7, File), {Config5, Postdirs} = acc_modules(AllModules, postprocess, Config4, File),
?DEBUG("Postdirs: ~p\n", [Postdirs]), ?DEBUG("Postdirs: ~p\n", [Postdirs]),
Res = process_each(Postdirs, Command, Config8, DirSet3, File), Res = process_each(Postdirs, Command, Config5, DirSet3, File),
%% Make sure the CWD is reset properly; processing the dirs may have %% Make sure the CWD is reset properly; processing the dirs may have
%% caused it to change %% caused it to change
@ -295,6 +278,33 @@ process_dir1(Dir, Command, Config, DirSet, CurrentCodePath,
%% Return the updated {config, dirset} as result %% Return the updated {config, dirset} as result
Res. Res.
maybe_execute(Dir, Command, Config, Modules, PluginModules, AllModules, File,
would_cd) ->
%% Check that this directory is not on the skip list
case rebar_config:is_skip_dir(Config, Dir) of
true ->
%% Do not execute the command on the directory, as some
%% module has requested a skip on it.
?INFO("Skipping ~s in ~s\n", [Command, Dir]),
Config;
false ->
%% Check for and get command specific environments
{Config1, Env} = setup_envs(Config, Modules),
%% Execute any before_command plugins on this directory
Config2 = execute_pre(Command, PluginModules, Config1, File, Env),
%% Execute the current command on this directory
Config3 = execute(Command, AllModules, Config2, File, Env),
%% Execute any after_command plugins on this directory
execute_post(Command, PluginModules, Config3, File, Env)
end;
maybe_execute(_Dir, _Command, Config, _Modules, _PluginModules, _AllModules,
_File, would_not_cd) ->
Config.
remember_cwd_predirs(Cwd, Predirs) -> remember_cwd_predirs(Cwd, Predirs) ->
Store = fun(Dir, Dict) -> Store = fun(Dir, Dict) ->
case dict:find(Dir, Dict) of case dict:find(Dir, Dict) of