From a78e6cd740d996c8397d6f1cedd9e595dd3e4b6e Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Thu, 7 Jun 2012 11:57:03 -0700 Subject: [PATCH] Add support for minimum OTP versions. Since you can't really do math with regexps and it's a pain to repeatedly update the config for each new version or erlang, I wanted to add support for minium OTP versions. This is a fix for https://github.com/basho/riaknostic/issues/38 --- src/rebar_require_vsn.erl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/rebar_require_vsn.erl b/src/rebar_require_vsn.erl index 327f75c..83cb79d 100644 --- a/src/rebar_require_vsn.erl +++ b/src/rebar_require_vsn.erl @@ -67,4 +67,33 @@ check_versions(Config) -> nomatch -> ?ABORT("OTP release ~s does not match required regex ~s\n", [erlang:system_info(otp_release), OtpRegex]) + end, + + case rebar_config:get(Config, require_min_otp_vsn, undefined) of + undefined -> ?DEBUG("Min OTP version unconfigured~n", []); + MinOtpVsn -> + {MinMaj, MinMin} = version_tuple(MinOtpVsn, "configured"), + {OtpMaj, OtpMin} = version_tuple(erlang:system_info(otp_release), + "OTP Release"), + case {OtpMaj, OtpMin} >= {MinMaj, MinMin} of + true -> + ?DEBUG("~s satisfies the requirement for vsn ~s~n", + [erlang:system_info(otp_release), + MinOtpVsn]); + false -> + ?ABORT("OTP release ~s or later is required, you have: ~s~n", + [MinOtpVsn, + erlang:system_info(otp_release)]) + end + end. + +version_tuple(OtpRelease, Type) -> + case re:run(OtpRelease, "R(\\d+)B?-?(\\d+)?", [{capture, all, list}]) of + {match, [_Full, Maj, Min]} -> + {list_to_integer(Maj), list_to_integer(Min)}; + {match, [_Full, Maj]} -> + {list_to_integer(Maj), 0}; + nomatch -> + ?ABORT("Cannot parse ~s version string: ~s~n", + [Type, OtpRelease]) end.