From 970257913070d8fe796067f6f457b80b65628e81 Mon Sep 17 00:00:00 2001 From: mcarans Date: Wed, 24 Jun 2026 14:02:51 +1200 Subject: [PATCH 01/23] Add mk.sh script --- ShellScripts/common/post_build.sh | 29 ++-- mk.sh | 213 ++++++++++++++++++++++++++++++ src/meson.build | 4 +- 3 files changed, 232 insertions(+), 14 deletions(-) create mode 100755 mk.sh diff --git a/ShellScripts/common/post_build.sh b/ShellScripts/common/post_build.sh index eed95d57d..fa9bd1c9c 100755 --- a/ShellScripts/common/post_build.sh +++ b/ShellScripts/common/post_build.sh @@ -12,9 +12,8 @@ run_script() { local appname=$(basename "$ORIGPROGPATH") local appdir=$(dirname "$ORIGPROGPATH") local progpath="$PROGDIR/$appname" - mkdir -p "$PROGDIR/Resources" - - generate_manifest "$PROGDIR/Resources/manifest.plist" + local resourcesdir="$PROGDIR/Resources" + mkdir -p "$resourcesdir" if [[ ! -f "$ORIGPROGPATH" ]]; then echo "❌ 'Oolite binary at '$ORIGPROGPATH' does not exist!" >&2 @@ -24,14 +23,20 @@ run_script() { echo "❌ Failed to copy '$ORIGPROGPATH' to '$progpath'!" >&2 return 1 fi - cp -fu "$ORIGPROGPATH" "$progpath" - cp -fu src/Cocoa/Info-Oolite.plist "$PROGDIR/Resources/Info-gnustep.plist" + generate_manifest "$resourcesdir/manifest.plist" + cp -fu src/Cocoa/Info-Oolite.plist "$resourcesdir/Info-gnustep.plist" + if [[ "$DEPLOYMENT_RELEASE_CONFIGURATION" == "no" ]]; then + local addonsdir="$PROGDIR/AddOns" + mkdir -p "$addonsdir" + rm -rf "$addonsdir/Basic-debug.oxp" + cp -rf DebugOXP/Debug.oxp "$addonsdir/Basic-debug.oxp" + fi # Voice Data if [[ "$ESPEAK" == "yes" ]]; then if [[ "$HOST_OS" == "windows" ]]; then # Windows espeak-ng-data - cp -rfu "$MINGW_PREFIX/share/espeak-ng-data" "$PROGDIR/Resources" + cp -rfu "$MINGW_PREFIX/share/espeak-ng-data" "$resourcesdir" else # Linux search paths for espeak-ng-data local SEARCH_PATHS=( @@ -44,7 +49,7 @@ run_script() { local path for path in "${SEARCH_PATHS[@]}"; do if [[ -d "$path" ]]; then - cp -rfu "$path" "$PROGDIR/Resources" + cp -rfu "$path" "$resourcesdir" found_data=true break fi @@ -59,10 +64,10 @@ run_script() { fi # Replace specific voices with Oolite-specific versions - rm -f "$PROGDIR/Resources/espeak-ng-data/voices/!v/f2" - rm -f "$PROGDIR/Resources/espeak-ng-data/voices/default" - cp -rfu Resources/. "$PROGDIR/Resources" - rm -f "$PROGDIR/Resources/AIReference.html" "$PROGDIR/Resources/*.icns" + rm -f "$resourcesdir/espeak-ng-data/voices/!v/f2" + rm -f "$resourcesdir/espeak-ng-data/voices/default" + cp -rfu Resources/. "$resourcesdir" + rm -f "$resourcesdir/AIReference.html" "$resourcesdir/*.icns" # Strip binary if requested if [[ "$STRIP_BIN" == "yes" ]]; then @@ -97,7 +102,7 @@ run_script() { if [ ! -f "$gnustep_conf" ] && [ "$GNUSTEP_FOLDER" = "/usr" ] && [ -f "/etc/GNUstep/GNUstep.conf" ]; then gnustep_conf="/etc/GNUstep/GNUstep.conf" fi - install -D "$gnustep_conf" "$PROGDIR/Resources/GNUstep.conf.orig" || { echo "$err_msg GNUstep config" >&2; return 1; } + install -D "$gnustep_conf" "$resourcesdir/GNUstep.conf.orig" || { echo "$err_msg GNUstep config" >&2; return 1; } # If we're using GNUstep libraries that aren't in a system folder copy them ldd "$progpath" | \ diff --git a/mk.sh b/mk.sh new file mode 100755 index 000000000..1bf550fc4 --- /dev/null +++ b/mk.sh @@ -0,0 +1,213 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) +pushd "$SCRIPT_DIR" > /dev/null + +# Strict expansions, but NO 'set -e' +set -u -o pipefail + +# --- Error Handling Trap --- +cleanup_and_exit() { + local exit_code=$? + + # If the exit code is 0 (success) but this function was triggered, + # force it to 1 to indicate an error. + if [[ $exit_code -eq 0 ]]; then + exit_code=1 + fi + + echo "❌ Oolite build failed on line $1 with exit code $exit_code!" >&2 + + # Always pop the directory stack before exiting + popd > /dev/null 2>&1 || true + + # Exit only if not sourced + if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + exit "$exit_code" + fi +} + +# Trap any command errors (ERR) passing ${LINENO} to know exactly where it failed. +trap 'cleanup_and_exit ${LINENO}' ERR + +# --- Environment Variables & Defaults --- +NATIVE_FILE="${NATIVE_FILE:-clang.ini}" +BUILDER="${BUILDER:-unknown}" +GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-}" + +# --- Feature Flags & Options --- +CLEAN_BUILD=false +SETUP_FLAGS=() # Array to cleanly store additional meson setup arguments + +# --- Helper Functions --- +# Replicates $(call meson_build,flags,suffix) +meson_build() { + local build_dir="build/meson_$2" + # If --clean was specified, delete the specific build directory first + if [[ "$CLEAN_BUILD" == true ]]; then + echo "--> Cleaning target build directory: ${build_dir}" + rm -rf "$build_dir" + fi + echo "--> Running Meson build for: $2" + # Setup with --reconfigure, fallback to fresh setup. SETUP_FLAGS safely expands the array only if it's not empty + meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dgithub_repository="${GITHUB_REPOSITORY}" --native-file "${NATIVE_FILE}" --reconfigure 2>/dev/null || \ + meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dgithub_repository="${GITHUB_REPOSITORY}" --native-file "${NATIVE_FILE}" + meson compile -C "$build_dir" +} + +meson_install() { + echo "--> Running Meson install for: $1" + meson install -C "build/meson_$1" +} + +# --- Script Help Menu --- +show_help() { + echo "Usage: $0 [options] " + echo "" + echo "Options:" + echo -e " \033[36m--clean\033[0m Delete target build directory before compiling" + echo -e " \033[36m--setup-flags=\"...\"\033[0m Pass additional arguments directly to 'meson setup'" + echo "" + echo "Targets:" + echo -e " \033[36mrelease\033[0m Build a test release executable" + echo -e " \033[36mrelease-deployment\033[0m Build a release deployment executable" + echo -e " \033[36mrelease-snapshot\033[0m Build a snapshot release executable" + echo -e " \033[36mdebug\033[0m Build a debug executable" + echo -e " \033[36minstall\033[0m Install the test release build" + echo -e " \033[36minstall-deployment\033[0m Install the release deployment build" + echo -e " \033[36minstall-snapshot\033[0m Install the snapshot release build" + echo -e " \033[36mtest\033[0m Run test suite (depends on release-snapshot)" + echo -e " \033[36mclean\033[0m Remove all generated build artifacts" + echo -e " \033[36mpkg-flatpak\033[0m Package a Flatpak application" + echo -e " \033[36mpkg-appimage\033[0m Package a test release AppImage" + echo -e " \033[36mpkg-appimage-deployment\033[0m Package a deployment AppImage" + echo -e " \033[36mpkg-appimage-snapshot\033[0m Package a snapshot AppImage" + echo -e " \033[36mpkg-win\033[0m Package a Windows NSIS test release installer" + echo -e " \033[36mpkg-win-deployment\033[0m Package a Windows NSIS deployment installer" + echo -e " \033[36mpkg-win-snapshot\033[0m Package a Windows NSIS snapshot installer" +} + +# --- Target Execution Logic --- +execute_target() { + case "$1" in + release) + meson_build "-Ddebug=false -Dstrip_bin=true -Db_lto=true" "release" + ;; + release-deployment) + meson_build "-Ddeployment_release_configuration=true -Ddebug=false -Dstrip_bin=true -Db_lto=true" "deployment" + ;; + release-snapshot) + meson_build "-Dsnapshot_build=true -Ddebug=false -Dstrip_bin=false" "snapshot" + ;; + debug) + meson_build "-Ddebug=true -Dstrip_bin=false" "debug" + ;; + install) + meson_install "release" + ;; + install-deployment) + meson_install "deployment" + ;; + install-snapshot) + meson_install "snapshot" + ;; + test) + execute_target "release-snapshot" + tests/run_test.sh + ;; + clean) + echo "--> Cleaning all build artifacts..." + rm -rf build/meson_* + ;; + pkg-flatpak) + ./installers/flatpak/create_flatpak.sh + ;; + pkg-appimage) + execute_target "release" + installers/appimage/create_appimage.sh meson_release/oolite.app "test" + ;; + pkg-appimage-deployment) + execute_target "release-deployment" + installers/appimage/create_appimage.sh meson_deployment/oolite.app + ;; + pkg-appimage-snapshot) + execute_target "release-snapshot" + installers/appimage/create_appimage.sh meson_snapshot/oolite.app "dev" + ;; + pkg-win) + execute_target "release" + installers/win32/create_nsis.sh meson_release/oolite.app "test" + ;; + pkg-win-deployment) + execute_target "release-deployment" + installers/win32/create_nsis.sh meson_deployment/oolite.app + ;; + pkg-win-snapshot) + execute_target "release-snapshot" + installers/win32/create_nsis.sh meson_snapshot/oolite.app "dev" + ;; + help|--help|-h) + show_help + ;; + *) + echo "Error: Unknown target '$1'" >&2 + show_help + exit 1 + ;; + esac +} + +# --- Flexible Argument Parser --- +TARGET="" + +while [[ $# -gt 0 ]]; do + case "$1" in + --clean) + CLEAN_BUILD=true + shift + ;; + --setup-flags=*) + # Handle inline assignment format (e.g., --setup-flags="-Dfoo=bar") + read -r -a flags_array <<< "${1#*=}" + SETUP_FLAGS+=("${flags_array[@]}") + shift + ;; + help|--help|-h) + show_help + exit 0 + ;; + -*) + echo "Error: Unknown option '$1'" >&2 + show_help + exit 1 + ;; + *) + if [[ -n "$TARGET" ]]; then + echo "Error: Multiple targets specified ('$TARGET' and '$1'). Only one target allowed." >&2 + exit 1 + fi + TARGET="$1" + shift + ;; + esac +done + +# Fallback to help menu if no target was provided +if [[ -z "$TARGET" ]]; then + show_help + exit 1 +fi + +execute_target "$TARGET" +# Successful Exit - remove the ERR trap so it doesn't accidentally fire during normal bailing. +trap - ERR +popd > /dev/null + +# Only print build success if it wasn't a help menu or a cleanup action +if [[ "$TARGET" != "help" && "$TARGET" != "--help" && "$TARGET" != "-h" && "$TARGET" != "clean" ]]; then + echo "✅ Oolite target '$TARGET' completed successfully" +fi + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + exit 0 +fi \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 314faa0ed..55f9e304d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -37,7 +37,7 @@ oolite_bin = executable( prog_dir = meson.global_build_root() / appname + '.app' stamp_file = '.oolite_bundle.stamp' -install_env_args = [ +post_build_env_args = [ 'ORIGPROGPATH=' + meson.current_build_dir() / appname, 'PROGDIR=' + prog_dir, 'HOST_OS=' + host_os, @@ -58,7 +58,7 @@ oolite_app_bundle = custom_target('post_build', depend_files: [post_build_script.full_path()], command: [ 'env', - install_env_args, + post_build_env_args, post_build_script.full_path(), ], build_by_default: true, From 63b9cbf92fd9f0406aed2996bc9f6eaafb427602 Mon Sep 17 00:00:00 2001 From: mcarans Date: Wed, 24 Jun 2026 15:05:12 +1200 Subject: [PATCH 02/23] Call as functions from mk.sh Remove Makefile --- .github/workflows/build-all.yaml | 6 +- .github/workflows/test_builds.yaml | 22 ++--- Makefile | 97 ------------------- ShellScripts/Linux/install_package_fn.sh | 2 +- ShellScripts/Windows/install_deps.sh | 1 - ShellScripts/common/build_oolite.sh | 35 ------- ...eate_appimage.sh => create_appimage_fn.sh} | 14 +-- ...create_flatpak.sh => create_flatpak_fn.sh} | 14 +-- installers/flatpak/flatpak_build.sh | 2 +- .../{create_nsis.sh => create_nsis_fn.sh} | 15 +-- mk.sh | 18 ++-- tests/{run_test.sh => run_test_fn.sh} | 11 +-- 12 files changed, 29 insertions(+), 208 deletions(-) delete mode 100755 Makefile delete mode 100755 ShellScripts/common/build_oolite.sh rename installers/appimage/{create_appimage.sh => create_appimage_fn.sh} (95%) rename installers/flatpak/{create_flatpak.sh => create_flatpak_fn.sh} (96%) rename installers/win32/{create_nsis.sh => create_nsis_fn.sh} (95%) rename tests/{run_test.sh => run_test_fn.sh} (92%) diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index aee2e9f3d..ffdf8e0fd 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -52,7 +52,7 @@ jobs: ldconfig - name: Build Oolite run: | - ShellScripts/common/build_oolite.sh ${{matrix.flavour}} + ./mk.sh ${{matrix.flavour}} - name: Archive installer uses: actions/upload-artifact@v6 with: @@ -78,7 +78,7 @@ jobs: fetch-depth: 0 - name: Build flatpak run: | - installers/flatpak/create_flatpak.sh + ./mk.sh pkg-flatpak - name: Archive installer uses: actions/upload-artifact@v6 with: @@ -122,7 +122,7 @@ jobs: env: msystem: UCRT64 run: | - ShellScripts/common/build_oolite.sh ${{matrix.flavour}} + ./mk.sh ${{matrix.flavour}} - name: Archive installer uses: actions/upload-artifact@v6 with: diff --git a/.github/workflows/test_builds.yaml b/.github/workflows/test_builds.yaml index ebf28ae4c..fcc032fd1 100644 --- a/.github/workflows/test_builds.yaml +++ b/.github/workflows/test_builds.yaml @@ -44,14 +44,14 @@ jobs: - name: Build and test Oolite if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ShellScripts/common/build_oolite.sh test + ./mk.sh test - name: Build Oolite (no test) if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name run: | - ShellScripts/common/build_oolite.sh + ./mk.sh release-snapshot - name: Build AppImage run: | - ShellScripts/common/build_oolite.sh pkg-appimage-snapshot + ./mk.sh pkg-appimage-snapshot fedora: runs-on: ubuntu-latest @@ -88,14 +88,14 @@ jobs: - name: Build and test Oolite if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ShellScripts/common/build_oolite.sh test + ./mk.sh test - name: Build Oolite (no test) if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name run: | - ShellScripts/common/build_oolite.sh + ./mk.sh release-snapshot - name: Build AppImage run: | - ShellScripts/common/build_oolite.sh pkg-appimage-snapshot + ./mk.sh pkg-appimage-snapshot arch: runs-on: ubuntu-latest @@ -132,14 +132,14 @@ jobs: - name: Build and test Oolite if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ShellScripts/common/build_oolite.sh test + ./mk.sh test - name: Build Oolite (no test) if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name run: | - ShellScripts/common/build_oolite.sh + ./mk.sh release-snapshot - name: Build AppImage run: | - ShellScripts/common/build_oolite.sh pkg-appimage-snapshot + ./mk.sh pkg-appimage-snapshot windows: runs-on: windows-latest @@ -174,7 +174,7 @@ jobs: env: msystem: UCRT64 run: | - ShellScripts/common/build_oolite.sh test + ./mk.sh test - name: Build Oolite (no test) if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name @@ -182,4 +182,4 @@ jobs: env: msystem: UCRT64 run: | - ShellScripts/common/build_oolite.sh + ./mk.sh release-snapshot diff --git a/Makefile b/Makefile deleted file mode 100755 index 6a25ab871..000000000 --- a/Makefile +++ /dev/null @@ -1,97 +0,0 @@ -# Use bash as the explicit shell and enable strict error handling for safety -SHELL := /bin/bash -.SHELLFLAGS := -eu -o pipefail -c - -NATIVE_FILE ?= clang.ini -BUILDER ?= unknown - -# Modern, self-documenting help target. -# It parses the '##' comments next to targets automatically. -.PHONY: help -help: ## Show this help message - @echo "Usage: make [target]" - @echo "" - @echo "Targets:" - @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-25s\033[0m %s\n", $$1, $$2}' - -# Macro for Meson workflow -define meson_build - meson setup build/meson_$(2) $(1) -Dgithub_repository=${GITHUB_REPOSITORY} --native-file $(NATIVE_FILE) --reconfigure 2>/dev/null || meson setup build/meson_$(2) $(1) -Dgithub_repository=${GITHUB_REPOSITORY} --native-file $(NATIVE_FILE) - meson compile -C build/meson_$(2) -endef - -# Helper macro for syncing OXP files cleanly -define sync_debug_oxp - mkdir -p build/meson_$(1)/oolite.app/AddOns - rm -rf build/meson_$(1)/oolite.app/AddOns/Basic-debug.oxp - cp -rf DebugOXP/Debug.oxp build/meson_$(1)/oolite.app/AddOns/Basic-debug.oxp -endef - -## -## Development Targets -## - -.PHONY: release -release: ## Build a test release executable - $(call meson_build,-Ddebug=false -Dstrip_bin=true -Db_lto=true,release) - $(call sync_debug_oxp,release) - -.PHONY: release-deployment -release-deployment: ## Build a release deployment executable - $(call meson_build,-Ddeployment_release_configuration=true -Ddebug=false -Dstrip_bin=true -Db_lto=true,deployment) - -.PHONY: release-snapshot -release-snapshot: ## Build a snapshot release executable - $(call meson_build,-Dsnapshot_build=true -Ddebug=false -Dstrip_bin=false,snapshot) - $(call sync_debug_oxp,snapshot) - -.PHONY: debug -debug: ## Build a debug executable - $(call meson_build,-Ddebug=true -Dstrip_bin=false,debug) - $(call sync_debug_oxp,debug) - -.PHONY: test -test: release-snapshot ## Run test suite - tests/run_test.sh - -.PHONY: clean -clean: ## Remove all generated build artifacts - rm -rf build/meson_* - -.PHONY: all -all: release release-deployment release-snapshot debug ## Build all standard development targets - -.PHONY: remake -remake: clean all - -## -## Packaging Targets -## - -.PHONY: pkg-flatpak -pkg-flatpak: ## Package a Flatpak application - ./installers/flatpak/create_flatpak.sh - -.PHONY: pkg-appimage -pkg-appimage: release ## Package a test release AppImage - installers/appimage/create_appimage.sh meson_release/oolite.app "test" - -.PHONY: pkg-appimage-deployment -pkg-appimage-deployment: release-deployment ## Package a deployment AppImage - installers/appimage/create_appimage.sh meson_deployment/oolite.app - -.PHONY: pkg-appimage-snapshot -pkg-appimage-snapshot: release-snapshot ## Package a snapshot AppImage - installers/appimage/create_appimage.sh meson_snapshot/oolite.app "dev" - -.PHONY: pkg-win -pkg-win: release ## Package a Windows NSIS test release installer - installers/win32/create_nsis.sh meson_release/oolite.app "test" - -.PHONY: pkg-win-deployment -pkg-win-deployment: release-deployment ## Package a Windows NSIS deployment installer - installers/win32/create_nsis.sh meson_deployment/oolite.app - -.PHONY: pkg-win-snapshot -pkg-win-snapshot: release-snapshot ## Package a Windows NSIS snapshot installer - installers/win32/create_nsis.sh meson_snapshot/oolite.app "dev" diff --git a/ShellScripts/Linux/install_package_fn.sh b/ShellScripts/Linux/install_package_fn.sh index affdaa29e..476ad8a43 100644 --- a/ShellScripts/Linux/install_package_fn.sh +++ b/ShellScripts/Linux/install_package_fn.sh @@ -15,7 +15,7 @@ install_package() { "base-devel") case "$CURRENT_DISTRO" in debian) pkg_name="build-essential" ;; - redhat) pkg_name="gcc gcc-c++ make" ;; + redhat) pkg_name="gcc gcc-c++" ;; arch) pkg_name="base-devel" ;; esac ;; diff --git a/ShellScripts/Windows/install_deps.sh b/ShellScripts/Windows/install_deps.sh index ce6669d84..e0424de02 100755 --- a/ShellScripts/Windows/install_deps.sh +++ b/ShellScripts/Windows/install_deps.sh @@ -47,7 +47,6 @@ run_script() { pacboy -S jq --noconfirm pacman -S unzip --noconfirm pacboy -S python-pip --noconfirm - pacman -S make --noconfirm pacboy -S meson --noconfirm pacboy -S ninja --noconfirm pacboy -S nsis --noconfirm diff --git a/ShellScripts/common/build_oolite.sh b/ShellScripts/common/build_oolite.sh deleted file mode 100755 index b68fc19bc..000000000 --- a/ShellScripts/common/build_oolite.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# No parameters: build target = release -# One parameter: build target - -run_script() { - local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) - pushd "$script_dir" - - cd ../.. - - local target - if [[ -z "$1" ]]; then - target=release - else - target=$1 - fi - - make clean - if ! make $target; then - echo "❌ Oolite build failed!" >&2 - return 1 - fi - echo "✅ Oolite build completed successfully" - - popd -} - -run_script "$@" -status=$? - - -# Exit only if not sourced -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - exit $status -fi \ No newline at end of file diff --git a/installers/appimage/create_appimage.sh b/installers/appimage/create_appimage_fn.sh similarity index 95% rename from installers/appimage/create_appimage.sh rename to installers/appimage/create_appimage_fn.sh index e81c99d75..6e09dbf8c 100755 --- a/installers/appimage/create_appimage.sh +++ b/installers/appimage/create_appimage_fn.sh @@ -4,9 +4,7 @@ # First parameter can be set to build type, typically one of "test", "dev" or omitted for release builds. # -echo I am $0 $@ - -run_script() { +create_appimage() { # First parameter is a suffix for the build type eg. test, dev local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" @@ -101,13 +99,3 @@ run_script() { popd } - -run_script "$@" -status=$? - - -# Exit only if not sourced -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - exit $status -fi - diff --git a/installers/flatpak/create_flatpak.sh b/installers/flatpak/create_flatpak_fn.sh similarity index 96% rename from installers/flatpak/create_flatpak.sh rename to installers/flatpak/create_flatpak_fn.sh index 0ded5d34b..ad2905f26 100755 --- a/installers/flatpak/create_flatpak.sh +++ b/installers/flatpak/create_flatpak_fn.sh @@ -1,8 +1,6 @@ #!/bin/bash -x -echo "I am $0 $@" - -run_script() { +create_flatpak() { # First parameter is a suffix for the build type eg. test, dev local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" @@ -127,13 +125,3 @@ EOF popd } - -run_script "$@" -status=$? - - -# Exit only if not sourced -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - exit $status -fi - diff --git a/installers/flatpak/flatpak_build.sh b/installers/flatpak/flatpak_build.sh index 503f5d8c1..5ff69cc84 100755 --- a/installers/flatpak/flatpak_build.sh +++ b/installers/flatpak/flatpak_build.sh @@ -11,7 +11,7 @@ source ShellScripts/Linux/install_freedesktop_fn.sh export ADDITIONAL_CFLAGS="-DBUILD_DATE='\"$CPP_DATE\"'" export ADDITIONAL_OBJCFLAGS="-DBUILD_DATE='\"$CPP_DATE\"'" -make release-deployment +./mk.sh release-deployment ABS_OOLITEDIR=$(realpath -m "build/meson_deployment/oolite.app") install_freedesktop $ABS_OOLITEDIR /app lib/debug/bin metainfo diff --git a/installers/win32/create_nsis.sh b/installers/win32/create_nsis_fn.sh similarity index 95% rename from installers/win32/create_nsis.sh rename to installers/win32/create_nsis_fn.sh index d4a74e8be..08190a328 100644 --- a/installers/win32/create_nsis.sh +++ b/installers/win32/create_nsis_fn.sh @@ -7,10 +7,7 @@ # VER_NSIS - the numberical version number (x.x.x.x) that the NSIS installer is built with # -echo I am $0 $@ - - -run_script() { +create_nsis() { # First parameter is a suffix for the build type eg. test, dev local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" @@ -78,13 +75,3 @@ run_script() { fi popd } - -run_script "$@" -status=$? - - -# Exit only if not sourced -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - exit $status -fi - diff --git a/mk.sh b/mk.sh index 1bf550fc4..7c9aca50b 100755 --- a/mk.sh +++ b/mk.sh @@ -4,7 +4,7 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$SCRIPT_DIR" > /dev/null # Strict expansions, but NO 'set -e' -set -u -o pipefail +set -o pipefail # --- Error Handling Trap --- cleanup_and_exit() { @@ -113,38 +113,38 @@ execute_target() { ;; test) execute_target "release-snapshot" - tests/run_test.sh + source tests/run_test_fn.sh && run_test ;; clean) echo "--> Cleaning all build artifacts..." rm -rf build/meson_* ;; pkg-flatpak) - ./installers/flatpak/create_flatpak.sh + source installers/flatpak/create_flatpak_fn.sh && create_flatpak ;; pkg-appimage) execute_target "release" - installers/appimage/create_appimage.sh meson_release/oolite.app "test" + source installers/appimage/create_appimage_fn.sh && create_appimage meson_release/oolite.app "test" ;; pkg-appimage-deployment) execute_target "release-deployment" - installers/appimage/create_appimage.sh meson_deployment/oolite.app + source installers/appimage/create_appimage_fn.sh && create_appimage meson_deployment/oolite.app ;; pkg-appimage-snapshot) execute_target "release-snapshot" - installers/appimage/create_appimage.sh meson_snapshot/oolite.app "dev" + source installers/appimage/create_appimage_fn.sh && create_appimage meson_snapshot/oolite.app "dev" ;; pkg-win) execute_target "release" - installers/win32/create_nsis.sh meson_release/oolite.app "test" + source installers/win32/create_nsis_fn.sh && create_nsis meson_release/oolite.app "test" ;; pkg-win-deployment) execute_target "release-deployment" - installers/win32/create_nsis.sh meson_deployment/oolite.app + source installers/win32/create_nsis_fn.sh && create_nsis meson_deployment/oolite.app ;; pkg-win-snapshot) execute_target "release-snapshot" - installers/win32/create_nsis.sh meson_snapshot/oolite.app "dev" + source installers/win32/create_nsis_fn.sh && create_nsis meson_snapshot/oolite.app "dev" ;; help|--help|-h) show_help diff --git a/tests/run_test.sh b/tests/run_test_fn.sh similarity index 92% rename from tests/run_test.sh rename to tests/run_test_fn.sh index f345ab359..1da802206 100755 --- a/tests/run_test.sh +++ b/tests/run_test_fn.sh @@ -9,7 +9,7 @@ output_log() { fi } -run_script() { +run_test() { if python3 --version >/dev/null 2>&1; then local PYTHON_CMD="python3" elif python --version >/dev/null 2>&1; then @@ -50,12 +50,3 @@ run_script() { echo "✅ Oolite test completed successfully" popd } - -run_script "$@" -status=$? - -# Exit only if not sourced -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - exit $status -fi - From da65cea549d9676339dbf208c89ef8c3136296e0 Mon Sep 17 00:00:00 2001 From: mcarans Date: Sat, 27 Jun 2026 10:14:47 +1200 Subject: [PATCH 03/23] mk.sh orchestrates everything Align builds to end filenames --- .github/workflows/build-all.yaml | 32 +-- .github/workflows/test_builds.yaml | 22 +- README.md | 52 ++-- ShellScripts/Linux/install_freedesktop_fn.sh | 47 ++-- ShellScripts/common/generate_manifest_fn.sh | 29 +-- ShellScripts/common/get_build_date_fn.sh | 26 ++ ShellScripts/common/get_version.sh | 58 ----- ShellScripts/common/get_version_fn.sh | 53 ++++ ShellScripts/common/install.sh | 24 +- ShellScripts/common/post_build.sh | 60 +++-- installers/appimage/create_appimage_fn.sh | 20 +- installers/flatpak/create_flatpak_fn.sh | 21 +- installers/flatpak/flatpak_build.sh | 24 -- installers/flatpak/flatpak_postbuild_fn.sh | 24 ++ installers/flatpak/space.oolite.Oolite.yaml | 5 +- installers/win32/OOlite.nsi | 20 +- installers/win32/create_nsis_fn.sh | 53 ++-- meson.build | 28 +- meson.options | 24 +- mk.sh | 259 ++++++++++++------- src/Core/OOLogHeader.m | 2 +- src/Core/Universe.m | 2 +- src/SDL/MyOpenGLView.m | 6 +- src/meson.build | 46 ++-- 24 files changed, 519 insertions(+), 418 deletions(-) create mode 100755 ShellScripts/common/get_build_date_fn.sh delete mode 100755 ShellScripts/common/get_version.sh create mode 100755 ShellScripts/common/get_version_fn.sh delete mode 100755 installers/flatpak/flatpak_build.sh create mode 100755 installers/flatpak/flatpak_postbuild_fn.sh diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index ffdf8e0fd..8ddd479e4 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -19,7 +19,7 @@ jobs: --security-opt apparmor:unconfined strategy: matrix: - flavour: [pkg-appimage-snapshot, pkg-appimage-deployment, pkg-appimage] + flavour: [pkg-appimage-deployment, pkg-appimage-test, pkg-appimage-dev] steps: ## This is for debugging only and helps developing the workflow. # - name: Environment Variables @@ -52,7 +52,7 @@ jobs: ldconfig - name: Build Oolite run: | - ./mk.sh ${{matrix.flavour}} + ./mk.sh ${{matrix.flavour}} --github-repository="$GITHUB_REPOSITORY" - name: Archive installer uses: actions/upload-artifact@v6 with: @@ -78,7 +78,7 @@ jobs: fetch-depth: 0 - name: Build flatpak run: | - ./mk.sh pkg-flatpak + ./mk.sh pkg-flatpak --github-repository="$GITHUB_REPOSITORY" - name: Archive installer uses: actions/upload-artifact@v6 with: @@ -91,7 +91,7 @@ jobs: runs-on: windows-latest strategy: matrix: - flavour: [pkg-win-snapshot, pkg-win-deployment, pkg-win] + flavour: [pkg-win-deployment, pkg-win-test, pkg-win-dev] steps: ## This is for debugging only and helps developing the workflow. # - name: Environment Variables @@ -122,7 +122,7 @@ jobs: env: msystem: UCRT64 run: | - ./mk.sh ${{matrix.flavour}} + ./mk.sh ${{matrix.flavour}} --github-repository="$GITHUB_REPOSITORY" - name: Archive installer uses: actions/upload-artifact@v6 with: @@ -146,7 +146,7 @@ jobs: uses: actions/download-artifact@v7 with: path: artifacts - - name: Calculate version number and set OOLITE_VERSION + - name: Calculate version number and set VER_FULL id: version run: | set -x @@ -166,14 +166,14 @@ jobs: echo "Found AppImage: $APPIMAGE_PATH" # 3. Run with packageinfo and extract the string inside quotes chmod +x "$APPIMAGE_PATH" - VERSION_STR=$("$APPIMAGE_PATH" packageinfo | awk -F'"' '/^[[:space:]]*version =/ {print $2; exit}') - if [[ -z "$VERSION_STR" ]]; then + VER_FULL=$("$APPIMAGE_PATH" packageinfo | awk -F'"' '/^[[:space:]]*version =/ {print $2; exit}') + if [[ -z "$VER_FULL" ]]; then echo "❌ Failed to extract version string from packageinfo output!" >&2 exit 1 fi - echo "Extracted Version: $VERSION_STR" + echo "Extracted Version: $VER_FULL" # 4. Output the extracted version for subsequent steps - echo "OOLITE_VERSION=$VERSION_STR" >> "$GITHUB_OUTPUT" + echo "VER_FULL=$VER_FULL" >> "$GITHUB_OUTPUT" - name: Remove old prereleases if: github.ref == 'refs/heads/master' || endsWith(github.ref, 'maintenance') uses: s00d/delete-older-releases@0.2.1 @@ -190,16 +190,16 @@ jobs: with: repo_token: "${{ secrets.GITHUB_TOKEN }}" # automatic_release_tag: "latest" - automatic_release_tag: "${{ steps.version.outputs.OOLITE_VERSION }}" + automatic_release_tag: "${{ steps.version.outputs.VER_FULL }}" prerelease: true - title: "Oolite ${{ steps.version.outputs.OOLITE_VERSION }}" + title: "Oolite ${{ steps.version.outputs.VER_FULL }}" files: | - artifacts/oolite-windows-pkg-win-snapshot/OoliteInstall-*-dev.exe artifacts/oolite-windows-pkg-win-deployment/OoliteInstall-*.exe - artifacts/oolite-windows-pkg-win/OoliteInstall-*.exe - artifacts/oolite-linux-pkg-appimage-snapshot/*.AppImage + artifacts/oolite-windows-pkg-win-test/OoliteInstall-*.exe + artifacts/oolite-windows-pkg-win-dev/OoliteInstall-*-dev.exe artifacts/oolite-linux-pkg-appimage-deployment/*.AppImage - artifacts/oolite-linux-pkg-appimage/*.AppImage + artifacts/oolite-linux-pkg-appimage-test/*.AppImage + artifacts/oolite-linux-pkg-appimage-dev/*.AppImage artifacts/oolite-flatpak/*.flatpak - name: Remove old workflow runs if: github.ref == 'refs/heads/master' || endsWith(github.ref, 'maintenance') diff --git a/.github/workflows/test_builds.yaml b/.github/workflows/test_builds.yaml index fcc032fd1..294654d68 100644 --- a/.github/workflows/test_builds.yaml +++ b/.github/workflows/test_builds.yaml @@ -44,14 +44,14 @@ jobs: - name: Build and test Oolite if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ./mk.sh test + ./mk.sh test-dev - name: Build Oolite (no test) if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name run: | - ./mk.sh release-snapshot + ./mk.sh build-dev - name: Build AppImage run: | - ./mk.sh pkg-appimage-snapshot + ./mk.sh pkg-appimage-dev fedora: runs-on: ubuntu-latest @@ -88,14 +88,14 @@ jobs: - name: Build and test Oolite if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ./mk.sh test + ./mk.sh test-dev - name: Build Oolite (no test) if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name run: | - ./mk.sh release-snapshot + ./mk.sh build-dev - name: Build AppImage run: | - ./mk.sh pkg-appimage-snapshot + ./mk.sh pkg-appimage-dev arch: runs-on: ubuntu-latest @@ -132,14 +132,14 @@ jobs: - name: Build and test Oolite if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ./mk.sh test + ./mk.sh test-dev - name: Build Oolite (no test) if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name run: | - ./mk.sh release-snapshot + ./mk.sh build-dev - name: Build AppImage run: | - ./mk.sh pkg-appimage-snapshot + ./mk.sh pkg-appimage-dev windows: runs-on: windows-latest @@ -174,7 +174,7 @@ jobs: env: msystem: UCRT64 run: | - ./mk.sh test + ./mk.sh test-dev - name: Build Oolite (no test) if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name @@ -182,4 +182,4 @@ jobs: env: msystem: UCRT64 run: | - ./mk.sh release-snapshot + ./mk.sh build-dev diff --git a/README.md b/README.md index 44a3ba468..b87409bdf 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ where XXX is a version number. Many Linux package managers support Flatpak so yo double click the downloaded file to install it. The AppImage is named `Oolite_XXX-x86_64.AppImage` where XXX is a version number. Download this -file to where you would like it stored, make it executable and run, for example by typing +file to where you would like it stored, ./mk.sh it executable and run, for example by typing ```bash chmod +x Oolite_XXX-x86_64.AppImage @@ -125,7 +125,7 @@ default, but you can supply a further argument to specify an alternative like do Next run this in your Bash or MSYS2 prompt to build Oolite: ```bash -ShellScripts/common/build_oolite.sh release +./mk.sh release-dev ``` The completed build (executable and games files) can be found in the oolite.app directory. @@ -133,45 +133,61 @@ The completed build (executable and games files) can be found in the oolite.app Subsequently, you can clean and build as follows: ```bash -make clean -make release +./mk.sh clean +./mk.sh release-dev ``` -You can run a test from your Bash or MSYS2 prompt as follows: +You can run a test that launches the game and takes a snapshot from your Bash or MSYS2 prompt as follows: ```bash -make test +./mk.sh test ``` -Other targets are release-deployment for a production release and release-snapshot for a debug release. +release-dev keeps debug symbols in the binary. Other release targets remove those symbols from the binary although they +are made available in a separate symbols file. release-deployment is for a production release and release-test is for a +test release that supports the debug console which is used by expansion developers for debugging their OXPs. +You can install: +```bash +./mk.sh install-dev +``` -### Other Linux Make Targets +Other targets are install-deployment for a production install and install-test for a test install. -This target builds an AppImage for testing which can be found in build: +The underlying build system is Meson. You can run the deployment build directly using Meson build commands like this: ```bash -make pkg-appimage +meson setup build/meson_deployment -Ddeployment_release=true -Ddebug=false -Dstrip_bin=true -Db_lto=true --native-file clang.ini --reconfigure +meson compile -C build/meson_deployment ``` -The target pkg-appimage-deployment is the production release, while pkg-appimage-snapshot is for debugging. +### Other Linux ./mk.sh Targets -This target builds a Flatpak which can be found in build: +This target builds an AppImage for development which can be found in the `build` fodler: ```bash -make pkg-flatpak +./mk.sh pkg-appimage-dev ``` -Although there is a top level Makefile, the underlying build system is Meson. You can run the deployment -build directly using Meson build commands like this: +The target pkg-appimage-deployment is the production release, while pkg-appimage-test is for test. + +This target builds a Flatpak (deployment only) which can be found in the `build` folder: ```bash -meson setup build/meson_deployment -Ddeployment_release_configuration=true -Ddebug=false -Dstrip_bin=true -Db_lto=true --native-file clang.ini --reconfigure -meson compile -C build/meson_deployment -meson install -C build/meson_deployment +./mk.sh pkg-flatpak ``` +### Other Windows ./mk.sh Targets + +This target builds a Windows NSIS installer for development which can be found in the `build` folder: + +```bash +./mk.sh pkg-win-dev +``` + +The target pkg-win-deployment is the production release, while pkg-win-test is for test. + ### Mac OS Intel-based Macs can run old builds of Oolite, but current Macs are unsupported. It is hoped that they can be supported diff --git a/ShellScripts/Linux/install_freedesktop_fn.sh b/ShellScripts/Linux/install_freedesktop_fn.sh index b3a66a81c..25f47ebb5 100644 --- a/ShellScripts/Linux/install_freedesktop_fn.sh +++ b/ShellScripts/Linux/install_freedesktop_fn.sh @@ -1,61 +1,55 @@ #!/bin/bash -x # # Installs the manifest and injects version number -# -# Requires environment variables: -# VERSION -# APP_DATE -# echo "I am install_freedesktop_fn.sh $@" printenv | sort install_freedesktop() { - # Install metainfo (eg. for FlatHub and AppImageHub) - # $1: oolite.app directory path (source) - # $2: app folder (destination) - # $3: debug symbol folder - # $4: appdata or metainfo + local build_folder="$1" # oolite.app directory path (source) + local ver_full="$2" # Oolite version + local app_date="$3" # Oolite build date + local app_folder="$4" # app folder (destination) + local symbol_folder="$5" # debug symbol folder + local metainfo_suffix="$6" # can be appdata or metainfo local err_msg="❌ Error: Failed to" local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" - source ../common/get_version.sh + echo "Installing metainfo to to $app_folder" - echo "Installing metainfo to to $2" - - local appbin="$2/bin" - local appshr="$2/share" + local appbin="$app_folder/bin" + local appshr="$app_folder/share" # Install binaries and scripts - install -D "$1/oolite" "$appbin/oolite" || { echo "$err_msg install oolite binary" >&2; return 1; } - if [[ -f "$1/oolite.debug" ]]; then - install -D "$1/oolite.debug" "$2/$3/oolite.debug" || { echo "$err_msg install oolite debug symbols" >&2; return 1; } + install -D "$build_folder/oolite" "$appbin/oolite" || { echo "$err_msg install oolite binary" >&2; return 1; } + if [[ -f "$build_folder/oolite.debug" ]]; then + install -D "$build_folder/oolite.debug" "$app_folder/$symbol_folder/oolite.debug" || { echo "$err_msg install oolite debug symbols" >&2; return 1; } fi - install -D "$1/run_oolite.sh" "$appbin/run_oolite.sh" || { echo "$err_msg install run_oolite.sh" >&2; return 1; } + install -D "$build_folder/run_oolite.sh" "$appbin/run_oolite.sh" || { echo "$err_msg install run_oolite.sh" >&2; return 1; } # Resources copy local resourcesdir="$appshr/oolite/Resources" mkdir -p "$resourcesdir" - cp -rf "$1/Resources/." "$resourcesdir/" || { echo "$err_msg copy Resources folder" >&2; return 1; } + cp -rf "$build_folder/Resources/." "$resourcesdir/" || { echo "$err_msg copy Resources folder" >&2; return 1; } # AddOns copy if folder exists in oolite.app - if [ -d "$1/AddOns" ]; then + if [ -d "$build_folder/AddOns" ]; then local addonsdir="$appshr/oolite/AddOns" mkdir -p "$addonsdir" - cp -rf "$1/AddOns/." "$addonsdir/" || { echo "$err_msg copy AddOns folder" >&2; return 1; } + cp -rf "$build_folder/AddOns/." "$addonsdir/" || { echo "$err_msg copy AddOns folder" >&2; return 1; } fi rm -f "$resourcesdir/GNUstep.conf.orig" install -D "GNUstep.conf.template" "$resourcesdir/GNUstep.conf.template" || { echo "$err_msg GNUstep template" >&2; return 1; } - local app_metainfo="$appshr/metainfo/space.oolite.Oolite.$4.xml" + local app_metainfo="$appshr/metainfo/space.oolite.Oolite.$metainfo_suffix.xml" install -D ../../installers/FreeDesktop/space.oolite.Oolite.metainfo.xml.template "$app_metainfo" || { echo "$err_msg metainfo template" >&2; return 1; } - sed -i "s/@VER@/${VER_FULL}/g" "$app_metainfo" - sed -i "s/@DATE@/${APP_DATE}/g" "$app_metainfo" + sed -i "s/@VER@/${ver_full}/g" "$app_metainfo" + sed -i "s/@DATE@/${app_date}/g" "$app_metainfo" echo =========================================== echo Our manifest looks like this: @@ -64,8 +58,7 @@ install_freedesktop() { # Desktop and Icon install -D ../../installers/FreeDesktop/space.oolite.Oolite.desktop "$appshr/applications/space.oolite.Oolite.desktop" || { echo "$err_msg desktop file" >&2; return 1; } - - install -D "$1/Resources/Textures/oolite-logo1.png" "$appshr/icons/hicolor/256x256/apps/space.oolite.Oolite.png" || { echo "$err_msg icon file" >&2; return 1; } + install -D "$build_folder/Resources/Textures/oolite-logo1.png" "$appshr/icons/hicolor/256x256/apps/space.oolite.Oolite.png" || { echo "$err_msg icon file" >&2; return 1; } popd } \ No newline at end of file diff --git a/ShellScripts/common/generate_manifest_fn.sh b/ShellScripts/common/generate_manifest_fn.sh index 2fe7a426a..10f6e878d 100755 --- a/ShellScripts/common/generate_manifest_fn.sh +++ b/ShellScripts/common/generate_manifest_fn.sh @@ -1,16 +1,8 @@ generate_manifest() { - # Locate the xcconfig file - local oolite_version_file="src/Cocoa/oolite-version.xcconfig" - - if [[ ! -f "$oolite_version_file" ]]; then - echo "❌ $oolite_version_file not found!" >&2 - popd > /dev/null - return 1 - fi - - # Extract definition of $OOLITE_VERSION from the xcconfig - source "$oolite_version_file" - + local output_file="$1" + local deployment_release="$2" + local ver_full="$3" + local $ver_githash="$4" source ShellScripts/common/get_gitremote_fn.sh get_gitremote git_remote @@ -20,21 +12,22 @@ generate_manifest() { echo " title = \"Oolite core\";" echo " identifier = \"org.oolite.oolite\";" echo " " - echo " version = \"$VER_FULL\";" + echo " version = \"$ver_full\";" echo " git_remote_url = \"$git_remote\";" - echo " git_commit_hash = \"$VER_GITHASH\";" + echo " git_commit_hash = \"$ver_githash\";" - if [[ "$DEPLOYMENT_RELEASE_CONFIGURATION" == "yes" ]]; then + if [[ "$deployment_release" == "yes" ]]; then echo " debug_functionality_support = no;" else echo " debug_functionality_support = yes;" fi - - echo " required_oolite_version = \"$OOLITE_VERSION\";" + IFS='.' read -r major minor rest <<< "$ver_full" + local ver_short="$major.$minor" + echo " required_oolite_version = \"${ver_short}\";" echo " " echo " license = \"GPL 2+ / CC-BY-NC-SA 3.0 - see LICENSE.md for details\";" echo " author = \"Giles Williams, Jens Ayton and contributors\";" echo " information_url = \"https://oolite.space/\";" echo "}" - } > "$1" + } > "$output_file" } \ No newline at end of file diff --git a/ShellScripts/common/get_build_date_fn.sh b/ShellScripts/common/get_build_date_fn.sh new file mode 100755 index 000000000..a84169f9f --- /dev/null +++ b/ShellScripts/common/get_build_date_fn.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Calculates the Oolite build date +# + +get_build_date() { + local -n output_cpp_date=$1 + local -n output_app_date=$2 + local -n output_buildtime=$3 + local -n output_builder=$4 + # $5 is GITHUB_REPOSITORY environment variable from GitHub Actions + + # Run timestamp exactly once + local getversion_timestamp=$(git log -1 --format=%ct) + + # Date conversions use UTC for consistency + output_cpp_date=$(date -u -d "@$getversion_timestamp" +"%b %e %Y") + output_app_date=$(date -u -d "@$getversion_timestamp" +"%Y-%m-%d") + output_buildtime=$(date -u -d "@$getversion_timestamp" "+%Y.%m.%d %H:%M") + + if [[ "$5" == "OoliteProject/oolite" ]]; then + output_builder="OoliteProject" + else + output_builder="unknown" + fi +} \ No newline at end of file diff --git a/ShellScripts/common/get_version.sh b/ShellScripts/common/get_version.sh deleted file mode 100755 index 66f241dac..000000000 --- a/ShellScripts/common/get_version.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -# -# Calculates the Oolite version number if not passed via env variables. Output goes to stdout. -# - -SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) -pushd "$SCRIPT_DIR" > /dev/null - -mkdir -p ../../build -cd ../../build - -# Timestamp of last commit/push -if [[ -z "${GETVERSION_TIMESTAMP}" ]]; then - # Run timestamp exactly once and export it for any subsequent child scripts - export GETVERSION_TIMESTAMP=$(git log -1 --format=%ct) -fi -# Date conversions use UTC for consistency -# Convert to __DATE__ format (e.g., Feb 20 2026) -CPP_DATE=$(date -u -d "@$GETVERSION_TIMESTAMP" +"%b %e %Y") -# Convert to YYYY-MM-DD -APP_DATE=$(date -u -d "@$GETVERSION_TIMESTAMP" +"%Y-%m-%d") -# Convert to YYMMDD format (e.g., 260313) -VER_DATE=$(date -u -d "@$GETVERSION_TIMESTAMP" +"%y%m%d") -# Convert to YYYY.MM.DD HH:MM format (e.g., 2026.06.21 07:56) -BUILDTIME=$(date -u -d "@$GETVERSION_TIMESTAMP" "+%Y.%m.%d %H:%M") - -if [[ -z "${VER_FULL}" ]]; then - if [[ -z "${GITVERSION_JSON}" ]]; then - # Run GitVersion exactly once and export it for any subsequent child scripts - if ! command -v gitversion &> /dev/null; then - echo "❌ gitversion binary not found!" >&2 - exit 1 - fi - export GITVERSION_JSON=$(gitversion) - fi - VER_MAJ=$(echo "$GITVERSION_JSON" | jq -r '.Major') - VER_MIN=$(echo "$GITVERSION_JSON" | jq -r '.Minor') - VER_REV=$(echo "$GITVERSION_JSON" | jq -r '.Patch') - if [[ "" == "$VER_REV" ]]; then - VER_REV="0" - fi - VER_DIST=$(echo "$GITVERSION_JSON" | jq -r '.VersionSourceDistance') - VER_SEMVER=$(echo "$GITVERSION_JSON" | jq -r '.SemVer') - VER_UNCOMMITTED=$(echo "$GITVERSION_JSON" | jq -r '.UncommittedChanges') - - if git diff --quiet; then - VER_FULL=$VER_SEMVER - else - VER_FULL="${VER_SEMVER}+dirty.${VER_UNCOMMITTED}" - fi - - VER_NSIS="$VER_MAJ.$VER_MIN.$VER_REV.$VER_DIST" - VER_GITREV=$(git rev-list --count HEAD) - VER_GITHASH=$(git rev-parse --short=7 HEAD) -fi - -echo "$VER_FULL" -popd > /dev/null diff --git a/ShellScripts/common/get_version_fn.sh b/ShellScripts/common/get_version_fn.sh new file mode 100755 index 000000000..5db99861e --- /dev/null +++ b/ShellScripts/common/get_version_fn.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Calculates the Oolite version number +# + +# Get the name of the script that is sourcing this file +SUITE_PARENT=$(basename "${BASH_SOURCE[1]}") +# Define the ONLY script allowed to source this +ALLOWED_SCRIPT="mk.sh" +if [ "$SUITE_PARENT" != "$ALLOWED_SCRIPT" ]; then + echo "❌ This file can only be sourced by $ALLOWED_SCRIPT!" >&2 + return 1 2>/dev/null || exit 1 +fi + +get_version() { + local -n output_ver_full=$1 + local -n output_ver_nsis=$2 + local -n output_ver_gitrev=$3 + local -n output_ver_githash=$4 + + if [[ -n "$5" ]]; then # VER_FULL already populated + return 0 + fi + + if ! command -v gitversion &> /dev/null; then + echo "❌ gitversion binary not found!" >&2 + exit 1 + fi + + local gitversion_json=$(gitversion) + local ver_maj=$(echo "$gitversion_json" | jq -r '.Major') + local ver_min=$(echo "$gitversion_json" | jq -r '.Minor') + local ver_rev=$(echo "$gitversion_json" | jq -r '.Patch') + + if [[ "" == "$ver_rev" ]]; then + ver_rev="0" + fi + + local ver_dist=$(echo "$gitversion_json" | jq -r '.VersionSourceDistance') + local ver_semver=$(echo "$gitversion_json" | jq -r '.SemVer') + local ver_uncommitted=$(echo "$gitversion_json" | jq -r '.UncommittedChanges') + + if git diff --quiet; then + output_ver_full=$ver_semver + output_ver_nsis="$ver_maj.$ver_min.$ver_rev.$ver_dist" + else + output_ver_full="${ver_semver}+dirty.${ver_uncommitted}" + output_ver_nsis="$ver_maj.$ver_min.$ver_rev.$ver_uncommitted" + fi + + output_ver_gitrev=$(git rev-list --count HEAD) + output_ver_githash=$(git rev-parse --short=7 HEAD) +} \ No newline at end of file diff --git a/ShellScripts/common/install.sh b/ShellScripts/common/install.sh index 2b1dd59b6..c64b2d756 100755 --- a/ShellScripts/common/install.sh +++ b/ShellScripts/common/install.sh @@ -2,17 +2,23 @@ # Processes Oolite data files after compilation run_script() { + local stageprogpath="$1" + local bindir="$2" + local datadir="$3" + local host_os="$4" + local deployment_release="$5" + local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" > /dev/null cd ../.. - set -x - local appname=$(basename "$STAGEPROGPATH") - local progdir=$(dirname "$STAGEPROGPATH") + set -x + local appname=$(basename "$stageprogpath") + local progdir=$(dirname "$stageprogpath") local installdir="${INSTALLDIR:-$MESON_INSTALL_DESTDIR_PREFIX}" - local fullbindir="$installdir/$BINDIR" - local fulldatadir="$installdir/$DATADIR/oolite" # don't use appname here as Obj-C has oolite specifically + local fullbindir="$installdir/$bindir" + local fulldatadir="$installdir/$datadir/oolite" # don't use appname here as Obj-C has oolite specifically local progpath="$fullbindir/$appname" if ! mkdir -p "$fullbindir"; then echo "❌ Failed to create folder '$fullbindir'!" >&2 @@ -22,11 +28,11 @@ run_script() { echo "❌ Failed to create folder '$fulldatadir'!" >&2 return 1 fi - if ! cp -fu "$STAGEPROGPATH" "$progpath"; then - echo "❌ Failed to copy '$STAGEPROGPATH' to '$progpath'!" >&2 + if ! cp -fu "$stageprogpath" "$progpath"; then + echo "❌ Failed to copy '$stageprogpath' to '$progpath'!" >&2 return 1 - fi - if [[ "$HOST_OS" == "linux" ]]; then + fi + if [[ "$host_os" == "linux" ]]; then local run_oolite_src="$progdir/run_oolite.sh" local run_oolite_dst="$fullbindir/run_oolite.sh" if ! cp -fu "$run_oolite_src" "$run_oolite_dst"; then diff --git a/ShellScripts/common/post_build.sh b/ShellScripts/common/post_build.sh index fa9bd1c9c..b23947ef7 100755 --- a/ShellScripts/common/post_build.sh +++ b/ShellScripts/common/post_build.sh @@ -2,6 +2,18 @@ # Processes Oolite data files after compilation run_script() { + local origprogpath="$1" + local progdir="$2" + local host_os="$3" + local debug="$4" + local deployment_release="$5" + local espeak="$6" + local strip_bin="$7" + local ver_full="$8" + local ver_githash="$9" + local gnustep_folder="${10}" + local stamp_file="${11}" + local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" > /dev/null @@ -9,32 +21,32 @@ run_script() { cd ../.. set -x - local appname=$(basename "$ORIGPROGPATH") - local appdir=$(dirname "$ORIGPROGPATH") - local progpath="$PROGDIR/$appname" - local resourcesdir="$PROGDIR/Resources" + local appname=$(basename "$origprogpath") + local appdir=$(dirname "$origprogpath") + local progpath="$progdir/$appname" + local resourcesdir="$progdir/Resources" mkdir -p "$resourcesdir" - if [[ ! -f "$ORIGPROGPATH" ]]; then - echo "❌ 'Oolite binary at '$ORIGPROGPATH' does not exist!" >&2 + if [[ ! -f "$origprogpath" ]]; then + echo "❌ 'Oolite binary at '$origprogpath' does not exist!" >&2 return 1 fi - if ! cp -fu "$ORIGPROGPATH" "$progpath"; then - echo "❌ Failed to copy '$ORIGPROGPATH' to '$progpath'!" >&2 + if ! cp -fu "$origprogpath" "$progpath"; then + echo "❌ Failed to copy '$origprogpath' to '$progpath'!" >&2 return 1 fi - generate_manifest "$resourcesdir/manifest.plist" + generate_manifest "$resourcesdir/manifest.plist" "$deployment_release" "$ver_full" "$ver_githash" cp -fu src/Cocoa/Info-Oolite.plist "$resourcesdir/Info-gnustep.plist" - if [[ "$DEPLOYMENT_RELEASE_CONFIGURATION" == "no" ]]; then - local addonsdir="$PROGDIR/AddOns" + if [[ "$deployment_release" == "no" ]]; then + local addonsdir="$progdir/AddOns" mkdir -p "$addonsdir" rm -rf "$addonsdir/Basic-debug.oxp" cp -rf DebugOXP/Debug.oxp "$addonsdir/Basic-debug.oxp" fi # Voice Data - if [[ "$ESPEAK" == "yes" ]]; then - if [[ "$HOST_OS" == "windows" ]]; then + if [[ "$espeak" == "yes" ]]; then + if [[ "$host_os" == "windows" ]]; then # Windows espeak-ng-data cp -rfu "$MINGW_PREFIX/share/espeak-ng-data" "$resourcesdir" else @@ -70,13 +82,13 @@ run_script() { rm -f "$resourcesdir/AIReference.html" "$resourcesdir/*.icns" # Strip binary if requested - if [[ "$STRIP_BIN" == "yes" ]]; then - if [[ "$HOST_OS" == "windows" ]]; then + if [[ "$strip_bin" == "yes" ]]; then + if [[ "$host_os" == "windows" ]]; then # Windows: Standard GNU strip is safest for PE/COFF strip "$progpath" else # Linux - local debugpath="$PROGDIR/$appname.debug" + local debugpath="$progdir/$appname.debug" # Extract symbols to file objcopy --only-keep-debug "$progpath" "$debugpath" # Compress the debug sections in the symbol file @@ -86,20 +98,20 @@ run_script() { # Add the debug link objcopy --add-gnu-debuglink="$debugpath" "$progpath" fi - elif [[ "$HOST_OS" == "linux" ]]; then + elif [[ "$host_os" == "linux" ]]; then # Compress the debug sections in the binary objcopy --compress-debug-sections=zlib-gnu "$progpath" fi - if [[ "$HOST_OS" == "windows" ]]; then + if [[ "$host_os" == "windows" ]]; then # Determine and copy DLL dependencies local unix_prefix=$(cygpath -u "$MINGW_PREFIX") - ldd "$progpath" | grep "$unix_prefix" | awk '{print $3}' | xargs -I {} cp -rfu {} "$PROGDIR" + ldd "$progpath" | grep "$unix_prefix" | awk '{print $3}' | xargs -I {} cp -rfu {} "$progdir" else # Copy Linux-specific wrapper script - cp -fu ShellScripts/Linux/run_oolite.sh "$PROGDIR" - local gnustep_conf="$GNUSTEP_FOLDER/etc/GNUstep/GNUstep.conf" - if [ ! -f "$gnustep_conf" ] && [ "$GNUSTEP_FOLDER" = "/usr" ] && [ -f "/etc/GNUstep/GNUstep.conf" ]; then + cp -fu ShellScripts/Linux/run_oolite.sh "$progdir" + local gnustep_conf="$gnustep_folder/etc/GNUstep/GNUstep.conf" + if [ ! -f "$gnustep_conf" ] && [ "$gnustep_folder" = "/usr" ] && [ -f "/etc/GNUstep/GNUstep.conf" ]; then gnustep_conf="/etc/GNUstep/GNUstep.conf" fi install -D "$gnustep_conf" "$resourcesdir/GNUstep.conf.orig" || { echo "$err_msg GNUstep config" >&2; return 1; } @@ -109,11 +121,11 @@ run_script() { grep -E "libgnustep-base|libobjc\.so\." | \ grep -vE "^[[:space:]]*.*=>[[:space:]]*/(usr/(local/)?|lib(64)?/)" | \ awk '{print $3}' | \ - xargs -I {} cp -Lrfu {} "$PROGDIR/" + xargs -I {} cp -Lrfu {} "$progdir/" fi echo "✅ Oolite post-build completed successfully" - touch "$appdir/$STAMP_FILE" + touch "$appdir/$stamp_file" popd > /dev/null } diff --git a/installers/appimage/create_appimage_fn.sh b/installers/appimage/create_appimage_fn.sh index 6e09dbf8c..a52545630 100755 --- a/installers/appimage/create_appimage_fn.sh +++ b/installers/appimage/create_appimage_fn.sh @@ -1,18 +1,18 @@ #!/bin/bash -x # # Creates the appimage. -# First parameter can be set to build type, typically one of "test", "dev" or omitted for release builds. -# create_appimage() { - # First parameter is a suffix for the build type eg. test, dev + local build_folder="$1" # Build folder + local ver_full="$2" # Oolite version + local app_date="$3" # Oolite build date + local build_type="$4" # Typically one of "test", "dev" or omitted for release builds + local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" - mkdir -p ../../build cd ../../build source ../ShellScripts/Linux/os_detection.sh - source ../ShellScripts/common/get_version.sh source ../ShellScripts/Linux/install_freedesktop_fn.sh local arch=$(uname -m) @@ -22,9 +22,9 @@ create_appimage() { local appshr="$APPDIR/share" rm -rf "$APPDIR" - local abs_oolitedir=$(realpath -m "$1") + local abs_oolitedir=$(realpath -m "$build_folder") local abs_appdir=$(realpath -m "$APPDIR") - if ! install_freedesktop "$abs_oolitedir" "$abs_appdir" bin appdata; then + if ! install_freedesktop "$abs_oolitedir" "$ver_full" "$app_date" "$abs_appdir" "bin" "appdata"; then return 1 fi @@ -42,10 +42,10 @@ create_appimage() { local DESKTOP="$appshr/applications/space.oolite.Oolite.desktop" export DESKTOP local suffix - if (( $# == 2 )); then - suffix="_${2}-${VER_FULL}" + if [[ -n "$build_type" ]]; then + suffix="_$build_type-$ver_full" else - suffix="-$VER_FULL" + suffix="-$ver_full" fi local OUTNAME="oolite${suffix}-${arch}.AppImage" export OUTNAME diff --git a/installers/flatpak/create_flatpak_fn.sh b/installers/flatpak/create_flatpak_fn.sh index ad2905f26..681077bb3 100755 --- a/installers/flatpak/create_flatpak_fn.sh +++ b/installers/flatpak/create_flatpak_fn.sh @@ -1,7 +1,9 @@ #!/bin/bash -x create_flatpak() { - # First parameter is a suffix for the build type eg. test, dev + local ver_full="$1" # Oolite version + local github_repository="$2" # GitHub repository (set by GitHub Actions) + local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" @@ -19,7 +21,6 @@ create_flatpak() { mv "$outputdir/gitversion" /usr/local/bin/gitversion rm -f ${gitversion_tgz} fi - source ../ShellScripts/common/get_version.sh cp ../installers/flatpak/space.oolite.Oolite.* ./ @@ -30,12 +31,7 @@ create_flatpak() { fi local manifest="space.oolite.Oolite.yaml" - - local env_block="env:\n VER_FULL: \"$VER_FULL\"\n GITHUB_REPOSITORY: \"$GITHUB_REPOSITORY\"" - # Swap the comment - sed -i "s|#[[:space:]]*CI builds add an env block here|$env_block|g" "$manifest" || return 1 - - # check manifest + sed -i "s|^\([[:space:]]*- \)./mk.sh.*|\1./mk.sh flatpak-deployment --ver-full=\"$ver_full\" --github-repository=\"$github_repository\"|" "$manifest" || return 1 local lint_exceptions=$(mktemp /tmp/oolite-lint-XXXXXX.json) cat < "$lint_exceptions" { @@ -46,7 +42,7 @@ create_flatpak() { EOF trap 'rm -f "$lint_exceptions"' RETURN EXIT - if command -v flatpak-builder-lint >/dev/null 2>&1; then + if command -v flatpak-builder-lint >/dev/null 2>&1; then # check manifest if ! flatpak-builder-lint manifest "$manifest" --exceptions --user-exceptions="$lint_exceptions"; then echo "❌ Flatpak manifest lint failed!" >&2 cat "$manifest" @@ -97,12 +93,7 @@ EOF return 1 fi - local suffix - if (( $# == 1 )); then - suffix="_${1}-${VER_FULL}" - else - suffix="-$VER_FULL" - fi + local suffix="-$ver_full" local ARCH=$(uname -m) local filename="space.oolite.Oolite${suffix}-${ARCH}.flatpak" echo "Creating Flatpak $filename..." diff --git a/installers/flatpak/flatpak_build.sh b/installers/flatpak/flatpak_build.sh deleted file mode 100755 index 5ff69cc84..000000000 --- a/installers/flatpak/flatpak_build.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -x -# -# Prepares the app directory for the flatpak builder -# - -echo "I am flatpak_build.sh $@" -printenv | sort - -source ShellScripts/common/get_version.sh -source ShellScripts/Linux/install_freedesktop_fn.sh - -export ADDITIONAL_CFLAGS="-DBUILD_DATE='\"$CPP_DATE\"'" -export ADDITIONAL_OBJCFLAGS="-DBUILD_DATE='\"$CPP_DATE\"'" -./mk.sh release-deployment - -ABS_OOLITEDIR=$(realpath -m "build/meson_deployment/oolite.app") -install_freedesktop $ABS_OOLITEDIR /app lib/debug/bin metainfo -# Ensure the destination directory exists -mkdir -p /app/lib/debug/source/oolite -# Copy the src directory recursively -cp -r src /app/lib/debug/source/oolite/ || { - echo "❌ $err_msg install oolite source code" >&2 - return 1 -} diff --git a/installers/flatpak/flatpak_postbuild_fn.sh b/installers/flatpak/flatpak_postbuild_fn.sh new file mode 100755 index 000000000..66fb4c6da --- /dev/null +++ b/installers/flatpak/flatpak_postbuild_fn.sh @@ -0,0 +1,24 @@ +#!/bin/bash -x +# +# Prepares the app directory for the flatpak builder +# + +flatpak_postbuild() { + local build_folder="$1" # Build folder + local ver_full="$2" # Oolite version + local app_date="$3" # Oolite build date + + local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) + pushd "$script_dir" + cd ../../build + source ../ShellScripts/Linux/install_freedesktop_fn.sh + + local abs_oolitedir=$(realpath -m "$build_folder") + install_freedesktop "$abs_oolitedir" "$ver_full" "$app_date" "/app" "lib/debug/bin" "metainfo" + mkdir -p /app/lib/debug/source/oolite # Ensure the destination directory exists + # Copy the src directory recursively + cp -r ../src /app/lib/debug/source/oolite/ || { + echo "❌ $err_msg install oolite source code" >&2 + return 1 + } +} \ No newline at end of file diff --git a/installers/flatpak/space.oolite.Oolite.yaml b/installers/flatpak/space.oolite.Oolite.yaml index 33456d2ff..8adb1e002 100644 --- a/installers/flatpak/space.oolite.Oolite.yaml +++ b/installers/flatpak/space.oolite.Oolite.yaml @@ -111,9 +111,10 @@ modules: buildsystem: simple build-options: no-debuginfo: true - # CI builds add an env block here build-commands: - - source installers/flatpak/flatpak_build.sh + # Update --ver-full for FlatHub release. For CI and local builds, create_flatpak.sh replaces + # --ver-full and --github-repository values + - ./mk.sh flatpak-deployment --ver-full="1.92.1" --github-repository="OoliteProject/oolite" sources: # Update tag and commit for FlatHub release. For CI and local builds, create_flatpak.sh replaces git source with: # - type: dir diff --git a/installers/win32/OOlite.nsi b/installers/win32/OOlite.nsi index 0f24d7858..6a70a8db3 100644 --- a/installers/win32/OOlite.nsi +++ b/installers/win32/OOlite.nsi @@ -1,5 +1,5 @@ ; Include the NSIS logic library. Required for the code that handles -; adding of the changelog file in the non-snapshot distributions +; adding of the changelog file in the non-dev distributions !include "LogicLib.nsh" ; Include the Sections library, required for being able to provide the @@ -35,8 +35,8 @@ !define SEMVER ${VERSION} !endif -!ifndef SNAPSHOT -!ifndef DEPLOYMENT +!ifndef DEV_RELEASE +!ifndef DEPLOYMENT_RELEASE !define EXTVER "-test" ; Official distribution with OXP developer tools !define ADDCHANGELOG 1 ; Official distributions go with a changelog file !else @@ -45,10 +45,10 @@ !endif !else !define EXTVER "-dev" -!define ADDCHANGELOG 0 ; Snapshot distributions do not need changelog +!define ADDCHANGELOG 0 ; Dev distributions do not need changelog !endif -!ifndef DEPLOYMENT +!ifndef DEPLOYMENT_RELEASE !define DEBUGOXPINCLUDED 1 !else !define DEBUGOXPINCLUDED 0 @@ -87,7 +87,7 @@ VIAddVersionKey "FileDescription" "A space combat/trading game, inspired by Elit VIAddVersionKey "LegalCopyright" "� 2003-2026 Giles Williams, Jens Ayton and contributors" VIAddVersionKey "FileVersion" "${VER}" VIAddVersionKey "ProductVersion" "${SEMVER}" -!ifdef SNAPSHOT +!ifdef DEV_RELEASE VIAddVersionKey "GIT Revision" "${VER_GITHASH}" !endif !ifdef BUILDTIME @@ -104,7 +104,7 @@ VIProductVersion "${VER}" !define MUI_UNICON oolite.ico !insertmacro MUI_PAGE_DIRECTORY -!ifndef DEPLOYMENT +!ifndef DEPLOYMENT_RELEASE !insertmacro MUI_PAGE_COMPONENTS !endif !insertmacro MUI_PAGE_INSTFILES @@ -127,14 +127,14 @@ VIProductVersion "${VER}" !insertmacro MUI_LANGUAGE "English" -!ifndef DEPLOYMENT +!ifndef DEPLOYMENT_RELEASE ; Create the main game and Debug OXP sections Section "Oolite Game" ooGame SectionIn RO ; The game itself cannot be unselected SectionEnd Section "Basic-debug.OXP" ooDebugOXP -; Do not use any of the Debug OXP files when we are building Deployment +; Do not use any of the Debug OXP files when we are building deployment release SetOutPath $INSTDIR File /r "${DST}\AddOns" SectionEnd @@ -200,7 +200,7 @@ uninst: done: FunctionEnd -!ifndef DEPLOYMENT +!ifndef DEPLOYMENT_RELEASE Function .onSelChange ${If} ${SectionIsSelected} ${ooDebugOXP} !insertmacro SelectSection ${ooDebugOXP} diff --git a/installers/win32/create_nsis_fn.sh b/installers/win32/create_nsis_fn.sh index 08190a328..3371e1b31 100644 --- a/installers/win32/create_nsis_fn.sh +++ b/installers/win32/create_nsis_fn.sh @@ -1,20 +1,20 @@ #!/bin/bash -x # # Creates the windows installer using NSIS. -# First parameter can be set to build type, typically one of "test", "dev" or omitted for release builds. -# Accepts two verion variables: -# VER_FULL - the full version number Oolite is getting built with -# VER_NSIS - the numberical version number (x.x.x.x) that the NSIS installer is built with -# create_nsis() { - # First parameter is a suffix for the build type eg. test, dev + local build_folder="$1" # Build folder + local ver_full="$2" # Oolite version + local ver_gitrev="$3" # Total number of commits in the history of current branch + local ver_githash="$4" # Git hash + local buildtime="$5" # Oolite build time + local build_type="$6" # Typically one of "test", "dev" or omitted for release builds + local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" mkdir -p ../../build/nsis cd ../../build/nsis - source ../../ShellScripts/common/get_version.sh cp ../../installers/win32/* ./ @@ -39,28 +39,35 @@ create_nsis() { return 1 fi - local oolite_dir="../$1" + local oolite_dir="../$build_folder" oolite_dir="${oolite_dir//\//\\}" - # Passing arguments cause problems with some versions of NSIS. - # Because of this, we generate them into a separate file and include them. + + [[ "$ver_full" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+).*\.([0-9]+)$ ]] # Regex captures: Major, Minor, Patch, Distance + local ver_maj="${BASH_REMATCH[1]}" + local ver_min="${BASH_REMATCH[2]}" + local ver_rev="${BASH_REMATCH[3]}" + local ver_dist="${BASH_REMATCH[4]}" + local ver_nsis="${ver_maj}.${ver_min}.${ver_rev}.${ver_dist}" + + # Passing arguments can cause problems with NSIS so we generate them into a separate file and include them. echo "; Version Definitions for Oolite" > OoliteVersions.nsh echo "; NOTE - This file is auto-generated by the Makefile, any manual edits will be overwritten" >> OoliteVersions.nsh - echo "!define oolite_dir ${oolite_dir}" >> OoliteVersions.nsh - echo "!define VER_MAJ ${VER_MAJ}" >> OoliteVersions.nsh - echo "!define VER_MIN ${VER_MIN}" >> OoliteVersions.nsh - echo "!define VER_REV ${VER_REV}" >> OoliteVersions.nsh - echo "!define VER_GITREV ${VER_GITREV}" >> OoliteVersions.nsh - echo "!define VER_GITHASH ${VER_GITHASH}" >> OoliteVersions.nsh - echo "!define VERSION ${VER_NSIS}" >> OoliteVersions.nsh - echo "!define SEMVER ${VER_FULL}" >> OoliteVersions.nsh - echo "!define BUILDTIME \"${BUILDTIME}\"" >> OoliteVersions.nsh + echo "!define OOLITE_DIR ${oolite_dir}" >> OoliteVersions.nsh + echo "!define VER_MAJ ${ver_maj}" >> OoliteVersions.nsh + echo "!define VER_MIN ${ver_min}" >> OoliteVersions.nsh + echo "!define VER_REV ${ver_rev}" >> OoliteVersions.nsh + echo "!define VER_GITREV ${ver_gitrev}" >> OoliteVersions.nsh + echo "!define VER_GITHASH ${ver_githash}" >> OoliteVersions.nsh + echo "!define VERSION ${ver_nsis}" >> OoliteVersions.nsh + echo "!define SEMVER ${ver_full}" >> OoliteVersions.nsh + echo "!define BUILDTIME \"${buildtime}\"" >> OoliteVersions.nsh echo "!define BUILDHOST_IS64BIT 1" >> OoliteVersions.nsh - if [[ "$2" == "dev" ]]; then - echo "!define SNAPSHOT 1" >> OoliteVersions.nsh - elif [[ "$2" != "test" ]]; then - echo "!define DEPLOYMENT 1" >> OoliteVersions.nsh + if [[ "$build_type" == "dev" ]]; then + echo "!define DEV_RELEASE 1" >> OoliteVersions.nsh + elif [[ "$build_type" != "test" ]]; then + echo "!define DEPLOYMENT_RELEASE 1" >> OoliteVersions.nsh fi local nsis diff --git a/meson.build b/meson.build index badc7b786..6602937cd 100644 --- a/meson.build +++ b/meson.build @@ -2,11 +2,7 @@ project( 'oolite', ['c', 'cpp', 'objc'], meson_version: '>= 1.4.0', - version: run_command( - 'bash', - files('ShellScripts/common/get_version.sh'), - check: true, - ).stdout().strip(), + version: 'not used', default_options: [ 'optimization=2', ], @@ -15,20 +11,11 @@ project( host_os = host_machine.system() c_family = ['c', 'cpp', 'objc'] -version_string = meson.project_version() +version_string = get_option('ver_full') # use instead of meson project version! add_project_arguments( '-DOO_VERSION_FULL="@0@"'.format(version_string), - language: c_family, -) - -github_repository = get_option('github_repository') -if github_repository == 'OoliteProject/oolite' - builder = 'OoliteProject' -else - builder = 'unknown' -endif -add_project_arguments( - '-DOO_BUILDER="@0@"'.format(builder), + '-DOO_BUILD_DATE="@0@"'.format(get_option('build_date')), + '-DOO_BUILDER="@0@"'.format(get_option('builder')), language: c_family, ) @@ -47,7 +34,7 @@ if get_option('no_shaders') add_project_arguments('-DNO_SHADERS=1', language: c_family) endif -if get_option('deployment_release_configuration') +if get_option('deployment_release') add_project_arguments( '-DNDEBUG', '-DOO_CHECK_GL_HEAVY=0', @@ -81,10 +68,9 @@ else endif endif -if get_option('snapshot_build') +if get_option('dev_release') add_project_arguments( - '-DSNAPSHOT_BUILD', - '-DOOLITE_SNAPSHOT_VERSION="@0@"'.format(version_string), + '-DDEV_RELEASE', language: c_family, ) endif diff --git a/meson.options b/meson.options index 7ff139544..f53c1418e 100644 --- a/meson.options +++ b/meson.options @@ -32,11 +32,11 @@ option('debug_graphviz', type: 'boolean', value: true, description: 'Enable AI state-machine graph visualization via GraphViz syntax output') # Release Variant Control -option('deployment_release_configuration', type: 'boolean', value: false, +option('deployment_release', type: 'boolean', value: false, description: 'Force a strict production deployment setup (overrides and disables most debugging instrumentation)') -option('snapshot_build', type: 'boolean', value: false, - description: 'Mark the compilation as a development snapshot build') +option('dev_release', type: 'boolean', value: false, + description: 'Mark the compilation as a development release') option('strip_bin', type: 'boolean', value: false, description: 'Enable stripping') @@ -44,8 +44,20 @@ option('strip_bin', type: 'boolean', value: false, description: 'Enable strippin option('pdb', type: 'boolean', value: false, description: 'Windows Clang builds only: Generate native .pdb debug symbol files') -# GitHub repository variable from CI if available -option('github_repository', type: 'string', value: '', - description: 'GitHub repository variable from CI if available') +# Oolite version +option('ver_full', type: 'string', value: '', + description: 'Oolite version') + +# Git hash of commit +option('ver_githash', type: 'string', value: '', + description: 'Git hash of commit') + +# Oolite build date +option('build_date', type: 'string', value: 'unknown', + description: 'Oolite build date') + +# Oolite builder +option('builder', type: 'string', value: 'unknown', + description: 'Oolite builder') diff --git a/mk.sh b/mk.sh index 7c9aca50b..b8fd481e4 100755 --- a/mk.sh +++ b/mk.sh @@ -3,148 +3,196 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$SCRIPT_DIR" > /dev/null -# Strict expansions, but NO 'set -e' -set -o pipefail +set -u -o pipefail # Strict expansions # --- Error Handling Trap --- cleanup_and_exit() { local exit_code=$? - # If the exit code is 0 (success) but this function was triggered, - # force it to 1 to indicate an error. if [[ $exit_code -eq 0 ]]; then - exit_code=1 + exit_code=1 # force 0 exit code to 1 to indicate an error fi - echo "❌ Oolite build failed on line $1 with exit code $exit_code!" >&2 - - # Always pop the directory stack before exiting - popd > /dev/null 2>&1 || true - - # Exit only if not sourced - if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + popd > /dev/null 2>&1 || true # Always pop the directory stack before exiting + if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then # Exit only if not sourced exit "$exit_code" fi } - -# Trap any command errors (ERR) passing ${LINENO} to know exactly where it failed. -trap 'cleanup_and_exit ${LINENO}' ERR - -# --- Environment Variables & Defaults --- -NATIVE_FILE="${NATIVE_FILE:-clang.ini}" -BUILDER="${BUILDER:-unknown}" -GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-}" +trap 'cleanup_and_exit ${LINENO}' ERR # Trap any command errors (ERR) passing ${LINENO} to know where it failed # --- Feature Flags & Options --- +NATIVE_FILE="" +VER_FULL="" +GITHUB_REPOSITORY="" CLEAN_BUILD=false SETUP_FLAGS=() # Array to cleanly store additional meson setup arguments +COMPILE_FLAGS=() # Array to cleanly store additional meson compile arguments +INSTALL_FLAGS=() # Array to cleanly store additional meson install arguments -# --- Helper Functions --- -# Replicates $(call meson_build,flags,suffix) -meson_build() { +meson_setup() { local build_dir="build/meson_$2" - # If --clean was specified, delete the specific build directory first if [[ "$CLEAN_BUILD" == true ]]; then echo "--> Cleaning target build directory: ${build_dir}" - rm -rf "$build_dir" + rm -rf "$build_dir" # If --clean was specified, delete the specific build directory first fi - echo "--> Running Meson build for: $2" + echo "--> Running Meson setup for: $2" # Setup with --reconfigure, fallback to fresh setup. SETUP_FLAGS safely expands the array only if it's not empty - meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dgithub_repository="${GITHUB_REPOSITORY}" --native-file "${NATIVE_FILE}" --reconfigure 2>/dev/null || \ - meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dgithub_repository="${GITHUB_REPOSITORY}" --native-file "${NATIVE_FILE}" - meson compile -C "$build_dir" + meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" --reconfigure 2>/dev/null || \ + meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" +} + +meson_build() { + echo "--> Running Meson build for: $1" + meson compile -C "build/meson_$1" ${COMPILE_FLAGS[@]+"${COMPILE_FLAGS[@]}"} } meson_install() { echo "--> Running Meson install for: $1" - meson install -C "build/meson_$1" + meson install -C "build/meson_$1" ${INSTALL_FLAGS[@]+"${INSTALL_FLAGS[@]}"} } -# --- Script Help Menu --- -show_help() { +show_help() { # Script Help Menu echo "Usage: $0 [options] " echo "" echo "Options:" - echo -e " \033[36m--clean\033[0m Delete target build directory before compiling" - echo -e " \033[36m--setup-flags=\"...\"\033[0m Pass additional arguments directly to 'meson setup'" + echo -e " \033[36m--clean\033[0m Delete target build directory before compiling" + echo -e " \033[36m--setup-flags=\"...\"\033[0m Pass additional arguments directly to 'meson setup'" + echo -e " \033[36m--native-file=\"...\"\033[0m Specify native file (defaults to clang.ini)" + echo -e " \033[36m--ver-full=\"...\"\033[0m Specify full version string" + echo -e " \033[36m--github-repository=\"...\"\033[0m Specify target GitHub repository" echo "" echo "Targets:" - echo -e " \033[36mrelease\033[0m Build a test release executable" - echo -e " \033[36mrelease-deployment\033[0m Build a release deployment executable" - echo -e " \033[36mrelease-snapshot\033[0m Build a snapshot release executable" - echo -e " \033[36mdebug\033[0m Build a debug executable" - echo -e " \033[36minstall\033[0m Install the test release build" - echo -e " \033[36minstall-deployment\033[0m Install the release deployment build" - echo -e " \033[36minstall-snapshot\033[0m Install the snapshot release build" - echo -e " \033[36mtest\033[0m Run test suite (depends on release-snapshot)" - echo -e " \033[36mclean\033[0m Remove all generated build artifacts" - echo -e " \033[36mpkg-flatpak\033[0m Package a Flatpak application" - echo -e " \033[36mpkg-appimage\033[0m Package a test release AppImage" - echo -e " \033[36mpkg-appimage-deployment\033[0m Package a deployment AppImage" - echo -e " \033[36mpkg-appimage-snapshot\033[0m Package a snapshot AppImage" - echo -e " \033[36mpkg-win\033[0m Package a Windows NSIS test release installer" - echo -e " \033[36mpkg-win-deployment\033[0m Package a Windows NSIS deployment installer" - echo -e " \033[36mpkg-win-snapshot\033[0m Package a Windows NSIS snapshot installer" + echo -e " \033[36msetup-deployment\033[0m Setup a deployment release executable" + echo -e " \033[36msetup-test\033[0m Setup a test release executable" + echo -e " \033[36msetup-dev\033[0m Setup a dev release executable" + echo -e " \033[36msetup-debug\033[0m Setup a debug executable" + echo -e " \033[36mcompile-deployment\033[0m Compile a deployment release executable" + echo -e " \033[36mcompile-test\033[0m Compile a test release executable" + echo -e " \033[36mcompile-dev\033[0m Compile a dev release executable" + echo -e " \033[36mcompile-debug\033[0m Compile a debug executable" + echo -e " \033[36mbuild-deployment\033[0m Setup and compile a deployment release executable" + echo -e " \033[36mbuild-test\033[0m Setup and compile a test release executable" + echo -e " \033[36mbuild-dev\033[0m Setup and compile a dev release executable" + echo -e " \033[36mbuild-debug\033[0m Setup and compile a debug executable" + echo -e " \033[36minstall-deployment\033[0m Install the deployment release installation" + echo -e " \033[36minstall-test\033[0m Install the test release installation" + echo -e " \033[36minstall-dev\033[0m Install the dev release installation" + echo -e " \033[36minstall-debug\033[0m Install the debug installation" + echo -e " \033[36mtest\033[0m Run test suite (depends on build-dev)" + echo -e " \033[36mclean\033[0m Remove all generated build artifacts" + echo -e " \033[36mpkg-flatpak\033[0m Package a Flatpak application" + echo -e " \033[36mpkg-appimage-deployment\033[0m Package a Linux deployment release AppImage" + echo -e " \033[36mpkg-appimage-test\033[0m Package a Linux test release AppImage" + echo -e " \033[36mpkg-appimage-dev\033[0m Package a Linux dev release AppImage" + echo -e " \033[36mpkg-win-deployment\033[0m Package a Windows NSIS deployment release installer" + echo -e " \033[36mpkg-win-test\033[0m Package a Windows NSIS test release installer" + echo -e " \033[36mpkg-win-dev\033[0m Package a Windows NSIS dev release installer" } -# --- Target Execution Logic --- -execute_target() { +execute_target() { # Target Execution Logic case "$1" in - release) - meson_build "-Ddebug=false -Dstrip_bin=true -Db_lto=true" "release" + setup-deployment) + meson_setup "-Ddeployment_release=true -Ddebug=false -Dstrip_bin=true -Db_lto=true" "deployment" + ;; + setup-test) + meson_setup "-Ddebug=false -Dstrip_bin=true -Db_lto=true" "test" + ;; + setup-dev) + meson_setup "-Ddev_release=true -Ddebug=false -Dstrip_bin=false" "dev" ;; - release-deployment) - meson_build "-Ddeployment_release_configuration=true -Ddebug=false -Dstrip_bin=true -Db_lto=true" "deployment" + setup-debug) + meson_setup "-Ddebug=true -Dstrip_bin=false" "debug" ;; - release-snapshot) - meson_build "-Dsnapshot_build=true -Ddebug=false -Dstrip_bin=false" "snapshot" + compile-deployment) + meson_build "deployment" ;; - debug) - meson_build "-Ddebug=true -Dstrip_bin=false" "debug" + compile-test) + meson_build "test" ;; - install) - meson_install "release" + compile-dev) + meson_build "dev" + ;; + compile-debug) + meson_build "debug" + ;; + build-deployment) + execute_target "setup-deployment" + execute_target "compile-deployment" + ;; + build-test) + execute_target "setup-test" + execute_target "compile-test" + ;; + build-dev) + execute_target "setup-dev" + execute_target "compile-dev" + ;; + build-debug) + execute_target "setup-debug" + execute_target "compile-debug" ;; install-deployment) meson_install "deployment" ;; - install-snapshot) - meson_install "snapshot" + install-test) + meson_install "test" + ;; + install-dev) + meson_install "dev" + ;; + install-debug) + meson_install "debug" + ;; + test-deployment) + execute_target "build-deployment" + source tests/run_test_fn.sh && run_test + ;; + test-test) + execute_target "build-test" + source tests/run_test_fn.sh && run_test ;; - test) - execute_target "release-snapshot" + test-dev) + execute_target "build-dev" + source tests/run_test_fn.sh && run_test + ;; + test-debug) + execute_target "build-debug" source tests/run_test_fn.sh && run_test ;; clean) echo "--> Cleaning all build artifacts..." rm -rf build/meson_* ;; - pkg-flatpak) - source installers/flatpak/create_flatpak_fn.sh && create_flatpak + flatpak-deployment) # This is used internally by the flatpak YAML + execute_target "build-deployment" + source installers/flatpak/flatpak_postbuild_fn.sh && flatpak_postbuild meson_deployment/oolite.app "$VER_FULL" "$APP_DATE" ;; - pkg-appimage) - execute_target "release" - source installers/appimage/create_appimage_fn.sh && create_appimage meson_release/oolite.app "test" + pkg-flatpak) + source installers/flatpak/create_flatpak_fn.sh && create_flatpak "$VER_FULL" "$GITHUB_REPOSITORY" ;; pkg-appimage-deployment) - execute_target "release-deployment" - source installers/appimage/create_appimage_fn.sh && create_appimage meson_deployment/oolite.app + execute_target "build-deployment" + source installers/appimage/create_appimage_fn.sh && create_appimage meson_deployment/oolite.app "$VER_FULL" "$APP_DATE" "" ;; - pkg-appimage-snapshot) - execute_target "release-snapshot" - source installers/appimage/create_appimage_fn.sh && create_appimage meson_snapshot/oolite.app "dev" + pkg-appimage-test) + execute_target "build-test" + source installers/appimage/create_appimage_fn.sh && create_appimage meson_test/oolite.app "$VER_FULL" "$APP_DATE" "test" ;; - pkg-win) - execute_target "release" - source installers/win32/create_nsis_fn.sh && create_nsis meson_release/oolite.app "test" + pkg-appimage-dev) + execute_target "build-dev" + source installers/appimage/create_appimage_fn.sh && create_appimage meson_dev/oolite.app "$VER_FULL" "$APP_DATE" "dev" ;; pkg-win-deployment) - execute_target "release-deployment" - source installers/win32/create_nsis_fn.sh && create_nsis meson_deployment/oolite.app + execute_target "build-deployment" + source installers/win32/create_nsis_fn.sh && create_nsis meson_deployment/oolite.app "$VER_FULL" "$VER_GITREV" "$VER_GITHASH" "$BUILDTIME" "" + ;; + pkg-win-test) + execute_target "build-test" + source installers/win32/create_nsis_fn.sh && create_nsis meson_test/oolite.app "$VER_FULL" "$VER_GITREV" "$VER_GITHASH" "$BUILDTIME" "test" ;; - pkg-win-snapshot) - execute_target "release-snapshot" - source installers/win32/create_nsis_fn.sh && create_nsis meson_snapshot/oolite.app "dev" + pkg-win-dev) + execute_target "build-dev" + source installers/win32/create_nsis_fn.sh && create_nsis meson_dev/oolite.app "$VER_FULL" "$VER_GITREV" "$VER_GITHASH" "$BUILDTIME" "dev" ;; help|--help|-h) show_help @@ -157,21 +205,40 @@ execute_target() { esac } -# --- Flexible Argument Parser --- TARGET="" - -while [[ $# -gt 0 ]]; do +while [[ $# -gt 0 ]]; do # Flexible Argument Parser case "$1" in --clean) CLEAN_BUILD=true shift ;; --setup-flags=*) - # Handle inline assignment format (e.g., --setup-flags="-Dfoo=bar") read -r -a flags_array <<< "${1#*=}" SETUP_FLAGS+=("${flags_array[@]}") shift ;; + --compile-flags=*) + read -r -a flags_array <<< "${1#*=}" + COMPILE_FLAGS+=("${flags_array[@]}") + shift + ;; + --install-flags=*) + read -r -a flags_array <<< "${1#*=}" + INSTALL_FLAGS+=("${flags_array[@]}") + shift + ;; + --native-file=*) + NATIVE_FILE="${1#*=}" + shift + ;; + --ver-full=*) + VER_FULL="${1#*=}" + shift + ;; + --github-repository=*) + GITHUB_REPOSITORY="${1#*=}" + shift + ;; help|--help|-h) show_help exit 0 @@ -192,20 +259,24 @@ while [[ $# -gt 0 ]]; do esac done -# Fallback to help menu if no target was provided if [[ -z "$TARGET" ]]; then - show_help + show_help # Fallback to help menu if no target was provided exit 1 fi +if [[ -z "$NATIVE_FILE" ]]; then + NATIVE_FILE="clang.ini" # Apply default for NATIVE_FILE if it wasn't passed as a parameter +fi + +source ShellScripts/common/get_build_date_fn.sh && get_build_date CPP_DATE APP_DATE BUILDTIME BUILDER "$GITHUB_REPOSITORY" +source ShellScripts/common/get_version_fn.sh && get_version VER_FULL VER_NSIS VER_GITREV VER_GITHASH "$VER_FULL" execute_target "$TARGET" -# Successful Exit - remove the ERR trap so it doesn't accidentally fire during normal bailing. -trap - ERR + +trap - ERR # Successful Exit - remove the ERR trap so it doesn't accidentally fire during normal bailing popd > /dev/null -# Only print build success if it wasn't a help menu or a cleanup action if [[ "$TARGET" != "help" && "$TARGET" != "--help" && "$TARGET" != "-h" && "$TARGET" != "clean" ]]; then - echo "✅ Oolite target '$TARGET' completed successfully" + echo "✅ Oolite target '$TARGET' completed successfully" # Print success if not a help menu or a cleanup action fi if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then diff --git a/src/Core/OOLogHeader.m b/src/Core/OOLogHeader.m index c2522d6b0..1e19beb86 100644 --- a/src/Core/OOLogHeader.m +++ b/src/Core/OOLogHeader.m @@ -161,7 +161,7 @@ void OOPrintLogHeader(void) #endif NSString *versionString = nil; - #if (defined (SNAPSHOT_BUILD)) + #if (defined (DEV_RELEASE)) versionString = @"development version " @OO_VERSION_FULL; #else versionString = @"version " @OO_VERSION_FULL; diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 68138c75e..bd8ecc0ce 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -5243,7 +5243,7 @@ - (void) drawUniverse // should come after the HUD to avoid it being overlapped by it [self drawMessage]; -#if (defined (SNAPSHOT_BUILD)) +#if (defined (DEV_RELEASE)) [self drawWatermarkString:@"Development version " @OO_VERSION_FULL]; #endif diff --git a/src/SDL/MyOpenGLView.m b/src/SDL/MyOpenGLView.m index 1a9a19ace..a33b942b1 100644 --- a/src/SDL/MyOpenGLView.m +++ b/src/SDL/MyOpenGLView.m @@ -144,11 +144,7 @@ - (NSMutableDictionary *) getNativeSize - (NSString*) getWindowCaption { -#ifdef BUILD_DATE - NSString *caption = [NSString stringWithFormat:@"Oolite v%@ by %@ - %s", @OO_VERSION_FULL, @OO_BUILDER, BUILD_DATE]; -#else - NSString *caption = [NSString stringWithFormat:@"Oolite v%@ by %@ - %s", @OO_VERSION_FULL, @OO_BUILDER, __DATE__]; -#endif + NSString *caption = [NSString stringWithFormat:@"Oolite v%@ by %@ - %@", @OO_VERSION_FULL, @OO_BUILDER, @OO_BUILD_DATE]; return [[caption retain] autorelease]; } diff --git a/src/meson.build b/src/meson.build index 55f9e304d..ad8b1c374 100644 --- a/src/meson.build +++ b/src/meson.build @@ -37,40 +37,36 @@ oolite_bin = executable( prog_dir = meson.global_build_root() / appname + '.app' stamp_file = '.oolite_bundle.stamp' -post_build_env_args = [ - 'ORIGPROGPATH=' + meson.current_build_dir() / appname, - 'PROGDIR=' + prog_dir, - 'HOST_OS=' + host_os, - 'DEBUG=' + (get_option('debug') ? 'yes' : 'no'), - 'DEPLOYMENT_RELEASE_CONFIGURATION=' + ( - get_option('deployment_release_configuration') ? 'yes' : 'no' - ), - 'ESPEAK=' + (get_option('espeak') ? 'yes' : 'no'), - 'STRIP_BIN=' + (get_option('strip_bin') ? 'yes' : 'no'), - 'VER_FULL=' + version_string, - 'GNUSTEP_FOLDER=' + gnustep_folder, - 'STAMP_FILE=' + stamp_file, +post_build_args = [ + meson.current_build_dir() / appname, + prog_dir, + host_os, + get_option('debug') ? 'yes' : 'no', + get_option('deployment_release') ? 'yes' : 'no', + get_option('espeak') ? 'yes' : 'no', + get_option('strip_bin') ? 'yes' : 'no', + version_string, + get_option('ver_githash'), + gnustep_folder, + stamp_file, ] post_build_script = find_program('../ShellScripts/common/post_build.sh') oolite_app_bundle = custom_target('post_build', input: oolite_bin, output: stamp_file, - depend_files: [post_build_script.full_path()], command: [ - 'env', - post_build_env_args, - post_build_script.full_path(), + post_build_script, + post_build_args, ], build_by_default: true, install: false, ) -install_env_args = [ - 'STAGEPROGPATH=' + prog_dir / appname, - 'BINDIR=' + get_option('bindir'), - 'DATADIR=' + get_option('datadir'), - 'HOST_OS=' + host_os, - 'DEPLOYMENT_RELEASE_CONFIGURATION=' + ( - get_option('deployment_release_configuration') ? 'yes' : 'no'), +install_args = [ + prog_dir / appname, + get_option('bindir'), + get_option('datadir'), + host_os, + get_option('deployment_release') ? 'yes' : 'no', ] install_script = find_program('../ShellScripts/common/install.sh') -meson.add_install_script('env', install_env_args, install_script.full_path()) \ No newline at end of file +meson.add_install_script(install_script, install_args) From 4a9e977e1bf8e50986683839fd82ce9072bb1226 Mon Sep 17 00:00:00 2001 From: mcarans Date: Sat, 27 Jun 2026 19:52:18 +1200 Subject: [PATCH 04/23] Fix test Fix Windows --- ShellScripts/common/get_version_fn.sh | 6 +++--- mk.sh | 21 +++++++++++++-------- tests/run_test_fn.sh | 6 +++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/ShellScripts/common/get_version_fn.sh b/ShellScripts/common/get_version_fn.sh index 5db99861e..12e6db1cc 100755 --- a/ShellScripts/common/get_version_fn.sh +++ b/ShellScripts/common/get_version_fn.sh @@ -18,6 +18,9 @@ get_version() { local -n output_ver_gitrev=$3 local -n output_ver_githash=$4 + output_ver_gitrev=$(git rev-list --count HEAD) + output_ver_githash=$(git rev-parse --short=7 HEAD) + if [[ -n "$5" ]]; then # VER_FULL already populated return 0 fi @@ -47,7 +50,4 @@ get_version() { output_ver_full="${ver_semver}+dirty.${ver_uncommitted}" output_ver_nsis="$ver_maj.$ver_min.$ver_rev.$ver_uncommitted" fi - - output_ver_gitrev=$(git rev-list --count HEAD) - output_ver_githash=$(git rev-parse --short=7 HEAD) } \ No newline at end of file diff --git a/mk.sh b/mk.sh index b8fd481e4..b6b24d3ef 100755 --- a/mk.sh +++ b/mk.sh @@ -28,6 +28,11 @@ CLEAN_BUILD=false SETUP_FLAGS=() # Array to cleanly store additional meson setup arguments COMPILE_FLAGS=() # Array to cleanly store additional meson compile arguments INSTALL_FLAGS=() # Array to cleanly store additional meson install arguments +if [[ -v MINGW_PREFIX ]]; then + meson() { # Windows path override + PATH="$MINGW_PREFIX/bin:$PATH" command meson "$@" + } +fi meson_setup() { local build_dir="build/meson_$2" @@ -144,20 +149,20 @@ execute_target() { # Target Execution Logic meson_install "debug" ;; test-deployment) - execute_target "build-deployment" - source tests/run_test_fn.sh && run_test + echo "❌ Cannot test deployment as not set up for debug console!" >&2 + exit 1 ;; test-test) execute_target "build-test" - source tests/run_test_fn.sh && run_test + source tests/run_test_fn.sh && run_test "test" ;; test-dev) execute_target "build-dev" - source tests/run_test_fn.sh && run_test + source tests/run_test_fn.sh && run_test "dev" ;; test-debug) execute_target "build-debug" - source tests/run_test_fn.sh && run_test + source tests/run_test_fn.sh && run_test "debug" ;; clean) echo "--> Cleaning all build artifacts..." @@ -198,7 +203,7 @@ execute_target() { # Target Execution Logic show_help ;; *) - echo "Error: Unknown target '$1'" >&2 + echo "❌ Unknown target '$1'" >&2 show_help exit 1 ;; @@ -244,13 +249,13 @@ while [[ $# -gt 0 ]]; do # Flexible Argument Parser exit 0 ;; -*) - echo "Error: Unknown option '$1'" >&2 + echo "❌ Unknown option '$1'" >&2 show_help exit 1 ;; *) if [[ -n "$TARGET" ]]; then - echo "Error: Multiple targets specified ('$TARGET' and '$1'). Only one target allowed." >&2 + echo "❌ Multiple targets specified ('$TARGET' and '$1'). Only one target allowed." >&2 exit 1 fi TARGET="$1" diff --git a/tests/run_test_fn.sh b/tests/run_test_fn.sh index 1da802206..5061c75e5 100755 --- a/tests/run_test_fn.sh +++ b/tests/run_test_fn.sh @@ -22,10 +22,10 @@ run_test() { local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" - local BUILD_TYPE="${1:-snapshot}" + local BUILD_TYPE="${1:-dev}" local TARGET_DIR=$(readlink -f "../build/meson_${BUILD_TYPE}/oolite.app") - if [[ -n "$MSYSTEM" ]]; then - local MESA_DLL="${MSYSTEM_PREFIX}/bin/opengl32.dll" + if [[ -v MINGW_PREFIX ]]; then + local MESA_DLL="${MINGW_PREFIX}/bin/opengl32.dll" if [[ -f "$MESA_DLL" ]]; then echo "📦 Copying $MSYSTEM Mesa driver at $MESA_DLL" cp "$MESA_DLL" "$TARGET_DIR/" From 0f975f31212cb8ac392074c51e9c268c01fede2a Mon Sep 17 00:00:00 2001 From: mcarans Date: Sat, 27 Jun 2026 20:14:10 +1200 Subject: [PATCH 05/23] Try to install gitversion for flatpak build --- .github/workflows/build-all.yaml | 9 +++++++++ ShellScripts/Linux/os_detection.sh | 5 ++++- installers/flatpak/create_flatpak_fn.sh | 11 ----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index 8ddd479e4..e87a91e56 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -78,6 +78,15 @@ jobs: fetch-depth: 0 - name: Build flatpak run: | + echo "Installing gitversion..." + source ShellScripts/common/download_github_fn.sh + OUTPUTDIR="." + download_latest_release gitversion_tgz "GitTools" "GitVersion" "linux-x64" "$OUTPUTDIR" + tar xfz ${gitversion_tgz} --directory "$OUTPUTDIR" + chmod +x "$OUTPUTDIR/gitversion" + mkdir -p /usr/local/bin + mv "$OUTPUTDIR/gitversion" /usr/local/bin/gitversion + rm -f ${gitversion_tgz} ./mk.sh pkg-flatpak --github-repository="$GITHUB_REPOSITORY" - name: Archive installer uses: actions/upload-artifact@v6 diff --git a/ShellScripts/Linux/os_detection.sh b/ShellScripts/Linux/os_detection.sh index 20e62ab61..bbffc97a6 100644 --- a/ShellScripts/Linux/os_detection.sh +++ b/ShellScripts/Linux/os_detection.sh @@ -5,7 +5,10 @@ if [ -f /etc/os-release ]; then . /etc/os-release - OS_FAMILY="${ID} ${ID_LIKE}" + if [[ -v ID_LIKE ]]; then + OS_FAMILY="${ID} ${ID_LIKE}" + else + OS_FAMILY="${ID}" else echo "❌ /etc/os-release not found - cannot detect OS!" >&2 exit 1 diff --git a/installers/flatpak/create_flatpak_fn.sh b/installers/flatpak/create_flatpak_fn.sh index 681077bb3..09c3517b3 100755 --- a/installers/flatpak/create_flatpak_fn.sh +++ b/installers/flatpak/create_flatpak_fn.sh @@ -10,17 +10,6 @@ create_flatpak() { cd ../.. mkdir -p build cd build - if ! command -v gitversion &> /dev/null; then - echo "Installing gitversion..." - source ../ShellScripts/common/download_github_fn.sh - local outputdir="." - download_latest_release gitversion_tgz "GitTools" "GitVersion" "linux-x64" "$outputdir" - tar xfz ${gitversion_tgz} --directory "$outputdir" - chmod +x "$outputdir/gitversion" - mkdir -p /usr/local/bin - mv "$outputdir/gitversion" /usr/local/bin/gitversion - rm -f ${gitversion_tgz} - fi cp ../installers/flatpak/space.oolite.Oolite.* ./ From abb006c8ea4e456ad49770cc1300d03c1896a650 Mon Sep 17 00:00:00 2001 From: mcarans Date: Sat, 27 Jun 2026 20:14:54 +1200 Subject: [PATCH 06/23] Try to install gitversion for flatpak build --- ShellScripts/Linux/os_detection.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ShellScripts/Linux/os_detection.sh b/ShellScripts/Linux/os_detection.sh index bbffc97a6..8dc20794e 100644 --- a/ShellScripts/Linux/os_detection.sh +++ b/ShellScripts/Linux/os_detection.sh @@ -9,6 +9,7 @@ if [ -f /etc/os-release ]; then OS_FAMILY="${ID} ${ID_LIKE}" else OS_FAMILY="${ID}" + fi else echo "❌ /etc/os-release not found - cannot detect OS!" >&2 exit 1 From efbc83ee4ce24cd4590f3e2715995ca71697bb33 Mon Sep 17 00:00:00 2001 From: mcarans Date: Sat, 27 Jun 2026 20:32:35 +1200 Subject: [PATCH 07/23] Try to fix Windows path --- installers/win32/create_nsis_fn.sh | 2 +- mk.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/installers/win32/create_nsis_fn.sh b/installers/win32/create_nsis_fn.sh index 3371e1b31..7415a4e43 100644 --- a/installers/win32/create_nsis_fn.sh +++ b/installers/win32/create_nsis_fn.sh @@ -71,7 +71,7 @@ create_nsis() { fi local nsis - if [[ -n "$MINGW_PREFIX" ]]; then + if [[ -v MINGW_PREFIX ]]; then nsis=$MINGW_PREFIX/bin/makensis else nsis=/nsis/makensis.exe diff --git a/mk.sh b/mk.sh index b6b24d3ef..697d9f8d9 100755 --- a/mk.sh +++ b/mk.sh @@ -30,7 +30,7 @@ COMPILE_FLAGS=() # Array to cleanly store additional meson compile arguments INSTALL_FLAGS=() # Array to cleanly store additional meson install arguments if [[ -v MINGW_PREFIX ]]; then meson() { # Windows path override - PATH="$MINGW_PREFIX/bin:$PATH" command meson "$@" + PATH="$MINGW_PREFIX/bin:/usr/bin:$PATH" command meson "$@" } fi @@ -41,6 +41,7 @@ meson_setup() { rm -rf "$build_dir" # If --clean was specified, delete the specific build directory first fi echo "--> Running Meson setup for: $2" + type meson # for debugging # Setup with --reconfigure, fallback to fresh setup. SETUP_FLAGS safely expands the array only if it's not empty meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" --reconfigure 2>/dev/null || \ meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" From 4a1bdfadef3399cc6831ce0c358d2ddb6f8b65b0 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 28 Jun 2026 09:35:07 +1200 Subject: [PATCH 08/23] Windows locally builds. Try fix CI --- .github/workflows/build-all.yaml | 2 ++ mk.sh | 7 +------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index e87a91e56..9b7da8e9e 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -114,8 +114,10 @@ jobs: - name: Set up MSYS2 uses: msys2/setup-msys2@v2 with: + msystem: UCRT64 update: true cache: false + path-type: minimal - name: Checkout Oolite uses: actions/checkout@v6 with: diff --git a/mk.sh b/mk.sh index 697d9f8d9..ff21cd55f 100755 --- a/mk.sh +++ b/mk.sh @@ -4,6 +4,7 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$SCRIPT_DIR" > /dev/null set -u -o pipefail # Strict expansions +which bash # --- Error Handling Trap --- cleanup_and_exit() { @@ -28,11 +29,6 @@ CLEAN_BUILD=false SETUP_FLAGS=() # Array to cleanly store additional meson setup arguments COMPILE_FLAGS=() # Array to cleanly store additional meson compile arguments INSTALL_FLAGS=() # Array to cleanly store additional meson install arguments -if [[ -v MINGW_PREFIX ]]; then - meson() { # Windows path override - PATH="$MINGW_PREFIX/bin:/usr/bin:$PATH" command meson "$@" - } -fi meson_setup() { local build_dir="build/meson_$2" @@ -41,7 +37,6 @@ meson_setup() { rm -rf "$build_dir" # If --clean was specified, delete the specific build directory first fi echo "--> Running Meson setup for: $2" - type meson # for debugging # Setup with --reconfigure, fallback to fresh setup. SETUP_FLAGS safely expands the array only if it's not empty meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" --reconfigure 2>/dev/null || \ meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" From 5ede762f2927c3c1f4bc80511ed220db2efd4dfe Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 28 Jun 2026 09:48:47 +1200 Subject: [PATCH 09/23] Force bash on Windows in CI --- .github/workflows/build-all.yaml | 1 - mk.sh | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index 9b7da8e9e..18f8e7948 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -117,7 +117,6 @@ jobs: msystem: UCRT64 update: true cache: false - path-type: minimal - name: Checkout Oolite uses: actions/checkout@v6 with: diff --git a/mk.sh b/mk.sh index ff21cd55f..a9065a9ed 100755 --- a/mk.sh +++ b/mk.sh @@ -4,7 +4,10 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$SCRIPT_DIR" > /dev/null set -u -o pipefail # Strict expansions -which bash + +if [[ -v MINGW_PREFIX ]]; then + export BASH="$(cygpath -w /usr/bin/bash.exe)" +fi # --- Error Handling Trap --- cleanup_and_exit() { From b31e571e612073c6def4b55563e9ecfc576d4a11 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 28 Jun 2026 09:55:38 +1200 Subject: [PATCH 10/23] Explicitly find bash in meson --- mk.sh | 4 ---- src/meson.build | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mk.sh b/mk.sh index a9065a9ed..483c40a28 100755 --- a/mk.sh +++ b/mk.sh @@ -5,10 +5,6 @@ pushd "$SCRIPT_DIR" > /dev/null set -u -o pipefail # Strict expansions -if [[ -v MINGW_PREFIX ]]; then - export BASH="$(cygpath -w /usr/bin/bash.exe)" -fi - # --- Error Handling Trap --- cleanup_and_exit() { local exit_code=$? diff --git a/src/meson.build b/src/meson.build index ad8b1c374..d3126ffc4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -35,6 +35,7 @@ oolite_bin = executable( install: false, ) +bash_prog = find_program('bash') prog_dir = meson.global_build_root() / appname + '.app' stamp_file = '.oolite_bundle.stamp' post_build_args = [ @@ -55,6 +56,7 @@ oolite_app_bundle = custom_target('post_build', input: oolite_bin, output: stamp_file, command: [ + bash_prog, post_build_script, post_build_args, ], From dd2fb55682133f52f680531df3234d70879e5c20 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 28 Jun 2026 09:57:05 +1200 Subject: [PATCH 11/23] Explicitly find bash in meson --- src/meson.build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/meson.build b/src/meson.build index d3126ffc4..7ba71670a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -51,7 +51,7 @@ post_build_args = [ gnustep_folder, stamp_file, ] -post_build_script = find_program('../ShellScripts/common/post_build.sh') +post_build_script = files('../ShellScripts/common/post_build.sh') oolite_app_bundle = custom_target('post_build', input: oolite_bin, output: stamp_file, @@ -70,5 +70,5 @@ install_args = [ host_os, get_option('deployment_release') ? 'yes' : 'no', ] -install_script = find_program('../ShellScripts/common/install.sh') -meson.add_install_script(install_script, install_args) +install_script = files('../ShellScripts/common/install.sh') +meson.add_install_script(bash_prog, install_script, install_args) From 92b318ac24874064265f0c09f962d1629ae1eff0 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 28 Jun 2026 10:18:16 +1200 Subject: [PATCH 12/23] update README --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b87409bdf..a684b37dd 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ default, but you can supply a further argument to specify an alternative like do Next run this in your Bash or MSYS2 prompt to build Oolite: ```bash -./mk.sh release-dev +./mk.sh build-dev ``` The completed build (executable and games files) can be found in the oolite.app directory. @@ -134,7 +134,7 @@ Subsequently, you can clean and build as follows: ```bash ./mk.sh clean -./mk.sh release-dev +./mk.sh build-dev ``` You can run a test that launches the game and takes a snapshot from your Bash or MSYS2 prompt as follows: @@ -143,8 +143,8 @@ You can run a test that launches the game and takes a snapshot from your Bash or ./mk.sh test ``` -release-dev keeps debug symbols in the binary. Other release targets remove those symbols from the binary although they -are made available in a separate symbols file. release-deployment is for a production release and release-test is for a +build-dev keeps debug symbols in the binary. Other build targets remove those symbols from the binary although they +are made available in a separate symbols file. build-deployment is for a production build and build-test is for a test release that supports the debug console which is used by expansion developers for debugging their OXPs. You can install: @@ -155,11 +155,11 @@ You can install: Other targets are install-deployment for a production install and install-test for a test install. -The underlying build system is Meson. You can run the deployment build directly using Meson build commands like this: +The underlying build system is Meson, but it is recommended to run via the mk.sh script which also allow you to pass +meson setup, compile and install flags. Type the following for help: ```bash -meson setup build/meson_deployment -Ddeployment_release=true -Ddebug=false -Dstrip_bin=true -Db_lto=true --native-file clang.ini --reconfigure -meson compile -C build/meson_deployment +./mk.sh help ``` ### Other Linux ./mk.sh Targets From 9dcaaf4da190449f165db02ec4c9bf665b54ab57 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 28 Jun 2026 10:20:46 +1200 Subject: [PATCH 13/23] update README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a684b37dd..0125f1be7 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ You can run a test that launches the game and takes a snapshot from your Bash or build-dev keeps debug symbols in the binary. Other build targets remove those symbols from the binary although they are made available in a separate symbols file. build-deployment is for a production build and build-test is for a -test release that supports the debug console which is used by expansion developers for debugging their OXPs. +test release that supports the debug console which is used by expansion developers for debugging their OXPs. You can install: @@ -162,6 +162,9 @@ meson setup, compile and install flags. Type the following for help: ./mk.sh help ``` +build-dev runs 2 targets which can be run independently: setup-dev which runs meson setup and compile-dev which runs +meson compile. + ### Other Linux ./mk.sh Targets This target builds an AppImage for development which can be found in the `build` fodler: From ca72ee64ccef90f37c79e5eb0413a9043e8f4dfc Mon Sep 17 00:00:00 2001 From: mcarans Date: Mon, 29 Jun 2026 07:03:06 +1200 Subject: [PATCH 14/23] Fix README.md Add missing help descriptions --- README.md | 2 +- mk.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0125f1be7..004930571 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ Next run this in your Bash or MSYS2 prompt to build Oolite: ./mk.sh build-dev ``` -The completed build (executable and games files) can be found in the oolite.app directory. +The completed build (executable and games files) can be found in the build/meson_dev/oolite.app directory. Subsequently, you can clean and build as follows: diff --git a/mk.sh b/mk.sh index 483c40a28..35d4668f0 100755 --- a/mk.sh +++ b/mk.sh @@ -57,6 +57,8 @@ show_help() { # Script Help Menu echo "Options:" echo -e " \033[36m--clean\033[0m Delete target build directory before compiling" echo -e " \033[36m--setup-flags=\"...\"\033[0m Pass additional arguments directly to 'meson setup'" + echo -e " \033[36m--compile-flags=\"...\"\033[0m Pass additional arguments directly to 'meson compile'" + echo -e " \033[36m--install-flags=\"...\"\033[0m Pass additional arguments directly to 'meson install'" echo -e " \033[36m--native-file=\"...\"\033[0m Specify native file (defaults to clang.ini)" echo -e " \033[36m--ver-full=\"...\"\033[0m Specify full version string" echo -e " \033[36m--github-repository=\"...\"\033[0m Specify target GitHub repository" From decdf5e98cdf33b0d0540b79f10c864acb1fe57f Mon Sep 17 00:00:00 2001 From: mcarans Date: Mon, 29 Jun 2026 16:36:29 +1200 Subject: [PATCH 15/23] Make help columns line up perfectly --- mk.sh | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/mk.sh b/mk.sh index 35d4668f0..e66a6ea8a 100755 --- a/mk.sh +++ b/mk.sh @@ -55,40 +55,40 @@ show_help() { # Script Help Menu echo "Usage: $0 [options] " echo "" echo "Options:" - echo -e " \033[36m--clean\033[0m Delete target build directory before compiling" + echo -e " \033[36m--clean\033[0m Delete target build directory before compiling" echo -e " \033[36m--setup-flags=\"...\"\033[0m Pass additional arguments directly to 'meson setup'" - echo -e " \033[36m--compile-flags=\"...\"\033[0m Pass additional arguments directly to 'meson compile'" - echo -e " \033[36m--install-flags=\"...\"\033[0m Pass additional arguments directly to 'meson install'" + echo -e " \033[36m--compile-flags=\"...\"\033[0m Pass additional arguments directly to 'meson compile'" + echo -e " \033[36m--install-flags=\"...\"\033[0m Pass additional arguments directly to 'meson install'" echo -e " \033[36m--native-file=\"...\"\033[0m Specify native file (defaults to clang.ini)" echo -e " \033[36m--ver-full=\"...\"\033[0m Specify full version string" echo -e " \033[36m--github-repository=\"...\"\033[0m Specify target GitHub repository" echo "" echo "Targets:" - echo -e " \033[36msetup-deployment\033[0m Setup a deployment release executable" - echo -e " \033[36msetup-test\033[0m Setup a test release executable" - echo -e " \033[36msetup-dev\033[0m Setup a dev release executable" - echo -e " \033[36msetup-debug\033[0m Setup a debug executable" - echo -e " \033[36mcompile-deployment\033[0m Compile a deployment release executable" - echo -e " \033[36mcompile-test\033[0m Compile a test release executable" - echo -e " \033[36mcompile-dev\033[0m Compile a dev release executable" - echo -e " \033[36mcompile-debug\033[0m Compile a debug executable" - echo -e " \033[36mbuild-deployment\033[0m Setup and compile a deployment release executable" - echo -e " \033[36mbuild-test\033[0m Setup and compile a test release executable" - echo -e " \033[36mbuild-dev\033[0m Setup and compile a dev release executable" - echo -e " \033[36mbuild-debug\033[0m Setup and compile a debug executable" - echo -e " \033[36minstall-deployment\033[0m Install the deployment release installation" - echo -e " \033[36minstall-test\033[0m Install the test release installation" - echo -e " \033[36minstall-dev\033[0m Install the dev release installation" - echo -e " \033[36minstall-debug\033[0m Install the debug installation" - echo -e " \033[36mtest\033[0m Run test suite (depends on build-dev)" - echo -e " \033[36mclean\033[0m Remove all generated build artifacts" - echo -e " \033[36mpkg-flatpak\033[0m Package a Flatpak application" - echo -e " \033[36mpkg-appimage-deployment\033[0m Package a Linux deployment release AppImage" - echo -e " \033[36mpkg-appimage-test\033[0m Package a Linux test release AppImage" - echo -e " \033[36mpkg-appimage-dev\033[0m Package a Linux dev release AppImage" - echo -e " \033[36mpkg-win-deployment\033[0m Package a Windows NSIS deployment release installer" - echo -e " \033[36mpkg-win-test\033[0m Package a Windows NSIS test release installer" - echo -e " \033[36mpkg-win-dev\033[0m Package a Windows NSIS dev release installer" + echo -e " \033[36msetup-deployment\033[0m Setup a deployment release executable" + echo -e " \033[36msetup-test\033[0m Setup a test release executable" + echo -e " \033[36msetup-dev\033[0m Setup a dev release executable" + echo -e " \033[36msetup-debug\033[0m Setup a debug executable" + echo -e " \033[36mcompile-deployment\033[0m Compile a deployment release executable" + echo -e " \033[36mcompile-test\033[0m Compile a test release executable" + echo -e " \033[36mcompile-dev\033[0m Compile a dev release executable" + echo -e " \033[36mcompile-debug\033[0m Compile a debug executable" + echo -e " \033[36mbuild-deployment\033[0m Setup and compile a deployment release executable" + echo -e " \033[36mbuild-test\033[0m Setup and compile a test release executable" + echo -e " \033[36mbuild-dev\033[0m Setup and compile a dev release executable" + echo -e " \033[36mbuild-debug\033[0m Setup and compile a debug executable" + echo -e " \033[36minstall-deployment\033[0m Install the deployment release installation" + echo -e " \033[36minstall-test\033[0m Install the test release installation" + echo -e " \033[36minstall-dev\033[0m Install the dev release installation" + echo -e " \033[36minstall-debug\033[0m Install the debug installation" + echo -e " \033[36mtest\033[0m Run test suite (depends on build-dev)" + echo -e " \033[36mclean\033[0m Remove all generated build artifacts" + echo -e " \033[36mpkg-flatpak\033[0m Package a Flatpak application" + echo -e " \033[36mpkg-appimage-deployment\033[0m Package a Linux deployment release AppImage" + echo -e " \033[36mpkg-appimage-test\033[0m Package a Linux test release AppImage" + echo -e " \033[36mpkg-appimage-dev\033[0m Package a Linux dev release AppImage" + echo -e " \033[36mpkg-win-deployment\033[0m Package a Windows NSIS deployment release installer" + echo -e " \033[36mpkg-win-test\033[0m Package a Windows NSIS test release installer" + echo -e " \033[36mpkg-win-dev\033[0m Package a Windows NSIS dev release installer" } execute_target() { # Target Execution Logic From ebfc664c75024f95ec5b9b831a88186b0390a1ca Mon Sep 17 00:00:00 2001 From: mcarans Date: Mon, 29 Jun 2026 16:37:39 +1200 Subject: [PATCH 16/23] Fix README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 004930571..62a3dd511 100644 --- a/README.md +++ b/README.md @@ -133,8 +133,7 @@ The completed build (executable and games files) can be found in the build/meson Subsequently, you can clean and build as follows: ```bash -./mk.sh clean -./mk.sh build-dev +./mk.sh build-dev --clean ``` You can run a test that launches the game and takes a snapshot from your Bash or MSYS2 prompt as follows: From 05ebaeb0b32f34f35da5f53941692f94b693b94e Mon Sep 17 00:00:00 2001 From: mcarans Date: Mon, 29 Jun 2026 16:44:03 +1200 Subject: [PATCH 17/23] Fix install_deps.sh --- ShellScripts/Windows/install_deps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ShellScripts/Windows/install_deps.sh b/ShellScripts/Windows/install_deps.sh index e0424de02..709b4b715 100755 --- a/ShellScripts/Windows/install_deps.sh +++ b/ShellScripts/Windows/install_deps.sh @@ -58,6 +58,7 @@ run_script() { pacboy -S mesa --noconfirm pacboy -S sdl3 --noconfirm + mkdir -p ../../build/packages cd ../../build # install gitversion local outputdir="." @@ -67,7 +68,6 @@ run_script() { mv "$outputdir/gitversion.exe" "$MINGW_PREFIX/bin/gitversion.exe" rm -f ${gitversion_zip} - mkdir -p packages cd packages curl -s "$oolite_deps_url" | \ grep -oP '"browser_download_url": "\K[^"]+' | \ From beec7c57a11120f3ac1c183fda0ee7c3bfb292a7 Mon Sep 17 00:00:00 2001 From: mcarans Date: Thu, 2 Jul 2026 14:33:51 +1200 Subject: [PATCH 18/23] Make an install Gitversion function for Linux to avoid copy paste coding --- .github/workflows/build-all.yaml | 9 ++------ ShellScripts/Linux/install_gitversion_fn.sh | 22 +++++++++++++++++++ ShellScripts/Linux/install_packages_root.sh | 12 +++------- ShellScripts/Windows/install_deps.sh | 4 ++-- ...ub_fn.sh => download_github_release_fn.sh} | 2 +- 5 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 ShellScripts/Linux/install_gitversion_fn.sh rename ShellScripts/common/{download_github_fn.sh => download_github_release_fn.sh} (98%) diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index 18f8e7948..8b7f018ec 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -79,14 +79,9 @@ jobs: - name: Build flatpak run: | echo "Installing gitversion..." - source ShellScripts/common/download_github_fn.sh - OUTPUTDIR="." - download_latest_release gitversion_tgz "GitTools" "GitVersion" "linux-x64" "$OUTPUTDIR" - tar xfz ${gitversion_tgz} --directory "$OUTPUTDIR" - chmod +x "$OUTPUTDIR/gitversion" + source ShellScripts/Linux/install_gitversion_fn.sh mkdir -p /usr/local/bin - mv "$OUTPUTDIR/gitversion" /usr/local/bin/gitversion - rm -f ${gitversion_tgz} + install_gitversion "." ./mk.sh pkg-flatpak --github-repository="$GITHUB_REPOSITORY" - name: Archive installer uses: actions/upload-artifact@v6 diff --git a/ShellScripts/Linux/install_gitversion_fn.sh b/ShellScripts/Linux/install_gitversion_fn.sh new file mode 100644 index 000000000..cc4deffe4 --- /dev/null +++ b/ShellScripts/Linux/install_gitversion_fn.sh @@ -0,0 +1,22 @@ +install_gitversion() { + local outputdir="$1" + + # If current user ID is NOT 0 (root) + if [[ $EUID -ne 0 ]]; then + echo "This script requires root to install dependencies. Rerun and escalate privileges (eg. sudo ...)" + return 1 + fi + + local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) + pushd "$script_dir" + + source ../common/download_github_release_fn.sh + + download_github_release gitversion_tgz "GitTools" "GitVersion" "linux-x64" "$outputdir" + tar xfz ${gitversion_tgz} --directory "$outputdir" + chmod +x "$outputdir/gitversion" + mv "$outputdir/gitversion" /usr/local/bin/gitversion + rm -f ${gitversion_tgz} + + popd +} \ No newline at end of file diff --git a/ShellScripts/Linux/install_packages_root.sh b/ShellScripts/Linux/install_packages_root.sh index 5d3672c79..ddd9a31a5 100755 --- a/ShellScripts/Linux/install_packages_root.sh +++ b/ShellScripts/Linux/install_packages_root.sh @@ -14,9 +14,8 @@ run_script() { local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" - source ../common/download_github_fn.sh - - source ./install_package_fn.sh + source install_gitversion_fn.sh + source install_package_fn.sh if ! install_package base-devel; then return 1 @@ -101,12 +100,7 @@ run_script() { # install gitversion local outputdir="../../build" mkdir -p "$outputdir" - download_latest_release gitversion_tgz "GitTools" "GitVersion" "linux-x64" "$outputdir" - tar xfz ${gitversion_tgz} --directory "$outputdir" - chmod +x "$outputdir/gitversion" - mv "$outputdir/gitversion" /usr/local/bin/gitversion - rm -f ${gitversion_tgz} - + install_gitversion "$outputdir" popd } diff --git a/ShellScripts/Windows/install_deps.sh b/ShellScripts/Windows/install_deps.sh index 709b4b715..0a2ecd1c2 100755 --- a/ShellScripts/Windows/install_deps.sh +++ b/ShellScripts/Windows/install_deps.sh @@ -35,7 +35,7 @@ run_script() { local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" - source ../common/download_github_fn.sh + source ../common/download_github_release_fn.sh local oolite_deps_url="https://api.github.com/repos/OoliteProject/oolite_windeps_build/releases/latest" @@ -62,7 +62,7 @@ run_script() { cd ../../build # install gitversion local outputdir="." - download_latest_release gitversion_zip "GitTools" "GitVersion" "win-x64" "$outputdir" + download_github_release gitversion_zip "GitTools" "GitVersion" "win-x64" "$outputdir" unzip -o ${gitversion_zip} -d "$outputdir" chmod +x "$outputdir/gitversion.exe" mv "$outputdir/gitversion.exe" "$MINGW_PREFIX/bin/gitversion.exe" diff --git a/ShellScripts/common/download_github_fn.sh b/ShellScripts/common/download_github_release_fn.sh similarity index 98% rename from ShellScripts/common/download_github_fn.sh rename to ShellScripts/common/download_github_release_fn.sh index 6b0b95ecd..74ed92a60 100755 --- a/ShellScripts/common/download_github_fn.sh +++ b/ShellScripts/common/download_github_release_fn.sh @@ -1,6 +1,6 @@ #!/bin/bash -download_latest_release() { +download_github_release() { local -n downloaded_file="$1" local owner="$2" local repository="$3" From 59e3b02d9aaf734a50f4f8bd4625e2a85a9a62b5 Mon Sep 17 00:00:00 2001 From: mcarans Date: Fri, 3 Jul 2026 10:06:47 +1200 Subject: [PATCH 19/23] Rename function meson_compile Ensure install depends on build --- mk.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mk.sh b/mk.sh index e66a6ea8a..8fc1395ed 100755 --- a/mk.sh +++ b/mk.sh @@ -41,7 +41,7 @@ meson_setup() { meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" } -meson_build() { +meson_compile() { echo "--> Running Meson build for: $1" meson compile -C "build/meson_$1" ${COMPILE_FLAGS[@]+"${COMPILE_FLAGS[@]}"} } @@ -106,16 +106,16 @@ execute_target() { # Target Execution Logic meson_setup "-Ddebug=true -Dstrip_bin=false" "debug" ;; compile-deployment) - meson_build "deployment" + meson_compile "deployment" ;; compile-test) - meson_build "test" + meson_compile "test" ;; compile-dev) - meson_build "dev" + meson_compile "dev" ;; compile-debug) - meson_build "debug" + meson_compile "debug" ;; build-deployment) execute_target "setup-deployment" @@ -134,15 +134,19 @@ execute_target() { # Target Execution Logic execute_target "compile-debug" ;; install-deployment) + execute_target "build-deployment" meson_install "deployment" ;; install-test) + execute_target "build-test" meson_install "test" ;; install-dev) + execute_target "build-dev" meson_install "dev" ;; install-debug) + execute_target "build-debug" meson_install "debug" ;; test-deployment) From b7bff484222782915a60c6a7d6ac5c034aa522a3 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 11 Jul 2026 17:08:35 +1200 Subject: [PATCH 20/23] Mk script2 (#11) * Add missing Schemata (#691) * appimage working * Remove --clean option as there is a clean target * Flatpak working locally * Fix workflows * Fix Windows * Output meson log on failure * Output parent process Bash parent * Try different way of getting parent process * Try different way of getting parent process 2 * echo $(ps -p $PPID) * echo $(ps -W -p $PPID) * echo $(ps -W -p $(ps -p $PPID -o winpid= | tr -d ' ')) * print lots of debug * print lots of debug * print lots of debug * print lots of debug * print lots of debug * print lots of debug * gwmi debug * gwmi debug 2 * gwmi debug 3 * Fix meson logging * Fix latest clang breaks Windows build due to conflict with ceil function used by SDL3 and Obj-C (#694) * Targeted SDL3 includes * Fix GitHub rate limiting curl * Fix meson folder * ver quad * Maybe we can do this without realpath * Maybe we can do this without realpath * Fix Windows * Wrong path * ver_githash * better flag handling * Echo ver quad * Version quad * Update meson.build to include version variables * Refactor post_build.sh to update version parameters * Rename version variables in generate_manifest function * Remove version_quad echo from manifest script Removed echo statement for version_quad in manifest generation. * Remove echo for ver_quad in create_nsis_fn.sh Remove echo statement for ver_quad variable. --- .github/workflows/build-all.yaml | 45 +- .github/workflows/test_builds.yaml | 82 ++-- {Schemata => Resources/Schemata}/README.txt | 0 .../Schemata}/demoshipsSchema.plist | 0 .../Schemata}/hudSchema.plist | 0 .../Schemata}/plistschema.plist | 0 .../Schemata}/shipdataEntrySchema.plist | 0 .../Schemata}/shipyardSchema.plist | 0 ShellScripts/Linux/build_gnustep.sh | 21 +- ShellScripts/Linux/install_freedesktop_fn.sh | 64 --- ShellScripts/Linux/install_gitversion_fn.sh | 1 + ShellScripts/Linux/install_mozilla_js.sh | 13 +- ShellScripts/Windows/install_deps.sh | 1 + .../common/download_github_release_fn.sh | 4 +- ShellScripts/common/generate_manifest_fn.sh | 11 +- ShellScripts/common/get_build_date_fn.sh | 41 +- ShellScripts/common/get_gitremote_fn.sh | 8 +- ShellScripts/common/get_version.sh | 127 ++++++ ShellScripts/common/get_version_fn.sh | 53 --- ShellScripts/common/install.sh | 7 +- ShellScripts/common/parse_manifest_fn.sh | 25 ++ ShellScripts/common/post_build.sh | 12 +- .../FreeDesktop}/GNUstep.conf.template | 0 .../FreeDesktop/install_freedesktop_fn.sh | 42 ++ installers/appimage/create_appimage_fn.sh | 22 +- installers/flatpak/create_flatpak_fn.sh | 104 +++-- installers/flatpak/flatpak_postbuild_fn.sh | 13 +- installers/flatpak/space.oolite.Oolite.yaml | 4 +- installers/win32/OOlite.nsi | 16 +- installers/win32/create_nsis_fn.sh | 40 +- meson.build | 25 +- meson.options | 18 - mk.sh | 385 ++++++++++-------- src/Core/GameController.m | 1 + src/Core/NSFileManagerOOExtensions.m | 2 +- src/Core/OOJoystickManager.h | 2 +- src/Core/OOLogOutputHandler.m | 2 +- src/SDL/MyOpenGLView.h | 2 +- src/SDL/MyOpenGLView.m | 1 + src/SDL/OOSDLJoystickManager.h | 2 +- src/SDL/main.m | 2 +- src/meson.build | 6 +- 42 files changed, 707 insertions(+), 497 deletions(-) rename {Schemata => Resources/Schemata}/README.txt (100%) rename {Schemata => Resources/Schemata}/demoshipsSchema.plist (100%) rename {Schemata => Resources/Schemata}/hudSchema.plist (100%) rename {Schemata => Resources/Schemata}/plistschema.plist (100%) rename {Schemata => Resources/Schemata}/shipdataEntrySchema.plist (100%) rename {Schemata => Resources/Schemata}/shipyardSchema.plist (100%) delete mode 100644 ShellScripts/Linux/install_freedesktop_fn.sh create mode 100755 ShellScripts/common/get_version.sh delete mode 100755 ShellScripts/common/get_version_fn.sh create mode 100644 ShellScripts/common/parse_manifest_fn.sh rename {ShellScripts/Linux => installers/FreeDesktop}/GNUstep.conf.template (100%) create mode 100644 installers/FreeDesktop/install_freedesktop_fn.sh diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index 8b7f018ec..6c5748a29 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -19,7 +19,7 @@ jobs: --security-opt apparmor:unconfined strategy: matrix: - flavour: [pkg-appimage-deployment, pkg-appimage-test, pkg-appimage-dev] + flavour: [deployment, test, dev] steps: ## This is for debugging only and helps developing the workflow. # - name: Environment Variables @@ -30,11 +30,17 @@ jobs: run: | pacman -Syu --noconfirm pacman -S --noconfirm --needed git - - name: Pre-setup ownership + - name: Pre-setup ownership & curl token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # This must run before the checkout action if the action tries to do git commands mkdir -p "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE" + cat << EOF >> ~/.curlrc + header = "Authorization: Bearer $GITHUB_TOKEN" + header = "Accept: application/vnd.github+json" + EOF - name: Checkout Oolite uses: actions/checkout@v6 with: @@ -52,7 +58,10 @@ jobs: ldconfig - name: Build Oolite run: | - ./mk.sh ${{matrix.flavour}} --github-repository="$GITHUB_REPOSITORY" + ./mk.sh build ${{matrix.flavour}} --github-repository="$GITHUB_REPOSITORY" + - name: Package Oolite + run: | + ./mk.sh pkg-appimage ${{matrix.flavour}} - name: Archive installer uses: actions/upload-artifact@v6 with: @@ -67,11 +76,17 @@ jobs: image: ghcr.io/flathub-infra/flatpak-github-actions:freedesktop-25.08 options: --privileged steps: - - name: Pre-setup ownership + - name: Pre-setup ownership & curl token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # This must run before the checkout action if the action tries to do git commands mkdir -p "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE" + cat << EOF >> ~/.curlrc + header = "Authorization: Bearer $GITHUB_TOKEN" + header = "Accept: application/vnd.github+json" + EOF - name: Checkout Oolite uses: actions/checkout@v6 with: @@ -82,7 +97,7 @@ jobs: source ShellScripts/Linux/install_gitversion_fn.sh mkdir -p /usr/local/bin install_gitversion "." - ./mk.sh pkg-flatpak --github-repository="$GITHUB_REPOSITORY" + ./mk.sh pkg-flatpak deployment --github-repository="$GITHUB_REPOSITORY" - name: Archive installer uses: actions/upload-artifact@v6 with: @@ -95,14 +110,14 @@ jobs: runs-on: windows-latest strategy: matrix: - flavour: [pkg-win-deployment, pkg-win-test, pkg-win-dev] + flavour: [deployment, test, dev] steps: ## This is for debugging only and helps developing the workflow. # - name: Environment Variables # run: | # Get-ChildItem Env: | Sort Name - - name: Configure Git Line Endings + - name: Git line endings & curl token run: | git config --global core.autocrlf false git config --global core.eol lf @@ -120,14 +135,28 @@ jobs: shell: msys2 {0} env: msystem: UCRT64 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + cat << EOF > ~/.curlrc + header = "Authorization: Bearer $GITHUB_TOKEN" + header = "Accept: application/vnd.github+json" + EOF + cp ~/.curlrc /c/Users/runneradmin/.curlrc 2>/dev/null || true ShellScripts/Windows/install_deps.sh clang - name: Build Oolite shell: msys2 {0} env: msystem: UCRT64 + PYTHONUTF8: "1" + run: | + ./mk.sh build ${{matrix.flavour}} --github-repository="$GITHUB_REPOSITORY" + - name: Package Oolite + shell: msys2 {0} + env: + msystem: UCRT64 + PYTHONUTF8: "1" run: | - ./mk.sh ${{matrix.flavour}} --github-repository="$GITHUB_REPOSITORY" + ./mk.sh pkg-win ${{matrix.flavour}} - name: Archive installer uses: actions/upload-artifact@v6 with: diff --git a/.github/workflows/test_builds.yaml b/.github/workflows/test_builds.yaml index 294654d68..e3018d3b6 100644 --- a/.github/workflows/test_builds.yaml +++ b/.github/workflows/test_builds.yaml @@ -22,11 +22,17 @@ jobs: run: | apt update apt install -y git curl ca-certificates - - name: Pre-setup ownership + - name: Pre-setup ownership & curl token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # This must run before the checkout action if the action tries to do git commands mkdir -p "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE" + cat << EOF >> ~/.curlrc + header = "Authorization: Bearer $GITHUB_TOKEN" + header = "Accept: application/vnd.github+json" + EOF - uses: actions/checkout@v6 with: fetch-depth: 0 @@ -41,17 +47,16 @@ jobs: - name: Install Mozilla static library run: | ShellScripts/Linux/install_mozilla_js.sh system - - name: Build and test Oolite - if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name + - name: Build Oolite run: | - ./mk.sh test-dev - - name: Build Oolite (no test) - if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + ./mk.sh build dev + - name: Test Oolite + if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ./mk.sh build-dev + ./mk.sh test dev - name: Build AppImage run: | - ./mk.sh pkg-appimage-dev + ./mk.sh pkg-appimage dev fedora: runs-on: ubuntu-latest @@ -66,11 +71,17 @@ jobs: run: | dnf -y update dnf -y install git - - name: Pre-setup ownership + - name: Pre-setup ownership & curl token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # This must run before the checkout action if the action tries to do git commands mkdir -p "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE" + cat << EOF >> ~/.curlrc + header = "Authorization: Bearer $GITHUB_TOKEN" + header = "Accept: application/vnd.github+json" + EOF - uses: actions/checkout@v6 with: fetch-depth: 0 @@ -85,17 +96,16 @@ jobs: ShellScripts/Linux/install_mozilla_js.sh system echo "/usr/local/lib64" | tee -a /etc/ld.so.conf ldconfig - - name: Build and test Oolite - if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name + - name: Build Oolite run: | - ./mk.sh test-dev - - name: Build Oolite (no test) - if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + ./mk.sh build dev + - name: Test Oolite + if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ./mk.sh build-dev + ./mk.sh test dev - name: Build AppImage run: | - ./mk.sh pkg-appimage-dev + ./mk.sh pkg-appimage dev arch: runs-on: ubuntu-latest @@ -110,11 +120,17 @@ jobs: run: | pacman -Syu --noconfirm pacman -S --noconfirm --needed git - - name: Pre-setup ownership + - name: Pre-setup ownership & curl token + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # This must run before the checkout action if the action tries to do git commands mkdir -p "$GITHUB_WORKSPACE" git config --global --add safe.directory "$GITHUB_WORKSPACE" + cat << EOF >> ~/.curlrc + header = "Authorization: Bearer $GITHUB_TOKEN" + header = "Accept: application/vnd.github+json" + EOF - uses: actions/checkout@v6 with: fetch-depth: 0 @@ -129,17 +145,16 @@ jobs: ShellScripts/Linux/install_mozilla_js.sh system echo "/usr/local/lib" | tee -a /etc/ld.so.conf ldconfig - - name: Build and test Oolite - if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name + - name: Build Oolite run: | - ./mk.sh test-dev - - name: Build Oolite (no test) - if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + ./mk.sh build dev + - name: Test Oolite + if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name run: | - ./mk.sh build-dev + ./mk.sh test dev - name: Build AppImage run: | - ./mk.sh pkg-appimage-dev + ./mk.sh pkg-appimage dev windows: runs-on: windows-latest @@ -165,21 +180,28 @@ jobs: shell: msys2 {0} env: msystem: UCRT64 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + cat << EOF > ~/.curlrc + header = "Authorization: Bearer $GITHUB_TOKEN" + header = "Accept: application/vnd.github+json" + EOF + cp ~/.curlrc /c/Users/runneradmin/.curlrc 2>/dev/null || true ShellScripts/Windows/install_deps.sh clang - - name: Build and test Oolite - if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name + - name: Build Oolite shell: msys2 {0} env: msystem: UCRT64 + PYTHONUTF8: "1" run: | - ./mk.sh test-dev + ./mk.sh build dev - - name: Build Oolite (no test) - if: github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name + - name: Test Oolite + if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name shell: msys2 {0} env: msystem: UCRT64 + PYTHONUTF8: "1" run: | - ./mk.sh build-dev + ./mk.sh test dev diff --git a/Schemata/README.txt b/Resources/Schemata/README.txt similarity index 100% rename from Schemata/README.txt rename to Resources/Schemata/README.txt diff --git a/Schemata/demoshipsSchema.plist b/Resources/Schemata/demoshipsSchema.plist similarity index 100% rename from Schemata/demoshipsSchema.plist rename to Resources/Schemata/demoshipsSchema.plist diff --git a/Schemata/hudSchema.plist b/Resources/Schemata/hudSchema.plist similarity index 100% rename from Schemata/hudSchema.plist rename to Resources/Schemata/hudSchema.plist diff --git a/Schemata/plistschema.plist b/Resources/Schemata/plistschema.plist similarity index 100% rename from Schemata/plistschema.plist rename to Resources/Schemata/plistschema.plist diff --git a/Schemata/shipdataEntrySchema.plist b/Resources/Schemata/shipdataEntrySchema.plist similarity index 100% rename from Schemata/shipdataEntrySchema.plist rename to Resources/Schemata/shipdataEntrySchema.plist diff --git a/Schemata/shipyardSchema.plist b/Resources/Schemata/shipyardSchema.plist similarity index 100% rename from Schemata/shipyardSchema.plist rename to Resources/Schemata/shipyardSchema.plist diff --git a/ShellScripts/Linux/build_gnustep.sh b/ShellScripts/Linux/build_gnustep.sh index d98b1457f..c8771cc41 100755 --- a/ShellScripts/Linux/build_gnustep.sh +++ b/ShellScripts/Linux/build_gnustep.sh @@ -1,6 +1,6 @@ #!/bin/bash # Parameter one: "system", "home", or "build" (defaults to home). -# Parameter two: Escalate command (defaults to sudo for 'system'). +# Parameter two: escalate command (defaults to sudo for 'system'). run_script() { local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) @@ -9,7 +9,8 @@ run_script() { echo "Building GNUStep libraries" source dep_location_fn.sh - dep_location LIB_SUBDIR TARGET ESCALATE "gnustep" $1 $2 + local lib_subdir target escalate + dep_location lib_subdir target escalate "gnustep" $1 $2 mkdir -p ../../build @@ -52,7 +53,7 @@ run_script() { rm -rf build mkdir build cd build - if ! cmake -DCMAKE_INSTALL_PREFIX="$TARGET" -DCMAKE_INSTALL_LIBDIR="$LIB_SUBDIR" -DTESTS=on -DCMAKE_BUILD_TYPE=Release -DGNUSTEP_INSTALL_TYPE=NONE -DEMBEDDED_BLOCKS_RUNTIME=ON -DOLDABI_COMPAT=OFF ../; then + if ! cmake -DCMAKE_INSTALL_PREFIX="$target" -DCMAKE_INSTALL_LIBDIR="$lib_subdir" -DTESTS=on -DCMAKE_BUILD_TYPE=Release -DGNUSTEP_INSTALL_TYPE=NONE -DEMBEDDED_BLOCKS_RUNTIME=ON -DOLDABI_COMPAT=OFF ../; then echo "❌ libobjc2 cmake configure failed!" >&2 return 1 fi @@ -61,29 +62,29 @@ run_script() { echo "❌ libobjc2 cmake build failed!" >&2 return 1 fi - $ESCALATE cmake --install . + $escalate cmake --install . cd ../.. cd tools-make make clean - local lib_dir="$TARGET/$LIB_SUBDIR" - export CPPFLAGS="-I$TARGET/include" + local lib_dir="$target/$lib_subdir" + export CPPFLAGS="-I$target/include" export LDFLAGS="-L$lib_dir" - if ! ./configure --prefix="$TARGET" --with-library-combo=ng-gnu-gnu --with-runtime-abi=gnustep-2.2 "--with-libdir=$LIB_SUBDIR"; then + if ! ./configure --prefix="$target" --with-library-combo=ng-gnu-gnu --with-runtime-abi=gnustep-2.2 "--with-libdir=$lib_subdir"; then echo "❌ tools-make configure failed!" >&2 return 1 fi make - $ESCALATE make install + $escalate make install cd .. cd libs-base make clean export LD_LIBRARY_PATH="$lib_dir:$LD_LIBRARY_PATH" - source "$TARGET/share/GNUstep/Makefiles/GNUstep.sh" + source "$target/share/GNUstep/Makefiles/GNUstep.sh" if ! ./configure; then echo "❌ libs-base configure failed!" >&2 return 1 @@ -92,7 +93,7 @@ run_script() { echo "❌ libs-base make failed!" >&2 return 1 fi - $ESCALATE make install + $escalate make install popd } diff --git a/ShellScripts/Linux/install_freedesktop_fn.sh b/ShellScripts/Linux/install_freedesktop_fn.sh deleted file mode 100644 index 25f47ebb5..000000000 --- a/ShellScripts/Linux/install_freedesktop_fn.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -x -# -# Installs the manifest and injects version number - -echo "I am install_freedesktop_fn.sh $@" -printenv | sort - -install_freedesktop() { - local build_folder="$1" # oolite.app directory path (source) - local ver_full="$2" # Oolite version - local app_date="$3" # Oolite build date - local app_folder="$4" # app folder (destination) - local symbol_folder="$5" # debug symbol folder - local metainfo_suffix="$6" # can be appdata or metainfo - - local err_msg="❌ Error: Failed to" - - local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) - pushd "$script_dir" - - echo "Installing metainfo to to $app_folder" - - local appbin="$app_folder/bin" - local appshr="$app_folder/share" - - # Install binaries and scripts - install -D "$build_folder/oolite" "$appbin/oolite" || { echo "$err_msg install oolite binary" >&2; return 1; } - if [[ -f "$build_folder/oolite.debug" ]]; then - install -D "$build_folder/oolite.debug" "$app_folder/$symbol_folder/oolite.debug" || { echo "$err_msg install oolite debug symbols" >&2; return 1; } - fi - install -D "$build_folder/run_oolite.sh" "$appbin/run_oolite.sh" || { echo "$err_msg install run_oolite.sh" >&2; return 1; } - - # Resources copy - local resourcesdir="$appshr/oolite/Resources" - mkdir -p "$resourcesdir" - cp -rf "$build_folder/Resources/." "$resourcesdir/" || { echo "$err_msg copy Resources folder" >&2; return 1; } - - # AddOns copy if folder exists in oolite.app - if [ -d "$build_folder/AddOns" ]; then - local addonsdir="$appshr/oolite/AddOns" - mkdir -p "$addonsdir" - cp -rf "$build_folder/AddOns/." "$addonsdir/" || { echo "$err_msg copy AddOns folder" >&2; return 1; } - fi - - rm -f "$resourcesdir/GNUstep.conf.orig" - install -D "GNUstep.conf.template" "$resourcesdir/GNUstep.conf.template" || { echo "$err_msg GNUstep template" >&2; return 1; } - - local app_metainfo="$appshr/metainfo/space.oolite.Oolite.$metainfo_suffix.xml" - install -D ../../installers/FreeDesktop/space.oolite.Oolite.metainfo.xml.template "$app_metainfo" || { echo "$err_msg metainfo template" >&2; return 1; } - - sed -i "s/@VER@/${ver_full}/g" "$app_metainfo" - sed -i "s/@DATE@/${app_date}/g" "$app_metainfo" - - echo =========================================== - echo Our manifest looks like this: - cat "$app_metainfo" - echo =========================================== - - # Desktop and Icon - install -D ../../installers/FreeDesktop/space.oolite.Oolite.desktop "$appshr/applications/space.oolite.Oolite.desktop" || { echo "$err_msg desktop file" >&2; return 1; } - install -D "$build_folder/Resources/Textures/oolite-logo1.png" "$appshr/icons/hicolor/256x256/apps/space.oolite.Oolite.png" || { echo "$err_msg icon file" >&2; return 1; } - - popd -} \ No newline at end of file diff --git a/ShellScripts/Linux/install_gitversion_fn.sh b/ShellScripts/Linux/install_gitversion_fn.sh index cc4deffe4..62d761cb2 100644 --- a/ShellScripts/Linux/install_gitversion_fn.sh +++ b/ShellScripts/Linux/install_gitversion_fn.sh @@ -12,6 +12,7 @@ install_gitversion() { source ../common/download_github_release_fn.sh + local gitversion_tgz download_github_release gitversion_tgz "GitTools" "GitVersion" "linux-x64" "$outputdir" tar xfz ${gitversion_tgz} --directory "$outputdir" chmod +x "$outputdir/gitversion" diff --git a/ShellScripts/Linux/install_mozilla_js.sh b/ShellScripts/Linux/install_mozilla_js.sh index be51a2dea..192e38a95 100755 --- a/ShellScripts/Linux/install_mozilla_js.sh +++ b/ShellScripts/Linux/install_mozilla_js.sh @@ -1,19 +1,20 @@ #!/bin/bash # Parameter one: "system", "home", or "build" (defaults to home). -# Parameter two: Escalate command (defaults to sudo for 'system'). +# Parameter two: escalate command (defaults to sudo for 'system'). run_script() { # Get the directory where the script is located local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) source "$script_dir/dep_location_fn.sh" - dep_location LIB_SUBDIR TARGET ESCALATE "mozilla_js" $1 $2 + local lib_subdir target escalate + dep_location lib_subdir target escalate "mozilla_js" $1 $2 # The URL to your specific GitHub release asset local release_url="https://github.com/OoliteProject/mozillajs-linux/releases/download/0.0.1/mozilla-js-static-lib.tar.gz" - echo "Installing Mozilla JS static library to $TARGET" - [[ -n "$ESCALATE" ]] && echo "Using escalation: $ESCALATE" + echo "Installing Mozilla JS static library to $target" + [[ -n "$escalate" ]] && echo "Using escalation: $escalate" # Download and extract # Curl downloads as current user, Tar extracts using escalation @@ -32,12 +33,12 @@ run_script() { fi # Move headers to include - if ! $ESCALATE cp -r "$temp_staging/include/"* "$TARGET/include/"; then + if ! $escalate cp -r "$temp_staging/include/"* "$target/include/"; then echo "❌ Mozilla JS library header install failed!" >&2 return 1 fi # Move libs from 'lib' in tarball to 'lib64' on system - if ! $ESCALATE cp -r "$temp_staging/lib/"* "$TARGET/$LIB_SUBDIR/"; then + if ! $escalate cp -r "$temp_staging/lib/"* "$target/$lib_subdir/"; then echo "❌ Mozilla JS library lib install failed!" >&2 return 1 fi diff --git a/ShellScripts/Windows/install_deps.sh b/ShellScripts/Windows/install_deps.sh index 0a2ecd1c2..f9cc4677b 100755 --- a/ShellScripts/Windows/install_deps.sh +++ b/ShellScripts/Windows/install_deps.sh @@ -61,6 +61,7 @@ run_script() { mkdir -p ../../build/packages cd ../../build # install gitversion + local gitversion_zip local outputdir="." download_github_release gitversion_zip "GitTools" "GitVersion" "win-x64" "$outputdir" unzip -o ${gitversion_zip} -d "$outputdir" diff --git a/ShellScripts/common/download_github_release_fn.sh b/ShellScripts/common/download_github_release_fn.sh index 74ed92a60..7abe8c69f 100755 --- a/ShellScripts/common/download_github_release_fn.sh +++ b/ShellScripts/common/download_github_release_fn.sh @@ -1,7 +1,7 @@ #!/bin/bash download_github_release() { - local -n downloaded_file="$1" + local -n _downloaded_file="$1" local owner="$2" local repository="$3" local filter="$4" @@ -39,5 +39,5 @@ download_github_release() { echo "Downloading latest release: ${filename}..." >&2 curl -L -O --output-dir "${outputdir}" "${download_url}" - downloaded_file="${outputdir}/${filename}" + _downloaded_file="${outputdir}/${filename}" } \ No newline at end of file diff --git a/ShellScripts/common/generate_manifest_fn.sh b/ShellScripts/common/generate_manifest_fn.sh index 10f6e878d..b6e5428ed 100755 --- a/ShellScripts/common/generate_manifest_fn.sh +++ b/ShellScripts/common/generate_manifest_fn.sh @@ -2,8 +2,11 @@ generate_manifest() { local output_file="$1" local deployment_release="$2" local ver_full="$3" - local $ver_githash="$4" + local ver_quad="$4" + local ver_githash="$5" + local build_time="$6" source ShellScripts/common/get_gitremote_fn.sh + local git_remote get_gitremote git_remote # Redirect the entire block output into the manifest_output file @@ -13,8 +16,10 @@ generate_manifest() { echo " identifier = \"org.oolite.oolite\";" echo " " echo " version = \"$ver_full\";" - echo " git_remote_url = \"$git_remote\";" + echo " version_quad = \"$ver_quad\";" echo " git_commit_hash = \"$ver_githash\";" + echo " build_time = \"$build_time\";" + echo " git_remote_url = \"$git_remote\";" if [[ "$deployment_release" == "yes" ]]; then echo " debug_functionality_support = no;" @@ -30,4 +35,4 @@ generate_manifest() { echo " information_url = \"https://oolite.space/\";" echo "}" } > "$output_file" -} \ No newline at end of file +} diff --git a/ShellScripts/common/get_build_date_fn.sh b/ShellScripts/common/get_build_date_fn.sh index a84169f9f..4413809d2 100755 --- a/ShellScripts/common/get_build_date_fn.sh +++ b/ShellScripts/common/get_build_date_fn.sh @@ -3,24 +3,37 @@ # Calculates the Oolite build date # +SUITE_PARENT=$(basename "${BASH_SOURCE[1]}") # Get the name of the script that is sourcing this file +ALLOWED_SCRIPT="get_version.sh" # Define the ONLY script allowed to source this +if [[ "$SUITE_PARENT" != "$ALLOWED_SCRIPT" ]]; then + echo "❌ This file can only be sourced by $ALLOWED_SCRIPT!" >&2 + unset SUITE_PARENT ALLOWED_SCRIPT + return 1 2>/dev/null || exit 1 +fi +unset SUITE_PARENT ALLOWED_SCRIPT + get_build_date() { - local -n output_cpp_date=$1 - local -n output_app_date=$2 - local -n output_buildtime=$3 - local -n output_builder=$4 - # $5 is GITHUB_REPOSITORY environment variable from GitHub Actions + local -n _cpp_date="$1" + local -n _app_date="$2" + local -n _buildtime="$3" + local -n _builder="$4" + local buildtime="$5" + - # Run timestamp exactly once - local getversion_timestamp=$(git log -1 --format=%ct) + if [[ -z "$buildtime" ]]; then + local getversion_timestamp=$(git log -1 --format=%ct) + _buildtime=$(date -u -d "@$getversion_timestamp" "+%Y.%m.%d %H:%M") + else + _buildtime="$buildtime" + fi - # Date conversions use UTC for consistency - output_cpp_date=$(date -u -d "@$getversion_timestamp" +"%b %e %Y") - output_app_date=$(date -u -d "@$getversion_timestamp" +"%Y-%m-%d") - output_buildtime=$(date -u -d "@$getversion_timestamp" "+%Y.%m.%d %H:%M") + local clean_date="${_buildtime//./-}" + _cpp_date=$(date -u -d "$clean_date" +"%b%e %Y") + _app_date=$(date -u -d "$clean_date" +"%Y-%m-%d") - if [[ "$5" == "OoliteProject/oolite" ]]; then - output_builder="OoliteProject" + if [[ "$GITHUB_REPOSITORY" == "OoliteProject/oolite" ]]; then + _builder="OoliteProject" else - output_builder="unknown" + _builder="unknown" fi } \ No newline at end of file diff --git a/ShellScripts/common/get_gitremote_fn.sh b/ShellScripts/common/get_gitremote_fn.sh index 932a7d8b5..0694be38f 100644 --- a/ShellScripts/common/get_gitremote_fn.sh +++ b/ShellScripts/common/get_gitremote_fn.sh @@ -1,6 +1,6 @@ get_gitremote() { # Accept a variable name as the first argument to use as a nameref return - local -n final_url=$1 + local -n _final_url=$1 local raw_url resolved_git_dir upstream_url @@ -21,12 +21,12 @@ get_gitremote() { # If we successfully found an upstream URL, use it. if [[ -n "$upstream_url" ]]; then - final_url="$upstream_url" + _final_url="$upstream_url" else - final_url="UNKNOWN" + _final_url="UNKNOWN" fi else # It's already a standard web URL (GitHub, GitLab, etc.) - final_url="$raw_url" + _final_url="$raw_url" fi } \ No newline at end of file diff --git a/ShellScripts/common/get_version.sh b/ShellScripts/common/get_version.sh new file mode 100755 index 000000000..f774abcfa --- /dev/null +++ b/ShellScripts/common/get_version.sh @@ -0,0 +1,127 @@ +#!/bin/bash +# +# Calculates the Oolite version number and build dates +# + + +if [[ -v MINGW_PREFIX ]]; then + WIN_PID=$(ps -p $$ | awk 'NR>1 {print $4}') + PARENT_PROCESS=$(powershell.exe -Command " + \$parentId = (gwmi Win32_Process -Filter 'ProcessId = $WIN_PID').ParentProcessId + if (\$parentId) { + Write-Output (gwmi Win32_Process -Filter \"ProcessId = \$parentId\").Name + } + " 2>/dev/null | tr -d '\r') + if [ "$PARENT_PROCESS" = "python.exe" ] && ps | grep -q "meson"; then + PARENT_PROCESS="meson" + fi +else + PARENT_PROCESS=$(ps -p $PPID -o comm= 2>/dev/null || true) +fi +if [[ "$PARENT_PROCESS" != "meson" ]] || [[ -z "$MESON_BUILD_ROOT" ]]; then + SUITE_PARENT=$(basename "${BASH_SOURCE[1]}") # Get the name of the script that is sourcing this file + ALLOWED_SCRIPT="create_flatpak_fn.sh" # Define the ONLY script allowed to source this + if [[ "$SUITE_PARENT" != "$ALLOWED_SCRIPT" ]]; then + echo "❌ Parent process is $PARENT_PROCESS, Bash parent is $SUITE_PARENT. This file can only be called by meson or sourced by $ALLOWED_SCRIPT!" >&2 + unset SUITE_PARENT ALLOWED_SCRIPT + return 1 2>/dev/null || exit 1 + fi + unset SUITE_PARENT ALLOWED_SCRIPT +fi + + +run_script() { + local build_dir="$1" # Input string arguments + + if [[ -z "$build_dir" ]]; then + echo "❌ build_dir argument is required!" >&2 + return 1 + fi + + source "ShellScripts/common/get_build_date_fn.sh" + local output_ver_githash=$(git rev-parse --short=7 HEAD) + local dirty_suffix="" + git diff --quiet || dirty_suffix="-dirty" + local lookup_hash="${output_ver_githash}${dirty_suffix}" + local output_ver_full="" + local output_buildtime="" + local version_file="$build_dir/.meson_version" + if [[ -z "${VER_FULL-}" ]]; then + if [[ -f "$version_file" ]]; then # Check if cache exists and has a matching hash context + local githash ver_full ver_quad ver_gitrev cpp_date app_date buildtime builder + source "$version_file" 2>/dev/null + if [[ "$ver_githash" == "$lookup_hash" ]]; then + echo "$ver_full" + return 0 + fi + fi + else + output_ver_full="$VER_FULL" + fi + + if [[ -z "$output_ver_full" ]]; then + local exact_tag="" # Check for an exact Git tag first on a clean tree + if [[ -z "$dirty_suffix" ]]; then + exact_tag=$(git describe --tags --exact-match HEAD 2>/dev/null) + fi + if [[ -n "$exact_tag" ]]; then + output_ver_full="$exact_tag" + else + if ! command -v gitversion &> /dev/null; then # exact tag didn't hit, use gitversion for ver_full + echo "❌ gitversion binary not found!" >&2 + exit 1 + fi + local gitversion_json=$(gitversion) # Run gitversion and get json output + local ver_semver=$(echo "$gitversion_json" | jq -r '.SemVer') + if [[ -z "$dirty_suffix" ]]; then + output_ver_full="$ver_semver" + else + local ver_uncommitted=$(echo "$gitversion_json" | jq -r '.UncommittedChanges') + output_ver_full="${ver_semver}+dirty.${ver_uncommitted}" + fi + fi + fi + + local clean_ver="${output_ver_full#v}" # Strip any leading 'v', prerelease tags (-alpha), or build metadata (+) + clean_ver="${clean_ver%%-*}" # Example: "v1.91.0-alpha.1+dirty.3" -> "1.91.0" + clean_ver="${clean_ver%%+*}" + local ver_maj=$(echo "$clean_ver" | cut -d. -f1) # Parse out Major, Minor, Patch using standard dot delimiters + local ver_min=$(echo "$clean_ver" | cut -d. -f2) + local ver_rev=$(echo "$clean_ver" | cut -d. -f3) + [[ -z "$ver_rev" ]] && ver_rev="0" + + if [[ -z "$dirty_suffix" ]]; then # Use git for other metrics for clean repository + local closest_tag=$(git describe --tags --abbrev=0 2>/dev/null) # Derive distance from closest Git tag + local ver_dist="0" + if [[ -n "$closest_tag" ]]; then + ver_dist=$(git rev-list --count "${closest_tag}..HEAD") + else + ver_dist=$(git rev-list --count HEAD) + fi + output_ver_quad="$ver_maj.$ver_min.$ver_rev.$ver_dist" + else + local ver_uncommitted=$(git status --porcelain 2>/dev/null | wc -l) # Dirty repo: get uncommitted file count + output_ver_quad="$ver_maj.$ver_min.$ver_rev.$ver_uncommitted" + fi + + local output_cpp_date output_app_date output_builder + get_build_date output_cpp_date output_app_date output_buildtime output_builder "${BUILDTIME-}" + + cat << EOF > "$version_file" # Write new values to the hidden cache file +ver_githash="$lookup_hash" +ver_full="$output_ver_full" +ver_quad="$output_ver_quad" +cpp_date="$output_cpp_date" +app_date="$output_app_date" +buildtime="$output_buildtime" +builder="$output_builder" +EOF + + echo "$output_ver_full" +} + +# Exit only if not sourced +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + run_script "$@" + exit $? +fi diff --git a/ShellScripts/common/get_version_fn.sh b/ShellScripts/common/get_version_fn.sh deleted file mode 100755 index 12e6db1cc..000000000 --- a/ShellScripts/common/get_version_fn.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -# -# Calculates the Oolite version number -# - -# Get the name of the script that is sourcing this file -SUITE_PARENT=$(basename "${BASH_SOURCE[1]}") -# Define the ONLY script allowed to source this -ALLOWED_SCRIPT="mk.sh" -if [ "$SUITE_PARENT" != "$ALLOWED_SCRIPT" ]; then - echo "❌ This file can only be sourced by $ALLOWED_SCRIPT!" >&2 - return 1 2>/dev/null || exit 1 -fi - -get_version() { - local -n output_ver_full=$1 - local -n output_ver_nsis=$2 - local -n output_ver_gitrev=$3 - local -n output_ver_githash=$4 - - output_ver_gitrev=$(git rev-list --count HEAD) - output_ver_githash=$(git rev-parse --short=7 HEAD) - - if [[ -n "$5" ]]; then # VER_FULL already populated - return 0 - fi - - if ! command -v gitversion &> /dev/null; then - echo "❌ gitversion binary not found!" >&2 - exit 1 - fi - - local gitversion_json=$(gitversion) - local ver_maj=$(echo "$gitversion_json" | jq -r '.Major') - local ver_min=$(echo "$gitversion_json" | jq -r '.Minor') - local ver_rev=$(echo "$gitversion_json" | jq -r '.Patch') - - if [[ "" == "$ver_rev" ]]; then - ver_rev="0" - fi - - local ver_dist=$(echo "$gitversion_json" | jq -r '.VersionSourceDistance') - local ver_semver=$(echo "$gitversion_json" | jq -r '.SemVer') - local ver_uncommitted=$(echo "$gitversion_json" | jq -r '.UncommittedChanges') - - if git diff --quiet; then - output_ver_full=$ver_semver - output_ver_nsis="$ver_maj.$ver_min.$ver_rev.$ver_dist" - else - output_ver_full="${ver_semver}+dirty.${ver_uncommitted}" - output_ver_nsis="$ver_maj.$ver_min.$ver_rev.$ver_uncommitted" - fi -} \ No newline at end of file diff --git a/ShellScripts/common/install.sh b/ShellScripts/common/install.sh index c64b2d756..23644a46a 100755 --- a/ShellScripts/common/install.sh +++ b/ShellScripts/common/install.sh @@ -16,9 +16,14 @@ run_script() { set -x local appname=$(basename "$stageprogpath") local progdir=$(dirname "$stageprogpath") - local installdir="${INSTALLDIR:-$MESON_INSTALL_DESTDIR_PREFIX}" + local installdir="$MESON_INSTALL_DESTDIR_PREFIX" local fullbindir="$installdir/$bindir" + rm -f "$fullbindir/oolite" + if [[ "$host_os" == "linux" ]]; then + rm -f "$fullbindir/run_oolite.sh" + fi local fulldatadir="$installdir/$datadir/oolite" # don't use appname here as Obj-C has oolite specifically + rm -rf "$fulldatadir" local progpath="$fullbindir/$appname" if ! mkdir -p "$fullbindir"; then echo "❌ Failed to create folder '$fullbindir'!" >&2 diff --git a/ShellScripts/common/parse_manifest_fn.sh b/ShellScripts/common/parse_manifest_fn.sh new file mode 100644 index 000000000..8f01e4ff1 --- /dev/null +++ b/ShellScripts/common/parse_manifest_fn.sh @@ -0,0 +1,25 @@ +parse_manifest() { + local -n _ver_full="$1" + local -n _ver_quad="$2" + local -n _githash="$3" + local -n _buildtime="$4" + local -n _app_date="$5" + local input_file="$6" + + if [[ ! -f "$input_file" ]]; then # Ensure the manifest file exists before parsing + echo "❌ Manifest file '$input_file' not found." >&2 + return 1 + fi + + get_manifest_value() { # Helper function to extract a string inside quotes for a given key + local key="$1" + grep -E "^[[:space:]]*${key}[[:space:]]*=" "$input_file" | sed -E 's/.*"[[:space:]]*([^"]*)[[:space:]]*".*/\1/' + } + + _ver_full=$(get_manifest_value "version") + _ver_quad=$(get_manifest_value "version_quad") + _githash=$(get_manifest_value "git_commit_hash") + _buildtime=$(get_manifest_value "build_time") + local clean_date="${_buildtime//./-}" + _app_date=$(date -u -d "${clean_date:0:10}" +"%Y-%m-%d" 2>/dev/null || echo "") +} \ No newline at end of file diff --git a/ShellScripts/common/post_build.sh b/ShellScripts/common/post_build.sh index b23947ef7..cc6871a1d 100755 --- a/ShellScripts/common/post_build.sh +++ b/ShellScripts/common/post_build.sh @@ -10,9 +10,11 @@ run_script() { local espeak="$6" local strip_bin="$7" local ver_full="$8" - local ver_githash="$9" - local gnustep_folder="${10}" - local stamp_file="${11}" + local ver_quad="$9" + local ver_githash="${10}" + local buildtime="${11}" + local gnustep_folder="${12}" + local stamp_file="${13}" local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" > /dev/null @@ -35,7 +37,7 @@ run_script() { echo "❌ Failed to copy '$origprogpath' to '$progpath'!" >&2 return 1 fi - generate_manifest "$resourcesdir/manifest.plist" "$deployment_release" "$ver_full" "$ver_githash" + generate_manifest "$resourcesdir/manifest.plist" "$deployment_release" "$ver_full" "$ver_quad" "$ver_githash" "$buildtime" cp -fu src/Cocoa/Info-Oolite.plist "$resourcesdir/Info-gnustep.plist" if [[ "$deployment_release" == "no" ]]; then local addonsdir="$progdir/AddOns" @@ -135,4 +137,4 @@ status=$? # Exit only if not sourced if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then exit $status -fi \ No newline at end of file +fi diff --git a/ShellScripts/Linux/GNUstep.conf.template b/installers/FreeDesktop/GNUstep.conf.template similarity index 100% rename from ShellScripts/Linux/GNUstep.conf.template rename to installers/FreeDesktop/GNUstep.conf.template diff --git a/installers/FreeDesktop/install_freedesktop_fn.sh b/installers/FreeDesktop/install_freedesktop_fn.sh new file mode 100644 index 000000000..b6d11f959 --- /dev/null +++ b/installers/FreeDesktop/install_freedesktop_fn.sh @@ -0,0 +1,42 @@ +#!/bin/bash -x +# +# Installs the manifest and injects version number + + +install_freedesktop() { + local -n output_ver_full="$1" # Oolite version + local build_folder="$2" # oolite.app directory path (source) + local app_folder="$3" # app folder (destination) + local symbol_folder="$4" # debug symbol folder + local metainfo_suffix="$5" # can be appdata or metainfo + + local err_msg="❌ Error: Failed to install" + + source ../../ShellScripts/common/parse_manifest_fn.sh + + echo "Installing metainfo to $app_folder" + + local ver_quad githash buildtime app_date + parse_manifest output_ver_full ver_quad githash buildtime app_date "$build_folder/Resources/manifest.plist" + + local freedesktopdir="../../installers/FreeDesktop" + local appshr="$app_folder/share" + local resourcesdir="$appshr/oolite/Resources" + rm -f "$resourcesdir/GNUstep.conf.orig" + install -D "$freedesktopdir/GNUstep.conf.template" "$resourcesdir/GNUstep.conf.template" || { echo "$err_msg GNUstep template" >&2; return 1; } + + local app_metainfo="$appshr/metainfo/space.oolite.Oolite.$metainfo_suffix.xml" + install -D "$freedesktopdir/space.oolite.Oolite.metainfo.xml.template" "$app_metainfo" || { echo "$err_msg metainfo template" >&2; return 1; } + + sed -i "s/@VER@/${output_ver_full}/g" "$app_metainfo" + sed -i "s/@DATE@/${app_date}/g" "$app_metainfo" + + echo =========================================== + echo Our manifest looks like this: + cat "$app_metainfo" + echo =========================================== + + # Desktop and Icon + install -D "$freedesktopdir/space.oolite.Oolite.desktop" "$appshr/applications/space.oolite.Oolite.desktop" || { echo "$err_msg desktop file" >&2; return 1; } + install -D "$build_folder/Resources/Textures/oolite-logo1.png" "$appshr/icons/hicolor/256x256/apps/space.oolite.Oolite.png" || { echo "$err_msg icon file" >&2; return 1; } +} \ No newline at end of file diff --git a/installers/appimage/create_appimage_fn.sh b/installers/appimage/create_appimage_fn.sh index a52545630..92a827287 100755 --- a/installers/appimage/create_appimage_fn.sh +++ b/installers/appimage/create_appimage_fn.sh @@ -3,28 +3,22 @@ # Creates the appimage. create_appimage() { - local build_folder="$1" # Build folder - local ver_full="$2" # Oolite version - local app_date="$3" # Oolite build date - local build_type="$4" # Typically one of "test", "dev" or omitted for release builds + local build_type="$1" # Typically one of "deployment", "test", "dev" + local build_folder="$2" # Build folder local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" + source ../FreeDesktop/install_freedesktop_fn.sh + source ../../ShellScripts/Linux/os_detection.sh - cd ../../build - source ../ShellScripts/Linux/os_detection.sh - source ../ShellScripts/Linux/install_freedesktop_fn.sh - + cd ../../build/appimage local arch=$(uname -m) local APPDIR="./oolite.AppDir" export APPDIR local appbin="$APPDIR/bin" local appshr="$APPDIR/share" - rm -rf "$APPDIR" - local abs_oolitedir=$(realpath -m "$build_folder") - local abs_appdir=$(realpath -m "$APPDIR") - if ! install_freedesktop "$abs_oolitedir" "$ver_full" "$app_date" "$abs_appdir" "bin" "appdata"; then + if ! install_freedesktop ver_full "../$build_folder" "$APPDIR" "bin" "appdata"; then return 1 fi @@ -42,7 +36,7 @@ create_appimage() { local DESKTOP="$appshr/applications/space.oolite.Oolite.desktop" export DESKTOP local suffix - if [[ -n "$build_type" ]]; then + if [[ "$build_type" != "deployment" ]]; then suffix="_$build_type-$ver_full" else suffix="-$ver_full" @@ -92,7 +86,7 @@ create_appimage() { fi echo "Creating AppImage $OUTNAME..." - if ! $appimagetool_bin "$abs_appdir" "$OUTNAME"; then + if ! $appimagetool_bin "$APPDIR" "../$OUTNAME"; then echo "❌ AppImage creation failed!" >&2 return 1 fi diff --git a/installers/flatpak/create_flatpak_fn.sh b/installers/flatpak/create_flatpak_fn.sh index 09c3517b3..0ce28358a 100755 --- a/installers/flatpak/create_flatpak_fn.sh +++ b/installers/flatpak/create_flatpak_fn.sh @@ -1,18 +1,22 @@ #!/bin/bash -x create_flatpak() { - local ver_full="$1" # Oolite version + local build_type="$1" local github_repository="$2" # GitHub repository (set by GitHub Actions) local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" cd ../.. - mkdir -p build - cd build - - cp ../installers/flatpak/space.oolite.Oolite.* ./ + flatpak_dir="build/flatpak" + mkdir -p "$flatpak_dir" + source ShellScripts/common/get_version.sh + run_script "$flatpak_dir" + local githash ver_full ver_quad ver_gitrev cpp_date app_date buildtime builder + source "$flatpak_dir/.meson_version" + cd "$flatpak_dir" + cp ../../installers/flatpak/space.oolite.Oolite.* ./ mkdir -p shared-modules/glu if ! curl -o shared-modules/glu/glu-9.json -L https://github.com/flathub/shared-modules/raw/refs/heads/master/glu/glu-9.json; then echo "❌ Flatpak download of glu shared module failed!" >&2 @@ -20,35 +24,37 @@ create_flatpak() { fi local manifest="space.oolite.Oolite.yaml" - sed -i "s|^\([[:space:]]*- \)./mk.sh.*|\1./mk.sh flatpak-deployment --ver-full=\"$ver_full\" --github-repository=\"$github_repository\"|" "$manifest" || return 1 - local lint_exceptions=$(mktemp /tmp/oolite-lint-XXXXXX.json) - cat < "$lint_exceptions" -{ - "space.oolite.Oolite": [ - "finish-args-has-dev-input" - ] -} -EOF - trap 'rm -f "$lint_exceptions"' RETURN EXIT - - if command -v flatpak-builder-lint >/dev/null 2>&1; then # check manifest - if ! flatpak-builder-lint manifest "$manifest" --exceptions --user-exceptions="$lint_exceptions"; then - echo "❌ Flatpak manifest lint failed!" >&2 - cat "$manifest" - echo "❌ Flatpak manifest lint failed!" >&2 - return 1 - fi - else - echo "Native linter not found. Falling back to Flatpak container..." - if ! flatpak run --filesystem="$lint_exceptions" --command=flatpak-builder-lint org.flatpak.Builder manifest "$manifest" --exceptions --user-exceptions="$lint_exceptions"; then - echo "❌ Flatpak manifest lint failed!" >&2 - return 1 - fi + if ! sed -i "s|^[[:space:]]*- \./mk.sh.*| - ./mk.sh flatpak-internal $build_type --ver-full=\"$ver_full\" --buildtime=\"$buildtime\" --github-repository=\"$github_repository\"|" "$manifest"; then + echo "❌ Replacement of ./mk.sh line in $manifest failed!" >&2 + return 1 fi + tail -n 12 $manifest - # 3. Clean up - rm -f "$lint_exceptions" - trap - RETURN EXIT +# local lint_exceptions=$(mktemp /tmp/oolite-lint-XXXXXX.json) +# cat < "$lint_exceptions" +#{ +# "space.oolite.Oolite": [ +# "finish-args-has-dev-input" +# ] +#} +#EOF +# trap 'rm -f "$lint_exceptions"' RETURN EXIT +# if command -v flatpak-builder-lint >/dev/null 2>&1; then # check manifest +# if ! flatpak-builder-lint manifest "$manifest" --exceptions --user-exceptions="$lint_exceptions"; then +# echo "❌ Flatpak manifest lint failed!" >&2 +# cat "$manifest" +# echo "❌ Flatpak manifest lint failed!" >&2 +# return 1 +# fi +# else +# echo "Native linter not found. Falling back to Flatpak container..." +# if ! flatpak run --filesystem="$lint_exceptions" --command=flatpak-builder-lint org.flatpak.Builder manifest "$manifest" --exceptions --user-exceptions="$lint_exceptions"; then +# echo "❌ Flatpak manifest lint failed!" >&2 +# return 1 +# fi +# fi +# rm -f "$lint_exceptions" # Clean up +# trap - RETURN EXIT echo "Creating Flatpak..." if ! flatpak remote-add \ @@ -59,16 +65,19 @@ EOF return 1 fi - local total_lines=$(wc -l < $manifest) - local start_line=$((total_lines - 3)) - sed -i "${start_line},\$d" $manifest - cat <> $manifest - - type: dir - path: ../ -EOF - - # show effective manifest - flatpak-builder --show-manifest $manifest + if ! sed -i "/- type: git/{ + N; + /url:.*oolite\.git/{ + N;N; + c\\ + - type: dir\\ + path: ../../ + } + }" "$manifest"; then + echo "❌ Replacement of Oolite git repo source lines in $manifest failed!" >&2 + return 1 + fi + tail -n 12 $manifest if ! flatpak-builder \ --user \ @@ -82,13 +91,18 @@ EOF return 1 fi - local suffix="-$ver_full" + local suffix + if [[ "$build_type" != "deployment" ]]; then + suffix="_$build_type-$ver_full" + else + suffix="-$ver_full" + fi local ARCH=$(uname -m) local filename="space.oolite.Oolite${suffix}-${ARCH}.flatpak" echo "Creating Flatpak $filename..." if ! flatpak build-bundle \ repo \ - "$filename" \ + "../$filename" \ space.oolite.Oolite; then echo "❌ Flatpak bundle creation failed!" >&2 return 1 @@ -97,7 +111,7 @@ EOF if ! flatpak build-bundle \ --runtime \ repo \ - "$debugname" \ + "../$debugname" \ space.oolite.Oolite.Debug; then echo "❌ Flatpak bundle creation failed!" >&2 return 1 diff --git a/installers/flatpak/flatpak_postbuild_fn.sh b/installers/flatpak/flatpak_postbuild_fn.sh index 66fb4c6da..a60f0a352 100755 --- a/installers/flatpak/flatpak_postbuild_fn.sh +++ b/installers/flatpak/flatpak_postbuild_fn.sh @@ -5,20 +5,17 @@ flatpak_postbuild() { local build_folder="$1" # Build folder - local ver_full="$2" # Oolite version - local app_date="$3" # Oolite build date local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" - cd ../../build - source ../ShellScripts/Linux/install_freedesktop_fn.sh + source ../FreeDesktop/install_freedesktop_fn.sh - local abs_oolitedir=$(realpath -m "$build_folder") - install_freedesktop "$abs_oolitedir" "$ver_full" "$app_date" "/app" "lib/debug/bin" "metainfo" + cd ../../build/flatpak + install_freedesktop ver_full "../$build_folder" "/app" "lib/debug/bin" "metainfo" mkdir -p /app/lib/debug/source/oolite # Ensure the destination directory exists - # Copy the src directory recursively - cp -r ../src /app/lib/debug/source/oolite/ || { + cp -r ../../src /app/lib/debug/source/oolite/ || { # Copy the src directory recursively echo "❌ $err_msg install oolite source code" >&2 return 1 } + popd } \ No newline at end of file diff --git a/installers/flatpak/space.oolite.Oolite.yaml b/installers/flatpak/space.oolite.Oolite.yaml index 8adb1e002..16398f6ae 100644 --- a/installers/flatpak/space.oolite.Oolite.yaml +++ b/installers/flatpak/space.oolite.Oolite.yaml @@ -114,11 +114,11 @@ modules: build-commands: # Update --ver-full for FlatHub release. For CI and local builds, create_flatpak.sh replaces # --ver-full and --github-repository values - - ./mk.sh flatpak-deployment --ver-full="1.92.1" --github-repository="OoliteProject/oolite" + - ./mk.sh flatpak deployment --ver-full="1.92.1" --buildtime="2026.03.19 07:13" --github-repository="OoliteProject/oolite" sources: # Update tag and commit for FlatHub release. For CI and local builds, create_flatpak.sh replaces git source with: # - type: dir - # path: ../ + # path: ../../ - type: git url: https://github.com/OoliteProject/oolite.git tag: "1.92.1.0" diff --git a/installers/win32/OOlite.nsi b/installers/win32/OOlite.nsi index 6a70a8db3..9f0f0cd8c 100644 --- a/installers/win32/OOlite.nsi +++ b/installers/win32/OOlite.nsi @@ -14,10 +14,6 @@ ; and it's too much work to try to dynamically edit this file !include /NONFATAL "OoliteVersions.nsh" -!ifndef VER_GITREV -!warning "No GIT Revision supplied" -!define VER_GITREV 0 -!endif !ifndef VERSION !warning "No Version information supplied" !define VERSION 0.0.0.0 @@ -31,8 +27,8 @@ !ifndef OUTDIR !define OUTDIR . !endif -!ifndef SEMVER -!define SEMVER ${VERSION} +!ifndef VER_FULL +!define VER_FULL ${VERSION} !endif !ifndef DEV_RELEASE @@ -61,10 +57,10 @@ SetCompress auto SetCompressor LZMA SetCompressorDictSize 32 SetDatablockOptimize on -OutFile "${OUTDIR}\OoliteInstall-${SEMVER}-win${EXTVER}.exe" +OutFile "${OUTDIR}\OoliteInstall-${VER_FULL}-win${EXTVER}.exe" BrandingText "(C) 2003-2026 Giles Williams, Jens Ayton and contributors" Name "Oolite" -Caption "Oolite ${SEMVER} ${EXTVER} Setup" +Caption "Oolite ${VER_FULL} ${EXTVER} Setup" SubCaption 0 " " SubCaption 1 " " SubCaption 2 " " @@ -86,9 +82,9 @@ VIAddVersionKey "ProductName" "Oolite" VIAddVersionKey "FileDescription" "A space combat/trading game, inspired by Elite." VIAddVersionKey "LegalCopyright" "� 2003-2026 Giles Williams, Jens Ayton and contributors" VIAddVersionKey "FileVersion" "${VER}" -VIAddVersionKey "ProductVersion" "${SEMVER}" +VIAddVersionKey "ProductVersion" "${VER_FULL}" !ifdef DEV_RELEASE -VIAddVersionKey "GIT Revision" "${VER_GITHASH}" +VIAddVersionKey "GIT Hash" "${VER_GITHASH}" !endif !ifdef BUILDTIME VIAddVersionKey "Build Time" "${BUILDTIME}" diff --git a/installers/win32/create_nsis_fn.sh b/installers/win32/create_nsis_fn.sh index 7415a4e43..4fe950893 100644 --- a/installers/win32/create_nsis_fn.sh +++ b/installers/win32/create_nsis_fn.sh @@ -3,19 +3,18 @@ # Creates the windows installer using NSIS. create_nsis() { - local build_folder="$1" # Build folder - local ver_full="$2" # Oolite version - local ver_gitrev="$3" # Total number of commits in the history of current branch - local ver_githash="$4" # Git hash - local buildtime="$5" # Oolite build time - local build_type="$6" # Typically one of "test", "dev" or omitted for release builds + local build_type="$1" # Typically one of "deployment", "test", "dev" + local build_folder="$2" # Build folder local script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) pushd "$script_dir" + source ../../ShellScripts/common/parse_manifest_fn.sh mkdir -p ../../build/nsis cd ../../build/nsis - + local oolite_dir="../$build_folder" + local ver_full ver_quad ver_githash buildtime app_date + parse_manifest ver_full ver_quad ver_githash buildtime app_date "$oolite_dir/Resources/manifest.plist" cp ../../installers/win32/* ./ if ! curl -o OoliteReadMe.pdf -L https://oolite.readthedocs.io/en/latest/index.pdf; then @@ -39,35 +38,20 @@ create_nsis() { return 1 fi - local oolite_dir="../$build_folder" - oolite_dir="${oolite_dir//\//\\}" - - - [[ "$ver_full" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+).*\.([0-9]+)$ ]] # Regex captures: Major, Minor, Patch, Distance - local ver_maj="${BASH_REMATCH[1]}" - local ver_min="${BASH_REMATCH[2]}" - local ver_rev="${BASH_REMATCH[3]}" - local ver_dist="${BASH_REMATCH[4]}" - local ver_nsis="${ver_maj}.${ver_min}.${ver_rev}.${ver_dist}" - # Passing arguments can cause problems with NSIS so we generate them into a separate file and include them. echo "; Version Definitions for Oolite" > OoliteVersions.nsh echo "; NOTE - This file is auto-generated by the Makefile, any manual edits will be overwritten" >> OoliteVersions.nsh - echo "!define OOLITE_DIR ${oolite_dir}" >> OoliteVersions.nsh - echo "!define VER_MAJ ${ver_maj}" >> OoliteVersions.nsh - echo "!define VER_MIN ${ver_min}" >> OoliteVersions.nsh - echo "!define VER_REV ${ver_rev}" >> OoliteVersions.nsh - echo "!define VER_GITREV ${ver_gitrev}" >> OoliteVersions.nsh + echo "!define OOLITE_DIR ${oolite_dir//\//\\}" >> OoliteVersions.nsh echo "!define VER_GITHASH ${ver_githash}" >> OoliteVersions.nsh - echo "!define VERSION ${ver_nsis}" >> OoliteVersions.nsh - echo "!define SEMVER ${ver_full}" >> OoliteVersions.nsh + echo "!define VERSION ${ver_quad}" >> OoliteVersions.nsh + echo "!define VER_FULL ${ver_full}" >> OoliteVersions.nsh echo "!define BUILDTIME \"${buildtime}\"" >> OoliteVersions.nsh echo "!define BUILDHOST_IS64BIT 1" >> OoliteVersions.nsh - if [[ "$build_type" == "dev" ]]; then - echo "!define DEV_RELEASE 1" >> OoliteVersions.nsh - elif [[ "$build_type" != "test" ]]; then + if [[ "$build_type" == "deployment" ]]; then echo "!define DEPLOYMENT_RELEASE 1" >> OoliteVersions.nsh + elif [[ "$build_type" == "dev" ]]; then + echo "!define DEV_RELEASE 1" >> OoliteVersions.nsh fi local nsis diff --git a/meson.build b/meson.build index 6602937cd..8397f071e 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,12 @@ project( 'oolite', ['c', 'cpp', 'objc'], meson_version: '>= 1.4.0', - version: 'not used', + version: run_command( + 'bash', + files('ShellScripts/common/get_version.sh'), + meson.project_build_root(), + check: true, + ).stdout().strip(), default_options: [ 'optimization=2', ], @@ -11,11 +16,23 @@ project( host_os = host_machine.system() c_family = ['c', 'cpp', 'objc'] -version_string = get_option('ver_full') # use instead of meson project version! +version_string = meson.project_version() +cat_cmd = find_program('cat', required: true) +version_file = meson.project_build_root() / '.meson_version' +cat_result = run_command(cat_cmd, version_file, check: true) +version_vars = {} +file_contents = cat_result.stdout().strip() + +foreach line : file_contents.split('\n') + parts = line.split('=') + key = parts[0].strip() + value = parts[1].strip('"\' ') + version_vars += { key : value } +endforeach add_project_arguments( '-DOO_VERSION_FULL="@0@"'.format(version_string), - '-DOO_BUILD_DATE="@0@"'.format(get_option('build_date')), - '-DOO_BUILDER="@0@"'.format(get_option('builder')), + '-DOO_BUILD_DATE="@0@"'.format(version_vars.get('app_date')), + '-DOO_BUILDER="@0@"'.format(version_vars.get('builder')), language: c_family, ) diff --git a/meson.options b/meson.options index f53c1418e..138a83074 100644 --- a/meson.options +++ b/meson.options @@ -43,21 +43,3 @@ option('strip_bin', type: 'boolean', value: false, description: 'Enable strippin # Windows Specific Customizations option('pdb', type: 'boolean', value: false, description: 'Windows Clang builds only: Generate native .pdb debug symbol files') - -# Oolite version -option('ver_full', type: 'string', value: '', - description: 'Oolite version') - -# Git hash of commit -option('ver_githash', type: 'string', value: '', - description: 'Git hash of commit') - -# Oolite build date -option('build_date', type: 'string', value: 'unknown', - description: 'Oolite build date') - -# Oolite builder -option('builder', type: 'string', value: 'unknown', - description: 'Oolite builder') - - diff --git a/mk.sh b/mk.sh index 8fc1395ed..2f9b44dc0 100755 --- a/mk.sh +++ b/mk.sh @@ -5,8 +5,7 @@ pushd "$SCRIPT_DIR" > /dev/null set -u -o pipefail # Strict expansions -# --- Error Handling Trap --- -cleanup_and_exit() { +cleanup_and_exit() { # Error handling trap local exit_code=$? if [[ $exit_code -eq 0 ]]; then @@ -20,204 +19,244 @@ cleanup_and_exit() { } trap 'cleanup_and_exit ${LINENO}' ERR # Trap any command errors (ERR) passing ${LINENO} to know where it failed +output_meson_log() { + meson_log="$1/meson-logs/meson-log.txt" + if [[ -f "$meson_log" ]]; then + echo -e "\n=== MESON LOG START ===" >&2 + cat "$meson_log" >&2 + echo -e "=== MESON LOG END ===\n" >&2 + fi +} + # --- Feature Flags & Options --- NATIVE_FILE="" VER_FULL="" +BUILDTIME="" GITHUB_REPOSITORY="" CLEAN_BUILD=false SETUP_FLAGS=() # Array to cleanly store additional meson setup arguments COMPILE_FLAGS=() # Array to cleanly store additional meson compile arguments INSTALL_FLAGS=() # Array to cleanly store additional meson install arguments +clean() { + echo "--> Cleaning target build directory: $1" + rm -rf "$1" +} + meson_setup() { - local build_dir="build/meson_$2" - if [[ "$CLEAN_BUILD" == true ]]; then - echo "--> Cleaning target build directory: ${build_dir}" - rm -rf "$build_dir" # If --clean was specified, delete the specific build directory first + local build_dir="build/meson_$1" + echo "--> Running Meson setup for: $1" + local meson_opts=("${@:2}") + if [[ -n "${VER_FULL:-}" ]]; then + export VER_FULL + fi + if [[ -n "${BUILDTIME:-}" ]]; then + export BUILDTIME + fi + if [[ -n "${GITHUB_REPOSITORY:-}" ]]; then + export GITHUB_REPOSITORY + fi + if [[ -d "$build_dir" ]] && [[ -f "$build_dir/build.ninja" ]]; then + echo "🔄 Directory exists, attempting to reconfigure..." + if ! meson setup "$build_dir" "${meson_opts[@]}" ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} --native-file "${NATIVE_FILE}" --reconfigure; then + echo "❌ Meson reconfiguration failed!" >&2 + output_meson_log "$build_dir" + exit 1 + fi + else + echo "🏗️ Creating new build configuration..." + if ! meson setup "$build_dir" "${meson_opts[@]}" ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} --native-file "${NATIVE_FILE}"; then + echo "❌ Meson initial setup failed!" >&2 + output_meson_log "$build_dir" + exit 1 + fi fi - echo "--> Running Meson setup for: $2" - # Setup with --reconfigure, fallback to fresh setup. SETUP_FLAGS safely expands the array only if it's not empty - meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" --reconfigure 2>/dev/null || \ - meson setup "$build_dir" $1 ${SETUP_FLAGS[@]+"${SETUP_FLAGS[@]}"} -Dver_full="$VER_FULL" -Dver_githash="$VER_GITHASH" -Dbuild_date="${CPP_DATE}" -Dbuilder="${BUILDER}" --native-file "${NATIVE_FILE}" } meson_compile() { + local build_dir="build/meson_$1" echo "--> Running Meson build for: $1" - meson compile -C "build/meson_$1" ${COMPILE_FLAGS[@]+"${COMPILE_FLAGS[@]}"} + if ! meson compile -C "$build_dir" ${COMPILE_FLAGS[@]+"${COMPILE_FLAGS[@]}"}; then + echo "❌ Meson compile failed!" >&2 + output_meson_log "$build_dir" + exit 1 + fi } meson_install() { + local build_dir="build/meson_$1" echo "--> Running Meson install for: $1" - meson install -C "build/meson_$1" ${INSTALL_FLAGS[@]+"${INSTALL_FLAGS[@]}"} + if ! meson install -C "$build_dir" ${INSTALL_FLAGS[@]+"${INSTALL_FLAGS[@]}"}; then + echo "❌ Meson install failed!" >&2 + output_meson_log "$build_dir" + exit 1 + fi } show_help() { # Script Help Menu - echo "Usage: $0 [options] " + echo "Usage: $0 [options] " + echo " $0 [options] " echo "" echo "Options:" - echo -e " \033[36m--clean\033[0m Delete target build directory before compiling" echo -e " \033[36m--setup-flags=\"...\"\033[0m Pass additional arguments directly to 'meson setup'" echo -e " \033[36m--compile-flags=\"...\"\033[0m Pass additional arguments directly to 'meson compile'" echo -e " \033[36m--install-flags=\"...\"\033[0m Pass additional arguments directly to 'meson install'" echo -e " \033[36m--native-file=\"...\"\033[0m Specify native file (defaults to clang.ini)" echo -e " \033[36m--ver-full=\"...\"\033[0m Specify full version string" + echo -e " \033[36m--buildtime=\"...\"\033[0m Specify build time" echo -e " \033[36m--github-repository=\"...\"\033[0m Specify target GitHub repository" echo "" - echo "Targets:" - echo -e " \033[36msetup-deployment\033[0m Setup a deployment release executable" - echo -e " \033[36msetup-test\033[0m Setup a test release executable" - echo -e " \033[36msetup-dev\033[0m Setup a dev release executable" - echo -e " \033[36msetup-debug\033[0m Setup a debug executable" - echo -e " \033[36mcompile-deployment\033[0m Compile a deployment release executable" - echo -e " \033[36mcompile-test\033[0m Compile a test release executable" - echo -e " \033[36mcompile-dev\033[0m Compile a dev release executable" - echo -e " \033[36mcompile-debug\033[0m Compile a debug executable" - echo -e " \033[36mbuild-deployment\033[0m Setup and compile a deployment release executable" - echo -e " \033[36mbuild-test\033[0m Setup and compile a test release executable" - echo -e " \033[36mbuild-dev\033[0m Setup and compile a dev release executable" - echo -e " \033[36mbuild-debug\033[0m Setup and compile a debug executable" - echo -e " \033[36minstall-deployment\033[0m Install the deployment release installation" - echo -e " \033[36minstall-test\033[0m Install the test release installation" - echo -e " \033[36minstall-dev\033[0m Install the dev release installation" - echo -e " \033[36minstall-debug\033[0m Install the debug installation" - echo -e " \033[36mtest\033[0m Run test suite (depends on build-dev)" - echo -e " \033[36mclean\033[0m Remove all generated build artifacts" - echo -e " \033[36mpkg-flatpak\033[0m Package a Flatpak application" - echo -e " \033[36mpkg-appimage-deployment\033[0m Package a Linux deployment release AppImage" - echo -e " \033[36mpkg-appimage-test\033[0m Package a Linux test release AppImage" - echo -e " \033[36mpkg-appimage-dev\033[0m Package a Linux dev release AppImage" - echo -e " \033[36mpkg-win-deployment\033[0m Package a Windows NSIS deployment release installer" - echo -e " \033[36mpkg-win-test\033[0m Package a Windows NSIS test release installer" - echo -e " \033[36mpkg-win-dev\033[0m Package a Windows NSIS dev release installer" + echo "Build Type Actions (Requires build_type as second parameter):" + echo -e " \033[36msetup \033[0m Setup a release build directory" + echo -e " \033[36mcompile \033[0m Compile a build directory" + echo -e " \033[36mbuild \033[0m Setup and compile a build build_type" + echo -e " \033[36minstall \033[0m Install a built build_type configuration" + echo -e " \033[36mtest \033[0m Run test suites (deployment build_type excluded)" + echo -e " \033[36mclean \033[0m Clean a specific build_type's directory" + echo -e " \033[36mflatpak-internal \033[0m Build flatpak dependencies internally" + echo -e " \033[36mpkg-flatpak \033[0m Package a Flatpak application" + echo -e " \033[36mpkg-appimage \033[0m Package a Linux AppImage installer" + echo -e " \033[36mpkg-win \033[0m Package a Windows NSIS installer" + echo "" + echo "Global Actions:" + echo -e " \033[36mclean-all\033[0m Remove generated artifacts for all builds" + echo -e " \033[36mhelp\033[0m Show this breakdown menu" + echo "" + echo "Build Types:" + echo -e " \033[32mdeployment, test, dev, debug\033[0m" +} + +validate_build_type() { + local build_type="$1" + if [[ "$build_type" != "deployment" && "$build_type" != "test" && "$build_type" != "dev" && "$build_type" != "debug" ]]; then + echo "❌ Invalid build_type '$build_type'. Expected: deployment, test, dev, or debug." >&2 + exit 1 + fi } execute_target() { # Target Execution Logic - case "$1" in - setup-deployment) - meson_setup "-Ddeployment_release=true -Ddebug=false -Dstrip_bin=true -Db_lto=true" "deployment" - ;; - setup-test) - meson_setup "-Ddebug=false -Dstrip_bin=true -Db_lto=true" "test" - ;; - setup-dev) - meson_setup "-Ddev_release=true -Ddebug=false -Dstrip_bin=false" "dev" - ;; - setup-debug) - meson_setup "-Ddebug=true -Dstrip_bin=false" "debug" - ;; - compile-deployment) - meson_compile "deployment" - ;; - compile-test) - meson_compile "test" - ;; - compile-dev) - meson_compile "dev" - ;; - compile-debug) - meson_compile "debug" - ;; - build-deployment) - execute_target "setup-deployment" - execute_target "compile-deployment" - ;; - build-test) - execute_target "setup-test" - execute_target "compile-test" - ;; - build-dev) - execute_target "setup-dev" - execute_target "compile-dev" - ;; - build-debug) - execute_target "setup-debug" - execute_target "compile-debug" - ;; - install-deployment) - execute_target "build-deployment" - meson_install "deployment" - ;; - install-test) - execute_target "build-test" - meson_install "test" - ;; - install-dev) - execute_target "build-dev" - meson_install "dev" - ;; - install-debug) - execute_target "build-debug" - meson_install "debug" + local action="$1" + local build_type="${2:-}" + +case "$action" in + setup) + validate_build_type "$build_type" + if [[ "$build_type" == "deployment" ]]; then + # Arguments passed individually (acts like an array) + meson_setup "deployment" "-Ddeployment_release=true" "-Ddebug=false" "-Dstrip_bin=true" "-Db_lto=true" + elif [[ "$build_type" == "test" ]]; then + meson_setup "test" "-Ddebug=false" "-Dstrip_bin=true" "-Db_lto=true" + elif [[ "$build_type" == "dev" ]]; then + meson_setup "dev" "-Ddev_release=true" "-Ddebug=false" "-Dstrip_bin=false" + elif [[ "$build_type" == "debug" ]]; then + meson_setup "debug" "-Ddebug=true" "-Dstrip_bin=false" + fi ;; - test-deployment) - echo "❌ Cannot test deployment as not set up for debug console!" >&2 - exit 1 + compile) + validate_build_type "$build_type" + meson_compile "$build_type" ;; - test-test) - execute_target "build-test" - source tests/run_test_fn.sh && run_test "test" + build) + validate_build_type "$build_type" + execute_target "setup" "$build_type" + execute_target "compile" "$build_type" ;; - test-dev) - execute_target "build-dev" - source tests/run_test_fn.sh && run_test "dev" + install) + validate_build_type "$build_type" + meson_install "$build_type" ;; - test-debug) - execute_target "build-debug" - source tests/run_test_fn.sh && run_test "debug" + test) + validate_build_type "$build_type" + if [[ "$build_type" == "deployment" ]]; then + echo "❌ Cannot test deployment as not set up for debug console!" >&2 + exit 1 + fi + source tests/run_test_fn.sh && run_test "$build_type" ;; clean) - echo "--> Cleaning all build artifacts..." - rm -rf build/meson_* + if [[ "$build_type" == "appimage" ]]; then + clean "build/appimage" + elif [[ "$build_type" == "flatpak" ]]; then + clean "build/flatpak" + else + validate_build_type "$build_type" + clean "build/meson_$build_type" + fi ;; - flatpak-deployment) # This is used internally by the flatpak YAML - execute_target "build-deployment" - source installers/flatpak/flatpak_postbuild_fn.sh && flatpak_postbuild meson_deployment/oolite.app "$VER_FULL" "$APP_DATE" + flatpak-internal) + validate_build_type "$build_type" + execute_target "build" "$build_type" + if ! meson configure "build/meson_$build_type" --prefix="/app"; then + echo "❌ Flatpak meson configure with prefix /app failed!" >&2 + exit 1 + fi + if ! meson_install "$build_type"; then + echo "❌ Flatpak meson install failed!" >&2 + exit 1 + fi + if ! source installers/flatpak/flatpak_postbuild_fn.sh; then + echo "❌ Failed to source flatpak_postbuild_fn.sh!" >&2 + exit 1 + fi + if ! flatpak_postbuild "meson_${build_type}/oolite.app"; then + echo "❌ Flatpak post build failed!" >&2 + exit 1 + fi ;; pkg-flatpak) - source installers/flatpak/create_flatpak_fn.sh && create_flatpak "$VER_FULL" "$GITHUB_REPOSITORY" - ;; - pkg-appimage-deployment) - execute_target "build-deployment" - source installers/appimage/create_appimage_fn.sh && create_appimage meson_deployment/oolite.app "$VER_FULL" "$APP_DATE" "" - ;; - pkg-appimage-test) - execute_target "build-test" - source installers/appimage/create_appimage_fn.sh && create_appimage meson_test/oolite.app "$VER_FULL" "$APP_DATE" "test" - ;; - pkg-appimage-dev) - execute_target "build-dev" - source installers/appimage/create_appimage_fn.sh && create_appimage meson_dev/oolite.app "$VER_FULL" "$APP_DATE" "dev" - ;; - pkg-win-deployment) - execute_target "build-deployment" - source installers/win32/create_nsis_fn.sh && create_nsis meson_deployment/oolite.app "$VER_FULL" "$VER_GITREV" "$VER_GITHASH" "$BUILDTIME" "" - ;; - pkg-win-test) - execute_target "build-test" - source installers/win32/create_nsis_fn.sh && create_nsis meson_test/oolite.app "$VER_FULL" "$VER_GITREV" "$VER_GITHASH" "$BUILDTIME" "test" + validate_build_type "$build_type" + if ! source installers/flatpak/create_flatpak_fn.sh; then + echo "❌ Failed to source create_flatpak_fn.sh!" >&2 + exit 1 + fi + if ! create_flatpak "$build_type" "$GITHUB_REPOSITORY"; then + echo "❌ Flatpak generation failed!" >&2 + exit 1 + fi ;; - pkg-win-dev) - execute_target "build-dev" - source installers/win32/create_nsis_fn.sh && create_nsis meson_dev/oolite.app "$VER_FULL" "$VER_GITREV" "$VER_GITHASH" "$BUILDTIME" "dev" + pkg-appimage) + validate_build_type "$build_type" + if ! meson configure "build/meson_$build_type" --prefix=$(realpath -m "build/appimage/oolite.AppDir"); then + echo "❌ AppImage meson configure with prefix /app failed!" >&2 + exit 1 + fi + if ! meson_install "$build_type"; then + echo "❌ AppImage meson install failed!" >&2 + exit 1 + fi + if ! source installers/appimage/create_appimage_fn.sh; then + echo "❌ Failed to source create_appimage_fn.sh!" >&2 + exit 1 + fi + if ! create_appimage "$build_type" "meson_${build_type}/oolite.app"; then + echo "❌ AppImage generation failed!" >&2 + exit 1 + fi ;; - help|--help|-h) - show_help + pkg-win) + validate_build_type "$build_type" + if ! source installers/win32/create_nsis_fn.sh; then + echo "❌ Failed to source create_nsis_fn.sh!" >&2 + exit 1 + fi + if ! create_nsis "$build_type" "meson_${build_type}/oolite.app"; then + echo "❌ NSIS generation failed!" >&2 + exit 1 + fi ;; *) - echo "❌ Unknown target '$1'" >&2 - show_help + echo "❌ Fatal structural error handling action '$action'" >&2 exit 1 ;; esac } -TARGET="" -while [[ $# -gt 0 ]]; do # Flexible Argument Parser +ACTION="" +BUILD_TYPE="" + +# --- Flexible Argument Parser (Allows flags and positionals anywhere) --- +while [[ $# -gt 0 ]]; do case "$1" in - --clean) - CLEAN_BUILD=true - shift - ;; --setup-flags=*) read -r -a flags_array <<< "${1#*=}" SETUP_FLAGS+=("${flags_array[@]}") @@ -241,6 +280,10 @@ while [[ $# -gt 0 ]]; do # Flexible Argument Parser VER_FULL="${1#*=}" shift ;; + --buildtime=*) + BUILDTIME="${1#*=}" + shift + ;; --github-repository=*) GITHUB_REPOSITORY="${1#*=}" shift @@ -255,35 +298,55 @@ while [[ $# -gt 0 ]]; do # Flexible Argument Parser exit 1 ;; *) - if [[ -n "$TARGET" ]]; then - echo "❌ Multiple targets specified ('$TARGET' and '$1'). Only one target allowed." >&2 + # Process sequential text items dynamically + if [[ -z "$ACTION" ]]; then + ACTION="$1" + elif [[ -z "$BUILD_TYPE" ]]; then + BUILD_TYPE="$1" + else + echo "❌ Unexpected extra argument '$1'." >&2 + show_help exit 1 fi - TARGET="$1" shift ;; esac done -if [[ -z "$TARGET" ]]; then - show_help # Fallback to help menu if no target was provided +if [[ -z "$ACTION" ]]; then + show_help # Fallback to help menu if no action was provided exit 1 fi -if [[ -z "$NATIVE_FILE" ]]; then - NATIVE_FILE="clang.ini" # Apply default for NATIVE_FILE if it wasn't passed as a parameter + +# Intercept global action 'clean-all' before validating build_type requirements +if [[ "$ACTION" == "clean-all" ]]; then + echo "--> Cleaning all build artifacts..." + rm -rf build/meson_* + rm -rf build/flatpak + rm -rf build/appimage + trap - ERR + popd > /dev/null + echo "✅ Oolite task 'clean-all' completed successfully" + exit 0 +fi + +# Everything past this point strictly requires a build_type parameter +if [[ -z "$BUILD_TYPE" ]]; then + echo "❌ Error: Action '$ACTION' requires a target build_type parameter." >&2 + show_help + exit 1 fi -source ShellScripts/common/get_build_date_fn.sh && get_build_date CPP_DATE APP_DATE BUILDTIME BUILDER "$GITHUB_REPOSITORY" -source ShellScripts/common/get_version_fn.sh && get_version VER_FULL VER_NSIS VER_GITREV VER_GITHASH "$VER_FULL" +if [[ -z "$NATIVE_FILE" ]]; then + NATIVE_FILE="clang.ini" # Apply default if it wasn't passed as an option +fi -execute_target "$TARGET" +execute_target "$ACTION" "$BUILD_TYPE" -trap - ERR # Successful Exit - remove the ERR trap so it doesn't accidentally fire during normal bailing +trap - ERR # Successful Exit popd > /dev/null -if [[ "$TARGET" != "help" && "$TARGET" != "--help" && "$TARGET" != "-h" && "$TARGET" != "clean" ]]; then - echo "✅ Oolite target '$TARGET' completed successfully" # Print success if not a help menu or a cleanup action -fi +echo "✅ Oolite task '$ACTION $BUILD_TYPE' completed successfully" if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then exit 0 diff --git a/src/Core/GameController.m b/src/Core/GameController.m index 362260bbe..2b297ad2f 100644 --- a/src/Core/GameController.m +++ b/src/Core/GameController.m @@ -864,6 +864,7 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende } #elif OOLITE_SDL +#include - (void) exitAppWithContext:(NSString *)context { diff --git a/src/Core/NSFileManagerOOExtensions.m b/src/Core/NSFileManagerOOExtensions.m index 979298f06..ae5bcaa67 100644 --- a/src/Core/NSFileManagerOOExtensions.m +++ b/src/Core/NSFileManagerOOExtensions.m @@ -27,7 +27,7 @@ */ #include -#include +#include #import "ResourceManager.h" #import "OOPListParsing.h" #import "GameController.h" diff --git a/src/Core/OOJoystickManager.h b/src/Core/OOJoystickManager.h index 724f40f82..fe349f564 100644 --- a/src/Core/OOJoystickManager.h +++ b/src/Core/OOJoystickManager.h @@ -164,7 +164,7 @@ enum { #if OOLITE_SDL -#import +#import enum { diff --git a/src/Core/OOLogOutputHandler.m b/src/Core/OOLogOutputHandler.m index 676b940bc..51b2fecd4 100644 --- a/src/Core/OOLogOutputHandler.m +++ b/src/Core/OOLogOutputHandler.m @@ -36,7 +36,7 @@ of this software and associated documentation files (the "Software"), to deal #include #import "NSThreadOOExtensions.h" #import "NSFileManagerOOExtensions.h" -#include +#include #undef NSLog // We need to be able to call the real NSLog. diff --git a/src/SDL/MyOpenGLView.h b/src/SDL/MyOpenGLView.h index e30eaed30..7d83eca61 100644 --- a/src/SDL/MyOpenGLView.h +++ b/src/SDL/MyOpenGLView.h @@ -28,7 +28,7 @@ MA 02110-1301, USA. #import "OOOpenGLMatrixManager.h" -#include +#include #define WINDOW_SIZE_DEFAULT_WIDTH 1280 #define WINDOW_SIZE_DEFAULT_HEIGHT 720 diff --git a/src/SDL/MyOpenGLView.m b/src/SDL/MyOpenGLView.m index a33b942b1..0b4f3e8d2 100644 --- a/src/SDL/MyOpenGLView.m +++ b/src/SDL/MyOpenGLView.m @@ -22,6 +22,7 @@ */ +#include #import "png.h" #import "MyOpenGLView.h" diff --git a/src/SDL/OOSDLJoystickManager.h b/src/SDL/OOSDLJoystickManager.h index b1a4510a6..7f7f18550 100644 --- a/src/SDL/OOSDLJoystickManager.h +++ b/src/SDL/OOSDLJoystickManager.h @@ -36,7 +36,7 @@ MA 02110-1301, USA. #import -#import +#import #import "OOJoystickManager.h" diff --git a/src/SDL/main.m b/src/SDL/main.m index 02a1c7b34..44dde3e16 100644 --- a/src/SDL/main.m +++ b/src/SDL/main.m @@ -34,7 +34,7 @@ #if OOLITE_WINDOWS #include -#include +#include #include // Make sure that a high performance GPU is // selected, if more than one are available diff --git a/src/meson.build b/src/meson.build index 7ba71670a..6c3dd2fb3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -47,11 +47,14 @@ post_build_args = [ get_option('espeak') ? 'yes' : 'no', get_option('strip_bin') ? 'yes' : 'no', version_string, - get_option('ver_githash'), + version_vars.get('ver_quad'), + version_vars.get('ver_githash'), + version_vars.get('buildtime'), gnustep_folder, stamp_file, ] post_build_script = files('../ShellScripts/common/post_build.sh') +generate_manifest_script = files('../ShellScripts/common/generate_manifest_fn.sh') oolite_app_bundle = custom_target('post_build', input: oolite_bin, output: stamp_file, @@ -60,6 +63,7 @@ oolite_app_bundle = custom_target('post_build', post_build_script, post_build_args, ], + depend_files: [generate_manifest_script], build_by_default: true, install: false, ) From 0b151295fc7a59f20455f61ca18eacb003999ea9 Mon Sep 17 00:00:00 2001 From: mcarans Date: Mon, 13 Jul 2026 10:09:27 +1200 Subject: [PATCH 21/23] Ensure debug symbols get copied in install Add configure action to mk.sh Update README --- README.md | 71 +++++++++++++++++++--------------- ShellScripts/common/install.sh | 9 +++++ mk.sh | 32 +++++++++++++-- 3 files changed, 77 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 62a3dd511..42b4471d0 100644 --- a/README.md +++ b/README.md @@ -122,74 +122,83 @@ default, but you can supply a further argument to specify an alternative like do ### Building Oolite -Next run this in your Bash or MSYS2 prompt to build Oolite: +The underlying build system is Meson, but it is recommended to build via the mk.sh script which also allow you to pass +meson setup, compile, configure and install flags. Type the following for help: ```bash -./mk.sh build-dev +./mk.sh help ``` -The completed build (executable and games files) can be found in the build/meson_dev/oolite.app directory. +Oolite has various build types: + +- **"dev"**: Keeps debug symbols in the binary. +- **"deployment"**: Intended for production builds. Removes debug symbols from the binary, but makes them available in + a separate symbols file. +- **"test"**: Used for test releases; supports the debug console, which expansion developers use to debug their OXPs. + Removes debug symbols from the binary, but makes them available in a separate symbols file. -Subsequently, you can clean and build as follows: +You can run this in your Bash or MSYS2 prompt to build Oolite for development: ```bash -./mk.sh build-dev --clean +./mk.sh build dev ``` -You can run a test that launches the game and takes a snapshot from your Bash or MSYS2 prompt as follows: +Optionally you can pass `--setup-flags` and/or `--compile-flags` to pass specific options to meson. The completed build +(executable and games files) can be found in the `build/meson_dev/oolite.app` directory. + +build dev runs 2 actions which can be run independently: `setup dev` which runs meson setup and `compile dev` which runs +meson compile. + +Subsequently, you can clean and build the development build as follows: ```bash -./mk.sh test +./mk.sh clean dev +./mk.sh build dev ``` -build-dev keeps debug symbols in the binary. Other build targets remove those symbols from the binary although they -are made available in a separate symbols file. build-deployment is for a production build and build-test is for a -test release that supports the debug console which is used by expansion developers for debugging their OXPs. - -You can install: +You can run a test of the development build that launches the game and takes a snapshot from your Bash or MSYS2 prompt +as follows: ```bash -./mk.sh install-dev +./mk.sh test dev ``` -Other targets are install-deployment for a production install and install-test for a test install. +You can modify build options of the build directory (such as `--prefix`): -The underlying build system is Meson, but it is recommended to run via the mk.sh script which also allow you to pass -meson setup, compile and install flags. Type the following for help: +```bash +./mk.sh configure dev --configure-flags="" +``` + +You can install the build folder: ```bash -./mk.sh help +./mk.sh install dev ``` -build-dev runs 2 targets which can be run independently: setup-dev which runs meson setup and compile-dev which runs -meson compile. +Optionally you can pass `--install-flags` to pass specific options to meson. -### Other Linux ./mk.sh Targets +### Other Linux ./mk.sh Actions -This target builds an AppImage for development which can be found in the `build` fodler: +This action builds an AppImage for development which can be found in the `build` folder: ```bash -./mk.sh pkg-appimage-dev +./mk.sh pkg-appimage dev ``` -The target pkg-appimage-deployment is the production release, while pkg-appimage-test is for test. - -This target builds a Flatpak (deployment only) which can be found in the `build` folder: +This action builds a Flatpak which can be found in the `build` folder: ```bash -./mk.sh pkg-flatpak +./mk.sh pkg-flatpak deployment ``` -### Other Windows ./mk.sh Targets +### Other Windows ./mk.sh Actions -This target builds a Windows NSIS installer for development which can be found in the `build` folder: +This action builds a Windows NSIS installer for development which can be found in the `build` folder: ```bash -./mk.sh pkg-win-dev +./mk.sh pkg-win dev ``` -The target pkg-win-deployment is the production release, while pkg-win-test is for test. - ### Mac OS Intel-based Macs can run old builds of Oolite, but current Macs are unsupported. It is hoped that they can be supported diff --git a/ShellScripts/common/install.sh b/ShellScripts/common/install.sh index 23644a46a..3f4e3e0fd 100755 --- a/ShellScripts/common/install.sh +++ b/ShellScripts/common/install.sh @@ -44,6 +44,15 @@ run_script() { echo "❌ Failed to copy '$run_oolite_src' to '$run_oolite_dst'!" >&2 return 1 fi + local debugname="$appname.debug" + local oolite_debug_src="$progdir/$debugname" + if [[ -f "$oolite_debug_src" ]]; then + local oolite_debug_dst="$fullbindir/$debugname" + if ! cp -fu "$oolite_debug_src" "$oolite_debug_dst"; then + echo "❌ Failed to copy '$oolite_debug_src' to '$oolite_debug_dst'!" >&2 + return 1 + fi + fi fi local resources_src="$progdir/Resources/." local resources_dst="$fulldatadir/Resources" diff --git a/mk.sh b/mk.sh index 2f9b44dc0..80622f5c8 100755 --- a/mk.sh +++ b/mk.sh @@ -36,6 +36,7 @@ GITHUB_REPOSITORY="" CLEAN_BUILD=false SETUP_FLAGS=() # Array to cleanly store additional meson setup arguments COMPILE_FLAGS=() # Array to cleanly store additional meson compile arguments +CONFIGURE_FLAGS=() # Array to cleanly store additional meson configure arguments INSTALL_FLAGS=() # Array to cleanly store additional meson install arguments clean() { @@ -83,6 +84,17 @@ meson_compile() { fi } +meson_configure() { + local build_dir="build/meson_$1" + echo "--> Running Meson configure for: $1" + local meson_opts=("${@:2}") + if ! meson configure "$build_dir" "${meson_opts[@]}" ${CONFIGURE_FLAGS[@]+"${CONFIGURE_FLAGS[@]}"}; then + echo "❌ Meson configure failed!" >&2 + output_meson_log "$build_dir" + exit 1 + fi +} + meson_install() { local build_dir="build/meson_$1" echo "--> Running Meson install for: $1" @@ -100,6 +112,7 @@ show_help() { # Script Help Menu echo "Options:" echo -e " \033[36m--setup-flags=\"...\"\033[0m Pass additional arguments directly to 'meson setup'" echo -e " \033[36m--compile-flags=\"...\"\033[0m Pass additional arguments directly to 'meson compile'" + echo -e " \033[36m--configure-flags=\"...\"\033[0m Pass additional arguments directly to 'meson configure'" echo -e " \033[36m--install-flags=\"...\"\033[0m Pass additional arguments directly to 'meson install'" echo -e " \033[36m--native-file=\"...\"\033[0m Specify native file (defaults to clang.ini)" echo -e " \033[36m--ver-full=\"...\"\033[0m Specify full version string" @@ -109,8 +122,9 @@ show_help() { # Script Help Menu echo "Build Type Actions (Requires build_type as second parameter):" echo -e " \033[36msetup \033[0m Setup a release build directory" echo -e " \033[36mcompile \033[0m Compile a build directory" - echo -e " \033[36mbuild \033[0m Setup and compile a build build_type" - echo -e " \033[36minstall \033[0m Install a built build_type configuration" + echo -e " \033[36mbuild \033[0m Setup and compile a build directory" + echo -e " \033[36mconfigure \033[0m Modify build options of an existing build directory" + echo -e " \033[36minstall \033[0m Install an existing build directory" echo -e " \033[36mtest \033[0m Run test suites (deployment build_type excluded)" echo -e " \033[36mclean \033[0m Clean a specific build_type's directory" echo -e " \033[36mflatpak-internal \033[0m Build flatpak dependencies internally" @@ -161,6 +175,10 @@ case "$action" in execute_target "setup" "$build_type" execute_target "compile" "$build_type" ;; + configure) + validate_build_type "$build_type" + meson_configure "$build_type" + ;; install) validate_build_type "$build_type" meson_install "$build_type" @@ -186,7 +204,7 @@ case "$action" in flatpak-internal) validate_build_type "$build_type" execute_target "build" "$build_type" - if ! meson configure "build/meson_$build_type" --prefix="/app"; then + if ! meson_configure "$build_type" "--prefix=/app"; then echo "❌ Flatpak meson configure with prefix /app failed!" >&2 exit 1 fi @@ -216,7 +234,8 @@ case "$action" in ;; pkg-appimage) validate_build_type "$build_type" - if ! meson configure "build/meson_$build_type" --prefix=$(realpath -m "build/appimage/oolite.AppDir"); then + local appdir=$(realpath -m "build/appimage/oolite.AppDir") + if ! meson_configure "$build_type" "--prefix=$appdir"; then echo "❌ AppImage meson configure with prefix /app failed!" >&2 exit 1 fi @@ -267,6 +286,11 @@ while [[ $# -gt 0 ]]; do COMPILE_FLAGS+=("${flags_array[@]}") shift ;; + --configure-flags=*) + read -r -a flags_array <<< "${1#*=}" + CONFIGURE_FLAGS+=("${flags_array[@]}") + shift + ;; --install-flags=*) read -r -a flags_array <<< "${1#*=}" INSTALL_FLAGS+=("${flags_array[@]}") From be7bf0259eb7049fac7357805623f1eb40b456b6 Mon Sep 17 00:00:00 2001 From: mcarans Date: Mon, 13 Jul 2026 11:16:03 +1200 Subject: [PATCH 22/23] Fix release --- .github/workflows/build-all.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-all.yaml b/.github/workflows/build-all.yaml index 6c5748a29..af26d4716 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/build-all.yaml @@ -65,7 +65,7 @@ jobs: - name: Archive installer uses: actions/upload-artifact@v6 with: - name: oolite-linux-${{matrix.flavour}} + name: oolite-linux-appimage-${{matrix.flavour}} path: | build/oolite*.AppImage retention-days: 5 @@ -101,7 +101,7 @@ jobs: - name: Archive installer uses: actions/upload-artifact@v6 with: - name: oolite-flatpak + name: oolite-linux-flatpak-deployment path: | build/space.oolite.Oolite*.flatpak retention-days: 5 @@ -160,7 +160,7 @@ jobs: - name: Archive installer uses: actions/upload-artifact@v6 with: - name: oolite-windows-${{matrix.flavour}} + name: oolite-windows-nsis-${{matrix.flavour}} path: | build/OoliteInstall*.exe retention-days: 5 @@ -228,13 +228,13 @@ jobs: prerelease: true title: "Oolite ${{ steps.version.outputs.VER_FULL }}" files: | - artifacts/oolite-windows-pkg-win-deployment/OoliteInstall-*.exe - artifacts/oolite-windows-pkg-win-test/OoliteInstall-*.exe - artifacts/oolite-windows-pkg-win-dev/OoliteInstall-*-dev.exe - artifacts/oolite-linux-pkg-appimage-deployment/*.AppImage - artifacts/oolite-linux-pkg-appimage-test/*.AppImage - artifacts/oolite-linux-pkg-appimage-dev/*.AppImage - artifacts/oolite-flatpak/*.flatpak + artifacts/oolite-windows-nsis-deployment/OoliteInstall-*.exe + artifacts/oolite-windows-nsis-test/OoliteInstall-*.exe + artifacts/oolite-windows-nsis-dev/OoliteInstall-*-dev.exe + artifacts/oolite-linux-appimage-deployment/*.AppImage + artifacts/oolite-linux-appimage-test/*.AppImage + artifacts/oolite-linux-appimage-dev/*.AppImage + artifacts/oolite-linux-flatpak-deployment/*.flatpak - name: Remove old workflow runs if: github.ref == 'refs/heads/master' || endsWith(github.ref, 'maintenance') uses: Mattraks/delete-workflow-runs@v2 From 570a59545f2f730887cec4868954095fdb797388 Mon Sep 17 00:00:00 2001 From: mcarans Date: Tue, 14 Jul 2026 07:12:24 +1200 Subject: [PATCH 23/23] Update README for clean step --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a36f15d33..642ccb527 100644 --- a/README.md +++ b/README.md @@ -149,11 +149,11 @@ Optionally you can pass `--setup-flags` and/or `--compile-flags` to pass specifi build dev runs 2 actions which can be run independently: `setup dev` which runs meson setup and `compile dev` which runs meson compile. -Subsequently, you can clean and build the development build as follows: +If for some reason the build fails, you can try cleaning the build folder first, although meson should not usually +require this step: ```bash ./mk.sh clean dev -./mk.sh build dev ``` You can run a test of the development build that launches the game and takes a snapshot from your Bash or MSYS2 prompt