Add initial target buildplan logic
authorAndrew Gaffney <agaffney@gentoo.org>
Sat, 28 Nov 2009 23:48:24 +0000 (17:48 -0600)
committerAndrew Gaffney <agaffney@gentoo.org>
Sat, 28 Nov 2009 23:48:24 +0000 (17:48 -0600)
ChangeLog
modules/catalyst/target/__init__.py

index eacd2edf7ba8d9c0b25713dd23c9f56b6bdf5ec8..75fcb31f9f5fefb0a82a5c858e820e30805bae1b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,10 @@
 # Distributed under the GPL v2
 # $Id$
 
+  28 Nov 2009; Andrew Gaffney <agaffney@gentoo.org>
+  modules/catalyst/target/__init__.py:
+  Add initial target buildplan logic
+
   28 Nov 2009; Andrew Gaffney <agaffney@gentoo.org>
   modules/catalyst/target/generic.py:
   Add initialization of values for catalyst.target.target in
index 7d735bd91dbadd44736b7ccad213ee3ad2851bde..3bb100c7ea8d5496750c177ddba1cd06050d8090 100644 (file)
@@ -41,6 +41,84 @@ def find_built_targets(build_dir):
 
        return built_targets
 
+def build_targets():
+       buildplan = build_target_buildplan()
+
+       for target in buildplan:
+               try:
+                       target.run()
+               except:
+                       catalyst.util.print_traceback()
+                       catalyst.output.warn("Error encountered during run of target " + x)
+                       raise
+
+def build_target_buildplan():
+       targets = []
+       config = catalyst.config.config()
+       spec = config.get_spec()
+       spec_values = spec.get_values()
+       targetmap = config.get_targetmap()
+
+       built_targets = find_built_targets(spec_values['storedir'] + '/builds/')
+
+       if not "targets" in spec_values or not spec_values['targets']:
+               raise CatalystError, "No target(s) specified."
+
+       for x in spec_values['targets']:
+               if not x in targetmap:
+                       raise CatalystError("Target \"" + x + "\" is not a known target.")
+               config.get_spec().set_target(x)
+               target_tmp = { 'object': targetmap[x](), 'parent': '' }
+               target_tmp['info'] = target_tmp['object'].get_target_info()
+               target_tmp['depends'] = target_tmp['object'].depends
+               targets.append(target_tmp)
+
+       for i, target in enumerate(targets):
+               if len(target['depends']) == 0:
+                       targets[i]['parent'] = 'pass'
+                       continue
+
+               for x target['depends']:
+                       for y in built_targets:
+                               info = y.get_target_info()
+                               if info['target'] == y and info['version_stamp'] == target['info']['version_stamp'] and \
+                                       info['arch'] == target['info']['arch'] and info['rel_type'] == target['info']['rel_type']:
+                                       targets[i]['parent'] = 'built'
+                                       break
+
+                       for y in targets:
+                               info = y.get_target_info()
+                               if info['target'] == y and info['version_stamp'] == target['info']['version_stamp'] and \
+                                       info['arch'] == target['info']['arch'] and info['rel_type'] == target['info']['rel_type']:
+                                       targets[i]['parent'] = info['target']
+                                       break
+
+               if targets[i]['parent']:
+                       continue
+
+               raise CatalystError("Failed to resolve depedencies for target '%s'" % (target['info']['target'],))
+
+       while True:
+               did_something = False
+               for i, target in enumerate(targets):
+                       if target['parent'] in ('built', 'pass'):
+                               continue
+                       else:
+                               for j, foo in enumerate(targets):
+                                       if foo['target'] == target['parent']:
+                                               if i < j:
+                                                       tmp_target = targets.pop(j)
+                                                       targets.insert(i, tmp_target)
+                                                       did_something = True
+                                                       break
+                               if did_something:
+                                       break
+               if not did_something:
+                       break
+
+       return targets
+
+
 class target:
 
        _target = None