Переглянути джерело

more cleanup

pull/760/head
Tristan Sloughter 9 роки тому
джерело
коміт
e6f6ccc757
8 змінених файлів з 45 додано та 62 видалено
  1. +11
    -11
      src/rebar_app_discover.erl
  2. +0
    -1
      src/rebar_hooks.erl
  3. +2
    -7
      src/rebar_prv_clean.erl
  4. +0
    -9
      src/rebar_prv_compile.erl
  5. +6
    -5
      src/rebar_prv_install_deps.erl
  6. +3
    -2
      src/rebar_prv_plugins_upgrade.erl
  7. +3
    -13
      src/rebar_state.erl
  8. +20
    -14
      src/rebar_utils.erl

+ 11
- 11
src/rebar_app_discover.erl Переглянути файл

@ -26,7 +26,7 @@ do(State, LibDirs) ->
%% Handle top level deps
State1 = lists:foldl(fun(Profile, StateAcc) ->
ProfileDeps = rebar_state:get(StateAcc, {deps, Profile}, []),
ProfileDeps2 = rebar_utils:tup_dedup(rebar_utils:tup_sort(ProfileDeps)),
ProfileDeps2 = rebar_utils:tup_dedup(ProfileDeps),
StateAcc1 = rebar_state:set(StateAcc, {deps, Profile}, ProfileDeps2),
ParsedDeps = parse_profile_deps(Profile
,TopLevelApp
@ -73,7 +73,7 @@ format_error({missing_module, Module}) ->
io_lib:format("Module defined in app file missing: ~p~n", [Module]).
merge_deps(AppInfo, State) ->
Default = rebar_state:default(State),
Default = reset_hooks(rebar_state:default(State)),
C = project_app_config(AppInfo, State),
AppInfo0 = rebar_app_info:update_opts(AppInfo, Default, C),
@ -97,10 +97,9 @@ handle_profile(Profile, Name, AppInfo, State) ->
TopParsedDeps = rebar_state:get(State, {parsed_deps, Profile}, {[], []}),
TopLevelProfileDeps = rebar_state:get(State, {deps, Profile}, []),
AppProfileDeps = rebar_app_info:get(AppInfo, {deps, Profile}, []),
AppProfileDeps2 = rebar_utils:tup_dedup(rebar_utils:tup_sort(AppProfileDeps)),
ProfileDeps2 = rebar_utils:tup_dedup(rebar_utils:tup_umerge(
rebar_utils:tup_sort(TopLevelProfileDeps)
,rebar_utils:tup_sort(AppProfileDeps2))),
AppProfileDeps2 = rebar_utils:tup_dedup(AppProfileDeps),
ProfileDeps2 = rebar_utils:tup_dedup(rebar_utils:tup_umerge(TopLevelProfileDeps
,AppProfileDeps2)),
State1 = rebar_state:set(State, {deps, Profile}, ProfileDeps2),
%% Only deps not also specified in the top level config need
@ -131,15 +130,16 @@ maybe_reset_hooks(C, Dir, State) ->
case ec_file:real_dir_path(rebar_dir:root_dir(State)) of
Dir ->
C1 = proplists:delete(provider_hooks, C),
proplists:delete(post_hooks, proplists:delete(pre_hooks, C1));
C2 = proplists:delete(artifacts, C1),
proplists:delete(post_hooks, proplists:delete(pre_hooks, C2));
_ ->
C
end.
%% reset_hooks(Opts) ->
%% lists:foldl(fun(Key, OptsAcc) ->
%% rebar_utils:set(OptsAcc, Key, [])
%% end, Opts, [post_hooks, pre_hooks, provider_hooks]).
reset_hooks(Opts) ->
lists:foldl(fun(Key, OptsAcc) ->
rebar_utils:set(OptsAcc, Key, [])
end, Opts, [post_hooks, pre_hooks, provider_hooks, artifacts]).
-spec all_app_dirs(list(file:name())) -> list(file:name()).
all_app_dirs(LibDirs) ->

+ 0
- 1
src/rebar_hooks.erl Переглянути файл

@ -35,7 +35,6 @@ run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) ->
Providers1 = rebar_state:providers(State),
State1 = rebar_state:providers(rebar_state:dir(State, Dir), Providers++Providers1),
HookProviders = proplists:get_all_values(Command, TypeHooks),
case rebar_core:do(HookProviders, State1) of
{error, ProviderName} ->
?DEBUG(format_error({bad_provider, Type, Command, ProviderName}), []),

+ 2
- 7
src/rebar_prv_clean.erl Переглянути файл

@ -44,10 +44,7 @@ do(State) ->
DepApps = []
end,
%% Need to allow global config vars used on deps
%% Right now no way to differeniate and just give deps a new state
EmptyState = rebar_state:new(),
clean_apps(EmptyState, Providers, DepApps),
clean_apps(State, Providers, DepApps),
Cwd = rebar_dir:get_cwd(),
rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State),
@ -66,10 +63,8 @@ format_error(Reason) ->
clean_apps(State, Providers, Apps) ->
lists:foreach(fun(AppInfo) ->
AppDir = rebar_app_info:dir(AppInfo),
%S = rebar_app_info:state_or_new(State, AppInfo),
?INFO("Cleaning out ~s...", [rebar_app_info:name(AppInfo)]),
AppDir = rebar_app_info:dir(AppInfo),
rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, AppInfo, State),
rebar_erlc_compiler:clean(State, rebar_app_info:out_dir(AppInfo)),
rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, AppInfo, State)

