From 0ed2cc445131663b07b547cf5aefac893b619e9a Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 27 Aug 2011 09:25:30 -0700 Subject: [PATCH] Generate version number information from git history. Due to the svn import structure, a special case is currently implemented to look for the 1.1.0 branchpoint instead of the most recent tag on the master branch. This will be removed after the first release is tagged on the master branch in git. Specific details: autogen.sh: More aggressively clean autoconf cache. This is needed to ensure the version number is actually regenerated. Don't generate PACKAGE_PATCHLEVEL or PACKAGE_BUILD variables. The genversion program now parses PACKAGE_VERSION directly. For Mkfiles builds, YASM-VERSION.h is generated and included by the custom config.h. This avoids the need to edit config.h for versioning. --- .gitignore | 2 + CMakeLists.txt | 9 +-- Makefile.am | 8 +++ Mkfiles/Makefile.flat | 7 +- Mkfiles/dj/config.h | 11 +-- Mkfiles/vc10/config.h | 11 +-- Mkfiles/vc10/genversion/genversion.vcxproj | 5 +- Mkfiles/vc10/genversion/runpre.bat | 2 + Mkfiles/vc10/yasm.sln | 3 + Mkfiles/vc9/config.h | 11 +-- Mkfiles/vc9/genversion/genversion.vcproj | 2 + Mkfiles/vc9/genversion/runpre.bat | 2 + Mkfiles/vc9/yasm.sln | 1 + YASM-VERSION-GEN.bat | 38 +++++++++++ YASM-VERSION-GEN.sh | 52 +++++++++++++++ autogen.sh | 3 +- cmake/modules/VersionGen.cmake | 78 ++++++++++++++++++++++ config.h.cmake | 6 -- configure.ac | 8 +-- frontends/tasm/tasm.c | 2 +- frontends/vsyasm/vsyasm.c | 2 +- frontends/yasm/yasm.c | 4 +- modules/preprocs/nasm/genversion.c | 23 ++++--- 23 files changed, 232 insertions(+), 58 deletions(-) create mode 100644 Mkfiles/vc10/genversion/runpre.bat create mode 100644 Mkfiles/vc9/genversion/runpre.bat create mode 100644 YASM-VERSION-GEN.bat create mode 100755 YASM-VERSION-GEN.sh create mode 100644 cmake/modules/VersionGen.cmake diff --git a/.gitignore b/.gitignore index 989c3f41..7ca446de 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,8 @@ x86regtmod.c nasm-version.c win64-gas.c win64-nasm.c +YASM-VERSION-FILE +YASM-VERSION.h .sw* *.s *.asm diff --git a/CMakeLists.txt b/CMakeLists.txt index 9237329e..b63d14b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ SET(BUILD_SHARED_LIBS ON) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") INCLUDE(YasmMacros) +INCLUDE(VersionGen) OPTION(ENABLE_NLS "Enable message translations" OFF) @@ -26,12 +27,8 @@ IF(NOT CMAKE_BUILD_TYPE) FORCE) ENDIF(NOT CMAKE_BUILD_TYPE) -set (YASM_VERSION_MAJOR 1) -set (YASM_VERSION_MINOR 1) -set (YASM_VERSION_SUBMINOR 99) -set (PACKAGE_INTVER "${YASM_VERSION_MAJOR}.${YASM_VERSION_MINOR}.${YASM_VERSION_SUBMINOR}") -set (PACKAGE_BUILD "HEAD") -set (PACKAGE_VERSION ${PACKAGE_BUILD}) +VERSION_GEN(PACKAGE_VERSION "${CMAKE_BINARY_DIR}/YASM-VERSION-FILE" "1.1.0") + set (PACKAGE_STRING "yasm ${PACKAGE_VERSION}") INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR} ${yasm_SOURCE_DIR}) diff --git a/Makefile.am b/Makefile.am index f3ed7d41..208dc67f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,6 +31,7 @@ EXTRA_DIST = config/config.rpath # libyasm-stdint.h doesn't clean up after itself? CONFIG_CLEAN_FILES = libyasm-stdint.h +CONFIG_CLEAN_FILES += YASM-VERSION-FILE EXTRA_DIST += tools/Makefile.inc EXTRA_DIST += libyasm/Makefile.inc @@ -55,6 +56,7 @@ EXTRA_DIST += BSD.txt EXTRA_DIST += GNU_GPL-2.0 EXTRA_DIST += GNU_LGPL-2.0 EXTRA_DIST += splint.sh +EXTRA_DIST += YASM-VERSION-GEN.sh EXTRA_DIST += Mkfiles/Makefile.flat EXTRA_DIST += Mkfiles/Makefile.dj EXTRA_DIST += Mkfiles/dj/config.h @@ -122,6 +124,12 @@ EXTRA_DIST += Mkfiles/vc10/re2c/run.bat # Until this gets fixed in automake DISTCLEANFILES += libyasm/stamp-h libyasm/stamp-h[0-9]* +dist-hook: YASM-VERSION-FILE + cp YASM-VERSION-FILE $(distdir)/version + +YASM-VERSION-FILE: $(top_srcdir)/YASM-VERSION-GEN.sh + $(top_srcdir)/YASM-VERSION-GEN.sh + distclean-local: -rm -rf results if HAVE_PYTHON diff --git a/Mkfiles/Makefile.flat b/Mkfiles/Makefile.flat index 3e190d73..011fbe51 100644 --- a/Mkfiles/Makefile.flat +++ b/Mkfiles/Makefile.flat @@ -197,7 +197,7 @@ win64-gas.c: modules/objfmts/coff/win64-gas.mac genmacro modules/objfmts/coff/coff-objfmt.c: win64-nasm.c win64-gas.c -genversion: modules/preprocs/nasm/genversion.c +genversion: modules/preprocs/nasm/genversion.c YASM-VERSION.h $(BUILDCC) -IMkfiles -I. -o $@ $< version.mac: genversion @@ -272,3 +272,8 @@ vsyasm: $(VSYASM_OBJS) .c.o: $(CC) -c $(CFLAGS) -o $@ $< +$(YASM_OBJS) $(YTASM_OBJS) $(VSYASM_OBJS): YASM-VERSION.h + +YASM-VERSION.h: YASM-VERSION-GEN.sh + sh YASM-VERSION-GEN.sh + diff --git a/Mkfiles/dj/config.h b/Mkfiles/dj/config.h index 46e3167e..b33554ac 100644 --- a/Mkfiles/dj/config.h +++ b/Mkfiles/dj/config.h @@ -1,3 +1,4 @@ +#include "YASM-VERSION.h" #define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail) #define yasm__abspath(path) yasm__abspath_win(path) #define yasm__combpath(from, to) yasm__combpath_win(from, to) @@ -116,23 +117,17 @@ /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "bug-yasm@tortall.net" -/* Define to build version of this package. */ -#define PACKAGE_BUILD "HEAD" - -/* Define to internal version of this package. */ -#define PACKAGE_INTVER "1.1.99" - /* Define to the full name of this package. */ #define PACKAGE_NAME "yasm" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "yasm HEAD" +/*#define PACKAGE_STRING "yasm HEAD"*/ /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "yasm" /* Define to the version of this package. */ -#define PACKAGE_VERSION "HEAD" +/*#define PACKAGE_VERSION "HEAD"*/ /* Define if the C compiler supports function prototypes. */ #define PROTOTYPES 1 diff --git a/Mkfiles/vc10/config.h b/Mkfiles/vc10/config.h index aba46abe..efb7cbe4 100644 --- a/Mkfiles/vc10/config.h +++ b/Mkfiles/vc10/config.h @@ -1,3 +1,4 @@ +#include "YASM-VERSION.h" #define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail) #define yasm__abspath(path) yasm__abspath_win(path) #define yasm__combpath(from, to) yasm__combpath_win(from, to) @@ -114,23 +115,17 @@ /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "bug-yasm@tortall.net" -/* Define to build version of this package. */ -#define PACKAGE_BUILD "HEAD" - -/* Define to internal version of this package. */ -#define PACKAGE_INTVER "1.1.99" - /* Define to the full name of this package. */ #define PACKAGE_NAME "yasm" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "yasm HEAD" +/*#define PACKAGE_STRING "yasm HEAD"*/ /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "yasm" /* Define to the version of this package. */ -#define PACKAGE_VERSION "HEAD" +/*#define PACKAGE_VERSION "HEAD"*/ /* Define if the C compiler supports function prototypes. */ #define PROTOTYPES 1 diff --git a/Mkfiles/vc10/genversion/genversion.vcxproj b/Mkfiles/vc10/genversion/genversion.vcxproj index cce7c7fd..1bfd9e7a 100644 --- a/Mkfiles/vc10/genversion/genversion.vcxproj +++ b/Mkfiles/vc10/genversion/genversion.vcxproj @@ -48,7 +48,7 @@ Disabled - ..\..\vc10;%(AdditionalIncludeDirectories) + ..\..\vc10;../../..;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true EnableFastChecks @@ -73,6 +73,9 @@ run.bat "$(TargetPath)" + + runpre.bat + diff --git a/Mkfiles/vc10/genversion/runpre.bat b/Mkfiles/vc10/genversion/runpre.bat new file mode 100644 index 00000000..fdd15708 --- /dev/null +++ b/Mkfiles/vc10/genversion/runpre.bat @@ -0,0 +1,2 @@ +cd ..\..\.. +YASM-VERSION-GEN.bat diff --git a/Mkfiles/vc10/yasm.sln b/Mkfiles/vc10/yasm.sln index 342bf07b..306c7b10 100644 --- a/Mkfiles/vc10/yasm.sln +++ b/Mkfiles/vc10/yasm.sln @@ -7,6 +7,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libyasm", "libyasm\libyasm.vcxproj", "{29FE7874-1256-4AD6-B889-68E399DC9608}" + ProjectSection(ProjectDependencies) = postProject + {B545983B-8EE0-4A7B-A67A-E749EEAE62A2} = {B545983B-8EE0-4A7B-A67A-E749EEAE62A2} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "modules", "modules\modules.vcxproj", "{D715A3D4-EFAA-442E-AD8B-5B4FF64E1DD6}" EndProject diff --git a/Mkfiles/vc9/config.h b/Mkfiles/vc9/config.h index aba46abe..efb7cbe4 100644 --- a/Mkfiles/vc9/config.h +++ b/Mkfiles/vc9/config.h @@ -1,3 +1,4 @@ +#include "YASM-VERSION.h" #define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail) #define yasm__abspath(path) yasm__abspath_win(path) #define yasm__combpath(from, to) yasm__combpath_win(from, to) @@ -114,23 +115,17 @@ /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "bug-yasm@tortall.net" -/* Define to build version of this package. */ -#define PACKAGE_BUILD "HEAD" - -/* Define to internal version of this package. */ -#define PACKAGE_INTVER "1.1.99" - /* Define to the full name of this package. */ #define PACKAGE_NAME "yasm" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "yasm HEAD" +/*#define PACKAGE_STRING "yasm HEAD"*/ /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "yasm" /* Define to the version of this package. */ -#define PACKAGE_VERSION "HEAD" +/*#define PACKAGE_VERSION "HEAD"*/ /* Define if the C compiler supports function prototypes. */ #define PROTOTYPES 1 diff --git a/Mkfiles/vc9/genversion/genversion.vcproj b/Mkfiles/vc9/genversion/genversion.vcproj index 84c92a2d..f5a01f97 100644 --- a/Mkfiles/vc9/genversion/genversion.vcproj +++ b/Mkfiles/vc9/genversion/genversion.vcproj @@ -26,6 +26,7 @@ > YASM-VERSION-FILE +echo #define PACKAGE_STRING "yasm %_ver_%" > YASM-VERSION.h +echo #define PACKAGE_VERSION "%_ver_%" >> YASM-VERSION.h + diff --git a/YASM-VERSION-GEN.sh b/YASM-VERSION-GEN.sh new file mode 100755 index 00000000..00c0136f --- /dev/null +++ b/YASM-VERSION-GEN.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +YVF=YASM-VERSION-FILE +DEF_VER=v1.1.0 + +LF=' +' + +# First see if there is a version file (included in release tarballs), +# then try git-describe, then default. +if test -f version +then + VN=$(cat version) || VN="$DEF_VER" +elif test -d .git -o -f .git && + VN=$(git describe --match "v[0-9]*" --abbrev=4 HEAD 2>/dev/null) && + case "$VN" in + *$LF*) (exit 1) ;; + v0.1.0*) + # Special handling until we get a more recent tag on the + # master branch + MERGE_BASE=$(git merge-base $DEF_VER HEAD 2>/dev/null) + VN1=$(git rev-list $MERGE_BASE..HEAD | wc -l 2>/dev/null) + VN2=$(git rev-list --max-count=1 --abbrev-commit --abbrev=4 HEAD 2>/dev/null) + VN=$(echo "v$DEF_VER-$VN1-g$VN2" | sed -e 's/ //g') + git update-index -q --refresh + test -z "$(git diff-index --name-only HEAD --)" || + VN="$VN-dirty" ;; + v[0-9]*) + git update-index -q --refresh + test -z "$(git diff-index --name-only HEAD --)" || + VN="$VN-dirty" ;; + esac +then + VN=$(echo "$VN" | sed -e 's/-/./g'); +else + VN="$DEF_VER" +fi + +VN=$(expr "$VN" : v*'\(.*\)') + +if test -r $YVF +then + VC=$(cat $YVF) +else + VC=unset +fi +test "$VN" = "$VC" || { + echo >&2 "$VN" + echo "$VN" >$YVF + echo "#define PACKAGE_STRING \"yasm $VN\"" > YASM-VERSION.h + echo "#define PACKAGE_VERSION \"$VN\"" >> YASM-VERSION.h +} diff --git a/autogen.sh b/autogen.sh index b91fc286..12da6aa4 100755 --- a/autogen.sh +++ b/autogen.sh @@ -73,7 +73,8 @@ if test ! -d "config"; then mkdir config fi -rm -f stamp-h.in +rm -rf autom4te.cache +rm -f configure config.h config.status config.log stamp-h.in #echo " gettextize -f --no-changelog" #echo "N" | gettextize -f --no-changelog || exit 1 echo " aclocal $ACLOCAL_FLAGS" diff --git a/cmake/modules/VersionGen.cmake b/cmake/modules/VersionGen.cmake new file mode 100644 index 00000000..340455b3 --- /dev/null +++ b/cmake/modules/VersionGen.cmake @@ -0,0 +1,78 @@ +# Redistribution and use is allowed according to the terms of the BSD license. +# +# Copyright (c) 2011 Peter Johnson + +macro (VERSION_GEN _version _version_file _default_version) + set (_vn "v${_default_version}") + + # First see if there is a version file (included in release tarballs), + # then try git-describe, then default. + if (EXISTS "${CMAKE_SOURCE_DIR}/version") + file (STRINGS "${CMAKE_SOURCE_DIR}/version" _version_strs LIMIT_COUNT 1) + list (GET _version_strs 0 _version_strs0) + if (NOT (${_version_strs0} STREQUAL "")) + set (_vn "v${_version_strs0}") + endif (${_version_strs0}) + elseif (EXISTS "${CMAKE_SOURCE_DIR}/.git") + execute_process (COMMAND git describe --match "v[0-9]*" --abbrev=4 HEAD + RESULT_VARIABLE _git_result + OUTPUT_VARIABLE _git_vn + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (_git_result EQUAL 0) + # Special handling until we get a more recent tag on the master + # branch + if (_git_vn MATCHES "^v0[.]1[.]0") + execute_process (COMMAND git merge-base v${_default_version} HEAD + OUTPUT_VARIABLE _merge_base + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + #message (STATUS "Merge base: ${_merge_base}") + + execute_process (COMMAND git rev-list ${_merge_base}..HEAD + OUTPUT_VARIABLE _rev_list + ERROR_QUIET) + string (REGEX MATCHALL "[^\n]*\n" _rev_list_lines "${_rev_list}") + #message (STATUS "Rev list: ${_rev_list_lines}") + list (LENGTH _rev_list_lines _vn1) + + execute_process (COMMAND git rev-list --max-count=1 --abbrev-commit --abbrev=4 HEAD + OUTPUT_VARIABLE _vn2 + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + set (_git_vn "v${_default_version}-${_vn1}-g${_vn2}") + endif (_git_vn MATCHES "^v0[.]1[.]0") + + # Append -dirty if there are local changes + execute_process (COMMAND git update-index -q --refresh) + execute_process (COMMAND git diff-index --name-only HEAD -- + OUTPUT_VARIABLE _git_vn_dirty) + if (_git_vn_dirty) + set (_git_vn "${_git_vn}-dirty") + endif (_git_vn_dirty) + + # Substitute . for - in the result + string (REPLACE "-" "." _vn "${_git_vn}") + endif (_git_result EQUAL 0) + endif (EXISTS "${CMAKE_SOURCE_DIR}/version") + + # Strip leading "v" from version + #message (STATUS "_vn: ${_vn}") + string (REGEX REPLACE "^v*(.+)" "\\1" _vn "${_vn}") + + # Update version file if required + if (EXISTS ${_version_file}) + file (STRINGS ${_version_file} _version_strs LIMIT_COUNT 1) + list (GET _version_strs 0 _vc) + else (EXISTS ${_version_file}) + set (_vc "unset") + endif (EXISTS ${_version_file}) + if (NOT ("${_vn}" STREQUAL "${_vc}")) + file (WRITE ${_version_file} "${_vn}") + endif (NOT ("${_vn}" STREQUAL "${_vc}")) + + # Set output version variable + set (${_version} ${_vn}) +endmacro (VERSION_GEN) diff --git a/config.h.cmake b/config.h.cmake index d282b931..50ed93ab 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -29,12 +29,6 @@ /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "bug-yasm@tortall.net" -/* Define to internal version of this package. */ -#define PACKAGE_INTVER "@PACKAGE_INTVER@" - -/* Define to build version of this package. */ -#define PACKAGE_BUILD "@PACKAGE_BUILD@" - /* Define to the full name of this package. */ #define PACKAGE_NAME "yasm" diff --git a/configure.ac b/configure.ac index 4dc92f41..c0507a6b 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,9 @@ # autoconf setup # AC_PREREQ(2.53) -AC_INIT([yasm], [HEAD], [bug-yasm@tortall.net]) +AC_INIT([yasm], + m4_esyscmd([./YASM-VERSION-GEN.sh && tr -d '\n' \n", argv[0]); return EXIT_FAILURE; } - if (sscanf(PACKAGE_INTVER, "%d.%d.%d", &major, &minor, &subminor) != 3) { + matched = sscanf(PACKAGE_VERSION, "%d.%d.%d.%d", &major, &minor, &subminor, + &patchlevel); + + if (matched == 3) + patchlevel = 0; + else if (matched != 4) { fprintf(stderr, "Version tokenizing error\n"); return EXIT_FAILURE; } @@ -61,17 +66,15 @@ main(int argc, char *argv[]) fprintf(out, "%%define __YASM_MAJOR__ %d\n", major); fprintf(out, "%%define __YASM_MINOR__ %d\n", minor); fprintf(out, "%%define __YASM_SUBMINOR__ %d\n", subminor); - if (!isdigit(PACKAGE_BUILD[0])) - fprintf(out, "%%define __YASM_BUILD__ 0\n"); - else - fprintf(out, "%%define __YASM_BUILD__ %d\n", atoi(PACKAGE_BUILD)); + fprintf(out, "%%define __YASM_BUILD__ %d\n", patchlevel); + fprintf(out, "%%define __YASM_PATCHLEVEL__ %d\n", patchlevel); /* Version id (hex number) */ - fprintf(out, "%%define __YASM_VERSION_ID__ 0%02x%02x%02x00h\n", major, - minor, subminor); + fprintf(out, "%%define __YASM_VERSION_ID__ 0%02x%02x%02x%02xh\n", major, + minor, subminor, patchlevel); - /* Version string - version sans build */ - fprintf(out, "%%define __YASM_VER__ \"%s\"\n", PACKAGE_INTVER); + /* Version string */ + fprintf(out, "%%define __YASM_VER__ \"%s\"\n", PACKAGE_VERSION); fclose(out); return EXIT_SUCCESS; -- 2.40.0