Bug 1363811 - Replace all uses of delayed_getattr(a, 'b') with a.b. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 17 May 2017 16:13:34 +0900
changeset 580726 48484f3995aa9395d41597c9c3ba4c12e4ddd85d
parent 580725 cde7a0e4ac03926ee8d7941da1f0ad92a0daef39
child 580727 5cb00873e9f60a59bf53f720a112793affe5cb0a
push id59648
push userbmo:mh+mozilla@glandium.org
push dateThu, 18 May 2017 22:06:14 +0000
reviewerschmanchester
bugs1363811
milestone55.0a1
Bug 1363811 - Replace all uses of delayed_getattr(a, 'b') with a.b. r?chmanchester And remove delayed_getattr.
build/moz.configure/init.configure
build/moz.configure/keyfiles.configure
build/moz.configure/toolchain.configure
build/moz.configure/util.configure
build/moz.configure/windows.configure
js/ffi.configure
moz.configure
toolkit/moz.configure
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -60,30 +60,29 @@ def check_build_environment(help, dist):
             '  *     1. cd %s\n'
             '  *     2. gmake distclean\n'
             '  ***'
             % ('\n  '.join(conflict_files), topsrcdir)
         )
 
     return result
 
-set_config('TOPSRCDIR', delayed_getattr(check_build_environment, 'topsrcdir'))
-set_config('TOPOBJDIR', delayed_getattr(check_build_environment, 'topobjdir'))
-set_config('MOZ_BUILD_ROOT', delayed_getattr(check_build_environment,
-                                             'topobjdir'))
-set_config('DIST', delayed_getattr(check_build_environment, 'dist'))
+set_config('TOPSRCDIR', check_build_environment.topsrcdir)
+set_config('TOPOBJDIR', check_build_environment.topobjdir)
+set_config('MOZ_BUILD_ROOT', check_build_environment.topobjdir)
+set_config('DIST', check_build_environment.dist)
 
 add_old_configure_assignment(
-    '_topsrcdir', delayed_getattr(check_build_environment, 'topsrcdir'))
+    '_topsrcdir', check_build_environment.topsrcdir)
 add_old_configure_assignment(
-    '_objdir', delayed_getattr(check_build_environment, 'topobjdir'))
+    '_objdir', check_build_environment.topobjdir)
 add_old_configure_assignment(
-    'MOZ_BUILD_ROOT', delayed_getattr(check_build_environment, 'topobjdir'))
+    'MOZ_BUILD_ROOT', check_build_environment.topobjdir)
 add_old_configure_assignment(
-    'DIST', delayed_getattr(check_build_environment, 'dist'))
+    'DIST', check_build_environment.dist)
 
 option(env='MOZ_AUTOMATION', help='Enable options for automated builds')
 set_config('MOZ_AUTOMATION', depends_if('MOZ_AUTOMATION')(lambda x: True))
 
 
 option(env='OLD_CONFIGURE', nargs=1, help='Path to the old configure script')
 
 option(env='MOZ_CURRENT_PROJECT', nargs=1, help='Current build project')
@@ -553,47 +552,46 @@ def target_variables(target):
 
     return namespace(
         OS_TARGET=os_target,
         OS_ARCH=os_arch,
         OS_TEST=os_test,
         INTEL_ARCHITECTURE=target.cpu in ('x86', 'x86_64') or None,
     )
 
