Bug 1251411 - Support defining static build data; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Thu, 25 Feb 2016 13:50:01 -0800
changeset 334698 ca2108eae8b3adb09110cc2c1efaf95a730dda96
parent 334689 5f2b6a81e84a0a88ad514809d8f0dd60fcdbf21a
child 514973 ab7b7f49346c2625e8ea5812c14191d1ce020df8
push id11613
push usergszorc@mozilla.com
push dateThu, 25 Feb 2016 21:51:07 +0000
reviewersglandium
bugs1251411
milestone47.0a1
Bug 1251411 - Support defining static build data; r?glandium There are various static data structures that are shared between multiple consumers. The build system, mach, etc. Currently, there is a lot of duplication of this code because there isn't an obvious location for this shared data. This commit attempts to change that. We introduce build/data.py as a standalone Python file that will hold static data. We import this module in the ConfigEnvironment class and expose the DATA module attribute (which is a dict) as .data in the ConfigEnvironment. Consumers will be added in the near future. We should arguably be putting this data in moz.build files or configure. At this junction, I'm not ready to commit to either. I'm worried that we'll end up stuffing lots of data in the root moz.build file. And given the volatility of configure at the moment, I'd rather wait until configure.py is running before we consider that. We're talking about static data, so porting it in the future shouldn't be too difficult. MozReview-Commit-ID: FvF2vNwhggr
build/data.py
python/mozbuild/mozbuild/backend/configenvironment.py
new file mode 100644
--- /dev/null
+++ b/build/data.py
@@ -0,0 +1,21 @@
+# 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/.
+
+# This file contains shared, read-only build data. Common lists of things,
+# etc.
+
+from __future__ import absolute_import, unicode_literals
+
+from mozbuild.util import (
+    ReadOnlyDict,
+)
+
+
+DATA = {
+
+}
+
+# TODO Ideally we'd iterate members and make them read-only as well.
+# For now, rely on people not doing stupid things.
+DATA = ReadOnlyDict(DATA)
--- a/python/mozbuild/mozbuild/backend/configenvironment.py
+++ b/python/mozbuild/mozbuild/backend/configenvironment.py
@@ -1,16 +1,18 @@
 # 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/.
 
 from __future__ import absolute_import
 
+import imp
 import os
 import sys
+import uuid
 
 from collections import Iterable
 from types import StringTypes
 
 import mozpack.path as mozpath
 
 from mozbuild.util import ReadOnlyDict
 from mozbuild.shellutil import quote as shell_quote
@@ -174,16 +176,23 @@ class ConfigEnvironment(object):
                     type(v)(decode(i) for i in v)
             elif not isinstance(v, text_type):
                 v = decode(v)
 
             self.substs_unicode[k] = v
 
         self.substs_unicode = ReadOnlyDict(self.substs_unicode)
 
+        # Load data module containing static data.
+        data_path = os.path.join(self.topsrcdir, 'build', 'data.py')
+        # Randomize module name to prevent conflicts.
+        data_mod = imp.load_source('mozbuild.build_data_%s' % uuid.uuid4(),
+                                   data_path)
+        self.data = data_mod.DATA
+
     @property
     def is_artifact_build(self):
         return self.substs.get('MOZ_ARTIFACT_BUILDS', False)
 
     @staticmethod
     def from_config_status(path):
         config = BuildConfig.from_config_status(path)