Bug 1249838 - Avoid dependency from the mozconfig loader on mach draft
authorMike Hommey <mh+mozilla@glandium.org>
Sat, 20 Feb 2016 10:00:31 +0900
changeset 332668 19728c0ee60a7f9ef5b2b47470190aa5423769ec
parent 332667 f7c1dfaa424d6800bcdb8c0d7b131caa6aa6a151
child 514582 b519d78f441f301650a78c5d4883f3bf283346be
push id11203
push userbmo:mh+mozilla@glandium.org
push dateSat, 20 Feb 2016 01:17:19 +0000
bugs1249838
milestone47.0a1
Bug 1249838 - Avoid dependency from the mozconfig loader on mach
python/mozbuild/mozbuild/mozconfig.py
--- 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:]