+ 0
- 9
src/rebar_prv_compile.erl Переглянути файл

@ -42,12 +42,6 @@ do(State) ->
Deps = rebar_state:deps_to_build(State),
Cwd = rebar_state:dir(State),
%% Need to allow global config vars used on deps.
%% Right now no way to differeniate and just give deps a new state.
%% But need an account of "all deps" for some hooks to use.
%% EmptyState = rebar_state:new(),
%% build_apps(rebar_state:all_deps(EmptyState,
%% rebar_state:all_deps(State)), Providers, Deps),
build_apps(State, Providers, Deps),
{ok, ProjectApps1} = rebar_digraph:compile_order(ProjectApps),
@ -85,9 +79,6 @@ build_app(State, Providers, AppInfo) ->
AppDir = rebar_app_info:dir(AppInfo),
OutDir = rebar_app_info:out_dir(AppInfo),
copy_app_dirs(AppInfo, AppDir, OutDir),
%S = rebar_app_info:state_or_new(State, AppInfo),
%S1 = rebar_state:all_deps(State, rebar_state:all_deps(State)),
compile(State, Providers, AppInfo).
compile(State, Providers, AppInfo) ->

+ 6
- 5
src/rebar_prv_install_deps.erl Переглянути файл

@ -254,9 +254,11 @@ handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) ->
Profiles = rebar_state:current_profiles(State),
Name = rebar_app_info:name(AppInfo),
C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
AppInfo0 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C),
AppInfo1 = rebar_app_info:apply_overrides(rebar_app_info:get(AppInfo, overrides, []), AppInfo0),
AppInfo2 = rebar_app_info:apply_profiles(AppInfo1, Profiles),
Plugins = rebar_app_info:get(AppInfo2, plugins, []),
AppInfo3 = rebar_app_info:set(AppInfo2, {plugins, Profile}, Plugins),
@ -265,16 +267,15 @@ handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) ->
%% Dep may have plugins to install. Find and install here.
State1 = rebar_plugins:install(State, AppInfo3),
%% TODO: Plugin Providers??
%AppInfo1 = rebar_app_info:state(AppInfo, S5),
%AppInfo2 = rebar_app_info:opts(AppInfo1, rebar_state:opts(S5)),
%% Upgrade lock level to be the level the dep will have in this dep tree
Deps = rebar_app_info:get(AppInfo3, {deps, default}, []),
AppInfo4 = rebar_app_info:deps(AppInfo3, rebar_state:deps_names(Deps)),
%% Keep all overrides from the global config and this dep when parsing its deps
Overrides = rebar_state:overrides(State) ++ rebar_app_info:get(AppInfo0, overrides, []),
Deps1 = rebar_app_utils:parse_deps(Name, DepsDir, Deps, rebar_state:overrides(State, Overrides), Locks, Level+1),
Deps1 = rebar_app_utils:parse_deps(Name, DepsDir, Deps, rebar_state:overrides(State, Overrides)
,Locks, Level+1),
{AppInfo4, Deps1, State1}.
-spec maybe_fetch(rebar_app_info:t(), atom(), boolean(),

+ 3
- 2
src/rebar_prv_plugins_upgrade.erl Переглянути файл

@ -91,5 +91,6 @@ build_plugin(AppInfo, Apps, State) ->
Providers = rebar_state:providers(State),
AppDir = rebar_app_info:dir(AppInfo),
C = rebar_config:consult(AppDir),
S = rebar_state:new(rebar_state:all_deps(rebar_state:new(), Apps), C, AppInfo),
rebar_prv_compile:compile(S, Providers, AppInfo).
S = rebar_state:new(rebar_state:all_deps(rebar_state:new(), Apps), C, AppDir),
AppInfo1 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C),
rebar_prv_compile:compile(S, Providers, AppInfo1).

