internal: better versioning (#3543)

* better versioning

* meson: better versioning

* nix: better versioning

---------

Co-authored-by: Mihai Fufezan <fufexan@protonmail.com>
This commit is contained in:
Vaxry 2023-10-10 20:21:57 +01:00 committed by GitHub
parent 3219c84433
commit 914851b91a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 79 deletions

2
.gitignore vendored
View File

@ -29,3 +29,5 @@ gmon.out
*.tar.gz *.tar.gz
PKGBUILD PKGBUILD
src/version.h

View File

@ -21,34 +21,8 @@ message(STATUS "Gathering git info")
# Get git info # Get git info
# hash and branch # hash and branch
execute_process( execute_process(
COMMAND git rev-parse --abbrev-ref HEAD COMMAND ./scripts/generateVersion.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND sh -c "git show ${GIT_COMMIT_HASH} | head -n 5 | tail -n 1 | sed -e 's/#//g' -e 's/\"//g'"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_MESSAGE
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND sh -c "git diff-index --quiet HEAD -- || echo \"dirty\""
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DIRTY
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND sh -c "git describe --tags"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE)
# #
# #

View File

@ -20,22 +20,12 @@ else
error('Could not configure current C++ compiler (' + cpp_compiler.get_id() + ' ' + cpp_compiler.version() + ') with required C++ standard (C++23)') error('Could not configure current C++ compiler (' + cpp_compiler.get_id() + ' ' + cpp_compiler.version() + ') with required C++ standard (C++23)')
endif endif
GIT_BRANCH = run_command('git', 'rev-parse', '--abbrev-ref', 'HEAD', check: false).stdout().strip()
GIT_COMMIT_HASH = run_command('git', 'rev-parse', 'HEAD', check: false).stdout().strip()
GIT_COMMIT_MESSAGE = run_command('sh', '-c', 'git show | head -n 5 | tail -n 1', check: false).stdout().strip()
GIT_DIRTY = run_command('sh', '-c', 'git diff-index --quiet HEAD -- || echo "dirty"', check: false).stdout().strip()
add_project_arguments( add_project_arguments(
[ [
'-Wno-unused-parameter', '-Wno-unused-parameter',
'-Wno-unused-value', '-Wno-unused-value',
'-Wno-missing-field-initializers', '-Wno-missing-field-initializers',
'-Wno-narrowing', '-Wno-narrowing',
f'-DGIT_BRANCH="@GIT_BRANCH@"',
f'-DGIT_COMMIT_HASH="@GIT_COMMIT_HASH@"',
f'-DGIT_COMMIT_MESSAGE="@GIT_COMMIT_MESSAGE@"',
f'-DGIT_DIRTY="@GIT_DIRTY@"',
], ],
language: 'cpp') language: 'cpp')
@ -81,6 +71,8 @@ foreach file : headers
install_headers(file, subdir: 'hyprland', preserve_path: true) install_headers(file, subdir: 'hyprland', preserve_path: true)
endforeach endforeach
version_h = run_command('sh', '-c', 'scripts/generateVersion.sh')
subdir('protocols') subdir('protocols')
subdir('src') subdir('src')
subdir('hyprctl') subdir('hyprctl')

View File

@ -105,9 +105,15 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov
postPatch = '' postPatch = ''
# Fix hardcoded paths to /usr installation # Fix hardcoded paths to /usr installation
sed -i "s#/usr#$out#" src/render/OpenGL.cpp sed -i "s#/usr#$out#" src/render/OpenGL.cpp
substituteInPlace meson.build \
--replace "@GIT_COMMIT_HASH@" '${commit}' \ # Generate version.h
--replace "@GIT_DIRTY@" '${ cp src/version.h.in src/version.h
substituteInPlace src/version.h \
--replace "@HASH@" '${commit}' \
--replace "@BRANCH@" "" \
--replace "@MESSAGE@" "" \
--replace "@TAG@" "" \
--replace "@DIRTY@" '${
if commit == "" if commit == ""
then "dirty" then "dirty"
else "" else ""

View File

@ -1,20 +1,8 @@
diff --git a/meson.build b/meson.build diff --git a/meson.build b/meson.build
index f3802553..6a924a79 100644 index 726933bc..28b4d9ac 100644
--- a/meson.build --- a/meson.build
+++ b/meson.build +++ b/meson.build
@@ -21,9 +21,9 @@ else @@ -29,20 +29,7 @@ add_project_arguments(
endif
GIT_BRANCH = run_command('git', 'rev-parse', '--abbrev-ref', 'HEAD', check: false).stdout().strip()
-GIT_COMMIT_HASH = run_command('git', 'rev-parse', 'HEAD', check: false).stdout().strip()
+GIT_COMMIT_HASH = '@GIT_COMMIT_HASH@'
GIT_COMMIT_MESSAGE = run_command('sh', '-c', 'git show | head -n 5 | tail -n 1', check: false).stdout().strip()
-GIT_DIRTY = run_command('sh', '-c', 'git diff-index --quiet HEAD -- || echo "dirty"', check: false).stdout().strip()
+GIT_DIRTY = '@GIT_DIRTY@'
add_project_arguments(
[
@@ -39,21 +39,8 @@ add_project_arguments(
], ],
language: 'cpp') language: 'cpp')
@ -32,17 +20,24 @@ index f3802553..6a924a79 100644
-have_xwayland = xcb_dep.found() and have_xwlr -have_xwayland = xcb_dep.found() and have_xwlr
- -
-if not have_xwayland -if not have_xwayland
- add_project_arguments('-DNO_XWAYLAND', language: 'cpp')
+if get_option('xwayland').disabled() +if get_option('xwayland').disabled()
+ add_project_arguments('-DNO_XWAYLAND', language: 'cpp') add_project_arguments('-DNO_XWAYLAND', language: 'cpp')
endif endif
backtrace_dep = cpp_compiler.find_library('execinfo', required: false) @@ -71,8 +58,6 @@ foreach file : headers
install_headers(file, subdir: 'hyprland', preserve_path: true)
endforeach
-version_h = run_command('sh', '-c', 'scripts/generateVersion.sh')
-
subdir('protocols')
subdir('src')
subdir('hyprctl')
diff --git a/src/meson.build b/src/meson.build diff --git a/src/meson.build b/src/meson.build
index 7b658d31..60aa4057 100644 index 2065c6f5..55530605 100644
--- a/src/meson.build --- a/src/meson.build
+++ b/src/meson.build +++ b/src/meson.build
@@ -7,16 +7,16 @@ executable('Hyprland', src, @@ -9,16 +9,16 @@ executable('Hyprland', src,
server_protos, server_protos,
dependency('wayland-server'), dependency('wayland-server'),
dependency('wayland-client'), dependency('wayland-client'),

14
scripts/generateVersion.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
cp ./src/version.h.in ./src/version.h -fr
HASH=$(git rev-parse HEAD)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
MESSAGE=$(git show ${GIT_COMMIT_HASH} | head -n 5 | tail -n 1 | sed -e 's/#//g' -e 's/\"//g')
DIRTY=$(git diff-index --quiet HEAD -- || echo \"dirty\")
TAG=$(git describe --tags)
awk -i inplace "{sub(/@HASH@/,\"${HASH}\")}1" ./src/version.h
awk -i inplace "{sub(/@BRANCH@/,\"${BRANCH}\")}1" ./src/version.h
awk -i inplace "{sub(/@MESSAGE@/,\"${MESSAGE}\")}1" ./src/version.h
awk -i inplace "{sub(/@DIRTY@/,\"${DIRTY}\")}1" ./src/version.h
awk -i inplace "{sub(/@TAG@/,\"${TAG}\")}1" ./src/version.h

View File

@ -14,22 +14,7 @@
#define ISDEBUG false #define ISDEBUG false
#endif #endif
// git stuff #include "version.h"
#ifndef GIT_COMMIT_HASH
#define GIT_COMMIT_HASH "?"
#endif
#ifndef GIT_BRANCH
#define GIT_BRANCH "?"
#endif
#ifndef GIT_COMMIT_MESSAGE
#define GIT_COMMIT_MESSAGE "?"
#endif
#ifndef GIT_DIRTY
#define GIT_DIRTY "?"
#endif
#ifndef GIT_TAG
#define GIT_TAG "?"
#endif
#define SPECIAL_WORKSPACE_START (-99) #define SPECIAL_WORKSPACE_START (-99)
@ -76,7 +61,9 @@
} }
#define FORMAT_FLAG(spec__, flag__) \ #define FORMAT_FLAG(spec__, flag__) \
case spec__: (flag__) = true; break; case spec__: \
(flag__) = true; \
break;
#define FORMAT_NUMBER(buf__) \ #define FORMAT_NUMBER(buf__) \
case '0': \ case '0': \
@ -88,7 +75,9 @@
case '6': \ case '6': \
case '7': \ case '7': \
case '8': \ case '8': \
case '9': (buf__).push_back(*it); break; case '9': \
(buf__).push_back(*it); \
break;
#if ISDEBUG #if ISDEBUG
#define UNREACHABLE() \ #define UNREACHABLE() \

5
src/version.h.in Normal file
View File

@ -0,0 +1,5 @@
#define GIT_COMMIT_HASH "@HASH@"
#define GIT_BRANCH "@BRANCH@"
#define GIT_COMMIT_MESSAGE "@MESSAGE@"
#define GIT_DIRTY "@DIRTY@"
#define GIT_TAG "@TAG@"