summaryrefslogtreecommitdiff
path: root/src/rebar_prv_update.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_prv_update.erl')
-rw-r--r--src/rebar_prv_update.erl44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl
index 54b135e..75c609e 100644
--- a/src/rebar_prv_update.erl
+++ b/src/rebar_prv_update.erl
@@ -104,7 +104,8 @@ hex_to_index(State) ->
case lists:any(fun is_supported/1, BuildTools) of
true ->
DepsList = update_deps_list(Pkg, PkgVsn, Deps, Registry, State),
- ets:insert(?PACKAGE_TABLE, {{Pkg, PkgVsn}, DepsList, Checksum});
+ HashedDeps = update_deps_hashes(DepsList),
+ ets:insert(?PACKAGE_TABLE, {{Pkg, PkgVsn}, HashedDeps, Checksum});
false ->
true
end;
@@ -142,8 +143,8 @@ hex_to_index(State) ->
end.
update_deps_list(Pkg, PkgVsn, Deps, HexRegistry, State) ->
- lists:foldl(fun([Dep, DepVsn, false, _AppName | _], DepsListAcc) ->
- Dep1 = {Pkg, PkgVsn, Dep},
+ lists:foldl(fun([Dep, DepVsn, false, AppName | _], DepsListAcc) ->
+ Dep1 = {Pkg, PkgVsn, Dep, AppName},
case {valid_vsn(DepVsn), DepVsn} of
%% Those are all not perfectly implemented!
%% and doubled since spaces seem not to be
@@ -168,14 +169,29 @@ update_deps_list(Pkg, PkgVsn, Deps, HexRegistry, State) ->
cmpl(Dep1, rm_ws(Vsn), HexRegistry, State,
DepsListAcc, fun ec_semver:lt/2);
{_, <<"==", Vsn/binary>>} ->
- [{Dep, Vsn} | DepsListAcc];
+ [{AppName, {pkg, Dep, Vsn, undefined}} | DepsListAcc];
{_, Vsn} ->
- [{Dep, Vsn} | DepsListAcc]
+ [{AppName, {pkg, Dep, Vsn, undefined}} | DepsListAcc]
end;
([_Dep, _DepVsn, true, _AppName | _], DepsListAcc) ->
DepsListAcc
end, [], Deps).
+update_deps_hashes(List) ->
+ [{Name, {pkg, PkgName, Vsn, lookup_hash(PkgName, Vsn, Hash)}}
+ || {Name, {pkg, PkgName, Vsn, Hash}} <- List].
+
+lookup_hash(Name, Vsn, undefined) ->
+ try
+ ets:lookup_element(?PACKAGE_TABLE, {Name, Vsn}, 3)
+ catch
+ _:_ ->
+ undefined
+ end;
+lookup_hash(_, _, Hash) ->
+ Hash.
+
+
rm_ws(<<" ", R/binary>>) ->
rm_ws(R);
rm_ws(R) ->
@@ -188,27 +204,27 @@ valid_vsn(Vsn) ->
SupportedVersions = "^(>=?|<=?|~>|==)?\\s*" ++ SemVerRegExp ++ "$",
re:run(Vsn, SupportedVersions) =/= nomatch.
-highest_matching({Pkg, PkgVsn, Dep}, Vsn, HexRegistry, State, DepsListAcc) ->
+highest_matching({Pkg, PkgVsn, Dep, App}, Vsn, HexRegistry, State, DepsListAcc) ->
case rebar_packages:find_highest_matching(Pkg, PkgVsn, Dep, Vsn, HexRegistry, State) of
{ok, HighestDepVsn} ->
- [{Dep, HighestDepVsn} | DepsListAcc];
+ [{App, {pkg, Dep, HighestDepVsn, undefined}} | DepsListAcc];
none ->
?WARN("[~s:~s] Missing registry entry for package ~s. Try to fix with `rebar3 update`",
[Pkg, PkgVsn, Dep]),
DepsListAcc
end.
-cmp({_Pkg, _PkgVsn, Dep} = Dep1, Vsn, HexRegistry, State, DepsListAcc, CmpFun) ->
+cmp({_Pkg, _PkgVsn, Dep, _App} = Dep1, Vsn, HexRegistry, State, DepsListAcc, CmpFun) ->
{ok, Vsns} = rebar_packages:find_all(Dep, HexRegistry, State),
cmp_(undefined, Vsn, Vsns, DepsListAcc, Dep1, CmpFun).
-cmp_(undefined, _MinVsn, [], DepsListAcc, {Pkg, PkgVsn, Dep}, _CmpFun) ->
+cmp_(undefined, _MinVsn, [], DepsListAcc, {Pkg, PkgVsn, Dep, _App}, _CmpFun) ->
?WARN("[~s:~s] Missing registry entry for package ~s. Try to fix with `rebar3 update`",
[Pkg, PkgVsn, Dep]),
DepsListAcc;
-cmp_(HighestDepVsn, _MinVsn, [], DepsListAcc, {_Pkg, _PkgVsn, Dep}, _CmpFun) ->
- [{Dep, HighestDepVsn} | DepsListAcc];
+cmp_(HighestDepVsn, _MinVsn, [], DepsListAcc, {_Pkg, _PkgVsn, Dep, App}, _CmpFun) ->
+ [{App, {pkg, Dep, HighestDepVsn, undefined}} | DepsListAcc];
cmp_(BestMatch, MinVsn, [Vsn | R], DepsListAcc, Dep, CmpFun) ->
case CmpFun(Vsn, MinVsn) of
@@ -224,13 +240,13 @@ cmpl({_Pkg, _PkgVsn, Dep} = Dep1, Vsn, HexRegistry, State, DepsListAcc, CmpFun)
{ok, Vsns} = rebar_packages:find_all(Dep, HexRegistry, State),
cmpl_(undefined, Vsn, Vsns, DepsListAcc, Dep1, CmpFun).
-cmpl_(undefined, _MaxVsn, [], DepsListAcc, {Pkg, PkgVsn, Dep}, _CmpFun) ->
+cmpl_(undefined, _MaxVsn, [], DepsListAcc, {Pkg, PkgVsn, Dep, _App}, _CmpFun) ->
?WARN("[~s:~s] Missing registry entry for package ~s. Try to fix with `rebar3 update`",
[Pkg, PkgVsn, Dep]),
DepsListAcc;
-cmpl_(HighestDepVsn, _MaxVsn, [], DepsListAcc, {_Pkg, _PkgVsn, Dep}, _CmpFun) ->
- [{Dep, HighestDepVsn} | DepsListAcc];
+cmpl_(HighestDepVsn, _MaxVsn, [], DepsListAcc, {_Pkg, _PkgVsn, Dep, App}, _CmpFun) ->
+ [{App, {pkg, Dep, HighestDepVsn, undefined}} | DepsListAcc];
cmpl_(undefined, MaxVsn, [Vsn | R], DepsListAcc, Dep, CmpFun) ->
case CmpFun(Vsn, MaxVsn) of