Bug 1314894 - Avoid path changes from b6be0e9e3e1e. r?chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 04 Nov 2016 06:50:43 +0900
changeset 433514 1a7e82f146412d13c6ca0b3b25ee4335038099d3
parent 433121 be398e3e2b2039ff982b747b3573ea338dbc7d45
child 535919 5e57cec207c58264223d0ad682a73c5693f73625
push id34611
push userbmo:mh+mozilla@glandium.org
push dateThu, 03 Nov 2016 21:59:05 +0000
reviewerschmanchester
bugs1314894
milestone52.0a1
Bug 1314894 - Avoid path changes from b6be0e9e3e1e. r?chmanchester Importing 'os' in python configure functions, on Windows, changes the separate the various os.path functions use, and that can have unexpected, badly handled, consequences. While on the long term, it is desirable to make @imports('os') modify os.path to use the same base functions as if there were no @imports, let's go with the simpler workaround of restoring the non-{isfile,isdir,exists} os.path functions from b6be0e9e3e1e.
build/moz.configure/android-ndk.configure
build/moz.configure/init.configure
build/moz.configure/old.configure
build/moz.configure/windows.configure
mobile/android/gradle.configure
toolkit/moz.configure
--- a/build/moz.configure/android-ndk.configure
+++ b/build/moz.configure/android-ndk.configure
@@ -49,17 +49,17 @@ def ndk(value, build_project):
     if value:
         return value[0]
 
 set_config('ANDROID_NDK', ndk)
 add_old_configure_assignment('android_ndk', ndk)
 
 @depends(target, android_version, ndk)
 @checking('for android platform directory')
-@imports('os')
+@imports(_from='os.path', _import='isdir')
 def android_platform(target, android_version, ndk):
     if target.os != 'Android':
         return
 
     if 'mips' in target.cpu:
         target_dir_name = 'mips'
     elif 'aarch64' == target.cpu:
         target_dir_name = 'arm64'