-set_config('OS_TARGET', delayed_getattr(target_variables, 'OS_TARGET'))
+set_config('OS_TARGET', target_variables.OS_TARGET)
 add_old_configure_assignment('OS_TARGET',
-                             delayed_getattr(target_variables, 'OS_TARGET'))
-set_config('OS_ARCH', delayed_getattr(target_variables, 'OS_ARCH'))
+                             target_variables.OS_TARGET)
+set_config('OS_ARCH', target_variables.OS_ARCH)
 add_old_configure_assignment('OS_ARCH',
-                             delayed_getattr(target_variables, 'OS_ARCH'))
-set_config('OS_TEST', delayed_getattr(target_variables, 'OS_TEST'))
+                             target_variables.OS_ARCH)
+set_config('OS_TEST', target_variables.OS_TEST)
 add_old_configure_assignment('OS_TEST',
-                             delayed_getattr(target_variables, 'OS_TEST'))
-set_config('CPU_ARCH', delayed_getattr(target, 'cpu'))
-add_old_configure_assignment('CPU_ARCH', delayed_getattr(target, 'cpu'))
-set_config('INTEL_ARCHITECTURE', delayed_getattr(target_variables,
-                                                 'INTEL_ARCHITECTURE'))
-set_config('TARGET_CPU', delayed_getattr(target, 'raw_cpu'))
-set_config('TARGET_OS', delayed_getattr(target, 'raw_os'))
+                             target_variables.OS_TEST)
+set_config('CPU_ARCH', target.cpu)
+add_old_configure_assignment('CPU_ARCH', target.cpu)
+set_config('INTEL_ARCHITECTURE', target_variables.INTEL_ARCHITECTURE)
+set_config('TARGET_CPU', target.raw_cpu)
+set_config('TARGET_OS', target.raw_os)
 
 
 @depends(host)
 def host_variables(host):
     if host.kernel == 'kFreeBSD':
         os_arch = 'GNU_kFreeBSD'
     else:
         os_arch = host.kernel
     return namespace(
         HOST_OS_ARCH=os_arch,
     )
 
-set_config('HOST_CPU_ARCH', delayed_getattr(host, 'cpu'))
-set_config('HOST_OS_ARCH', delayed_getattr(host_variables, 'HOST_OS_ARCH'))
+set_config('HOST_CPU_ARCH', host.cpu)
+set_config('HOST_OS_ARCH', host_variables.HOST_OS_ARCH)
 add_old_configure_assignment('HOST_OS_ARCH',
-                             delayed_getattr(host_variables, 'HOST_OS_ARCH'))
+                             host_variables.HOST_OS_ARCH)
 
 @depends(target)
 def target_is_windows(target):
     if target.kernel == 'WINNT':
         return True
 
 set_define('_WINDOWS', target_is_windows)
 set_define('WIN32', target_is_windows)
@@ -716,25 +714,25 @@ def milestone(build_env, _):
     return namespace(version=milestone,
                      is_nightly=is_nightly,
                      is_release_or_beta=is_release_or_beta)
 
 @depends(milestone)
 def is_nightly(milestone):
     return milestone.is_nightly
 
-set_config('GRE_MILESTONE', delayed_getattr(milestone, 'version'))
+set_config('GRE_MILESTONE', milestone.version)
 set_config('NIGHTLY_BUILD', is_nightly)
 set_define('NIGHTLY_BUILD', is_nightly)
 add_old_configure_assignment('NIGHTLY_BUILD',
                              is_nightly)
-set_config('RELEASE_OR_BETA', delayed_getattr(milestone, 'is_release_or_beta'))
-set_define('RELEASE_OR_BETA', delayed_getattr(milestone, 'is_release_or_beta'))
+set_config('RELEASE_OR_BETA', milestone.is_release_or_beta)
+set_define('RELEASE_OR_BETA', milestone.is_release_or_beta)
 add_old_configure_assignment('RELEASE_OR_BETA',
-                             delayed_getattr(milestone, 'is_release_or_beta'))
+                             milestone.is_release_or_beta)
 
 # The app update channel is 'default' when not supplied. The value is used in
 # the application's confvars.sh (and is made available to a project specific
 # moz.configure).
 option('--enable-update-channel',
        nargs=1,
        help='Select application update channel',
        default='default')
--- a/build/moz.configure/keyfiles.configure
+++ b/build/moz.configure/keyfiles.configure
@@ -55,10 +55,10 @@ def id_and_secret_keyfile(desc):
         )
 
     content = keyfile(desc, help='Use the client id and secret key contained '
                                  'in the given keyfile for %s requests' % desc,
                       callback=id_and_secret)
 
 
     name = desc.upper().replace(' ', '_')
