output sensible version number without git or .git

Summary:
Create infer/src/backend/version.ml even if git is not installed or returns
errors. This is useful for source releases of Infer, which need to be able to
produce a sensible version number without a .git repository.

See also #167.
master
Jules Villard 9 years ago
parent 6f65486942
commit 6e29be8559

@ -5,6 +5,10 @@
# LICENSE file in the root directory of this source tree. An additional grant # LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory. # of patent rights can be found in the PATENTS file in the same directory.
INFER_VERSION_MAJOR = 0
INFER_VERSION_MINOR = 3
INFER_VERSION_PATCH = 0
REMOVE = rm -vf REMOVE = rm -vf
REMOVE_DIR = rm -rvf REMOVE_DIR = rm -rvf
COPY = cp -f -p COPY = cp -f -p
@ -194,27 +198,24 @@ init: sanitize version $(BUILDDIR)
sanitize: sanitize:
$(SANITIZE_SCRIPT) $(SANITIZE_SCRIPT)
ifneq ($(shell which git),)
MAJOR = 0
MINOR = 3
PATCH = 0
GIT_COMMIT = $(shell git rev-parse HEAD | awk '{print $0; exit}' | xargs echo -n | sed 's/[\/&]/\\&/g')
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD | awk '{print $0; exit}' | xargs echo -n | sed 's/[\/&]/\\&/g')
GIT_TAG = $(shell git tag --points-at $(GIT_COMMIT))
version: version:
sed -e 's/@MAJOR@/$(MAJOR)/g' \ GIT_COMMIT=$$(git rev-parse HEAD 2> /dev/null \
-e 's/@MINOR@/$(MINOR)/g' \ || printf "unknown commit"); \
-e 's/@PATCH@/$(PATCH)/g' \ GIT_BRANCH=$$(git rev-parse --abbrev-ref HEAD 2> /dev/null \
-e 's/@GIT_COMMIT@/$(GIT_COMMIT)/g' \ || printf "unknown branch"); \
-e 's/@GIT_BRANCH@/$(GIT_BRANCH)/g' \ UNKNOWN="-unknown"; \
-e 's/@GIT_TAG@/$(GIT_TAG)/g' \ if [ -e "$(ROOT)/.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.in > $(BACKEND_SOURCES)/version.ml
else
version:
$(info Infer is not tracked, not updating $(BACKEND_SOURCES)/version.ml)
endif
$(BUILDDIR): $(BUILDDIR):
$(MKDIR) $(BUILDDIR) $(MKDIR) $(BUILDDIR)
@ -243,4 +244,7 @@ $(CHECKCOPYRIGHT_BINARY): $(BUILDDIR)/$(CHECKCOPYRIGHT_MAIN).native
clean: $(BUILDDIR) clean: $(BUILDDIR)
$(OCAMLBUILD) -clean $(OCAMLBUILD) -clean
$(REMOVE_DIR) $(ANNOTDIR) $(REMOVE_DIR) $(ANNOTDIR)
$(REMOVE) $(TYPEPROP_BINARY) $(INFERANALYZE_BINARY) $(INFERPRINT_BINARY) $(INFERJAVA_BINARY) $(INFERCLANG_BINARY) $(INFERLLVM_BINARY) $(CHECKCOPYRIGHT_BINARY) $(REMOVE) $(BACKEND_SOURCES)/version.ml
$(REMOVE) $(TYPEPROP_BINARY) $(INFERANALYZE_BINARY) $(INFERPRINT_BINARY)
$(REMOVE) $(INFERJAVA_BINARY) $(INFERCLANG_BINARY) $(INFERLLVM_BINARY)
$(REMOVE) $(CHECKCOPYRIGHT_BINARY)

@ -39,7 +39,8 @@ git clone https://github.com/facebook/infer.git $INFER_SOURCE
# Copy infer source # Copy infer source
mkdir -p $PKG_DIR mkdir -p $PKG_DIR
rsync -a $INFER_SOURCE/ $PKG_DIR rsync -a --exclude=".git/" --exclude=".gitmodules" --exclude=".gitignore" $INFER_SOURCE/ $PKG_DIR
touch $PKG_DIR/.release
# Add facebook-clang-plugin binaries # Add facebook-clang-plugin binaries
PKG_PLUGIN_DIR=$PKG_DIR/facebook-clang-plugins PKG_PLUGIN_DIR=$PKG_DIR/facebook-clang-plugins

Loading…
Cancel
Save