summary refs log tree commit diff
diff options
context:
space:
mode:
authorEric Merritt <eric@merritt.tech>2016-04-25 07:55:34 -0700
committerEric Merritt <eric@merritt.tech>2016-04-25 08:34:55 -0700
commitcd27abe7513791280a5a450839ee5879241c0b7b (patch)
tree79b0d85050225d07b8b7f67f463f9433229e4092
parent585c1a8f96bf27fd26cced5015e3e9d3dc434a8a (diff)
downloadnixlib-cd27abe7513791280a5a450839ee5879241c0b7b.tar
nixlib-cd27abe7513791280a5a450839ee5879241c0b7b.tar.gz
nixlib-cd27abe7513791280a5a450839ee5879241c0b7b.tar.bz2
nixlib-cd27abe7513791280a5a450839ee5879241c0b7b.tar.lz
nixlib-cd27abe7513791280a5a450839ee5879241c0b7b.tar.xz
nixlib-cd27abe7513791280a5a450839ee5879241c0b7b.tar.zst
nixlib-cd27abe7513791280a5a450839ee5879241c0b7b.zip
rebar3: refactor
cleanup up the code quite a bit in the bootstrapper
-rw-r--r--pkgs/development/tools/build-managers/rebar3/default.nix12
-rwxr-xr-xpkgs/development/tools/build-managers/rebar3/rebar3-nix-bootstrap61
2 files changed, 30 insertions, 43 deletions
diff --git a/pkgs/development/tools/build-managers/rebar3/default.nix b/pkgs/development/tools/build-managers/rebar3/default.nix
index 6fa5578ed675..d8938e2d4689 100644
--- a/pkgs/development/tools/build-managers/rebar3/default.nix
+++ b/pkgs/development/tools/build-managers/rebar3/default.nix
@@ -7,68 +7,56 @@ let
 
   bootstrapper = ./rebar3-nix-bootstrap;
 
-  # TODO: all these below probably should go into nixpkgs.erlangModules.sources.*
-  # {erlware_commons,     "0.19.0"},
   erlware_commons = fetchHex {
     pkg = "erlware_commons";
     version = "0.19.0";
     sha256 = "1gfsy9bbhjb94c5ghff2niamn93x2x08lnklh6pp7sfr5i0gkgsv";
   };
-  # {ssl_verify_hostname, "1.0.5"},
   ssl_verify_hostname = fetchHex {
     pkg = "ssl_verify_hostname";
     version = "1.0.5";
     sha256 = "1gzavzqzljywx4l59gvhkjbr1dip4kxzjjz1s4wsn42f2kk13jzj";
   };
-  # {certifi,             "0.4.0"},
   certifi = fetchHex {
     pkg = "certifi";
     version = "0.4.0";
     sha256 = "04bnvsbssdcf6b9h9bfglflds7j0gx6q5igl1xxhx6fnwaz37hhw";
   };
-  # {providers,           "1.6.0"},
   providers = fetchHex {
     pkg = "providers";
     version = "1.6.0";
     sha256 = "0byfa1h57n46jilz4q132j0vk3iqc0v1vip89li38gb1k997cs0g";
   };
-  # {getopt,              "0.8.2"},
   getopt = fetchHex {
     pkg = "getopt";
     version = "0.8.2";
     sha256 = "1xw30h59zbw957cyjd8n50hf9y09jnv9dyry6x3avfwzcyrnsvkk";
   };
-  # {bbmustache,          "1.0.4"},
   bbmustache = fetchHex {
     pkg = "bbmustache";
     version = "1.0.4";
     sha256 = "04lvwm7f78x8bys0js33higswjkyimbygp4n72cxz1kfnryx9c03";
   };
-  # {relx,                "3.17.0"},
   relx = fetchHex {
     pkg = "relx";
     version = "3.17.0";
     sha256 = "1xjybi93m8gj9f9z3lkc7xbg3k5cw56yl78rcz5qfirr0223sby2";
   };
-  # {cf,                  "0.2.1"},
   cf = fetchHex {
     pkg = "cf";
     version = "0.2.1";
     sha256 = "19d0yvg8wwa57cqhn3vqfvw978nafw8j2rvb92s3ryidxjkrmvms";
   };
-  # {cth_readable,        "1.2.2"},
   cth_readable = fetchHex {
     pkg = "cth_readable";
     version = "1.2.2";
     sha256 = "0kb9v4998liwyidpjkhcg1nin6djjzxcx6b313pbjicbp4r58n3p";
   };
-  # {eunit_formatters,    "0.3.1"}
   eunit_formatters = fetchHex {
     pkg = "eunit_formatters";
     version = "0.3.1";
     sha256 = "0cg9dasv60v09q3q4wja76pld0546mhmlpb0khagyylv890hg934";
   };
