Skip to content
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

Add and use version.py #79671

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft

Add and use version.py #79671

wants to merge 29 commits into from

Conversation

alef
Copy link
Contributor

@alef alef commented Feb 15, 2025

Summary

Build "Add and use version.py"

Purpose of change

The project was creating src/version.h and VERSION.txt in many ways.

Describe the solution

All logic is now handled by a single Python v3.8 script.
This Python version is available in the oldest project baseline.
Windows build was not requiring Python but this PR documentation will add it as requirement.

Describe alternatives you've considered

None

Testing

The following build methods succeed and the game + VERSION.txt show the correct version:

  • Visual Studio 2022 Solution and CMake on Windows
  • Visual Studio Code CMake on Windows
  • Makefile on Ubuntu 20.04
  • Makefile and CMake on Ubuntu 22
  • I can't do macOS
  • I can't do Android

Additional context

Draft PR to let others review while testing.

@github-actions github-actions bot added <Documentation> Design documents, internal info, guides and help. Code: Build Issues regarding different builds and build environments [Markdown] Markdown issues and PRs [Python] Code made in Python Code: Tooling Tooling that is not part of the main game but is part of the repo. json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Feb 15, 2025
@github-actions github-actions bot added BasicBuildPassed This PR builds correctly, label assigned by github actions and removed BasicBuildPassed This PR builds correctly, label assigned by github actions labels Feb 15, 2025
@moxian
Copy link
Contributor

moxian commented Feb 15, 2025

I haven't looked at the changes remotely in depth yet, but If python is a hard requirement, then this would need a documentation update.
It might also be nice to fall back and somehow skip version generation if python isn't found. Just so as not to bother the user needlessly (i think we already do something like this when we can't find git?)

Draft PR to let others review while testing.

I found it rather convenient to employ github's CI to test platform-sweeping changes like this one. Just make a PR to your own fork, and ensure that all the checks pass (see this mess: https://github.com/moxian/Cataclysm-DDA/pulls). Personal-fork checks would be much faster than upstream too since they all can run in parallel.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Feb 15, 2025
Copy link
Contributor

@moxian moxian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the python. Left some comments.

cat >VERSION.txt <<EOL
build type: ${{ matrix.artifact }}
build number: ${{ needs.release.outputs.timestamp }}
commit sha: ${{ github.sha }}
commit url: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
EOL
python3 build-scripts/version.py ARTIFACT=${{ matrix.artifact }} TIMESTAMP=${{ needs.release.outputs.timestamp }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave this one be? It's not doing any sort of git invocations, or any complex logic.
It's only needed for release, not in the normal dev workflow, there should be no need to move it into python, right? It would make the script more lightweight too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but I would prefer keeping the option that a release build can be done offline without GHA.

@@ -230,7 +230,7 @@ jobs:
if: ${{ env.SKIP == 'false' && runner.os == 'Linux' }}
run: |
sudo apt-get update
sudo apt-get install libncursesw5-dev ccache gettext parallel
sudo apt-get install libncursesw5-dev ccache gettext parallel python-is-python3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for CI, but I'm not convinced we can require our users to have this installed. Even if it works for ubuntu, it might not for other distros.

I think it would be much better to handle this in Makefile instead, since we can. Something like

PYTHON=$(shell which python || which python3)
version:
    $(PYTHON) build-scripts/version.py

printf '// NOLINT(cata-header-guard)\n#define VERSION "%s"\n' "$$VERSION_STRING" | tee $(SRC_DIR)/version.h ; \
fi \
)
python build-scripts/version.py VERSION=$(VERSION) ARTIFACT=$(ARTIFACT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARTIFACT is not defined here at all

Comment on lines +8 to +9
VERSION=<version>
VERSION_STRING=<version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's surprising to accept both VERSION and VERSION_STRING which are synonyms, and which get overwritten by the output of git anyway.

try:
git = subprocess.run(('git', 'rev-parse', '--is-inside-work-tree'),
capture_output=True)
except FileNotFoundError: # `git` command is missing
Copy link
Contributor

@moxian moxian Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The present makefile tolerates lack of git. It might be something worth preserving.

I also realized that it should be technically possible to build cdda from a tarball that has no .git/ in it (and I believe existing Makefile tries to work around that as well)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions Code: Build Issues regarding different builds and build environments Code: Tooling Tooling that is not part of the main game but is part of the repo. <Documentation> Design documents, internal info, guides and help. json-styled JSON lint passed, label assigned by github actions [Markdown] Markdown issues and PRs [Python] Code made in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants