Bug 1298740 - Populate Python environment with variables from mozconfig. r=glandium
MozReview-Commit-ID: KDCoxxh37Um
* * *
[mq]: fix_env.path
MozReview-Commit-ID: 5Jao0MEEmBW
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -255,16 +255,17 @@ def early_options():
)
return early_options
early_options = early_options()
@depends(mozconfig, '--help')
# This gives access to the sandbox. Don't copy this blindly.
@imports('__sandbox__')
+@imports('os')
def mozconfig_options(mozconfig, help):
if mozconfig['path']:
helper = __sandbox__._helper
log.info('Adding configure options from %s' % mozconfig['path'])
for arg in mozconfig['configure_args']:
log.info(' %s' % arg)
# We could be using imply_option() here, but it has other
# contraints that don't really apply to the command-line
@@ -274,18 +275,20 @@ def mozconfig_options(mozconfig, help):
def add(key, value):
if key.isupper():
arg = '%s=%s' % (key, value)
log.info(' %s' % arg)
helper.add(arg, origin='mozconfig', args=helper._args)
for key, value in mozconfig['env']['added'].iteritems():
add(key, value)
+ os.environ[key] = value
for key, (_, value) in mozconfig['env']['modified'].iteritems():
add(key, value)
+ os.environ[key] = value
for key, value in mozconfig['vars']['added'].iteritems():
# mozconfig_loader adds _IS_SET variables that are irrelevant
if not key.endswith('_IS_SET'):
add(key, value)
for key, (_, value) in mozconfig['vars']['modified'].iteritems():
add(key, value)
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -113,20 +113,16 @@ def prepare_configure(old_configure, moz
cmd = [shell, old_configure]
with encoded_open('old-configure.vars', 'w') as out:
log.debug('Injecting the following to old-configure:')
def inject(command):
print(command, file=out)
log.debug('| %s', command)
if mozconfig['path']:
- for key, value in mozconfig['env']['added'].items():
- inject("export %s=%s" % (key, quote(value)))
- for key, (old, value) in mozconfig['env']['modified'].items():
- inject("export %s=%s" % (key, quote(value)))
for key, value in mozconfig['vars']['added'].items():
inject("%s=%s" % (key, quote(value)))
for key, (old, value) in mozconfig['vars']['modified'].items():
inject("%s=%s" % (key, quote(value)))
for t in ('env', 'vars'):
for key in mozconfig[t]['removed'].keys():
inject("unset %s" % key)
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/dump_env.py
@@ -0,0 +1,10 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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/.
+
+# We invoke a Python program to dump our environment in order to get
+# native paths printed on Windows so that these paths can be incorporated
+# into Python configure's environment.
+import os
+for key, value in os.environ.items():
+ print('%s=%s' % (key, value))
--- a/python/mozbuild/mozbuild/mozconfig.py
+++ b/python/mozbuild/mozbuild/mozconfig.py
@@ -230,17 +230,19 @@ class MozconfigLoader(object):
# 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]
+ mozpath.normsep(self.topsrcdir), path, sys.executable,
+ mozpath.join(mozpath.dirname(self._loader_script),
+ 'dump_env.py')]
try:
# We need to capture stderr because that's where the shell sends
# errors if execution fails.
output = subprocess.check_output(command, stderr=subprocess.STDOUT,
cwd=self.topsrcdir, env=env)
except subprocess.CalledProcessError as e:
lines = e.output.splitlines()
--- a/python/mozbuild/mozbuild/mozconfig_loader
+++ b/python/mozbuild/mozbuild/mozconfig_loader
@@ -53,17 +53,17 @@ mk_add_options() {
# Note: $(echo ${name}) strips the variable from any leading and trailing
# whitespaces.
eval "$(echo ${name})_IS_SET=1"
echo "------END_MK_OPTION"
done
}
echo "------BEGIN_ENV_BEFORE_SOURCE"
-env
+$3 $4
echo "------END_ENV_BEFORE_SOURCE"
echo "------BEGIN_BEFORE_SOURCE"
set
echo "------END_BEFORE_SOURCE"
topsrcdir=$1
@@ -71,11 +71,10 @@ topsrcdir=$1
unset topsrcdir
echo "------BEGIN_AFTER_SOURCE"
set
echo "------END_AFTER_SOURCE"
echo "------BEGIN_ENV_AFTER_SOURCE"
-env
+$3 $4
echo "------END_ENV_AFTER_SOURCE"
-
--- a/python/mozbuild/mozbuild/test/test_mozconfig.py
+++ b/python/mozbuild/mozbuild/test/test_mozconfig.py
@@ -374,56 +374,60 @@ class TestMozconfigLoader(unittest.TestC
result = self.get_loader().read_mozconfig(mozconfig.name)
self.assertEqual(result['vars']['added'], {})
self.assertEqual(result['env']['added'], {
'MY_EXPORTED': 'woot'})
def test_read_modify_variables(self):
"""Variables modified by mozconfig are detected."""
- os.environ[b'CC'] = b'/usr/bin/gcc'
+ old_path = os.path.realpath(b'/usr/bin/gcc')
+ new_path = os.path.realpath(b'/usr/local/bin/clang')
+ os.environ[b'CC'] = old_path
with NamedTemporaryFile(mode='w') as mozconfig:
- mozconfig.write('CC=/usr/local/bin/clang\n')
+ mozconfig.write('CC="%s"\n' % new_path)
mozconfig.flush()
result = self.get_loader().read_mozconfig(mozconfig.name)
self.assertEqual(result['vars']['modified'], {})
self.assertEqual(result['env']['modified'], {
- 'CC': ('/usr/bin/gcc', '/usr/local/bin/clang')
+ 'CC': (old_path, new_path)
})
def test_read_unmodified_variables(self):
"""Variables modified by mozconfig are detected."""
- os.environ[b'CC'] = b'/usr/bin/gcc'
+ cc_path = os.path.realpath(b'/usr/bin/gcc')
+ os.environ[b'CC'] = cc_path
with NamedTemporaryFile(mode='w') as mozconfig:
mozconfig.flush()
result = self.get_loader().read_mozconfig(mozconfig.name)
self.assertEqual(result['vars']['unmodified'], {})
self.assertEqual(result['env']['unmodified'], {
- 'CC': '/usr/bin/gcc'
+ 'CC': cc_path
})
def test_read_removed_variables(self):
"""Variables unset by the mozconfig are detected."""
- os.environ[b'CC'] = b'/usr/bin/clang'
+ cc_path = os.path.realpath(b'/usr/bin/clang')
+ os.environ[b'CC'] = cc_path
with NamedTemporaryFile(mode='w') as mozconfig:
mozconfig.write('unset CC\n')
mozconfig.flush()
result = self.get_loader().read_mozconfig(mozconfig.name)
self.assertEqual(result['vars']['removed'], {})
self.assertEqual(result['env']['removed'], {
- 'CC': '/usr/bin/clang'})
+ 'CC': cc_path})
def test_read_multiline_variables(self):
"""Ensure multi-line variables are captured properly."""
with NamedTemporaryFile(mode='w') as mozconfig:
mozconfig.write('multi="foo\nbar"\n')
mozconfig.write('single=1\n')
mozconfig.flush()