meson: Use meson.can_run_host_binaries()

It is not only shorter than `not meson.is_cross_build() or
meson.has_exe_wrapper()` but also handle the case of cross compiling to
a compatible arch such as building for i386 on an amd64.
This commit is contained in:
Xavier Claessens 2022-03-08 09:48:36 -05:00 committed by Philip Withnall
parent 25ab87d8e5
commit 374be41433
21 changed files with 21 additions and 30 deletions

View File

@ -1,9 +0,0 @@
#!/usr/bin/env python3
import os
import subprocess
import sys
if not os.environ.get("DESTDIR"):
print("GIO module cache creation...")
subprocess.call([sys.argv[1], sys.argv[2]])

View File

@ -978,7 +978,7 @@ glib_compile_resources = executable('glib-compile-resources',
# Cannot override those programs in cross compilation case because they are # Cannot override those programs in cross compilation case because they are
# native executables that cannot be run on the build machine. # native executables that cannot be run on the build machine.
# See https://gitlab.gnome.org/GNOME/glib/issues/1859. # See https://gitlab.gnome.org/GNOME/glib/issues/1859.
if not meson.is_cross_build() if not meson.can_run_host_binaries()
meson.override_find_program('glib-compile-schemas', glib_compile_schemas) meson.override_find_program('glib-compile-schemas', glib_compile_schemas)
meson.override_find_program('glib-compile-resources', glib_compile_resources) meson.override_find_program('glib-compile-resources', glib_compile_resources)
meson.override_find_program('gio-querymodules', gio_querymodules) meson.override_find_program('gio-querymodules', gio_querymodules)

View File

@ -603,7 +603,7 @@ if installed_tests_enabled
endforeach endforeach
endif endif
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
compiler_type = '--compiler=@0@'.format(cc.get_id()) compiler_type = '--compiler=@0@'.format(cc.get_id())

View File

@ -71,7 +71,7 @@ int main ()
gl_cv_cc_double_expbit0_word = -1 gl_cv_cc_double_expbit0_word = -1
gl_cv_cc_double_expbit0_bit = -1 gl_cv_cc_double_expbit0_bit = -1
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(double_exponent_test, run_result = cc.run(double_exponent_test,
name : 'where to find the exponent in a \'double\'') name : 'where to find the exponent in a \'double\'')
if run_result.compiled() and run_result.returncode() == 0 if run_result.compiled() and run_result.returncode() == 0

View File

@ -76,7 +76,7 @@ int main()
return result; return result;
}''' }'''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(frexp_test, run_result = cc.run(frexp_test,
name : 'frexp works', name : 'frexp works',
dependencies : [libm]) dependencies : [libm])

View File

@ -104,7 +104,7 @@ int main()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(frexpl_test, run_result = cc.run(frexpl_test,
name : 'frexpl works', name : 'frexpl works',
dependencies : [libm]) dependencies : [libm])

View File

@ -33,7 +33,7 @@ int main()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(ldexpl_test, run_result = cc.run(ldexpl_test,
name : 'ldexpl works', name : 'ldexpl works',
dependencies : [libm]) dependencies : [libm])

View File

@ -79,7 +79,7 @@ glibc_printf_directive_a_test = '''
int main () { return 0; } int main () { return 0; }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_directive_a_test, run_result = cc.run(printf_directive_a_test,
name : 'printf supports the \'a\' and \'A\' directives') name : 'printf supports the \'a\' and \'A\' directives')
gl_cv_func_printf_directive_a = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_directive_a = run_result.compiled() and run_result.returncode() == 0

View File

@ -29,7 +29,7 @@ int main ()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_directive_f_test, run_result = cc.run(printf_directive_f_test,
name : 'printf supports the \'F\' directive') name : 'printf supports the \'F\' directive')
gl_cv_func_printf_directive_f = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_directive_f = run_result.compiled() and run_result.returncode() == 0

View File

@ -62,7 +62,7 @@ int main ()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_directive_ls_test, run_result = cc.run(printf_directive_ls_test,
name : 'printf supports the \'ls\' directive') name : 'printf supports the \'ls\' directive')
gl_cv_func_printf_directive_ls = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_directive_ls = run_result.compiled() and run_result.returncode() == 0

View File

@ -54,7 +54,7 @@ int main()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_enomem_test, run_result = cc.run(printf_enomem_test,
name : 'printf survives out-of-memory conditions') name : 'printf survives out-of-memory conditions')
gl_cv_func_printf_enomem = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_enomem = run_result.compiled() and run_result.returncode() == 0

View File

@ -20,7 +20,7 @@ int main ()
return 0; return 0;
}''' }'''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_flag_grouping_test, run_result = cc.run(printf_flag_grouping_test,
name : 'printf supports the grouping flag') name : 'printf supports the grouping flag')
gl_cv_func_printf_flag_grouping = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_flag_grouping = run_result.compiled() and run_result.returncode() == 0

View File

@ -22,7 +22,7 @@ int main ()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_flag_leftadjust_test, run_result = cc.run(printf_flag_leftadjust_test,
name : 'printf supports the left-adjust flag correctly') name : 'printf supports the left-adjust flag correctly')
gl_cv_func_printf_flag_leftadjust = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_flag_leftadjust = run_result.compiled() and run_result.returncode() == 0

View File

@ -23,7 +23,7 @@ int main ()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_flag_zero_test, run_result = cc.run(printf_flag_zero_test,
name : 'printf supports the zero flag correctly') name : 'printf supports the zero flag correctly')
gl_cv_func_printf_flag_zero = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_flag_zero = run_result.compiled() and run_result.returncode() == 0

View File

@ -77,7 +77,7 @@ int main ()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_infinite_double_test, run_result = cc.run(printf_infinite_double_test,
name : 'printf supports infinite \'double\' arguments') name : 'printf supports infinite \'double\' arguments')
gl_cv_func_printf_infinite = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_infinite = run_result.compiled() and run_result.returncode() == 0

View File

@ -167,7 +167,7 @@ int main ()
''' '''
if gl_cv_func_printf_long_double if gl_cv_func_printf_long_double
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_infinite_long_double_test, run_result = cc.run(printf_infinite_long_double_test,
name : 'printf supports infinite \'long double\' arguments') name : 'printf supports infinite \'long double\' arguments')
gl_cv_func_printf_infinite_long_double = (run_result.compiled() and run_result.returncode() == 0) gl_cv_func_printf_infinite_long_double = (run_result.compiled() and run_result.returncode() == 0)

View File

@ -30,7 +30,7 @@ int main ()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_long_double_test, run_result = cc.run(printf_long_double_test,
name : 'printf supports \'long double\' arguments') name : 'printf supports \'long double\' arguments')
gl_cv_func_printf_long_double = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_long_double = run_result.compiled() and run_result.returncode() == 0

View File

@ -37,7 +37,7 @@ int main ()
} }
''' '''
if not meson.is_cross_build() or meson.has_exe_wrapper() if meson.can_run_host_binaries()
run_result = cc.run(printf_precision_test, run_result = cc.run(printf_precision_test,
name : 'printf supports large precisions') name : 'printf supports large precisions')
gl_cv_func_printf_precision = run_result.compiled() and run_result.returncode() == 0 gl_cv_func_printf_precision = run_result.compiled() and run_result.returncode() == 0

View File

@ -315,7 +315,7 @@ executable('testing-helper', 'testing-helper.c',
) )
# some testing of gtester functionality # some testing of gtester functionality
if not meson.is_cross_build() and host_system != 'windows' if meson.can_run_host_binaries() and host_system != 'windows'
xmllint = find_program('xmllint', required: false) xmllint = find_program('xmllint', required: false)
if xmllint.found() if xmllint.found()
tmpsample_xml = custom_target('tmpsample.xml', tmpsample_xml = custom_target('tmpsample.xml',

View File

@ -25,7 +25,7 @@ if g_module_impl == 'G_MODULE_IMPL_DL'
if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
message('Building for MSVC: assuming that symbols are prefixed with underscore') message('Building for MSVC: assuming that symbols are prefixed with underscore')
g_module_need_uscore = 1 g_module_need_uscore = 1
elif meson.has_exe_wrapper() elif meson.can_run_host_binaries()
# FIXME: communicate result via stdout instead of return value, so non-0 return is not printed in bold red # FIXME: communicate result via stdout instead of return value, so non-0 return is not printed in bold red
rres = cc.run(dlopen_dlsym_test_code, rres = cc.run(dlopen_dlsym_test_code,
dependencies : libdl_dep, dependencies : libdl_dep,

View File

@ -12,7 +12,7 @@ project('glib', 'c', 'cpp',
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp') cxx = meson.get_compiler('cpp')
cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper() cc_can_run = meson.can_run_host_binaries()
if cc.get_argument_syntax() == 'msvc' if cc.get_argument_syntax() == 'msvc'
# Ignore several spurious warnings for things glib does very commonly # Ignore several spurious warnings for things glib does very commonly
@ -100,7 +100,7 @@ installed_tests_template = files('template.test.in')
installed_tests_template_tap = files('template-tap.test.in') installed_tests_template_tap = files('template-tap.test.in')
# Dont build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use) # Dont build the tests unless we can run them (either natively, in an exe wrapper, or by installing them for later use)
build_tests = get_option('tests') and (not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper()) or installed_tests_enabled) build_tests = get_option('tests') and (meson.can_run_host_binaries() or installed_tests_enabled)
add_project_arguments('-D_GNU_SOURCE', language: 'c') add_project_arguments('-D_GNU_SOURCE', language: 'c')