aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Wilberding <[email protected]>2014-08-09 20:29:31 -0700
committerJordan Wilberding <[email protected]>2014-08-09 20:29:31 -0700
commit1d7f26d786452f53a77fba64fe5081885d26856f (patch)
treeb256b3c4ba3db142c92d037438b7e2f50052a205
parentf8737c88f54aaa8f2e9a4b66bb74034f0a3bbab1 (diff)
parent11b4775c6610bd8f1c00d45e0766423301927b45 (diff)
downloadrelx-1d7f26d786452f53a77fba64fe5081885d26856f.tar.gz
relx-1d7f26d786452f53a77fba64fe5081885d26856f.tar.bz2
relx-1d7f26d786452f53a77fba64fe5081885d26856f.zip
Merge pull request #207 from tsloughter/app_sort
sort apps by version, so newest is chosen if it passes constraints
-rw-r--r--src/rlx_depsolver.erl23
-rw-r--r--test/rlx_depsolver_tester.erl20
2 files changed, 24 insertions, 19 deletions
diff --git a/src/rlx_depsolver.erl b/src/rlx_depsolver.erl
index e054cc9..f9dc73d 100644
--- a/src/rlx_depsolver.erl
+++ b/src/rlx_depsolver.erl
@@ -214,14 +214,20 @@ add_package_version({?MODULE, Dom0}, RawPkg, RawVsn, RawPkgConstraints) ->
Info2 =
case gb_trees:lookup(Pkg, Dom0) of
{value, Info0} ->
- case lists:keytake(Vsn, 1, Info0) of
- {value, {Vsn, Constraints}, Info1} ->
- [{Vsn, join_constraints(Constraints,
- PkgConstraints)}
- | Info1];
- false ->
- [{Vsn, PkgConstraints} | Info0]
- end;
+ %% Sort Vsns from greatest to lowest
+ lists:reverse(
+ lists:sort(fun(X, Y) ->
+ ec_semver:lte(element(1, X), element(1, Y))
+ end,
+ case lists:keytake(Vsn, 1, Info0) of
+ {value, {Vsn, Constraints}, Info1} ->
+ [{Vsn, join_constraints(Constraints,
+ PkgConstraints)}
+ | Info1];
+ false ->
+ [{Vsn, PkgConstraints} | Info0]
+
+ end));
none ->
[{Vsn, PkgConstraints}]
end,
@@ -621,7 +627,6 @@ pkgs(DepGraph, Visited, Pkg, Constraints, OtherPkgs, PathInd) ->
NewVisited = [{Pkg, Vsn} | Visited],
Res = all_pkgs(DepGraph, NewVisited, DepPkgs ++ OtherPkgs, UConstraints, PathInd),
Res
-
end,
case constrained_package_versions(DepGraph, Pkg, Constraints) of
[] ->
diff --git a/test/rlx_depsolver_tester.erl b/test/rlx_depsolver_tester.erl
index b441a1e..9b55603 100644
--- a/test/rlx_depsolver_tester.erl
+++ b/test/rlx_depsolver_tester.erl
@@ -61,12 +61,12 @@ data1_test() ->
data2_test() ->
ExpectedResult = versionify([{"app18","0.0.1"},
- {"app4","0.0.1"},
+ {"app4","0.0.7"},
{"app1","0.0.1"},
{"app6","0.0.1"},
{"dep_pkg13","0.0.2"},
{"app13","0.0.1"},
- {"dep_pkg5","0.0.2"},
+ {"dep_pkg5","0.0.3"},
{"dep_pkg1","0.0.2"},
{"dep_pkg2","0.0.5"},
{"dep_pkg7","0.1.2"},
@@ -82,12 +82,12 @@ data3_test() ->
{"app38","0.0.1"},
{"app28","0.0.1"},
{"app18","0.0.1"},
- {"app4","0.0.1"},
+ {"app4","0.0.7"},
{"app1","0.0.1"},
{"app6","0.0.1"},
{"dep_pkg13","0.0.2"},
{"app13","0.0.1"},
- {"dep_pkg5","0.0.2"},
+ {"dep_pkg5","0.0.3"},
{"dep_pkg1","0.0.2"},
{"dep_pkg2","0.0.5"},
{"dep_pkg7","0.1.2"},
@@ -104,12 +104,12 @@ data4_test() ->
{"app38","0.0.1"},
{"app28","0.0.1"},
{"app18","0.0.1"},
- {"app4","0.0.1"},
+ {"app4","0.0.7"},
{"app1","0.0.1"},
{"app6","0.0.1"},
{"dep_pkg13","0.0.2"},
{"app13","0.0.1"},
- {"dep_pkg5","0.0.2"},
+ {"dep_pkg5","0.0.3"},
{"dep_pkg1","0.0.2"},
{"dep_pkg2","0.0.5"},
{"dep_pkg7","0.1.2"},
@@ -129,12 +129,12 @@ data5_test() ->
{"app38","0.0.1"},
{"app28","0.0.1"},
{"app18","0.0.1"},
- {"app4","0.0.1"},
+ {"app4","0.0.7"},
{"app1","0.0.1"},
{"app6","0.0.1"},
{"dep_pkg13","0.0.2"},
{"app13","0.0.1"},
- {"dep_pkg5","0.0.2"},
+ {"dep_pkg5","0.0.3"},
{"dep_pkg1","0.0.2"},
{"dep_pkg2","0.0.5"},
{"dep_pkg7","0.1.2"},
@@ -157,12 +157,12 @@ data6_test() ->
{"app38","0.0.1"},
{"app28","0.0.1"},
{"app18","0.0.1"},
- {"app4","0.0.1"},
+ {"app4","0.0.7"},
{"app1","0.0.1"},
{"app6","0.0.1"},
{"dep_pkg13","0.0.2"},
{"app13","0.0.1"},
- {"dep_pkg5","0.0.2"},
+ {"dep_pkg5","0.0.3"},
{"dep_pkg1","0.0.2"},
{"dep_pkg2","0.0.5"},
{"dep_pkg7","0.1.2"},