diff mbox series

[2/9] GIT-VERSION-GEN: move default version into a separate file

Message ID 20250113-b4-pks-meson-additions-v1-2-97f6a93f691d@pks.im (mailing list archive)
State Superseded
Headers show
Series meson: a couple of additions | expand

Commit Message

Patrick Steinhardt Jan. 13, 2025, 8:33 a.m. UTC
The Git version for Meson is currently wired up manually. It can thus
grow (and alread has grown) stale quite easily, as having multiple
sources of truth is never a good idea. This issue is mostly of cosmetic
nature as we don't use the project version anywhere, and instead use the
GIT-VERSION-GEN script to propagate the correct version into our build.
But it is somewhat puzzling when `meson setup` announces to build an old
Git release.

There are a couple of alternatives for how to solve this:

  - We can keep the version undefined, but this makes Meson output
    "undefined" for the version, as well.

  - We can adapt GIT-VERSION-GEN so that it knows to print a version to
    stdout with a specific invocation and then use `run_command()`. At
    the point of configuring the project we haven't yet figured out host
    details though, and thus we didn't yet set up the shell environment.
    While not an issue for Unix-based systems, this would be an issue in
    Windows, where the shell typically gets provided via Git for Windows
    and thus requires some special setup.

  - We can pull the default version out of GIT-VERSION-GEN and move it
    into its own file. This likely requires some adjustments for scripts
    that bump the version, but allows Meson to read the version from
    that file trivially.

The last option is a proper solution and quite trivial to implement, and
adapting scripts should be a one-time event. Refactor GIT-VERSION-GEN
accordingly.

This refactoring also prepares for a planned consolidation of all build
scripts into a separate folder. This should reduce clutter and make it
easier to find all scripts part of the build process.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 GIT-VERSION     | 1 +
 GIT-VERSION-GEN | 4 ++--
 meson.build     | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

Comments

Junio C Hamano Jan. 13, 2025, 5:42 p.m. UTC | #1
Patrick Steinhardt <ps@pks.im> writes:

>   - We can pull the default version out of GIT-VERSION-GEN and move it
>     into its own file. This likely requires some adjustments for scripts
>     that bump the version, but allows Meson to read the version from
>     that file trivially.
>
> The last option is a proper solution and quite trivial to implement, and
> adapting scripts should be a one-time event. Refactor GIT-VERSION-GEN
> accordingly.

It is not clear what "proper" is.  It smells like we are bending an
established work flow element to placate a tool that is not willing
to cooperate, which is very much unwelcome.

Compared to that, grepping for "^DEF_VER=" in the file may be less
yucky.
Eli Schwartz Jan. 13, 2025, 5:51 p.m. UTC | #2
On 1/13/25 12:42 PM, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> 
>>   - We can pull the default version out of GIT-VERSION-GEN and move it
>>     into its own file. This likely requires some adjustments for scripts
>>     that bump the version, but allows Meson to read the version from
>>     that file trivially.
>>
>> The last option is a proper solution and quite trivial to implement, and
>> adapting scripts should be a one-time event. Refactor GIT-VERSION-GEN
>> accordingly.
> 
> It is not clear what "proper" is.  It smells like we are bending an
> established work flow element to placate a tool that is not willing
> to cooperate, which is very much unwelcome.


If I understand correctly, the constraint is that it should work on
Windows, which means there is a bootstrap issue regarding detection of
an "sh" command for running ./GIT-VERSION-GEN

Proper simply means it works reliably on all supported targets.


> Compared to that, grepping for "^DEF_VER=" in the file may be less
> yucky.


Or for the sake of Windows portability, grep_version.py?
Patrick Steinhardt Jan. 14, 2025, 9:13 a.m. UTC | #3
On Mon, Jan 13, 2025 at 12:51:59PM -0500, Eli Schwartz wrote:
> On 1/13/25 12:42 PM, Junio C Hamano wrote:
> > Patrick Steinhardt <ps@pks.im> writes:
> > 
> >>   - We can pull the default version out of GIT-VERSION-GEN and move it
> >>     into its own file. This likely requires some adjustments for scripts
> >>     that bump the version, but allows Meson to read the version from
> >>     that file trivially.
> >>
> >> The last option is a proper solution and quite trivial to implement, and
> >> adapting scripts should be a one-time event. Refactor GIT-VERSION-GEN
> >> accordingly.
> > 
> > It is not clear what "proper" is.  It smells like we are bending an
> > established work flow element to placate a tool that is not willing
> > to cooperate, which is very much unwelcome.
> 
> 
> If I understand correctly, the constraint is that it should work on
> Windows, which means there is a bootstrap issue regarding detection of
> an "sh" command for running ./GIT-VERSION-GEN
> 
> Proper simply means it works reliably on all supported targets.

Yeah, exactly, that's the issue. We could of course try to use
GIT-VERSION-GEN anyway and just fall back to an empty string if the
command wasn't found. We don't use the project version anyway, so it's
only a cosmetic problem. And it's more accurate than extracting DEF_VER,
too.

> > Compared to that, grepping for "^DEF_VER=" in the file may be less
> > yucky.
> 
> Or for the sake of Windows portability, grep_version.py?

I don't want to make Python an explicit dependency for building Git, and
due to Muon it isn't even with the Meson build infra.

Patrick
diff mbox series

Patch

diff --git a/GIT-VERSION b/GIT-VERSION
new file mode 100644
index 0000000000000000000000000000000000000000..ed39430ff189488182bc6d651bdb88a531498baa
--- /dev/null
+++ b/GIT-VERSION
@@ -0,0 +1 @@ 
+v2.48.0
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 754b8ca9eedaa2f7e3b61c83c1cc763538394fe6..95d7d41d233450774a6580c0de332e7b8f69eb4e 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,7 +1,5 @@ 
 #!/bin/sh
 
-DEF_VER=v2.48.0
-
 LF='
 '
 
@@ -21,6 +19,8 @@  then
 	exit 1
 fi
 
+DEF_VER=$(cat "$SOURCE_DIR"/GIT-VERSION)
+
 # Protect us from reading Git version information outside of the Git directory
 # in case it is not a repository itself, but embedded in an unrelated
 # repository.
diff --git a/meson.build b/meson.build
index 7361eb2eaad422e7a6c6ed95d275615836c21cdb..87755537d2aff84a9d8e86f0f5b025ef8dd23292 100644
--- a/meson.build
+++ b/meson.build
@@ -170,7 +170,7 @@ 
 
 project('git', 'c',
   meson_version: '>=0.61.0',
-  version: 'v2.47.GIT',
+  version: files('GIT-VERSION'),
 )
 
 fs = import('fs')