Skip to content

Commit

Permalink
arg0 trick for rebar invocation doesn't work, replacing it with a hid…
Browse files Browse the repository at this point in the history
…den "rebar" command
  • Loading branch information
yrashk committed Feb 24, 2011
1 parent e76b1f2 commit b7e0b47
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -17,6 +17,7 @@ build-plt:

compile: deps
@./rebar compile
@cp deps/*/ebin/* ebin/
@./rebar escriptize

install:
Expand Down
Binary file modified rebar
Binary file not shown.
40 changes: 11 additions & 29 deletions src/agner_fetch.erl
Expand Up @@ -452,38 +452,20 @@ build_dep(ReqName, ReqVersion, #opts_rec{ spec = {spec, Spec}, directory = Direc
{directory, filename:join(deps_dir(Spec, Directory),ReqName)}|
proplists:delete(spec,rec_to_opts(Opts))]).

rebar(#opts_rec{ spec = {spec, Spec}, quiet = Quiet, directory = Directory }) ->
rebar(#opts_rec{ spec = {spec, Spec} } = Opts) ->
case proplists:get_value(rebar_compatible, Spec) of
true ->
io:format("[Building...]~n"),
RebarCommands = proplists:get_value(rebar_commands, Spec),

Port = open_port({spawn_executable,escript:script_name()},[{cd, Directory},{arg0, filename:join(filename:dirname(escript:script_name()), "rebar")}, {args, RebarCommands}, exit_status,stderr_to_stdout,use_stdio, stream]),
unlink(Port),
PortHandler = fun (F) ->
receive
{'EXIT', Port, normal} ->
ok;
{'EXIT', Port, _} ->
error;
{Port,{exit_status,0}} ->
ok;
{Port,{exit_status,_}} ->
error;
{Port, {data, D}} when not Quiet andalso is_list(D) ->
io:format("~s",[D]),
F(F);
_ ->
F(F)
end
end,
Result = PortHandler(PortHandler),
receive
{'EXIT', Port, normal} -> %% flush port exit
ok
after 0 ->
ok
end,
ScriptName = filename:absname(escript:script_name()),

Spec1 =
case filename:basename(ScriptName) of
"agner" ->
[{build_command, ScriptName ++ " rebar " ++ string:join(RebarCommands," ")}|Spec];
"rebar" ->
[{build_command, ScriptName ++ " " ++ string:join(RebarCommands," ")}|Spec]
end,
Result = build_command(Opts#opts_rec{ spec = {spec, Spec1} }),
Result;
_ ->
ignore
Expand Down
6 changes: 5 additions & 1 deletion src/agner_main.erl
Expand Up @@ -128,7 +128,7 @@ arg_proplist() ->
[
{variable, undefined, undefined, string, "Variable name, omit to list all of them"}
]}}].


command_descriptions() ->
[{Cmd, Desc} || {Cmd, {_Atom, Desc, _Opts}} <- arg_proplist()].
Expand All @@ -150,6 +150,9 @@ usage() ->
io:format("Valid commands are:~n", []),
[io:format(" ~-10s ~s~n", [Cmd, Desc]) || {Cmd, Desc} <- command_descriptions()].

main(["rebar"|Args]) ->
rebar:main(Args);

main(Args) ->
os:putenv("AGNER", filename:absname(escript:script_name())),
case parse_args(Args) of
Expand Down Expand Up @@ -418,6 +421,7 @@ handle_command(config, [{variable, "prefix"}]) ->
io:format("~s~n",[os:getenv("AGNER_PREFIX")]);
handle_command(config, [{variable, "bin"}]) ->
io:format("~s~n",[os:getenv("AGNER_BIN")]).


%%%

Expand Down

0 comments on commit b7e0b47

Please sign in to comment.