瀏覽代碼

Merge pull request #353 from tsloughter/dup_hooks

don't duplicate hooks for top level app
pull/357/head
Fred Hebert 10 年之前
父節點
當前提交
71dfa8eca6
共有 3 個文件被更改,包括 30 次插入10 次删除
  1. +24
    -2
      src/rebar_app_discover.erl
  2. +2
    -1
      src/rebar_dir.erl
  3. +4
    -7
      src/rebar_prv_compile.erl

+ 24
- 2
src/rebar_app_discover.erl 查看文件

@ -37,12 +37,13 @@ merge_deps(AppInfo, State) ->
Default = rebar_state:default(State),
CurrentProfiles = rebar_state:current_profiles(State),
Name = rebar_app_info:name(AppInfo),
C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
C = project_app_config(AppInfo, State),
%% We reset the opts here to default so no profiles are applied multiple times
AppState = rebar_state:apply_overrides(
rebar_state:apply_profiles(
rebar_state:new(rebar_state:opts(State, Default), C, rebar_app_info:dir(AppInfo)), CurrentProfiles), Name),
rebar_state:new(reset_hooks(rebar_state:opts(State, Default)), C,
rebar_app_info:dir(AppInfo)), CurrentProfiles), Name),
AppInfo1 = rebar_app_info:state(AppInfo, AppState),
State1 = lists:foldl(fun(Profile, StateAcc) ->
@ -56,6 +57,27 @@ merge_deps(AppInfo, State) ->
{AppInfo1, State1}.
project_app_config(AppInfo, State) ->
C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
Dir = rebar_app_info:dir(AppInfo),
maybe_reset_hooks(C, Dir, State).
%% Here we check if the app is at the root of the project.
%% If it is, then drop the hooks from the config so they aren't run twice
maybe_reset_hooks(C, Dir, State) ->
case filename:dirname(rebar_dir:root_dir(State)) of
Dir ->
C1 = proplists:delete(provider_hooks, C),
proplists:delete(hooks, C1);
_ ->
C
end.
reset_hooks(State) ->
lists:foldl(fun(Key, StateAcc) ->
rebar_state:set(StateAcc, Key, [])
end, State, [post_hooks, pre_hooks, provider_hooks]).
-spec all_app_dirs(list(file:name())) -> list(file:name()).
all_app_dirs(LibDirs) ->
lists:flatmap(fun(LibDir) ->

+ 2
- 1
src/rebar_dir.erl 查看文件

@ -4,6 +4,7 @@
profile_dir/2,
deps_dir/1,
deps_dir/2,
root_dir/1,
checkouts_dir/1,
checkouts_dir/2,
plugins_dir/1,
@ -48,7 +49,7 @@ deps_dir(DepsDir, App) ->
filename:join(DepsDir, App).
root_dir(State) ->
rebar_state:get(State, root_dir, ?DEFAULT_ROOT_DIR).
filename:absname(rebar_state:get(State, root_dir, ?DEFAULT_ROOT_DIR)).
-spec checkouts_dir(rebar_state:t()) -> file:filename_all().
checkouts_dir(State) ->

+ 4
- 7
src/rebar_prv_compile.erl 查看文件

@ -43,17 +43,14 @@ do(State) ->
EmptyState = rebar_state:new(),
build_apps(EmptyState, Providers, Deps),
%% Use the project State for building project apps
%% Set hooks to empty so top-level hooks aren't run for each project app
State2 = rebar_state:set(rebar_state:set(State, post_hooks, []), pre_hooks, []),
{ok, ProjectApps1} = rebar_digraph:compile_order(ProjectApps),
ProjectApps2 = build_apps(State2, Providers, ProjectApps1),
State3 = rebar_state:project_apps(State2, ProjectApps2),
ProjectApps2 = build_apps(State, Providers, ProjectApps1),
State2 = rebar_state:project_apps(State, ProjectApps2),
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State3),
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State2),
{ok, State3}.
{ok, State2}.
-spec format_error(any()) -> iolist().
format_error(Reason) ->

Loading…
取消
儲存