Browse Source

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.
pull/6084/head
Gleb Mazovetskiy 3 years ago
parent
commit
8896a34a13
  1. 7
      .github/workflows/Linux_aarch64.yml
  2. 7
      .github/workflows/Linux_x86.yml
  3. 7
      .github/workflows/Linux_x86_64.yml
  4. 7
      .github/workflows/Linux_x86_64_SDL1.yml
  5. 2
      .github/workflows/s390x_qemu_big_endian_tests.yml
  6. 9
      CMake/functions/git.cmake
  7. 37
      CMakeLists.txt
  8. 2
      Packaging/nix/LinuxReleasePackaging.sh
  9. 1
      VERSION
  10. 6
      docs/building.md
  11. 24
      tools/make_src_dist.py
  12. 2
      tools/run_big_endian_tests.sh

7
.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

7
.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

7
.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

7
.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

2
.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)

9
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

37
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 "-$<CONFIG>")
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}$<$<CONFIG:Debug>:-${VERSION_SUFFIX}>")
project(DevilutionX
VERSION ${VERSION_NUM}
LANGUAGES C CXX)
set(PROJECT_VERSION_WITH_SUFFIX "${VERSION_PREFIX}$<$<NOT:$<CONFIG:Release>>:${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`.

2
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"

1
VERSION

@ -0,0 +1 @@
1.5.0-dev

6
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
```
<details><summary>Linux</summary>
Note that ```pkg-config``` is an optional dependency for finding libsodium, although we have a fallback if necessary.

24
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.

2
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}"

Loading…
Cancel
Save