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.
This commit is contained in:
Tamás Bálint Misius 2023-01-25 09:30:43 +01:00
parent 416f84a1c4
commit 2566506e4b
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
15 changed files with 104 additions and 90 deletions

3
.github/build.sh vendored
View File

@ -185,7 +185,6 @@ meson_configure+=$'\t'-Dapp_data=$APP_DATA
meson_configure+=$'\t'-Dapp_vendor=$APP_VENDOR meson_configure+=$'\t'-Dapp_vendor=$APP_VENDOR
meson_configure+=$'\t'-Db_strip=false meson_configure+=$'\t'-Db_strip=false
meson_configure+=$'\t'-Db_staticpic=false meson_configure+=$'\t'-Db_staticpic=false
meson_configure+=$'\t'-Dinstall_check=true
meson_configure+=$'\t'-Dmod_id=$MOD_ID meson_configure+=$'\t'-Dmod_id=$MOD_ID
case $BSH_HOST_ARCH-$BSH_HOST_PLATFORM-$BSH_HOST_LIBC-$BSH_DEBUG_RELEASE in case $BSH_HOST_ARCH-$BSH_HOST_PLATFORM-$BSH_HOST_LIBC-$BSH_DEBUG_RELEASE in
x86_64-linux-gnu-debug) ;& x86_64-linux-gnu-debug) ;&
@ -376,7 +375,7 @@ if [[ $BSH_HOST_PLATFORM == android ]]; then
fi fi
if [[ $PACKAGE_MODE == appimage ]]; then 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 # 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 strip_target=$APP_EXE
fi fi
if [[ $BSH_BUILD_PLATFORM == windows ]]; then if [[ $BSH_BUILD_PLATFORM == windows ]]; then

View File

@ -72,11 +72,7 @@ endif
is_static = static_variant != 'none' is_static = static_variant != 'none'
is_debug = get_option('optimization') in [ '0', 'g' ] is_debug = get_option('optimization') in [ '0', 'g' ]
enforce_https = get_option('enforce_https') app_exe = get_option('app_exe')
if not is_debug and not enforce_https
error('refusing to build a release binary with enforce_https=false')
endif
tpt_libs_static = 'none' tpt_libs_static = 'none'
if static_variant == 'prebuilt' if static_variant == 'prebuilt'
@ -130,8 +126,6 @@ else
endif endif
endif endif
conf_data = configuration_data()
x86_sse_level_str = get_option('x86_sse') x86_sse_level_str = get_option('x86_sse')
if x86_sse_level_str == 'auto' if x86_sse_level_str == 'auto'
x86_sse_level = 20 x86_sse_level = 20
@ -322,47 +316,6 @@ else
ident_platform = 'UNKNOWN' ident_platform = 'UNKNOWN'
endif 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 = [] data_files = []
subdir('src') subdir('src')

View File

@ -18,10 +18,11 @@ option(
description: 'Don\'t show notifications about available updates' description: 'Don\'t show notifications about available updates'
) )
option( option(
'install_check', 'can_install',
type: 'boolean', type: 'combo',
value: false, choices: [ 'no', 'yes', 'yes_check', 'auto' ],
description: 'Do install check on startup' 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( option(
'http', 'http',

View File

@ -11,6 +11,7 @@ constexpr bool NOHTTP = @NOHTTP@;
constexpr bool LUACONSOLE = @LUACONSOLE@; constexpr bool LUACONSOLE = @LUACONSOLE@;
constexpr bool ALLOW_FAKE_NEWER_VERSION = @ALLOW_FAKE_NEWER_VERSION@; constexpr bool ALLOW_FAKE_NEWER_VERSION = @ALLOW_FAKE_NEWER_VERSION@;
constexpr bool USE_UPDATESERVER = @USE_UPDATESERVER@; constexpr bool USE_UPDATESERVER = @USE_UPDATESERVER@;
constexpr bool CAN_INSTALL = @CAN_INSTALL@;
constexpr bool INSTALL_CHECK = @INSTALL_CHECK@; constexpr bool INSTALL_CHECK = @INSTALL_CHECK@;
constexpr bool IGNORE_UPDATES = @IGNORE_UPDATES@; constexpr bool IGNORE_UPDATES = @IGNORE_UPDATES@;
constexpr bool ENFORCE_HTTPS = @ENFORCE_HTTPS@; constexpr bool ENFORCE_HTTPS = @ENFORCE_HTTPS@;

View File

@ -13,3 +13,4 @@ if enable_http
else else
client_files += files('RequestManagerNoHttp.cpp') client_files += files('RequestManagerNoHttp.cpp')
endif endif
conf_data.set('NOHTTP', not enable_http ? 'true' : 'false')

View File

@ -106,9 +106,4 @@ bool WriteFile(const std::vector<char> &fileData, ByteString filename)
} }
return true; return true;
} }
bool CanInstall()
{
return INSTALL_CHECK;
}
} }

