From 9830e29945876a0c2e3c290b8a8dce2889393c60 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Fri, 9 Mar 2018 20:48:36 -0500 Subject: [PATCH] fix version generation --- Makefile | 14 +++----------- src/getxattr.cpp | 2 ++ src/option_parser.cpp | 13 +++---------- tools/update-version | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 21 deletions(-) create mode 100755 tools/update-version diff --git a/Makefile b/Makefile index 7a1303bd..0137632c 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ help: @echo "usage: make" @echo "make XATTR_AVAILABLE=0 - to build program without xattrs functionality (auto discovered otherwise)" -$(TARGET): src/version.hpp obj/obj-stamp libfuse/lib/.libs/libfuse.a $(OBJ) +$(TARGET): version obj/obj-stamp libfuse/lib/.libs/libfuse.a $(OBJ) cd libfuse && make $(CXX) $(CFLAGS) $(OBJ) -o $@ libfuse/lib/.libs/libfuse.a -ldl $(LDFLAGS) @@ -102,15 +102,7 @@ ifeq ($(GIT_REPO),1) endif version: -ifeq ($(GIT_REPO),1) - $(eval VERSION := $(shell $(GIT) describe --always --tags --dirty)) - @echo "$(VERSION)" > VERSION -endif - -src/version.hpp: version - $(eval VERSION := $(shell cat VERSION)) - @echo "#pragma once" > src/version.hpp - @echo "static const char MERGERFS_VERSION[] = \"$(VERSION)\";" >> src/version.hpp + tools/update-version obj/obj-stamp: $(MKDIR) -p obj @@ -229,6 +221,6 @@ endif libfuse/lib/.libs/libfuse.a: libfuse_Makefile cd libfuse && $(MAKE) -.PHONY: all clean install help +.PHONY: all clean install help version -include $(DEPS) diff --git a/src/getxattr.cpp b/src/getxattr.cpp index e86d424b..55187624 100644 --- a/src/getxattr.cpp +++ b/src/getxattr.cpp @@ -148,6 +148,8 @@ void _getxattr_controlfile_version(string &attrvalue) { attrvalue = MERGERFS_VERSION; + if(attrvalue.empty()) + attrvalue = "unknown_possible_problem_with_build"; } static diff --git a/src/option_parser.cpp b/src/option_parser.cpp index 01e13f4a..4f93bed3 100644 --- a/src/option_parser.cpp +++ b/src/option_parser.cpp @@ -305,15 +305,6 @@ usage(void) << std::endl; } -static -void -version(void) -{ - std::cout << "mergerfs version: " - << MERGERFS_VERSION - << std::endl; -} - static int option_processor(void *data, @@ -344,7 +335,9 @@ option_processor(void *data, break; case MERGERFS_OPT_VERSION: - version(); + std::cout << "mergerfs version: " + << (MERGERFS_VERSION[0] ? MERGERFS_VERSION : "unknown") + << std::endl; fuse_opt_add_arg(outargs,"--version"); break; diff --git a/tools/update-version b/tools/update-version new file mode 100755 index 00000000..fef0f950 --- /dev/null +++ b/tools/update-version @@ -0,0 +1,16 @@ +#!/bin/sh + +GIT=$(which git) +if [ "${GIT}" = "" ]; then + exit 0 +fi + +VERSION=$(git describe --always --tags --dirty) + +echo -n "${VERSION}" > VERSION +grep -q \"${VERSION}\" src/version.hpp +RV=$? +if [ $RV -ne 0 ]; then + echo "#pragma once" > src/version.hpp + echo "static const char MERGERFS_VERSION[] = \"${VERSION}\";" >> src/version.hpp +fi