Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

tools: add dir-version to print a package version from git references

Open illwieckz opened this issue 1 year ago • 7 comments

This is an extraction and a port to Python of the printVersion function from the release-scripts/build-release script, the produced version string is usable for dpk archives, but also fr other things like unizip or the symbols zip for which we expect to have the same version string of the game dpk.

This is a standalone re-implementation of what is done in Urcheon for computing dpk version strings.

This is usable in two ways:

Without argument:

tools/repo-version/repo-version

This prints the version string for the current directory.

With argument:

tools/repo-version/repo-version 'path/to/some/other/repository'

This prints the version string for the given repository path passed as argument.

This script is stored in Dæmon repository because I want a common place for it. We may even use it when doing nightly builds of the engine only, or things like that.

illwieckz avatar Jan 02 '24 13:01 illwieckz

Without argument:

tools/git-version/git-version

This prints the version string for the repository the script is stored,

With argument:

tools/git-version/git-version 'path/to/some/other/repository'

This prints the version string for the given repository path passed as argument.

I would find the no-argument behavior surprising, expecting it to use the current directory rather than Daemon's directory.

slipher avatar Jan 02 '24 19:01 slipher

I would find the no-argument behavior surprising, expecting it to use the current directory rather than Daemon's directory.

Hmm, right, this would also remove the need for a wrapper in Unvanquished repo.

illwieckz avatar Jan 03 '24 10:01 illwieckz

I would find the no-argument behavior surprising, expecting it to use the current directory rather than Daemon's directory.

Now using the current directory.

illwieckz avatar Apr 06 '24 17:04 illwieckz

My original code was purposed to also handles the cases when:

  • the directory is not a Git repository yet
  • there is no commit yet
  • there is no tag yet

And to provide fallbacks to them.

The reason why I want that is that such permissivity is useful in Urcheon, and at some point I want this code to be exactly the same in Urcheon (I'll replace current Urcheon version code with this one, as it is more mature and less convoluted).

So I finally made the script erroring on Git errors, and made it not sending Git error message to /dev/null, by default. But I also added options to ignore and silence errors, so I can merge this back in Urcheon later.

We may want to check for the directory always being a repository in the Unvanquished release script, so having this code aborting on error and printing errors is fine. Same if one day we wire it into cmake to embed the result as internal game version string.

illwieckz avatar Apr 07 '24 01:04 illwieckz

I renamed the tool to dir-version, because it prints a version string for a given directory, either being a git repository or not, either being a subdir of the repository or not.

I finally ported and improved the complete dirt detection code from Urcheon.

  • It reports the version as dirty if there are uncommitted and untracked files in the directory.
  • It doesn't report the version as dirty if the modified file is outside of the directory the script is computing a version from, even if the directory is from the same git repository.

The second feature means doing this dir-version Unvanquished/pkg/unvanquished_src.dpkdir doesn't report the version as dirty if there is a change outside of this directory, despite this directory being part of the same Unvanquished/ repository.

I added a --whole option to force looking for dirt in the whole repository the directory is part of. For example that will report dirt from Unvanquished/src and other places fromUnvanquished when doing dir-version Unvanquished/pkg/unvanquished_src.dpkdir.

illwieckz avatar Apr 08 '24 08:04 illwieckz

Some things I'm still thinking about:

  • I'm not entirely happy with the name, I may rename it git-dir-version/GitDirVersion.

I'm not happy with the original git-version/GitVersion because it was confusing it may provide the version of Git itself, but I'm not happy with repo-version/RepoVersion or dir-version/DirVersion because this is a tool to compute a Git-based version (with a non-Git optional fallback) for a source directory. Git is always required even when the directory is not tracked by Git (to know it's not tracked by Git).

  • I will probably implement the integration of this new lib in some Urcheon branch before merging it there to make sure it works in Urcheon too to avoid some back and forth merge roundtrips.

  • I may add an option to provide a custom/explicit Git binary path (may be useful when integrating things like CMake to make sure we use the same Git CMake uses).

illwieckz avatar Apr 09 '24 05:04 illwieckz

I would name the tool version-string

slipher avatar Apr 09 '24 18:04 slipher