-    set_config('MOZ_%s_CLIENTID' % name, delayed_getattr(content, 'id'))
-    set_config('MOZ_%s_KEY' % name, delayed_getattr(content, 'secret'))
+    set_config('MOZ_%s_CLIENTID' % name, content.id)
+    set_config('MOZ_%s_KEY' % name, content.secret)
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -22,19 +22,19 @@ def yasm_version(yasm):
         yasm, '--version',
         onerror=lambda: die('Failed to get yasm version.')
     ).splitlines()[0].split()[1]
     return Version(version)
 
 # Until we move all the yasm consumers out of old-configure.
 # bug 1257904
 add_old_configure_assignment('_YASM_MAJOR_VERSION',
-                             delayed_getattr(yasm_version, 'major'))
+                             yasm_version.major)
 add_old_configure_assignment('_YASM_MINOR_VERSION',
-                             delayed_getattr(yasm_version, 'minor'))
+                             yasm_version.minor)
 
 @depends(yasm, target)
 def yasm_asflags(yasm, target):
     if yasm:
         asflags = {
             ('OSX', 'x86'): '-f macho32',
             ('OSX', 'x86_64'): '-f macho64',
             ('WINNT', 'x86'): '-f win32',
@@ -640,17 +640,17 @@ def compiler(language, host_or_target, c
                     for k, v in other_compiler.__dict__.iteritems()
                 })
 
     # Normally, we'd use `var` instead of `_var`, but the interaction with
     # old-configure complicates things, and for now, we a) can't take the plain
     # result from check_prog as CC/CXX/HOST_CC/HOST_CXX and b) have to let
     # old-configure AC_SUBST it (because it's autoconf doing it, not us)
     compiler = check_prog('_%s' % var, what=what, progs=default_compilers,
-                          input=delayed_getattr(provided_compiler, 'compiler'),
+                          input=provided_compiler.compiler,
                           paths=toolchain_search_path)
 
     @depends(compiler, provided_compiler, compiler_wrapper, host_or_target)
     @checking('whether %s can be used' % what, lambda x: bool(x))
     @imports(_from='mozbuild.shellutil', _import='quote')
     def valid_compiler(compiler, provided_compiler, compiler_wrapper,
                        host_or_target):
         wrapper = list(compiler_wrapper or ())
@@ -786,21 +786,21 @@ def compiler(language, host_or_target, c
     # be provided.
     add_old_configure_assignment(var, depends_if(valid_compiler)(
         lambda x: list(x.wrapper) + [x.compiler] + list(x.flags)))
 
     # Set CC_TYPE/CC_VERSION/HOST_CC_TYPE/HOST_CC_VERSION to allow
     # old-configure to do some of its still existing checks.
     if language == 'C':
         set_config(
-            '%s_TYPE' % var, delayed_getattr(valid_compiler, 'type'))
+            '%s_TYPE' % var, valid_compiler.type)
         add_old_configure_assignment(
-            '%s_TYPE' % var, delayed_getattr(valid_compiler, 'type'))
+            '%s_TYPE' % var, valid_compiler.type)
         add_old_configure_assignment(
-            '%s_VERSION' % var, delayed_getattr(valid_compiler, 'version'))
+            '%s_VERSION' % var, valid_compiler.version)
 
     valid_compiler = compiler_class(valid_compiler)
 
     def compiler_error():
         raise FatalCheckError('Failed compiling a simple %s source with %s'
                               % (language, what))
 
     valid_compiler.try_compile(check_msg='%s works' % what,
--- a/build/moz.configure/util.configure
+++ b/build/moz.configure/util.configure
@@ -361,37 +361,16 @@ def dependable(obj):
         return depends(when=True)(obj)
     return depends(when=True)(lambda: obj)
 
 
 always = dependable(True)
 never = dependable(False)
 
 
-# Some @depends function return namespaces, and one could want to use one
-# specific attribute from such a namespace as a "value" given to functions
-# such as `set_config`. But those functions do not take immediate values.
-# The `delayed_getattr` function allows access to attributes from the result
-# of a @depends function in a non-immediate manner.
-#   @depends('--option')
-#   def option(value)
-#       return namespace(foo=value)
-#   set_config('FOO', delayed_getattr(option, 'foo')
-@template
-def delayed_getattr(func, key):
-    @depends(func)
-    def result(value):
-        # The @depends function we're being passed may have returned
-        # None, or an object that simply doesn't have the wanted key.
-        # In that case, just return None.
-        return getattr(value, key, None)
-
-    return result
-
-
 # Like @depends, but the decorated function is only called if one of the
 # arguments it would be called with has a positive value (bool(value) is True)
 @template
 def depends_if(*args, **kwargs):
     if kwargs:
         assert len(kwargs) == 1
         when = kwargs['when']
     else:
--- a/build/moz.configure/windows.configure
+++ b/build/moz.configure/windows.configure
@@ -148,17 +148,17 @@ def valid_windows_sdk_dir(compiler, wind
         include=sdk.include,
         lib=sdk.lib,
         version=biggest_version,
     )
 
 
 add_old_configure_assignment(
     'WINDOWSSDKDIR',
-    delayed_getattr(valid_windows_sdk_dir, 'path'))
+    valid_windows_sdk_dir.path)
 add_old_configure_assignment(
     'MOZ_WINSDK_MAXVER',
     depends(valid_windows_sdk_dir)(
         lambda x: '0x%04X0000' % x.version if x else None))
 
 
 @imports(_from='mozbuild.shellutil', _import='quote')
 def valid_ucrt_sdk_dir_result(value):
