Permalink
Browse files

Merge commit 'v0.4.18' into release

  • Loading branch information...
2 parents 97f23e7 + bdf5bad commit e8a13a7f56006c417a31d8949547201252ae8949 @yrashk yrashk committed Jun 13, 2011
Showing with 100 additions and 20 deletions.
  1. +7 −4 README.md
  2. +4 −0 include/agner_spec.hrl
  3. BIN rebar
  4. +2 −2 src/agner.app.src
  5. +18 −0 src/agner.erl
  6. +59 −8 src/agner_fetch.erl
  7. +4 −2 src/agner_main.erl
  8. +4 −3 src/agner_rebar_plugin.erl
  9. +2 −1 src/agner_spec.erl
View
11 README.md
@@ -15,11 +15,11 @@ Installation
It is just a matter of a simple oneliner to get Agner installed:
- curl https://github.com/agner/agner/raw/master/scripts/oneliner | sh
+ curl https://raw.github.com/agner/agner/master/scripts/oneliner | sh
If you want to install latest release instead of HEAD, use this one:
- curl https://github.com/agner/agner/raw/master/scripts/oneliner.release | sh
+ curl https://raw.github.com/agner/agner/aster/scripts/oneliner.release | sh
Motivation
----------
@@ -166,18 +166,21 @@ defaults to `.`)
For convenience, the following shortcuts are defined:
- agner build PACKAGE [DESTDIR] [-v/--version VERSION] [-s/--spec-file SPECFILE] [-a/--add-path] [-i/--install]
+ agner build PACKAGE [DESTDIR] [-v/--version VERSION] [-s/--spec-file SPECFILE] [-a/--add-path] [-i/--install] [--no-fetch]
Alias for `agner fetch --build PACKAGE`.
- agner install PACKAGE [-v/--version VERSION] [-s/--spec-file SPECFILE]
+ agner install PACKAGE [-v/--version VERSION] [-s/--spec-file SPECFILE] [--no-fetch]
Alias for `agner fetch --build --install PACKAGE
/tmp/<uniq_filename>`. A typical example would be `agner install
rebar` or `agner install rebar -v @agner` to get `rebar` binary in
your `PATH`. It is assumed that `install_command` property will make use
of `AGNER_INSTALL_PREFIX` OS environment variable.
+`--no-fetch` option could be useful when you don't want to update already
+fetched repository, but just build or install it.
+
### Uninstalling
agner uninstall PACKAGE [-v/--version VERSION] [-s/--spec-file SPECFILE]
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
4 src/agner.app.src
@@ -1,7 +1,7 @@
{application, agner,
[
{description, ""},
- {vsn, "0.4.17"},
+ {vsn, "0.4.18"},
{registered, []},
{applications, [
kernel,
@@ -10,7 +10,7 @@
gproc
]},
{agner, [
- {requires, ["typespecs","getopt","gproc","plists","gen_fsm2","jsx","rebar"]}
+ {requires, ["typespecs","getopt","gproc","plists","gen_fsm2","jsx",{"rebar","@original"}]}
]},
{env, [
{indices, [{github, "agner"}]},
View
18 src/agner.erl
@@ -28,6 +28,7 @@ start() ->
[_|_] ->
ignore
end,
+ ensure_crypto_loaded(),
filelib:ensure_dir(os:getenv("AGNER_EXACT_PREFIX") ++ "/"),
inets:start(),
ssl:start(),
@@ -104,3 +105,20 @@ fetch(Name, Version, Directory) ->
versions(Name) ->
agner_server:versions(Name).
+
+
+%%%===================================================================
+%%% private
+%%%===================================================================
+ensure_crypto_loaded() ->
+ case code:ensure_loaded(crypto) of
+ {module, crypto} ->
+ ignore;
+ {error, _Err} ->
+ [io:format("~s~n", [Msg])
+ || Msg <- ["Your local Erlang installation doesn't include the crypto module",
+ "Make sure you have erlang-crypto and erlang-dev if on Debian",
+ " have erlang-crypto and erlang-devel if on Redhat/Fedora",
+ " sudo port install erlang +ssl if on OS X",
+ "Or, let kerl (https://github.com/evax/kerl) take care of those for you"]]
+ end.
View
67 src/agner_fetch.erl
@@ -24,13 +24,14 @@
install,
spec,
package_path,
- quiet
+ quiet,
+ nofetch
}).
-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]
}).
@@ -85,7 +86,7 @@ handle_state(ready, #state{ opts = #opts_rec { package = undefined,
end,
case AgnerKey of
not_found ->
- {stop, {error, {app_missing, "Can't find application " ++ App ++ " or its `agner' key"}}, State};
+ {stop, shutdown, State};
_ ->
Spec = agner_spec:normalize(AgnerKey),
handle_state(ready, State#state{ opts = Opts#opts_rec{ package = App,
@@ -148,6 +149,11 @@ handle_state(fetchable, #state{ opts = #opts_rec{ spec = Spec, package_path = Pa
handle_state(fetchable, State#state{ opts = Opts#opts_rec{ spec = {spec, agner_spec:normalize(Spec0)} }, repo_dir = PackagePath } );
%% Everything is ready to go, fetch
+handle_state(fetchable, #state{ opts = #opts_rec{version = Version, directory = Directory, nofetch = true }
+ } = State) when is_list(Directory) andalso is_list(Version) ->
+ gen_fsm2:send_event(self(), next),
+ {ok, State};
+
handle_state(fetchable, #state{ opts = #opts_rec{spec = {spec, Spec}, version = Version, directory = Directory }
} = State) when is_list(Directory) andalso is_list(Version) ->
agner:fetch(Spec, Version, Directory),
@@ -229,6 +235,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 +260,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 +477,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 +495,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 +548,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
6 src/agner_main.erl
@@ -78,7 +78,8 @@ arg_proplist() ->
{version, $v, "version", {string, "@master"}, "Version"},
{app, undefined, "app", string, "Fetch dependencies from .app"},
{spec, $s, "spec-file", string, "Use local specification file"},
- {quiet, $q, "quiet", {boolean, false}, "Don't render build/install scripts output"}
+ {quiet, $q, "quiet", {boolean, false}, "Don't render build/install scripts output"},
+ {nofetch, undefined, "no-fetch", {boolean, false}, "Don't (re)-fetch the source code"}
]}},
{"uninstall",
{uninstall,
@@ -107,7 +108,8 @@ arg_proplist() ->
{addpath, $a, "add-path", {boolean, false}, "Add path to compiled package to .erlang"},
{install, $i, "install", {boolean, false}, "Install package (if install_command is available)"},
{directory, undefined, undefined, string, "Directory to check package out to"},
- {quiet, $q, "quiet", {boolean, false}, "Don't render build/install scripts output"}
+ {quiet, $q, "quiet", {boolean, false}, "Don't render build/install scripts output"},
+ {nofetch, undefined, "no-fetch", {boolean, false}, "Don't (re)-fetch the source code"}
]}},
{"create",
{create,
View
7 src/agner_rebar_plugin.erl
@@ -2,11 +2,11 @@
-export(['check-deps'/2,
'get-deps'/2,
- compile/2]).
+ pre_compile/2]).
'check-deps'(Config, AppFile) ->
- compile(Config, AppFile).
+ pre_compile(Config, AppFile).
'get-deps'(Config, AppFile) ->
agner:start(),
@@ -15,10 +15,11 @@
{install, false},{build, false}]),
agner:stop().
-compile(Config, AppFile) ->
+pre_compile(Config, AppFile) ->
agner:start(),
set_indices(Config),
agner_main:handle_command(build,[{app, AppFile},{version, "@master"},{quiet, false},
+ {nofetch, true},
{addpath, false},
{install, false}]),
agner:stop().
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, []},

0 comments on commit e8a13a7

Please sign in to comment.