Let mods customize app constants

Mainly via meson_options.txt.
This commit is contained in:
Tamás Bálint Misius 2022-12-17 13:53:37 +01:00
parent 2140d6db4b
commit 59f89f9a46
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
25 changed files with 123 additions and 99 deletions

93
.github/build.sh vendored
View File

@ -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

1
.github/mod_id.txt vendored
View File

@ -1 +0,0 @@
0

36
.github/prepare.py vendored
View File

@ -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

View File

@ -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 }}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.powdertoy.tpt"
package="@APPID@"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto"

View File

@ -1,4 +1,4 @@
package uk.co.powdertoy.tpt;
package @APPID@;
import org.libsdl.app.SDLActivity;

View File

@ -32,12 +32,14 @@ if tpt_arch == 'aarch64':
if tpt_arch == 'x86_64':
android_arch = 'x86_64'
sha_packaged_name = 'libpowder.so'
manifest_path = os.path.join(build_dir, manifest_xml)
sha_path = os.path.join(build_dir, sha_name)
unaligned_path = os.path.join(build_dir, unaligned_name)
private_dir = os.path.join(build_dir, private_name)
arch_dir = os.path.join(private_dir, 'lib', android_arch)
sha_lib_path = os.path.join(arch_dir, sha_name)
sha_lib_path = os.path.join(arch_dir, sha_packaged_name)
flat_dir = os.path.join(private_dir, 'flat')
if os.path.exists(arch_dir):
@ -79,7 +81,7 @@ if subprocess.run([
aapt,
'add',
unaligned_path,
os.path.join('lib', android_arch, sha_name),
os.path.join('lib', android_arch, sha_packaged_name),
], cwd = private_dir).returncode:
sys.exit(1)

View File

@ -1,6 +1,12 @@
android_manifest_xml = files('AndroidManifest.xml')
powder_jar_sources = files(
'uk/co/powdertoy/tpt/PowderActivity.java',
android_manifest_xml = configure_file(
input: 'AndroidManifest.template.xml',
output: 'AndroidManifest.xml',
configuration: conf_data,
)
powder_jar_sources = configure_file(
input: 'PowderActivity.template.java',
output: 'PowderActivity.java',
configuration: conf_data,
)
subdir('res')
@ -12,7 +18,7 @@ android_keystore = get_option('android_keystore')
sdl_jar = tpt_libs.get_variable('sdl_jar')
powder_jar = custom_target(
'powder-jar',
output: 'powder.jar',
output: app_exe + '.jar',
command: [
python3,
files('powder-jar.py'),
@ -31,7 +37,7 @@ powder_jar = custom_target(
)
unaligned_apk = custom_target(
'build-apk',
output: 'powder.unaligned.apk',
output: app_exe + '.unaligned.apk',
input: powder_sha,
command: [
python3,
@ -55,7 +61,7 @@ unaligned_apk = custom_target(
)
unsigned_apk = custom_target(
'align-apk',
output: 'powder.unsigned.apk',
output: app_exe + '.unsigned.apk',
input: unaligned_apk,
command: [
python3,
@ -68,7 +74,7 @@ unsigned_apk = custom_target(
)
signed_apk = custom_target(
'sign-apk',
output: 'powder.apk',
output: app_exe + '.apk',
input: unsigned_apk,
command: [
python3,
@ -94,6 +100,6 @@ if adb.found()
input: [ signed_apk, install_apk ],
build_always_stale: true,
output: 'run-apk',
command: [ python3, files('run-apk.py'), adb, meson.project_build_root(), '@OUTPUT@', '@INPUT0@' ],
command: [ python3, files('run-apk.py'), adb, meson.project_build_root(), '@OUTPUT@', '@INPUT0@', app_id ],
)
endif

View File

@ -1,6 +1,7 @@
android_resources = files(
'mipmap-mdpi/ic_launcher.png',
'values/colors.xml',
'values/strings.xml',
'values/styles.xml',
)
subdir('values')

View File

@ -0,0 +1,5 @@
android_resources += configure_file(
input: 'strings.template.xml',
output: 'strings.xml',
configuration: conf_data,
)

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">@APPNAME@</string>
</resources>

View File

@ -1,3 +0,0 @@
<resources>
<string name="app_name">The Powder Toy</string>
</resources>

View File

@ -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)

View File

@ -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,

View File

@ -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'
)

View File

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -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',

View File

@ -15,7 +15,7 @@
#include <iostream>
#if defined(LIN)
# include "powder-128.png.h"
# include "icon-128.png.h"
#endif
#include <stdexcept>

View File

@ -18,7 +18,7 @@
#include <iostream>
#if defined(LIN)
# include "powder-128.png.h"
# include "icon-128.png.h"
#endif
#include <csignal>
#include <stdexcept>

View File

@ -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