From 2566506e4b4afda26ffcf6d671361eba80b281fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 25 Jan 2023 09:30:43 +0100 Subject: [PATCH] Provide three levels of install support Namely: no, yes, and yes and ask at startup. The install_check option is thus replaced by the can_install option. -Dinstall_check=true maps to -Dcan_install=yes_check, while -Dinstall_check=false maps to -Dcan_install=yes. -Dcan_install=no is new and is recommended for downstream packaging, where -Dinstall_check=false was historically used. Also improve error messages about bad configuration here and there and scatter configuration code in subdirectories, where they can be closer to their areas of effect. --- .github/build.sh | 3 +- meson.build | 49 +---------------------------- meson_options.txt | 9 +++--- src/Config.template.h | 1 + src/client/http/meson.build | 1 + src/common/Platform.cpp | 5 --- src/common/Platform.h | 1 - src/common/PlatformAndroid.cpp | 5 --- src/common/PlatformDarwin.cpp | 5 --- src/common/PlatformNull.cpp | 5 --- src/common/meson.build | 56 +++++++++++++++++++++++++++------ src/gui/game/GameController.cpp | 2 +- src/lua/meson.build | 1 + src/meson.build | 50 ++++++++++++++++++++++++++--- src/simulation/meson.build | 1 + 15 files changed, 104 insertions(+), 90 deletions(-) diff --git a/.github/build.sh b/.github/build.sh index ee1b60477..d6adce12d 100755 --- a/.github/build.sh +++ b/.github/build.sh @@ -185,7 +185,6 @@ meson_configure+=$'\t'-Dapp_data=$APP_DATA meson_configure+=$'\t'-Dapp_vendor=$APP_VENDOR meson_configure+=$'\t'-Db_strip=false meson_configure+=$'\t'-Db_staticpic=false -meson_configure+=$'\t'-Dinstall_check=true meson_configure+=$'\t'-Dmod_id=$MOD_ID case $BSH_HOST_ARCH-$BSH_HOST_PLATFORM-$BSH_HOST_LIBC-$BSH_DEBUG_RELEASE in x86_64-linux-gnu-debug) ;& @@ -376,7 +375,7 @@ if [[ $BSH_HOST_PLATFORM == android ]]; then 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 + meson configure -Dcan_install=no -Dignore_updates=true -Dbuild_render=false -Dbuild_font=false strip_target=$APP_EXE fi if [[ $BSH_BUILD_PLATFORM == windows ]]; then diff --git a/meson.build b/meson.build index 2f82aae74..99250e1ef 100644 --- a/meson.build +++ b/meson.build @@ -72,11 +72,7 @@ endif is_static = static_variant != 'none' is_debug = get_option('optimization') in [ '0', 'g' ] -enforce_https = get_option('enforce_https') - -if not is_debug and not enforce_https - error('refusing to build a release binary with enforce_https=false') -endif +app_exe = get_option('app_exe') tpt_libs_static = 'none' if static_variant == 'prebuilt' @@ -130,8 +126,6 @@ else endif endif -conf_data = configuration_data() - x86_sse_level_str = get_option('x86_sse') if x86_sse_level_str == 'auto' x86_sse_level = 20 @@ -322,47 +316,6 @@ else ident_platform = 'UNKNOWN' endif -install_check = get_option('install_check') -if host_platform == 'darwin' or host_platform == 'android' - install_check = false -endif -app_exe = get_option('app_exe') -app_id = get_option('app_id') -mod_id = get_option('mod_id') -is_snapshot = get_option('snapshot') -is_beta = get_option('beta') -is_mod = mod_id > 0 -update_server = get_option('update_server') - -conf_data.set('SET_WINDOW_ICON', host_platform == 'linux' ? 'true' : 'false') -conf_data.set('X86', is_x86 ? 'true' : 'false') -conf_data.set('BETA', is_beta ? 'true' : 'false') -conf_data.set('INSTALL_CHECK', install_check ? 'true' : 'false') -conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false') -conf_data.set('MOD_ID', mod_id) -conf_data.set('DEBUG', is_debug ? 'true' : 'false') -conf_data.set('SNAPSHOT', is_snapshot ? 'true' : 'false') -conf_data.set('MOD', is_mod ? 'true' : 'false') -conf_data.set('SNAPSHOT_ID', get_option('snapshot_id')) -conf_data.set('SERVER', get_option('server')) -conf_data.set('STATICSERVER', get_option('static_server')) -conf_data.set('UPDATESERVER', update_server) -conf_data.set('USE_UPDATESERVER', update_server != '' ? 'true' : 'false') -conf_data.set('IDENT_PLATFORM', ident_platform) -conf_data.set('IDENT', '@0@-@1@-@2@'.format(host_arch, host_platform, host_libc).to_upper()) -conf_data.set('ENFORCE_HTTPS', enforce_https ? 'true' : 'false') -conf_data.set('ALLOW_FAKE_NEWER_VERSION', (is_snapshot or is_beta or is_debug or is_mod) ? 'true' : 'false') -conf_data.set('APPNAME', get_option('app_name')) -conf_data.set('APPCOMMENT', get_option('app_comment')) -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')) -conf_data.set('LUACONSOLE', lua_variant != 'none' ? 'true' : 'false') -conf_data.set('GRAVFFT', enable_gravfft ? 'true' : 'false') -conf_data.set('NOHTTP', not enable_http ? 'true' : 'false') -conf_data.set('PATH_SEP_CHAR', host_platform == 'windows' ? '\\\\' : '/') - data_files = [] subdir('src') diff --git a/meson_options.txt b/meson_options.txt index cfffdafee..7c7f2a51d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -18,10 +18,11 @@ option( description: 'Don\'t show notifications about available updates' ) option( - 'install_check', - type: 'boolean', - value: false, - description: 'Do install check on startup' + 'can_install', + type: 'combo', + choices: [ 'no', 'yes', 'yes_check', 'auto' ], + value: 'auto', + description: 'Disable (\'no\') or enable (\'yes\') setting up file and URL associations, or even offer to do it at startup (\'yes_check\')' ) option( 'http', diff --git a/src/Config.template.h b/src/Config.template.h index 04a6c892d..0eade2857 100644 --- a/src/Config.template.h +++ b/src/Config.template.h @@ -11,6 +11,7 @@ constexpr bool NOHTTP = @NOHTTP@; constexpr bool LUACONSOLE = @LUACONSOLE@; constexpr bool ALLOW_FAKE_NEWER_VERSION = @ALLOW_FAKE_NEWER_VERSION@; constexpr bool USE_UPDATESERVER = @USE_UPDATESERVER@; +constexpr bool CAN_INSTALL = @CAN_INSTALL@; constexpr bool INSTALL_CHECK = @INSTALL_CHECK@; constexpr bool IGNORE_UPDATES = @IGNORE_UPDATES@; constexpr bool ENFORCE_HTTPS = @ENFORCE_HTTPS@; diff --git a/src/client/http/meson.build b/src/client/http/meson.build index 8fe08df9a..90af28efb 100644 --- a/src/client/http/meson.build +++ b/src/client/http/meson.build @@ -13,3 +13,4 @@ if enable_http else client_files += files('RequestManagerNoHttp.cpp') endif +conf_data.set('NOHTTP', not enable_http ? 'true' : 'false') diff --git a/src/common/Platform.cpp b/src/common/Platform.cpp index b14b72cb3..55f4b1242 100644 --- a/src/common/Platform.cpp +++ b/src/common/Platform.cpp @@ -106,9 +106,4 @@ bool WriteFile(const std::vector &fileData, ByteString filename) } return true; } - -bool CanInstall() -{ - return INSTALL_CHECK; -} } diff --git a/src/common/Platform.h b/src/common/Platform.h index 719a84b66..884aa079d 100644 --- a/src/common/Platform.h +++ b/src/common/Platform.h @@ -46,7 +46,6 @@ namespace Platform bool CanUpdate(); - bool CanInstall(); bool Install(); bool ChangeDir(ByteString toDir); diff --git a/src/common/PlatformAndroid.cpp b/src/common/PlatformAndroid.cpp index 034b0ff04..e2599ceff 100644 --- a/src/common/PlatformAndroid.cpp +++ b/src/common/PlatformAndroid.cpp @@ -24,9 +24,4 @@ bool CanUpdate() { return false; } - -bool Install() -{ - return false; -} } diff --git a/src/common/PlatformDarwin.cpp b/src/common/PlatformDarwin.cpp index a75be3c38..b73a675aa 100644 --- a/src/common/PlatformDarwin.cpp +++ b/src/common/PlatformDarwin.cpp @@ -48,9 +48,4 @@ bool CanUpdate() { return false; } - -bool Install() -{ - return false; -} } diff --git a/src/common/PlatformNull.cpp b/src/common/PlatformNull.cpp index 1f082f369..96cd3a4cd 100644 --- a/src/common/PlatformNull.cpp +++ b/src/common/PlatformNull.cpp @@ -11,9 +11,4 @@ bool CanUpdate() { return false; } - -bool Install() -{ - return false; -} } diff --git a/src/common/meson.build b/src/common/meson.build index 677ef088c..a07e07cb9 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -4,19 +4,57 @@ common_files += files( 'tpt-rand.cpp', 'tpt-thread-local.cpp', ) + +can_install_enforce_no = false +set_window_icon = false +path_sep_char = '/' if host_platform == 'windows' - common_files += files('PlatformWindows.cpp') + path_sep_char = '\\\\' + common_files += files( + 'PlatformWindows.cpp', + ) elif host_platform == 'darwin' - common_files += files('PlatformDarwin.cpp') - common_files += files('PlatformPosix.cpp') + can_install_enforce_no = true + common_files += files( + 'PlatformDarwin.cpp', + 'PlatformPosix.cpp', + ) elif host_platform == 'android' - common_files += files('PlatformAndroid.cpp') - common_files += files('PlatformPosix.cpp') + can_install_enforce_no = true + common_files += files( + 'PlatformAndroid.cpp', + 'PlatformPosix.cpp', + ) elif host_platform == 'linux' # TODO: again, this is more like "posix" than "linux" - common_files += files('PlatformLinux.cpp') - common_files += files('PlatformPosix.cpp') + set_window_icon = true + common_files += files( + 'PlatformLinux.cpp', + 'PlatformPosix.cpp', + ) else - common_files += files('PlatformNull.cpp') - common_files += files('PlatformPosix.cpp') + can_install_enforce_no = true + common_files += files( + 'PlatformNull.cpp', + 'PlatformPosix.cpp', + ) endif +conf_data.set('SET_WINDOW_ICON', set_window_icon ? 'true' : 'false') +conf_data.set('PATH_SEP_CHAR', path_sep_char) + +can_install = get_option('can_install') +if can_install == 'auto' + can_install = 'yes_check' + if is_debug + can_install = 'yes' + endif + if can_install_enforce_no + can_install = 'no' + endif +endif +if can_install != 'no' and can_install_enforce_no + error('cannot provide install support, configure with -Dcan_install=no to fix this error') +endif +conf_data.set('CAN_INSTALL', can_install != 'no' ? 'true' : 'false') +conf_data.set('INSTALL_CHECK', can_install == 'yes_check' ? 'true' : 'false') + diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 841d278ba..4b57041a3 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -252,7 +252,7 @@ void GameController::PlaceSave(ui::Point position) void GameController::Install() { - if (Platform::CanInstall()) + if constexpr (CAN_INSTALL) { new ConfirmPrompt("Install " + String(APPNAME), "Do you wish to install " + String(APPNAME) + " on this computer?\nThis allows you to open save files and saves directly from the website.", { [] { if (Platform::Install()) diff --git a/src/lua/meson.build b/src/lua/meson.build index 137466f0b..997fe04c4 100644 --- a/src/lua/meson.build +++ b/src/lua/meson.build @@ -25,6 +25,7 @@ if enable_http else luaconsole_files += files('LuaSocketTCPNoHttp.cpp') endif +conf_data.set('LUACONSOLE', lua_variant != 'none' ? 'true' : 'false') subdir('luascripts') diff --git a/src/meson.build b/src/meson.build index 3e433fcc4..083d34e66 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,8 +1,40 @@ -configure_file( - input: 'Config.template.h', - output: 'Config.h', - configuration: conf_data -) +conf_data = configuration_data() + +app_id = get_option('app_id') +mod_id = get_option('mod_id') +is_snapshot = get_option('snapshot') +is_beta = get_option('beta') +is_mod = mod_id > 0 +conf_data.set('X86', is_x86 ? 'true' : 'false') +conf_data.set('BETA', is_beta ? 'true' : 'false') +conf_data.set('MOD_ID', mod_id) +conf_data.set('DEBUG', is_debug ? 'true' : 'false') +conf_data.set('MOD', is_mod ? 'true' : 'false') +conf_data.set('SNAPSHOT', is_snapshot ? 'true' : 'false') +conf_data.set('SNAPSHOT_ID', get_option('snapshot_id')) +conf_data.set('ALLOW_FAKE_NEWER_VERSION', (is_snapshot or is_beta or is_debug or is_mod) ? 'true' : 'false') +conf_data.set('IDENT_PLATFORM', ident_platform) +conf_data.set('IDENT', '@0@-@1@-@2@'.format(host_arch, host_platform, host_libc).to_upper()) + +update_server = get_option('update_server') +conf_data.set('UPDATESERVER', update_server) +conf_data.set('USE_UPDATESERVER', update_server != '' ? 'true' : 'false') + +enforce_https = get_option('enforce_https') +if not is_debug and not enforce_https + error('refusing to build a release binary without enforcing HTTPS, configure with -Denforce_https=true to fix this error') +endif +conf_data.set('ENFORCE_HTTPS', enforce_https ? 'true' : 'false') + +conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false') +conf_data.set('SERVER', get_option('server')) +conf_data.set('STATICSERVER', get_option('static_server')) +conf_data.set('APPNAME', get_option('app_name')) +conf_data.set('APPCOMMENT', get_option('app_comment')) +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')) powder_files = files( 'SDLCompat.cpp', @@ -43,10 +75,12 @@ subdir('graphics') subdir('gui') if lua_variant != 'none' subdir('lua') + conf_data.set('LUACONSOLE', 'true') else powder_files += files( 'lua/PlainCommandInterface.cpp', ) + conf_data.set('LUACONSOLE', 'false') endif subdir('prefs') subdir('resampler') @@ -80,3 +114,9 @@ configure_file( output: 'ToolNumbers.h', configuration: tools_conf_data ) + +configure_file( + input: 'Config.template.h', + output: 'Config.h', + configuration: conf_data +) diff --git a/src/simulation/meson.build b/src/simulation/meson.build index 5597d3292..12f2b81fc 100644 --- a/src/simulation/meson.build +++ b/src/simulation/meson.build @@ -31,4 +31,5 @@ if enable_gravfft else powder_files += files('PlainGravity.cpp') endif +conf_data.set('GRAVFFT', enable_gravfft ? 'true' : 'false') render_files += files('PlainGravity.cpp')