From edcc984158bb38e45cb12a9008caaae12b743983 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 15 Dec 2015 09:37:37 -0800 Subject: [PATCH] compute version number inside configure script Summary: public This moves the hardcoded version numbers in one place and simplifies the logic to compute the version a bit. Reviewed By: jberdine Differential Revision: D2759779 fb-gh-sync-id: 0e4d3c1 --- configure.ac | 27 ++++++++++++++++------ infer/src/Makefile.in | 40 ++++++++++++++------------------- infer/src/backend/version.ml.in | 18 ++++++++------- 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/configure.ac b/configure.ac index 8c6267a37..f2c104659 100644 --- a/configure.ac +++ b/configure.ac @@ -10,16 +10,29 @@ dnl of patent rights can be found in the PATENTS file in the same directory. AC_PREREQ([2.63]) -# TODO: use the stuff in infer/src/Makefile and version.ml.in instead -# of 0.4.0 -AC_INIT([Infer],[0.4.0],[https://github.com/facebook/infer/issues/]) - +# WARNING: AC_INIT only accepts string literals so the version number +# has to be kept in sync with below +AC_INIT([Infer], + [0.4.0], + [https://github.com/facebook/infer/issues/]) AC_CONFIG_SRCDIR([infer/src/backend/sil.ml]) +# WARNING: keep in sync with above +INFER_MAJOR=0 +INFER_MINOR=4 +INFER_PATCH=0 + +AC_SUBST([INFER_MAJOR]) +AC_SUBST([INFER_MINOR]) +AC_SUBST([INFER_PATCH]) + # record if we are in a release of Infer +AC_MSG_CHECKING([if we are in an Infer release build]) is_infer_release=no AS_IF([test -f ".release"], [is_infer_release=yes]) - +INFER_IS_RELEASE=$is_infer_release +AC_SUBST([INFER_IS_RELEASE]) +AC_MSG_RESULT([$is_infer_release]) # to compile the facebook-clang-plugins AC_ARG_VAR([CLANG_PREFIX], [directory where clang is installed (defaults=$PWD/facebook-clang-plugins/clang)]) @@ -49,7 +62,7 @@ AC_ARG_WITH(fcp-clang, with_fcp_clang=$is_infer_release) AS_IF([test "x$enable_c_analyzers" = "xyes"], [ - AC_MSG_CHECKING([checking whether to use the compilers in $CLANG_PREFIX/bin]) + AC_MSG_CHECKING([whether to use the compilers in $CLANG_PREFIX/bin]) case "$with_fcp_clang" in no) AC_MSG_RESULT([no]) @@ -95,7 +108,7 @@ if test "x$enable_c_analyzers" = "xyes"; then dnl clang wants either clang version >= 3.1 or gcc version >= 4.7.2 to dnl compile itself - AC_MSG_CHECKING([checking if the C/C++ compiler is recent enough]) + AC_MSG_CHECKING([if the C/C++ compiler is recent enough]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ #ifdef __clang__ #if __clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1) diff --git a/infer/src/Makefile.in b/infer/src/Makefile.in index 03e43402f..ec62809b7 100644 --- a/infer/src/Makefile.in +++ b/infer/src/Makefile.in @@ -8,9 +8,10 @@ ROOT_DIR = ../.. include $(ROOT_DIR)/Makefile.config -INFER_VERSION_MAJOR = 0 -INFER_VERSION_MINOR = 4 -INFER_VERSION_PATCH = 0 +INFER_MAJOR = @INFER_MAJOR@ +INFER_MINOR = @INFER_MINOR@ +INFER_PATCH = @INFER_PATCH@ +INFER_IS_RELEASE = @INFER_IS_RELEASE@ REMOVE = @rm -vf REMOVE_DIR = @rm -rvf @@ -148,7 +149,7 @@ DEPENDENCIES = $(BACKEND_SOURCES) checkers facebook/checkers facebook/checkers/g OCAMLBUILD = ocamlbuild $(OCAMLBUILD_OPTIONS) -build-dir $(BUILD_DIR) -j 0 $(addprefix -I , $(DEPENDENCIES)) $(JAVA_OPTIONS) -.PHONY: all java clang llvm checkCopyright build_java build_clang build_llvm build_checkCopyright annotations init sanitize version clean +.PHONY: all java clang llvm checkCopyright build_java build_clang build_llvm build_checkCopyright annotations init sanitize clean all: java clang llvm checkCopyright @@ -200,29 +201,22 @@ $(CLANG_BINIOU_DICT): $(CLANG_ATDGEN_STUB_ATD) | sort | uniq \ > $(CLANG_BINIOU_DICT) -init: sanitize version $(BUILD_DIR) +init: sanitize $(BACKEND_SOURCES)/version.ml $(BUILD_DIR) sanitize: $(SANITIZE_SCRIPT) -version: - GIT_COMMIT=$$(git rev-parse HEAD 2> /dev/null \ - || printf "unknown commit"); \ - GIT_BRANCH=$$(git rev-parse --abbrev-ref HEAD 2> /dev/null \ - || printf "unknown branch"); \ - UNKNOWN="-unknown"; \ - if [ -e "$(ROOT_DIR)/.release" ]; then \ - UNKNOWN=""; \ - fi; \ - GIT_TAG=$$(git tag --points-at HEAD 2> /dev/null \ - || printf "v$(INFER_VERSION_MAJOR).$(INFER_VERSION_MINOR).$(INFER_VERSION_PATCH)$$UNKNOWN"); \ - sed -e 's/@MAJOR@/$(INFER_VERSION_MAJOR)/g' \ - -e 's/@MINOR@/$(INFER_VERSION_MINOR)/g' \ - -e 's/@PATCH@/$(INFER_VERSION_PATCH)/g' \ - -e "s/@GIT_COMMIT@/$$GIT_COMMIT/g" \ - -e "s#@GIT_BRANCH@#$$GIT_BRANCH#g" \ - -e "s/@GIT_TAG@/$$GIT_TAG/g" \ - $(BACKEND_SOURCES)/version.ml.in > $(BACKEND_SOURCES)/version.ml +$(BACKEND_SOURCES)/version.ml: Makefile $(BACKEND_SOURCES)/version.ml.in + INFER_GIT_COMMIT=$$(git rev-parse --short HEAD || printf "unknown"); \ + INFER_GIT_BRANCH=$$(git rev-parse --abbrev-ref HEAD || printf "unknown"); \ + sed \ + -e 's|@INFER_MAJOR[@]|$(INFER_MAJOR)|g' \ + -e 's|@INFER_MINOR[@]|$(INFER_MINOR)|g' \ + -e 's|@INFER_PATCH[@]|$(INFER_PATCH)|g' \ + -e 's|@INFER_IS_RELEASE[@]|$(INFER_IS_RELEASE)|g' \ + -e "s|@INFER_GIT_COMMIT[@]|$$INFER_GIT_COMMIT|g" \ + -e "s|@INFER_GIT_BRANCH[@]|$$INFER_GIT_BRANCH|g" \ + $@.in > $@ $(BUILD_DIR): $(MKDIR) $(BUILD_DIR) diff --git a/infer/src/backend/version.ml.in b/infer/src/backend/version.ml.in index 209b99192..8a4285587 100644 --- a/infer/src/backend/version.ml.in +++ b/infer/src/backend/version.ml.in @@ -8,16 +8,18 @@ * of patent rights can be found in the PATENTS file in the same directory. *) -let major = @MAJOR@ -let minor = @MINOR@ -let patch = @PATCH@ -let commit = "@GIT_COMMIT@" -let branch = "@GIT_BRANCH@" -let tag = "@GIT_TAG@" +let major = @INFER_MAJOR@ +let minor = @INFER_MINOR@ +let patch = @INFER_PATCH@ + +let commit = "@INFER_GIT_COMMIT@" +let branch = "@INFER_GIT_BRANCH@" +let is_release = Utils.string_equal "@INFER_IS_RELEASE@" "yes" +let tag = Printf.sprintf "v%d.%d.%d" major minor patch let versionString = - if tag = "" then "git-" ^ commit - else tag + if is_release then tag + else Printf.sprintf "%s-%s" tag commit let versionJson = String.concat "\n" [ "{"; "\"major\": " ^ (string_of_int major) ^ ", ";