From 8896a34a13d9c7268288546e1e7af44deeacd069 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 6 May 2023 17:13:26 +0100 Subject: [PATCH] Overhaul version handling Stop using git for the version tag. The new process is as follows: 1. The `VERSION` file contains the version. For release, it should contain "1.5.0". Immediately after the release, it should be changed to "1.6.0-dev". 2. The build type is included in the version string unless it is "Release". The commit hash is now included into the version string whenever the `VERSION` file has a suffix (i.e. 1.5.0-dev rather than just 1.5.0). The full version string for development builds now looks like this: `1.5.0-dev-Debug-b102dccf8`. This means we longer need git or `-DVERSION_NUM` to get a sensible version number. The in-development versions are now always clearly indicated with the `-dev` suffix no matter how DevilutionX was built. --- .github/workflows/Linux_aarch64.yml | 7 +++- .github/workflows/Linux_x86.yml | 7 +++- .github/workflows/Linux_x86_64.yml | 7 +++- .github/workflows/Linux_x86_64_SDL1.yml | 7 +++- .../workflows/s390x_qemu_big_endian_tests.yml | 2 +- CMake/functions/git.cmake | 9 ----- CMakeLists.txt | 37 ++++++++++--------- Packaging/nix/LinuxReleasePackaging.sh | 2 +- VERSION | 1 + docs/building.md | 6 --- tools/make_src_dist.py | 24 ++++++------ tools/run_big_endian_tests.sh | 2 +- 12 files changed, 55 insertions(+), 56 deletions(-) create mode 100644 VERSION diff --git a/.github/workflows/Linux_aarch64.yml b/.github/workflows/Linux_aarch64.yml index 661948e1b..41a6c0dc3 100644 --- a/.github/workflows/Linux_aarch64.yml +++ b/.github/workflows/Linux_aarch64.yml @@ -40,8 +40,8 @@ jobs: uses: actions/cache@v3 with: path: build - key: ${{ github.workflow }}-v1-${{ github.sha }} - restore-keys: ${{ github.workflow }}-v1- + key: ${{ github.workflow }}-v2-${{ github.sha }} + restore-keys: ${{ github.workflow }}-v2- - name: Build working-directory: ${{github.workspace}} @@ -85,3 +85,6 @@ jobs: file: devilutionx-aarch64-linux-gnu.* file_glob: true overwrite: true + + - name: Clean up artifacts + run: rm -rf build/package build/*.deb build/*.rpm build/*.appimage build/*.tar.xz diff --git a/.github/workflows/Linux_x86.yml b/.github/workflows/Linux_x86.yml index 664b8246e..b5c8a5136 100644 --- a/.github/workflows/Linux_x86.yml +++ b/.github/workflows/Linux_x86.yml @@ -40,8 +40,8 @@ jobs: uses: actions/cache@v3 with: path: build - key: ${{ github.workflow }}-v2-${{ github.sha }} - restore-keys: ${{ github.workflow }}-v2- + key: ${{ github.workflow }}-v3-${{ github.sha }} + restore-keys: ${{ github.workflow }}-v3- - name: Build working-directory: ${{github.workspace}} @@ -86,3 +86,6 @@ jobs: file: devilutionx-i386-linux-gnu.* file_glob: true overwrite: true + + - name: Clean up artifacts + run: rm -rf build/package build/*.deb build/*.rpm build/*.appimage build/*.tar.xz diff --git a/.github/workflows/Linux_x86_64.yml b/.github/workflows/Linux_x86_64.yml index a9898d69e..16160cc6f 100644 --- a/.github/workflows/Linux_x86_64.yml +++ b/.github/workflows/Linux_x86_64.yml @@ -36,8 +36,8 @@ jobs: uses: actions/cache@v3 with: path: build - key: ${{ github.workflow }}-v1-${{ github.sha }} - restore-keys: ${{ github.workflow }}-v1- + key: ${{ github.workflow }}-v2-${{ github.sha }} + restore-keys: ${{ github.workflow }}-v2- - name: Build working-directory: ${{github.workspace}} @@ -78,3 +78,6 @@ jobs: file: devilutionx-x86_64-linux-gnu.* file_glob: true overwrite: true + + - name: Clean up artifacts + run: rm -rf build/package build/*.deb build/*.rpm build/*.appimage build/*.tar.xz diff --git a/.github/workflows/Linux_x86_64_SDL1.yml b/.github/workflows/Linux_x86_64_SDL1.yml index 84aaadf99..af8da0d89 100644 --- a/.github/workflows/Linux_x86_64_SDL1.yml +++ b/.github/workflows/Linux_x86_64_SDL1.yml @@ -33,8 +33,8 @@ jobs: uses: actions/cache@v3 with: path: build - key: ${{ github.workflow }}-v1-${{ github.sha }} - restore-keys: ${{ github.workflow }}-v1- + key: ${{ github.workflow }}-v2-${{ github.sha }} + restore-keys: ${{ github.workflow }}-v2- - name: Configure CMake shell: bash @@ -55,3 +55,6 @@ jobs: with: name: devilutionx_linux_x86_64_SDL1.tar.xz path: devilutionx.tar.xz + + - name: Clean up artifacts + run: rm -rf build/package build/*.deb build/*.rpm build/*.appimage build/*.tar.xz diff --git a/.github/workflows/s390x_qemu_big_endian_tests.yml b/.github/workflows/s390x_qemu_big_endian_tests.yml index cb1e527e2..d272b67e5 100644 --- a/.github/workflows/s390x_qemu_big_endian_tests.yml +++ b/.github/workflows/s390x_qemu_big_endian_tests.yml @@ -38,7 +38,7 @@ jobs: apk add --update-cache g++ ninja cmake ccache sdl2-dev sdl2_image-dev fmt-dev libpng-dev bzip2-dev gtest-dev wget && cd /host && export CCACHE_DIR=/host/.ccache && - cmake -S. -Bbuild -G Ninja -DNONET=ON -DNOSOUND=ON -DVERSION_NUM=1.0.0 -DVERSION_SUFFIX=FFFFFFF && + cmake -S. -Bbuild -G Ninja -DNONET=ON -DNOSOUND=ON && wget -nv -nc https://github.com/diasurgical/devilutionx-assets/releases/download/v2/spawn.mpq -P build && cmake --build build -j $(nproc) && ctest --test-dir build --output-on-failure -j $(nproc) diff --git a/CMake/functions/git.cmake b/CMake/functions/git.cmake index 97def8904..e68a5e1b4 100644 --- a/CMake/functions/git.cmake +++ b/CMake/functions/git.cmake @@ -1,12 +1,3 @@ -function(get_git_tag output_var) - execute_process( - COMMAND git describe --abbrev=0 --tags - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_TAG - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(${output_var} ${GIT_TAG} PARENT_SCOPE) -endfunction(get_git_tag) - function(get_git_commit_hash output_var) execute_process( COMMAND git log -1 --format=%h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cb59f0bf..27dfd75c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,27 +48,30 @@ include(VcPkgManifestFeatures) # 2. Toolchain file is evaluated, required for `Platforms.cmake`, # which can override the options. if(NOT VERSION_NUM) - include(functions/git) - get_git_tag(VERSION_NUM) - if(NOT "${VERSION_NUM}" STREQUAL "") - string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" VERSION_NUM ${VERSION_NUM} ) - endif() - if(NOT VERSION_SUFFIX) - get_git_commit_hash(GIT_COMMIT_HASH) - set(VERSION_SUFFIX "${GIT_COMMIT_HASH}") + file(STRINGS "VERSION" VERSION_STR) + if(NOT "${VERSION_STR}" STREQUAL "") + string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)(.*)?" VERSION_PREFIX ${VERSION_STR}) + set(VERSION_NUM ${CMAKE_MATCH_1}) endif() endif() + if(NOT VERSION_SUFFIX) - set(VERSION_SUFFIX "debug") -endif() -if(VERSION_NUM MATCHES untagged) - project(DevilutionX LANGUAGES C CXX) -else() - project(DevilutionX - VERSION ${VERSION_NUM} - LANGUAGES C CXX) + set(VERSION_SUFFIX "-$") + if(VERSION_PREFIX MATCHES "-") + if(NOT GIT_COMMIT_HASH) + include(functions/git) + get_git_commit_hash(GIT_COMMIT_HASH) + endif() + if(GIT_COMMIT_HASH) + set(VERSION_SUFFIX "${VERSION_SUFFIX}-${GIT_COMMIT_HASH}") + endif() + endif() endif() -set(PROJECT_VERSION_WITH_SUFFIX "${PROJECT_VERSION}$<$:-${VERSION_SUFFIX}>") + +project(DevilutionX + VERSION ${VERSION_NUM} + LANGUAGES C CXX) +set(PROJECT_VERSION_WITH_SUFFIX "${VERSION_PREFIX}$<$>:${VERSION_SUFFIX}>") # Platform definitions can override options and we want `cmake_dependent_option` to see the effects. # Note that a few options are still defined before this because they're needed by `VcPkgManifestFeatures.cmake`. diff --git a/Packaging/nix/LinuxReleasePackaging.sh b/Packaging/nix/LinuxReleasePackaging.sh index 9b84dfbe8..c40facaa9 100755 --- a/Packaging/nix/LinuxReleasePackaging.sh +++ b/Packaging/nix/LinuxReleasePackaging.sh @@ -5,7 +5,7 @@ set -x BUILD_DIR="${1-build}" mkdir -p "${BUILD_DIR}/package" -find "${BUILD_DIR}/_CPack_Packages/Linux/7Z/" -name 'devilutionx' -exec cp "{}" "${BUILD_DIR}/devilutionx" \; +find "${BUILD_DIR}/_CPack_Packages/Linux/7Z/" -type f -name 'devilutionx' -exec cp "{}" "${BUILD_DIR}/devilutionx" \; cp "${BUILD_DIR}/devilutionx" "${BUILD_DIR}/package/devilutionx" cp "${BUILD_DIR}/devilutionx.mpq" "${BUILD_DIR}/package/devilutionx.mpq" diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..bf0b12b59 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.5.0-dev diff --git a/docs/building.md b/docs/building.md index 9e1b50262..6efb78eba 100644 --- a/docs/building.md +++ b/docs/building.md @@ -5,12 +5,6 @@ all the dependencies that must be vendored, the version information, and `devilu This is the version most appropriate for packaging DevilutionX for Linux distributions. For other use cases, use the git repository. -Note: If you do not use git or `devilutionx-src.tar.xz` to get the source you must provide the version to CMake manually: - -```bash -cmake -S. -Bbuild -DVERSION_NUM=1.0.0 -DVERSION_SUFFIX=FFFFFFF -DCMAKE_BUILD_TYPE=Release -``` -
Linux Note that ```pkg-config``` is an optional dependency for finding libsodium, although we have a fallback if necessary. diff --git a/tools/make_src_dist.py b/tools/make_src_dist.py index e7752b929..48206f213 100755 --- a/tools/make_src_dist.py +++ b/tools/make_src_dist.py @@ -54,12 +54,10 @@ _LOGGER.addHandler(logging.StreamHandler(sys.stderr)) class Version(): - def __init__(self, num: bytes, suffix: bytes): - self.num = num - self.suffix = suffix - self.str = f'{num.decode()}' - if suffix: - self.str += f'-{suffix.decode()}' + def __init__(self, prefix: str, commit_sha: str): + self.prefix = prefix + self.commit_sha = commit_sha + self.str = f'{prefix}-{commit_sha}' if '-' in prefix else prefix def __str__(self) -> str: return self.str @@ -163,18 +161,18 @@ def ignore_dep_src(src, names): def get_version() -> Version: - git_tag = git('describe', '--abbrev=0', '--tags').rstrip() - git_commit_sha = git('rev-parse', '--short', 'HEAD').rstrip() - git_tag_sha = git('rev-parse', '--short', git_tag).rstrip() - return Version(git_tag, (git_commit_sha if git_tag_sha != git_commit_sha else None)) + version_prefix = None + with open('VERSION', 'r') as f: + version_prefix = f.read().rstrip() + git_commit_sha = git('rev-parse', '--short', 'HEAD').rstrip().decode() + return Version(version_prefix, git_commit_sha) def write_dist_cmakelists(paths: Paths, version: Version, fully_vendored: bool): with open(paths.dist_dir.joinpath('CMakeLists.txt'), 'wb') as f: f.write(b'# Generated by tools/make_src_dist.py\n') - f.write(b'set(VERSION_NUM "%s" PARENT_SCOPE)\n' % version.num) - if version.suffix: - f.write(b'set(VERSION_SUFFIX "%s" PARENT_SCOPE)\n' % version.suffix) + if version.commit_sha: + f.write(b'set(GIT_COMMIT_HASH "%s" PARENT_SCOPE)\n' % version.commit_sha.encode('utf-8')) f.write(b''' # Pre-generated `devilutionx.mpq` is provided so that distributions do not have to depend on smpq. diff --git a/tools/run_big_endian_tests.sh b/tools/run_big_endian_tests.sh index 4b6e76278..7c50654e8 100755 --- a/tools/run_big_endian_tests.sh +++ b/tools/run_big_endian_tests.sh @@ -15,7 +15,7 @@ fi docker run -u "$(id -u "$USER"):$(id -g "$USER")" --rm --mount "type=bind,source=${PWD},target=/host" devilutionx-s390x-test sh -c "cd /host && \ export CCACHE_DIR=/host/.s390x-ccache && \ cmake -S. -Bbuild-s390x-test -G Ninja -DASAN=OFF -DUBSAN=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \ - -DNONET=ON -DNOSOUND=ON -DVERSION_NUM=1.0.0 -DVERSION_SUFFIX=FFFFFFF && \ + -DNONET=ON -DNOSOUND=ON && \ ln -sf /opt/spawn.mpq /host/build-s390x-test/spawn.mpq && \ cmake --build build-s390x-test -j ${PARALLELISM} && \ ctest --test-dir build-s390x-test --output-on-failure -j ${PARALLELISM}"