From 90ad8e58f5f42b4077b65d92941dbe94e3b3ae4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 7 Aug 2018 16:31:07 +0200 Subject: [PATCH] Squashed 'cmake/cable/' changes from 36b6cb6..a0c88f9 a0c88f9 Cable 0.2.7 94bf242 buildinfo: Export buildinfo.json file c013495 gitinfo: Include branch name and origin URL git-subtree-dir: cmake/cable git-subtree-split: a0c88f96fb70bb897ac59335be1a173a1c3be8d8 --- bootstrap.cmake | 2 +- buildinfo/buildinfo.cmake | 10 +++++++--- buildinfo/buildinfo.json.in | 10 ++++++++++ buildinfo/gitinfo.cmake | 33 ++++++++++++++++++++++++++++++--- 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 buildinfo/buildinfo.json.in diff --git a/bootstrap.cmake b/bootstrap.cmake index 686f6b4..6258dbd 100644 --- a/bootstrap.cmake +++ b/bootstrap.cmake @@ -10,7 +10,7 @@ # # This is internal variable automaticaly updated with external tools. # Use CABLE_VERSION variable if you need this information. -set(version 0.2.6) +set(version 0.2.7) # For conveniance, add the project CMake module dir to module path. set(module_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake) diff --git a/buildinfo/buildinfo.cmake b/buildinfo/buildinfo.cmake index 85fe3e6..cfed170 100644 --- a/buildinfo/buildinfo.cmake +++ b/buildinfo/buildinfo.cmake @@ -10,13 +10,16 @@ string(TIMESTAMP TIMESTAMP) # Read the git info from a file. The gitinfo is suppose to update the file # only if the information has changed. -file(READ ${OUTPUT_DIR}/gitinfo.txt GIT_INFO) +file(STRINGS ${OUTPUT_DIR}/gitinfo.txt gitinfo) +list(GET gitinfo 0 describe) +list(GET gitinfo 1 GIT_BRANCH) +list(GET gitinfo 2 GIT_ORIGIN_URL) # The output of `git describe --always --long --tags --match=v*`. -string(REGEX MATCH "(v(.+)-([0-9]+)-g)?([0-9a-f]+)(-dirty)?" match "${GIT_INFO}") +string(REGEX MATCH "(v(.+)-([0-9]+)-g)?([0-9a-f]+)(-dirty)?" match "${describe}") if(NOT match) - message(WARNING "Cannot parse git describe: ${GIT_INFO}") + message(WARNING "Cannot parse git describe: ${describe}") endif() set(GIT_LATEST_PROJECT_VERSION ${CMAKE_MATCH_2}) @@ -67,5 +70,6 @@ message( ) configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.c.in ${OUTPUT_DIR}/buildinfo.c) +configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.json.in ${OUTPUT_DIR}/buildinfo.json) configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.sh.in ${OUTPUT_DIR}/buildinfo.sh) configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.ps1.in ${OUTPUT_DIR}/buildinfo.ps1) diff --git a/buildinfo/buildinfo.json.in b/buildinfo/buildinfo.json.in new file mode 100644 index 0000000..107d9ab --- /dev/null +++ b/buildinfo/buildinfo.json.in @@ -0,0 +1,10 @@ +{ + "name": "@PROJECT_NAME@", + "version": "@PROJECT_VERSION@", + "is_prerelease": @PROJECT_VERSION_IS_PRERELEASE@, + "commit": "@GIT_COMMIT_HASH@", + "branch": "@GIT_BRANCH@", + "repo": "@GIT_ORIGIN_URL@", + "system_name": "@SYSTEM_NAME@", + "system_processor": "@SYSTEM_PROCESSOR@" +} diff --git a/buildinfo/gitinfo.cmake b/buildinfo/gitinfo.cmake index 727e9cd..53068da 100644 --- a/buildinfo/gitinfo.cmake +++ b/buildinfo/gitinfo.cmake @@ -12,10 +12,37 @@ if(GIT) ERROR_VARIABLE error ERROR_STRIP_TRAILING_WHITESPACE ) -endif() + if(error) + message(WARNING "Git ${error}") + endif() -if(error) - message(WARNING "Git ${error}") + execute_process( + COMMAND ${GIT} rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE gitbranch + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE error + ERROR_STRIP_TRAILING_WHITESPACE + ) + if(error) + message(WARNING "Git ${error}") + else() + set(gitinfo "${gitinfo}\n${gitbranch}") + endif() + + execute_process( + COMMAND ${GIT} config --get remote.origin.url + WORKING_DIRECTORY ${SOURCE_DIR} + OUTPUT_VARIABLE gitorigin + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE error + ERROR_STRIP_TRAILING_WHITESPACE + ) + if(error) + message(WARNING "Git ${error}") + else() + set(gitinfo "${gitinfo}\n${gitorigin}\n") + endif() endif() set(gitinfo_file ${OUTPUT_DIR}/gitinfo.txt)