View File

@ -46,7 +46,6 @@ namespace Platform
bool CanUpdate(); bool CanUpdate();
bool CanInstall();
bool Install(); bool Install();
bool ChangeDir(ByteString toDir); bool ChangeDir(ByteString toDir);

View File

@ -24,9 +24,4 @@ bool CanUpdate()
{ {
return false; return false;
} }
bool Install()
{
return false;
}
} }

View File

@ -48,9 +48,4 @@ bool CanUpdate()
{ {
return false; return false;
} }
bool Install()
{
return false;
}
} }

View File

@ -11,9 +11,4 @@ bool CanUpdate()
{ {
return false; return false;
} }
bool Install()
{
return false;
}
} }

View File

@ -4,19 +4,57 @@ common_files += files(
'tpt-rand.cpp', 'tpt-rand.cpp',
'tpt-thread-local.cpp', 'tpt-thread-local.cpp',
) )
can_install_enforce_no = false
set_window_icon = false
path_sep_char = '/'
if host_platform == 'windows' if host_platform == 'windows'
common_files += files('PlatformWindows.cpp') path_sep_char = '\\\\'
common_files += files(
'PlatformWindows.cpp',
)
elif host_platform == 'darwin' elif host_platform == 'darwin'
common_files += files('PlatformDarwin.cpp') can_install_enforce_no = true
common_files += files('PlatformPosix.cpp') common_files += files(
'PlatformDarwin.cpp',
'PlatformPosix.cpp',
)
elif host_platform == 'android' elif host_platform == 'android'
common_files += files('PlatformAndroid.cpp') can_install_enforce_no = true
common_files += files('PlatformPosix.cpp') common_files += files(
'PlatformAndroid.cpp',
'PlatformPosix.cpp',
)
elif host_platform == 'linux' elif host_platform == 'linux'
# TODO: again, this is more like "posix" than "linux" # TODO: again, this is more like "posix" than "linux"
common_files += files('PlatformLinux.cpp') set_window_icon = true
common_files += files('PlatformPosix.cpp') common_files += files(
'PlatformLinux.cpp',
'PlatformPosix.cpp',
)
else else
common_files += files('PlatformNull.cpp') can_install_enforce_no = true
common_files += files('PlatformPosix.cpp') common_files += files(
'PlatformNull.cpp',
'PlatformPosix.cpp',
)
endif 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')

View File

@ -252,7 +252,7 @@ void GameController::PlaceSave(ui::Point position)
void GameController::Install() 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.", { [] { 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()) if (Platform::Install())

View File

@ -25,6 +25,7 @@ if enable_http
else else
luaconsole_files += files('LuaSocketTCPNoHttp.cpp') luaconsole_files += files('LuaSocketTCPNoHttp.cpp')
endif endif
conf_data.set('LUACONSOLE', lua_variant != 'none' ? 'true' : 'false')
subdir('luascripts') subdir('luascripts')

View File

@ -1,8 +1,40 @@
configure_file( conf_data = configuration_data()
input: 'Config.template.h',
output: 'Config.h', app_id = get_option('app_id')
configuration: conf_data 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( powder_files = files(
'SDLCompat.cpp', 'SDLCompat.cpp',
@ -43,10 +75,12 @@ subdir('graphics')
subdir('gui') subdir('gui')
if lua_variant != 'none' if lua_variant != 'none'
subdir('lua') subdir('lua')
conf_data.set('LUACONSOLE', 'true')
else else
powder_files += files( powder_files += files(
'lua/PlainCommandInterface.cpp', 'lua/PlainCommandInterface.cpp',
) )
conf_data.set('LUACONSOLE', 'false')
endif endif
subdir('prefs') subdir('prefs')
subdir('resampler') subdir('resampler')
@ -80,3 +114,9 @@ configure_file(
output: 'ToolNumbers.h', output: 'ToolNumbers.h',
configuration: tools_conf_data configuration: tools_conf_data
) )
configure_file(
input: 'Config.template.h',
output: 'Config.h',
configuration: conf_data
)

View File

@ -31,4 +31,5 @@ if enable_gravfft
else else
powder_files += files('PlainGravity.cpp') powder_files += files('PlainGravity.cpp')
endif endif
conf_data.set('GRAVFFT', enable_gravfft ? 'true' : 'false')
render_files += files('PlainGravity.cpp') render_files += files('PlainGravity.cpp')