-  # {rebar3_hex,    "1.12.0"}
   rebar3_hex = fetchHex {
     pkg = "rebar3_hex";
     version = "1.12.0";
diff --git a/pkgs/development/tools/build-managers/rebar3/rebar3-nix-bootstrap b/pkgs/development/tools/build-managers/rebar3/rebar3-nix-bootstrap
index d75d69f054d6..4784f2224cc9 100755
--- a/pkgs/development/tools/build-managers/rebar3/rebar3-nix-bootstrap
+++ b/pkgs/development/tools/build-managers/rebar3/rebar3-nix-bootstrap
@@ -38,15 +38,14 @@
 main(Args) ->
     {ok, ArgData} = parse_args(Args),
     {ok, RequiredData} = gather_required_data_from_the_environment(ArgData),
-    do(RequiredData).
+    do_the_bootstrap(RequiredData).
 
-%% @doc
-%% This actually runs the command. There are two modes 'register_only'
-%% where the register is created from hex and everything else.
--spec do(#data{}) -> ok.
-do(RequiredData = #data{registry_only = true}) ->
+%% @doc There are two modes 'registery_only' where the register is
+%% created from hex and everything else.
+-spec do_the_bootstrap(#data{}) -> ok.
+do_the_bootstrap(RequiredData = #data{registry_only = true}) ->
     ok = bootstrap_registry(RequiredData);
-do(RequiredData) ->
+do_the_bootstrap(RequiredData) ->
     ok = bootstrap_registry(RequiredData),
     ok = bootstrap_configs(RequiredData),
     ok = bootstrap_plugins(RequiredData),
@@ -55,10 +54,15 @@ do(RequiredData) ->
 %% @doc
 %% Argument parsing is super simple only because we want to keep the
 %% dependencies minimal. For now there can be two entries on the
-%% command line, "register-only" and "compile-ports"
+%% command line, "registery-only"
 -spec parse_args([string()]) -> #data{}.
+parse_args(["registry-only"]) ->
+    {ok, #data{registry_only = true}};
+parse_args([]) ->
+    {ok, #data{registry_only = false}};
 parse_args(Args) ->
-    {ok, #data{registry_only = lists:member("registry-only", Args)}}.
+    io:format("Unexpected command line arguments passed in: ~p~n", [Args]),
+    erlang:halt(120).
 
 -spec bootstrap_configs(#data{}) -> ok.
 bootstrap_configs(RequiredData)->
@@ -76,7 +80,7 @@ bootstrap_plugins(#data{plugins = Plugins}) ->
                             gather_dependency(Path) ++ Acc
                     end, [], Paths),
     lists:foreach(fun (Path) ->
-                          link_app(Path, Target)
+                          ok = link_app(Path, Target)
                   end, CopiableFiles).
 
 -spec bootstrap_libs(#data{}) -> ok.
@@ -89,7 +93,7 @@ bootstrap_libs(#data{erl_libs = ErlLibs}) ->
                             gather_directory_contents(Path) ++ Acc
                     end, [], Paths),
     lists:foreach(fun (Path) ->
-                          link_app(Path, Target)
+                          ok = link_app(Path, Target)
                   end, CopiableFiles).
 
 -spec gather_dependency(string()) -> [{string(), string()}].
@@ -199,21 +203,20 @@ guard_env(Name) ->
 %% include the 'pc' plugin.
 -spec if_compile_ports_add_pc_plugin(#data{}) -> ok.
 if_compile_ports_add_pc_plugin(#data{compile_ports = true}) ->
-    ConfigTerms = update_config(read_rebar_config()),
+    ConfigTerms = add_pc_to_plugins(read_rebar_config()),
     Text = lists:map(fun(Term) -> io_lib:format("~tp.~n", [Term]) end,
                      ConfigTerms),
     file:write_file("rebar.config", Text);
 if_compile_ports_add_pc_plugin(_) ->
     ok.
 
--spec update_config([term()]) -> [term()].
-update_config(Config) ->
-    case lists:keysearch(plugins, 1, Config) of
-        {ok, {plugins, PluginList}} ->
-            lists:keystore(plugins, 1, Config, {plugins, [Config | PluginList]});
-        _ ->
-            [{plugins, [pc]} | Config]
-    end.
+-spec add_pc_to_plugins([term()]) -> [term()].
+add_pc_to_plugins(Config) ->
+    PluginList = case lists:keysearch(plugins, 1, Config) of
+                     {ok, {plugins, ExistingPluginList}} -> ExistingPluginList;
+                     _ -> []
+                 end,
+    lists:keystore(plugins, 1, Config, {plugins, [pc | PluginList]}).
 
 -spec read_rebar_config() -> [term()].
 read_rebar_config() ->
@@ -229,10 +232,13 @@ read_rebar_config() ->
 -spec if_single_app_project_update_app_src_version(#data{}) -> ok.
 if_single_app_project_update_app_src_version(#data{name = Name,
                                                    version = Version}) ->
-    case app_src_exists(Name) of
-        {true, SrcFile} ->
+    SrcFile = filename:join("src",
+                            lists:concat([Name, ".app.src"])),
+
+    case filelib:is_file(SrcFile) of
+        true ->
             update_app_src_with_version(SrcFile, Version);
-        {false, _} ->
+        false ->
             ok
     end.
 
@@ -240,14 +246,7 @@ if_single_app_project_update_app_src_version(#data{name = Name,
 update_app_src_with_version(SrcFile, Version) ->
     {ok, [{application, Name, Details}]} = file:consult(SrcFile),
     NewDetails = lists:keyreplace(vsn, 1, Details, {vsn, Version}),
-    file:write_file(SrcFile, io_lib:fwrite("~p.\n", [{application, Name, NewDetails}])).
-
--spec app_src_exists(string()) -> boolean().
-app_src_exists(Name) ->
-    FileName = filename:join("src",
-                             lists:concat([Name, ".app.src"])),
-    {filelib:is_file(FileName), FileName}.
-
+    ok = file:write_file(SrcFile, io_lib:fwrite("~p.\n", [{application, Name, NewDetails}])).
 
 %% @doc
 %% Write the result of the format string out to stderr.