From ce918fd0fc94d29c23f335e57b2f11bb8768508d Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Thu, 18 Jun 2020 13:08:04 +0200 Subject: [PATCH] Make CMake get Graphviz version from autogen.sh by parsing it This will make autotools and CMake builds have a single source of truth for the Graphviz version. First, the major, minor and patch versions are retrieved. If the patch version is "$GRAPHVIZ_VERSION_DATE", the patch version is set to the committer date of the latest commit. This effectively repeals part of the intention of 266ff5ee80b2d91231907e90ec650154f5225aa5: "Don't encode build date stamp in it to be able to create reproducable builds". --- .gitlab-ci.yml | 1 + CMakeLists.txt | 63 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 755209045..4e7beed1b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -58,6 +58,7 @@ portable-source: # Install and set PATH - choco install --no-progress -y activeperl - choco install --no-progress -y python3 + - choco install --no-progress -y grep - $Env:Path += ";C:\Python38" - $Env:Path += ";$env:CI_PROJECT_DIR\windows\dependencies\graphviz-build-utilities" - $Env:Path += ";C:\Program Files\CMake\bin" diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ae3072d2..6fd6573b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,13 +97,63 @@ if (WIN32) endif() # ============================ Set Graphviz version ============================ -set(GRAPHVIZ_VERSION_MAJOR 2) -set(GRAPHVIZ_VERSION_MINOR 45) -set(GRAPHVIZ_VERSION_PATCH 0) -set(GRAPHVIZ_VERSION_STRING "${GRAPHVIZ_VERSION_MAJOR}.${GRAPHVIZ_VERSION_MINOR}.${GRAPHVIZ_VERSION_PATCH}") configure_file(graphviz_version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/graphviz_version.h @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphviz_version.h DESTINATION ${HEADER_INSTALL_DIR}) +execute_process( + COMMAND grep "^m4_define.*graphviz_version_major" autogen.sh + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE major_version_result + OUTPUT_VARIABLE AUTOGEN_MAJOR_VERSION_LINE + ERROR_VARIABLE major_version_error + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE +) +if (major_version_result EQUAL 0) + string(REGEX REPLACE ".*\\[([0-9]*)\\].*" + "\\1" GRAPHVIZ_VERSION_MAJOR + ${AUTOGEN_MAJOR_VERSION_LINE}) +else() + message(FATAL_ERROR "Failed to set major version: ${major_version_error}") + set(GRAPHVIZ_VERSION_MAJOR {$major_version_result}) +endif() + +execute_process( + COMMAND grep "^m4_define.*graphviz_version_minor" autogen.sh + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE minor_version_result + OUTPUT_VARIABLE AUTOGEN_MINOR_VERSION_LINE + ERROR_VARIABLE minor_version_error + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE +) +if (minor_version_result EQUAL 0) + string(REGEX REPLACE ".*\\[([0-9]*)\\].*" + "\\1" GRAPHVIZ_VERSION_MINOR + ${AUTOGEN_MINOR_VERSION_LINE}) +else() + message(FATAL_ERROR "Failed to set minor version: ${minor_version_error}") + set(GRAPHVIZ_VERSION_MINOR {$minor_version_result}) +endif() + +execute_process( + COMMAND grep "^m4_define.*graphviz_version_micro" autogen.sh + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE patch_version_result + OUTPUT_VARIABLE AUTOGEN_PATCH_VERSION_LINE + ERROR_VARIABLE patch_version_error + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE +) +if (patch_version_result EQUAL 0) + string(REGEX REPLACE ".*,\\[(.*)\\].*" + "\\1" GRAPHVIZ_VERSION_PATCH + ${AUTOGEN_PATCH_VERSION_LINE}) +else() + message(FATAL_ERROR "Failed to set patch version: ${patch_version_error}") + set(GRAPHVIZ_VERSION_PATCH {$patch_version_result}) +endif() + # Set GRAPHVIZ_VERSION_BUILD to time of last commit, or to 0 if that fails. execute_process( COMMAND "${GIT_EXECUTABLE}" log -n 1 --format=%cd --date=format:%Y%m%d.%H%M @@ -119,6 +169,11 @@ if(NOT git_result EQUAL 0) set(GRAPHVIZ_VERSION_BUILD 0) endif() +if (GRAPHVIZ_VERSION_PATCH STREQUAL "\$GRAPHVIZ_VERSION_DATE") + set(GRAPHVIZ_VERSION_PATCH ${GRAPHVIZ_VERSION_BUILD}) +endif() + +set(GRAPHVIZ_VERSION_STRING "${GRAPHVIZ_VERSION_MAJOR}.${GRAPHVIZ_VERSION_MINOR}.${GRAPHVIZ_VERSION_PATCH}") set(GRAPHVIZ_VERSION_FULL "${GRAPHVIZ_VERSION_MAJOR}.${GRAPHVIZ_VERSION_MINOR}.${GRAPHVIZ_VERSION_BUILD}") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/builddate.h "#define BUILDDATE \"${GRAPHVIZ_VERSION_BUILD}\"") -- 2.40.0