From e95acdfe1d3a790e18617bb992a712b34f41800d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 29 Jul 2023 22:41:43 +0900 Subject: [PATCH] meson: drop short script to generate vcs tag --- meson.build | 64 ++++++++++++++++++++++++------------------ tools/meson-vcs-tag.sh | 19 ------------- 2 files changed, 36 insertions(+), 47 deletions(-) delete mode 100755 tools/meson-vcs-tag.sh diff --git a/meson.build b/meson.build index 26deafd562..9efb0bd778 100644 --- a/meson.build +++ b/meson.build @@ -631,34 +631,6 @@ endif ##################################################################### -version_tag = get_option('version-tag') -if version_tag != '' - vcs_data = configuration_data() - vcs_data.set('VCS_TAG', version_tag) - version_h = configure_file(configuration : vcs_data, - input : 'src/version/version.h.in', - output : 'version.h') -else - vcs_tagger = [ - project_source_root + '/tools/meson-vcs-tag.sh', - project_source_root, - meson.project_version()] - - version_h = vcs_tag( - input : 'src/version/version.h.in', - output : 'version.h', - command: vcs_tagger) -endif - -versiondep = declare_dependency( - sources: version_h, - include_directories : include_directories('.')) - -shared_lib_tag = get_option('shared-lib-tag') -if shared_lib_tag == '' - shared_lib_tag = meson.project_version() -endif - sh = find_program('sh') echo = find_program('echo') sed = find_program('sed') @@ -2145,6 +2117,42 @@ xml_helper_py = find_program('tools/xml_helper.py') ############################################################ +version_tag = get_option('version-tag') +if version_tag == '' + # Check that we have either .git/ (a normal clone) or a .git file (a work-tree) and that we don't + # get confused if a tarball is extracted in a higher-level git repository. + if git.found() and fs.exists(project_source_root / '.git') + # Apparently git describe has a bug where it always considers the work-tree dirty when + # invoked with --git-dir (even though 'git status' is happy). Work around this issue by + # cd-ing to the source directory. + version_tag = run_command( + sh, '-c', + 'cd "$MESON_SOURCE_ROOT"; git describe --abbrev=7 --dirty=^ 2>/dev/null | sed "s/^v//; s/-rc/~rc/"', + check : true, + ).stdout().strip() + else + version_tag = meson.project_version() + endif +endif + +vcs_data = configuration_data() +vcs_data.set('VCS_TAG', version_tag) +version_h = configure_file(configuration : vcs_data, + input : 'src/version/version.h.in', + output : 'version.h') + +versiondep = declare_dependency( + sources : version_h, + include_directories : include_directories('.'), +) + +shared_lib_tag = get_option('shared-lib-tag') +if shared_lib_tag == '' + shared_lib_tag = meson.project_version() +endif + +############################################################ + if get_option('b_coverage') userspace_c_args += ['-include', 'src/basic/coverage.h'] endif diff --git a/tools/meson-vcs-tag.sh b/tools/meson-vcs-tag.sh deleted file mode 100755 index 3964a8e198..0000000000 --- a/tools/meson-vcs-tag.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: LGPL-2.1-or-later - -set -eu -set -o pipefail - -dir="${1:?}" -fallback="${2:?}" - -# Apparently git describe has a bug where it always considers the work-tree -# dirty when invoked with --git-dir (even though 'git status' is happy). Work -# around this issue by cd-ing to the source directory. -cd "$dir" -# Check that we have either .git/ (a normal clone) or a .git file (a work-tree) -# and that we don't get confused if a tarball is extracted in a higher-level -# git repository. -[ -e .git ] && \ - git describe --abbrev=7 --dirty=^ 2>/dev/null | sed 's/^v//; s/-rc/~rc/' || \ - echo "$fallback"