From 9f4af75f097ff9a18cf3a45a48d7732b6efc81fc Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 21:12:57 +0200 Subject: [PATCH 01/20] ccache stats --- .ci/compile.sh | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index ee846897b..2a74117de 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -164,16 +164,6 @@ fi # Add cmake --build flags buildflags=(--config "$BUILDTYPE") -function ccachestatsverbose() { - # note, verbose only works on newer ccache, discard the error - local got - if got="$(ccache --show-stats --verbose 2>/dev/null)"; then - echo "$got" - else - ccache --show-stats - fi -} - # Compile if [[ $RUNNER_OS == macOS ]]; then # QTDIR is needed for macOS since we actually only use the cached thin Qt binaries instead of the install-qt-action, @@ -258,8 +248,14 @@ elif [[ $RUNNER_OS == Windows ]]; then fi if [[ $USE_CCACHE ]]; then - echo "::group::Show ccache stats" - ccachestatsverbose + echo "::group::Clear ccache stats" + # https://ccache.dev/manual/4.13.6.html#_command_line_options + ccache --version + ccache --show-config + ccache --show-stats # remove again + ccache --show-log-stats # helpful? + ccache --zero-stats # zero former cache statistics (but not the configuration options) + ccache --show-stats # helpful? echo "::endgroup::" fi @@ -280,8 +276,10 @@ if [[ $USE_CCACHE ]]; then ccache --evict-older-than "$CCACHE_EVICTION_AGE" echo "::endgroup::" fi - echo "::group::Show ccache stats again" - ccachestatsverbose + echo "::group::Show ccache stats" + ccache --verify # remove again + ccache --show-stats --verbose # too verbose? + ccache --show-compression # helpful? echo "::endgroup::" elif [[ $CCACHE_EVICTION_AGE ]]; then echo "::error file=$0::ccache eviction is enabled while ccache is disabled!" From f9997328c614e8445cf048d9389195533f536012 Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 22:36:52 +0200 Subject: [PATCH 02/20] comments --- .ci/compile.sh | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 2a74117de..8a381df93 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -130,13 +130,14 @@ fi if [[ ! $BUILD_DIR ]]; then BUILD_DIR="build" fi +# TODO check BUILD_DIR logic mkdir -p "$BUILD_DIR" cd "$BUILD_DIR" # Set minimum CMake Version export CMAKE_POLICY_VERSION_MINIMUM=3.10 -# Add cmake flags +# Add CMake flags flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE") if [[ $MAKE_SERVER ]]; then flags+=("-DWITH_SERVER=1") @@ -150,7 +151,7 @@ fi if [[ $USE_CCACHE ]]; then flags+=("-DUSE_CCACHE=1") if [[ $CCACHE_SIZE ]]; then - # note, this setting persists after running the script + # Note, this setting persists after running the script ccache --max-size "$CCACHE_SIZE" fi fi @@ -161,11 +162,12 @@ if [[ $USE_VCPKG ]]; then flags+=("-DUSE_VCPKG=1") fi -# Add cmake --build flags +# Add CMake --build flags buildflags=(--config "$BUILDTYPE") -# Compile +# Prepare compilation if [[ $RUNNER_OS == macOS ]]; then +# TODO qtdir # QTDIR is needed for macOS since we actually only use the cached thin Qt binaries instead of the install-qt-action, # which sets a few environment variables if QTDIR=$(find "$GITHUB_WORKSPACE/Qt" -depth -maxdepth 2 -name macos -type d -print -quit); then @@ -174,17 +176,17 @@ if [[ $RUNNER_OS == macOS ]]; then echo "could not find QTDIR!" exit 2 fi - # the qtdir is located at Qt/[qtversion]/macos - # we use find to get the first subfolder with the name "macos" - # this works independent of the qt version as there should be only one version installed on the runner at a time + # The qtdir is located at Qt//macos + # We use "find" to get the first subfolder with the name "macos" + # This works independent of the Qt version as there should be only one version installed on the runner at a time export QTDIR if [[ $TARGET_MACOS_VERSION ]]; then - # CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla cmake flag needed to compile to target macOS version + # CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla CMake flag needed to compile to target macOS version flags+=("-DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_MACOS_VERSION") # vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version - # an easy way is to copy the x64-osx.cmake file and modify it + # An easy way is to copy the x64-osx.cmake file and modify it triplets_dir="/tmp/cmake/triplets" triplet_version="custom-triplet" triplet_file="$triplets_dir/$triplet_version.cmake" @@ -225,7 +227,7 @@ if [[ $RUNNER_OS == macOS ]]; then if [[ $MAKE_PACKAGE ]]; then # Workaround https://github.com/actions/runner-images/issues/7522 - # have hdiutil repeat the command 10 times in hope of success + # Have hdiutil repeat the command 10 times in hope of success hdiutil_script="/tmp/hdiutil.sh" # shellcheck disable=SC2016 echo '#!/bin/bash @@ -242,11 +244,12 @@ if [[ $RUNNER_OS == macOS ]]; then fi elif [[ $RUNNER_OS == Windows ]]; then - # Enable MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ + # Enable MSBuild switches for MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ # and https://devblogs.microsoft.com/cppblog/cpp-build-throughput-investigation-and-tune-up/#multitooltask-mtt buildflags+=(-- -p:UseMultiToolTask=true -p:EnableClServerMode=true) fi +# Pre-build ccache if [[ $USE_CCACHE ]]; then echo "::group::Clear ccache stats" # https://ccache.dev/manual/4.13.6.html#_command_line_options @@ -259,17 +262,20 @@ if [[ $USE_CCACHE ]]; then echo "::endgroup::" fi -echo "::group::Configure cmake" +# Configure CMake +echo "::group::Configure CMake" cmake --version -echo "Running cmake with flags: ${flags[*]}" +echo "Running CMake configuration with following flags: ${flags[*]}" cmake .. "${flags[@]}" echo "::endgroup::" +# Build echo "::group::Build project" -echo "Running cmake --build with flags: ${buildflags[*]}" +echo "Running CMake with following build flags: ${buildflags[*]}" cmake --build . "${buildflags[@]}" echo "::endgroup::" +# Post-build ccache if [[ $USE_CCACHE ]]; then if [[ $CCACHE_EVICTION_AGE ]]; then echo "::group::evict ccache files older than $CCACHE_EVICTION_AGE" @@ -285,6 +291,7 @@ elif [[ $CCACHE_EVICTION_AGE ]]; then echo "::error file=$0::ccache eviction is enabled while ccache is disabled!" fi +# [macOS] Inspect binaries if [[ $RUNNER_OS == macOS ]]; then echo "::group::Inspect Mach-O binaries" for app in cockatrice oracle servatrice; do @@ -298,18 +305,21 @@ if [[ $RUNNER_OS == macOS ]]; then echo "::endgroup::" fi + # Test if [[ $MAKE_TEST ]]; then echo "::group::Run tests" ctest -C "$BUILDTYPE" --output-on-failure echo "::endgroup::" fi +# Install if [[ $MAKE_INSTALL ]]; then echo "::group::Install" cmake --build . --target install --config "$BUILDTYPE" echo "::endgroup::" fi +# Package if [[ $MAKE_PACKAGE ]]; then echo "::group::Create package" cmake --build . --target package --config "$BUILDTYPE" From 4cb5eb31e23a928d65d216d78833081568fe728e Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 22:50:02 +0200 Subject: [PATCH 03/20] cmake commands --- .ci/compile.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 8a381df93..c3a32fa37 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -131,8 +131,6 @@ if [[ ! $BUILD_DIR ]]; then BUILD_DIR="build" fi # TODO check BUILD_DIR logic -mkdir -p "$BUILD_DIR" -cd "$BUILD_DIR" # Set minimum CMake Version export CMAKE_POLICY_VERSION_MINIMUM=3.10 @@ -266,13 +264,14 @@ fi echo "::group::Configure CMake" cmake --version echo "Running CMake configuration with following flags: ${flags[*]}" -cmake .. "${flags[@]}" +cmake -S . -B "$BUILD_DIR" "${flags[@]}" +# cmake -S .. -B "$BUILD_DIR" "${flags[@]}" echo "::endgroup::" # Build echo "::group::Build project" echo "Running CMake with following build flags: ${buildflags[*]}" -cmake --build . "${buildflags[@]}" +cmake --build "$BUILD_DIR" "${buildflags[@]}" echo "::endgroup::" # Post-build ccache @@ -308,26 +307,28 @@ fi # Test if [[ $MAKE_TEST ]]; then echo "::group::Run tests" - ctest -C "$BUILDTYPE" --output-on-failure + ctest --version + ctest --build-config "$BUILDTYPE" --test-dir "$BUILD_DIR" --output-on-failure echo "::endgroup::" fi # Install if [[ $MAKE_INSTALL ]]; then echo "::group::Install" - cmake --build . --target install --config "$BUILDTYPE" + cmake --build "$BUILD_DIR" --target install --config "$BUILDTYPE" + # cmake --install "$BUILD_DIR" --config "$BUILDTYPE" echo "::endgroup::" fi # Package if [[ $MAKE_PACKAGE ]]; then echo "::group::Create package" - cmake --build . --target package --config "$BUILDTYPE" + cpack --version + cmake --build "$BUILD_DIR" --target package --config "$BUILDTYPE" echo "::endgroup::" if [[ $PACKAGE_SUFFIX ]]; then echo "::group::Update package name" - cd .. BUILD_DIR="$BUILD_DIR" .ci/name_build.sh "$PACKAGE_SUFFIX" echo "::endgroup::" fi From a253d0344a60fd855618a06002a09a41edb1415f Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 22:50:37 +0200 Subject: [PATCH 04/20] cleanup --- .ci/compile.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index c3a32fa37..46588febb 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -132,9 +132,6 @@ if [[ ! $BUILD_DIR ]]; then fi # TODO check BUILD_DIR logic -# Set minimum CMake Version -export CMAKE_POLICY_VERSION_MINIMUM=3.10 - # Add CMake flags flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE") if [[ $MAKE_SERVER ]]; then From 3d2dedd0071cad7519405870a9e62669c242bee6 Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 22:56:29 +0200 Subject: [PATCH 05/20] readability --- .ci/compile.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.ci/compile.sh b/.ci/compile.sh index 46588febb..d5321cc95 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -127,6 +127,7 @@ set -e if [[ ! $BUILDTYPE ]]; then BUILDTYPE=Release fi + if [[ ! $BUILD_DIR ]]; then BUILD_DIR="build" fi @@ -137,12 +138,15 @@ flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE") if [[ $MAKE_SERVER ]]; then flags+=("-DWITH_SERVER=1") fi + if [[ $MAKE_NO_CLIENT ]]; then flags+=("-DWITH_CLIENT=0" "-DWITH_ORACLE=0") fi + if [[ $MAKE_TEST ]]; then flags+=("-DTEST=1") fi + if [[ $USE_CCACHE ]]; then flags+=("-DUSE_CCACHE=1") if [[ $CCACHE_SIZE ]]; then @@ -150,9 +154,11 @@ if [[ $USE_CCACHE ]]; then ccache --max-size "$CCACHE_SIZE" fi fi + if [[ $PACKAGE_TYPE ]]; then flags+=("-DCPACK_GENERATOR=$PACKAGE_TYPE") fi + if [[ $USE_VCPKG ]]; then flags+=("-DUSE_VCPKG=1") fi @@ -163,6 +169,7 @@ buildflags=(--config "$BUILDTYPE") # Prepare compilation if [[ $RUNNER_OS == macOS ]]; then # TODO qtdir + # QTDIR is needed for macOS since we actually only use the cached thin Qt binaries instead of the install-qt-action, # which sets a few environment variables if QTDIR=$(find "$GITHUB_WORKSPACE/Qt" -depth -maxdepth 2 -name macos -type d -print -quit); then @@ -171,6 +178,7 @@ if [[ $RUNNER_OS == macOS ]]; then echo "could not find QTDIR!" exit 2 fi + # The qtdir is located at Qt//macos # We use "find" to get the first subfolder with the name "macos" # This works independent of the Qt version as there should be only one version installed on the runner at a time @@ -186,14 +194,18 @@ if [[ $RUNNER_OS == macOS ]]; then triplet_version="custom-triplet" triplet_file="$triplets_dir/$triplet_version.cmake" arch=$(uname -m) + if [[ $arch == x86_64 ]]; then arch="x64" fi + mkdir -p "$triplets_dir" triplet_source="../vcpkg/triplets/$arch-osx.cmake" + if [[ ! -f "$triplet_source" ]]; then triplet_source="../vcpkg/triplets/community/$arch-osx.cmake" fi + cp "$triplet_source" "$triplet_file" echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file" echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file" @@ -206,6 +218,7 @@ if [[ $RUNNER_OS == macOS ]]; then fi echo "::group::Signing Certificate" + if [[ -n "$MACOS_CERTIFICATE_NAME" ]]; then echo "$MACOS_CERTIFICATE" | base64 --decode >"certificate.p12" security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain @@ -218,6 +231,7 @@ if [[ $RUNNER_OS == macOS ]]; then else echo "No signing certificate configured. Skipping set up of keychain in macOS environment." fi + echo "::endgroup::" if [[ $MAKE_PACKAGE ]]; then @@ -273,23 +287,28 @@ echo "::endgroup::" # Post-build ccache if [[ $USE_CCACHE ]]; then + if [[ $CCACHE_EVICTION_AGE ]]; then echo "::group::evict ccache files older than $CCACHE_EVICTION_AGE" ccache --evict-older-than "$CCACHE_EVICTION_AGE" echo "::endgroup::" fi + echo "::group::Show ccache stats" ccache --verify # remove again ccache --show-stats --verbose # too verbose? ccache --show-compression # helpful? echo "::endgroup::" + elif [[ $CCACHE_EVICTION_AGE ]]; then echo "::error file=$0::ccache eviction is enabled while ccache is disabled!" fi # [macOS] Inspect binaries if [[ $RUNNER_OS == macOS ]]; then + echo "::group::Inspect Mach-O binaries" + for app in cockatrice oracle servatrice; do binary="$GITHUB_WORKSPACE/build/$app/$app.app/Contents/MacOS/$app" echo "Inspecting $app..." @@ -297,6 +316,7 @@ if [[ $RUNNER_OS == macOS ]]; then file "$binary" lipo -info "$binary" echo "" + done echo "::endgroup::" fi From 5126696eb094996261d6e4beb3c8ddfc6933f4f9 Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 23:13:01 +0200 Subject: [PATCH 06/20] readability and removed duplication --- .ci/compile.sh | 55 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index d5321cc95..f95bbfcdd 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -1,22 +1,45 @@ #!/bin/bash -# This script is to be used by the ci environment from the project root directory, do not use it from somewhere else. +# This script is to be used by the CI environment from the project root directory, do not use it from somewhere else. -# Compiles cockatrice inside of a ci environment -# --install runs make install -# --package [] runs make package, optionally force the type -# --suffix renames package with this suffix, requires arg -# --server compiles servatrice -# --test runs tests -# --debug or --release sets the build type ie CMAKE_BUILD_TYPE -# --ccache [] uses ccache and shows stats, optionally provide size -# --evict-ccache runs ccache eviction based on given age after build -# --dir sets the name of the build dir, default is "build" -# --cmake-generator sets CMAKE_GENERATOR as used by cmake -# --target-macos-version sets the min os version - only used for macOS builds -# uses env: BUILDTYPE MAKE_INSTALL MAKE_PACKAGE PACKAGE_TYPE PACKAGE_SUFFIX MAKE_SERVER MAKE_NO_CLIENT MAKE_TEST USE_CCACHE CCACHE_SIZE CCACHE_EVICTION_AGE BUILD_DIR CMAKE_GENERATOR TARGET_MACOS_VERSION -# (correspond to args: --debug/--release --install --package --suffix --server --test --ccache --dir ) -# exitcode: 1 for failure, 3 for invalid arguments +# Compiles Cockatrice inside a CI environment +# +# Supported arguments: +# --install Runs cmake install +# --package [] Runs cmake package (optionally: define the type) +# --suffix Renames package with provided suffix +# --server Compiles Servatrice +# --test Runs tests +# --debug / --release Sets the build type (CMAKE_BUILD_TYPE) +# --ccache [] Uses ccache and shows stats, optionally provide size +# --evict-ccache Runs ccache eviction based on given age after build +# --dir Sets the name of the build dir, default is "build" +# --cmake-generator Sets the CMake generator (CMAKE_GENERATOR) +# --target-macos-version Sets the min OS version - only used for macOS builds +# +# Used environment variables: +# BUILDTYPE +# MAKE_INSTALL +# MAKE_PACKAGE +# PACKAGE_TYPE +# PACKAGE_SUFFIX +# MAKE_SERVER +# MAKE_NO_CLIENT +# MAKE_TEST +# USE_CCACHE +# CCACHE_SIZE +# CCACHE_EVICTION_AGE +# BUILD_DIR +# CMAKE_GENERATOR +# TARGET_MACOS_VERSION +# +# Exitcodes: +# 1 --> Failure +# 3 --> Invalid argument(s) + +#TODO order above comment, check & add +# there are also missing ones like "--no-client" and "--vcpkg" +# arguments and env variables are doubled and are not used uniformly between Linux and macOS/Windows builds which adds complexity # Read arguments while [[ $# != 0 ]]; do From 6f5e81d31be9d55acb642b42ecda60fdbf508aaf Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 23:22:04 +0200 Subject: [PATCH 07/20] cleanup --- CMakeLists.txt | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c10e1db68..477be73cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,15 +27,10 @@ option(USE_VCPKG "Use vcpkg regardless of OS" OFF) # Default to "Release" build type # User-provided value for CMAKE_BUILD_TYPE must be checked before the PROJECT() call -if(DEFINED CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE - ${CMAKE_BUILD_TYPE} - CACHE STRING "Type of build" - ) -else() +if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release - CACHE STRING "Type of build" + CACHE STRING "Build type" ) endif() @@ -87,6 +82,7 @@ set(CMAKE_CXX_STANDARD CACHE STRING "C++ ISO Standard" ) set(CMAKE_CXX_STANDARD_REQUIRED True) +set(CMAKE_CXX_EXTENSIONS OFF) # Set conventional loops set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) @@ -140,11 +136,11 @@ endif() # Define proper compilation flags if(MSVC) - # Disable Warning C4251, C++20 compatibility, Multi-threaded Builds, Warn Detection, Unwind Semantics, Debug Symbols - set(CMAKE_CXX_FLAGS "/wd4251 /Zc:__cplusplus /std:c++20 /permissive- /W4 /MP /EHsc /Zi") - # Visual Studio: Maximum Optimization, Multi-threaded DLL + # Disable Warning C4251, Enable Warning Level 4, Multi-threaded Builds, xx, Debug Symbols + set(CMAKE_CXX_FLAGS "/wd4251 /W4 /MP /EHsc /Zi") + # Maximum Optimization, Multi-threaded DLL set(CMAKE_CXX_FLAGS_RELEASE "/Ox /MD") - # Visual Studio: No Optimization, Multi-threaded Debug DLL + # No Optimization, Multi-threaded Debug DLL set(CMAKE_CXX_FLAGS_DEBUG "/Od /MDd") # Generate PDB, even when in release (So developers can better analyze crash logs) @@ -312,7 +308,7 @@ if(UNIX) endif() elseif(WIN32) set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR}) - if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "(x64)") + if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(TRICE_IS_64_BIT 1) else() set(TRICE_IS_64_BIT 0) From 4cfea8dd57ce0a190d58b9917a05b287b737ee99 Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 23:50:11 +0200 Subject: [PATCH 08/20] comments + readability --- CMakeLists.txt | 93 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 477be73cd..7a962e457 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ # Cockatrice's main CMakeLists.txt # # This is basically a wrapper to enable/disable the compilation -# of the different projects: servatrice, cockatrice, test +# of the different projects: cockatrice, servatrice, test # This file sets all the variables shared between the projects # like the installation path, compilation flags etc.. -# cmake 3.16 is required if using qt6 +# CMake 3.16 is required if using Qt6 cmake_minimum_required(VERSION 3.10) # Early detect ccache @@ -36,6 +36,7 @@ endif() if(USE_CCACHE) find_program(CCACHE_PROGRAM ccache) + if(CCACHE_PROGRAM) # Support Unix Makefiles and Ninja set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") @@ -49,6 +50,7 @@ if(WIN32 OR USE_VCPKG) ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file" ) + # Qt path set by user or env var if(QTDIR OR DEFINED ENV{QTDIR} @@ -71,12 +73,12 @@ endif() # Version can be overriden by git tags, see cmake/getversion.cmake project("Cockatrice" VERSION 3.1.0) -# Set release name if not provided via env/cmake var +# Set release name if not provided via ENV/CMake var if(NOT DEFINED GIT_TAG_RELEASENAME) set(GIT_TAG_RELEASENAME "Graduation Day") endif() -# Use c++20 for all targets +# Use C++20 for all targets set(CMAKE_CXX_STANDARD 20 CACHE STRING "C++ ISO Standard" @@ -87,7 +89,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) # Set conventional loops set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) -# Search path for cmake modules +# Search path for CMake modules set(COCKATRICE_CMAKE_PATH "${PROJECT_SOURCE_DIR}/cmake") list(INSERT CMAKE_MODULE_PATH 0 "${COCKATRICE_CMAKE_PATH}") @@ -98,14 +100,14 @@ include(createversionfile) # Define a proper install path if(UNIX) - if(APPLE) - # macOS - # Due to the special bundle structure ignore - # the prefix eventually set by the user. + + if(APPLE) # macOS + # Due to the special bundle structure ignore the prefix eventually set by the user set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/release) # Force ccache usage if available get_property(RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE) + if(RULE_LAUNCH_COMPILE) message(STATUS "Force enabling CCache usage under macOS") # Set up wrapper scripts @@ -119,39 +121,52 @@ if(UNIX) set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c") set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx") endif() - else() - # Linux / BSD + + else() # Linux / BSD if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - #fix package build + + # Fix package build if(PREFIX) set(CMAKE_INSTALL_PREFIX ${PREFIX}) else() set(CMAKE_INSTALL_PREFIX /usr/local) endif() + endif() endif() -elseif(WIN32) + +elseif(WIN32) # Windows set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/rundir/${CMAKE_BUILD_TYPE}) endif() # Define proper compilation flags -if(MSVC) - # Disable Warning C4251, Enable Warning Level 4, Multi-threaded Builds, xx, Debug Symbols +if(MSVC) # Microsoft Visual C++ compiler + # /wd4251 Suppress C4251 (DLL interface) warnings + # /W4 Enable warning level 4 + # /MP Enable multi-threaded building + # /EHsc Enable standard C++ exception handling + # /Zi Generate debugging information (Program Databases, PDBs) set(CMAKE_CXX_FLAGS "/wd4251 /W4 /MP /EHsc /Zi") - # Maximum Optimization, Multi-threaded DLL + + # /Ox Enable maximum optimization + # /MD Link against the multi-threaded DLL runtime library (Release CRT) set(CMAKE_CXX_FLAGS_RELEASE "/Ox /MD") - # No Optimization, Multi-threaded Debug DLL + + # /Od Disable optimization + # /MDd Link against the multi-threaded Debug DLL runtime library (Debug CRT) set(CMAKE_CXX_FLAGS_DEBUG "/Od /MDd") - # Generate PDB, even when in release (So developers can better analyze crash logs) + # Generate PDBs, even when in release (Allow developers to better analyze crash logs) set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF") add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) + elseif(CMAKE_COMPILER_IS_GNUCXX) - # linux/gcc, bsd/gcc, windows/mingw + # Linux/GCC, BSD/GCC, Windows/MinGW include(CheckCXXCompilerFlag) set(CMAKE_CXX_FLAGS_RELEASE "-s -O2") + if(WARNING_AS_ERROR) set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0 -Wall -Wextra -Werror") else() @@ -170,23 +185,26 @@ elseif(CMAKE_COMPILER_IS_GNUCXX) -Wno-error=delete-non-virtual-dtor -Wno-error=sign-compare -Wno-error=missing-declarations - -Wno-error=sfinae-incomplete # GCC 16+: Qt MOC + protobuf forward decls trigger this + -Wno-error=sfinae-incomplete # GCC 16+: Qt MOC + protobuf forward declarations trigger this ) foreach(FLAG ${ADDITIONAL_DEBUG_FLAGS}) check_cxx_compiler_flag("${FLAG}" CXX_HAS_WARNING_${FLAG}) + if(CXX_HAS_WARNING_${FLAG}) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}") endif() endforeach() -else() - # other: osx/llvm, bsd/llvm + +else() # Other: macOS/LLVM, BSD/LLVM set(CMAKE_CXX_FLAGS_RELEASE "-O2") + if(WARNING_AS_ERROR) set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra -Werror -Wno-unused-parameter") else() set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra") endif() + endif() # GNU systems need to define the Mersenne exponent for the RNG to compile w/o warning @@ -221,6 +239,7 @@ set(CMAKE_AUTOMOC TRUE) # Find other needed libraries find_package(Protobuf CONFIG) + if(NOT Protobuf_FOUND) find_package(Protobuf REQUIRED) endif() @@ -229,9 +248,11 @@ if(${Protobuf_VERSION} VERSION_LESS "3.21.0.0" AND NOT EXISTS "${Protobuf_PROTOC message(FATAL_ERROR "No protoc command found!") endif() -#Find OpenSSL +# Find OpenSSL if(WIN32) + find_package(OpenSSL REQUIRED) + if(OPENSSL_FOUND) include_directories(${OPENSSL_INCLUDE_DIRS}) else() @@ -242,7 +263,7 @@ if(WIN32) endif() endif() -#Find VCredist +# Find Visual C++ Redistributable if(MSVC) find_package(VCredistRuntime) endif() @@ -252,7 +273,9 @@ set(CPACK_PACKAGE_CONTACT "Zach Halpern ") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_NAME}") set(CPACK_PACKAGE_VENDOR "Cockatrice Development Team") set(CPACK_PACKAGE_DESCRIPTION - "Cockatrice is an open-source, multiplatform application for playing tabletop card games over a network. The program's server design prevents users from manipulating the game for unfair advantage. The client also provides a single-player mode, which allows users to brew while offline." + "Cockatrice is an open-source, multiplatform application for playing tabletop card games over a network. \ + The program's server design prevents users from manipulating the game for unfair advantage. \ + The client also provides a single-player mode, which allows users to brew while offline." ) set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") @@ -261,7 +284,8 @@ set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") set(CPACK_PACKAGE_FILE_NAME "${PROJECT_VERSION_FILENAME}") if(UNIX) - if(APPLE) + + if(APPLE) # macOS set(CPACK_GENERATOR DragNDrop ${CPACK_GENERATOR}) set(CPACK_GENERATOR "DragNDrop") set(CPACK_DMG_FORMAT "UDBZ") @@ -271,8 +295,8 @@ if(UNIX) set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeDMGSetup.script") set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/dmgBackground.tif") set(CPACK_PRE_BUILD_SCRIPTS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/SignMacApplications.cmake") - else() - # linux + + else() # Linux if(CPACK_GENERATOR STREQUAL "RPM") set(CPACK_RPM_PACKAGE_LICENSE "GPLv2") set(CPACK_RPM_MAIN_COMPONENT "cockatrice") @@ -283,7 +307,7 @@ if(UNIX) endif() set(CPACK_RPM_PACKAGE_GROUP "Amusements/Games") set(CPACK_RPM_PACKAGE_URL "http://github.com/Cockatrice/Cockatrice") - # stop directories from making package conflicts + # Stop directories from creating package conflicts set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/share/applications /usr/share/icons @@ -300,13 +324,14 @@ if(UNIX) set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://github.com/Cockatrice/Cockatrice") if(Qt6_FOUND) set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt6multimedia6, libqt6svg6, qt6-qpa-plugins, qt6-image-formats-plugins") - set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libqt6sql6-mysql") # for connecting servatrice to a mysql db + set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "libqt6sql6-mysql") # for connecting Servatrice to a MySQL DB elseif(Qt5_FOUND) set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5multimedia5-plugins, libqt5svg5") endif() endif() endif() -elseif(WIN32) + +elseif(WIN32) # Windows set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR}) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(TRICE_IS_64_BIT 1) @@ -314,10 +339,10 @@ elseif(WIN32) set(TRICE_IS_64_BIT 0) endif() - # Configure file with custom definitions for NSIS. + # Configure file with custom definitions for NSIS configure_file("${COCKATRICE_CMAKE_PATH}/NSIS.definitions.nsh.in" "${PROJECT_BINARY_DIR}/NSIS.definitions.nsh") - # include vcredist into the package; NSIS will take care of running it + # Include vcredist into the package, NSIS will take care of running it if(VCREDISTRUNTIME_FOUND) install(FILES "${VCREDISTRUNTIME_FILE}" DESTINATION ./) endif() @@ -364,6 +389,6 @@ if(TEST) endif() if(Qt6_FOUND AND Qt6_VERSION_MINOR GREATER_EQUAL 3) - # Qt6.3+ requires project finalization to support translations + # Qt 6.3+ requires project finalization to support translations qt6_finalize_project() endif() From de6e16e2ff20ed4cff46aa78fe4740836ee93680 Mon Sep 17 00:00:00 2001 From: tooomm Date: Fri, 24 Jul 2026 23:56:25 +0200 Subject: [PATCH 09/20] comments + choco flag --- .github/workflows/desktop-build.yml | 2 +- servatrice/check_schema_version.sh | 2 +- tests/CMakeLists.txt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index f1846ecf6..2786dac21 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -422,7 +422,7 @@ jobs: - name: "[Windows] Install NSIS" if: matrix.os == 'Windows' shell: bash - run: choco install nsis + run: choco install nsis --no-progress - name: "Setup vcpkg cache" id: vcpkg-cache diff --git a/servatrice/check_schema_version.sh b/servatrice/check_schema_version.sh index c4aadf356..8b645b5d2 100755 --- a/servatrice/check_schema_version.sh +++ b/servatrice/check_schema_version.sh @@ -10,7 +10,7 @@ declare -i schema_ver="${version_line%%)*}" latest_migration="$(ls -1 servatrice/migrations/ | tail -n1)" xtoysql="${latest_migration#servatrice_}" xtoy="${xtoysql%.sql}" -declare -i old_ver="10#${xtoy%_to_*}" #declare as integer with base 10, numbers with a leading 0 are normally interpreted as base 16 +declare -i old_ver="10#${xtoy%_to_*}" # declare as integer with base 10, numbers with a leading 0 are normally interpreted as base 16 declare -i new_ver="10#${xtoy#*_to_}" if ((old_ver >= new_ver)); then diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a179a3603..94a7327d4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,10 +11,9 @@ add_test(NAME server_card_counter_test COMMAND server_card_counter_test) add_test(NAME server_counter_test COMMAND server_counter_test) add_test(NAME deck_hash_performance_test COMMAND deck_hash_performance_test) +set_tests_properties(dummy_test PROPERTIES TIMEOUT 5) set_tests_properties(deck_hash_performance_test PROPERTIES TIMEOUT 5) -# Find GTest - add_executable(dummy_test dummy_test.cpp) add_executable(expression_test expression_test.cpp) add_executable(clamped_arithmetic_test clamped_arithmetic_test.cpp) @@ -24,6 +23,7 @@ add_executable(deck_hash_performance_test deck_hash_performance_test.cpp) add_executable(server_card_counter_test server_card_counter_test.cpp) add_executable(server_counter_test server_counter_test.cpp) +# Find GTest find_package(GTest) if(NOT GTEST_FOUND) From d60da410d45d62b3e16b8caf8b617a990287ab30 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 25 Jul 2026 00:04:16 +0200 Subject: [PATCH 10/20] add missing arguments + order --- .ci/compile.sh | 51 +++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index f95bbfcdd..6b8830144 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -5,40 +5,41 @@ # Compiles Cockatrice inside a CI environment # # Supported arguments: -# --install Runs cmake install -# --package [] Runs cmake package (optionally: define the type) -# --suffix Renames package with provided suffix -# --server Compiles Servatrice -# --test Runs tests -# --debug / --release Sets the build type (CMAKE_BUILD_TYPE) # --ccache [] Uses ccache and shows stats, optionally provide size -# --evict-ccache Runs ccache eviction based on given age after build -# --dir Sets the name of the build dir, default is "build" # --cmake-generator Sets the CMake generator (CMAKE_GENERATOR) +# --debug / --release Sets the build type (CMAKE_BUILD_TYPE) +# --dir Sets the name of the build dir, default is "build" +# --evict-ccache Runs ccache eviction based on given age after build +# --install Runs cmake install +# --no-client x +# --package [] Runs cmake package (optionally: define the type) +# --server Compiles Servatrice +# --suffix Renames package with provided suffix # --target-macos-version Sets the min OS version - only used for macOS builds +# --test Runs tests +# --vcpkg x # # Used environment variables: -# BUILDTYPE -# MAKE_INSTALL -# MAKE_PACKAGE -# PACKAGE_TYPE -# PACKAGE_SUFFIX -# MAKE_SERVER -# MAKE_NO_CLIENT -# MAKE_TEST -# USE_CCACHE -# CCACHE_SIZE -# CCACHE_EVICTION_AGE -# BUILD_DIR -# CMAKE_GENERATOR -# TARGET_MACOS_VERSION +# BUILDTYPE x +# BUILD_DIR x +# CCACHE_EVICTION_AGE x +# CCACHE_SIZE x +# CMAKE_GENERATOR x +# MAKE_INSTALL x +# MAKE_NO_CLIENT x +# MAKE_PACKAGE x +# MAKE_SERVER x +# MAKE_TEST x +# PACKAGE_SUFFIX x +# PACKAGE_TYPE x +# TARGET_MACOS_VERSION x +# USE_CCACHE x # -# Exitcodes: +# Exit codes: # 1 --> Failure # 3 --> Invalid argument(s) -#TODO order above comment, check & add -# there are also missing ones like "--no-client" and "--vcpkg" +#TODO check & add missing arguments/variables above # arguments and env variables are doubled and are not used uniformly between Linux and macOS/Windows builds which adds complexity # Read arguments From fe6d11f1459e389f1c9dc8228ed40aa32f880103 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 25 Jul 2026 16:50:06 +0200 Subject: [PATCH 11/20] ordering + comments --- .ci/compile.sh | 330 +++++++++++++++++++++++++++---------------------- 1 file changed, 183 insertions(+), 147 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 6b8830144..c5a2ec711 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -1,57 +1,122 @@ #!/bin/bash -# This script is to be used by the CI environment from the project root directory, do not use it from somewhere else. +## This script is to be used by the CI environment from the project root directory, do not use it from somewhere else # Compiles Cockatrice inside a CI environment # -# Supported arguments: -# --ccache [] Uses ccache and shows stats, optionally provide size -# --cmake-generator Sets the CMake generator (CMAKE_GENERATOR) -# --debug / --release Sets the build type (CMAKE_BUILD_TYPE) -# --dir Sets the name of the build dir, default is "build" -# --evict-ccache Runs ccache eviction based on given age after build -# --install Runs cmake install -# --no-client x -# --package [] Runs cmake package (optionally: define the type) -# --server Compiles Servatrice -# --suffix Renames package with provided suffix -# --target-macos-version Sets the min OS version - only used for macOS builds -# --test Runs tests -# --vcpkg x +# Supported options: +# --ccache [] Use ccache (USE_CCACHE) (optionally: provide cache size, e.g. "500M" or "1G" (CCACHE_SIZE)) +# --cmake-generator Sets the CMake generator (CMAKE_GENERATOR), e.g. "Ninja", "Visual Studio 18 2026" +# --debug / --release Sets the build type (BUILDTYPE --> CMAKE_BUILD_TYPE) +# --dir Sets the name of the build dir (BUILD_DIR) +# --evict-ccache Evicts compiler cache older than after build (CCACHE_EVICTION_AGE), e.g. "7d" +# --install Runs cmake install (MAKE_INSTALL) +# --no-client Compiles without Cockatrice (MAKE_NO_CLIENT) +# --package [] Runs cmake package (MAKE_PACKAGE) (optionally: define type (PACKAGE_TYPE)), e.g. "DEB" [Linux only?] +# --release Sets the build type (BUILDTYPE --> CMAKE_BUILD_TYPE) +# --server Compiles Servatrice (MAKE_SERVER) +# --suffix Renames package with provided suffix (PACKAGE_SUFFIX), e.g. "-macOS15" +# --target-macos-version Sets the min OS version (TARGET_MACOS_VERSION), e.g. "14" [macOS only] +# --test Runs tests (MAKE_TEST) +# --vcpkg Use vcpkg package manager to resolve dependencies (USE_VCPKG) # # Used environment variables: -# BUILDTYPE x -# BUILD_DIR x -# CCACHE_EVICTION_AGE x -# CCACHE_SIZE x -# CMAKE_GENERATOR x -# MAKE_INSTALL x -# MAKE_NO_CLIENT x -# MAKE_PACKAGE x -# MAKE_SERVER x -# MAKE_TEST x -# PACKAGE_SUFFIX x -# PACKAGE_TYPE x -# TARGET_MACOS_VERSION x -# USE_CCACHE x +# BUILDTYPE Build type to be used by CMake and buildsystem (defaults to "Release" if omitted) +# See "--debug" and "--release" flags +# BUILD_DIR See value for "--dir" option (defaults to "build" if omitted) +# CCACHE_EVICTION_AGE See value for "--evict-ccache" option +# CCACHE_SIZE See value for "--ccache" option +# CMAKE_GENERATOR See "--cmake-generator" option +# MAKE_INSTALL See "--install" flag +# MAKE_NO_CLIENT See "--no-client" flag +# MAKE_PACKAGE See "--package" option +# MAKE_SERVER See "--server" flag +# MAKE_TEST See "--test" flag +# PACKAGE_SUFFIX See "--suffix" option +# PACKAGE_TYPE See value for "--package" option +# TARGET_MACOS_VERSION See "--target-macos-version" option +# USE_CCACHE See "--ccache" option +# USE_VCPKG See "--vcpkg" flag # # Exit codes: # 1 --> Failure # 3 --> Invalid argument(s) -#TODO check & add missing arguments/variables above -# arguments and env variables are doubled and are not used uniformly between Linux and macOS/Windows builds which adds complexity +# TODO flags/options and env variables are doubled (and just proxying some tool variables) and are not used uniformly between Linux and macOS/Windows builds which adds complexity -# Read arguments +set -e + +## Read options +#TODO group only alphabetically and put flag/option to comments above with no "argument"/"boolean flag" and "accept an argument"/"options with values"? while [[ $# != 0 ]]; do case "$1" in - '--') + + # Flags (no argument) + '--debug') + BUILDTYPE="Debug" shift ;; '--install') MAKE_INSTALL=1 shift ;; + '--no-client') + MAKE_NO_CLIENT=1 + shift + ;; + '--release') + BUILDTYPE="Release" + shift + ;; + '--server') + MAKE_SERVER=1 + shift + ;; + '--test') + MAKE_TEST=1 + shift + ;; + '--vcpkg') + USE_VCPKG=1 + shift + ;; + + # Options (accept an argument) + '--ccache') + USE_CCACHE=1 + shift + if [[ $# != 0 && ${1:0:1} != - ]]; then + CCACHE_SIZE="$1" + shift + fi + ;; + '--cmake-generator') + shift + if [[ $# == 0 ]]; then + echo "::error file=$0::--cmake-generator expects an argument" + exit 3 + fi + export CMAKE_GENERATOR=$1 + shift + ;; + '--dir') + shift + if [[ $# == 0 ]]; then + echo "::error file=$0::--dir expects an argument" + exit 3 + fi + BUILD_DIR="$1" + shift + ;; + '--evict-ccache') + shift + if [[ $# == 0 ]]; then + echo "::error file=$0::--evict-ccache expects an argument" + exit 3 + fi + CCACHE_EVICTION_AGE=$1 + shift + ;; '--package') MAKE_PACKAGE=1 shift @@ -69,65 +134,6 @@ while [[ $# != 0 ]]; do PACKAGE_SUFFIX="$1" shift ;; - '--server') - MAKE_SERVER=1 - shift - ;; - '--no-client') - MAKE_NO_CLIENT=1 - shift - ;; - '--test') - MAKE_TEST=1 - shift - ;; - '--debug') - BUILDTYPE="Debug" - shift - ;; - '--release') - BUILDTYPE="Release" - shift - ;; - '--ccache') - USE_CCACHE=1 - shift - if [[ $# != 0 && ${1:0:1} != - ]]; then - CCACHE_SIZE="$1" - shift - fi - ;; - '--evict-ccache') - shift - if [[ $# == 0 ]]; then - echo "::error file=$0::--evict-ccache expects an argument" - exit 3 - fi - CCACHE_EVICTION_AGE=$1 - shift - ;; - '--vcpkg') - USE_VCPKG=1 - shift - ;; - '--dir') - shift - if [[ $# == 0 ]]; then - echo "::error file=$0::--dir expects an argument" - exit 3 - fi - BUILD_DIR="$1" - shift - ;; - '--cmake-generator') - shift - if [[ $# == 0 ]]; then - echo "::error file=$0::--cmake-generator expects an argument" - exit 3 - fi - export CMAKE_GENERATOR=$1 - shift - ;; '--target-macos-version') shift if [[ $# == 0 ]]; then @@ -137,6 +143,8 @@ while [[ $# != 0 ]]; do TARGET_MACOS_VERSION="$1" shift ;; + + # Unknown options *) echo "::error file=$0::unrecognized option: $1" exit 3 @@ -144,56 +152,68 @@ while [[ $# != 0 ]]; do esac done -set -e -# Setup +## Set defaults ./servatrice/check_schema_version.sh if [[ ! $BUILDTYPE ]]; then - BUILDTYPE=Release + BUILDTYPE="Release" fi if [[ ! $BUILD_DIR ]]; then BUILD_DIR="build" fi -# TODO check BUILD_DIR logic -# Add CMake flags + +## Prepare compilation + +# Prepare CMake options +if [[ $BUILDTYPE ]]; then flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE") -if [[ $MAKE_SERVER ]]; then - flags+=("-DWITH_SERVER=1") fi if [[ $MAKE_NO_CLIENT ]]; then flags+=("-DWITH_CLIENT=0" "-DWITH_ORACLE=0") fi -if [[ $MAKE_TEST ]]; then - flags+=("-DTEST=1") +if [[ $MAKE_SERVER ]]; then + flags+=("-DWITH_SERVER=1") fi -if [[ $USE_CCACHE ]]; then - flags+=("-DUSE_CCACHE=1") - if [[ $CCACHE_SIZE ]]; then - # Note, this setting persists after running the script - ccache --max-size "$CCACHE_SIZE" - fi +if [[ $MAKE_TEST ]]; then + flags+=("-DTEST=1") fi if [[ $PACKAGE_TYPE ]]; then flags+=("-DCPACK_GENERATOR=$PACKAGE_TYPE") fi +if [[ $USE_CCACHE ]]; then + flags+=("-DUSE_CCACHE=1") + + if [[ $CCACHE_SIZE ]]; then + # Note: Setting persists after running the script + ccache --max-size "$CCACHE_SIZE" + fi +fi + if [[ $USE_VCPKG ]]; then flags+=("-DUSE_VCPKG=1") fi -# Add CMake --build flags -buildflags=(--config "$BUILDTYPE") +# Prepare CMake --build options +if [[ $BUILDTYPE ]]; then + buildflags=(--config "$BUILDTYPE") +fi -# Prepare compilation +if [[ $RUNNER_OS == Windows ]]; then + # Enable MSBuild switches for MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ + # and https://devblogs.microsoft.com/cppblog/cpp-build-throughput-investigation-and-tune-up/#multitooltask-mtt + buildflags+=(-- -p:UseMultiToolTask=true -p:EnableClServerMode=true) +fi + +# Other OS-specific configuration (GitHub runner) if [[ $RUNNER_OS == macOS ]]; then # TODO qtdir - # QTDIR is needed for macOS since we actually only use the cached thin Qt binaries instead of the install-qt-action, # which sets a few environment variables if QTDIR=$(find "$GITHUB_WORKSPACE/Qt" -depth -maxdepth 2 -name macos -type d -print -quit); then @@ -209,36 +229,41 @@ if [[ $RUNNER_OS == macOS ]]; then export QTDIR if [[ $TARGET_MACOS_VERSION ]]; then - # CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla CMake flag needed to compile to target macOS version + # CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla CMake option needed to compile to target macOS version flags+=("-DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_MACOS_VERSION") - # vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version - # An easy way is to copy the x64-osx.cmake file and modify it - triplets_dir="/tmp/cmake/triplets" - triplet_version="custom-triplet" - triplet_file="$triplets_dir/$triplet_version.cmake" - arch=$(uname -m) + if [[ $USE_VCPKG ]]; then + echo "vcpkg triplet" + # vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version + # An easy way is to copy the x64-osx.cmake file and modify it + triplets_dir="/tmp/cmake/triplets" + triplet_version="custom-triplet" + triplet_file="$triplets_dir/$triplet_version.cmake" + arch=$(uname -m) - if [[ $arch == x86_64 ]]; then - arch="x64" + if [[ $arch == x86_64 ]]; then + arch="x64" + fi + + mkdir -p "$triplets_dir" + triplet_source="../vcpkg/triplets/$arch-osx.cmake" + + if [[ ! -f "$triplet_source" ]]; then + triplet_source="../vcpkg/triplets/community/$arch-osx.cmake" + fi + + cp "$triplet_source" "$triplet_file" + echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file" + echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file" + flags+=("-DVCPKG_OVERLAY_TRIPLETS=$triplets_dir") + flags+=("-DVCPKG_HOST_TRIPLET=$triplet_version") + flags+=("-DVCPKG_TARGET_TRIPLET=$triplet_version") + echo "::endgroup::" + + echo "::group::Generated triplet $triplet_file" + cat "$triplet_file" + echo "::endgroup::" fi - - mkdir -p "$triplets_dir" - triplet_source="../vcpkg/triplets/$arch-osx.cmake" - - if [[ ! -f "$triplet_source" ]]; then - triplet_source="../vcpkg/triplets/community/$arch-osx.cmake" - fi - - cp "$triplet_source" "$triplet_file" - echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file" - echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file" - flags+=("-DVCPKG_OVERLAY_TRIPLETS=$triplets_dir") - flags+=("-DVCPKG_HOST_TRIPLET=$triplet_version") - flags+=("-DVCPKG_TARGET_TRIPLET=$triplet_version") - echo "::group::Generated triplet $triplet_file" - cat "$triplet_file" - echo "::endgroup::" fi echo "::group::Signing Certificate" @@ -277,12 +302,17 @@ if [[ $RUNNER_OS == macOS ]]; then fi elif [[ $RUNNER_OS == Windows ]]; then - # Enable MSBuild switches for MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ - # and https://devblogs.microsoft.com/cppblog/cpp-build-throughput-investigation-and-tune-up/#multitooltask-mtt - buildflags+=(-- -p:UseMultiToolTask=true -p:EnableClServerMode=true) + : + +elif [[ $RUNNER_OS == Linux ]]; then + : + fi -# Pre-build ccache + +## Pre-build + +# ccache if [[ $USE_CCACHE ]]; then echo "::group::Clear ccache stats" # https://ccache.dev/manual/4.13.6.html#_command_line_options @@ -295,6 +325,9 @@ if [[ $USE_CCACHE ]]; then echo "::endgroup::" fi + +## Build + # Configure CMake echo "::group::Configure CMake" cmake --version @@ -303,13 +336,16 @@ cmake -S . -B "$BUILD_DIR" "${flags[@]}" # cmake -S .. -B "$BUILD_DIR" "${flags[@]}" echo "::endgroup::" -# Build +# Compile echo "::group::Build project" echo "Running CMake with following build flags: ${buildflags[*]}" cmake --build "$BUILD_DIR" "${buildflags[@]}" echo "::endgroup::" -# Post-build ccache + +## Post-build + +# ccache if [[ $USE_CCACHE ]]; then if [[ $CCACHE_EVICTION_AGE ]]; then @@ -328,9 +364,8 @@ elif [[ $CCACHE_EVICTION_AGE ]]; then echo "::error file=$0::ccache eviction is enabled while ccache is disabled!" fi -# [macOS] Inspect binaries +# Inspect binaries if [[ $RUNNER_OS == macOS ]]; then - echo "::group::Inspect Mach-O binaries" for app in cockatrice oracle servatrice; do @@ -340,12 +375,13 @@ if [[ $RUNNER_OS == macOS ]]; then file "$binary" lipo -info "$binary" echo "" - done + echo "::endgroup::" fi - # Test + +# Test if [[ $MAKE_TEST ]]; then echo "::group::Run tests" ctest --version From cb2d0c484b0b6bfe40583918f8af8671bb098341 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 25 Jul 2026 17:12:53 +0200 Subject: [PATCH 12/20] more verbose checks --- .ci/compile.sh | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index c5a2ec711..b2f5becfc 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -11,7 +11,7 @@ # --dir Sets the name of the build dir (BUILD_DIR) # --evict-ccache Evicts compiler cache older than after build (CCACHE_EVICTION_AGE), e.g. "7d" # --install Runs cmake install (MAKE_INSTALL) -# --no-client Compiles without Cockatrice (MAKE_NO_CLIENT) +# --no-client Compiles without Cockatrice and Oracle (MAKE_NO_CLIENT) # --package [] Runs cmake package (MAKE_PACKAGE) (optionally: define type (PACKAGE_TYPE)), e.g. "DEB" [Linux only?] # --release Sets the build type (BUILDTYPE --> CMAKE_BUILD_TYPE) # --server Compiles Servatrice (MAKE_SERVER) @@ -154,12 +154,14 @@ done ## Set defaults +#TODO comment on script ./servatrice/check_schema_version.sh -if [[ ! $BUILDTYPE ]]; then + +if [[ -z $BUILDTYPE ]]; then BUILDTYPE="Release" fi -if [[ ! $BUILD_DIR ]]; then +if [[ -z $BUILD_DIR ]]; then BUILD_DIR="build" fi @@ -167,43 +169,39 @@ fi ## Prepare compilation # Prepare CMake options -if [[ $BUILDTYPE ]]; then flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE") -fi -if [[ $MAKE_NO_CLIENT ]]; then +if [[ $MAKE_NO_CLIENT == 1 ]]; then flags+=("-DWITH_CLIENT=0" "-DWITH_ORACLE=0") fi -if [[ $MAKE_SERVER ]]; then +if [[ $MAKE_SERVER == 1 ]]; then flags+=("-DWITH_SERVER=1") fi -if [[ $MAKE_TEST ]]; then +if [[ $MAKE_TEST == 1 ]]; then flags+=("-DTEST=1") fi -if [[ $PACKAGE_TYPE ]]; then +if [[ -n $PACKAGE_TYPE ]]; then flags+=("-DCPACK_GENERATOR=$PACKAGE_TYPE") fi -if [[ $USE_CCACHE ]]; then +if [[ $USE_CCACHE == 1]]; then flags+=("-DUSE_CCACHE=1") - if [[ $CCACHE_SIZE ]]; then + if [[ -n $CCACHE_SIZE ]]; then # Note: Setting persists after running the script ccache --max-size "$CCACHE_SIZE" fi fi -if [[ $USE_VCPKG ]]; then +if [[ $USE_VCPKG == 1 ]]; then flags+=("-DUSE_VCPKG=1") fi # Prepare CMake --build options -if [[ $BUILDTYPE ]]; then - buildflags=(--config "$BUILDTYPE") -fi +buildflags=(--config "$BUILDTYPE") if [[ $RUNNER_OS == Windows ]]; then # Enable MSBuild switches for MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ @@ -228,11 +226,11 @@ if [[ $RUNNER_OS == macOS ]]; then # This works independent of the Qt version as there should be only one version installed on the runner at a time export QTDIR - if [[ $TARGET_MACOS_VERSION ]]; then + if [[ -n $TARGET_MACOS_VERSION ]]; then # CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla CMake option needed to compile to target macOS version flags+=("-DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_MACOS_VERSION") - if [[ $USE_VCPKG ]]; then + if [[ $USE_VCPKG == 1 ]]; then echo "vcpkg triplet" # vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version # An easy way is to copy the x64-osx.cmake file and modify it @@ -283,7 +281,7 @@ if [[ $RUNNER_OS == macOS ]]; then echo "::endgroup::" - if [[ $MAKE_PACKAGE ]]; then + if [[ $MAKE_PACKAGE == 1 ]]; then # Workaround https://github.com/actions/runner-images/issues/7522 # Have hdiutil repeat the command 10 times in hope of success hdiutil_script="/tmp/hdiutil.sh" @@ -313,7 +311,7 @@ fi ## Pre-build # ccache -if [[ $USE_CCACHE ]]; then +if [[ $USE_CCACHE == 1 ]]; then echo "::group::Clear ccache stats" # https://ccache.dev/manual/4.13.6.html#_command_line_options ccache --version @@ -346,9 +344,9 @@ echo "::endgroup::" ## Post-build # ccache -if [[ $USE_CCACHE ]]; then +if [[ $USE_CCACHE == 1 ]]; then - if [[ $CCACHE_EVICTION_AGE ]]; then + if [[ -n $CCACHE_EVICTION_AGE ]]; then echo "::group::evict ccache files older than $CCACHE_EVICTION_AGE" ccache --evict-older-than "$CCACHE_EVICTION_AGE" echo "::endgroup::" @@ -360,7 +358,7 @@ if [[ $USE_CCACHE ]]; then ccache --show-compression # helpful? echo "::endgroup::" -elif [[ $CCACHE_EVICTION_AGE ]]; then +elif [[ -n $CCACHE_EVICTION_AGE ]]; then echo "::error file=$0::ccache eviction is enabled while ccache is disabled!" fi @@ -382,7 +380,7 @@ fi # Test -if [[ $MAKE_TEST ]]; then +if [[ $MAKE_TEST == 1 ]]; then echo "::group::Run tests" ctest --version ctest --build-config "$BUILDTYPE" --test-dir "$BUILD_DIR" --output-on-failure @@ -390,7 +388,7 @@ if [[ $MAKE_TEST ]]; then fi # Install -if [[ $MAKE_INSTALL ]]; then +if [[ $MAKE_INSTALL == 1 ]]; then echo "::group::Install" cmake --build "$BUILD_DIR" --target install --config "$BUILDTYPE" # cmake --install "$BUILD_DIR" --config "$BUILDTYPE" @@ -398,13 +396,13 @@ if [[ $MAKE_INSTALL ]]; then fi # Package -if [[ $MAKE_PACKAGE ]]; then +if [[ $MAKE_PACKAGE == 1 ]]; then echo "::group::Create package" cpack --version cmake --build "$BUILD_DIR" --target package --config "$BUILDTYPE" echo "::endgroup::" - if [[ $PACKAGE_SUFFIX ]]; then + if [[ -n $PACKAGE_SUFFIX ]]; then echo "::group::Update package name" BUILD_DIR="$BUILD_DIR" .ci/name_build.sh "$PACKAGE_SUFFIX" echo "::endgroup::" From 065924a72931377999ada7807691d0ee6dc927cb Mon Sep 17 00:00:00 2001 From: tooomm Date: Sat, 25 Jul 2026 19:29:16 +0200 Subject: [PATCH 13/20] initialize variables, cli>env>defaults, modern install/packaging, db migration script guard+logging --- .ci/compile.sh | 146 +++++++++++++++-------------- servatrice/check_schema_version.sh | 23 +++-- 2 files changed, 91 insertions(+), 78 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index b2f5becfc..4225653ec 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -1,13 +1,21 @@ -#!/bin/bash +#!/usr/bin/env bash -## This script is to be used by the CI environment from the project root directory, do not use it from somewhere else +set -euo pipefail -# Compiles Cockatrice inside a CI environment +### Compiles Cockatrice inside GitHub Actions CI, run only from project root directory (GITHUB_WORKSPACE) # -# Supported options: +# Build flow and script structure: +# - Read options +# - Pre-checks (CI, Servatrice schema) +# - Prepare compilation (CMake options, OS-specific configuration) +# - Pre-buld (ccache) +# - Build (Configure, Compile) +# - Post-build (ccache, Inspect, Test, Install, Package) + +### Supported command-line options: # --ccache [] Use ccache (USE_CCACHE) (optionally: provide cache size, e.g. "500M" or "1G" (CCACHE_SIZE)) # --cmake-generator Sets the CMake generator (CMAKE_GENERATOR), e.g. "Ninja", "Visual Studio 18 2026" -# --debug / --release Sets the build type (BUILDTYPE --> CMAKE_BUILD_TYPE) +# --debug Sets the build type (BUILDTYPE --> CMAKE_BUILD_TYPE) # --dir Sets the name of the build dir (BUILD_DIR) # --evict-ccache Evicts compiler cache older than after build (CCACHE_EVICTION_AGE), e.g. "7d" # --install Runs cmake install (MAKE_INSTALL) @@ -19,35 +27,31 @@ # --target-macos-version Sets the min OS version (TARGET_MACOS_VERSION), e.g. "14" [macOS only] # --test Runs tests (MAKE_TEST) # --vcpkg Use vcpkg package manager to resolve dependencies (USE_VCPKG) -# -# Used environment variables: -# BUILDTYPE Build type to be used by CMake and buildsystem (defaults to "Release" if omitted) -# See "--debug" and "--release" flags -# BUILD_DIR See value for "--dir" option (defaults to "build" if omitted) -# CCACHE_EVICTION_AGE See value for "--evict-ccache" option -# CCACHE_SIZE See value for "--ccache" option -# CMAKE_GENERATOR See "--cmake-generator" option -# MAKE_INSTALL See "--install" flag -# MAKE_NO_CLIENT See "--no-client" flag -# MAKE_PACKAGE See "--package" option -# MAKE_SERVER See "--server" flag -# MAKE_TEST See "--test" flag -# PACKAGE_SUFFIX See "--suffix" option -# PACKAGE_TYPE See value for "--package" option -# TARGET_MACOS_VERSION See "--target-macos-version" option -# USE_CCACHE See "--ccache" option -# USE_VCPKG See "--vcpkg" flag -# -# Exit codes: + +### Initialize configuration variables: +# Precedence: command-line options > environment variables > built-in script defaults +BUILDTYPE="${BUILDTYPE:-Release}" # See "--debug" and "--release" flags (defaults to "Release" if omitted) +BUILD_DIR="${BUILD_DIR:-build}" # See value for "--dir" option (defaults to "build" if omitted) +CCACHE_EVICTION_AGE="${CCACHE_EVICTION_AGE:-}" # See value for "--evict-ccache" option +CCACHE_SIZE="${CCACHE_SIZE:-}" # See value for "--ccache" option +CMAKE_GENERATOR="${CMAKE_GENERATOR:-}" # See "--cmake-generator" option +MAKE_INSTALL="${MAKE_INSTALL:-0}" # See "--install" flag +MAKE_NO_CLIENT="${MAKE_NO_CLIENT:-0}" # See "--no-client" flag +MAKE_PACKAGE="${MAKE_PACKAGE:-0}" # See "--package" option +MAKE_SERVER="${MAKE_SERVER:-0}" # See "--server" flag +MAKE_TEST="${MAKE_TEST:-0}" # See "--test" flag +PACKAGE_SUFFIX="${PACKAGE_SUFFIX:-}" # See "--suffix" option +PACKAGE_TYPE="${PACKAGE_TYPE:-}" # See value for "--package" option +TARGET_MACOS_VERSION="${TARGET_MACOS_VERSION:-}" # See "--target-macos-version" option +USE_CCACHE="${USE_CCACHE:-0}" # See "--ccache" option +USE_VCPKG="${USE_VCPKG:-0}" # See "--vcpkg" flag + +### Exit codes: # 1 --> Failure # 3 --> Invalid argument(s) -# TODO flags/options and env variables are doubled (and just proxying some tool variables) and are not used uniformly between Linux and macOS/Windows builds which adds complexity -set -e - -## Read options -#TODO group only alphabetically and put flag/option to comments above with no "argument"/"boolean flag" and "accept an argument"/"options with values"? +### Read options while [[ $# != 0 ]]; do case "$1" in @@ -96,7 +100,7 @@ while [[ $# != 0 ]]; do echo "::error file=$0::--cmake-generator expects an argument" exit 3 fi - export CMAKE_GENERATOR=$1 + CMAKE_GENERATOR="$1" shift ;; '--dir') @@ -114,7 +118,7 @@ while [[ $# != 0 ]]; do echo "::error file=$0::--evict-ccache expects an argument" exit 3 fi - CCACHE_EVICTION_AGE=$1 + CCACHE_EVICTION_AGE="$1" shift ;; '--package') @@ -144,74 +148,81 @@ while [[ $# != 0 ]]; do shift ;; + # Positional arguments are not supported + '--') + shift + if [[ $# != 0 ]]; then + echo "::error file=$0::Unexpected positional arguments: $*" + exit 3 + fi + break + ;; + # Unknown options *) - echo "::error file=$0::unrecognized option: $1" + echo "::error file=$0::Unrecognized option: $1" exit 3 ;; esac done -## Set defaults -#TODO comment on script -./servatrice/check_schema_version.sh +### Pre-checks -if [[ -z $BUILDTYPE ]]; then - BUILDTYPE="Release" +# CI context (GitHub Actions provided environment variable) +if [[ -z ${RUNNER_OS:-} ]]; then + echo "This script requires GitHub Actions environment variable RUNNER_OS" + exit 1 fi -if [[ -z $BUILD_DIR ]]; then - BUILD_DIR="build" +# Schema version consistency +if [[ $MAKE_SERVER == 1 ]]; then + ./servatrice/check_schema_version.sh fi -## Prepare compilation +### Prepare compilation -# Prepare CMake options +# CMake options flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE") +if [[ -n $CMAKE_GENERATOR ]]; then + flags+=(-G "$CMAKE_GENERATOR") +fi if [[ $MAKE_NO_CLIENT == 1 ]]; then flags+=("-DWITH_CLIENT=0" "-DWITH_ORACLE=0") fi - if [[ $MAKE_SERVER == 1 ]]; then flags+=("-DWITH_SERVER=1") fi - if [[ $MAKE_TEST == 1 ]]; then flags+=("-DTEST=1") fi - if [[ -n $PACKAGE_TYPE ]]; then flags+=("-DCPACK_GENERATOR=$PACKAGE_TYPE") fi - -if [[ $USE_CCACHE == 1]]; then +if [[ $USE_CCACHE == 1 ]]; then flags+=("-DUSE_CCACHE=1") - if [[ -n $CCACHE_SIZE ]]; then # Note: Setting persists after running the script ccache --max-size "$CCACHE_SIZE" fi fi - if [[ $USE_VCPKG == 1 ]]; then flags+=("-DUSE_VCPKG=1") fi -# Prepare CMake --build options +# CMake --build options buildflags=(--config "$BUILDTYPE") -if [[ $RUNNER_OS == Windows ]]; then +if [[ ${RUNNER_OS:-} == "Windows" ]]; then # Enable MSBuild switches for MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ # and https://devblogs.microsoft.com/cppblog/cpp-build-throughput-investigation-and-tune-up/#multitooltask-mtt buildflags+=(-- -p:UseMultiToolTask=true -p:EnableClServerMode=true) fi -# Other OS-specific configuration (GitHub runner) -if [[ $RUNNER_OS == macOS ]]; then -# TODO qtdir +# Other OS-specific configuration (GitHub Actions runner) +if [[ ${RUNNER_OS:-} == "macOS" ]]; then # QTDIR is needed for macOS since we actually only use the cached thin Qt binaries instead of the install-qt-action, # which sets a few environment variables if QTDIR=$(find "$GITHUB_WORKSPACE/Qt" -depth -maxdepth 2 -name macos -type d -print -quit); then @@ -264,9 +275,8 @@ if [[ $RUNNER_OS == macOS ]]; then fi fi - echo "::group::Signing Certificate" - - if [[ -n "$MACOS_CERTIFICATE_NAME" ]]; then + echo "::group::Setup signing certificate" + if [[ -n $MACOS_CERTIFICATE_NAME ]]; then echo "$MACOS_CERTIFICATE" | base64 --decode >"certificate.p12" security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain security default-keychain -s build.keychain @@ -278,7 +288,6 @@ if [[ $RUNNER_OS == macOS ]]; then else echo "No signing certificate configured. Skipping set up of keychain in macOS environment." fi - echo "::endgroup::" if [[ $MAKE_PACKAGE == 1 ]]; then @@ -299,16 +308,16 @@ if [[ $RUNNER_OS == macOS ]]; then flags+=(-DCPACK_COMMAND_HDIUTIL="$hdiutil_script") fi -elif [[ $RUNNER_OS == Windows ]]; then +elif [[ ${RUNNER_OS:-} == "Windows" ]]; then : -elif [[ $RUNNER_OS == Linux ]]; then +elif [[ ${RUNNER_OS:-} == "Linux" ]]; then : fi -## Pre-build +### Pre-build # ccache if [[ $USE_CCACHE == 1 ]]; then @@ -324,14 +333,13 @@ if [[ $USE_CCACHE == 1 ]]; then fi -## Build +### Build # Configure CMake echo "::group::Configure CMake" cmake --version echo "Running CMake configuration with following flags: ${flags[*]}" cmake -S . -B "$BUILD_DIR" "${flags[@]}" -# cmake -S .. -B "$BUILD_DIR" "${flags[@]}" echo "::endgroup::" # Compile @@ -341,7 +349,7 @@ cmake --build "$BUILD_DIR" "${buildflags[@]}" echo "::endgroup::" -## Post-build +### Post-build # ccache if [[ $USE_CCACHE == 1 ]]; then @@ -362,8 +370,8 @@ elif [[ -n $CCACHE_EVICTION_AGE ]]; then echo "::error file=$0::ccache eviction is enabled while ccache is disabled!" fi -# Inspect binaries -if [[ $RUNNER_OS == macOS ]]; then +# Inspect +if [[ ${RUNNER_OS:-} == "macOS" ]]; then echo "::group::Inspect Mach-O binaries" for app in cockatrice oracle servatrice; do @@ -378,7 +386,6 @@ if [[ $RUNNER_OS == macOS ]]; then echo "::endgroup::" fi - # Test if [[ $MAKE_TEST == 1 ]]; then echo "::group::Run tests" @@ -390,8 +397,7 @@ fi # Install if [[ $MAKE_INSTALL == 1 ]]; then echo "::group::Install" - cmake --build "$BUILD_DIR" --target install --config "$BUILDTYPE" - # cmake --install "$BUILD_DIR" --config "$BUILDTYPE" + cmake --install "$BUILD_DIR" --config "$BUILDTYPE" echo "::endgroup::" fi @@ -399,7 +405,7 @@ fi if [[ $MAKE_PACKAGE == 1 ]]; then echo "::group::Create package" cpack --version - cmake --build "$BUILD_DIR" --target package --config "$BUILDTYPE" + cpack --config "$BUILD_DIR/CPackConfig.cmake" echo "::endgroup::" if [[ -n $PACKAGE_SUFFIX ]]; then diff --git a/servatrice/check_schema_version.sh b/servatrice/check_schema_version.sh index 8b645b5d2..75d44b826 100755 --- a/servatrice/check_schema_version.sh +++ b/servatrice/check_schema_version.sh @@ -2,6 +2,7 @@ set -e +echo "::group::Check Servatrice database schema version" version_line="$(grep 'INSERT INTO cockatrice_schema_version' servatrice/servatrice.sql)" version_line="${version_line#*VALUES(}" declare -i schema_ver="${version_line%%)*}" @@ -13,24 +14,30 @@ xtoy="${xtoysql%.sql}" declare -i old_ver="10#${xtoy%_to_*}" # declare as integer with base 10, numbers with a leading 0 are normally interpreted as base 16 declare -i new_ver="10#${xtoy#*_to_}" +echo "Schema version: $schema_ver" +echo "Latest migration: $latest_migration ($old_ver → $new_ver)" + if ((old_ver >= new_ver)); then - echo "New version $new_ver is not newer than $old_ver" - exit 1 + echo "New version $new_ver is not newer than $old_ver" + exit 1 fi if ((schema_ver != new_ver)); then - echo "Schema version $schema_ver does not equal new version $new_ver" - exit 1 + echo "Schema version $schema_ver does not match new version $new_ver" + exit 1 fi expected_sql="^UPDATE cockatrice_schema_version SET version=${new_ver} WHERE version=${old_ver};$" if ! grep -q "$expected_sql" "servatrice/migrations/$latest_migration"; then - echo "$latest_migration does not contain expected sql: $expected_sql" - exit 1 + echo "$latest_migration does not contain expected sql: $expected_sql" + exit 1 fi expected_define="^#define DATABASE_SCHEMA_VERSION $new_ver$" if ! grep -q "$expected_define" servatrice/src/servatrice_database_interface.h; then - echo "servatrice_database_interface.h does not contain expected #define: $expected_define" - exit 1 + echo "servatrice_database_interface.h does not contain expected #define: $expected_define" + exit 1 fi + +echo " ✓ Database schema version is consistent" +echo "::endgroup:: From 176914c24b38baeb6d0f1ebb0bde4c6a5244a654 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 26 Jul 2026 13:08:23 +0200 Subject: [PATCH 14/20] fix shellcheck warning --- .ci/lint_cpp.sh | 4 ++-- servatrice/check_schema_version.sh | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.ci/lint_cpp.sh b/.ci/lint_cpp.sh index 9786a83fc..c28329dbe 100755 --- a/.ci/lint_cpp.sh +++ b/.ci/lint_cpp.sh @@ -1,9 +1,9 @@ #!/bin/bash -# fetch master branch +# Fetch master branch git fetch origin master -# unshallow if needed +# Unshallow if needed echo "Finding merge base" if ! git merge-base origin/master HEAD; then echo "Could not find merge base, unshallowing repo" diff --git a/servatrice/check_schema_version.sh b/servatrice/check_schema_version.sh index 75d44b826..13c5f77f8 100755 --- a/servatrice/check_schema_version.sh +++ b/servatrice/check_schema_version.sh @@ -7,8 +7,7 @@ version_line="$(grep 'INSERT INTO cockatrice_schema_version' servatrice/servatri version_line="${version_line#*VALUES(}" declare -i schema_ver="${version_line%%)*}" -# shellcheck disable=2012 -latest_migration="$(ls -1 servatrice/migrations/ | tail -n1)" +latest_migration="$(printf '%s\n' servatrice/migrations/*.sql | sed 's#.*/##' | sort | tail -n1)" xtoysql="${latest_migration#servatrice_}" xtoy="${xtoysql%.sql}" declare -i old_ver="10#${xtoy%_to_*}" # declare as integer with base 10, numbers with a leading 0 are normally interpreted as base 16 @@ -40,4 +39,4 @@ if ! grep -q "$expected_define" servatrice/src/servatrice_database_interface.h; fi echo " ✓ Database schema version is consistent" -echo "::endgroup:: +echo "::endgroup::" From 922ed1bbbac05aa4ff04ced9bd7a2abc3dd3844b Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 26 Jul 2026 13:50:24 +0200 Subject: [PATCH 15/20] file logging, ci env check --- .ci/compile.sh | 20 ++++++++++---------- format.sh | 3 ++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 4225653ec..511f3fdbc 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -171,8 +171,7 @@ done # CI context (GitHub Actions provided environment variable) if [[ -z ${RUNNER_OS:-} ]]; then - echo "This script requires GitHub Actions environment variable RUNNER_OS" - exit 1 + echo "::notice::RUNNER_OS (GitHub Actions CI environment variable) is not available and OS-specific configuration will be skipped." fi # Schema version consistency @@ -255,10 +254,10 @@ if [[ ${RUNNER_OS:-} == "macOS" ]]; then fi mkdir -p "$triplets_dir" - triplet_source="../vcpkg/triplets/$arch-osx.cmake" + triplet_source="./vcpkg/triplets/$arch-osx.cmake" if [[ ! -f "$triplet_source" ]]; then - triplet_source="../vcpkg/triplets/community/$arch-osx.cmake" + triplet_source="./vcpkg/triplets/community/$arch-osx.cmake" fi cp "$triplet_source" "$triplet_file" @@ -322,13 +321,14 @@ fi # ccache if [[ $USE_CCACHE == 1 ]]; then echo "::group::Clear ccache stats" - # https://ccache.dev/manual/4.13.6.html#_command_line_options ccache --version ccache --show-config - ccache --show-stats # remove again - ccache --show-log-stats # helpful? - ccache --zero-stats # zero former cache statistics (but not the configuration options) - ccache --show-stats # helpful? + echo "---" + ccache --show-stats --verbose + echo "---" + ccache --zero-stats # zero former cache statistics (but not the configuration options or the cache itself) + echo "---" + ccache --show-stats --verbose echo "::endgroup::" fi @@ -361,7 +361,7 @@ if [[ $USE_CCACHE == 1 ]]; then fi echo "::group::Show ccache stats" - ccache --verify # remove again + ccache --show-stats ccache --show-stats --verbose # too verbose? ccache --show-compression # helpful? echo "::endgroup::" diff --git a/format.sh b/format.sh index 83dee9e28..294fe8f29 100755 --- a/format.sh +++ b/format.sh @@ -327,8 +327,9 @@ case $mode in done if (( code>0 )); then echo "$sep" + echo "Affected file(s):" for name in "${files_to_format[@]}"; do - echo "$name" + echo " $name" done fi exit $code From 4f9bd4338dd60e95c72e944a765dcddb3ef975b3 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 26 Jul 2026 20:14:51 +0200 Subject: [PATCH 16/20] don't depend on build path + cleanup + renaming --- .ci/compile.sh | 20 +++---- .ci/name_build.sh | 81 +++++++++++++++-------------- .github/workflows/desktop-build.yml | 40 +++++++------- 3 files changed, 72 insertions(+), 69 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 511f3fdbc..8a4fb9919 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -171,7 +171,7 @@ done # CI context (GitHub Actions provided environment variable) if [[ -z ${RUNNER_OS:-} ]]; then - echo "::notice::RUNNER_OS (GitHub Actions CI environment variable) is not available and OS-specific configuration will be skipped." + echo "::notice::RUNNER_OS (GitHub Actions CI environment variable) is not available and OS-specific build configuration will be skipped" fi # Schema version consistency @@ -320,15 +320,15 @@ fi # ccache if [[ $USE_CCACHE == 1 ]]; then - echo "::group::Clear ccache stats" + echo "::group::Show ccache configuration" ccache --version ccache --show-config echo "---" - ccache --show-stats --verbose + ccache --show-stats echo "---" - ccache --zero-stats # zero former cache statistics (but not the configuration options or the cache itself) + ccache --zero-stats echo "---" - ccache --show-stats --verbose + ccache --show-stats echo "::endgroup::" fi @@ -360,10 +360,10 @@ if [[ $USE_CCACHE == 1 ]]; then echo "::endgroup::" fi - echo "::group::Show ccache stats" - ccache --show-stats - ccache --show-stats --verbose # too verbose? - ccache --show-compression # helpful? + echo "::group::Show ccache statistics" + ccache --show-stats --verbose + echo "---" + ccache --show-compression echo "::endgroup::" elif [[ -n $CCACHE_EVICTION_AGE ]]; then @@ -410,7 +410,7 @@ if [[ $MAKE_PACKAGE == 1 ]]; then if [[ -n $PACKAGE_SUFFIX ]]; then echo "::group::Update package name" - BUILD_DIR="$BUILD_DIR" .ci/name_build.sh "$PACKAGE_SUFFIX" + .ci/name_build.sh "$PACKAGE_SUFFIX" echo "::endgroup::" fi fi diff --git a/.ci/name_build.sh b/.ci/name_build.sh index 85818bbd9..cdc6c8b8a 100755 --- a/.ci/name_build.sh +++ b/.ci/name_build.sh @@ -1,49 +1,52 @@ -#!/bin/bash -# used by the ci to rename build artifacts -# renames the file to [original name][SUFFIX].[original extension] -# where SUFFIX is either available in the environment or as the first arg -# expected to be run in the build directory unless BUILD_DIR is set -# adds output to GITHUB_OUTPUT -builddir="${BUILD_DIR:=.}" -findrx="Cockatrice-*.*" +#!/usr/bin/env bash -if [[ $1 ]]; then - SUFFIX="$1" -fi +set -euo pipefail -# check env -if [[ ! $SUFFIX ]]; then - echo "::error file=$0::SUFFIX is missing" +# Used by the CI build script to rename package artifacts +# +# Appends PACKAGE_SUFFIX to the package's filename +# = +# = +# PACKAGE_SUFFIX must be passed as the first argument to the script +# Adds output to GITHUB_OUTPUT +# +# Expected to be run in the repository root where CPack executes from and places its output binary +# Expects a single binary for package_pattern and picks the first match +# Expects to be e.g. ".dmg", ".deb" or ".exe" (".tar.gz" etc. with more than one dot will break) + +# Initialize PACKAGE_SUFFIX from positional argument +PACKAGE_SUFFIX="${1:-}" + +# Check variable +if [[ -z $PACKAGE_SUFFIX ]]; then + echo "::error file=$0::Missing required argument: PACKAGE_SUFFIX" exit 2 fi -set -e +package_pattern="Cockatrice-*.*" -# find file -found="$(find "$builddir" -maxdepth 1 -type f -name "$findrx" -print -quit)" -path="${found%/*}" # remove all including first "/" from right side -file="${found##*/}" # remove all including last "/" from left side -if [[ ! $file ]]; then - echo "::error file=$0::could not find package" - exit 1 -fi -oldpwd="$PWD" -if ! cd "$path"; then - echo "::error file=$0::could not get file path" +# Find package in current directory +package_path="$(find "$PWD" -maxdepth 1 -type f -name "$package_pattern" -print -quit)" + +if [[ -z "$package_path" ]]; then + echo "::error file=$0::Could not find package" exit 1 fi -# set filename -name="${file%.*}" # remove all including first "." from right side -new_name="$name$SUFFIX" -extension="${file##*.}" # remove all including last "." from left side -filename="$new_name.$extension" -echo "renaming '$file' to '$filename'" -mv "$file" "$filename" +# = +package="${package_path##*/}" # remove folder path (keep e.g. "Cockatrice-3.0.0.deb") +filename="${package%.*}" # remove extension (keep e.g. "Cockatrice-3.0.0") +extension=".${package##*.}" # remove filename (keep e.g. ".deb") -cd "$oldpwd" -relative_path="$path/$filename" -ls -l "$relative_path" -echo "path=$relative_path" >>"$GITHUB_OUTPUT" -echo "name=$new_name" >>"$GITHUB_OUTPUT" -echo "fullname=$filename" >>"$GITHUB_OUTPUT" +# Rename package (build artifact) +filename_new="$filename$PACKAGE_SUFFIX" +package_new="$filename_new$extension" +package_path_new="$PWD/$package_new" + +echo "Renaming '$package' to '$package_new'" +mv "$package_path" "$package_path_new" +du -h "$package_path_new" + +echo "package_path=$package_path_new" >>"$GITHUB_OUTPUT" +echo "package=$package_new" >>"$GITHUB_OUTPUT" +echo "filename=$filename_new" >>"$GITHUB_OUTPUT" diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index 2786dac21..13eae89c9 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -227,18 +227,18 @@ jobs: with: archive: false if-no-files-found: error - path: ${{ steps.build.outputs.path }} + path: ${{ steps.build.outputs.package_path }} - name: "Upload to release" id: upload_release if: matrix.package != 'skip' && needs.configure.outputs.tag != null shell: bash env: - asset_name: ${{ steps.build.outputs.fullname }} - asset_path: ${{ steps.build.outputs.path }} + package: ${{ steps.build.outputs.package }} + package_path: ${{ steps.build.outputs.package_path }} GH_TOKEN: ${{ github.token }} tag_name: ${{ needs.configure.outputs.tag }} - run: gh release upload "$tag_name" "$asset_path#$asset_name" + run: gh release upload "$tag_name" "$package_path#$package" - name: "Attest binary provenance" id: attestation @@ -246,15 +246,15 @@ jobs: uses: actions/attest@v4 with: show-summary: false - subject-path: ${{ steps.build.outputs.path }} + subject-path: ${{ steps.build.outputs.package_path }} - name: "Verify binary attestation" if: steps.attestation.outcome == 'success' shell: bash env: - BUILD_PATH: ${{ steps.build.outputs.path }} + PACKAGE_PATH: ${{ steps.build.outputs.package_path }} GH_TOKEN: ${{ github.token }} - run: gh attestation verify "$BUILD_PATH" --repo Cockatrice/Cockatrice + run: gh attestation verify "$PACKAGE_PATH" --repo Cockatrice/Cockatrice build-vcpkg: strategy: @@ -475,20 +475,20 @@ jobs: if: matrix.os == 'macOS' && matrix.make_package && needs.configure.outputs.tag != null id: sign_macos env: - BUILD_PATH: ${{ steps.build.outputs.path }} + PACKAGE_PATH: ${{ steps.build.outputs.package_path }} MACOS_CERTIFICATE_NAME: ${{ secrets.PROD_MACOS_CERTIFICATE_NAME }} MACOS_CI_KEYCHAIN_PWD: ${{ secrets.PROD_MACOS_CI_KEYCHAIN_PWD }} run: | if [[ -n "$MACOS_CERTIFICATE_NAME" ]] then security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain - /usr/bin/codesign --sign="$MACOS_CERTIFICATE_NAME" --entitlements=".ci/macos.entitlements" --options=runtime --force --deep --timestamp --verbose "$BUILD_PATH" + /usr/bin/codesign --sign="$MACOS_CERTIFICATE_NAME" --entitlements=".ci/macos.entitlements" --options=runtime --force --deep --timestamp --verbose "$PACKAGE_PATH" fi - name: "[macOS] Notarize app bundle" if: matrix.os == 'macOS' && steps.sign_macos.outcome == 'success' env: - BUILD_PATH: ${{ steps.build.outputs.path }} + PACKAGE_PATH: ${{ steps.build.outputs.package_path }} MACOS_NOTARIZATION_APPLE_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_APPLE_ID }} MACOS_NOTARIZATION_PWD: ${{ secrets.PROD_MACOS_NOTARIZATION_PWD }} MACOS_NOTARIZATION_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }} @@ -503,7 +503,7 @@ jobs: # Therefore, we create a zip file containing our app bundle, so that we can send it to the # notarization service echo "Creating temp notarization archive" - ditto -c -k --keepParent "$BUILD_PATH" "notarization.zip" + ditto -c -k --keepParent "$PACKAGE_PATH" "notarization.zip" # Here we send the notarization request to the Apple's Notarization service, waiting for the result. # This typically takes a few seconds inside a CI environment, but it might take more depending on the App @@ -515,7 +515,7 @@ jobs: # Finally, we need to "attach the staple" to our executable, which will allow our app to be # validated by macOS even when an internet connection is not available. echo "Attach staple" - xcrun stapler staple "$BUILD_PATH" + xcrun stapler staple "$PACKAGE_PATH" fi - name: "Upload artifact" @@ -525,14 +525,14 @@ jobs: with: archive: false if-no-files-found: error - path: ${{ steps.build.outputs.path }} + path: ${{ steps.build.outputs.package_path }} - name: "[Windows] Upload PDBs (Program Databases)" if: matrix.os == 'Windows' && github.ref_type != 'tag' uses: actions/upload-artifact@v7 with: if-no-files-found: error - name: ${{ steps.build.outputs.name }}-PDBs + name: ${{ steps.build.outputs.filename }}-PDBs path: | build/cockatrice/Release/*.pdb build/oracle/Release/*.pdb @@ -543,11 +543,11 @@ jobs: id: upload_release shell: bash env: - asset_name: ${{ steps.build.outputs.fullname }} - asset_path: ${{ steps.build.outputs.path }} + package: ${{ steps.build.outputs.package }} + package_path: ${{ steps.build.outputs.package_path }} GH_TOKEN: ${{ github.token }} tag_name: ${{ needs.configure.outputs.tag }} - run: gh release upload "$tag_name" "$asset_path#$asset_name" + run: gh release upload "$tag_name" "$package_path#$package" - name: "Attest binary provenance" if: steps.upload_release.outcome == 'success' @@ -555,12 +555,12 @@ jobs: uses: actions/attest@v4 with: show-summary: false - subject-path: ${{ steps.build.outputs.path }} + subject-path: ${{ steps.build.outputs.package_path }} - name: "Verify binary attestation" if: steps.attestation.outcome == 'success' shell: bash env: - BUILD_PATH: ${{ steps.build.outputs.path }} + PACKAGE_PATH: ${{ steps.build.outputs.package_path }} GH_TOKEN: ${{ github.token }} - run: gh attestation verify "$BUILD_PATH" --repo Cockatrice/Cockatrice + run: gh attestation verify "$PACKAGE_PATH" --repo Cockatrice/Cockatrice From 163098b0a849f44b2f2fbbba55df813202751f13 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 26 Jul 2026 20:55:25 +0200 Subject: [PATCH 17/20] comments + shellcheck --- .ci/compile.sh | 7 ++--- .ci/name_build.sh | 16 +++++----- format.sh | 78 +++++++++++++++++++++++------------------------ 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 8a4fb9919..da45ec6af 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -323,11 +323,11 @@ if [[ $USE_CCACHE == 1 ]]; then echo "::group::Show ccache configuration" ccache --version ccache --show-config - echo "---" + echo " -----" ccache --show-stats - echo "---" + echo " -----" ccache --zero-stats - echo "---" + echo " -----" ccache --show-stats echo "::endgroup::" fi @@ -362,7 +362,6 @@ if [[ $USE_CCACHE == 1 ]]; then echo "::group::Show ccache statistics" ccache --show-stats --verbose - echo "---" ccache --show-compression echo "::endgroup::" diff --git a/.ci/name_build.sh b/.ci/name_build.sh index cdc6c8b8a..07c93c675 100755 --- a/.ci/name_build.sh +++ b/.ci/name_build.sh @@ -11,8 +11,8 @@ set -euo pipefail # Adds output to GITHUB_OUTPUT # # Expected to be run in the repository root where CPack executes from and places its output binary -# Expects a single binary for package_pattern and picks the first match # Expects to be e.g. ".dmg", ".deb" or ".exe" (".tar.gz" etc. with more than one dot will break) +# If multiple packages match , the first match is used # Initialize PACKAGE_SUFFIX from positional argument PACKAGE_SUFFIX="${1:-}" @@ -34,9 +34,9 @@ if [[ -z "$package_path" ]]; then fi # = -package="${package_path##*/}" # remove folder path (keep e.g. "Cockatrice-3.0.0.deb") -filename="${package%.*}" # remove extension (keep e.g. "Cockatrice-3.0.0") -extension=".${package##*.}" # remove filename (keep e.g. ".deb") +package="${package_path##*/}" # e.g. "Cockatrice-3.0.0.deb" +filename="${package%.*}" # e.g. "Cockatrice-3.0.0" +extension=".${package##*.}" # e.g. ".deb" # Rename package (build artifact) filename_new="$filename$PACKAGE_SUFFIX" @@ -47,6 +47,8 @@ echo "Renaming '$package' to '$package_new'" mv "$package_path" "$package_path_new" du -h "$package_path_new" -echo "package_path=$package_path_new" >>"$GITHUB_OUTPUT" -echo "package=$package_new" >>"$GITHUB_OUTPUT" -echo "filename=$filename_new" >>"$GITHUB_OUTPUT" +{ + echo "package_path=$package_path_new" >> "$GITHUB_OUTPUT" + echo "package=$package_new" >> "$GITHUB_OUTPUT" + echo "filename=$filename_new" >> "$GITHUB_OUTPUT" +} >> "$GITHUB_OUTPUT" diff --git a/format.sh b/format.sh index 294fe8f29..45eef9b41 100755 --- a/format.sh +++ b/format.sh @@ -1,30 +1,30 @@ #!/bin/bash -# This script will run clang-format on all modified, non-3rd-party C++/Header files. +# This script will run Clang-Format on all modified, non-3rd-party C++/Header files. # Optionally runs cmake-format on all modified cmake files. -# Optionally runs shellcheck on all modified shell files. +# Optionally runs ShellCheck on all modified shell files. # Uses clang-format, cmake-format, git, diff, find and shellcheck # Never, ever, should this receive a path with a newline in it. Don't bother proofing it for that. set -o pipefail -# go to the project root directory, this file should be located in the project root directory +# Go to the project root directory, this file should be located in the project root directory olddir="$PWD" cd "${BASH_SOURCE%/*}/" || exit 2 # could not find path, this could happen with special links etc. -# defaults +# Defaults include=("cockatrice/src" \ libcockatrice_* \ -"oracle/src" \ -"servatrice/src" \ -"tests") + "oracle/src" \ + "servatrice/src" \ + "tests") exclude=("libcockatrice_rng/libcockatrice/rng/sfmt/" \ -"libcockatrice_utility/libcockatrice/utility/peglib.h" \ -"oracle/src/lzma/" \ -"oracle/src/qt-json/" \ -"oracle/src/zip/" \ -"servatrice/src/smtp/") -exts=("cpp" "h" "proto") + "libcockatrice_utility/libcockatrice/utility/peglib.h" \ + "oracle/src/lzma/" \ + "oracle/src/qt-json/" \ + "oracle/src/zip/" \ + "servatrice/src/smtp/") +extensions=("cpp" "h" "proto") cf_cmd="clang-format" branch="origin/master" cmakefile="CMakeLists.txt" @@ -33,9 +33,9 @@ cmakeinclude=("cmake/gtest-CMakeLists.txt.in") scripts="*.sh" color="--" verbosity=0 -sep="----------" +separator="----------" -# parse options +# Parse options while [[ $* ]]; do case "$1" in '-b'|'--branch') @@ -58,7 +58,7 @@ while [[ $* ]]; do ;; '-h'|'--help') cat <s are given, all source files in those directories of the project root @@ -165,7 +165,7 @@ EOM ;; *) if [[ ! $dashdash && $1 =~ ^-- ]]; then - echo "error in parsing arguments of $0: $1 is an unrecognized option" >&2 + echo "Error in parsing arguments of $0: $1 is an unrecognized option" >&2 exit 2 # input error fi if [[ ! $1 ]] || next_dir=$(cd "$olddir" && cd -- "$1" && pwd); then @@ -175,13 +175,13 @@ EOM fi if [[ $1 ]]; then if [[ $next_dir != $PWD/* ]]; then - echo "error in parsing arguments of $0: $next_dir is not in $PWD" >&2 + echo "Error in parsing arguments of $0: $next_dir is not in $PWD" >&2 exit 2 # input error fi include+=("$next_dir") fi else - echo "error in parsing arguments of $0: $1 is not a directory" >&2 + echo "Error in parsing arguments of $0: $1 is not a directory" >&2 exit 2 # input error fi if ! [[ $set_branch ]]; then @@ -192,39 +192,39 @@ EOM esac done -# check availability of clang-format +# Check availability of Clang-Format if ! hash $cf_cmd 2>/dev/null; then echo "could not find $cf_cmd" >&2 - # find any clang-format-x.x in /usr/bin + # Find any "clang-format-x.x" in /usr/bin cf_cmd=$(find /usr/bin -regex '.*/clang-format-[0-9]+\.[0-9]+' -print -quit) if [[ $cf_cmd ]]; then - echo "found $cf_cmd instead" >&2 + echo "Found $cf_cmd instead" >&2 else exit 3 # special exit code for missing dependency fi fi -# check availability of cmake-format +# Check availability of cmake-format if [[ $do_cmake ]] && ! hash cmake-format 2>/dev/null; then - echo "could not find cmake-format" >&2 + echo "Could not find cmake-format" >&2 exit 3 fi -# check availability of shellcheck +# Check availability of ShellCheck if [[ $do_shell ]] && ! hash shellcheck 2>/dev/null; then - echo "could not find shellcheck" >&2 + echo "Could not find shellcheck" >&2 exit 3 fi if [[ $branch ]]; then - # get all dirty files through git + # Get all dirty files through git if ! base=$(git merge-base "$branch" HEAD); then - echo "could not find git merge base" >&2 + echo "Could not find git merge base" >&2 exit 2 # input error fi mapfile -t basenames < <(git diff --diff-filter=d --name-only "$base") names=() - for ex in "${exts[@]}"; do + for ex in "${extensions[@]}"; do for path in "${include[@]}"; do for name in "${basenames[@]}"; do rx="^$path/.*\\.$ex$" @@ -260,7 +260,7 @@ if [[ $branch ]]; then fi else exts_o=() - for ext in "${exts[@]}"; do + for ext in "${extensions[@]}"; do exts_o+=(-o -name "*\\.$ext") done unset "exts_o[0]" # remove first -o @@ -274,7 +274,7 @@ else fi fi -# filter excludes +# Filter excludes for path in "${exclude[@]}"; do for i in "${!names[@]}"; do rx="^$path" @@ -284,12 +284,12 @@ for path in "${exclude[@]}"; do done done -# optionally print version +# Optionally print version if [[ $print_version ]]; then $cf_cmd -version [[ $do_cmake ]] && echo "cmake-format version $(cmake-format --version)" - [[ $do_shell ]] && echo "shellcheck $(shellcheck --version | grep "version:")" - echo "$sep" + [[ $do_shell ]] && echo "ShellCheck $(shellcheck --version | grep "version:")" + echo "$separator" fi if [[ ! ${cmake_names[*]} ]]; then @@ -302,7 +302,7 @@ if [[ ! ( ${names[*]} || $do_cmake || $do_shell ) ]]; then exit 0 # nothing to format means format is successful! fi -# format +# Format case $mode in diff) declare -i code=0 @@ -326,7 +326,7 @@ case $mode in fi done if (( code>0 )); then - echo "$sep" + echo "$separator" echo "Affected file(s):" for name in "${files_to_format[@]}"; do echo " $name" @@ -375,15 +375,15 @@ case $mode in cmake-format -i "${cmake_names[@]}" fi if [[ $do_shell ]]; then - echo "warning: --shell is not compatible with the current mode but shell files were modified!" >&2 - echo "recommendation: try $0 --diff --shell" >&2 + echo "Warning: --shell is not compatible with the current mode but shell files were modified!" >&2 + echo "Recommendation: try $0 --diff --shell" >&2 fi if (( verbosity>0 )); then count="${#names[*]}" if [[ $do_cmake ]]; then (( count+=${#cmake_names[*]} )) fi - echo "parsed $count files that differ from base $branch" + echo "Parsed $count files that differ from base $branch" fi ;; esac From 1118c26a5cac1c92d816f4d5ee54fee21e8ecd72 Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 26 Jul 2026 22:08:52 +0200 Subject: [PATCH 18/20] fix upload path for linux/docker + comments --- .ci/compile.sh | 19 ++++++++++--------- .ci/name_build.sh | 4 ++-- .github/workflows/desktop-build.yml | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index da45ec6af..606f6248c 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail - -### Compiles Cockatrice inside GitHub Actions CI, run only from project root directory (GITHUB_WORKSPACE) +# Compiles Cockatrice inside GitHub Actions CI, run only from project root directory (GITHUB_WORKSPACE) # # Build flow and script structure: # - Read options @@ -11,8 +9,8 @@ set -euo pipefail # - Pre-buld (ccache) # - Build (Configure, Compile) # - Post-build (ccache, Inspect, Test, Install, Package) - -### Supported command-line options: +# +# Supported command-line options: # --ccache [] Use ccache (USE_CCACHE) (optionally: provide cache size, e.g. "500M" or "1G" (CCACHE_SIZE)) # --cmake-generator Sets the CMake generator (CMAKE_GENERATOR), e.g. "Ninja", "Visual Studio 18 2026" # --debug Sets the build type (BUILDTYPE --> CMAKE_BUILD_TYPE) @@ -27,6 +25,13 @@ set -euo pipefail # --target-macos-version Sets the min OS version (TARGET_MACOS_VERSION), e.g. "14" [macOS only] # --test Runs tests (MAKE_TEST) # --vcpkg Use vcpkg package manager to resolve dependencies (USE_VCPKG) +# +# Exit codes: +# 1 --> Failure +# 3 --> Invalid argument(s) + +set -euo pipefail + ### Initialize configuration variables: # Precedence: command-line options > environment variables > built-in script defaults @@ -46,10 +51,6 @@ TARGET_MACOS_VERSION="${TARGET_MACOS_VERSION:-}" # See "--target-macos-versio USE_CCACHE="${USE_CCACHE:-0}" # See "--ccache" option USE_VCPKG="${USE_VCPKG:-0}" # See "--vcpkg" flag -### Exit codes: -# 1 --> Failure -# 3 --> Invalid argument(s) - ### Read options while [[ $# != 0 ]]; do diff --git a/.ci/name_build.sh b/.ci/name_build.sh index 07c93c675..36b565782 100755 --- a/.ci/name_build.sh +++ b/.ci/name_build.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -set -euo pipefail - # Used by the CI build script to rename package artifacts # # Appends PACKAGE_SUFFIX to the package's filename @@ -14,6 +12,8 @@ set -euo pipefail # Expects to be e.g. ".dmg", ".deb" or ".exe" (".tar.gz" etc. with more than one dot will break) # If multiple packages match , the first match is used +set -euo pipefail + # Initialize PACKAGE_SUFFIX from positional argument PACKAGE_SUFFIX="${1:-}" diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index 13eae89c9..911851bec 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -227,7 +227,7 @@ jobs: with: archive: false if-no-files-found: error - path: ${{ steps.build.outputs.package_path }} + path: ${{ steps.build.outputs.package }} # package is resolved against workspace (container path /= host path) - name: "Upload to release" id: upload_release From ee1a7815e9c661a3dea6449ff0e8a5ba114e8d1b Mon Sep 17 00:00:00 2001 From: tooomm Date: Sun, 26 Jul 2026 23:10:56 +0200 Subject: [PATCH 19/20] debug nsis --- .ci/compile.sh | 2 ++ .ci/name_build.sh | 1 + .github/workflows/desktop-build.yml | 15 ++++++++++----- format.sh | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index 606f6248c..ef895e51f 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -326,10 +326,12 @@ if [[ $USE_CCACHE == 1 ]]; then ccache --show-config echo " -----" ccache --show-stats + ccache --show-compression echo " -----" ccache --zero-stats echo " -----" ccache --show-stats + ccache --show-compression echo "::endgroup::" fi diff --git a/.ci/name_build.sh b/.ci/name_build.sh index 36b565782..d221534f1 100755 --- a/.ci/name_build.sh +++ b/.ci/name_build.sh @@ -47,6 +47,7 @@ echo "Renaming '$package' to '$package_new'" mv "$package_path" "$package_path_new" du -h "$package_path_new" +#TODO remove package_path as it's default working direcotry / repo root? { echo "package_path=$package_path_new" >> "$GITHUB_OUTPUT" echo "package=$package_new" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml index 911851bec..f04bd8ed1 100644 --- a/.github/workflows/desktop-build.yml +++ b/.github/workflows/desktop-build.yml @@ -227,7 +227,7 @@ jobs: with: archive: false if-no-files-found: error - path: ${{ steps.build.outputs.package }} # package is resolved against workspace (container path /= host path) + path: ${{ steps.build.outputs.package }} # package is resolved against github.workspace - name: "Upload to release" id: upload_release @@ -235,10 +235,10 @@ jobs: shell: bash env: package: ${{ steps.build.outputs.package }} - package_path: ${{ steps.build.outputs.package_path }} + package_path: ${{ steps.build.outputs.package_path }} # <-- to check GH_TOKEN: ${{ github.token }} tag_name: ${{ needs.configure.outputs.tag }} - run: gh release upload "$tag_name" "$package_path#$package" + run: gh release upload "$tag_name" "$package_path#$package" # <-- to check - name: "Attest binary provenance" id: attestation @@ -246,13 +246,13 @@ jobs: uses: actions/attest@v4 with: show-summary: false - subject-path: ${{ steps.build.outputs.package_path }} + subject-path: ${{ steps.build.outputs.package_path }} # <-- to check - name: "Verify binary attestation" if: steps.attestation.outcome == 'success' shell: bash env: - PACKAGE_PATH: ${{ steps.build.outputs.package_path }} + PACKAGE_PATH: ${{ steps.build.outputs.package_path }} # <-- to check GH_TOKEN: ${{ github.token }} run: gh attestation verify "$PACKAGE_PATH" --repo Cockatrice/Cockatrice @@ -451,6 +451,11 @@ jobs: VCPKG_BINARY_SOURCES: 'clear;files,${{ steps.vcpkg-cache.outputs.path }},readwrite' VCPKG_DISABLE_METRICS: 1 run: .ci/compile.sh --server --test --vcpkg + continue-on-error: true + + - name: "[Windows] DEBUG: Print NSIS log output" + if: matrix.os == 'Windows' + run: cat "_CPack_Packages/win64/NSIS/NSISOutput.log" # Delete used cache to emulate a ccache update. See https://github.com/actions/cache/issues/342 - name: "[macOS] Delete remote compiler cache (ccache)" diff --git a/format.sh b/format.sh index 45eef9b41..01239479b 100755 --- a/format.sh +++ b/format.sh @@ -33,7 +33,7 @@ cmakeinclude=("cmake/gtest-CMakeLists.txt.in") scripts="*.sh" color="--" verbosity=0 -separator="----------" +separator=" ----------" # Parse options while [[ $* ]]; do From 6cba8b7c64989e31e3a1ea1dcd625ed053b7d3b5 Mon Sep 17 00:00:00 2001 From: tooomm Date: Mon, 27 Jul 2026 11:08:29 +0200 Subject: [PATCH 20/20] cpack debug --- .ci/compile.sh | 24 +++++++++++++++++++++--- .ci/lint_cpp.sh | 2 -- format.sh | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.ci/compile.sh b/.ci/compile.sh index ef895e51f..b7ef3c770 100755 --- a/.ci/compile.sh +++ b/.ci/compile.sh @@ -328,10 +328,14 @@ if [[ $USE_CCACHE == 1 ]]; then ccache --show-stats ccache --show-compression echo " -----" + ccache --show-stats --verbose + ccache --show-compression + echo " -----" ccache --zero-stats echo " -----" ccache --show-stats - ccache --show-compression + echo " -----" + ccache --show-stats --verbose echo "::endgroup::" fi @@ -339,7 +343,7 @@ fi ### Build # Configure CMake -echo "::group::Configure CMake" +echo "::group::Generate buildsystem" cmake --version echo "Running CMake configuration with following flags: ${flags[*]}" cmake -S . -B "$BUILD_DIR" "${flags[@]}" @@ -405,9 +409,23 @@ fi # Package if [[ $MAKE_PACKAGE == 1 ]]; then + echo "::group::Debug NSIS / CPack" + cat "_CPack_Packages/win64/NSIS/NSISOutput.log" + echo " -----" + find . -name "NSIS.definitions.nsh" + find "$BUILD_DIR" -name "NSIS.definitions.nsh" + ls -l "$BUILD_DIR/NSIS.definitions.nsh" + echo "::endgroup:" + echo "::group::Create package" cpack --version - cpack --config "$BUILD_DIR/CPackConfig.cmake" + ( + cd "$BUILD_DIR" + cpack + ) + # cpack --config "$BUILD_DIR/CPackConfig.cmake" + # cmake --build "$BUILD_DIR" --target package + #TODO included --config? compare with former isntall and other --target variants used echo "::endgroup::" if [[ -n $PACKAGE_SUFFIX ]]; then diff --git a/.ci/lint_cpp.sh b/.ci/lint_cpp.sh index c28329dbe..b934c0307 100755 --- a/.ci/lint_cpp.sh +++ b/.ci/lint_cpp.sh @@ -32,7 +32,6 @@ case $err in *** *** *********************************************************** -Exiting... EOM exit 2 ;; @@ -48,7 +47,6 @@ EOM *** *** *********************************************************** -Exiting... EOM exit 0 ;; diff --git a/format.sh b/format.sh index 01239479b..b174bea2f 100755 --- a/format.sh +++ b/format.sh @@ -14,7 +14,7 @@ cd "${BASH_SOURCE%/*}/" || exit 2 # could not find path, this could happen with # Defaults include=("cockatrice/src" \ -libcockatrice_* \ + libcockatrice_* \ "oracle/src" \ "servatrice/src" \ "tests")