mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1298740 - Populate Python environment with variables from mozconfig. r=glandium
MozReview-Commit-ID: KDCoxxh37Um
This commit is contained in:
parent
0d0d70f0f2
commit
b09b78a7c5
@ -260,6 +260,7 @@ 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
|
||||
@ -279,8 +280,10 @@ def mozconfig_options(mozconfig, help):
|
||||
|
||||
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'):
|
||||
|
@ -118,10 +118,6 @@ def prepare_configure(old_configure, mozconfig, autoconf, build_env, shell,
|
||||
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():
|
||||
|
10
python/mozbuild/mozbuild/action/dump_env.py
Normal file
10
python/mozbuild/mozbuild/action/dump_env.py
Normal file
@ -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))
|
@ -235,7 +235,9 @@ class MozconfigLoader(object):
|
||||
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),
|
||||
'action', 'dump_env.py')]
|
||||
|
||||
try:
|
||||
# We need to capture stderr because that's where the shell sends
|
||||
|
@ -58,7 +58,7 @@ mk_add_options() {
|
||||
}
|
||||
|
||||
echo "------BEGIN_ENV_BEFORE_SOURCE"
|
||||
env
|
||||
$3 $4
|
||||
echo "------END_ENV_BEFORE_SOURCE"
|
||||
|
||||
echo "------BEGIN_BEFORE_SOURCE"
|
||||
@ -76,6 +76,5 @@ set
|
||||
echo "------END_AFTER_SOURCE"
|
||||
|
||||
echo "------BEGIN_ENV_AFTER_SOURCE"
|
||||
env
|
||||
$3 $4
|
||||
echo "------END_ENV_AFTER_SOURCE"
|
||||
|
||||
|
@ -379,22 +379,25 @@ class TestMozconfigLoader(unittest.TestCase):
|
||||
|
||||
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()
|
||||
@ -403,12 +406,13 @@ class TestMozconfigLoader(unittest.TestCase):
|
||||
|
||||
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')
|
||||
@ -418,7 +422,7 @@ class TestMozconfigLoader(unittest.TestCase):
|
||||
|
||||
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."""
|
||||
|
Loading…
Reference in New Issue
Block a user