Move version strings to meson.build

This makes it possible for meson to detect changes to these version numbers, unlike when they were just the default values for options that build sites would retain and fall out of sync.
This commit is contained in:
Tamás Bálint Misius 2025-01-31 17:18:29 +01:00
parent 56ede6caad
commit 97d443531e
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
4 changed files with 50 additions and 70 deletions

40
.github/build.sh vendored
View File

@ -300,19 +300,14 @@ if [[ $stable_or_beta == yes ]]; then
xyz=$(echo $RELEASE_NAME | cut -d 'v' -f 2 | cut -d 'b' -f 1) # $RELEASE_NAME is vX.Y.Z or vX.Y.Zb
display_version_major=$(echo $xyz | cut -d '.' -f 1)
display_version_minor=$(echo $xyz | cut -d '.' -f 2)
build_num=$(echo $xyz | cut -d '.' -f 3)
build_num=$( echo $xyz | cut -d '.' -f 3)
if [[ $MOD_ID != 0 ]]; then
meson_configure+=$'\t'-Ddisplay_version_major=$display_version_major
meson_configure+=$'\t'-Ddisplay_version_minor=$display_version_minor
meson_configure+=$'\t'-Dbuild_num=$build_num
meson_configure+=$'\t'-Doverride_display_version="$display_version_major.$display_version_minor.$build_num"
fi
fi
if [[ $RELEASE_TYPE == snapshot ]]; then
build_num=$(echo $RELEASE_NAME | cut -d '-' -f 2) # $RELEASE_NAME is snapshot-X
meson_configure+=$'\t'-Dsnapshot=true
if [[ $MOD_ID != 0 ]]; then
meson_configure+=$'\t'-Dbuild_num=$build_num
fi
fi
if [[ $RELEASE_TYPE == snapshot ]] && [[ $MOD_ID != 0 ]]; then
>&2 echo "mods and snapshots do not mix"
@ -419,31 +414,34 @@ meson_configure+=$'\t'-Dc_args=[$c_args]
meson_configure+=$'\t'-Dcpp_args=[$c_args]
meson_configure+=$'\t'-Dc_link_args=[$c_link_args]
meson_configure+=$'\t'-Dcpp_link_args=[$c_link_args]
$meson_configure build
cd build
meson_xyz=$(grep meson.build -we "project(" | cut -d "'" -f 6)
if echo $meson_xyz | grep upstream; then
meson_xyz=$(echo $meson_xyz | cut -d '-' -f 3)
fi
actual_display_version_major=$(echo $meson_xyz | cut -d '.' -f 1)
actual_display_version_minor=$(echo $meson_xyz | cut -d '.' -f 2)
actual_build_num=$( echo $meson_xyz | cut -d '.' -f 3)
function verify_version_component() {
local key=$1
local expected=$2
local actual=$(jq -r '.[] | select(.name == "'$key'") | .value' < meson-info/intro-buildoptions.json)
if [[ $actual != $expected ]]; then
declare -n expected_ptr="$1"
declare -n actual_ptr="actual_$1"
if [[ "$actual_ptr" != "$expected_ptr" ]]; then
>&2 echo "meson option $key expected to be $expected, is instead $actual"
exit 1
fi
}
if [[ $stable_or_beta == yes ]] && [[ $MOD_ID == 0 ]]; then
verify_version_component display_version_major $display_version_major
verify_version_component display_version_minor $display_version_minor
verify_version_component build_num $build_num
verify_version_component upstream_version_major $display_version_major
verify_version_component upstream_version_minor $display_version_minor
verify_version_component upstream_build_num $build_num
verify_version_component display_version_major
verify_version_component display_version_minor
verify_version_component build_num
fi
if [[ $RELEASE_TYPE == snapshot ]] && [[ $MOD_ID == 0 ]]; then
verify_version_component build_num $build_num
verify_version_component upstream_build_num $build_num
verify_version_component build_num
fi
$meson_configure build
cd build
strip=strip
objcopy=objcopy
strip_target=$ASSET_PATH

View File

