From f7f3c70f1e8e3ece21bc3e1d759dc79a78fa856c Mon Sep 17 00:00:00 2001 From: progandy Date: Thu, 14 Feb 2019 00:53:14 +0100 Subject: [PATCH] meson: better version string for exported archives Use the gitattribute 'export-subst' to include some commit information in meson.build during 'git archive' operations. --- .gitattributes | 1 + meson.build | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..426acfbc4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +meson.build export-subst diff --git a/meson.build b/meson.build index 2336a1489..fb06fbe5e 100644 --- a/meson.build +++ b/meson.build @@ -11,6 +11,10 @@ project( ], ) +gitinfo_hash='$Format:%h$' +gitinfo_tree='$Format:%t$' +gitinfo_refname='$Format:%D$' + add_project_arguments( [ '-DSWAY_SRC_DIR="@0@"'.format(meson.current_source_dir()), @@ -129,6 +133,18 @@ endif add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)), language : 'c') version = '"@0@"'.format(meson.project_version()) +version_extras = [] +if not gitinfo_hash.startswith('$') + version_extras += ['id \'@0@\''.format(gitinfo_hash)] +elif not gitinfo_tree.startswith('$') + version_extras += ['tree \'@0@\''.format(gitinfo_tree)] +endif +if not gitinfo_refname.startswith('$') + version_extras += ['refs \'@0@\''.format(gitinfo_refname)] +endif +if version_extras.length() > 0 + version = '"@0@ (@1@)"'.format(meson.project_version(), ', '.join(version_extras)) +endif if git.found() git_commit_hash = run_command([git.path(), 'describe', '--always', '--tags']) git_branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD'])