Bug 1255433 - Store old-configure.vars as utf-8 or mbcs. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 11 Mar 2016 16:33:15 +0900
changeset 339729 bb7a50a5ab26945a1318718dcafaf7306f9120ab
parent 339728 fa7740691562c77554cf41c4e36e1ad744b82ffa
child 339730 13e2c954630cb434b28b3622970fbc3fdd6d2773
push id12803
push userjbeich@FreeBSD.org
push dateSun, 13 Mar 2016 09:48:54 +0000
Bug 1255433 - Store old-configure.vars as utf-8 or mbcs. r=gps The data we get out of mozconfig can be unicode, and needs to be in a form the shell used to run old-configure will be able to recognize, which is likely utf-8 on UNIX (that's what we settled on), and mbcs on Windows.
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -14,16 +14,25 @@ def shell(mozillabuild):
     shell = 'sh'
     if mozillabuild:
         shell = mozillabuild[0] + '/msys/bin/sh'
     if sys.platform == 'win32':
         shell = shell + '.exe'
     return shell
+def encoded_open(path, mode):
+    import codecs
+    import sys
+    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')
 def autoconf(mozconfig, autoconf):
     import re
     mozconfig_autoconf = None
@@ -95,17 +104,17 @@ def prepare_configure(old_configure, moz
         warn('Refreshing %s with %s' % (old_configure, autoconf))
         with open(old_configure, 'wb') as fh:
                 shell, autoconf,
                 '--localdir=%s' % os.path.dirname(old_configure),
                 old_configure + '.in'], stdout=fh)
     cmd = [shell, old_configure]
-    with open('old-configure.vars', 'w') as out:
+    with encoded_open('old-configure.vars', 'w') as out:
         if mozconfig['path']:
             for key, value in mozconfig['env']['added'].items():
                 print("export %s=%s" % (key, quote(value)), file=out)
             for key, (old, value) in mozconfig['env']['modified'].items():
                 print("export %s=%s" % (key, quote(value)), file=out)
             for key, value in mozconfig['vars']['added'].items():
                 print("%s=%s" % (key, quote(value)), file=out)
             for key, (old, value) in mozconfig['vars']['modified'].items():
@@ -351,17 +360,16 @@ def old_configure_options(*options):
 def old_configure(prepare_configure, extra_old_configure_args, all_options,
-    import codecs
     import os
     import subprocess
     import sys
     import types
     from mozbuild.shellutil import quote
     cmd = prepare_configure
@@ -383,18 +391,17 @@ def old_configure(prepare_configure, ext
     # For debugging purpose, in case it's not what we'd expect.
     warn('running %s' % ' '.join(quote(a) for a in cmd))
     ret = subprocess.call(cmd)
     if ret:
     raw_config = {}
-    encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
-    with codecs.open('config.data', 'r', encoding) as fh:
+    with encoded_open('config.data', 'r') as fh:
         code = compile(fh.read(), 'config.data', 'exec')
         # Every variation of the exec() function I tried led to:
         # SyntaxError: unqualified exec is not allowed in function 'main' it
         # contains a nested function with free variables
         exec code in raw_config
     # Ensure all the flags known to old-configure appear in the
     # @old_configure_options above.