Browse Source

add support for old format otp versions

pull/642/head
Tristan Sloughter 9 years ago
parent
commit
90fbd6dbb9
4 changed files with 34 additions and 16 deletions
  1. +4
    -0
      src/rebar_app_discover.erl
  2. +3
    -0
      src/rebar_prv_install_deps.erl
  3. +16
    -15
      src/rebar_utils.erl
  4. +11
    -1
      test/rebar_utils_SUITE.erl

+ 4
- 0
src/rebar_app_discover.erl View File

@ -51,6 +51,10 @@ merge_deps(AppInfo, State) ->
rebar_state:apply_profiles(
rebar_state:new(reset_hooks(rebar_state:opts(State, Default)), C,
rebar_app_info:dir(AppInfo)), CurrentProfiles), Name),
rebar_utils:check_min_otp_version(rebar_state:get(AppState, minimum_otp_vsn, undefined)),
rebar_utils:check_blacklisted_otp_versions(rebar_state:get(AppState, blacklisted_otp_vsns, [])),
AppState1 = rebar_state:set(AppState, artifacts, []),
AppInfo1 = rebar_app_info:state(AppInfo, AppState1),

+ 3
- 0
src/rebar_prv_install_deps.erl View File

@ -386,6 +386,9 @@ handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) ->
S4 = rebar_state:set(S3, {plugins, Profile}, Plugins),
AppInfo1 = rebar_app_info:state(AppInfo, S4),
rebar_utils:check_min_otp_version(rebar_state:get(S4, minimum_otp_vsn, undefined)),
rebar_utils:check_blacklisted_otp_versions(rebar_state:get(S4, blacklisted_otp_vsns, [])),
%% Dep may have plugins to install. Find and install here.
S5 = rebar_plugins:install(S4),
AppInfo2 = rebar_app_info:state(AppInfo1, S5),

+ 16
- 15
src/rebar_utils.erl View File

@ -306,16 +306,16 @@ check_min_otp_version(undefined) ->
check_min_otp_version(MinOtpVersion) ->
%% Fully-qualify with ?MODULE so the function can be meck'd in rebar_utils_SUITE
OtpRelease = ?MODULE:otp_release(),
{MinMajor, MinMinor} = version_tuple(MinOtpVersion),
{OtpMajor, OtpMinor} = version_tuple(OtpRelease),
ParsedMin = version_tuple(MinOtpVersion),
ParsedVsn = version_tuple(OtpRelease),
case {OtpMajor, OtpMinor} >= {MinMajor, MinMinor} of
case ParsedVsn >= ParsedMin of
true ->
?DEBUG("~s satisfies the requirement for minimum OTP version ~s",
[OtpRelease, MinOtpVersion]);
[OtpRelease, MinOtpVersion]);
false ->
?ABORT("OTP release ~s or later is required. Verion in use: ~s",
[MinOtpVersion, OtpRelease])
?ABORT("OTP release ~s or later is required. Version in use: ~s",
[MinOtpVersion, OtpRelease])
end.
check_blacklisted_otp_versions(undefined) ->
@ -331,10 +331,10 @@ abort_if_blacklisted(BlacklistedRegex, OtpRelease) ->
case re:run(OtpRelease, BlacklistedRegex, [{capture, none}]) of
match ->
?ABORT("OTP release ~s matches blacklisted version ~s",
[OtpRelease, BlacklistedRegex]);
nomatch ->
?DEBUG("~s does not match blacklisted OTP version ~s",
[OtpRelease, BlacklistedRegex])
[OtpRelease, BlacklistedRegex]);
nomatch ->
?DEBUG("~s does not match blacklisted OTP version ~s",
[OtpRelease, BlacklistedRegex])
end.
@ -342,14 +342,15 @@ abort_if_blacklisted(BlacklistedRegex, OtpRelease) ->
%% Internal functions
%% ====================================================================
version_tuple(OtpRelease) ->
case re:run(OtpRelease, "R?(\\d+)B?-?(\\d+)?", [{capture, all, list}]) of
case re:run(OtpRelease, "R?(\\d+)B?.?-?(\\d+)?.?-?(\\d+)?", [{capture, all, list}]) of
{match, [_Full, Maj, Min, Patch]} ->
{list_to_integer(Maj), list_to_integer(Min), list_to_integer(Patch)};
{match, [_Full, Maj, Min]} ->
{list_to_integer(Maj), list_to_integer(Min)};
{list_to_integer(Maj), list_to_integer(Min), 0};
{match, [_Full, Maj]} ->
{list_to_integer(Maj), 0};
{list_to_integer(Maj), 0, 0};
nomatch ->
?WARN("", []),
{0,0}
?ABORT("Minimum OTP release unable to be parsed: ~s", [OtpRelease])
end.
otp_release() ->

+ 11
- 1
test/rebar_utils_SUITE.erl View File

@ -150,7 +150,17 @@ valid_otp_version(_Config) ->
valid_old_format_otp_version(_Config) ->
meck:new(rebar_utils, [passthrough]),
meck:expect(rebar_utils, otp_release, fun() -> "R15B03-1" end),
rebar_utils:check_min_otp_version("R15"),
rebar_utils:check_min_otp_version("14"),
meck:expect(rebar_utils, otp_release, fun() -> "R16B03" end),
rebar_utils:check_min_otp_version("16.0"),
meck:expect(rebar_utils, otp_release, fun() -> "18.0.1" end),
rebar_utils:check_min_otp_version("17.5.4"),
meck:expect(rebar_utils, otp_release, fun() -> "18.0-rc1" end),
?assertException(throw, rebar_abort, rebar_utils:check_min_otp_version("19")),
meck:unload(rebar_utils).
valid_otp_version_equal(_Config) ->

Loading…
Cancel
Save