changeset 9193:c8f4e1081c0b

support for referencing commands in other suites (e.g. mx.suite('graal').commands.build([]))
author Doug Simon <doug.simon@oracle.com>
date Fri, 19 Apr 2013 14:05:55 +0200
parents 123991e4fbd8
children cdd10396f2ad
files mx/projects mxtool/mx.py
diffstat 2 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mx/projects	Fri Apr 19 11:51:20 2013 +0200
+++ b/mx/projects	Fri Apr 19 14:05:55 2013 +0200
@@ -1,5 +1,7 @@
 # The format of this file is described in the documentation for my.py.
 
+suite=graal
+
 library@JDK_TOOLS@path=${JAVA_HOME}/lib/tools.jar
 library@JDK_TOOLS@optional=true
 
--- a/mxtool/mx.py	Fri Apr 19 11:51:20 2013 +0200
+++ b/mxtool/mx.py	Fri Apr 19 14:05:55 2013 +0200
@@ -459,7 +459,11 @@
         self._load_env(mxDir)
         self._load_commands(mxDir)
         self._load_includes(mxDir)
-
+        self.name = d # re-initialized in _load_projects
+
+    def __str__(self):
+        return self.name
+    
     def _load_projects(self, mxDir):
         libsMap = dict()
         projsMap = dict()
@@ -475,8 +479,11 @@
 
                     parts = key.split('@')
 
-                    if len(parts) == 2:
-                        pass
+                    if len(parts) == 1:
+                        if parts[0] != 'suite':
+                            abort('Single part property must be "suite": ' + key)
+                        self.name = value
+                        continue
                     if len(parts) != 3:
                         abort('Property name does not have 3 parts separated by "@": ' + key)
                     kind, name, attr = parts
@@ -539,6 +546,9 @@
             d = Distribution(self, name, path, deps)
             d.__dict__.update(attrs)
             self.dists.append(d)
+            
+        if self.name is None:
+            abort('Missing "suite=<name>" in ' + projectsFile)
 
     def _load_commands(self, mxDir):
         commands = join(mxDir, 'commands.py')
@@ -547,7 +557,8 @@
             sys.path.insert(0, mxDir)
             mod = __import__('commands')
             
-            sys.modules[join(mxDir, 'commands')] = sys.modules.pop('commands')
+            self.commands = sys.modules.pop('commands')
+            sys.modules[join(mxDir, 'commands')] = self.commands
 
             # revert the Python path
             del sys.path[0]
@@ -582,6 +593,7 @@
     def _post_init(self, opts):
         mxDir = join(self.dir, 'mx')
         self._load_projects(mxDir)
+        _suites[self.name] = self
         for p in self.projects:
             existing = _projects.get(p.name)
             if existing is not None:
@@ -703,6 +715,15 @@
     """
     return _suites.values()
 
+def suite(name, fatalIfMissing=True):
+    """
+    Get the suite for a given name.
+    """
+    s = _suites.get(name)
+    if s is None and fatalIfMissing:
+        abort('suite named ' + name + ' not found')
+    return s
+
 def projects():
     """
     Get the list of all loaded projects.