Skip to content

Commit 18c25ef

Browse files
committed
Fix project version when not in cloned repository
1 parent 79a1072 commit 18c25ef

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ execute_process(
3535
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
3636
OUTPUT_VARIABLE GIT_COMMIT_HASH
3737
RESULT_VARIABLE GIT_COMMAND_SUCCESS
38-
OUTPUT_STRIP_TRAILING_WHITESPACE)
38+
OUTPUT_STRIP_TRAILING_WHITESPACE
39+
ERROR_QUIET)
3940

4041
if (GIT_COMMAND_SUCCESS EQUAL 0)
4142
set(SNITCH_FULL_VERSION "${PROJECT_VERSION}.${GIT_COMMIT_HASH}")
43+
else()
44+
set(SNITCH_FULL_VERSION "${PROJECT_VERSION}")
4245
endif()
4346

4447
# Create configure file to store CMake build parameter

snitch/meson.build

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
version = meson.project_version()
22
vers = version.split('.')
33

4-
git_hash = run_command(find_program('git'), 'log', '-1', '--format=%h', check:true).stdout().strip()
4+
git_command = run_command(find_program('git'), 'log', '-1', '--format=%h', check: false)
5+
if git_command.returncode() == 0
6+
git_hash = git_command.stdout().strip()
7+
full_version = version + '.' + git_hash
8+
else
9+
full_version = version
10+
endif
511

612
conf_data = configuration_data({
713
'PROJECT_VERSION' : version,
814
'PROJECT_VERSION_MAJOR' : vers[0],
915
'PROJECT_VERSION_MINOR' : vers[1],
1016
'PROJECT_VERSION_PATCH' : vers[2],
1117

12-
'SNITCH_FULL_VERSION' : version + '.' + git_hash,
18+
'SNITCH_FULL_VERSION' : full_version,
1319

1420
'SNITCH_MAX_TEST_CASES' : get_option('max_test_cases'),
1521
'SNITCH_MAX_NESTED_SECTIONS' : get_option('max_nested_sections'),

0 commit comments

Comments
 (0)