[ostree/wip/ostbuild-v2: 2/4] build: Refactor compose to operate off "binary snapshot"
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/ostbuild-v2: 2/4] build: Refactor compose to operate off "binary snapshot"
- Date: Thu, 19 Apr 2012 03:15:19 +0000 (UTC)
commit 01cf3af962b0a2c3628fbd8a964c11cb832212a1
Author: Colin Walters <walters verbum org>
Date: Tue Apr 17 14:50:22 2012 -0400
build: Refactor compose to operate off "binary snapshot"
src/ostbuild/pyostbuild/builtin_build.py | 78 +++++++++++++++++-------------
1 files changed, 45 insertions(+), 33 deletions(-)
---
diff --git a/src/ostbuild/pyostbuild/builtin_build.py b/src/ostbuild/pyostbuild/builtin_build.py
index cac17b3..c044601 100755
--- a/src/ostbuild/pyostbuild/builtin_build.py
+++ b/src/ostbuild/pyostbuild/builtin_build.py
@@ -143,31 +143,18 @@ class OstbuildBuild(builtins.Builtin):
os.unlink(statoverride_path)
return True
- def _compose(self, target):
- base_name = 'bases/%s' % (target['base']['name'], )
- branch_to_rev = {}
- branch_to_subtrees = {}
-
- contents = [base_name]
- branch_to_subtrees[base_name] = ['/']
- base_revision = run_sync_get_output(['ostree', '--repo=' + self.repo,
- 'rev-parse', base_name])
+ def _resolve_refs(self, refs):
+ args = ['ostree', '--repo=' + self.repo, 'rev-parse']
+ args.extend(refs)
+ output = run_sync_get_output(args)
+ return output.split('\n')
- branch_to_rev[base_name] = base_revision
+ def _compose_one_target(self, bin_snapshot, target):
+ components = bin_snapshot['components']
+ base = target['base']
+ base_name = 'bases/%s' % (base['name'], )
+ base_revision = target['base']['ostree-revision']
- args = ['ostree', '--repo=' + self.repo, 'rev-parse']
- for component in target['contents']:
- name = component['name']
- contents.append(name)
- args.append('components/%s' % (name, ))
- branch_to_subtrees[name] = component['trees']
- branch_revs_text = run_sync_get_output(args)
- branch_revs = branch_revs_text.split('\n')
-
- for (content, rev) in zip(target['contents'], branch_revs):
- name = content['name']
- branch_to_rev[name] = rev
-
compose_rootdir = os.path.join(self.workdir, 'roots', target['name'])
if os.path.isdir(compose_rootdir):
shutil.rmtree(compose_rootdir)
@@ -176,23 +163,27 @@ class OstbuildBuild(builtins.Builtin):
resolved_base = dict(target['base'])
resolved_base['ostree-revision'] = base_revision
resolved_contents = list(target['contents'])
- for component in resolved_contents:
- component['ostree-revision'] = branch_to_rev[component['name']]
+ for tree_content_item in resolved_contents:
+ name = tree_content_item['name']
+ rev = components[name]['ostree-revision']
+ tree_content_item['ostree-revision'] = rev
metadata = {'source': 'ostbuild compose v0',
'base': resolved_base,
'contents': resolved_contents}
- for k,v in self.snapshot.iteritems():
+
+ # Copy all other keys
+ for k,v in bin_snapshot.iteritems():
if k in ['components', 'targets']:
continue
metadata[k] = v
- compose_contents = []
- for branch in contents:
- branch_rev = branch_to_rev[branch]
- subtrees = branch_to_subtrees[branch]
+ compose_contents = [(base_revision, '/')]
+ for tree_content in resolved_contents:
+ rev = tree_content['ostree-revision']
+ subtrees = tree_content['trees']
for subpath in subtrees:
- compose_contents.append((branch_rev, subpath))
+ compose_contents.append((rev, subpath))
(fd, tmppath) = tempfile.mkstemp(suffix='.txt', prefix='ostbuild-compose-')
f = os.fdopen(fd, 'w')
@@ -273,7 +264,28 @@ class OstbuildBuild(builtins.Builtin):
self._build_one_component(component_name, component)
if not args.skip_compose:
- for target in self.snapshot['targets']:
- self._compose(target)
+
+ bin_snapshot = dict(self.snapshot)
+
+ for target in bin_snapshot['targets']:
+ base = target['base']
+ base_name = 'bases/%s' % (base['name'], )
+ base_revision = run_sync_get_output(['ostree', '--repo=' + self.repo,
+ 'rev-parse', base_name])
+ base['ostree-revision'] = base_revision
+
+ component_refs = []
+ for name in bin_snapshot['components'].iterkeys():
+ component_refs.append('components/%s' % (name, ))
+
+ new_components = {}
+ resolved_refs = self._resolve_refs(component_refs)
+ for name,rev in zip(bin_snapshot['components'].iterkeys(), resolved_refs):
+ new_components[name] = {'ostree-revision': rev}
+
+ bin_snapshot['components'] = new_components
+
+ for target in bin_snapshot['targets']:
+ self._compose_one_target(bin_snapshot, target)
builtins.register(OstbuildBuild)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]