Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Publish issued, current and remaining commands in config #143

Closed
wants to merge 1 commit into from

3 participants

@hyperthunk

This patch adds the original, current and remaining commands to global config.
This information is useful to plugin authors who wish to know how rebar was
originally invoked, and how far along the build pipeline has progressed.

@hyperthunk hyperthunk Publish issued, current and remaining commands in config
This patch adds the original, current and remaining commands to global config.
This information is useful to plugin authors who wish to know how rebar was
originally invoked, and how far along the build pipeline has progressed.
3aef896
@hyperthunk

I use this in the rebar_alien_plugin to determine during the preprocess/2 call whether or not a clean operation is pending. I also use it in the rebar_paths_plugin where it allows me to dynamically check the current command against the plugin's configuration, rather than having to hook pre_this and pre_that for every potential command including future one's I don't know about. E.g.,

{path_opts, [

    %% prepend the list of dirs when the compile command is running
    %% NB: the code path is restored immediately after the compile command finishes
    {compile, [{prepend, ["/tmp/foo/ebin"]}]},

    %% append the list of dirs when the xref command runs
    {xref, [
        {append, ["../ebin"]}
    ]}

]}.
{plugins, [rebar_paths_plugin]}.

Having this feature makes the lookup implementation as simple as lists:keyfind(rebar_utils:command_info(current), 1, Opts), which I think proves this is a valuable hook for plugin authors.

@dizzyd

IMO, this shouldn't use rebar global, but should just set values in the process dictionary. I'm OK with the patch, otherwise.

@hyperthunk

Ok I'll replace with the process dict and resubmit. Cheers!

@hyperthunk

In light of the work in ta-state, I'm happy to close this now. Perhaps the context data that gets passed around (in ta-state) could incorporate this information now instead?

@dizzyd dizzyd closed this
@tuncer tuncer was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 6, 2011
  1. @hyperthunk

    Publish issued, current and remaining commands in config

    hyperthunk authored
    This patch adds the original, current and remaining commands to global config.
    This information is useful to plugin authors who wish to know how rebar was
    originally invoked, and how far along the build pipeline has progressed.
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 1 deletion.
  1. +3 −0  src/rebar.erl
  2. +6 −0 src/rebar_core.erl
  3. +13 −1 src/rebar_utils.erl
View
3  src/rebar.erl
@@ -110,6 +110,9 @@ run_aux(Commands) ->
end,
BaseConfig = rebar_config:base_config(GlobalConfig),
+ %% Publish the originally given commands
+ rebar_config:set_global(issued_commands, CommandAtoms),
+
%% Process each command, resetting any state between each one
rebar_core:process_commands(CommandAtoms, BaseConfig).
View
6 src/rebar_core.erl
@@ -76,6 +76,10 @@ process_commands([Command | Rest], ParentConfig) ->
lists:foreach(fun (D) -> erlang:erase({skip_dir, D}) end, skip_dirs()),
Operations = erlang:get(operations),
+ %% Publish the current command and remaining pipeline in our config
+ rebar_config:set_global(current_command, Command),
+ rebar_config:set_global(remaining_commands, Rest),
+
%% Convert the code path so that all the entries are absolute paths.
%% If not, code:set_path() may choke on invalid relative paths when trying
%% to restore the code path from inside a subdirectory.
@@ -90,6 +94,8 @@ process_commands([Command | Rest], ParentConfig) ->
_ ->
ok
end,
+ PreviousCommands = rebar_config:get_global(previous_commands, []),
+ rebar_config:set_global(previous_commands, [Command|PreviousCommands]),
process_commands(Rest, ParentConfig).
View
14 src/rebar_utils.erl
@@ -26,7 +26,8 @@
%% -------------------------------------------------------------------
-module(rebar_utils).
--export([get_cwd/0,
+-export([command_info/1,
+ get_cwd/0,
is_arch/1,
get_arch/0,
wordsize/0,
@@ -51,6 +52,17 @@
%% Public API
%% ====================================================================
+command_info(current) ->
+ rebar_config:get_global(current_command, undefined);
+command_info(remaining) ->
+ rebar_config:get_global(remaining_commands, undefined);
+command_info(previous) ->
+ rebar_config:get_global(previous_commands, undefined);
+command_info(issued) ->
+ rebar_config:get_global(issued_commands, undefined);
+command_info(_) ->
+ undefined.
+
get_cwd() ->
{ok, Dir} = file:get_cwd(),
Dir.
Something went wrong with that request. Please try again.