@@ -75,17 +75,17 @@ def android_platform(target, android_ver
     else:
         platform_version = android_version
 
     platform_dir = os.path.join(ndk,
                                 'platforms',
                                 'android-%s' % platform_version,
                                 'arch-%s' % target_dir_name)
 
-    if not os.path.isdir(platform_dir):
+    if not isdir(platform_dir):
         die("Android platform directory not found. With the current "
             "configuration, it should be in %s" % platform_dir)
 
     return platform_dir
 
 add_old_configure_assignment('android_platform', android_platform)
 
 @depends(android_platform)
@@ -93,17 +93,17 @@ def extra_toolchain_flags(platform_dir):
     if not platform_dir:
         return []
     return ['-idirafter',
             os.path.join(platform_dir, 'usr', 'include')]
 
 @depends(target, host, ndk, '--with-android-toolchain',
          '--with-android-gnu-compiler-version')
 @checking('for the Android toolchain directory', lambda x: x or 'not found')
-@imports('os')
+@imports(_from='os.path', _import='isdir')
 @imports(_from='mozbuild.shellutil', _import='quote')
 def android_toolchain(target, host, ndk, toolchain, gnu_compiler_version):
     if not ndk:
         return
     if toolchain:
         return toolchain[0]
     else:
         if target.cpu == 'arm' and target.endianness == 'little':
@@ -118,21 +118,21 @@ def android_toolchain(target, host, ndk,
             die('Target cpu is not supported.')
 
         toolchain_format = '%s/toolchains/%s-%s/prebuilt/%s-%s'
 
         for version in gnu_compiler_version or ['4.9', '4.8', '4.7']:
             toolchain = toolchain_format % (ndk, target_base, version,
                                             host.kernel.lower(), host.cpu)
             log.debug('Trying %s' % quote(toolchain))
-            if not os.path.isdir(toolchain) and host.cpu == 'x86_64':
+            if not isdir(toolchain) and host.cpu == 'x86_64':
                 toolchain = toolchain_format % (ndk, target_base, version,
                                                 host.kernel.lower(), 'x86')
                 log.debug('Trying %s' % quote(toolchain))
-            if os.path.isdir(toolchain):
+            if isdir(toolchain):
                 return toolchain
         else:
             if gnu_compiler_version:
                 die('Your --with-android-gnu-compiler-version may be wrong')
             die('You have to specify --with-android-toolchain='
                 '/path/to/ndk/toolchain.')
 
 set_config('ANDROID_TOOLCHAIN', android_toolchain)
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -7,17 +7,17 @@
 include('util.configure')
 include('checks.configure')
 
 option(env='DIST', nargs=1, help='DIST directory')
 
 # Do not allow objdir == srcdir builds.
 # ==============================================================
 @depends('--help', 'DIST')
-@imports('os')
+@imports(_from='os.path', _import='exists')
 def check_build_environment(help, dist):
     topobjdir = os.path.realpath(os.path.abspath('.'))
     topsrcdir = os.path.realpath(os.path.abspath(
         os.path.join(os.path.dirname(__file__), '..', '..')))
 
     if dist:
         dist = normsep(dist[0])
     else:
@@ -42,17 +42,17 @@ def check_build_environment(help, dist):
             '  * If you are building with a mozconfig, you will need to change your\n'
             '  * mozconfig to point to a different object directory.\n'
             '  ***'
         )
 
     # Check for a couple representative files in the source tree
     conflict_files = [
         '*         %s' % f for f in ('Makefile', 'config/autoconf.mk')
-        if os.path.exists(os.path.join(topsrcdir, f))
+        if exists(os.path.join(topsrcdir, f))
     ]
     if conflict_files:
         die('  ***\n'
             '  *   Your source tree contains these files:\n'
             '  %s\n'
             '  *   This indicates that you previously built in the source tree.\n'
             '  *   A source tree build can confuse the separate objdir build.\n'
             '  *\n'
@@ -629,27 +629,27 @@ def default_project(build_env, help):
 option('--enable-project', nargs=1, default=default_project,
        help='Project to build')
 
 option('--with-external-source-dir', env='EXTERNAL_SOURCE_DIR', nargs=1,
        help='External directory containing additional build files')
 
 @depends('--enable-project', '--with-external-source-dir',
          check_build_environment, '--help')
-@imports('os')
+@imports(_from='os.path', _import='exists')
 def include_project_configure(project, external_source_dir, build_env, help):
     if not project:
         die('--enable-project is required.')
 
     base_dir = build_env.topsrcdir
     if external_source_dir:
         base_dir = os.path.join(base_dir, external_source_dir[0])
 
     path = os.path.join(base_dir, project[0], 'moz.configure')
-    if not os.path.exists(path):
+    if not exists(path):
         die('Cannot find project %s', project[0])
     return path
 
 @depends('--with-external-source-dir')
 def external_source_dir(value):
     if value:
         return value[0]
 
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -10,17 +10,17 @@ def encoded_open(path, mode):
     encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
     return codecs.open(path, mode, encoding)
 
 
 option(env='AUTOCONF', nargs=1, help='Path to autoconf 2.13')
 
 @depends(mozconfig, 'AUTOCONF')
 @checking('for autoconf')
-@imports('os')
+@imports(_from='os.path', _import='exists')
 @imports('re')
 def autoconf(mozconfig, autoconf):
     mozconfig_autoconf = None
     if mozconfig['path']:
         make_extra = mozconfig['make_extra']
         if make_extra:
             for assignment in make_extra:
                 m = re.match('(?:export\s+)?AUTOCONF\s*:?=\s*(.+)$',
@@ -46,50 +46,50 @@ def autoconf(mozconfig, autoconf):
             if brew:
                 autoconf = os.path.normpath(os.path.join(
                     brew, '..', '..', 'Cellar', 'autoconf213', '2.13', 'bin',
                     'autoconf213'))
 
     if not autoconf:
         die('Could not find autoconf 2.13')
 
-    if not os.path.exists(autoconf):
+    if not exists(autoconf):
         die('Could not find autoconf 2.13 at %s', autoconf)
 
     return autoconf
 
 set_config('AUTOCONF', autoconf)
 
 
 @depends('OLD_CONFIGURE', mozconfig, autoconf, check_build_environment, shell,
          old_configure_assignments, build_project)
 @imports(_from='__builtin__', _import='open')
 @imports(_from='__builtin__', _import='print')
 @imports('glob')
 @imports('itertools')
-@imports('os')
 @imports('subprocess')
 # Import getmtime without overwriting the sandbox os.path.
 @imports(_from='os.path', _import='getmtime')
+@imports(_from='os.path', _import='exists')
 @imports(_from='mozbuild.shellutil', _import='quote')
 def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
                       old_configure_assignments, build_project):
     # os.path.abspath in the sandbox will ensure forward slashes on Windows,
     # which is actually necessary because this path actually ends up literally
     # as $0, and backslashes there breaks autoconf's detection of the source
     # directory.
     old_configure = os.path.abspath(old_configure[0])
     if build_project == 'js':
         old_configure_dir = os.path.dirname(old_configure)
-        if not old_configure_dir.replace(os.sep, '/').endswith('/js/src'):
+        if not old_configure_dir.endswith('/js/src'):
             old_configure = os.path.join(old_configure_dir, 'js', 'src',
                                          os.path.basename(old_configure))
 
     refresh = True
-    if os.path.exists(old_configure):
+    if exists(old_configure):
         mtime = getmtime(old_configure)
         aclocal = os.path.join(build_env.topsrcdir, 'build', 'autoconf',
                                '*.m4')
         for input in itertools.chain(
             (old_configure + '.in',
              os.path.join(os.path.dirname(old_configure), 'aclocal.m4')),
             glob.iglob(aclocal),
         ):
--- a/build/moz.configure/windows.configure
+++ b/build/moz.configure/windows.configure
@@ -260,21 +260,21 @@ def vc_path(c_compiler):
         result = next
         if p.lower() == 'bin':
             break
     return result
 
 
 @depends_win(vc_path)
 @checking('for the Debug Interface Access SDK', lambda x: x or 'not found')
-@imports('os')
+@imports(_from='os.path', _import='isdir')
 def dia_sdk_dir(vc_path):
     if vc_path:
         path = os.path.join(os.path.dirname(vc_path), 'DIA SDK')
-        if os.path.isdir(path):
+        if isdir(path):
             return path
 
 
 @depends_win(vc_path, valid_windows_sdk_dir, valid_ucrt_sdk_dir, dia_sdk_dir)
 @imports('os')
 def include_path(vc_path, windows_sdk_dir, ucrt_sdk_dir, dia_sdk_dir):
     if not vc_path:
         return
--- a/mobile/android/gradle.configure
+++ b/mobile/android/gradle.configure
@@ -16,23 +16,23 @@ option('--with-gradle', nargs='?',
 def with_gradle(value):
     if value:
         return True
 
 set_config('MOZ_BUILD_MOBILE_ANDROID_WITH_GRADLE', with_gradle)
 
 
 @depends('--with-gradle', check_build_environment)
-@imports('os')
+@imports(_from='os.path', _import='isfile')
 def gradle(value, build_env):
     gradle = value[0] if len(value) else \
         os.path.join(build_env.topsrcdir, 'gradlew')
 
     # TODO: verify that $GRADLE is executable.
-    if not os.path.isfile(gradle):
+    if not isfile(gradle):
         die('GRADLE must be executable: %s', gradle)
 
     return gradle
 
 set_config('GRADLE', gradle)
 
 
 # Automation uses this to change log levels, not use the daemon, and use
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -87,21 +87,21 @@ include('../js/moz.configure')
 
 
 # L10N
 # ==============================================================
 option('--with-l10n-base', nargs=1, env='L10NBASEDIR',
        help='Path to l10n repositories')
 
 @depends('--with-l10n-base')
-@imports('os')
+@imports(_from='os.path', _import='isdir')
 def l10n_base(value):
     if value:
         path = value[0]
-        if not os.path.isdir(path):
+        if not isdir(path):
             die("Invalid value --with-l10n-base, %s doesn't exist", path)
         return os.path.realpath(os.path.abspath(path))
 
 set_config('L10NBASEDIR', l10n_base)
 
 
 # Default toolkit
 # ==============================================================