--- a/js/ffi.configure
+++ b/js/ffi.configure
@@ -51,10 +51,10 @@ def ffi_target(target):
         target_dir = 'x86'
         target_name = target.cpu.upper()
 
     return namespace(
         name=target_name,
         dir=target_dir
     )
 
-set_config('FFI_TARGET', delayed_getattr(ffi_target, 'name'))
-set_config('FFI_TARGET_DIR', delayed_getattr(ffi_target, 'dir'))
+set_config('FFI_TARGET', ffi_target.name)
+set_config('FFI_TARGET_DIR', ffi_target.dir)
--- a/moz.configure
+++ b/moz.configure
@@ -84,21 +84,21 @@ set_define('GTEST_HAS_RTTI', gtest_has_r
 @depends(target, enable_tests)
 def linux_gtest_defines(target, enable_tests):
     if enable_tests and target.os == 'Android':
         return namespace(os_linux_android=True,
                          use_own_tr1_tuple=True,
                          has_clone='0')
 
 set_define('GTEST_OS_LINUX_ANDROID',
-           delayed_getattr(linux_gtest_defines, 'os_linux_android'))
+           linux_gtest_defines.os_linux_android)
 set_define('GTEST_USE_OWN_TR1_TUPLE',
-           delayed_getattr(linux_gtest_defines, 'use_own_tr1_tuple'))
+           linux_gtest_defines.use_own_tr1_tuple)
 set_define('GTEST_HAS_CLONE',
-           delayed_getattr(linux_gtest_defines, 'has_clone'))
+           linux_gtest_defines.has_clone)
 
 js_option('--enable-debug',
           nargs='?',
           help='Enable building with developer debug info '
                '(using the given compiler flags).')
 
 add_old_configure_assignment('MOZ_DEBUG',
                              depends('--enable-debug')(lambda v: bool(v)))
@@ -285,23 +285,23 @@ def extra_programs(target):
         return namespace(
             DSYMUTIL=('dsymutil', 'llvm-dsymutil'),
             MKFSHFS=('newfs_hfs', 'mkfs.hfsplus'),
             HFS_TOOL=('hfsplus',)
         )
     if target.os == 'GNU' and target.kernel == 'Linux':
         return namespace(RPMBUILD=('rpmbuild',))
 
