diff --git a/core/build.sh b/core/build.sh index b97ce73515..291bb750b8 100755 --- a/core/build.sh +++ b/core/build.sh @@ -115,12 +115,10 @@ builder_describe_outputs \ build:arch /core/build/arch/$BUILDER_CONFIGURATION/src/libkeymancore.a \ build:wasm /core/build/wasm/$BUILDER_CONFIGURATION/src/libkeymancore.a -# Import our standard compiler defines; this is copied from -# /resources/build/meson/standard.meson.build by build.sh, because meson doesn't -# allow us to reference a file outside its root if builder_has_action configure; then - mkdir -p "$THIS_SCRIPT_PATH/resources" - cp "$KEYMAN_ROOT/resources/build/meson/standard.meson.build" "$THIS_SCRIPT_PATH/resources/meson.build" + # Import our standard compiler defines + source "$KEYMAN_ROOT/resources/build/meson/standard_meson_build.inc.sh" + standard_meson_build fi # Iterate through all possible targets; note that targets that cannot be built diff --git a/core/getversion.bat b/core/getversion.bat deleted file mode 100644 index 69cf57c27b..0000000000 --- a/core/getversion.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -REM Get the version number from VERSION.md -more ..\VERSION.md diff --git a/core/getversion.sh b/core/getversion.sh deleted file mode 100755 index 4d436285a3..0000000000 --- a/core/getversion.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -# Get the version number from VERSION.md -cat ../VERSION.md diff --git a/core/meson.build b/core/meson.build index 8c6cbfdc61..01e016ad27 100644 --- a/core/meson.build +++ b/core/meson.build @@ -6,7 +6,7 @@ # project('keyman_core', 'cpp', 'c', - version: run_command(find_program('getversion.bat', 'getversion.sh'), check:true).stdout().strip(), + version: files('../VERSION.md'), license: 'MIT', default_options : ['buildtype=release', 'cpp_std=c++17', diff --git a/developer/src/kmcmplib/build.sh b/developer/src/kmcmplib/build.sh index aaf7184676..77036cc990 100755 --- a/developer/src/kmcmplib/build.sh +++ b/developer/src/kmcmplib/build.sh @@ -92,12 +92,10 @@ fi do_action clean # Note, we have a 'global' configure and also a per-arch configure -if builder_start_action configure; then - # Import our standard compiler defines; this is copied from - # /resources/build/meson/standard.meson.build by build.sh, because meson doesn't - # allow us to reference a file outside its root - mkdir -p "$THIS_SCRIPT_PATH/resources" - cp "$KEYMAN_ROOT/resources/build/meson/standard.meson.build" "$THIS_SCRIPT_PATH/resources/meson.build" +if builder_has_action configure; then + # Import our standard compiler defines + source "$KEYMAN_ROOT/resources/build/meson/standard_meson_build.inc.sh" + standard_meson_build # We have to checkout the keyboards repo in a 'configure' action because # otherwise meson will not get the right list of keyboard source files, @@ -105,8 +103,6 @@ if builder_start_action configure; then if should_do_full_test; then checkout_keyboards fi - - builder_finish_action success configure fi do_action configure diff --git a/developer/src/kmcmplib/getversion.bat b/developer/src/kmcmplib/getversion.bat deleted file mode 100644 index dcab02e4d9..0000000000 --- a/developer/src/kmcmplib/getversion.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -REM Get the version number from VERSION.md -more ..\..\..\VERSION.md diff --git a/developer/src/kmcmplib/getversion.sh b/developer/src/kmcmplib/getversion.sh deleted file mode 100755 index cd02c07929..0000000000 --- a/developer/src/kmcmplib/getversion.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# Get the version number from VERSION.md -VERSIONFILE=../../../VERSION.md -cat $VERSIONFILE diff --git a/developer/src/kmcmplib/meson.build b/developer/src/kmcmplib/meson.build index d494e884d9..0493c504f4 100644 --- a/developer/src/kmcmplib/meson.build +++ b/developer/src/kmcmplib/meson.build @@ -5,7 +5,7 @@ # project('kmcmplib', 'cpp', 'c', - version: run_command(find_program('getversion.bat', 'getversion.sh'), check: true).stdout().strip(), + version: files('../../../VERSION.md'), license: 'MIT', default_options : ['buildtype=release', 'cpp_std=c++14', diff --git a/linux/ibus-keyman/build.sh b/linux/ibus-keyman/build.sh index 231e9039ea..d21c52c2ae 100755 --- a/linux/ibus-keyman/build.sh +++ b/linux/ibus-keyman/build.sh @@ -45,13 +45,10 @@ else MESON_COVERAGE= fi -# Import our standard compiler defines; this is copied from -# /resources/build/meson/standard.meson.build by build.sh, because meson doesn't -# allow us to reference a file outside its root. ${THIS_SCRIPT_PATH}/meson.build -# then includes `resources` as a subdir. if builder_has_action configure; then - mkdir -p "${THIS_SCRIPT_PATH}/resources" - cp "${KEYMAN_ROOT}/resources/build/meson/standard.meson.build" "${THIS_SCRIPT_PATH}/resources/meson.build" + # Import our standard compiler defines + source "$KEYMAN_ROOT/resources/build/meson/standard_meson_build.inc.sh" + standard_meson_build fi configure_action() { diff --git a/linux/ibus-keyman/meson.build b/linux/ibus-keyman/meson.build index e94c90285b..401da66004 100644 --- a/linux/ibus-keyman/meson.build +++ b/linux/ibus-keyman/meson.build @@ -1,5 +1,5 @@ project('ibus-keyman', 'c', 'cpp', - version: run_command('cat', '../../VERSION.md', check: true).stdout().strip(), + version: files('../../VERSION.md'), license: 'GPL-2+', meson_version: '>=1.0') diff --git a/linux/keyman-system-service/build.sh b/linux/keyman-system-service/build.sh index c9507726f4..cb66486f01 100755 --- a/linux/keyman-system-service/build.sh +++ b/linux/keyman-system-service/build.sh @@ -23,12 +23,12 @@ builder_describe \ builder_parse "$@" -# Import our standard compiler defines; this is copied from -# /resources/build/meson/standard.meson.build by build.sh, because meson doesn't -# allow us to reference a file outside its root. ${THIS_SCRIPT_PATH}/meson.build -# then includes `resources` as a subdir. if builder_has_action configure; then - cp "${KEYMAN_ROOT}/resources/build/meson/standard.meson.build" "${THIS_SCRIPT_PATH}/resources/meson.build" + # Import our standard compiler defines + source "$KEYMAN_ROOT/resources/build/meson/standard_meson_build.inc.sh" + standard_meson_build + + # TODO: it would be cleaner to split this from the standard.meson.build file/folder cat "${THIS_SCRIPT_PATH}/resources/meson.build.in" >> "${THIS_SCRIPT_PATH}/resources/meson.build" fi diff --git a/linux/keyman-system-service/meson.build b/linux/keyman-system-service/meson.build index c8ff6994aa..410ec80036 100644 --- a/linux/keyman-system-service/meson.build +++ b/linux/keyman-system-service/meson.build @@ -1,5 +1,5 @@ project('keyman-system-service', 'c', 'cpp', - version: run_command('cat', '../../VERSION.md', check: true).stdout().strip(), + version: files('../../VERSION.md'), license: 'GPL-2+', meson_version: '>=1.0') diff --git a/linux/mcompile/keymap/meson.build b/linux/mcompile/keymap/meson.build index c2ac9acc76..b6d489902c 100644 --- a/linux/mcompile/keymap/meson.build +++ b/linux/mcompile/keymap/meson.build @@ -1,5 +1,6 @@ project( 'mcompile', 'c', 'cpp', + version: files('../../../VERSION.md'), license: 'MIT', meson_version: '>=1.0', ) diff --git a/mac/mcompile/meson.build b/mac/mcompile/meson.build index 6a359f9f5c..0918028e45 100644 --- a/mac/mcompile/meson.build +++ b/mac/mcompile/meson.build @@ -1,4 +1,5 @@ project('mcompile', 'c', 'cpp', + version: files('../../VERSION.md'), license: 'MIT', meson_version: '>=1.0') diff --git a/resources/build/meson-utils.inc.sh b/resources/build/meson-utils.inc.sh index 24375a840a..271e017ea7 100644 --- a/resources/build/meson-utils.inc.sh +++ b/resources/build/meson-utils.inc.sh @@ -2,6 +2,7 @@ # This script contains common meson functions +source "$KEYMAN_ROOT/resources/build/meson/standard_meson_build.inc.sh" # ---------------------------------------------------------------------------- # clean @@ -17,11 +18,8 @@ do_meson_clean() { # ---------------------------------------------------------------------------- do_meson_configure() { - # Import our standard compiler defines; this is copied from - # /resources/build/meson/standard.meson.build by build.sh, because meson doesn't - # allow us to reference a file outside its root - mkdir -p "$THIS_SCRIPT_PATH/resources" - cp "$KEYMAN_ROOT/resources/build/meson/standard.meson.build" "$THIS_SCRIPT_PATH/resources/meson.build" + # Import our standard compiler defines + standard_meson_build pushd "$THIS_SCRIPT_PATH" > /dev/null # Additional arguments are used by Linux build, e.g. -Dprefix=${INSTALLDIR} diff --git a/resources/build/meson/standard.meson.build b/resources/build/meson/standard.meson.build index a08eb7a6ad..0bf48f9e9c 100644 --- a/resources/build/meson/standard.meson.build +++ b/resources/build/meson/standard.meson.build @@ -4,6 +4,11 @@ # This file has the master location /resources/build/meson/standard.meson.build, # and is copied into each project's /resources/meson.build in the # configure step, so that it can be referenced by meson directly. +# +# Use standard_meson_build.inc.sh to make the file copy +# + + # # Where possible, we want to use these flags everywhere # @@ -26,6 +31,17 @@ message('meson.project_version(): ' + meson.project_version()) message('host_machine.system(): ' + host_machine.system()) message('compiler.get_id(): ' + cpp_compiler.get_id()) +# +# Import `VERSION_WITH_TAG` which we can use where appropriate instead of +# meson.project_version() which is only major.minor.patch. +# + +fs = import('fs') +if fs.exists('VERSION_WITH_TAG.md') + VERSION_WITH_TAG = fs.read('VERSION_WITH_TAG.md').strip() + message('VERSION_WITH_TAG: ' + VERSION_WITH_TAG) +endif + # # Standard compiler flags for all platforms # diff --git a/resources/build/meson/standard_meson_build.inc.sh b/resources/build/meson/standard_meson_build.inc.sh new file mode 100644 index 0000000000..39fd49de05 --- /dev/null +++ b/resources/build/meson/standard_meson_build.inc.sh @@ -0,0 +1,35 @@ +# +# Keyman is copyright (C) SIL Global. MIT License. +# +# Created by mcdurdin on 2025-04-30 +# +# This import script helps us setup a consistent meson environment across all +# our build scripts. It will generate two files in the calling scripts +# resources/ folder (which should be git-ignored): +# +# * resources/meson.build - a copy of standard.meson.build from this folder +# * resources/VERSION_WITH_TAG.md - the value of the env var $VERSION_WITH_TAG +# +# We do this because meson doesn't allow us to: +# +# * reference a file outside the project root, or +# * read environment variables +# +# Sample of normal usage: +# +# if builder_has_action configure; then +# # Import our standard compiler defines +# source "$KEYMAN_ROOT/resources/build/meson/standard_meson_build.inc.sh" +# standard_meson_build +# fi +# +# ${THIS_SCRIPT_PATH}/meson.build then includes `resources` as a subdir: +# +# subdir('resources') +# + +standard_meson_build() { + mkdir -p "$THIS_SCRIPT_PATH/resources" + cp "$KEYMAN_ROOT/resources/build/meson/standard.meson.build" "$THIS_SCRIPT_PATH/resources/meson.build" + echo "$VERSION_WITH_TAG" > "$THIS_SCRIPT_PATH/resources/VERSION_WITH_TAG.md" +}