mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 03:00:17 +00:00
Universally support apps=/skip_apps=
This commit is contained in:
parent
a5e39c2c54
commit
8c89a388bf
7 changed files with 168 additions and 158 deletions
|
@ -11,8 +11,8 @@ _rebar()
|
||||||
cmdsnvars="check-deps clean compile create create-app create-node \
|
cmdsnvars="check-deps clean compile create create-app create-node \
|
||||||
ct doc delete-deps eunit get-deps generate generate-upgrade \
|
ct doc delete-deps eunit get-deps generate generate-upgrade \
|
||||||
help list-deps list-templates update-deps version xref overlay \
|
help list-deps list-templates update-deps version xref overlay \
|
||||||
case= force=1 jobs= suite= verbose=1 appid= previous_release= \
|
apps= case= force=1 jobs= suite= verbose=1 appid= previous_release= \
|
||||||
root_dir= skip_deps=true skip_app= template= template_dir="
|
root_dir= skip_deps=true skip_apps= template= template_dir="
|
||||||
|
|
||||||
if [[ ${cur} == --* ]] ; then
|
if [[ ${cur} == --* ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "${lopts}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${lopts}" -- ${cur}) )
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
app_name/1,
|
app_name/1,
|
||||||
app_applications/1,
|
app_applications/1,
|
||||||
app_vsn/1,
|
app_vsn/1,
|
||||||
is_skipped_app/0]).
|
is_skipped_app/1]).
|
||||||
|
|
||||||
-export([load_app_file/1]). % TEMPORARY
|
-export([load_app_file/1]). % TEMPORARY
|
||||||
|
|
||||||
|
@ -105,40 +105,26 @@ app_vsn(AppFile) ->
|
||||||
[AppFile, Reason])
|
[AppFile, Reason])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%
|
is_skipped_app(AppFile) ->
|
||||||
%% Return: true, if we are in the context of a 'Skipped App', else: false
|
ThisApp = app_name(AppFile),
|
||||||
%% (Example: rebar xref skip_app=mochiweb,webmachine)
|
%% Check for apps global parameter; this is a comma-delimited list
|
||||||
is_skipped_app() ->
|
%% of apps on which we want to run commands
|
||||||
case rebar_config:get_global(skip_app, undefined) of
|
case get_apps() of
|
||||||
undefined ->
|
undefined ->
|
||||||
%% no skip list
|
%% No apps parameter specified, check the skip_apps list..
|
||||||
|
case get_skip_apps() of
|
||||||
|
undefined ->
|
||||||
|
%% No skip_apps list, run everything..
|
||||||
false;
|
false;
|
||||||
|
|
||||||
SkipApps ->
|
SkipApps ->
|
||||||
|
TargetApps = [list_to_atom(A) ||
|
||||||
case string:tokens(SkipApps, ",") of
|
A <- string:tokens(SkipApps, ",")],
|
||||||
[] ->
|
is_skipped_app(ThisApp, TargetApps)
|
||||||
%% no tokens
|
end;
|
||||||
false;
|
Apps ->
|
||||||
|
%% run only selected apps
|
||||||
SkipAppsTokens ->
|
TargetApps = [list_to_atom(A) || A <- string:tokens(Apps, ",")],
|
||||||
|
is_selected_app(ThisApp, TargetApps)
|
||||||
%% Where we are at the moment
|
|
||||||
Cwd = rebar_utils:get_cwd(),
|
|
||||||
|
|
||||||
%% Return true if app should be skipped
|
|
||||||
SkipPred = fun(App) ->
|
|
||||||
case re:run(Cwd, App) of
|
|
||||||
{match,_} -> true;
|
|
||||||
_ -> false
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
|
|
||||||
%% Check if 'we' are among the skipped apps.
|
|
||||||
lists:foldl(fun(SkippedApp, Bool) ->
|
|
||||||
SkipPred(SkippedApp) or Bool
|
|
||||||
end, false, SkipAppsTokens)
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
@ -224,3 +210,47 @@ vcs_vsn_cmd(Version) -> {unknown, Version}.
|
||||||
vcs_vsn_invoke(Cmd, Dir) ->
|
vcs_vsn_invoke(Cmd, Dir) ->
|
||||||
{ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),
|
{ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),
|
||||||
string:strip(VsnString, right, $\n).
|
string:strip(VsnString, right, $\n).
|
||||||
|
|
||||||
|
%% apps= for selecting apps
|
||||||
|
is_selected_app(ThisApp, TargetApps) ->
|
||||||
|
case lists:member(ThisApp, TargetApps) of
|
||||||
|
false ->
|
||||||
|
{true, ThisApp};
|
||||||
|
true ->
|
||||||
|
false
|
||||||
|
end.
|
||||||
|
|
||||||
|
%% skip_apps= for filtering apps
|
||||||
|
is_skipped_app(ThisApp, TargetApps) ->
|
||||||
|
case lists:member(ThisApp, TargetApps) of
|
||||||
|
false ->
|
||||||
|
false;
|
||||||
|
true ->
|
||||||
|
{true, ThisApp}
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_apps() ->
|
||||||
|
get_global_cs_opt(app, apps).
|
||||||
|
|
||||||
|
get_skip_apps() ->
|
||||||
|
get_global_cs_opt(skip_app, skip_apps).
|
||||||
|
|
||||||
|
get_global_cs_opt(Old, New) ->
|
||||||
|
Apps = rebar_config:get_global(New, undefined),
|
||||||
|
case rebar_config:get_global(Old, undefined) of
|
||||||
|
undefined ->
|
||||||
|
case Apps of
|
||||||
|
undefined ->
|
||||||
|
undefined;
|
||||||
|
Apps ->
|
||||||
|
Apps
|
||||||
|
end;
|
||||||
|
App ->
|
||||||
|
rebar_utils:deprecated(Old, Old, New, "soon"),
|
||||||
|
case Apps of
|
||||||
|
undefined ->
|
||||||
|
App;
|
||||||
|
Apps ->
|
||||||
|
string:join([App, Apps], ",")
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
|
@ -114,9 +114,40 @@ process_dir(Dir, ParentConfig, Command, DirSet) ->
|
||||||
%% CWD to see if it's a fit -- if it is, use that set of modules
|
%% CWD to see if it's a fit -- if it is, use that set of modules
|
||||||
%% to process this dir.
|
%% to process this dir.
|
||||||
{ok, AvailModuleSets} = application:get_env(rebar, modules),
|
{ok, AvailModuleSets} = application:get_env(rebar, modules),
|
||||||
{DirModules, ModuleSetFile} = choose_module_set(AvailModuleSets,
|
ModuleSet = choose_module_set(AvailModuleSets, Dir),
|
||||||
Dir),
|
{_DirModules, ModuleSetFile} = ModuleSet,
|
||||||
|
|
||||||
|
case lists:reverse(ModuleSetFile) of
|
||||||
|
"ppa." ++ _ ->
|
||||||
|
%% .app file
|
||||||
|
maybe_process_dir0(ModuleSetFile, ModuleSet, Config,
|
||||||
|
CurrentCodePath, Dir,
|
||||||
|
Command, DirSet);
|
||||||
|
"crs.ppa." ++ _ ->
|
||||||
|
%% .app.src file
|
||||||
|
maybe_process_dir0(ModuleSetFile, ModuleSet, Config,
|
||||||
|
CurrentCodePath, Dir,
|
||||||
|
Command, DirSet);
|
||||||
|
_ ->
|
||||||
|
process_dir0(Dir, Command, DirSet, Config,
|
||||||
|
CurrentCodePath, ModuleSet)
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
maybe_process_dir0(AppFile, ModuleSet, Config, CurrentCodePath,
|
||||||
|
Dir, Command, DirSet) ->
|
||||||
|
case rebar_app_utils:is_skipped_app(AppFile) of
|
||||||
|
{true, SkippedApp} ->
|
||||||
|
?DEBUG("Skipping app: ~p~n", [SkippedApp]),
|
||||||
|
increment_operations(),
|
||||||
|
DirSet;
|
||||||
|
false ->
|
||||||
|
process_dir0(Dir, Command, DirSet, Config,
|
||||||
|
CurrentCodePath, ModuleSet)
|
||||||
|
end.
|
||||||
|
|
||||||
|
process_dir0(Dir, Command, DirSet, Config, CurrentCodePath,
|
||||||
|
{DirModules, ModuleSetFile}) ->
|
||||||
%% 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
|
||||||
|
@ -187,8 +218,7 @@ process_dir(Dir, ParentConfig, Command, DirSet) ->
|
||||||
restore_code_path(CurrentCodePath),
|
restore_code_path(CurrentCodePath),
|
||||||
|
|
||||||
%% Return the updated dirset as our result
|
%% Return the updated dirset as our result
|
||||||
DirSet4
|
DirSet4.
|
||||||
end.
|
|
||||||
|
|
||||||
maybe_load_local_config(Dir, ParentConfig) ->
|
maybe_load_local_config(Dir, ParentConfig) ->
|
||||||
%% We need to ensure we don't overwrite custom
|
%% We need to ensure we don't overwrite custom
|
||||||
|
@ -274,9 +304,7 @@ execute(Command, Modules, Config, ModuleFile) ->
|
||||||
Dir = rebar_utils:get_cwd(),
|
Dir = rebar_utils:get_cwd(),
|
||||||
?CONSOLE("==> ~s (~s)\n", [filename:basename(Dir), Command]),
|
?CONSOLE("==> ~s (~s)\n", [filename:basename(Dir), Command]),
|
||||||
|
|
||||||
%% Increment the count of operations, since some module
|
increment_operations(),
|
||||||
%% responds to this command
|
|
||||||
erlang:put(operations, erlang:get(operations) + 1),
|
|
||||||
|
|
||||||
%% Check for and get command specific environments
|
%% Check for and get command specific environments
|
||||||
Env = setup_envs(Config, Modules),
|
Env = setup_envs(Config, Modules),
|
||||||
|
@ -300,6 +328,11 @@ execute(Command, Modules, Config, ModuleFile) ->
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% Increment the count of operations, since some module
|
||||||
|
%% responds to this command
|
||||||
|
increment_operations() ->
|
||||||
|
erlang:put(operations, erlang:get(operations) + 1).
|
||||||
|
|
||||||
|
|
||||||
update_code_path(Config) ->
|
update_code_path(Config) ->
|
||||||
case rebar_config:get_local(Config, lib_dirs, []) of
|
case rebar_config:get_local(Config, lib_dirs, []) of
|
||||||
|
|
|
@ -46,20 +46,7 @@
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
ct(Config, File) ->
|
ct(Config, File) ->
|
||||||
case rebar_config:get_global(app, undefined) of
|
run_test_if_present("test", Config, File).
|
||||||
undefined ->
|
|
||||||
%% No app parameter specified, run everything..
|
|
||||||
run_test_if_present("test", Config, File);
|
|
||||||
Apps ->
|
|
||||||
TargetApps = [list_to_atom(A) || A <- string:tokens(Apps, ",")],
|
|
||||||
ThisApp = rebar_app_utils:app_name(File),
|
|
||||||
case lists:member(ThisApp, TargetApps) of
|
|
||||||
true ->
|
|
||||||
run_test_if_present("test", Config, File);
|
|
||||||
false ->
|
|
||||||
?DEBUG("Skipping common_test on app: ~p\n", [ThisApp])
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
|
|
@ -63,40 +63,7 @@
|
||||||
%% Public API
|
%% Public API
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
eunit(Config, AppFile) ->
|
eunit(Config, _AppFile) ->
|
||||||
%% Check for app global parameter; this is a comma-delimited list
|
|
||||||
%% of apps on which we want to run eunit
|
|
||||||
case rebar_config:get_global(app, undefined) of
|
|
||||||
undefined ->
|
|
||||||
%% No app parameter specified, check the skip list..
|
|
||||||
case rebar_config:get_global(skip_app, undefined) of
|
|
||||||
undefined ->
|
|
||||||
%% no skip list, run everything..
|
|
||||||
ok;
|
|
||||||
SkipApps ->
|
|
||||||
TargetApps = [list_to_atom(A) ||
|
|
||||||
A <- string:tokens(SkipApps, ",")],
|
|
||||||
ThisApp = rebar_app_utils:app_name(AppFile),
|
|
||||||
case lists:member(ThisApp, TargetApps) of
|
|
||||||
false ->
|
|
||||||
ok;
|
|
||||||
true ->
|
|
||||||
?DEBUG("Skipping eunit on app: ~p\n", [ThisApp]),
|
|
||||||
throw(ok)
|
|
||||||
end
|
|
||||||
end;
|
|
||||||
Apps ->
|
|
||||||
TargetApps = [list_to_atom(A) || A <- string:tokens(Apps, ",")],
|
|
||||||
ThisApp = rebar_app_utils:app_name(AppFile),
|
|
||||||
case lists:member(ThisApp, TargetApps) of
|
|
||||||
true ->
|
|
||||||
ok;
|
|
||||||
false ->
|
|
||||||
?DEBUG("Skipping eunit on app: ~p\n", [ThisApp]),
|
|
||||||
throw(ok)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
|
|
||||||
%% Make sure ?EUNIT_DIR/ and ebin/ directory exists (tack on dummy module)
|
%% Make sure ?EUNIT_DIR/ and ebin/ directory exists (tack on dummy module)
|
||||||
ok = filelib:ensure_dir(eunit_dir() ++ "/foo"),
|
ok = filelib:ensure_dir(eunit_dir() ++ "/foo"),
|
||||||
ok = filelib:ensure_dir(ebin_dir() ++ "/foo"),
|
ok = filelib:ensure_dir(ebin_dir() ++ "/foo"),
|
||||||
|
|
|
@ -56,7 +56,6 @@ get_cwd() ->
|
||||||
{ok, Dir} = file:get_cwd(),
|
{ok, Dir} = file:get_cwd(),
|
||||||
Dir.
|
Dir.
|
||||||
|
|
||||||
|
|
||||||
is_arch(ArchRegex) ->
|
is_arch(ArchRegex) ->
|
||||||
case re:run(get_arch(), ArchRegex, [{capture, none}]) of
|
case re:run(get_arch(), ArchRegex, [{capture, none}]) of
|
||||||
match ->
|
match ->
|
||||||
|
|
|
@ -40,17 +40,7 @@
|
||||||
%% Public API
|
%% Public API
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
xref(Config, _X) ->
|
xref(Config, _) ->
|
||||||
case rebar_app_utils:is_skipped_app() of
|
|
||||||
true -> ok;
|
|
||||||
false -> xref0(Config, _X)
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% ===================================================================
|
|
||||||
%% Internal functions
|
|
||||||
%% ===================================================================
|
|
||||||
|
|
||||||
xref0(Config, _) ->
|
|
||||||
%% Spin up xref
|
%% Spin up xref
|
||||||
{ok, _} = xref:start(xref),
|
{ok, _} = xref:start(xref),
|
||||||
ok = xref:set_library_path(xref, code_path()),
|
ok = xref:set_library_path(xref, code_path()),
|
||||||
|
@ -100,6 +90,10 @@ xref0(Config, _) ->
|
||||||
?FAIL
|
?FAIL
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% ===================================================================
|
||||||
|
%% Internal functions
|
||||||
|
%% ===================================================================
|
||||||
|
|
||||||
check_exports_not_used() ->
|
check_exports_not_used() ->
|
||||||
{ok, UnusedExports0} = xref:analyze(xref, exports_not_used),
|
{ok, UnusedExports0} = xref:analyze(xref, exports_not_used),
|
||||||
UnusedExports = filter_away_ignored(UnusedExports0),
|
UnusedExports = filter_away_ignored(UnusedExports0),
|
||||||
|
|
Loading…
Reference in a new issue