summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2018-10-14 09:37:50 -0600
committerGitHub <noreply@github.com>2018-10-14 09:37:50 -0600
commita80d1988963698717548ba269d7e5f915fca4e27 (patch)
tree7ae62971dd05db16b5914f92a6bb1b97607231cd
parent1df574a6f55506d606020d64f42c33f8bbf16a7b (diff)
fix finding transitive deps with prerelease versions (#1914)
-rw-r--r--rebar.config2
-rw-r--r--rebar.lock4
-rw-r--r--src/rebar_packages.erl20
-rw-r--r--test/rebar_pkg_SUITE.erl16
4 files changed, 25 insertions, 17 deletions
diff --git a/rebar.config b/rebar.config
index 1c19a91..202bb0d 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,7 +1,7 @@
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
-{deps, [{erlware_commons, "1.2.0"},
+{deps, [{erlware_commons, "1.3.0"},
{ssl_verify_fun, "1.1.3"},
{certifi, "2.3.1"},
{parse_trans, "3.3.0"}, % force otp-21 compat
diff --git a/rebar.lock b/rebar.lock
index 0bf16f9..a17e688 100644
--- a/rebar.lock
+++ b/rebar.lock
@@ -3,7 +3,7 @@
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.3.1">>},0},
{<<"cf">>,{pkg,<<"cf">>,<<"0.2.2">>},0},
{<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.4.2">>},0},
- {<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"1.2.0">>},0},
+ {<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"1.3.0">>},0},
{<<"eunit_formatters">>,{pkg,<<"eunit_formatters">>,<<"0.5.0">>},0},
{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0},
{<<"hex_core">>,{pkg,<<"hex_core">>,<<"0.2.0">>},0},
@@ -17,7 +17,7 @@
{<<"certifi">>, <<"D0F424232390BF47D82DA8478022301C561CF6445B5B5FB6A84D49A9E76D2639">>},
{<<"cf">>, <<"7F2913FFF90ABCABD0F489896CFEB0B0674F6C8DF6C10B17A83175448029896C">>},
{<<"cth_readable">>, <<"0F57B4EB7DA7F5438F422312245F9143A1B3118C11B6BAE5C3D1391C9EE88322">>},
- {<<"erlware_commons">>, <<"2BAB99CF88941145767A502F1209886F1F0D31695EEF21978A30F15E645721E0">>},
+ {<<"erlware_commons">>, <<"1705CF2AB4212EF235C21971A55E22E2A39055C05B9C65C8848126865F42A07A">>},
{<<"eunit_formatters">>, <<"6A9133943D36A465D804C1C5B6E6839030434B8879C5600D7DDB5B3BAD4CCB59">>},
{<<"getopt">>, <<"C73A9FA687B217F2FF79F68A3B637711BB1936E712B521D8CE466B29CBF7808A">>},
{<<"hex_core">>, <<"3A7EACCFB8ADD3FF05D950C10ED5BDB5D0C48C988EBBC5D7AE2A55498F0EFF1B">>},
diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl
index 7676213..6faa5e1 100644
--- a/src/rebar_packages.erl
+++ b/src/rebar_packages.erl
@@ -55,11 +55,13 @@ get_all_names(State) ->
_='_'},
[], ['$1']}])).
--spec get_package_versions(unicode:unicode_binary(), unicode:unicode_binary(),
+-spec get_package_versions(unicode:unicode_binary(), ec_semver:semver(),
+ unicode:unicode_binary(),
ets:tid(), rebar_state:t()) -> [vsn()].
-get_package_versions(Dep, Repo, Table, State) ->
+get_package_versions(Dep, {_, AlphaInfo}, Repo, Table, State) ->
?MODULE:verify_table(State),
- AllowPreRelease = rebar_state:get(State, deps_allow_prerelease, false),
+ AllowPreRelease = rebar_state:get(State, deps_allow_prerelease, false)
+ orelse AlphaInfo =/= {[],[]},
ets:select(Table, [{#package{key={Dep, {'$1', '$2'}, Repo},
_='_'},
[{'==', '$2', {{[],[]}}} || not AllowPreRelease], [{{'$1', '$2'}}]}]).
@@ -180,7 +182,7 @@ find_highest_matching(Dep, Constraint, Repo, Table, State) ->
end.
find_highest_matching_(Dep, Constraint, #{name := Repo}, Table, State) ->
- try get_package_versions(Dep, Repo, Table, State) of
+ try get_package_versions(Dep, Constraint, Repo, Table, State) of
[Vsn] ->
handle_single_vsn(Vsn, Constraint);
Vsns ->
@@ -292,7 +294,7 @@ resolve_version(Dep, DepVsn, Hash, HexRegistry, State) when is_binary(Hash) ->
end;
resolve_version(Dep, undefined, Hash, HexRegistry, State) ->
Fun = fun(Repo) ->
- case highest_matching(Dep, "0", Repo, HexRegistry, State) of
+ case highest_matching(Dep, {0,{[],[]}}, Repo, HexRegistry, State) of
none ->
not_found;
{ok, Vsn} ->
@@ -360,9 +362,9 @@ resolve_version_(Dep, DepVsn, Repo, HexRegistry, State) ->
end.
rm_ws(<<" ", R/binary>>) ->
- rm_ws(R);
+ ec_semver:parse(rm_ws(R));
rm_ws(R) ->
- R.
+ ec_semver:parse(R).
valid_vsn(Vsn) ->
%% Regepx from https://github.com/sindresorhus/semver-regex/blob/master/index.js
@@ -375,7 +377,7 @@ highest_matching(Dep, Vsn, Repo, HexRegistry, State) ->
find_highest_matching_(Dep, Vsn, #{name => Repo}, HexRegistry, State).
cmp(Dep, Vsn, Repo, HexRegistry, State, CmpFun) ->
- case get_package_versions(Dep, Repo, HexRegistry, State) of
+ case get_package_versions(Dep, Vsn, Repo, HexRegistry, State) of
[] ->
none;
Vsns ->
@@ -398,7 +400,7 @@ cmp_(BestMatch, MinVsn, [Vsn | R], CmpFun) ->
%% We need to treat this differently since we want a version that is LOWER but
%% the higest possible one.
cmpl(Dep, Vsn, Repo, HexRegistry, State, CmpFun) ->
- case get_package_versions(Dep, Repo, HexRegistry, State) of
+ case get_package_versions(Dep, Vsn, Repo, HexRegistry, State) of
[] ->
none;
Vsns ->
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl
index b8495fd..ee74af5 100644
--- a/test/rebar_pkg_SUITE.erl
+++ b/test/rebar_pkg_SUITE.erl
@@ -225,19 +225,24 @@ pkgs_provider(Config) ->
find_highest_matching(_Config) ->
State = rebar_state:new(),
{ok, Vsn} = rebar_packages:find_highest_matching_(
- <<"goodpkg">>, <<"1.0.0">>, #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
+ <<"goodpkg">>, ec_semver:parse(<<"1.0.0">>), #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
?assertEqual({{1,0,1},{[],[]}}, Vsn),
{ok, Vsn1} = rebar_packages:find_highest_matching(
- <<"goodpkg">>, <<"1.0">>, #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
+ <<"goodpkg">>, ec_semver:parse(<<"1.0">>), #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
?assertEqual({{1,1,1},{[],[]}}, Vsn1),
{ok, Vsn2} = rebar_packages:find_highest_matching(
- <<"goodpkg">>, <<"2.0">>, #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
+ <<"goodpkg">>, ec_semver:parse(<<"2.0">>), #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
?assertEqual({{2,0,0},{[],[]}}, Vsn2),
%% regression test. ~> constraints higher than the available packages would result
%% in returning the first package version instead of 'none'.
- ?assertEqual(none, rebar_packages:find_highest_matching_(<<"goodpkg">>, <<"~> 5.0">>,
- #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State)).
+ ?assertEqual(none, rebar_packages:find_highest_matching_(<<"goodpkg">>, ec_semver:parse(<<"5.0">>),
+ #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State)),
+
+
+ {ok, Vsn3} = rebar_packages:find_highest_matching_(<<"goodpkg">>, ec_semver:parse(<<"3.0.0-rc.0">>),
+ #{name => <<"hexpm">>}, ?PACKAGE_TABLE, State),
+ ?assertEqual({{3,0,0},{[<<"rc">>,0],[]}}, Vsn3).
%%%%%%%%%%%%%%%
%%% Helpers %%%
@@ -253,6 +258,7 @@ mock_config(Name, Config) ->
{{<<"goodpkg">>,<<"1.0.1">>}, [[], ?good_checksum, [<<"rebar3">>]]},
{{<<"goodpkg">>,<<"1.1.1">>}, [[], ?good_checksum, [<<"rebar3">>]]},
{{<<"goodpkg">>,<<"2.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]},
+ {{<<"goodpkg">>,<<"3.0.0-rc.0">>}, [[], ?good_checksum, [<<"rebar3">>]]},
{{<<"badpkg">>,<<"1.0.0">>}, [[], ?badpkg_checksum, [<<"rebar3">>]]}
],
ets:insert_new(Tid, AllDeps),