using file:script() if possible

Ulf Wiger ulf at feuerlabs.com
Fri Feb 10 09:46:31 EST 2012


Hmm, apologies, my hack actually _did_ work as intended. :)

But here is the wrapper script:

%% -*- erlang -*-
{ok, Opts} = file:consult(filename:join(filename:dirname(SCRIPT), "rebar.config")).
io:fwrite("consulted: Opts = ~p~n", [Opts]).
Opts1 = case os:getenv("REBAR_DEPS") of
	    false ->
		Opts;
	    Dir ->
		lists:keystore(deps_dir, 1, Opts, {deps_dir, Dir})
	end.
io:fwrite("Opts1 = ~p~n", [Opts1]).
Opts1.


BR,
Ulf

On 10 Feb 2012, at 15:30, Ulf Wiger wrote:

> 
> I made a little rebar hack just now that perhaps might work for some of the trickier path issues, or for local customization.
> 
> https://github.com/uwiger/rebar/blob/uw-config-script/src/rebar_config.erl#L135
> 
> The idea is to check if there is a config file in the form of a file:script/2 file, here identified with the suffix .script.
> 
> In other words, when we would consult rebar.config, we check if there is a rebar.config.script, and then read it instead, using 
> 
> file:script(Script, [{'SCRIPT', Script}])
> 
> I know one can use the -config flag and point to a different rebar.config, but if rebar is wrapped inside a make script, perhaps with fairly complicated targets, this may prove unwieldy.
> 
> This way, I can throw in a wrapper, which amends the rebar.config in some way, still being able to use the make script and not having to mess up the git merges by hacking a version-controlled file.
> 
> An example, which didn't pan out, but which can serve to illustrate the concept:
> 
> rebar.config.script:
> %% -*- erlang -*-
> {ok, Opts} = file:consult(filename:join(filename:dirname(SCRIPT), "rebar.config")).
> io:fwrite("consulted: Opts = ~p~n", [Opts]).
> Opts1 = case os:getenv("REBAR_DEPS") of
> 	    false ->
> 		Opts;
> 	    Deps ->
> 		DepsL = re:split(Deps, ":", [{return, list}]),
> 		case proplists:get_value(deps_dir, Opts) of
> 		    undefined ->
> 			[{deps_dir, DepsL}|Opts];
> 		    OtherDeps ->
> 			lists:keyreplace(deps_dir, 1, Opts, {deps_dir, OtherDeps ++ DepsL})
> 		end
> 	end.
> io:fwrite("Opts1 = ~p~n", [Opts1]).
> Opts1.
> 
> In this particular case, the wanted result didn't happen, and I decided to rely on ERL_LIBS instead.
> 
> Still, I thought I'd push the change, in case others might find it useful.
> 
> BR,
> Ulf W
> _______________________________________________
> rebar mailing list
> rebar at lists.basho.com
> http://lists.basho.com/mailman/listinfo/rebar_lists.basho.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/rebar_lists.basho.com/attachments/20120210/5e41957f/attachment.html>


More information about the rebar mailing list