summaryrefslogtreecommitdiff
path: root/src/rebar_core.erl
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2012-02-07 20:15:58 +0100
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2012-04-16 23:17:24 +0200
commit7c418ed2b4a4316e4a784b83c2ffbdc1adf33dbe (patch)
tree3ded7f0217ef75eedffd6685fe0f27b48a2fb9ec /src/rebar_core.erl
parent2ae73cc2d3c4650a0e542d3e111159183926e10e (diff)
Add support for target-specific port options
{port_specs, [{".*", "priv/foo.so", ["c_src/foo.c"], [{env, []}]}]}.
Diffstat (limited to 'src/rebar_core.erl')
-rw-r--r--src/rebar_core.erl78
1 files changed, 44 insertions, 34 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 0f098af..484b446 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -168,7 +168,7 @@ maybe_process_dir0(AppFile, ModuleSet, Config, CurrentCodePath,
CurrentCodePath, ModuleSet)
end.
-process_dir0(Dir, Command, DirSet, Config, CurrentCodePath,
+process_dir0(Dir, Command, DirSet, Config0, CurrentCodePath,
{DirModules, ModuleSetFile}) ->
%% Get the list of modules for "any dir". This is a catch-all list
%% of modules that are processed in addition to modules associated
@@ -180,21 +180,21 @@ process_dir0(Dir, Command, DirSet, Config, CurrentCodePath,
%% Invoke 'preprocess' on the modules -- this yields a list of other
%% directories that should be processed _before_ the current one.
- Predirs = acc_modules(Modules, preprocess, Config, ModuleSetFile),
+ Predirs = acc_modules(Modules, preprocess, Config0, ModuleSetFile),
SubdirAssoc = remember_cwd_subdir(Dir, Predirs),
%% Get the list of plug-in modules from rebar.config. These
%% modules may participate in preprocess and postprocess.
- {ok, PluginModules} = plugin_modules(Config, SubdirAssoc),
+ {ok, PluginModules} = plugin_modules(Config0, SubdirAssoc),
PluginPredirs = acc_modules(PluginModules, preprocess,
- Config, ModuleSetFile),
+ Config0, ModuleSetFile),
AllPredirs = Predirs ++ PluginPredirs,
?DEBUG("Predirs: ~p\n", [AllPredirs]),
- DirSet2 = process_each(AllPredirs, Command, Config,
+ DirSet2 = process_each(AllPredirs, Command, Config0,
ModuleSetFile, DirSet),
%% Make sure the CWD is reset properly; processing the dirs may have
@@ -202,25 +202,31 @@ process_dir0(Dir, Command, DirSet, Config, CurrentCodePath,
ok = file:set_cwd(Dir),
%% Check that this directory is not on the skip list
- case is_skip_dir(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 = case is_skip_dir(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]),
+ Config0;
- false ->
- %% Execute any before_command plugins on this directory
- execute_pre(Command, PluginModules,
- Config, ModuleSetFile),
+ false ->
+ %% Check for and get command specific environments
+ {Config1, Env} = setup_envs(Config0, Modules),
- %% Execute the current command on this directory
- execute(Command, Modules ++ PluginModules,
- Config, ModuleSetFile),
+ %% Execute any before_command plugins on this directory
+ execute_pre(Command, PluginModules,
+ Config1, ModuleSetFile, Env),
- %% Execute any after_command plugins on this directory
- execute_post(Command, PluginModules,
- Config, ModuleSetFile)
- end,
+ %% Execute the current command on this directory
+ execute(Command, Modules ++ PluginModules,
+ Config1, ModuleSetFile, Env),
+
+ %% Execute any after_command plugins on this directory
+ execute_post(Command, PluginModules,
+ Config1, ModuleSetFile, Env),
+
+ Config1
+ end,
%% Mark the current directory as processed
DirSet3 = sets:add_element(Dir, DirSet2),
@@ -311,22 +317,22 @@ is_dir_type(rel_dir, Dir) ->
is_dir_type(_, _) ->
false.
-execute_pre(Command, Modules, Config, ModuleFile) ->
+execute_pre(Command, Modules, Config, ModuleFile, Env) ->
execute_plugin_hook("pre_", Command, Modules,
- Config, ModuleFile).
+ Config, ModuleFile, Env).
-execute_post(Command, Modules, Config, ModuleFile) ->
+execute_post(Command, Modules, Config, ModuleFile, Env) ->
execute_plugin_hook("post_", Command, Modules,
- Config, ModuleFile).
+ Config, ModuleFile, Env).
-execute_plugin_hook(Hook, Command, Modules, Config, ModuleFile) ->
+execute_plugin_hook(Hook, Command, Modules, Config, ModuleFile, Env) ->
HookFunction = list_to_atom(Hook ++ atom_to_list(Command)),
- execute(HookFunction, Modules, Config, ModuleFile).
+ execute(HookFunction, Modules, Config, ModuleFile, Env).
%%
%% Execute a command across all applicable modules
%%
-execute(Command, Modules, Config, ModuleFile) ->
+execute(Command, Modules, Config, ModuleFile, Env) ->
case select_modules(Modules, Command, []) of
[] ->
Cmd = atom_to_list(Command),
@@ -346,9 +352,6 @@ execute(Command, Modules, Config, ModuleFile) ->
increment_operations(),
- %% Check for and get command specific environments
- Env = setup_envs(Config, Modules),
-
%% Run the available modules
apply_hooks(pre_hooks, Config, Command, Env),
case catch(run_modules(TargetModules, Command,
@@ -443,9 +446,16 @@ apply_hook({Env, {Command, Hook}}) ->
rebar_utils:sh(Hook, [{env, Env}, {abort_on_error, Msg}]).
setup_envs(Config, Modules) ->
- lists:flatten([M:setup_env(Config) ||
- M <- Modules,
- erlang:function_exported(M, setup_env, 1)]).
+ lists:foldl(fun(M, {C,E}=T) ->
+ case erlang:function_exported(M, setup_env, 1) of
+ true ->
+ Env = M:setup_env(C),
+ C1 = rebar_config:set_env(C, M, Env),
+ {C1, E++Env};
+ false ->
+ T
+ end
+ end, {Config, []}, Modules).
acc_modules(Modules, Command, Config, File) ->
acc_modules(select_modules(Modules, Command, []),