Skip to content

Commit

Permalink
Bug 1776255 - Add the appropriate 'when' to all 'option' that end up …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ahochheiden committed Nov 25, 2022
1 parent bae4637 commit 3086d55
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 46 deletions.
17 changes: 13 additions & 4 deletions build/moz.configure/nspr.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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 ""
Expand Down
6 changes: 5 additions & 1 deletion build/moz.configure/nss.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
25 changes: 17 additions & 8 deletions build/moz.configure/pkg.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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")
Expand Down
6 changes: 5 additions & 1 deletion build/moz.configure/toolchain.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions js/ffi.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 12 additions & 2 deletions js/moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions moz.configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand All @@ -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
Expand Down
14 changes: 6 additions & 8 deletions python/mozbuild/mozbuild/test/configure/test_checks_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 3086d55

Please sign in to comment.