Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Extracted rebar/custom dependency management commands to the fetching…

… step
  • Loading branch information...
commit 6e260291dd62875ce6f9bc6a64b653a9fa9b42a7 1 parent a96284a
@yrashk yrashk authored
View
4 include/agner_spec.hrl
@@ -27,7 +27,9 @@
-type agner_spec_property_authors() :: {authors, list(string())}.
-type agner_spec_property_homepage() :: {homepage, string()}.
-type agner_spec_property_rebar_compatible() :: {rebar_compatible, boolean()}.
+-type agner_spec_property_rebar_fetch_deps_commands() :: {rebar_commands, list(string())}.
-type agner_spec_property_rebar_commands() :: {rebar_commands, list(string())}.
+-type agner_spec_property_fetch_deps_command() :: {fetch_deps_command, string()}.
-type agner_spec_property_build_command() :: {build_command, string()}.
-type agner_spec_property_install_command() :: {install_command, string()}.
-type agner_spec_property_install_dirs() :: {install_dirs, list(agner_install_dir())}.
@@ -49,7 +51,9 @@
agner_spec_property_authors() |
agner_spec_property_homepage() |
agner_spec_property_rebar_compatible() |
+ agner_spec_property_rebar_fetch_deps_commands() |
agner_spec_property_rebar_commands() |
+ agner_spec_property_fetch_deps_command() |
agner_spec_property_build_command() |
agner_spec_property_install_command() |
agner_spec_property_bin_files() |
View
BIN  rebar
Binary file not shown
View
57 src/agner_fetch.erl
@@ -30,7 +30,7 @@
-record(state, {
opts = #opts_rec{},
repo_dir,
- fetched_steps = [check_requirements, fetch_requirements, caveats],
+ fetched_steps = [check_requirements, fetch_requirements, fetch_deps, caveats],
build_steps = [rebar, build_command, add_path],
install_steps = [install_dirs, install_command, print_prefix]
}).
@@ -229,6 +229,12 @@ fetched(fetch_requirements, #state{ opts = #opts_rec{ spec = {spec, Spec} } = Op
os:putenv("__AGNER_DEP_DIRECTORY", ""),
{next_state, fetched, State};
+fetched(fetch_deps, #state{ opts = #opts_rec{ spec = {spec, Spec} } = Opts } = State) ->
+ RebarCommands = proplists:get_value(rebar_fetch_deps_commands, Spec),
+ rebar(RebarCommands, Opts),
+ fetch_deps_command(Opts),
+ {next_state, fetched, State};
+
fetched(caveats, #state{ opts = #opts_rec{spec = {spec, Spec} }} = State) ->
case proplists:get_value(caveats, Spec) of
undefined ->
@@ -248,8 +254,10 @@ buildable(next, State) ->
buildable(_, #state{ opts = #opts_rec{ build = false }} = State) ->
{next_state, buildable, State};
-buildable(rebar, #state{ opts = #opts_rec{ build = true } = Opts} = State) ->
- rebar(Opts),
+buildable(rebar, #state{ opts = #opts_rec{ build = true, spec = {spec, Spec} } = Opts } = State) ->
+ io:format("[Building...]~n"),
+ RebarCommands = proplists:get_value(rebar_commands, Spec),
+ rebar(RebarCommands, Opts),
{next_state, buildable, State};
buildable(build_command, #state{ opts = #opts_rec{ build = true } = Opts, repo_dir = RepoDir} = State) ->
@@ -463,10 +471,9 @@ build_dep(ReqName, ReqVersion, #opts_rec{ spec = {spec, Spec}, directory = Direc
agner_main:handle_command(fetch, [{package, ReqName},{version, ReqVersion},
{directory, filename:join(deps_dir(Spec, Directory),ReqName)}|
proplists:delete(spec,rec_to_opts(Opts))]).
-rebar(#opts_rec{ spec = {spec, Spec} } = Opts) ->
+rebar(RebarCommands, #opts_rec{ spec = {spec, Spec} } = Opts) ->
case proplists:get_value(rebar_compatible, Spec) of
true ->
- RebarCommands = proplists:get_value(rebar_commands, Spec),
ScriptName = filename:absname(escript:script_name()),
Spec1 =
@@ -482,6 +489,45 @@ rebar(#opts_rec{ spec = {spec, Spec} } = Opts) ->
ignore
end.
+fetch_deps_command(#opts_rec{ spec = {spec, Spec}, directory = Directory, quiet = Quiet, package = Package, version = Version } = Opts) ->
+ os:putenv("AGNER_PACKAGE_NAME", Package),
+ os:putenv("AGNER_PACKAGE_VERSION", Version),
+
+ case proplists:get_value(fetch_deps_command, Spec) of
+ undefined ->
+ ignore;
+ Command ->
+ set_install_prefix(Opts),
+ io:format("[Fetching dependencies...]~n"),
+ Port = open_port({spawn,"sh -c \"" ++ Command ++ "\""},[{cd, Directory},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,
+ Result
+ end.
+
build_command(#opts_rec{ spec = {spec, Spec}, directory = Directory, quiet = Quiet, package = Package, version = Version } = Opts) ->
os:putenv("AGNER_PACKAGE_NAME", Package),
os:putenv("AGNER_PACKAGE_VERSION", Version),
@@ -496,7 +542,6 @@ build_command(#opts_rec{ spec = {spec, Spec}, directory = Directory, quiet = Qui
end;
Command ->
set_install_prefix(Opts),
- io:format("[Building...]~n"),
Port = open_port({spawn,"sh -c \"" ++ Command ++ "\""},[{cd, Directory},exit_status,stderr_to_stdout,use_stdio, stream]),
unlink(Port),
PortHandler = fun (F) ->
View
3  src/agner_spec.erl
@@ -118,7 +118,8 @@ defaults(Package) ->
[{rebar_compatible, false},
{requires, []},
{deps_dir, "deps"},
- {rebar_commands, ["get-deps","compile"]},
+ {rebar_fetch_deps_commands, ["get-deps"]},
+ {rebar_commands, ["compile"]},
{homepage, "http://google.com/#q=" ++ Package},
{description, ""},
{keywords, []},
Please sign in to comment.
Something went wrong with that request. Please try again.