Bug 1498450 - Avoid the footgun from @depends-function comparison r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 12 Oct 2018 13:44:08 +0000
changeset 440954 a232864e100291f7fe7e7b60745aae2094786b43
parent 440953 ddb585f4d9d751d42c3b69ebad15b9c3128efbab
child 440955 994a0ec3420ff869b56aa868a2ca471390751e60
push id34841
push useraciure@mozilla.com
push dateSat, 13 Oct 2018 09:35:03 +0000
treeherdermozilla-central@0dfb3afc7357 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1498450, 21357, 30414, 1492305
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1498450 - Avoid the footgun from @depends-function comparison r=froydnj While we do have some uses of @depends-function comparison in some templaces, related to host/target, we ought to be using `is` comparisons rather than `==` anyways, so we switch those, and prevent other kinds of comparisons being used at all. This unveils the one noted in https://phabricator.services.mozilla.com/D7713?id=21357#inline-30414 (and surprisingly only that one), that we remove entirely since it was doing nothing in practice. Bug 1492305 will have to add it back in a proper form. Differential Revision: https://phabricator.services.mozilla.com/D8501
build/moz.configure/compile-checks.configure
build/moz.configure/rust.configure
build/moz.configure/toolchain.configure
moz.configure
python/mozbuild/mozbuild/configure/__init__.py
toolkit/moz.configure
--- a/build/moz.configure/compile-checks.configure
+++ b/build/moz.configure/compile-checks.configure
@@ -107,18 +107,18 @@ def check_and_add_flags(flag, flags_coll
     results = []
 
     if test_flags:
         flags = test_flags
     else:
         flags = [flag]
 
     for c in compilers:
-        assert c in (c_compiler, cxx_compiler,
-                     host_c_compiler, host_cxx_compiler)
+        assert c in {c_compiler, cxx_compiler,
+                     host_c_compiler, host_cxx_compiler}
         lang, list_of_flags = {
             c_compiler: ('C', flags_collection.cflags),
             cxx_compiler: ('C++', flags_collection.cxxflags),
             host_c_compiler: ('host C', flags_collection.host_cflags),
             host_cxx_compiler: ('host C++', flags_collection.host_cxxflags),
         }[c]
 
         @depends(c, when)
--- a/build/moz.configure/rust.configure
+++ b/build/moz.configure/rust.configure
@@ -147,17 +147,17 @@ def rust_supported_targets(rustc):
 
 
 @template
 def rust_triple_alias(host_or_target):
     """Template defining the alias used for rustc's --target flag.
     `host_or_target` is either `host` or `target` (the @depends functions
     from init.configure).
     """
-    assert host_or_target in (host, target)
+    assert host_or_target in {host, target}
 
     @depends(rustc, host_or_target, c_compiler, rust_supported_targets,
              when=rust_compiler)
     @imports('os')
     @imports('subprocess')
     @imports(_from='mozbuild.configure.util', _import='LineIO')
     @imports(_from='mozbuild.shellutil', _import='quote')
     @imports(_from='tempfile', _import='mkstemp')
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -688,17 +688,17 @@ def toolchain_search_path(vc_compiler_pa
 @template
 def default_c_compilers(host_or_target, other_c_compiler=None):
     '''Template defining the set of default C compilers for the host and
     target platforms.
     `host_or_target` is either `host` or `target` (the @depends functions
     from init.configure.
     `other_c_compiler` is the `target` C compiler when `host_or_target` is `host`.
     '''
-    assert host_or_target in (host, target)
+    assert host_or_target in {host, target}
 
     other_c_compiler = () if other_c_compiler is None else (other_c_compiler,)
 
     @depends(host_or_target, target, toolchain_prefix, android_clang_compiler,
              *other_c_compiler)
     def default_c_compilers(host_or_target, target, toolchain_prefix,
                             android_clang_compiler, *other_c_compiler):
         if host_or_target.kernel == 'WINNT':
@@ -833,21 +833,21 @@ def compiler(language, host_or_target, c
     When the language is 'C++', `c_compiler` is the result of the `compiler`
     template for the language 'C' for the same `host_or_target`.
     When `host_or_target` is `host`, `other_compiler` is the result of the
     `compiler` template for the same `language` for `target`.
     When `host_or_target` is `host` and the language is 'C++',
     `other_c_compiler` is the result of the `compiler` template for the
     language 'C' for `target`.
     '''
-    assert host_or_target in (host, target)
+    assert host_or_target in {host, target}
     assert language in ('C', 'C++')
     assert language == 'C' or c_compiler is not None
-    assert host_or_target == target or other_compiler is not None
-    assert language == 'C' or host_or_target == target or \
+    assert host_or_target is target or other_compiler is not None
+    assert language == 'C' or host_or_target is target or \
         other_c_compiler is not None
 
     host_or_target_str = {
         host: 'host',
         target: 'target',
     }[host_or_target]
 
     var = {
@@ -1045,17 +1045,17 @@ def compiler(language, host_or_target, c
 
     valid_compiler.try_compile(check_msg='%s works' % what,
                                onerror=compiler_error)
 
     # Set CPP/CXXCPP for both the build system and old-configure. We don't
     # need to check this works for preprocessing, because we already relied
     # on $CC -E/$CXX -E doing preprocessing work to validate the compiler
     # in the first place.
-    if host_or_target == target:
+    if host_or_target is target:
         pp_var = {
             'C': 'CPP',
             'C++': 'CXXCPP',
         }[language]
 
         preprocessor = depends_if(valid_compiler)(
             lambda x: list(x.wrapper) + [x.compiler, '-E'] + list(x.flags))
 
@@ -1074,17 +1074,17 @@ def compiler(language, host_or_target, c
                 return value[0]
 
         @depends(valid_compiler, linker)
         def unused_linker(compiler, linker):
             if linker and compiler.type != 'msvc':
                 log.warning('The value of %s is not used by this build system.'
                             % linker_var)
 
-        if host_or_target == target:
+        if host_or_target is target:
             @depends(valid_compiler)
             def is_msvc(compiler):
                 return compiler.type == 'msvc'
 
             imply_option('LINKER', linker, reason='LD', when=is_msvc)
 
     return valid_compiler
 
--- a/moz.configure
+++ b/moz.configure
@@ -164,17 +164,17 @@ option(env='SO_VERSION', nargs=1, defaul
        help='Shared library version for OpenBSD systems')
 
 @depends('SO_VERSION', when=is_openbsd)
 def so_version(value):
     return value
 
 @template
 def library_name_info_template(host_or_target):
-    assert host_or_target in (host, target)
+    assert host_or_target in {host, target}
     compiler = {
         host: host_c_compiler,
         target: c_compiler,
     }[host_or_target]
 
     @depends(host_or_target, compiler, so_version)
     def library_name_info_impl(host_or_target, compiler, so_version):
         if host_or_target.kernel == 'WINNT':
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -61,16 +61,41 @@ class SandboxDependsFunction(object):
         return self._or(other).sandboxed
 
     def __and__(self, other):
         if not isinstance(other, SandboxDependsFunction):
             raise ConfigureError('Can only do binary arithmetic operations '
                                  'with another @depends function.')
         return self._and(other).sandboxed
 
+    def __cmp__(self, other):
+        raise ConfigureError('Cannot compare @depends functions.')
+
+    def __eq__(self, other):
+        raise ConfigureError('Cannot compare @depends functions.')
+
+    def __ne__(self, other):
+        raise ConfigureError('Cannot compare @depends functions.')
+
+    def __lt__(self, other):
+        raise ConfigureError('Cannot compare @depends functions.')
+
+    def __le__(self, other):
+        raise ConfigureError('Cannot compare @depends functions.')
+
+    def __gt__(self, other):
+        raise ConfigureError('Cannot compare @depends functions.')
+
+    def __ge__(self, other):
+        raise ConfigureError('Cannot compare @depends functions.')
+
+    def __nonzero__(self):
+        raise ConfigureError('Cannot use @depends functions in '
+                             'e.g. conditionals.')
+
     def __getattr__(self, key):
         return self._getattr(key).sandboxed
 
     def __nonzero__(self):
         raise ConfigureError(
             'Cannot do boolean operations on @depends functions.')
 
 
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -729,28 +729,16 @@ set_define('MOZ_WEBSPEECH_TEST_BACKEND',
 # ==============================================================
 option('--enable-ipdl-tests', help='Enable expensive IPDL tests')
 
 set_config('MOZ_IPDL_TESTS',
            depends_if('--enable-ipdl-tests')(lambda _: True))
 
 include('nss.configure')
 
-# LibSecret
-# ==============================================================
-# To access the OS key store on Linux systems we use libsecret.
-# https://developer.gnome.org/libsecret/
-
-if target.os == 'Linux':
-    libsecret = pkg_check_modules('MOZ_LIB_SECRET', 'libsecret-1',
-                                  allow_missing=True)
-
-    set_config('MOZ_LIB_SECRET', depends_if(libsecret)(lambda _: True))
-    set_define('MOZ_LIB_SECRET', depends_if(libsecret)(lambda _: True))
-
 # Graphics
 # ==============================================================
 option('--disable-skia', help='Disable use of Skia')
 
 @depends('--disable-skia')
 def skia(value):
     if not value:
         die('--disable-skia is not supported anymore')