summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-07-26 07:52:18 +0100
committerFred Hebert <mononcqc@ferd.ca>2015-07-26 07:52:18 +0100
commite2b4dcdb4c68c8142aba9835a5ee4c644aef4e9b (patch)
tree5312e3762996feb316a813880b85aada69bdb173 /src
parentbe1b16aea5650b57e28a77db044be27096b60c64 (diff)
parentc983675b9ef8499a41e18ee6b8d83d11d75bd6b7 (diff)
Merge pull request #642 from tsloughter/validate-otp-version
Validate otp version
Diffstat (limited to 'src')
-rw-r--r--src/rebar_app_discover.erl4
-rw-r--r--src/rebar_prv_install_deps.erl3
-rw-r--r--src/rebar_utils.erl52
3 files changed, 58 insertions, 1 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index f55a4d5..95b3273 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -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),
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 8bb394a..69956f0 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -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),
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index c8b9e10..bcb4777 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -60,7 +60,9 @@
set_httpc_options/0,
escape_chars/1,
escape_double_quotes/1,
- escape_double_quotes_weak/1]).
+ escape_double_quotes_weak/1,
+ check_min_otp_version/1,
+ check_blacklisted_otp_versions/1]).
%% for internal use only
-export([otp_release/0]).
@@ -299,9 +301,57 @@ line_count(PatchLines) ->
Tokenized = string:tokens(PatchLines, "\n"),
{ok, length(Tokenized)}.
+check_min_otp_version(undefined) ->
+ ok;
+check_min_otp_version(MinOtpVersion) ->
+ %% Fully-qualify with ?MODULE so the function can be meck'd in rebar_utils_SUITE
+ OtpRelease = ?MODULE:otp_release(),
+ ParsedMin = version_tuple(MinOtpVersion),
+ ParsedVsn = version_tuple(OtpRelease),
+
+ case ParsedVsn >= ParsedMin of
+ true ->
+ ?DEBUG("~s satisfies the requirement for minimum OTP version ~s",
+ [OtpRelease, MinOtpVersion]);
+ false ->
+ ?ABORT("OTP release ~s or later is required. Version in use: ~s",
+ [MinOtpVersion, OtpRelease])
+ end.
+
+check_blacklisted_otp_versions(undefined) ->
+ ok;
+check_blacklisted_otp_versions(BlacklistedRegexes) ->
+ %% Fully-qualify with ?MODULE so the function can be meck'd in rebar_utils_SUITE
+ OtpRelease = ?MODULE:otp_release(),
+ lists:foreach(
+ fun(BlacklistedRegex) -> abort_if_blacklisted(BlacklistedRegex, OtpRelease) end,
+ BlacklistedRegexes).
+
+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])
+ end.
+
+
%% ====================================================================
%% Internal functions
%% ====================================================================
+version_tuple(OtpRelease) ->
+ 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), 0};
+ {match, [_Full, Maj]} ->
+ {list_to_integer(Maj), 0, 0};
+ nomatch ->
+ ?ABORT("Minimum OTP release unable to be parsed: ~s", [OtpRelease])
+ end.
otp_release() ->
otp_release1(erlang:system_info(otp_release)).