summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2014-09-02 18:29:29 -0500
committerTristan Sloughter <t@crashfast.com>2014-09-02 18:29:29 -0500
commit5373b56bfa199f8db4caead2ec28f9a6a87e2e83 (patch)
treef1b4e892cbe9d2b0cf4e2a839321b42b35384d33
parentd2cd52c3d265f76a4faae60a258b54baf4010ec8 (diff)
move locking to a provider
-rw-r--r--ebin/rebar.app3
-rw-r--r--src/rebar_fetch.erl18
-rw-r--r--src/rebar_lock.erl7
-rw-r--r--src/rebar_prv_compile.erl3
-rw-r--r--src/rebar_prv_install_deps.erl4
-rw-r--r--src/rebar_prv_lock.erl43
6 files changed, 58 insertions, 20 deletions
diff --git a/ebin/rebar.app b/ebin/rebar.app
index 999963a..e3c2e0a 100644
--- a/ebin/rebar.app
+++ b/ebin/rebar.app
@@ -16,7 +16,7 @@
rebar_fetch,
rebar_file_utils,
rebar_log,
- rebar_lock,
+ rebar_prv_lock,
rebar_otp_app,
rebar_provider,
rebar_packages,
@@ -54,6 +54,7 @@
%% any_dir processing modules
{providers, [rebar_prv_escripter,
rebar_prv_deps,
+ rebar_prv_lock,
rebar_prv_install_deps,
rebar_prv_packages,
rebar_erlydtl_compiler,
diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl
index 2cad9f2..6b31f6c 100644
--- a/src/rebar_fetch.erl
+++ b/src/rebar_fetch.erl
@@ -8,7 +8,7 @@
-module(rebar_fetch).
-export([new/4,
- current_ref/2,
+ lock_source/2,
download_source/2,
update_source1/2,
source_engine_avail/1,
@@ -27,8 +27,8 @@
}).
new(Dir, App, Vsn, Source) ->
- Ref = current_ref(Dir, Source),
- {App, Vsn, setelement(3, Source, Ref)}.
+ NewSource = lock_source(Dir, Source),
+ {App, Vsn, NewSource}.
init_p4_settings(Basename) ->
#p4_settings{client =
@@ -40,8 +40,11 @@ init_p4_settings(Basename) ->
++ "-Rebar-automated-download"
end}.
-current_ref(AppDir, {git, _, _}) ->
- string:strip(os:cmd("git --git-dir='" ++ AppDir ++ "/.git' rev-parse --verify HEAD"), both, $\n).
+lock_source(AppDir, {git, Url, _}) ->
+ Ref = string:strip(os:cmd("git --git-dir='" ++ AppDir ++ "/.git' rev-parse --verify HEAD"), both, $\n),
+ {git, Url, Ref};
+lock_source(_AppDir, Source) ->
+ Source.
download_source(AppDir, Source) ->
TmpDir = ec_file:insecure_mkdtemp(),
@@ -121,9 +124,8 @@ download_source_tmp(TmpDir, {fossil, Url, Version}) ->
[{cd, TmpDir}]),
rebar_utils:sh(?FMT("fossil open ~s ~s --nested", [Repository, Version]),
[]);
-download_source_tmp(TmpDir, {AppName, AppVersion, Url}) when is_binary(AppName)
- , is_binary(AppVersion) ->
- TmpFile = binary_to_list(filename:join(TmpDir, <<AppName/binary, "-", AppVersion/binary, ".tar.gz">>)),
+download_source_tmp(TmpDir, Url) ->
+ TmpFile = filename:join(TmpDir, "package.tar.gz"),
{ok, saved_to_file} = httpc:request(get, {binary_to_list(Url), []}, [], [{stream, TmpFile}]),
{tarball, TmpFile}.
diff --git a/src/rebar_lock.erl b/src/rebar_lock.erl
deleted file mode 100644
index 2a54600..0000000
--- a/src/rebar_lock.erl
+++ /dev/null
@@ -1,7 +0,0 @@
--module(rebar_lock).
-
--export([create/1]).
-
-create(State) ->
- LockDeps = rebar_state:get(State, locks, []),
- ok = file:write_file("./rebar.lock", io_lib:format("~p.~n", [LockDeps])).
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index 4f5d75c..5e7bd82 100644
--- a/src/rebar_prv_compile.erl
+++ b/src/rebar_prv_compile.erl
@@ -9,7 +9,7 @@
-include("rebar.hrl").
-define(PROVIDER, compile).
--define(DEPS, [install_deps]).
+-define(DEPS, [lock]).
%% ===================================================================
%% Public API
@@ -38,7 +38,6 @@ do(State) ->
build(S, AppInfo)
end, Deps++ProjectApps),
- rebar_lock:create(State),
{ok, State}.
build(State, AppInfo) ->
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 423a577..b75964f 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -144,7 +144,7 @@ handle_deps(State, Deps) ->
,ordsets:from_list(Solved)]),
%% Sort all apps to build order
- State3 = rebar_state:set(State2, all_deps, AllDeps),
+ State3 = rebar_state:set(State2, all_deps, AllDeps -- ProjectApps),
{ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)),
{ok, rebar_state:set(State3, deps_to_build, lists:dropwhile(fun is_valid/1, Sort) -- ProjectApps)}.
@@ -164,7 +164,7 @@ package_to_app(DepsDir, Packages, Name, Vsn) ->
AppInfo1 = rebar_app_info:deps(AppInfo, PkgDeps),
AppInfo2 =
rebar_app_info:dir(AppInfo1, get_deps_dir(DepsDir, <<Name/binary, "-", FmtVsn/binary>>)),
- rebar_app_info:source(AppInfo2, {Name, FmtVsn, Link}).
+ rebar_app_info:source(AppInfo2, Link).
-spec update_src_deps(rebar_state:t()) -> rebat_state:t().
update_src_deps(State) ->
diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl
new file mode 100644
index 0000000..6aaf7ac
--- /dev/null
+++ b/src/rebar_prv_lock.erl
@@ -0,0 +1,43 @@
+-module(rebar_prv_lock).
+
+-behaviour(rebar_provider).
+
+-export([init/1,
+ do/1]).
+
+-include("rebar.hrl").
+
+-define(PROVIDER, lock).
+-define(DEPS, [install_deps]).
+
+%% ===================================================================
+%% Public API
+%% ===================================================================
+
+-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
+init(State) ->
+ State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
+ provider_impl = ?MODULE,
+ bare = false,
+ deps = ?DEPS,
+ example = "",
+ short_desc = "Locks dependencies",
+ desc = info("Locks dependencies"),
+ opts = []}),
+ {ok, State1}.
+
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+do(State) ->
+ AllDeps = rebar_state:get(State, all_deps, []),
+ Locks = lists:map(fun(Dep) ->
+ Dir = rebar_app_info:dir(Dep),
+ {rebar_app_info:name(Dep)
+ ,rebar_app_info:original_vsn(Dep)
+ ,rebar_fetch:lock_source(Dir, rebar_app_info:source(Dep))}
+ end, AllDeps),
+ Dir = rebar_state:dir(State),
+ file:write_file(filename:join(Dir, "rebar.lock"), io_lib:format("~p.~n", [Locks])),
+ {ok, rebar_state:set(State, locks, Locks)}.
+
+info(_) ->
+ "".