@ -1,4 +1,8 @@
project('the-powder-toy', 'cpp', version: 'the.cake.is.a.lie', meson_version: '>=0.64.0')
project('the-powder-toy', 'cpp', version: '99.3.386', meson_version: '>=0.64.0')
# if you are a mod developer and don't mind dealing with merge conflicts,
# you can replace 'the-powder-toy' with your mod's simplified name, and version: 'X.Y.Z' with version: 'A.B.C-upstream-X.Y.Z'
# where A.B.C is your mod's version (you can change this to anything) and X.Y.Z is the upstream version (merge this from upstream)
# this is purely cosmetic though: it only affects what meson prints when setting up build sites
if get_option('prepare')
# we're being run by prepare.py in a ghactions workflow only to determine the values of options; exit early
@ -115,6 +119,7 @@ else
static: bzip2_static,
),
include_directories: bzip2_include_dir,
version: '1.0.8-elusive',
))
endif
endif

View File

@ -48,48 +48,6 @@ option(
value: false,
description: 'Snapshot build'
)
option(
'display_version_major',
type: 'integer',
min: 0,
value: 99,
description: 'Major component of the display version, should more or less map to the MINOR version in semantic versioning'
)
option(
'display_version_minor',
type: 'integer',
min: 0,
value: 3,
description: 'Minor component of the display version, should more or less map to the PATCH version in semantic versioning'
)
option(
'build_num',
type: 'integer',
min: 0,
value: 386,
description: 'Build number, should be strictly monotonously increasing across public releases'
)
option(
'upstream_version_major',
type: 'integer',
min: 0,
value: 99,
description: 'Major component of the upstream display version, mod owners should not change this but merge upstream changes to it'
)
option(
'upstream_version_minor',
type: 'integer',
min: 0,
value: 3,
description: 'Minor component of the upstream display version, mod owners should not change this but merge upstream changes to it'
)
option(
'upstream_build_num',
type: 'integer',
min: 0,
value: 386,
description: 'Upstream build number, mod owners should not change this but merge upstream changes to it'
)
option(
'mod_id',
type: 'integer',
@ -267,6 +225,12 @@ option(
value: false,
description: 'Used by ghactions workflows, not useful otherwise'
)
option(
'override_display_version',
type: 'string',
value: '',
description: 'Used by ghactions workflows, not useful otherwise'
)
option(
'render_icons_with_inkscape',
type: 'feature',

View File

@ -1,5 +1,18 @@
conf_data = configuration_data()
upstream_version = meson.project_version()
upstream_version_components = upstream_version.split('-')
if upstream_version_components.length() > 1
upstream_version = upstream_version_components[upstream_version_components.length() - 1]
endif
display_version = upstream_version
override_display_version = get_option('override_display_version')
if override_display_version != ''
display_version = override_display_version
endif
display_version = display_version.split('.')
upstream_version = upstream_version.split('.')
app_id = get_option('app_id')
mod_id = get_option('mod_id')
is_snapshot = get_option('snapshot')
@ -11,12 +24,12 @@ conf_data.set('MOD_ID', mod_id)
conf_data.set('DEBUG', is_debug.to_string())
conf_data.set('MOD', is_mod.to_string())
conf_data.set('SNAPSHOT', is_snapshot.to_string())
conf_data.set('DISPLAY_VERSION_MAJOR', get_option('display_version_major'))
conf_data.set('DISPLAY_VERSION_MINOR', get_option('display_version_minor'))
conf_data.set('BUILD_NUM', get_option('build_num'))
conf_data.set('UPSTREAM_VERSION_MAJOR', get_option('upstream_version_major'))
conf_data.set('UPSTREAM_VERSION_MINOR', get_option('upstream_version_minor'))
conf_data.set('UPSTREAM_BUILD_NUM', get_option('upstream_build_num'))
conf_data.set('DISPLAY_VERSION_MAJOR', display_version[0].to_int())
conf_data.set('DISPLAY_VERSION_MINOR', display_version[1].to_int())
conf_data.set('BUILD_NUM', display_version[2].to_int())
conf_data.set('UPSTREAM_VERSION_MAJOR', upstream_version[0].to_int())
conf_data.set('UPSTREAM_VERSION_MINOR', upstream_version[1].to_int())
conf_data.set('UPSTREAM_BUILD_NUM', upstream_version[2].to_int())
conf_data.set('MANIFEST_COPYRIGHT', get_option('manifest_copyright'))
conf_data.set('MANIFEST_MACOS_MIN_VER', get_option('manifest_macos_min_ver'))
conf_data.set('MANIFEST_DATE', get_option('manifest_date'))