Skip to content

Commit

Permalink
Bug 1575135 - Define whether the system encoding is mbcs or utf-8 onc…
Browse files Browse the repository at this point in the history
…e. r=nalexander

Differential Revision: https://phabricator.services.mozilla.com/D42601
  • Loading branch information
glandium committed Aug 20, 2019
1 parent e49aa1c commit 9fc6c0a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build/moz.configure/old.configure
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@imports('codecs')
@imports('sys')
@imports(_from='mozbuild.util', _import='system_encoding')
def encoded_open(path, mode):
encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
return codecs.open(path, mode, encoding)
return codecs.open(path, mode, system_encoding)


option(env='AUTOCONF', nargs=1, help='Path to autoconf 2.13')
Expand Down
5 changes: 2 additions & 3 deletions build/moz.configure/toolchain.configure
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,9 @@ def check_compiler(compiler, language, target):
@imports('json')
@imports('os')
@imports('subprocess')
@imports('sys')
@imports(_from='mozbuild.util', _import='system_encoding')
def get_vc_paths(topsrcdir):
def vswhere(args):
encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
program_files = (os.environ.get('PROGRAMFILES(X86)') or
os.environ.get('PROGRAMFILES'))
if not program_files:
Expand All @@ -618,7 +617,7 @@ def get_vc_paths(topsrcdir):
return []
return json.loads(
subprocess.check_output([vswhere, '-format', 'json'] + args)
.decode(encoding, 'replace'))
.decode(system_encoding, 'replace'))

for install in vswhere(['-products', '*', '-requires', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64']):
path = install['installationPath']
Expand Down
8 changes: 4 additions & 4 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from mozbuild.util import (
indented_repr,
encode,
system_encoding,
)
import mozpack.path as mozpath

Expand Down Expand Up @@ -74,15 +75,14 @@ def sanitized_bools(v):
# here, when we're able to skip configure tests/use cached results/not rely
# on autoconf.
logging.getLogger('moz.configure').info('Creating config.status')
encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
with codecs.open('config.status', 'w', encoding) as fh:
with codecs.open('config.status', 'w', system_encoding) as fh:
fh.write(textwrap.dedent('''\
#!%(python)s
# coding=%(encoding)s
from __future__ import unicode_literals
from mozbuild.util import encode
encoding = '%(encoding)s'
''') % {'python': config['PYTHON'], 'encoding': encoding})
''') % {'python': config['PYTHON'], 'encoding': system_encoding})
# A lot of the build backend code is currently expecting byte
# strings and breaks in subtle ways with unicode strings. (bug 1296508)
for k, v in sanitized_config.iteritems():
Expand Down Expand Up @@ -125,7 +125,7 @@ def sanitized_bools(v):

# A lot of the build backend code is currently expecting byte strings
# and breaks in subtle ways with unicode strings.
return config_status(args=[], **encode(sanitized_config, encoding))
return config_status(args=[], **encode(sanitized_config, system_encoding))
return 0


Expand Down
4 changes: 2 additions & 2 deletions python/mozbuild/mozbuild/backend/configenvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
FileAvoidWrite,
memoized_property,
ReadOnlyDict,
system_encoding,
)
from mozbuild.shellutil import quote as shell_quote

Expand Down Expand Up @@ -252,10 +253,9 @@ def _load_config_track(self):
return existing_files

def _write_file(self, key, value):
encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
filename = mozpath.join(self._datadir, key)
with FileAvoidWrite(filename) as fh:
json.dump(value, fh, indent=4, encoding=encoding)
json.dump(value, fh, indent=4, encoding=system_encoding)
return filename

def _fill_group(self, values):
Expand Down
4 changes: 2 additions & 2 deletions python/mozbuild/mozbuild/mozconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import traceback

from mozpack import path as mozpath
from mozbuild.util import system_encoding


MOZ_MYCONFIG_ERROR = '''
Expand Down Expand Up @@ -356,8 +357,7 @@ def _parse_loader_output(self, output):
# XXX This is an ugly hack. Data may be lost from things
# like environment variable values.
# See https://bugzilla.mozilla.org/show_bug.cgi?id=831381
line = line.decode('mbcs' if sys.platform == 'win32' else 'utf-8',
'ignore')
line = line.decode(system_encoding, 'ignore')

if not line:
continue
Expand Down
3 changes: 3 additions & 0 deletions python/mozbuild/mozbuild/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
if sys.platform == 'win32':
_kernel32 = ctypes.windll.kernel32
_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000
system_encoding = 'mbcs'
else:
system_encoding = 'utf-8'


def exec_(object, globals=None, locals=None):
Expand Down

0 comments on commit 9fc6c0a

Please sign in to comment.