-check_prog('DSYMUTIL', delayed_getattr(extra_programs, 'DSYMUTIL'),
+check_prog('DSYMUTIL', extra_programs.DSYMUTIL,
            allow_missing=True)
-check_prog('MKFSHFS', delayed_getattr(extra_programs, 'MKFSHFS'),
+check_prog('MKFSHFS', extra_programs.MKFSHFS,
            allow_missing=True)
-check_prog('HFS_TOOL', delayed_getattr(extra_programs, 'HFS_TOOL'),
+check_prog('HFS_TOOL', extra_programs.HFS_TOOL,
            allow_missing=True)
-check_prog('RPMBUILD', delayed_getattr(extra_programs, 'RPMBUILD'),
+check_prog('RPMBUILD', extra_programs.RPMBUILD,
            allow_missing=True)
 
 option('--enable-system-hunspell',
        help="Use system hunspell (located with pkgconfig)")
 
 @depends('--enable-system-hunspell', compile_environment)
 def check_for_hunspell(value, compile_env):
     return value and compile_env
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -345,21 +345,21 @@ set_define('HAVE_FT_LOAD_SFNT_TABLE', tr
 @depends(freetype2_combined_info, tree_freetype, check_build_environment)
 def ft2_info(freetype2_combined_info, tree_freetype, build_env):
     if tree_freetype:
         return namespace(cflags=('-I%s/modules/freetype2/include' % build_env.topsrcdir,),
                          libs=())
     if freetype2_combined_info:
         return freetype2_combined_info
 
-set_config('FT2_LIBS', delayed_getattr(ft2_info, 'libs'))
+set_config('FT2_LIBS', ft2_info.libs)
 add_old_configure_assignment('FT2_LIBS',
-                             delayed_getattr(ft2_info, 'libs'))
+                             ft2_info.libs)
 add_old_configure_assignment('FT2_CFLAGS',
-                             delayed_getattr(ft2_info, 'cflags'))
+                             ft2_info.cflags)
 
 # Apple platform decoder support
 # ==============================================================
 @depends(toolkit)
 def applemedia(toolkit):
     if toolkit in ('cocoa', 'uikit'):
         return True
 
@@ -712,22 +712,22 @@ def stylo(stylo_enabled, bindgen_config_
 
     return namespace(
         enabled=bool(stylo_enabled),
         libclang_path=bindgen_config_paths.libclang_path,
         clang_path=bindgen_config_paths.clang_path,
         bindgen_enabled=bool(bindgen_enabled),
     )
 
-set_config('MOZ_STYLO', delayed_getattr(stylo, 'enabled'))
-set_define('MOZ_STYLO', delayed_getattr(stylo, 'enabled'))
+set_config('MOZ_STYLO', stylo.enabled)
+set_define('MOZ_STYLO', stylo.enabled)
 
-set_config('MOZ_LIBCLANG_PATH', delayed_getattr(stylo, 'libclang_path'))
-set_config('MOZ_CLANG_PATH', delayed_getattr(stylo, 'clang_path'))
-set_config('MOZ_STYLO_BINDGEN', delayed_getattr(stylo, 'bindgen_enabled'))
+set_config('MOZ_LIBCLANG_PATH', stylo.libclang_path)
+set_config('MOZ_CLANG_PATH', stylo.clang_path)
+set_config('MOZ_STYLO_BINDGEN', stylo.bindgen_enabled)
 
 option('--with-servo', env='SERVO_TARGET_DIR', nargs=1,
        help='Absolute path of the target directory where libgeckoservo can '
             'be found. This is generally servo_src_dir/target/release.')
 
 @depends_if('--with-servo')
 def servo_target_dir(value):
     return value[0]
@@ -755,19 +755,19 @@ def webrender(value, milestone):
         enable_webrender = True
 
     # in all other cases, don't build it or enable it (defaults are fine)
     return namespace(
         build = build_webrender,
         enable = enable_webrender,
     )
 
-set_config('MOZ_BUILD_WEBRENDER', delayed_getattr(webrender, 'build'))
-set_define('MOZ_BUILD_WEBRENDER', delayed_getattr(webrender, 'build'))
-set_config('MOZ_ENABLE_WEBRENDER', delayed_getattr(webrender, 'enable'))
+set_config('MOZ_BUILD_WEBRENDER', webrender.build)
+set_define('MOZ_BUILD_WEBRENDER', webrender.build)
+set_config('MOZ_ENABLE_WEBRENDER', webrender.enable)
 
 # Printing
 # ==============================================================
 @depends(target)
 def ios_disable_printing(target):
     if target.os == 'iOS':
         return False