+ 3
- 13
src/rebar_state.erl Переглянути файл

@ -97,19 +97,9 @@ new(ParentState=#state_t{}, Config) ->
Dir = rebar_dir:get_cwd(),
new(ParentState, Config, Dir).
-spec new(t(), list(), rebar_app_info:t() | file:filename_all()) -> t().
new(ParentState, Config, Dir) when is_list(Dir) ->
new(ParentState, Config, deps_from_config(Dir, Config), Dir);
new(ParentState, Config, AppInfo) ->
Dir = rebar_app_info:dir(AppInfo),
DepLocks = case rebar_app_info:resource_type(AppInfo) of
pkg ->
Deps = rebar_app_info:deps(AppInfo),
[{{locks, default}, Deps}, {{deps, default}, Deps}];
_ ->
deps_from_config(Dir, Config)
end,
new(ParentState, Config, DepLocks, Dir).
-spec new(t(), list(), file:filename_all()) -> t().
new(ParentState, Config, Dir) ->
new(ParentState, Config, deps_from_config(Dir, Config), Dir).
new(ParentState, Config, Deps, Dir) ->
Opts = ParentState#state_t.opts,

+ 20
- 14
src/rebar_utils.erl Переглянути файл

@ -269,20 +269,23 @@ deps_to_binary([{Name, Source} | T]) ->
deps_to_binary([Name | T]) ->
[ec_cnv:to_binary(Name) | deps_to_binary(T)].
tup_dedup([]) ->
tup_dedup(List) ->
tup_dedup_(tup_sort(List)).
tup_dedup_([]) ->
[];
tup_dedup([A]) ->
tup_dedup_([A]) ->
[A];
tup_dedup([A,B|T]) when element(1, A) =:= element(1, B) ->
tup_dedup([A | T]);
tup_dedup([A,B|T]) when element(1, A) =:= B ->
tup_dedup([A | T]);
tup_dedup([A,B|T]) when A =:= element(1, B) ->
tup_dedup([A | T]);
tup_dedup([A,A|T]) ->
[A|tup_dedup(T)];
tup_dedup([A|T]) ->
[A|tup_dedup(T)].
tup_dedup_([A,B|T]) when element(1, A) =:= element(1, B) ->
tup_dedup_([A | T]);
tup_dedup_([A,B|T]) when element(1, A) =:= B ->
tup_dedup_([A | T]);
tup_dedup_([A,B|T]) when A =:= element(1, B) ->
tup_dedup_([A | T]);
tup_dedup_([A,A|T]) ->
[A|tup_dedup_(T)];
tup_dedup_([A|T]) ->
[A|tup_dedup_(T)].
%% Sort the list in proplist-order, meaning that `{a,b}' and `{a,c}'
%% both compare as usual, and `a' and `b' do the same, but `a' and `{a,b}' will
@ -311,9 +314,12 @@ tup_sort(List) ->
%%
%% This lets us apply proper overrides to list of elements according to profile
%% priority. This function depends on a stable proplist sort.
tup_umerge([], Olds) ->
tup_umerge(NewList, OldList) ->
tup_umerge_(tup_sort(NewList), tup_sort(OldList)).
tup_umerge_([], Olds) ->
Olds;
tup_umerge([New|News], Olds) ->
tup_umerge_([New|News], Olds) ->
lists:reverse(umerge(News, Olds, [], New)).
tup_find(_Elem, []) ->

Завантаження…
Відмінити
Зберегти