Bug 1278415 - Make the buildconfig module use MozbuildObject.from_environment. r?gps
The buildconfig module predates MozbuildObject.from_environment, and
it's about time to start factoring things out such that we only have
one way to get config.status data. This is step 1: making the
buildconfig module use MozbuildObject.from_environment.
Eventually, we'll want to remove the buildconfig module uses everywhere.
--- a/build/buildconfig.py
+++ b/build/buildconfig.py
@@ -1,30 +1,20 @@
# 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/.
-import imp
import os
import sys
+from mozbuild.base import MozbuildObject
-path = os.path.dirname(sys.executable)
-while not os.path.exists(os.path.join(path, 'config.status')):
- parent = os.path.normpath(os.path.join(path, os.pardir))
- if parent == path:
- raise Exception("Can't find config.status")
- path = parent
+config = MozbuildObject.from_environment()
-path = os.path.join(path, 'config.status')
-config = imp.load_module('_buildconfig', open(path), path, ('', 'r', imp.PY_SOURCE))
+for var in ('topsrcdir', 'topobjdir', 'defines', 'non_global_defines',
+ 'substs'):
+ value = getattr(config, var)
+ setattr(sys.modules[__name__], var, value)
-# Copy values from the config.status namespace into this module namespace.
-# This effectively imports topsrcdir, topobjdir, defines, substs, files,
-# headers and non_global_defines
-for var in config.__all__:
- value = getattr(config, var)
- if isinstance(value, list) and value and isinstance(value[0], tuple):
- value = dict(value)
- setattr(sys.modules[__name__], var, value)
+substs = dict(substs)
for var in os.environ:
if var != 'SHELL' and var in substs:
substs[var] = os.environ[var]
--- a/python/mozbuild/mozbuild/base.py
+++ b/python/mozbuild/mozbuild/base.py
@@ -265,16 +265,20 @@ class MozbuildObject(ProcessExecutionMix
return self._config_environment
@property
def defines(self):
return self.config_environment.defines
@property
+ def non_global_defines(self):
+ return self.config_environment.non_global_defines
+
+ @property
def substs(self):
return self.config_environment.substs
@property
def distdir(self):
return os.path.join(self.topobjdir, 'dist')
@property