Skip to content

Commit

Permalink
Merge pull request #93 from cschreib/no_git
Browse files Browse the repository at this point in the history
Fix project version when not in cloned repository
  • Loading branch information
cschreib authored May 2, 2023
2 parents 79a1072 + 18c25ef commit d7cc8f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ execute_process(
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
RESULT_VARIABLE GIT_COMMAND_SUCCESS
OUTPUT_STRIP_TRAILING_WHITESPACE)
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)

if (GIT_COMMAND_SUCCESS EQUAL 0)
set(SNITCH_FULL_VERSION "${PROJECT_VERSION}.${GIT_COMMIT_HASH}")
else()
set(SNITCH_FULL_VERSION "${PROJECT_VERSION}")
endif()

# Create configure file to store CMake build parameter
Expand Down
10 changes: 8 additions & 2 deletions snitch/meson.build
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
version = meson.project_version()
vers = version.split('.')

git_hash = run_command(find_program('git'), 'log', '-1', '--format=%h', check:true).stdout().strip()
git_command = run_command(find_program('git'), 'log', '-1', '--format=%h', check: false)
if git_command.returncode() == 0
git_hash = git_command.stdout().strip()
full_version = version + '.' + git_hash
else
full_version = version
endif

conf_data = configuration_data({
'PROJECT_VERSION' : version,
'PROJECT_VERSION_MAJOR' : vers[0],
'PROJECT_VERSION_MINOR' : vers[1],
'PROJECT_VERSION_PATCH' : vers[2],

'SNITCH_FULL_VERSION' : version + '.' + git_hash,
'SNITCH_FULL_VERSION' : full_version,

'SNITCH_MAX_TEST_CASES' : get_option('max_test_cases'),
'SNITCH_MAX_NESTED_SECTIONS' : get_option('max_nested_sections'),
Expand Down

0 comments on commit d7cc8f5

Please sign in to comment.