Bug 936555 - make mozinfo use MozconfigLoader to locate the mozconfig; r=gps

This commit is contained in:
Nathan Froyd 2014-01-27 11:35:59 -05:00
parent c4fd86b0c7
commit 5ccc50ad47
3 changed files with 24 additions and 19 deletions

View File

@ -75,7 +75,7 @@ class MozconfigLoader(ProcessExecutionMixin):
return os.path.join(our_dir, 'mozconfig_loader')
def find_mozconfig(self):
def find_mozconfig(self, env=os.environ):
"""Find the active mozconfig file for the current environment.
This emulates the logic in mozconfig-find.
@ -91,10 +91,10 @@ class MozconfigLoader(ProcessExecutionMixin):
"""
# Check for legacy methods first.
if 'MOZ_MYCONFIG' in os.environ:
if 'MOZ_MYCONFIG' in env:
raise MozconfigFindException(MOZ_MYCONFIG_ERROR)
env_path = os.environ.get('MOZCONFIG', None)
env_path = env.get('MOZCONFIG', None)
if env_path is not None:
if not os.path.exists(env_path):
raise MozconfigFindException(
@ -128,7 +128,7 @@ class MozconfigLoader(ProcessExecutionMixin):
deprecated_paths = [os.path.join(self.topsrcdir, s) for s in
self.DEPRECATED_TOPSRCDIR_PATHS]
home = os.environ.get('HOME', None)
home = env.get('HOME', None)
if home is not None:
deprecated_paths.extend([os.path.join(home, s) for s in
self.DEPRECATED_HOME_PATHS])

View File

@ -8,7 +8,7 @@
import os
import re
import json
import mozbuild.mozconfig as mozconfig
def build_dict(config, env=os.environ):
"""
@ -27,10 +27,9 @@ def build_dict(config, env=os.environ):
d = {}
d['topsrcdir'] = config.topsrcdir
if 'MOZCONFIG' in env:
mozconfig = env["MOZCONFIG"]
mozconfig = os.path.join(config.topsrcdir, mozconfig)
d['mozconfig'] = os.path.normpath(mozconfig)
the_mozconfig = mozconfig.MozconfigLoader(config.topsrcdir).find_mozconfig(env)
if the_mozconfig:
d['mozconfig'] = the_mozconfig
# os
o = substs["OS_TARGET"]

View File

@ -19,6 +19,8 @@ from mozbuild.mozinfo import (
write_mozinfo,
)
from mozfile.mozfile import NamedTemporaryFile
class Base(object):
def _config(self, substs={}):
@ -238,16 +240,20 @@ class TestWriteMozinfo(unittest.TestCase, Base):
TARGET_CPU='i386',
MOZ_WIDGET_TOOLKIT='windows',
))
c.topsrcdir = '/tmp'
write_mozinfo(self.f, c, {'MOZCONFIG': 'foo'})
with open(self.f) as f:
d = json.load(f)
self.assertEqual('win', d['os'])
self.assertEqual('x86', d['processor'])
self.assertEqual('windows', d['toolkit'])
self.assertEqual('/tmp', d['topsrcdir'])
self.assertEqual(os.path.normpath('/tmp/foo'), d['mozconfig'])
self.assertEqual(32, d['bits'])
tempdir = tempfile.tempdir
c.topsrcdir = tempdir
with NamedTemporaryFile(dir=os.path.normpath(c.topsrcdir)) as mozconfig:
mozconfig.write('unused contents')
mozconfig.flush()
write_mozinfo(self.f, c, {'MOZCONFIG': mozconfig.name})
with open(self.f) as f:
d = json.load(f)
self.assertEqual('win', d['os'])
self.assertEqual('x86', d['processor'])
self.assertEqual('windows', d['toolkit'])
self.assertEqual(tempdir, d['topsrcdir'])
self.assertEqual(mozconfig.name, d['mozconfig'])
self.assertEqual(32, d['bits'])
def test_fileobj(self):
"""