From 07d71d237081843658ee3256fbee2e1c3180daa1 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Wed, 27 Jan 2016 02:57:07 -0800 Subject: [PATCH] check ocaml version in configure script Summary: public Infer depends on OCaml >= 4.02.3 now. Reviewed By: jberdine Differential Revision: D2865159 fb-gh-sync-id: 5ec45e5 --- build-infer.sh | 10 +++++++++- configure.ac | 2 ++ m4/ac_assert_ocaml_min_version.m4 | 22 +++++++++++++++++++++ m4/ac_check_ocaml_pkg_path.m4 | 26 ++++--------------------- m4/compare_version_strings.m4 | 32 +++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 m4/ac_assert_ocaml_min_version.m4 create mode 100644 m4/compare_version_strings.m4 diff --git a/build-infer.sh b/build-infer.sh index 581d24272..ae5787ada 100755 --- a/build-infer.sh +++ b/build-infer.sh @@ -37,6 +37,7 @@ function usage() { BUILD_CLANG=no BUILD_JAVA=no INTERACTIVE=yes +ORIG_ARGS="$*" while [[ $# > 0 ]]; do opt_key="$1" @@ -166,4 +167,11 @@ echo " *************************" echo ./configure $CONFIGURE_ARGS -make -j $TARGETS || (echo 'compilation failure; try running "make clean"'; exit 1) +make -j $TARGETS || ( + echo + echo ' compilation failure; you can try running' + echo + echo ' make clean' + echo " $0 $ORIG_ARGS" + echo + exit 1) diff --git a/configure.ac b/configure.ac index 55bcbde43..ad841d24b 100644 --- a/configure.ac +++ b/configure.ac @@ -151,6 +151,8 @@ fi # OCaml dependencies AC_PROG_OCAML AC_ASSERT_PROG([ocamlc], [$OCAMLC]) +# check the version of OCaml +AC_ASSERT_OCAML_MIN_VERSION([4.02.0]) AC_ASSERT_PROG([ocamlopt], [$OCAMLOPT]) AC_ASSERT_PROG([ocamlbuild], [$OCAMLBUILD]) AC_PROG_FINDLIB diff --git a/m4/ac_assert_ocaml_min_version.m4 b/m4/ac_assert_ocaml_min_version.m4 new file mode 100644 index 000000000..f0585f820 --- /dev/null +++ b/m4/ac_assert_ocaml_min_version.m4 @@ -0,0 +1,22 @@ +dnl Copyright (c) 2016 - present Facebook, Inc. +dnl All rights reserved. +dnl +dnl This source code is licensed under the BSD style license found in the +dnl LICENSE file in the root directory of this source tree. An additional grant +dnl of patent rights can be found in the PATENTS file in the same directory. + +AC_DEFUN([AC_ASSERT_OCAML_MIN_VERSION], +[dnl + AC_REQUIRE([AC_PROG_OCAML]) + + AC_MSG_CHECKING([if OCaml version is >= $1]) + + AC_COMPARE_VERSION_STRINGS([$1], [$OCAMLVERSION], + [AC_MSG_RESULT([yes])], + [AC_MSG_ERROR([m4_join([],[found version $OCAMLVERSION. + m4_newline([ Please upgrade to OCaml >= $1. If you are using opam, you can run]) + m4_newline([dnl + opam switch $1 + eval \$(opam config env)]) +])])]) +]) diff --git a/m4/ac_check_ocaml_pkg_path.m4 b/m4/ac_check_ocaml_pkg_path.m4 index b5a9a008e..eb7825332 100644 --- a/m4/ac_check_ocaml_pkg_path.m4 +++ b/m4/ac_check_ocaml_pkg_path.m4 @@ -28,28 +28,10 @@ AC_DEFUN([AC_CHECK_OCAML_PKG_PATH], path=`$OCAMLFIND query $pkg 2>/dev/null` if test "x$3" != "x"; then version=`$OCAMLFIND query -format '%v' $pkg 2>/dev/null` - unset major_req - unset minor_req - unset patch_req - unset major_inst - unset minor_inst - unset patch_inst - - major_req=$(printf "$3" | cut -d . -f 1) - minor_req=$(printf "$3" | cut -d . -f 2) - patch_req=$(printf "$3" | cut -d . -f 3) - - major_inst=$(printf "$version" | cut -d . -f 1) - minor_inst=$(printf "$version" | cut -d . -f 2) - # discard trailing characters after patch number, eg 1.2.3+4~5 -> 3 - patch_inst=$(printf "$version" | cut -d . -f 3 | grep -o -e '^[[[:digit:]]]*') - if test $major_inst -gt $major_req || \ - (test $major_inst -eq $major_req && \ - (test $minor_inst -gt $minor_req || \ - (test $minor_inst -eq $minor_req && \ - test $path_inst -ge $path_req))); then - found=yes - fi + AC_COMPARE_VERSION_STRINGS([$3], [$version], + [found=yes], + [], + ) else found=yes fi diff --git a/m4/compare_version_strings.m4 b/m4/compare_version_strings.m4 new file mode 100644 index 000000000..f4d35ba52 --- /dev/null +++ b/m4/compare_version_strings.m4 @@ -0,0 +1,32 @@ +dnl Copyright (c) 2016 - present Facebook, Inc. +dnl All rights reserved. +dnl +dnl This source code is licensed under the BSD style license found in the +dnl LICENSE file in the root directory of this source tree. An additional grant +dnl of patent rights can be found in the PATENTS file in the same directory. + +AC_DEFUN([AC_COMPARE_VERSION_STRINGS], +[dnl + unset major_req + unset minor_req + unset patch_req + unset major_inst + unset minor_inst + unset patch_inst + + major_req=$(printf "$1" | cut -d . -f 1) + minor_req=$(printf "$1" | cut -d . -f 2) + patch_req=$(printf "$1" | cut -d . -f 3) + + major_inst=$(printf "$2" | cut -d . -f 1) + minor_inst=$(printf "$2" | cut -d . -f 2) + # discard trailing characters after patch number, eg 1.2.3+4~5 -> 3 + patch_inst=$(printf "$2" | cut -d . -f 3 | grep -o -e '^[[[:digit:]]]*') + AS_IF([test $major_inst -gt $major_req || \ + (test $major_inst -eq $major_req && \ + (test $minor_inst -gt $minor_req || \ + (test $minor_inst -eq $minor_req && \ + test $patch_inst -ge $patch_req)))], + $3, + $4) +])