Skip to content

Commit

Permalink
Use Git hooks for updating version in header
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorenar committed Nov 8, 2024
1 parent 44e0412 commit 07a6129
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 63 deletions.
11 changes: 11 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

if ! git diff --quiet --cached src/*; then
if ! git diff --cached -U0 CMakeLists.txt | grep -q ' VERSION'; then
ver="$(git describe --always --long | sed 's/^v//')"
ver="${ver%-*}-$(git branch --show-current)"
echo "Updating version macro to $ver"
sed -i 's/#define XDGDIRS_VER ".*"/#define XDGDIRS_VER "'"$ver"'"/' src/xdgdirs.h
git add src/xdgdirs.h
fi
fi
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed

- Use Git hooks for updating version in header

## [1.1.2] - 2024-07-06
### Added

Expand Down
16 changes: 1 addition & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE YES)
add_library("${XDGDIRS}" STATIC xdgdirs.c)

add_custom_target(version
${CMAKE_COMMAND}
-D SRC=${CMAKE_CURRENT_SOURCE_DIR}/xdgdirs_ver.h.in
-D DST=${CMAKE_CURRENT_SOURCE_DIR}/xdgdirs_ver.h
-P ${CMAKE_CURRENT_SOURCE_DIR}/GenerateVersion.cmake
)
add_dependencies(${XDGDIRS} version)

file(GLOB_RECURSE INCLUDE_FILES "*.h")

set_target_properties("${XDGDIRS}"
PROPERTIES
PUBLIC_HEADER "${INCLUDE_FILES}"
)
set_target_properties("${XDGDIRS}" PROPERTIES PUBLIC_HEADER "src/xdgdirs.h")
29 changes: 0 additions & 29 deletions src/GenerateVersion.cmake

This file was deleted.

10 changes: 9 additions & 1 deletion src/xdgdirs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ extern "C" {

#include <stddef.h>

#include "xdgdirs_ver.h"
/** @def XDGDIRS_VER
* @brief Version of libXDGdirs
* @details
* Adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
*/
#define XDGDIRS_VER "1.1.2-0-master"

/// Version of XDG Base Directory specification implemented in this library
#define XDGBDS_VER "0.8"

/// @brief Container for environment variables which are colon separated lists
struct xdgDirsList_t {
Expand Down
18 changes: 0 additions & 18 deletions src/xdgdirs_ver.h.in

This file was deleted.

0 comments on commit 07a6129

Please sign in to comment.