From: Zbigniew Jędrzejewski-Szmek Date: Sat, 26 Aug 2023 07:17:44 +0000 (+0200) Subject: meson: simplify version_tag handling X-Git-Tag: v255-rc1~639^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1671799beefc55675a03b669cee5381f3f06c8e5;p=thirdparty%2Fsystemd.git meson: simplify version_tag handling Let's also use vcs_tag() when we're doing a non-git build. In those scenarios, the build would normally be done just once in a given copy, so doing an extra call does not matter. We can save a few lines of meson config. The special path was added in 064b8e2c99ceb348c515353cc5c7d7bd05c49fcb, with the justifaction that vcs_tag() is slow and -Dversion-tag=foo can be used to fix the version tag and speed up partial rebuilds. I think the justification for this is weak: having an accurate version tag is particularly useful when developing the code. Shaving of a fraction of a second at the cost of having to manually update the version seems iffy. Secondly, with vcs_tag() we can be pretty sure that meson will build the version file first and that it'll be available to all build steps. Because we didn't use version tag, we had to manually specify the dependency on version.h in various places. It seems nicer to use vcs_tag() and not have to deal with this problem at all. Finally, the savings in time seem much smaller than back when 064b8e2c99ceb348c515353cc5c7d7bd05c49fcb was made. It reported a change from 94 ms to 521 ms. But now the difference seems to be about 50 ms: Before this patch: $ time ninja -C build ninja: Entering directory `build' ninja: no work to do. ninja -C build 0.04s user 0.02s system 97% cpu 0.057 total ninja -C build 0.03s user 0.01s system 97% cpu 0.049 total ninja -C build 0.03s user 0.02s system 96% cpu 0.051 total ninja -C build 0.03s user 0.01s system 96% cpu 0.049 total ninja -C build 0.03s user 0.01s system 97% cpu 0.046 total With the two patches in this PR: systemd-stable [drop-versiondep] time ninja -C build ninja: Entering directory `build' [1/669] Generating version.h with a custom command ninja -C build 0.08s user 0.03s system 98% cpu 0.106 total ninja -C build 0.08s user 0.03s system 98% cpu 0.104 total ninja -C build 0.09s user 0.02s system 98% cpu 0.116 total ninja -C build 0.08s user 0.02s system 97% cpu 0.108 total Overall, I think the tiny time savings are not worth the complexity. --- diff --git a/meson.build b/meson.build index 52e3ebad34f..a599c0ca8f3 100644 --- a/meson.build +++ b/meson.build @@ -1811,27 +1811,24 @@ version_tag = get_option('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 version_tag == '' and git.found() and fs.exists(project_source_root / '.git') - version_h = vcs_tag( - input : 'src/version/version.h.in', - output : 'version.h', - # If the working tree has no tags (CI builds), the first git-describe will fail - # and we fall back to project_version-commitid instead. - # TODO: Use 'sh' variable with meson >= 0.63.0 - command: ['sh', - '-euc', - '''git -C "$1" describe --abbrev=7 --dirty=^ 2>/dev/null || - echo "$2-$(git -C "$1" describe --always --abbrev=7)" | - sed 's/^v//; s/-rc/~rc/' ''', - '_', - project_source_root, - meson.project_version()]) + # If the working tree has no tags (CI builds), the first git-describe will fail + # and we fall back to project_version-commitid instead. + version_cmd = '''git -C "$1" describe --abbrev=7 --dirty=^ 2>/dev/null || + echo "$2-$(git -C "$1" describe --always --abbrev=7)" | + sed 's/^v//; s/-rc/~rc/' ''' else - vcs_data = configuration_data() - vcs_data.set('VCS_TAG', version_tag == '' ? meson.project_version() : version_tag) - version_h = configure_file(configuration : vcs_data, - input : 'src/version/version.h.in', - output : 'version.h') -endif + version_cmd = '''echo "$2" ''' +endif + +version_h = vcs_tag( + input : 'src/version/version.h.in', + output : 'version.h', + # TODO: Use 'sh' variable with meson >= 0.63.0 + command: ['sh', '-euc', version_cmd, + '_', + project_source_root, + version_tag == '' ? meson.project_version() : version_tag, + ]) versiondep = declare_dependency( sources : version_h,