diff --git a/apps/rebar/src/rebar_packages.erl b/apps/rebar/src/rebar_packages.erl index 5f39ac39b..445d7a06c 100644 --- a/apps/rebar/src/rebar_packages.erl +++ b/apps/rebar/src/rebar_packages.erl @@ -376,31 +376,31 @@ handle_missing_no_exception(Fun, Dep, State) -> resolve_version_(Dep, DepVsn, Repo, HexRegistry, State) -> case DepVsn of <<"~>", Vsn/binary>> -> - highest_matching(Dep, rm_ws(Vsn), Repo, HexRegistry, State); + highest_matching(Dep, process_vsn(Vsn), Repo, HexRegistry, State); <<">=", Vsn/binary>> -> - cmp(Dep, rm_ws(Vsn), Repo, HexRegistry, State, fun ec_semver:gte/2); + cmp(Dep, process_vsn(Vsn), Repo, HexRegistry, State, fun ec_semver:gte/2); <<">", Vsn/binary>> -> - cmp(Dep, rm_ws(Vsn), Repo, HexRegistry, State, fun ec_semver:gt/2); + cmp(Dep, process_vsn(Vsn), Repo, HexRegistry, State, fun ec_semver:gt/2); <<"<=", Vsn/binary>> -> - cmpl(Dep, rm_ws(Vsn), Repo, HexRegistry, State, fun ec_semver:lte/2); + cmpl(Dep, process_vsn(Vsn), Repo, HexRegistry, State, fun ec_semver:lte/2); <<"<", Vsn/binary>> -> - cmpl(Dep, rm_ws(Vsn), Repo, HexRegistry, State, fun ec_semver:lt/2); + cmpl(Dep, process_vsn(Vsn), Repo, HexRegistry, State, fun ec_semver:lt/2); <<"==", Vsn/binary>> -> {ok, Vsn}; Vsn -> {ok, Vsn} end. -rm_ws(<<" ", R/binary>>) -> - ec_semver:parse(rm_ws(R)); -rm_ws(R) -> - ec_semver:parse(R). +process_vsn(Vsn) -> + [Vsn1|_] = string:split(Vsn, <<" or ">>), + Vsn2 = string:trim(Vsn1), + ec_semver:parse(Vsn2). valid_vsn(Vsn) -> %% Regepx from https://github.com/sindresorhus/semver-regex/blob/master/index.js SemVerRegExp = "v?(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?" "(-[0-9a-z-]+(\\.[0-9a-z-]+)*)?(\\+[0-9a-z-]+(\\.[0-9a-z-]+)*)?", - SupportedVersions = "^(>=?|<=?|~>|==)?\\s*" ++ SemVerRegExp ++ "$", + SupportedVersions = "^(>=?|<=?|~>|==)?\\s*" ++ SemVerRegExp ++ "( or .*)?$", re:run(Vsn, SupportedVersions, [unicode]) =/= nomatch. highest_matching(Dep, Vsn, Repo, HexRegistry, State) -> diff --git a/apps/rebar/test/rebar_deps_SUITE.erl b/apps/rebar/test/rebar_deps_SUITE.erl index 0618bd2c0..84e4b9e7a 100644 --- a/apps/rebar/test/rebar_deps_SUITE.erl +++ b/apps/rebar/test/rebar_deps_SUITE.erl @@ -499,6 +499,8 @@ valid_version(_Config) -> ?assert(rebar_packages:valid_vsn(<<"~>0.1.0">>)), ?assert(rebar_packages:valid_vsn(<<"~> 0.1.0">>)), ?assert(rebar_packages:valid_vsn(<<"~> 0.1.0">>)), + ?assert(rebar_packages:valid_vsn(<<"~> 0.1 or 0.5">>)), + ?assert(rebar_packages:valid_vsn(<<"~> 0.1-or-something">>)), ?assertNot(rebar_packages:valid_vsn(<<"> 0.1.0 and < 0.2.0">>)), ok. diff --git a/apps/rebar/test/rebar_pkg_repos_SUITE.erl b/apps/rebar/test/rebar_pkg_repos_SUITE.erl index 1a29fc63d..76654c131 100644 --- a/apps/rebar/test/rebar_pkg_repos_SUITE.erl +++ b/apps/rebar/test/rebar_pkg_repos_SUITE.erl @@ -14,7 +14,9 @@ all() -> groups() -> [{resolve_version, [use_first_repo_match, use_exact_with_hash, fail_repo_update, - ignore_match_in_excluded_repo, optional_prereleases]}]. + ignore_match_in_excluded_repo, optional_prereleases, + or_in_prerelease + ]}]. init_per_group(resolve_version, Config) -> Repo1 = <<"test-repo-1">>, @@ -106,7 +108,7 @@ init_per_testcase(ignore_match_in_excluded_repo, Config) -> fun(_State) -> true end), [{state, State} | Config]; -init_per_testcase(optional_prereleases, Config) -> +init_per_testcase(Case, Config) when Case =:= optional_prereleases; Case =:= or_in_prerelease -> Deps = ?config(deps, Config), Repos = ?config(repos, Config), @@ -145,7 +147,8 @@ end_per_testcase(Case, _Config) when Case =:= use_first_repo_match ; Case =:= use_exact_with_hash ; Case =:= fail_repo_update ; Case =:= ignore_match_in_excluded_repo ; - Case =:= optional_prereleases -> + Case =:= optional_prereleases ; + Case =:= or_in_prerelease -> meck:unload(rebar_packages); end_per_testcase(_, _) -> ok. @@ -459,6 +462,24 @@ optional_prereleases(Config) -> rebar_packages:resolve_version(<<"B">>, <<"~> 1.5.0">>, <<"inner checksum">>, <<"outer checksum">>, ?PACKAGE_TABLE, State1)). +or_in_prerelease(Config) -> + State = ?config(state, Config), + + ?assertMatch({ok,{package,{<<"B">>, {{1,5,0}, {[],[]}}, Hexpm}, + <<"inner checksum">>,<<"outer checksum">>, false, []}, + #{name := Hexpm, + http_adapter := {rebar_httpc_adapter, #{profile := rebar}}}}, + rebar_packages:resolve_version(<<"B">>, <<"~> 1.5.0">>, undefined, undefined, + ?PACKAGE_TABLE, State)), + + State1 = rebar_state:set(State, deps_allow_prerelease, true), + ?assertMatch({ok,{package,{<<"B">>, {{1,5,6}, {[<<"rc">>,0],[]}}, Hexpm}, + <<"inner checksum">>,<<"outer checksum">>, true, []}, + #{name := Hexpm, + http_adapter := {rebar_httpc_adapter, #{profile := rebar}}}}, + rebar_packages:resolve_version(<<"B">>, <<"~> 1.5.5-a-or-b.0">>, <<"inner checksum">>, <<"outer checksum">>, + ?PACKAGE_TABLE, State1)). + %% setup_deps_and_repos(Deps, Repos) ->