From fc2d2db76f4081936ffecd01f2f8be164abd292c Mon Sep 17 00:00:00 2001 From: patrick96 Date: Fri, 14 Dec 2018 09:30:17 +0100 Subject: [PATCH] refactor(cmake): Determine version in cmake We need to have the version string available in multiple places not just the source code. It is now hardcoded in the root CMakeLists.txt and all files that need it will be configured with cmake. This also removed the unecessary duality of GIT_TAG and APP_VERSION and GIT_TAG_NAMESPACE and APP_VERSION_NAMESPACE. --- CMakeLists.txt | 16 ++++++++++++++++ common/bump.sh | 34 ---------------------------------- common/version.sh | 29 ----------------------------- include/CMakeLists.txt | 9 --------- include/settings.hpp.cmake | 9 --------- include/version.hpp | 4 ---- src/utils/http.cpp | 2 +- 7 files changed, 17 insertions(+), 86 deletions(-) delete mode 100755 common/bump.sh delete mode 100755 common/version.sh delete mode 100644 include/version.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ee8ee8f..40b316fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,22 @@ endif() project(polybar C CXX) +set(VERSION_MAJOR "3") +set(VERSION_MINOR "3") +set(VERSION_PATCH "0") + +# TODO set APP_VERSION by checking it command was successful +execute_process(COMMAND git describe --tags --dirty=-git + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE APP_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) + +if(NOT APP_VERSION) + set(APP_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") +endif() + +STRING(REGEX REPLACE "[^a-zA-Z0-9_]" "_" APP_VERSION_NAMESPACE "v${APP_VERSION}") + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake diff --git a/common/bump.sh b/common/bump.sh deleted file mode 100755 index 402ec34e..00000000 --- a/common/bump.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -main() { - if [ $# -eq 0 ]; then - version=$(git describe --tags --abbrev=0) - set -- "${version%.*}.$((${version##*.}+1))" - fi - - git tag "$@" || exit 1 - - tag_curr="$(git tag --sort=version:refname | tail -1)" - tag_prev="$(git tag --sort=version:refname | tail -2 | head -1)" - - if [ -x ./common/version.sh ]; then - ./common/version.sh "$tag_curr" - fi - - sed -r "s/${tag_prev}/${tag_curr}/g" -i \ - README.md CMakeLists.txt \ - contrib/polybar.aur/PKGBUILD \ - contrib/polybar-git.aur/PKGBUILD - - git add -u README.md CMakeLists.txt \ - contrib/polybar.aur/PKGBUILD \ - contrib/polybar-git.aur/PKGBUILD \ - include/version.hpp - - git commit -m "build: Bump version to ${tag_curr}" - - # Recreate the tag to include the last commit - [ $# -eq 1 ] && git tag -f "$@" -} - -main "$@" diff --git a/common/version.sh b/common/version.sh deleted file mode 100755 index 290b1f0b..00000000 --- a/common/version.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -msg() { - if [ -t 1 ]; then - printf " \033[1;32m**\033[0m %s\n" "$@" - else - printf "** %s\n" "$@" - fi -} - -main() { - if [ $# -eq 0 ]; then - set -- "$(git describe --tags --dirty=-dev)" - fi - - GIT_TAG_NAMESPACE=$(echo "v$1" | sed "s/[^a-zA-Z0-9_]/_/g") - - msg "Current version: $1" - sed -r "/#define GIT_TAG/s/GIT_TAG .*/GIT_TAG \"$1\"/" -i include/version.hpp - sed -r "/#define GIT_TAG_NAMESPACE/s/GIT_TAG_NAMESPACE .*/GIT_TAG_NAMESPACE $GIT_TAG_NAMESPACE/" -i include/version.hpp - - if git diff include/version.hpp 2>/dev/null | grep -q .; then - msg "Updated include/version.hpp" - else - msg " is already up-to-date" - fi -} - -main "$@" diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 7a1feeeb..2e9b91fa 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -24,15 +24,6 @@ if(WITH_XKB) endif() string(REPLACE ";" ", " XPP_EXTENSION_LIST "${XPP_EXTENSION_LIST}") -execute_process(COMMAND git describe --tags --dirty=-git - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - OUTPUT_VARIABLE APP_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) - -if(APP_VERSION) - STRING(REGEX REPLACE "[^a-zA-Z0-9_]" "_" APP_VERSION_NAMESPACE "v${APP_VERSION}") -endif() - configure_file( ${CMAKE_CURRENT_LIST_DIR}/settings.hpp.cmake ${CMAKE_BINARY_DIR}/generated-sources/settings.hpp diff --git a/include/settings.hpp.cmake b/include/settings.hpp.cmake index 47457326..f86af49b 100644 --- a/include/settings.hpp.cmake +++ b/include/settings.hpp.cmake @@ -4,18 +4,9 @@ #include #include -#include "version.hpp" - #define APP_NAME "@PROJECT_NAME@" #cmakedefine APP_VERSION "@APP_VERSION@" -#ifndef APP_VERSION -#define APP_VERSION GIT_TAG -#endif #cmakedefine APP_VERSION_NAMESPACE @APP_VERSION_NAMESPACE@ -#ifndef APP_VERSION_NAMESPACE -#define APP_VERSION_NAMESPACE GIT_TAG_NAMESPACE -#endif -#define BASE_PATH "@PROJECT_SOURCE_DIR@" #cmakedefine01 ENABLE_ALSA #cmakedefine01 ENABLE_MPD diff --git a/include/version.hpp b/include/version.hpp deleted file mode 100644 index f4e680a1..00000000 --- a/include/version.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#define GIT_TAG "3.3.0" -#define GIT_TAG_NAMESPACE v3_3_0 diff --git a/src/utils/http.cpp b/src/utils/http.cpp index 15b6b7e6..aee8d443 100644 --- a/src/utils/http.cpp +++ b/src/utils/http.cpp @@ -14,7 +14,7 @@ http_downloader::http_downloader(int connection_timeout) { curl_easy_setopt(m_curl, CURLOPT_CONNECTTIMEOUT, connection_timeout); curl_easy_setopt(m_curl, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, true); - curl_easy_setopt(m_curl, CURLOPT_USERAGENT, "polybar/" GIT_TAG); + curl_easy_setopt(m_curl, CURLOPT_USERAGENT, "polybar/" APP_VERSION); curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, http_downloader::write); curl_easy_setopt(m_curl, CURLOPT_FORBID_REUSE, true); }