Bug 1249838 - Avoid dependency from the mozconfig loader on mach
--- a/python/mozbuild/mozbuild/mozconfig.py
+++ b/python/mozbuild/mozbuild/mozconfig.py
@@ -2,21 +2,22 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, unicode_literals
import filecmp
import os
import re
+import sys
import subprocess
import traceback
from collections import defaultdict
-from mach.mixin.process import ProcessExecutionMixin
+from mozpack import path as mozpath
MOZ_MYCONFIG_ERROR = '''
The MOZ_MYCONFIG environment variable to define the location of mozconfigs
is deprecated. If you wish to define the mozconfig path via an environment
variable, use MOZCONFIG instead.
'''.strip()
@@ -51,17 +52,17 @@ class MozconfigLoadException(Exception):
"""
def __init__(self, path, message, output=None):
self.path = path
self.output = output
Exception.__init__(self, message)
-class MozconfigLoader(ProcessExecutionMixin):
+class MozconfigLoader(object):
"""Handles loading and parsing of mozconfig files."""
RE_MAKE_VARIABLE = re.compile('''
^\s* # Leading whitespace
(?P<var>[a-zA-Z_0-9]+) # Variable name
\s* [?:]?= \s* # Assignment operator surrounded by optional
# spaces
(?P<value>.*$)''', # Everything else (likely the value)
@@ -209,31 +210,40 @@ class MozconfigLoader(ProcessExecutionMi
'make_extra': None,
'env': None,
'vars': None,
}
if path is None:
return result
- path = path.replace(os.sep, '/')
+ path = mozpath.normsep(path)
result['configure_args'] = []
result['make_extra'] = []
result['make_flags'] = []
env = dict(os.environ)
- args = self._normalize_command([self._loader_script,
- self.topsrcdir.replace(os.sep, '/'), path], True)
+ # Since mozconfig_loader is a shell script, running it "normally"
+ # actually leads to two shell executions on Windows. Avoid this by
+ # directly calling sh mozconfig_loader.
+ shell = 'sh'
+ if 'MOZILLABUILD' in os.environ:
+ shell = os.environ['MOZILLABUILD'] + '/msys/bin/sh'
+ if sys.platform == 'win32':
+ shell = shell + '.exe'
+
+ command = [shell, mozpath.normsep(self._loader_script),
+ mozpath.normsep(self.topsrcdir), path]
try:
# We need to capture stderr because that's where the shell sends
# errors if execution fails.
- output = subprocess.check_output(args, stderr=subprocess.STDOUT,
+ output = subprocess.check_output(command, stderr=subprocess.STDOUT,
cwd=self.topsrcdir, env=env)
except subprocess.CalledProcessError as e:
lines = e.output.splitlines()
# Output before actual execution shouldn't be relevant.
try:
index = lines.index('------END_BEFORE_SOURCE')
lines = lines[index + 1:]