Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial implementation of a default installation method

  • Loading branch information...
commit 3d8fc24dab120f21395ca40160752cb359e69d5d 1 parent 5fa5e83
@yrashk yrashk authored
Showing with 51 additions and 6 deletions.
  1. +3 −0  include/agner_spec.hrl
  2. +27 −4 src/agner_fetch.erl
  3. +21 −2 src/agner_spec.erl
View
3  include/agner_spec.hrl
@@ -15,6 +15,8 @@
{hg, url(), hg_rev()} |
{svn, url(), svn_rev()}.
+-type agner_install_dir() :: otp | directory().
+
-type agner_spec_requirement() :: {agner_package_name(), agner_package_version_string()} |
agner_package_name().
@@ -28,6 +30,7 @@
-type agner_spec_property_rebar_commands() :: {rebar_commands, list(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())}.
-type agner_spec_property_bin_files() :: {bin_files, list(string())}.
-type agner_spec_property_license() :: {license, string(), file()} |
{license, string()}.
View
31 src/agner_fetch.erl
@@ -32,7 +32,7 @@
repo_dir,
fetched_steps = [check_requirements, fetch_requirements, caveats],
build_steps = [rebar, build_command, add_path],
- install_steps = [install_command, print_prefix]
+ install_steps = [install_dirs, install_command, print_prefix]
}).
%%%===================================================================
@@ -270,6 +270,14 @@ installable(next, State) ->
installable(_, #state{ opts = #opts_rec{ install = false }} = State) ->
{next_state, installable, State};
+installable(install_dirs, #state{ opts = #opts_rec{ install = true } = Opts } = State) ->
+ case install_dirs(Opts) of
+ ok ->
+ {next_state, installable, State};
+ _ ->
+ {stop, {error, {install_failed, "Installation failed"}}, State}
+ end;
+
installable(install_command, #state{ opts = #opts_rec{ install = true } = Opts, repo_dir = RepoDir} = State) ->
os:putenv("AGNER_PACKAGE_REPO", RepoDir),
case install_command(Opts) of
@@ -512,19 +520,34 @@ add_path(#opts_rec{ addpath = false }) ->
ignore.
+
+install_dirs(#opts_rec{ spec = {spec, Spec} } = Opts) ->
+ io:format("[Installing...]~n"),
+ Spec1 = [{install_command,"cp -R " ++ string:join(proplists:get_value(install_dirs, Spec, [])," ") ++
+ " $AGNER_INSTALL_PREFIX 2>/dev/null && true || true"}|
+ Spec],
+
+ filelib:ensure_dir(filename:join([os:getenv("AGNER_PREFIX"),"packages"]) ++ "/"),
+ InstallPrefix = set_install_prefix(Opts),
+
+ os:cmd("rm -rf " ++ InstallPrefix),
+
+ install_command(Opts#opts_rec{ spec = {spec, Spec1} }),
+ ok.
+
install_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),
filelib:ensure_dir(filename:join([os:getenv("AGNER_PREFIX"),"packages"]) ++ "/"),
InstallPrefix = set_install_prefix(Opts),
- os:cmd("rm -rf " ++ InstallPrefix),
+
ok = filelib:ensure_dir(InstallPrefix ++ "/"),
case proplists:get_value(install_command, Spec) of
undefined ->
- io:format("ERROR: No install_command specified, can't install this package. Maybe you want to use just `agner build ~s`?~n", [Package]);
+ ok;
Command ->
- io:format("[Installing...]~n"),
+ io:format("[Running installation command...]~n"),
Port = open_port({spawn,"sh -c \"" ++ Command ++ "\""},[{cd, Directory},exit_status,stderr_to_stdout,use_stdio, stream]),
PortHandler = fun (F) ->
receive
View
23 src/agner_spec.erl
@@ -92,7 +92,25 @@ version_components(Version) ->
-spec normalize(agner_spec()) -> agner_spec().
normalize(Spec) ->
- lists:ukeysort(1,Spec ++ defaults(proplists:get_value(name, Spec, ""))).
+ lists:map(fun normalize_property/1, lists:ukeysort(1,Spec ++ defaults(proplists:get_value(name, Spec, "")))).
+
+-spec normalize_property(agner_spec_property()) -> agner_spec_property().
+
+-define(OTP_DIRS,"doc","ebin","include","priv").
+
+normalize_property({install_dirs, []}) ->
+ {install_dirs, []};
+
+normalize_property({install_dirs, [otp|Rest]}) ->
+ {install_dirs, Rest1} = normalize_property({install_dirs, Rest}),
+ {install_dirs, [?OTP_DIRS|Rest1]};
+
+normalize_property({install_dirs, [Any|Rest]}) ->
+ {install_dirs, Rest1} = normalize_property({install_dirs, Rest}),
+ {install_dirs, [Any|Rest1]};
+
+normalize_property(Property) ->
+ Property.
-spec defaults(agner_package_name()) -> agner_spec().
@@ -105,5 +123,6 @@ defaults(Package) ->
{description, ""},
{keywords, []},
{code_paths, ["ebin"]},
- {applications, []}].
+ {applications, []},
+ {install_dirs, [otp]}].
Please sign in to comment.
Something went wrong with that request. Please try again.