feat(build): Build with version

This commit is contained in:
Michael Carlberg 2016-06-28 14:50:21 +02:00
parent e1279d6582
commit 4c83b363bf
5 changed files with 70 additions and 6 deletions

View File

@ -2,9 +2,7 @@
# Build configuration # Build configuration
# #
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(lemonbuddy)
# TODO(jaagr): Replace with git tag
project(lemonbuddy VERSION 1.2.2)
# Include the local cmake modules # Include the local cmake modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
@ -139,6 +137,11 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/lib/xpp")
set(PROJECT_INCL_DIRS ${PROJECT_INCL_DIRS} ${XPP_INCLUDE_DIRS}) set(PROJECT_INCL_DIRS ${PROJECT_INCL_DIRS} ${XPP_INCLUDE_DIRS})
set(PROJECT_LINK_LIBS ${PROJECT_LINK_LIBS} ${XPP_LIBRARIES}) set(PROJECT_LINK_LIBS ${PROJECT_LINK_LIBS} ${XPP_LIBRARIES})
#
# Execute versioning script
#
execute_process(COMMAND ./version.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_QUIET ERROR_QUIET)
# #
# Install executable and wrapper # Install executable and wrapper
# #

View File

@ -1,5 +1,10 @@
#!/bin/sh #!/bin/sh
# Use passed argument as new tag
[ $# -eq 1 ] && git tag "$@"
./version.sh
# shellcheck disable=SC2016 # shellcheck disable=SC2016
tag_prev=$(git tag -l | tail -2 | head -1) tag_prev=$(git tag -l | tail -2 | head -1)
tag_curr=$(git tag -l | tail -1) tag_curr=$(git tag -l | tail -1)
@ -7,4 +12,6 @@ tag_curr=$(git tag -l | tail -1)
sed -r "s/${tag_prev}/${tag_curr}/g" -i README.md CMakeLists.txt contrib/lemonbuddy.aur/PKGBUILD contrib/lemonbuddy.aur/.SRCINFO sed -r "s/${tag_prev}/${tag_curr}/g" -i README.md CMakeLists.txt contrib/lemonbuddy.aur/PKGBUILD contrib/lemonbuddy.aur/.SRCINFO
git add README.md CMakeLists.txt contrib/lemonbuddy.aur/PKGBUILD contrib/lemonbuddy.aur/.SRCINFO git add README.md CMakeLists.txt contrib/lemonbuddy.aur/PKGBUILD contrib/lemonbuddy.aur/.SRCINFO
git commit -m "build: Bump version to ${tag_curr}" git commit -m "build: Bump version to ${tag_curr}"
git show HEAD
# Recreate the tag to include the last commit
[ $# -eq 1 ] && git tag -f "$@"

3
include/version.hpp Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#define GIT_TAG "1.2.2-dev"

View File

@ -3,6 +3,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <thread> #include <thread>
#include "version.hpp"
#include "bar.hpp" #include "bar.hpp"
#include "config.hpp" #include "config.hpp"
#include "eventloop.hpp" #include "eventloop.hpp"
@ -59,14 +60,43 @@ int main(int argc, char **argv)
cli::add_option("-d", "--dump", "PARAM", "Show value of PARAM in section [bar_name]"); cli::add_option("-d", "--dump", "PARAM", "Show value of PARAM in section [bar_name]");
cli::add_option("-x", "--print-exec", "Print the generated command line string used to start the lemonbar process"); cli::add_option("-x", "--print-exec", "Print the generated command line string used to start the lemonbar process");
cli::add_option("-w", "--print-wmname", "Print the generated WM_NAME"); cli::add_option("-w", "--print-wmname", "Print the generated WM_NAME");
cli::add_option("-v", "--version", "Print version information");
/** /**
* Parse command line arguments * Parse command line arguments
*/ */
if (argc < 2 || cli::is_option(argv[1], "-h", "--help") || argv[1][0] == '-') if (argc < 2 || cli::is_option(argv[1], "-h", "--help"))
cli::usage(usage, (argc > 1 && cli::is_option(argv[1], "-h", "--help"))); cli::usage(usage, (argc > 1 && cli::is_option(argv[1], "-h", "--help")));
cli::parse(2, argc, argv); cli::parse(2, argc, argv);
if (cli::has_option("help"))
if (cli::has_option("version") || cli::is_option(argv[1], "-v", "--version")) {
std::cout << APP_NAME << " " << GIT_TAG << std::endl;
if (std::strncmp(argv[1], "-vv", 3) == 0) {
std::cout << "\n" << "Built with: "
<< (ENABLE_ALSA ? "+" : "-") << "alsa "
<< (ENABLE_I3 ? "+" : "-") << "i3 "
<< (ENABLE_MPD ? "+" : "-") << "mpd "
<< (ENABLE_NETWORK ? "+" : "-") << "network "
<< "\n\n";
if (ENABLE_ALSA)
std::cout
<< "ALSA_SOUNDCARD " << ALSA_SOUNDCARD << std::endl;
std::cout
<< "CONNECTION_TEST_IP " << CONNECTION_TEST_IP << "\n"
<< "PATH_BACKLIGHT_VAL " << PATH_BACKLIGHT_VAL << "\n"
<< "PATH_BACKLIGHT_MAX " << PATH_BACKLIGHT_MAX << "\n"
<< "BSPWM_SOCKET_PATH " << BSPWM_SOCKET_PATH << "\n"
<< "BSPWM_STATUS_PREFIX " << BSPWM_STATUS_PREFIX << "\n"
<< "PATH_CPU_INFO " << PATH_CPU_INFO << "\n"
<< "PATH_MEMORY_INFO " << PATH_MEMORY_INFO << "\n";
}
return EXIT_SUCCESS;
}
if (cli::has_option("help") || argv[1][0] == '-')
cli::usage(usage); cli::usage(usage);
/** /**

21
version.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/sh
msg() {
echo " \033[1;32m**\033[0m" "$@"
}
main() {
version="$(git describe --tags --dirty=-dev)"
msg "Current version: ${version}"
sed -r "/#define GIT_TAG/s/GIT_TAG .*/GIT_TAG \"${version}\"/" -i include/version.hpp
if [ "$(git diff include/version.hpp 2>/dev/null)" ]; then
msg "Updated include/version.hpp"
else
msg "<include/version.hpp> is already up-to-date"
fi
}
main "$@"