diff options
author | Tristan Sloughter <t@crashfast.com> | 2014-08-28 09:17:01 -0500 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2014-08-28 09:17:01 -0500 |
commit | 393abe92d01040a847bfc42a80d61b33f0254ca7 (patch) | |
tree | 2441809c82d2dc5fe4ac4c818b6714221a0915e2 /src | |
parent | 97db15d2a58de542aaef4075cddc3769f0308759 (diff) |
use locks if exists
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar.erl | 11 | ||||
-rw-r--r-- | src/rebar_lock.erl | 10 | ||||
-rw-r--r-- | src/rebar_prv_app_builder.erl | 3 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 62 | ||||
-rw-r--r-- | src/rebar_state.erl | 2 |
5 files changed, 49 insertions, 39 deletions
diff --git a/src/rebar.erl b/src/rebar.erl index 338e97b..01dca79 100644 --- a/src/rebar.erl +++ b/src/rebar.erl @@ -131,6 +131,13 @@ init_config({Options, _NonOptArgs}) -> rebar_config:consult_file(ConfigFile) end, + Config1 = case rebar_config:consult_file(?LOCK_FILE) of + [D] -> + [{locks, D} | Config]; + _ -> + Config + end, + %% If $HOME/.rebar/config exists load and use as global config GlobalConfigFile = filename:join([os:getenv("HOME"), ".rebar", "config"]), State = case filelib:is_regular(GlobalConfigFile) of @@ -138,9 +145,9 @@ init_config({Options, _NonOptArgs}) -> ?DEBUG("Load global config file ~p~n", [GlobalConfigFile]), rebar_config:consult_file(GlobalConfigFile), - rebar_state:new(GlobalConfigFile, Config); + rebar_state:new(GlobalConfigFile, Config1); false -> - rebar_state:new(Config) + rebar_state:new(Config1) end, %% Initialize vsn cache diff --git a/src/rebar_lock.erl b/src/rebar_lock.erl index a973ccc..2a54600 100644 --- a/src/rebar_lock.erl +++ b/src/rebar_lock.erl @@ -1,13 +1,7 @@ -module(rebar_lock). --export([update/3]). +-export([create/1]). create(State) -> - LockDeps = [], - ok = file:write_file("./rebar.lock", io_lib:format("~p.~n", [LockDeps])). - -update(State, App, Source) -> - New = rebar_fetch:new(rebar_app_info:dir(App), rebar_app_info:name(App), rebar_app_info:original_vsn(App), Source), - {ok, [Terms]} = file:consult("./rebar.lock"), - LockDeps = lists:keyreplace(rebar_app_info:name(App), 1, Terms, New), + LockDeps = rebar_state:get(State, locks, []), ok = file:write_file("./rebar.lock", io_lib:format("~p.~n", [LockDeps])). diff --git a/src/rebar_prv_app_builder.erl b/src/rebar_prv_app_builder.erl index ebc3368..c4502e4 100644 --- a/src/rebar_prv_app_builder.erl +++ b/src/rebar_prv_app_builder.erl @@ -37,8 +37,7 @@ do(State) -> _AppInfo1 = build(State, AppInfo) end, Apps), - LockDeps = rebar_state:get(State, deps, []), - ok = file:write_file("./rebar.lock", io_lib:format("~p.~n", [LockDeps])), + 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 27088bc..a01db16 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -66,32 +66,38 @@ init(State) -> do(State) -> %% Read in package index and dep graph {Packages, Graph} = rebar_packages:get_packages(State), - - case rebar_state:get(State, deps, []) of + case rebar_state:get(State, locks, []) of [] -> - {ok, State}; - Deps -> - %% Split source deps form binary deps, needed to keep backwards compatibility - {SrcDeps, Goals} = parse_deps(Deps), - case update_src_deps(State, SrcDeps, Goals, []) of - {State1, SrcDeps1, [], Locked} -> - {ok, rebar_state:set(State1, deps, Locked)}; - {State1, SrcDeps1, Goals1, Locked} -> - {ok, Solved} = rlx_depsolver:solve(Graph, Goals1), - M = lists:map(fun({Name, Vsn}) -> - FmtVsn = ec_cnv:to_binary(rlx_depsolver:format_version(Vsn)), - {ok, P} = dict:find({Name, FmtVsn}, Packages), - Link = proplists:get_value(<<"link">>, P), - #dep{name=Name, - vsn=FmtVsn, - source={Name - ,FmtVsn - ,Link}} - end, Solved), - {State2, Deps1, Locked2} = update_deps(State1, M), - State3 = rebar_state:set(State2, deps, Locked++Locked2), - {ok, rebar_state:set(State3, goals, Goals1)} - end + case rebar_state:get(State, deps, []) of + [] -> + {ok, State}; + Deps -> + %% Split source deps form binary deps, needed to keep backwards compatibility + {SrcDeps, Goals} = parse_deps(Deps), + case update_src_deps(State, SrcDeps, Goals, []) of + {State1, SrcDeps1, [], Locked} -> + {ok, rebar_state:set(State1, locks, Locked)}; + {State1, SrcDeps1, Goals1, Locked} -> + {ok, Solved} = rlx_depsolver:solve(Graph, Goals1), + M = lists:map(fun({Name, Vsn}) -> + FmtVsn = ec_cnv:to_binary(rlx_depsolver:format_version(Vsn)), + {ok, P} = dict:find({Name, FmtVsn}, Packages), + Link = proplists:get_value(<<"link">>, P), + #dep{name=Name, + vsn=FmtVsn, + source={Name + ,FmtVsn + ,Link}} + end, Solved), + {State2, Deps1, Locked2} = update_deps(State1, M), + State3 = rebar_state:set(State2, locks, Locked++Locked2), + {ok, rebar_state:set(State3, goals, Goals1)} + end + end; + Locks -> + Locks1 = [new(Lock) || Lock <- Locks], + {State2, _, _} = update_deps(State, Locks1), + {ok, State2} end. %% set REBAR_DEPS_DIR and ERL_LIBS environment variables @@ -124,8 +130,12 @@ get_deps_dir(DepsDir, App) -> %% Internal functions %% =================================================================== -new({Name, Vsn, Source})-> +new({Name, Vsn, Source}) when is_tuple(Source) -> #dep{name=ec_cnv:to_binary(Name), vsn=ec_cnv:to_binary(Vsn), source=Source}; +new({Name, Vsn, Source}) when is_binary(Source) -> + #dep{name=ec_cnv:to_binary(Name) + ,vsn=ec_cnv:to_binary(Vsn) + ,source={ec_cnv:to_binary(Name), ec_cnv:to_binary(Vsn), Source}}; new(Name) -> #dep{name=ec_cnv:to_binary(Name)}. diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 1e06ac6..4b4ada8 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -59,7 +59,7 @@ new(ParentState, Config, Dir) -> _Opts = ParentState#state_t.opts, LocalOpts = case rebar_config:consult_file(?LOCK_FILE) of {ok, [D]} -> - [{lock_deps, D} | Config]; + [{locks, D} | Config]; _ -> Config end, |