-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
git version #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This should do what you need. |
Interesting, but how does that help to specify the project version? |
It can't. Project versions must be written by hand and be explicit. It must also work when Git is not installed. The common approach is to have a sensible version number in |
It's not the same though, git-version-gen allows to generate incremental version for each commit, and avoid having hard-coded version duplication. It's not simply about the git hash. |
I'm not sure I understand how that's not covered by the |
By default vcs_tag will output something using |
What is project() version used for? According to reference manual, it's just for later reference with meson.project_version(), but if you use vcs_tag you'll probably not use it. Similarly what is the project name for? I can't even find a 'dist' target. Is there a way to list available targets? Btw, it would be quite helpeful if the reference manual had function declarations: project(project_name, language1, language2 ...) Meson is quite confusing when coming from autofoo or even plain Makefile, and documentation has a lot to be desired. A guess a more complete hello-world project (not just http://mesonbuild.com/samples.html or test cases in meson.git), including binary, static library, shared library, tests.. would help a lot. |
I wish there would be a meson version of GNU hello: http://git.savannah.gnu.org/cgit/hello.git |
Project versions are used when importing subprojects. They allow you you specify version limits similar to
The wiki has a more in-depth tutorial, which should be what you want. The function declarations thing is a known issue. Unfortunately Github's wiki formatting is limited so it is hard to make it look similar to e.g. gtk-doc output. |
Is there anything else you need here, @elmarco? |
@nirbheek I haven't tried recently, and I have not good knowledge of meson. Afaik, it's not possible to let the version be generated from git describe, like git-version-gen does. |
It's almost possible to use an approach similar to git-version-gen, since you should be able to run_command() like that:
However, there is no easy way I can think of to ship .tarball_version... That file should be generated at dist time, and not kept in the build directory after dist, but should be included in dist. |
Resolving #2166 would provide one, I think? |
I am also interested in having some automagic git tag versioneering, much like https://github.com/pypa/setuptools_scm. It's just so convenient to not have to do boring version bump commits and being able to do a release by tagging a commit in a UI. |
Question for @elmarco: if the |
@axxel that sounds like it would be enough. fwiw, Eduardo Lima managed to somehow use git-version-gen in spice-gtk: https://gitlab.freedesktop.org/spice/spice-gtk/blob/master/meson.build#L5 I haven't looked at the details, but my feeling is that this could be simplified by some common meson facilities. |
actually, his solution doesn't work, tarball-version isn't shipped, and make dist fails. |
Even if it would work, it would not be quite the same thing: the Also, I was not proposing to somehow make the meson.project_version() 'automacially' return the vcs version of the current wc, albeit I would see the conceptual benefit of that: You'd had only one kind of version to reason about. It would also naturally fix #3903. @jpakkane: would you consider merging something along the lines of:
It would make the |
Since I got no reaction from Jussi to my "would you consider merging...?" question above, I did not further investigate this idea. |
I think it would make sense to have it as new function (e.g. From an implementation POV, it would be a @jpakkane any objection? |
Any system that sets up the vcs tag version via a |
Just to make sure I understand your objection correctly: a reconfiguration would be necessary after every WC state change (like commit, checkout, etc.) not on every build attempt. How long does a reconfiguration after a manual change of the version info in the |
Worst case that I know of is tens of seconds. But even worse is that it changes an operation (empty build) from something that is instantaneous to something that is noticeable. This is poor UX. |
Tens of seconds sounds not very nice (in and of itself) indeed. But going one step back and looking at the issue from a top level point of view, this cost is what you have to pay for getting an up to date Apart from that: would it not be possible to speed up the reconfiguration by caching data if the only change is known to be the version string? |
I just spent an hour going through issue #2166 and playing around with add_dist_script(), add_postconf_script() etc., but none of these really work. I wrote a little #!/bin/sh
set -eux
ROOT=$(dirname $(dirname $(realpath "$0")))
STAMP="$ROOT/.version"
[ ! -e "$ROOT/.git" ] || git describe > "$STAMP"
if [ -e "$STAMP" ]; then
cat "$STAMP"
else
echo "ERROR: Neither a git checkout nor $STAMP, cannot determine version" >&2
exit 1
fi But I can't figure out how to integrate that into meson.build. add_dist_script() does not have access to the git checkout (so can't run Did anyone here happen to have a solution for this? It feels to me like one could coerce all these building blocks into something that works, but the meson docs nor google make this really hard to figure out.. I'd even go as far as saying that meson should have some builtin default of taking the release number from git (and storing it in the dist tarball somehow), but at least documenting a supported way would be really nice. Thanks! |
It should, though? There are 3 documented environment variables:
The first one is, obviously, the temporary staging directory without access to the git checkout. The other two are documented as only set for dist scripts since 0.54.0; they were previously only available in other types of scripts. Regardless of which type of script is being run, if |
I do want to eventually add this kind of thing. I have some thoughts about how it might work. The tricky part is probably figuring out how to handle |
@eli-schwartz : I did find these env variables in the docs, but they didn't seem to help me. On top of the initial naive broken attempt I added a debug commit which shows all the env variables that contain "MESON", and the current dir:
That That's why I was looking into _postconf_hook(), as that runs in the source dir. (This is meson 0.62.2) |
Ah, another thing I tried yesterday: --- meson.build
+++ meson.build
@@ -44,7 +44,7 @@ if cc.has_function('__fxstatat', prefix: '#include <sys/stat.h>')
add_project_arguments('-DHAVE_FXSTATAT', language: 'c')
endif
-meson.add_dist_script(srcdir / 'getversion.sh')
+meson.add_dist_script(srcdir / 'getversion.sh', meson.current_source_dir())
#
# dependencies
diff --git src/getversion.sh src/getversion.sh
index e2922f1..9c01ed6 100755
--- src/getversion.sh
+++ src/getversion.sh
@@ -1,5 +1,6 @@
#!/bin/sh
set -eux
+echo "ARG1: ${1:-}" >&2
pwd >&2
env | grep MESON >&2
ROOT=$(dirname $(dirname $(realpath "$0"))) as the documentation says that you can pass arguments to add_dist_script(). But it is not actually getting passed, |
You're running getversion.sh twice, once as a dist script and once as a project() version kwarg. So I guess it is erroring out after the dist, once it tries testing the dist. |
Thanks @eli-schwartz ! Indeed, the script needs to cover these cases as well. I am getting somewhere now in the branch, still fighting with getting this to green on all the OS tests. I'll report here once I have a fully working solution, as several other people are interested in this as well. |
So, with a rather large amount of stubbornness I figured it out. Here is the commit, if you ignore the bits in tests/, it is generic (i.e. nothing umockdev specific). Now I can change the release workflow, and finally the release process will be "push a signed tag with the release news in the tag body", and that takes care of the upstream and all Fedora releases. |
Would it be possible to adopt a solution in the style of @martinpitt's? I'm thinking something like project('demo', 'c',
version : improved_vcs_tag(fallback : '@MESON_VERSION@')) where the distributed It would be even nicer if it could work without the fallback argument. As part of if meson.project_version().is_set_from_vcs():
meson.rewrite_kwargs.set(project : '/', {'version' : meson.project_version()}) where the rewrite happens on the edit: I'm guessing all that is really missing is a way to access the dist root from the meson build file, allowing meson.add_dist_script('meson', 'rewrite', '-s', meson.dist_root(), 'kwargs', 'set', 'project', '/', 'version', meson.project_version()) edit2: The dist root is available from the environment as edit3: The first solution I suggested is almost possible by setting the version = "$Format:%(describe)$"
if version.endswith("$") and version.startswith("$Format:")
version = run_command('git', 'log', '-1', '--format=' + version.substring(8, -1)).stdout().strip()
endif but meson does not support setting variables before calling |
While I still stand behind #12804/#12782, I just thought of a more elegant way. We could make project('demo', 'c',
version : import('git').expand('$Format:%(describe)$')) work. Adding |
Very cool, thanks @jpakkane ! 🌟 |
Many projects rely on git generated version. git itself, and there is the popular http://git.savannah.gnu.org/cgit/autoconf.git/tree/build-aux/git-version-gen for autoconf. Other projects use similar scripts.
It would be great if meson had a 'git-version-gen' option in project()
The text was updated successfully, but these errors were encountered: