From 3086d55972bfeb1faf15f620d54435c7d07c5e50 Mon Sep 17 00:00:00 2001 From: ahochheiden Date: Fri, 25 Nov 2022 17:22:03 +0000 Subject: [PATCH] Bug 1776255 - Add the appropriate 'when' to all 'option' that end up calling 'pkg_check_modules' later r=firefox-build-system-reviewers,glandium We don't check for pkg-config on some platforms (Windows, OSX, Android). On those platforms, calling 'pkg_check_modules' will not work. Adding the same 'when' used for the 'pkg_config' check to all the options that end up calling 'pkg_check_modules' effectively disables them, and prevents 'pkg_check_modules' from being called. Differential Revision: https://phabricator.services.mozilla.com/D150649 --- build/moz.configure/nspr.configure | 17 +++- build/moz.configure/nss.configure | 6 +- build/moz.configure/pkg.configure | 25 ++++-- build/moz.configure/toolchain.configure | 6 +- js/ffi.configure | 6 +- js/moz.configure | 14 +++- moz.configure | 14 +++- .../test/configure/test_checks_configure.py | 14 ++-- toolkit/moz.configure | 84 +++++++++++++++---- 9 files changed, 140 insertions(+), 46 deletions(-) diff --git a/build/moz.configure/nspr.configure b/build/moz.configure/nspr.configure index 06f03d9bc72dd..3c0933da5effd 100644 --- a/build/moz.configure/nspr.configure +++ b/build/moz.configure/nspr.configure @@ -19,10 +19,19 @@ def enable_nspr_build(enable): return enable -system_lib_option("--with-system-nspr", help="Use system NSPR") +system_lib_option( + "--with-system-nspr", + help="Use system NSPR", + when=use_pkg_config, +) + + +@depends("--with-system-nspr", when=use_pkg_config) +def with_system_nspr_option(with_system_nspr): + return with_system_nspr -@depends(enable_nspr_build, "--with-system-nspr", js_standalone) +@depends(enable_nspr_build, with_system_nspr_option, js_standalone) def build_nspr(nspr_build, system_nspr, js_standalone): if nspr_build is not None and nspr_build.origin != "default": if nspr_build and system_nspr: @@ -36,7 +45,7 @@ set_config("MOZ_BUILD_NSPR", True, when=build_nspr) set_config("MOZ_SYSTEM_NSPR", True, when="--with-system-nspr") -@depends(build_nspr, "--with-system-nspr", js_standalone) +@depends(build_nspr, with_system_nspr_option, js_standalone) def js_without_nspr(build_nspr, system_nspr, js_standalone): if js_standalone: return not build_nspr and not system_nspr @@ -74,7 +83,7 @@ def nspr_pkg(nspr_pkg): ) -@depends("--with-system-nspr", nspr_minver) +@depends(with_system_nspr_option, nspr_minver) def pkgconf_requires_private(system_nspr, nspr_minver): if not system_nspr: return "" diff --git a/build/moz.configure/nss.configure b/build/moz.configure/nss.configure index fa58afef37b0f..8667e81f62d9f 100644 --- a/build/moz.configure/nss.configure +++ b/build/moz.configure/nss.configure @@ -4,7 +4,11 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -system_lib_option("--with-system-nss", help="Use system NSS") +system_lib_option( + "--with-system-nss", + help="Use system NSS", + when=use_pkg_config, +) imply_option("--with-system-nspr", True, when="--with-system-nss") diff --git a/build/moz.configure/pkg.configure b/build/moz.configure/pkg.configure index 6b460ae174eed..79ff780cf7db6 100644 --- a/build/moz.configure/pkg.configure +++ b/build/moz.configure/pkg.configure @@ -10,13 +10,17 @@ def pkg_config(prefixes): return tuple("{}pkg-config".format(p) for p in (prefixes or ()) + ("",)) +@depends(compile_environment, target) +def use_pkg_config(compile_environment, target): + return compile_environment and target.os not in ("WINNT", "OSX", "Android") + + pkg_config = check_prog( "PKG_CONFIG", pkg_config, bootstrap=depends(when=target_sysroot.bootstrapped)(lambda: "pkgconf"), allow_missing=True, - when=compile_environment - & depends(target.os)(lambda os: os not in ("WINNT", "OSX", "Android")), + when=use_pkg_config, ) @@ -101,7 +105,12 @@ set_config("PKG_CONFIG_LIBDIR", pkg_config_vars.PKG_CONFIG_LIBDIR) # Returns `True` when the package description is fulfilled. @template def pkg_check_modules( - var, package_desc, when=always, allow_missing=False, config=True, cflags_only=False + var, + package_desc, + when=always, + allow_missing=False, + config=True, + cflags_only=False, ): @depends(dependable(package_desc), when=when) def package_desc(desc): @@ -116,11 +125,11 @@ def pkg_check_modules( allow_missing = dependable(allow_missing) - @depends(when, "--enable-compile-environment") - def when_and_compile_environment(when, compile_environment): - return when and compile_environment + @depends(when, when=use_pkg_config) + def when_and_use_pkg_config(when): + return when - @depends(pkg_config, pkg_config_version, when=when_and_compile_environment) + @depends(pkg_config, pkg_config_version, when=when_and_use_pkg_config) def check_pkg_config(pkg_config, version): min_version = "0.9.0" if pkg_config is None: @@ -140,7 +149,7 @@ def pkg_check_modules( pkg_config_env, package_desc, allow_missing, - when=when_and_compile_environment, + when=when_and_use_pkg_config, ) @imports("sys") @imports(_from="mozbuild.configure.util", _import="LineIO") diff --git a/build/moz.configure/toolchain.configure b/build/moz.configure/toolchain.configure index a33f243d405c0..826e7c2243469 100755 --- a/build/moz.configure/toolchain.configure +++ b/build/moz.configure/toolchain.configure @@ -1034,7 +1034,11 @@ target_sysroot = sysroot(target) def system_lib_option(name, *args, **kwargs): option(name, *args, **kwargs) - @depends(name, target_sysroot.bootstrapped) + @depends( + name, + target_sysroot.bootstrapped, + when=kwargs.get("when"), + ) def no_system_lib_in_sysroot(value, bootstrapped): if bootstrapped and value: die( diff --git a/js/ffi.configure b/js/ffi.configure index ec4e572c7a1b1..6217233d3b84a 100644 --- a/js/ffi.configure +++ b/js/ffi.configure @@ -15,10 +15,12 @@ def force_system_ffi(target): imply_option("--with-system-ffi", force_system_ffi, "target") system_lib_option( - "--with-system-ffi", help="Use system libffi (located with pkgconfig)" + "--with-system-ffi", + help="Use system libffi (located with pkgconfig)", + when=use_pkg_config, ) -use_system_ffi = depends_if("--with-system-ffi")(lambda _: True) +use_system_ffi = depends_if("--with-system-ffi", when=use_pkg_config)(lambda _: True) system_ffi = pkg_check_modules("MOZ_FFI", "libffi > 3.0.9", when=use_system_ffi) diff --git a/js/moz.configure b/js/moz.configure index 707c64808719c..22e4603e0a762 100644 --- a/js/moz.configure +++ b/js/moz.configure @@ -1014,12 +1014,22 @@ set_define( # ECMAScript Internationalization API Support (uses ICU) # ====================================================== -system_lib_option("--with-system-icu", help="Use system ICU") +system_lib_option( + "--with-system-icu", + help="Use system ICU", + when=use_pkg_config, +) + + +@depends("--with-system-icu", when=use_pkg_config) +def enable_system_icu_option(enable_system_icu): + return enable_system_icu + system_icu = pkg_check_modules("MOZ_ICU", "icu-i18n >= 72.1", when="--with-system-icu") -@depends("--with-system-icu") +@depends(enable_system_icu_option) def in_tree_icu(system_icu): return not system_icu diff --git a/moz.configure b/moz.configure index 2b6446c6c81f1..9f4a55eb72b7c 100755 --- a/moz.configure +++ b/moz.configure @@ -193,6 +193,8 @@ include("build/moz.configure/bootstrap.configure") # check_prog to use bootstrap_search_path directly because check_prog # comes first, so we use a trick to allow it. Uses of check_prog # happening before here won't allow bootstrap. + + @template def check_prog(*args, **kwargs): kwargs["bootstrap_search_path"] = bootstrap_search_path @@ -983,12 +985,18 @@ option( nargs="?", default=system_zlib_default, help="{Use|Do not use} system libz", + when=use_pkg_config, ) -@depends("--with-system-zlib") +@depends("--with-system-zlib", when=use_pkg_config) +def with_system_zlib_option(with_system_zlib): + return with_system_zlib + + +@depends(with_system_zlib_option) def deprecated_system_zlib_path(value): - if len(value) == 1: + if value and len(value) == 1: die( "--with-system-zlib=PATH is not supported anymore. Please use " "--with-system-zlib and set any necessary pkg-config environment variable." @@ -1000,7 +1008,7 @@ pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib") set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib") -@depends("--with-system-zlib", js_shared, moz_linker, target.os) +@depends(with_system_zlib_option, js_shared, moz_linker, target.os) def zlib_in_mozglue(system_zlib, js_shared, linker, os): if not system_zlib and (js_shared or linker or os == "Android"): return True diff --git a/python/mozbuild/mozbuild/test/configure/test_checks_configure.py b/python/mozbuild/mozbuild/test/configure/test_checks_configure.py index 7cda43ed52b39..4519b96c00aea 100644 --- a/python/mozbuild/mozbuild/test/configure/test_checks_configure.py +++ b/python/mozbuild/mozbuild/test/configure/test_checks_configure.py @@ -4,21 +4,19 @@ from __future__ import absolute_import, print_function, unicode_literals -from six import StringIO import os import sys import textwrap import unittest -from mozunit import main, MockedOpen - +from buildconfig import topsrcdir +from common import ConfigureTestSandbox, ensure_exe_extension, fake_short_path from mozbuild.configure import ConfigureError, ConfigureSandbox -from mozbuild.util import exec_ from mozbuild.shellutil import quote as shell_quote +from mozbuild.util import exec_ from mozpack import path as mozpath - -from buildconfig import topsrcdir -from common import ConfigureTestSandbox, ensure_exe_extension, fake_short_path +from mozunit import MockedOpen, main +from six import StringIO class TestChecksConfigure(unittest.TestCase): @@ -734,7 +732,7 @@ def get_result(cmd, args=[], bootstrapped_sysroot=False, extra_paths=None): toolchain_prefix = depends(when=True)(lambda: None) target_multiarch_dir = depends(when=True)(lambda: None) target_sysroot = depends(when=True)(lambda: %(sysroot)s) - target = depends(when=True)(lambda: None) + target = depends(when=True)(lambda: namespace(os="unknown")) include('%(topsrcdir)s/build/moz.configure/util.configure') include('%(topsrcdir)s/build/moz.configure/checks.configure') # Skip bootstrapping. diff --git a/toolkit/moz.configure b/toolkit/moz.configure index a3cb536a7e03c..14cb91bddf1da 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -320,10 +320,20 @@ set_config("MOZ_WASAPI", imply_wasapi, when="--enable-audio-backends") # ALSA cubeb backend # ============================================================== -option("--enable-alsa", env="MOZ_ALSA", help="Enable ALSA audio backend.") +option( + "--enable-alsa", + env="MOZ_ALSA", + help="Enable ALSA audio backend.", + when=use_pkg_config, +) + + +@depends("--enable-alsa", when=use_pkg_config) +def enable_alsa_option(enable_alsa): + return enable_alsa -@depends("--enable-alsa", midir_linux_support) +@depends(enable_alsa_option, midir_linux_support) def enable_alsa_or_midir_linux_support(alsa_enabled, midir_linux_support): return alsa_enabled or midir_linux_support @@ -334,7 +344,12 @@ set_config("MOZ_ALSA", True, when="--enable-alsa") # JACK cubeb backend # ============================================================== -system_lib_option("--enable-jack", env="MOZ_JACK", help="Enable JACK audio backend.") +system_lib_option( + "--enable-jack", + env="MOZ_JACK", + help="Enable JACK audio backend.", + when=use_pkg_config, +) jack = pkg_check_modules("MOZ_JACK", "jack", when="--enable-jack") @@ -346,6 +361,7 @@ option( "--enable-pulseaudio", env="MOZ_PULSEAUDIO", help="{Enable|Disable} PulseAudio audio backend.", + when=use_pkg_config, ) pulseaudio = pkg_check_modules("MOZ_PULSEAUDIO", "libpulse", when="--enable-pulseaudio") @@ -354,7 +370,12 @@ set_config("MOZ_PULSEAUDIO", depends_if(pulseaudio)(lambda _: True)) # sndio cubeb backend # ============================================================== -system_lib_option("--enable-sndio", env="MOZ_SNDIO", help="Enable sndio audio backend.") +system_lib_option( + "--enable-sndio", + env="MOZ_SNDIO", + help="Enable sndio audio backend.", + when=use_pkg_config, +) sndio = pkg_check_modules("MOZ_SNDIO", "sndio", when="--enable-sndio") @@ -978,10 +999,15 @@ set_define("MOZ_TELEMETRY_ON_BY_DEFAULT", True, when=telemetry_on_by_default) # gpsd support # ============================================================== -system_lib_option("--enable-gpsd", env="MOZ_GPSD", help="Enable gpsd support") +system_lib_option( + "--enable-gpsd", + env="MOZ_GPSD", + help="Enable gpsd support", + when=use_pkg_config, +) -@depends("--enable-gpsd") +@depends("--enable-gpsd", when=use_pkg_config) def gpsd(value): return bool(value) @@ -1129,7 +1155,9 @@ set_config( ) system_lib_option( - "--with-system-webp", help="Use system libwebp (located with pkgconfig)" + "--with-system-webp", + help="Use system libwebp (located with pkgconfig)", + when=use_pkg_config, ) system_webp = pkg_check_modules( @@ -1873,9 +1901,15 @@ with only_when(compile_environment): with only_when(compile_environment): system_lib_option( - "--with-system-libvpx", help="Use system libvpx (located with pkgconfig)" + "--with-system-libvpx", + help="Use system libvpx (located with pkgconfig)", + when=use_pkg_config, ) + @depends("--with-system-libvpx", when=use_pkg_config) + def with_system_libvpx_option(with_system_libvpx): + return with_system_libvpx + with only_when("--with-system-libvpx"): vpx = pkg_check_modules("MOZ_LIBVPX", "vpx >= 1.10.0") @@ -1900,7 +1934,7 @@ with only_when(compile_environment): set_config("MOZ_SYSTEM_LIBVPX", True) - @depends("--with-system-libvpx", target) + @depends(with_system_libvpx_option, target) def in_tree_vpx(system_libvpx, target): if system_libvpx: return @@ -2111,9 +2145,10 @@ with only_when(compile_environment): "--with-system-png", nargs="?", help="Use system libpng", + when=use_pkg_config, ) - @depends("--with-system-png") + @depends("--with-system-png", when=use_pkg_config) def deprecated_system_png_path(value): if len(value) == 1: die( @@ -2807,9 +2842,10 @@ with only_when(compile_environment): "--with-system-libevent", nargs="?", help="Use system libevent", + when=use_pkg_config, ) - @depends("--with-system-libevent") + @depends("--with-system-libevent", when=use_pkg_config) def deprecated_system_libevent_path(value): if len(value) == 1: die( @@ -2886,9 +2922,13 @@ with only_when(toolkit_gtk): # DBus # ============================================================== with only_when(toolkit_gtk): - option("--disable-dbus", help="Disable dbus support") + option("--disable-dbus", help="Disable dbus support", when=use_pkg_config) + + @depends("--enable-dbus", when=use_pkg_config) + def enable_dbus_option(enable_dbus): + return enable_dbus - with only_when("--enable-dbus"): + with only_when(enable_dbus_option): pkg_check_modules("MOZ_DBUS", "dbus-1 >= 0.60") pkg_check_modules("MOZ_DBUS_GLIB", "dbus-glib-1 >= 0.60") @@ -2913,7 +2953,7 @@ set_define("NECKO_WIFI", True, when="--enable-necko-wifi") @depends( depends("--enable-necko-wifi", when=necko_wifi_when)(lambda x: x), - depends("--enable-dbus", when=toolkit_gtk)(lambda x: x), + depends(enable_dbus_option, when=toolkit_gtk)(lambda x: x), when=depends(target)(lambda t: t.os == "GNU" and t.kernel == "Linux"), ) def necko_wifi_dbus(necko_wifi, dbus): @@ -2952,7 +2992,11 @@ set_define("MOZ_LAYERS_HAVE_LOG", True, when="--enable-dump-painting") # libproxy support # ============================================================== with only_when(toolkit_gtk): - system_lib_option("--enable-libproxy", help="Enable libproxy support") + system_lib_option( + "--enable-libproxy", + help="Enable libproxy support", + when=use_pkg_config, + ) with only_when("--enable-libproxy"): pkg_check_modules("MOZ_LIBPROXY", "libproxy-1.0") @@ -3043,10 +3087,16 @@ set_define("ENABLE_SYSTEM_EXTENSION_DIRS", True, when="--enable-system-extension # ============================================================== with only_when(compile_environment): system_lib_option( - "--enable-system-pixman", help="Use system pixman (located with pkgconfig)" + "--enable-system-pixman", + help="Use system pixman (located with pkgconfig)", + when=use_pkg_config, ) - @depends("--enable-system-pixman") + @depends("--enable-system-pixman", when=use_pkg_config) + def enable_system_pixman_option(enable_system_pixman): + return enable_system_pixman + + @depends(enable_system_pixman_option) def in_tree_pixman(pixman): return not pixman