From 59f89f9a46c4496d873898c5422c7d332722acfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sat, 17 Dec 2022 13:53:37 +0100 Subject: [PATCH] Let mods customize app constants Mainly via meson_options.txt. --- .github/build.sh | 93 ++++++------------ .github/mod_id.txt | 1 - .github/prepare.py | 36 +++++-- .github/workflows/build.yaml | 13 +++ ...ifest.xml => AndroidManifest.template.xml} | 2 +- ...vity.java => PowderActivity.template.java} | 2 +- android/build-apk.py | 6 +- android/meson.build | 22 +++-- android/res/meson.build | 3 +- android/res/values/meson.build | 5 + android/res/values/strings.template.xml | 3 + android/res/values/strings.xml | 3 - android/run-apk.py | 3 +- meson.build | 16 ++- meson_options.txt | 6 ++ .../icon/{powder-128.png => icon-128.png} | Bin resources/icon/{powder-16.png => icon-16.png} | Bin resources/icon/{powder-24.png => icon-24.png} | Bin .../icon/{powder-256.png => icon-256.png} | Bin resources/icon/{powder-32.png => icon-32.png} | Bin resources/icon/{powder-48.png => icon-48.png} | Bin resources/meson.build | 2 +- src/PowderToyFontEditor.cpp | 2 +- src/PowderToySDL.cpp | 2 +- src/common/Platform.cpp | 2 +- 25 files changed, 123 insertions(+), 99 deletions(-) delete mode 100644 .github/mod_id.txt rename android/{AndroidManifest.xml => AndroidManifest.template.xml} (98%) rename android/{uk/co/powdertoy/tpt/PowderActivity.java => PowderActivity.template.java} (75%) create mode 100644 android/res/values/meson.build create mode 100644 android/res/values/strings.template.xml delete mode 100644 android/res/values/strings.xml rename resources/icon/{powder-128.png => icon-128.png} (100%) rename resources/icon/{powder-16.png => icon-16.png} (100%) rename resources/icon/{powder-24.png => icon-24.png} (100%) rename resources/icon/{powder-256.png => icon-256.png} (100%) rename resources/icon/{powder-32.png => icon-32.png} (100%) rename resources/icon/{powder-48.png => icon-48.png} (100%) diff --git a/.github/build.sh b/.github/build.sh index 588519cba..357a9d0da 100755 --- a/.github/build.sh +++ b/.github/build.sh @@ -3,58 +3,25 @@ set -euo pipefail IFS=$'\n\t' -if [[ -z ${BSH_BUILD_PLATFORM-} ]]; then - >&2 echo "BSH_BUILD_PLATFORM not set" - exit 1 -fi -if [[ -z ${BSH_HOST_ARCH-} ]]; then - >&2 echo "BSH_HOST_ARCH not set" - exit 1 -fi -if [[ -z ${BSH_HOST_PLATFORM-} ]]; then - >&2 echo "BSH_HOST_PLATFORM not set" - exit 1 -fi -if [[ -z ${BSH_HOST_LIBC-} ]]; then - >&2 echo "BSH_HOST_LIBC not set" - exit 1 -fi -if [[ -z ${BSH_STATIC_DYNAMIC-} ]]; then - >&2 echo "BSH_STATIC_DYNAMIC not set" - exit 1 -fi -if [[ -z ${BSH_DEBUG_RELEASE-} ]]; then - >&2 echo "BSH_DEBUG_RELEASE not set" - exit 1 -fi -if [[ -z ${RELEASE_NAME-} ]]; then - >&2 echo "RELEASE_NAME not set" - exit 1 -fi -if [[ -z ${RELEASE_TYPE-} ]]; then - >&2 echo "RELEASE_TYPE not set" - exit 1 -fi -if [[ -z ${MOD_ID-} ]]; then - >&2 echo "MOD_ID not set" - exit 1 -fi -if [[ -z ${SEPARATE_DEBUG-} ]]; then - >&2 echo "SEPARATE_DEBUG not set" - exit 1 -fi -if [[ -z ${PACKAGE_MODE-} ]]; then - >&2 echo "PACKAGE_MODE not set" - exit 1 -fi -if [[ -z ${ASSET_PATH-} ]]; then - >&2 echo "ASSET_PATH not set" - exit 1 -fi -if [[ -z ${DEBUG_ASSET_PATH-} ]]; then - >&2 echo "DEBUG_ASSET_PATH not set" - exit 1 -fi +if [[ -z ${BSH_BUILD_PLATFORM-} ]]; then >&2 echo "BSH_BUILD_PLATFORM not set"; exit 1; fi +if [[ -z ${BSH_HOST_ARCH-} ]]; then >&2 echo "BSH_HOST_ARCH not set"; exit 1; fi +if [[ -z ${BSH_HOST_PLATFORM-} ]]; then >&2 echo "BSH_HOST_PLATFORM not set"; exit 1; fi +if [[ -z ${BSH_HOST_LIBC-} ]]; then >&2 echo "BSH_HOST_LIBC not set"; exit 1; fi +if [[ -z ${BSH_STATIC_DYNAMIC-} ]]; then >&2 echo "BSH_STATIC_DYNAMIC not set"; exit 1; fi +if [[ -z ${BSH_DEBUG_RELEASE-} ]]; then >&2 echo "BSH_DEBUG_RELEASE not set"; exit 1; fi +if [[ -z ${RELEASE_NAME-} ]]; then >&2 echo "RELEASE_NAME not set"; exit 1; fi +if [[ -z ${RELEASE_TYPE-} ]]; then >&2 echo "RELEASE_TYPE not set"; exit 1; fi +if [[ -z ${MOD_ID-} ]]; then >&2 echo "MOD_ID not set"; exit 1; fi +if [[ -z ${SEPARATE_DEBUG-} ]]; then >&2 echo "SEPARATE_DEBUG not set"; exit 1; fi +if [[ -z ${PACKAGE_MODE-} ]]; then >&2 echo "PACKAGE_MODE not set"; exit 1; fi +if [[ -z ${ASSET_PATH-} ]]; then >&2 echo "ASSET_PATH not set"; exit 1; fi +if [[ -z ${DEBUG_ASSET_PATH-} ]]; then >&2 echo "DEBUG_ASSET_PATH not set"; exit 1; fi +if [[ -z ${APP_NAME-} ]]; then >&2 echo "APP_NAME not set"; exit 1; fi +if [[ -z ${APP_COMMENT-} ]]; then >&2 echo "APP_COMMENT not set"; exit 1; fi +if [[ -z ${APP_EXE-} ]]; then >&2 echo "APP_EXE not set"; exit 1; fi +if [[ -z ${APP_ID-} ]]; then >&2 echo "APP_ID not set"; exit 1; fi +if [[ -z ${APP_DATA-} ]]; then >&2 echo "APP_DATA not set"; exit 1; fi +if [[ -z ${APP_VENDOR-} ]]; then >&2 echo "APP_VENDOR not set"; exit 1; fi case $BSH_HOST_ARCH-$BSH_HOST_PLATFORM-$BSH_HOST_LIBC-$BSH_STATIC_DYNAMIC in x86_64-linux-gnu-static) ;; @@ -333,19 +300,19 @@ strip_target=$ASSET_PATH if [[ $BSH_HOST_PLATFORM == android ]]; then strip=$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-$strip objcopy=$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-$objcopy - strip_target=libpowder.so + strip_target=lib$APP_EXE.so fi if [[ $PACKAGE_MODE == appimage ]]; then # so far this can only happen with $BSH_HOST_PLATFORM-$BSH_HOST_LIBC == linux-gnu, but this may change later meson configure -Dinstall_check=false -Dignore_updates=true -Dbuild_render=false -Dbuild_font=false - strip_target=powder + strip_target=$APP_EXE fi if [[ $BSH_BUILD_PLATFORM == windows ]]; then set +e ninja -v -d keeprsp ninja_code=$? set -e - cat powder.exe.rsp + cat $APP_EXE.exe.rsp [[ $ninja_code == 0 ]]; else ninja -v @@ -360,8 +327,8 @@ fi if [[ $BSH_HOST_PLATFORM == android ]]; then $JAVA_HOME_8_X64/bin/keytool -genkeypair -keystore keystore.jks -alias androidkey -validity 10000 -keyalg RSA -keysize 2048 -keypass bagelsbagels -storepass bagelsbagels -dname "CN=nobody" meson configure -Dandroid_keystore=$(realpath keystore.jks) - ANDROID_KEYSTORE_PASS=bagelsbagels ninja android/powder.apk - mv android/powder.apk powder.apk + ANDROID_KEYSTORE_PASS=bagelsbagels ninja android/$APP_EXE.apk + mv android/$APP_EXE.apk $APP_EXE.apk fi if [[ $PACKAGE_MODE == appimage ]]; then # so far this can only happen with $BSH_HOST_PLATFORM-$BSH_HOST_LIBC == linux-gnu, but this may change later @@ -385,12 +352,12 @@ if [[ $PACKAGE_MODE == appimage ]]; then mkdir -p $appdir/usr/share/metainfo mkdir -p $appdir/usr/share/applications mkdir -p $appdir/usr/share/icons - cp powder $appdir/usr/bin/powder + cp $APP_EXE $appdir/usr/bin/$APP_EXE mv AppRun $appdir/AppRun - cp ../resources/icon/powder-128.png $appdir/powdertoy-powder.png - cp resources/powder.desktop $appdir/uk.co.powdertoy.tpt.desktop - cp appdata.xml $appdir/usr/share/metainfo/uk.co.powdertoy.tpt.appdata.xml - cp $appdir/powdertoy-powder.png $appdir/usr/share/icons/powdertoy-powder.png - cp $appdir/uk.co.powdertoy.tpt.desktop $appdir/usr/share/applications/uk.co.powdertoy.tpt.desktop + cp ../resources/icon/icon-128.png $appdir/$APP_VENDOR-$APP_EXE.png + cp resources/powder.desktop $appdir/$APP_ID.desktop + cp appdata.xml $appdir/usr/share/metainfo/$APP_ID.appdata.xml + cp $appdir/$APP_VENDOR-$APP_EXE.png $appdir/usr/share/icons/$APP_VENDOR-$APP_EXE.png + cp $appdir/$APP_ID.desktop $appdir/usr/share/applications/$APP_ID.desktop ./appimagetool $appdir $ASSET_PATH fi diff --git a/.github/mod_id.txt b/.github/mod_id.txt deleted file mode 100644 index 573541ac9..000000000 --- a/.github/mod_id.txt +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/.github/prepare.py b/.github/prepare.py index 52e51faea..3a2d99db6 100755 --- a/.github/prepare.py +++ b/.github/prepare.py @@ -2,6 +2,7 @@ import datetime import json import os import re +import subprocess import sys ref = os.getenv('GITHUB_REF') @@ -39,8 +40,23 @@ do_publish = publish_hostport and do_release set_output('release_type', release_type) set_output('release_name', release_name) -with open('.github/mod_id.txt') as f: - set_output('mod_id', f.read()) +subprocess.run([ 'meson', 'setup', '-Dprepare=true', 'build-prepare' ], check = True) +build_options = {} +with open('build-prepare/meson-info/intro-buildoptions.json') as f: + for option in json.loads(f.read()): + build_options[option['name']] = option['value'] + +set_output('mod_id' , build_options['mod_id' ]) +set_output('app_name' , build_options['app_name' ]) +set_output('app_comment', build_options['app_comment']) +set_output('app_exe' , build_options['app_exe' ]) +set_output('app_id' , build_options['app_id' ]) +set_output('app_data' , build_options['app_data' ]) +set_output('app_vendor' , build_options['app_vendor' ]) + +app_exe = build_options['app_exe'] +app_name = build_options['app_name'] +app_name_slug = re.sub('[^A-Za-z0-9]', '_', app_name) build_matrix = [] publish_matrix = [] @@ -97,15 +113,15 @@ for arch, platform, libc, statdyn, bplatform, runson, suff if dbgrel != 'release': assert not publish assert not artifact - asset_path = f'powder{suffix}' - asset_name = f'powder-{release_name}-{arch}-{platform}-{libc}{suffix}' - debug_asset_path = f'powder{dbgsuffix}' - debug_asset_name = f'powder-{release_name}-{arch}-{platform}-{libc}{dbgsuffix}' + asset_path = f'{app_exe}{suffix}' + asset_name = f'{app_exe}-{release_name}-{arch}-{platform}-{libc}{suffix}' + debug_asset_path = f'{app_exe}{dbgsuffix}' + debug_asset_name = f'{app_exe}-{release_name}-{arch}-{platform}-{libc}{dbgsuffix}' if mode == 'appimage': - asset_path = f'The_Powder_Toy-{arch}.AppImage' - asset_name = f'The_Powder_Toy-{arch}.AppImage' - debug_asset_path = f'The_Powder_Toy-{arch}.AppImage.dbg' - debug_asset_name = f'The_Powder_Toy-{arch}.AppImage.dbg' + asset_path = f'{app_name_slug}-{arch}.AppImage' + asset_name = f'{app_name_slug}-{arch}.AppImage' + debug_asset_path = f'{app_name_slug}-{arch}.AppImage.dbg' + debug_asset_name = f'{app_name_slug}-{arch}.AppImage.dbg' starcatcher_name = f'powder-{release_name}-{starcatcher}{suffix}' build_matrix.append({ 'bsh_build_platform': bplatform, # part of the unique portion of the matrix diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c581f0b99..450247501 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,12 +23,19 @@ jobs: release_type: ${{ steps.prepare.outputs.release_type }} release_name: ${{ steps.prepare.outputs.release_name }} mod_id: ${{ steps.prepare.outputs.mod_id }} + app_name: ${{ steps.prepare.outputs.app_name }} + app_comment: ${{ steps.prepare.outputs.app_comment }} + app_exe: ${{ steps.prepare.outputs.app_exe }} + app_id: ${{ steps.prepare.outputs.app_id }} + app_data: ${{ steps.prepare.outputs.app_data }} + app_vendor: ${{ steps.prepare.outputs.app_vendor }} do_publish: ${{ steps.prepare.outputs.do_publish }} steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: '3.10' + - run: python -m pip install meson ninja - id: prepare run: python ./.github/prepare.py env: @@ -77,6 +84,12 @@ jobs: RELEASE_NAME: ${{ needs.prepare.outputs.release_name }} RELEASE_TYPE: ${{ needs.prepare.outputs.release_type }} MOD_ID: ${{ needs.prepare.outputs.mod_id }} + APP_NAME: ${{ needs.prepare.outputs.app_name }} + APP_COMMENT: ${{ needs.prepare.outputs.app_comment }} + APP_EXE: ${{ needs.prepare.outputs.app_exe }} + APP_ID: ${{ needs.prepare.outputs.app_id }} + APP_DATA: ${{ needs.prepare.outputs.app_data }} + APP_VENDOR: ${{ needs.prepare.outputs.app_vendor }} SEPARATE_DEBUG: ${{ matrix.separate_debug }} PACKAGE_MODE: ${{ matrix.package_mode }} ASSET_PATH: ${{ matrix.asset_path }} diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.template.xml similarity index 98% rename from android/AndroidManifest.xml rename to android/AndroidManifest.template.xml index ba2fed4ab..40b5d93c7 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.template.xml @@ -1,7 +1,7 @@ + @APPNAME@ + diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml deleted file mode 100644 index 7a69b0f5c..000000000 --- a/android/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - The Powder Toy - diff --git a/android/run-apk.py b/android/run-apk.py index 7ee08b853..113df5b6f 100644 --- a/android/run-apk.py +++ b/android/run-apk.py @@ -9,6 +9,7 @@ import sys build_dir, phony, apk_name, + app_id, ) = sys.argv apk_path = os.path.join(build_dir, apk_name) @@ -19,6 +20,6 @@ if subprocess.run([ 'am', 'start', '--activity-clear-top', - '-n', 'uk.co.powdertoy.tpt/.PowderActivity', + '-n', app_id + '/.PowderActivity', ]).returncode: sys.exit(1) diff --git a/meson.build b/meson.build index c470c3971..49e8b3a7e 100644 --- a/meson.build +++ b/meson.build @@ -13,6 +13,11 @@ project( meson_version: '>=0.61.0', ) +if get_option('prepare') + # we're being run by prepare.py in a ghactions workflow only to determine the values of options; exit early + subdir_done() +endif + to_array = generator( executable('toarray', sources: 'data/ToArray.cpp', native: true), output: [ '@PLAINNAME@.cpp', '@PLAINNAME@.h' ], @@ -308,6 +313,9 @@ else ident_platform = 'UNKNOWN' endif +app_exe = get_option('app_exe') +app_id = get_option('app_id') + conf_data.set('LIN', host_platform == 'linux') conf_data.set('AND', host_platform == 'android') conf_data.set('WIN', host_platform == 'windows') @@ -331,8 +339,8 @@ conf_data.set('IDENT', '"@0@-@1@-@2@"'.format(host_arch, host_platform, host_lib conf_data.set('ENFORCE_HTTPS', enforce_https) conf_data.set('APPNAME', get_option('app_name')) conf_data.set('APPCOMMENT', get_option('app_comment')) -conf_data.set('APPEXE', get_option('app_exe')) -conf_data.set('APPID', get_option('app_id')) +conf_data.set('APPEXE', app_exe) +conf_data.set('APPID', app_id) conf_data.set('APPDATA', get_option('app_data')) conf_data.set('APPVENDOR', get_option('app_vendor')) @@ -366,7 +374,7 @@ if get_option('build_powder') ] if host_platform == 'android' powder_sha = shared_library( - 'powder', + app_exe, sources: powder_files, include_directories: [ project_inc, powder_inc ], c_args: project_c_args, @@ -377,7 +385,7 @@ if get_option('build_powder') subdir('android') else executable( - 'powder', + app_exe, sources: powder_files, include_directories: [ project_inc, powder_inc ], c_args: project_c_args, diff --git a/meson_options.txt b/meson_options.txt index 3335da24d..c7d6a5796 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -207,3 +207,9 @@ option( value: true, description: 'Enforce encrypted HTTP traffic, may be disabled for debugging' ) +option( + 'prepare', + type: 'boolean', + value: false, + description: 'Used by ghactions workflows, not useful otherwise' +) diff --git a/resources/icon/powder-128.png b/resources/icon/icon-128.png similarity index 100% rename from resources/icon/powder-128.png rename to resources/icon/icon-128.png diff --git a/resources/icon/powder-16.png b/resources/icon/icon-16.png similarity index 100% rename from resources/icon/powder-16.png rename to resources/icon/icon-16.png diff --git a/resources/icon/powder-24.png b/resources/icon/icon-24.png similarity index 100% rename from resources/icon/powder-24.png rename to resources/icon/icon-24.png diff --git a/resources/icon/powder-256.png b/resources/icon/icon-256.png similarity index 100% rename from resources/icon/powder-256.png rename to resources/icon/icon-256.png diff --git a/resources/icon/powder-32.png b/resources/icon/icon-32.png similarity index 100% rename from resources/icon/powder-32.png rename to resources/icon/icon-32.png diff --git a/resources/icon/powder-48.png b/resources/icon/icon-48.png similarity index 100% rename from resources/icon/powder-48.png rename to resources/icon/icon-48.png diff --git a/resources/meson.build b/resources/meson.build index a5dba8e34..90aef9d69 100644 --- a/resources/meson.build +++ b/resources/meson.build @@ -13,7 +13,7 @@ if host_platform == 'linux' data_files += to_array.process('cps16.png', extra_args: 'cps16_png') data_files += to_array.process('cps32.png', extra_args: 'cps32_png') data_files += to_array.process('exe48.png', extra_args: 'exe48_png') - data_files += to_array.process('icon/powder-128.png', extra_args: 'icon_png') + data_files += to_array.process('icon/icon-128.png', extra_args: 'icon_png') data_files += to_array.process('save.xml', extra_args: 'save_xml') data_files += to_array.process(configure_file( input: 'powder.template.desktop', diff --git a/src/PowderToyFontEditor.cpp b/src/PowderToyFontEditor.cpp index b09cbe2dc..b5f4dcc50 100644 --- a/src/PowderToyFontEditor.cpp +++ b/src/PowderToyFontEditor.cpp @@ -15,7 +15,7 @@ #include #if defined(LIN) -# include "powder-128.png.h" +# include "icon-128.png.h" #endif #include diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index d44974f3d..876f42cc9 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -18,7 +18,7 @@ #include #if defined(LIN) -# include "powder-128.png.h" +# include "icon-128.png.h" #endif #include #include diff --git a/src/common/Platform.cpp b/src/common/Platform.cpp index 90b383fa7..fd91ab9c8 100644 --- a/src/common/Platform.cpp +++ b/src/common/Platform.cpp @@ -137,7 +137,7 @@ void DoRestart() exit(0); } #elif defined(LIN) || defined(MACOSX) - execl(exename.c_str(), "powder", NULL); + execl(exename.c_str(), exename.c_str(), NULL); int ret = errno; fprintf(stderr, "cannot restart: execl(...) failed: code %i\n", ret); #endif