comparison mxtool/mx.py @ 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 025448743177
children 0f4ae7bbe062
comparison
equal deleted inserted replaced
9192:123991e4fbd8 9193:c8f4e1081c0b
457 self.primary = primary 457 self.primary = primary
458 mxDir = join(d, 'mx') 458 mxDir = join(d, 'mx')
459 self._load_env(mxDir) 459 self._load_env(mxDir)
460 self._load_commands(mxDir) 460 self._load_commands(mxDir)
461 self._load_includes(mxDir) 461 self._load_includes(mxDir)
462 462 self.name = d # re-initialized in _load_projects
463
464 def __str__(self):
465 return self.name
466
463 def _load_projects(self, mxDir): 467 def _load_projects(self, mxDir):
464 libsMap = dict() 468 libsMap = dict()
465 projsMap = dict() 469 projsMap = dict()
466 distsMap = dict() 470 distsMap = dict()
467 projectsFile = join(mxDir, 'projects') 471 projectsFile = join(mxDir, 'projects')
473 if len(line) != 0 and line[0] != '#': 477 if len(line) != 0 and line[0] != '#':
474 key, value = line.split('=', 1) 478 key, value = line.split('=', 1)
475 479
476 parts = key.split('@') 480 parts = key.split('@')
477 481
478 if len(parts) == 2: 482 if len(parts) == 1:
479 pass 483 if parts[0] != 'suite':
484 abort('Single part property must be "suite": ' + key)
485 self.name = value
486 continue
480 if len(parts) != 3: 487 if len(parts) != 3:
481 abort('Property name does not have 3 parts separated by "@": ' + key) 488 abort('Property name does not have 3 parts separated by "@": ' + key)
482 kind, name, attr = parts 489 kind, name, attr = parts
483 if kind == 'project': 490 if kind == 'project':
484 m = projsMap 491 m = projsMap
537 path = attrs.pop('path') 544 path = attrs.pop('path')
538 deps = pop_list(attrs, 'dependencies') 545 deps = pop_list(attrs, 'dependencies')
539 d = Distribution(self, name, path, deps) 546 d = Distribution(self, name, path, deps)
540 d.__dict__.update(attrs) 547 d.__dict__.update(attrs)
541 self.dists.append(d) 548 self.dists.append(d)
549
550 if self.name is None:
551 abort('Missing "suite=<name>" in ' + projectsFile)
542 552
543 def _load_commands(self, mxDir): 553 def _load_commands(self, mxDir):
544 commands = join(mxDir, 'commands.py') 554 commands = join(mxDir, 'commands.py')
545 if exists(commands): 555 if exists(commands):
546 # temporarily extend the Python path 556 # temporarily extend the Python path
547 sys.path.insert(0, mxDir) 557 sys.path.insert(0, mxDir)
548 mod = __import__('commands') 558 mod = __import__('commands')
549 559
550 sys.modules[join(mxDir, 'commands')] = sys.modules.pop('commands') 560 self.commands = sys.modules.pop('commands')
561 sys.modules[join(mxDir, 'commands')] = self.commands
551 562
552 # revert the Python path 563 # revert the Python path
553 del sys.path[0] 564 del sys.path[0]
554 565
555 if not hasattr(mod, 'mx_init'): 566 if not hasattr(mod, 'mx_init'):
580 os.environ[key.strip()] = expandvars_in_property(value.strip()) 591 os.environ[key.strip()] = expandvars_in_property(value.strip())
581 592
582 def _post_init(self, opts): 593 def _post_init(self, opts):
583 mxDir = join(self.dir, 'mx') 594 mxDir = join(self.dir, 'mx')
584 self._load_projects(mxDir) 595 self._load_projects(mxDir)
596 _suites[self.name] = self
585 for p in self.projects: 597 for p in self.projects:
586 existing = _projects.get(p.name) 598 existing = _projects.get(p.name)
587 if existing is not None: 599 if existing is not None:
588 abort('cannot override project ' + p.name + ' in ' + p.dir + " with project of the same name in " + existing.dir) 600 abort('cannot override project ' + p.name + ' in ' + p.dir + " with project of the same name in " + existing.dir)
589 if not p.name in _opts.ignored_projects: 601 if not p.name in _opts.ignored_projects:
700 def suites(): 712 def suites():
701 """ 713 """
702 Get the list of all loaded suites. 714 Get the list of all loaded suites.
703 """ 715 """
704 return _suites.values() 716 return _suites.values()
717
718 def suite(name, fatalIfMissing=True):
719 """
720 Get the suite for a given name.
721 """
722 s = _suites.get(name)
723 if s is None and fatalIfMissing:
724 abort('suite named ' + name + ' not found')
725 return s
705 726
706 def projects(): 727 def projects():
707 """ 728 """
708 Get the list of all loaded projects. 729 Get the list of all loaded projects.
709 """ 730 """