1
0
mirror of https://github.com/ostreedev/ostree.git synced 2025-03-21 02:50:37 +03:00

ostbuild: Make binary snapshots an extension of source

This significantly simplifies things; we no longer need to retrieve
individual components via 'pull-components', etc.
This commit is contained in:
Colin Walters 2012-05-10 19:07:54 -04:00
parent c18817eca1
commit 65165ff1df
7 changed files with 37 additions and 107 deletions

@ -23,7 +23,6 @@ EXTRA_DIST += src/ostbuild/ostbuild.in
pyostbuilddir=$(libdir)/ostbuild/pyostbuild
pyostbuild_PYTHON = \
src/ostbuild/pyostbuild/buildutil.py \
src/ostbuild/pyostbuild/builtin_bin_to_src.py \
src/ostbuild/pyostbuild/builtin_branch_prefix.py \
src/ostbuild/pyostbuild/builtin_build_components.py \
src/ostbuild/pyostbuild/builtin_checkout.py \
@ -38,7 +37,7 @@ pyostbuild_PYTHON = \
src/ostbuild/pyostbuild/builtin_prefix.py \
src/ostbuild/pyostbuild/builtin_resolve.py \
src/ostbuild/pyostbuild/builtin_modify_snapshot.py \
src/ostbuild/pyostbuild/builtin_tree_to_bin.py \
src/ostbuild/pyostbuild/builtin_tree_to_src.py \
src/ostbuild/pyostbuild/builtin_init.py \
src/ostbuild/pyostbuild/builtin_status.py \
src/ostbuild/pyostbuild/builtins.py \

@ -1,81 +0,0 @@
# Copyright (C) 2011,2012 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
# ostbuild-compile-one-make wraps systems that implement the GNOME build API:
# http://people.gnome.org/~walters/docs/build-api.txt
import os,sys,stat,subprocess,tempfile,re,shutil
import argparse
from StringIO import StringIO
import json
from . import builtins
from .ostbuildlog import log, fatal
from .subprocess_helpers import run_sync, run_sync_get_output
from . import buildutil
class OstbuildBinToSrc(builtins.Builtin):
name = "bin-to-src"
short_description = "Turn a binary snapshot into a source snapshot"
def __init__(self):
builtins.Builtin.__init__(self)
def bin_snapshot_to_src(self, bin_snapshot):
del bin_snapshot['00ostree-bin-snapshot-version']
src_snapshot = dict(bin_snapshot)
src_snapshot['00ostree-src-snapshot-version'] = 0
all_architectures = src_snapshot['architecture-buildroots'].keys()
# Arbitrarily take first architecture
first_arch = all_architectures[0]
bin_components = src_snapshot['components']
src_components = {}
src_snapshot['components'] = src_components
for archname,rev in bin_components.iteritems():
(name, arch) = archname.rsplit('/', 1)
if arch != first_arch:
continue
meta = dict(self.get_component_meta_from_revision(rev))
del meta['name']
src_components[name] = meta
for target in src_snapshot['targets']:
for content_item in target['contents']:
name = content_item['name']
rev = bin_components[name]
content_item['ostree-revision'] = rev
return src_snapshot
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
parser.add_argument('--prefix')
parser.add_argument('--bin-snapshot')
args = parser.parse_args(argv)
self.parse_config()
self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
snapshot = self.bin_snapshot_to_src(self.bin_snapshot)
db = self.get_src_snapshot_db()
path = db.store(snapshot)
log("Source snapshot: %s" % (path, ))
builtins.register(OstbuildBinToSrc)

@ -178,7 +178,7 @@ class OstbuildBuildComponents(builtins.Builtin):
bin_snapshot = dict(self.snapshot)
del bin_snapshot['00ostree-src-snapshot-version']
bin_snapshot['00ostree-bin-snapshot-version'] = 0
bin_snapshot['00ostree-bin-snapshot-version'] = 1
for target in bin_snapshot['targets']:
base = target['base']
@ -199,14 +199,14 @@ class OstbuildBuildComponents(builtins.Builtin):
for architecture in component_architectures[name]:
component_refs.append('components/%s/%s' % (name, architecture))
new_components = {}
component_revisions = {}
resolved_refs = self._resolve_refs(component_refs)
for name,rev in zip(components.iterkeys(), resolved_refs):
for architecture in component_architectures[name]:
archname = '%s/%s' % (name, architecture)
new_components[archname] = rev
component_revisions[archname] = rev
bin_snapshot['components'] = new_components
bin_snapshot['component-revisions'] = component_revisions
path = self.get_bin_snapshot_db().store(bin_snapshot)
log("Binary snapshot: %s" % (path, ))
@ -218,6 +218,7 @@ class OstbuildBuildComponents(builtins.Builtin):
parser.add_argument('--prefix')
parser.add_argument('--src-snapshot')
parser.add_argument('--compose', action='store_true')
parser.add_argument('--compose-only', action='store_true')
parser.add_argument('--start-at')
parser.add_argument('--shell-on-failure', action='store_true')
parser.add_argument('--debug-shell', action='store_true')
@ -276,11 +277,12 @@ class OstbuildBuildComponents(builtins.Builtin):
else:
start_at_index = 0
for component_name in build_component_order[start_at_index:]:
component = required_components[component_name]
architectures = component_architectures[component_name]
for architecture in architectures:
self._build_one_component(component_name, component, architecture)
if not args.compose_only:
for component_name in build_component_order[start_at_index:]:
component = required_components[component_name]
architectures = component_architectures[component_name]
for architecture in architectures:
self._build_one_component(component_name, component, architecture)
self._save_bin_snapshot(required_components, component_architectures)

@ -41,7 +41,7 @@ class OstbuildCompose(builtins.Builtin):
builtins.Builtin.__init__(self)
def _compose_one_target(self, bin_snapshot, target):
components = bin_snapshot['components']
components = bin_snapshot['component-revisions']
base = target['base']
base_name = 'bases/%s' % (base['name'], )
base_revision = target['base']['ostree-revision']

@ -28,13 +28,21 @@ from .ostbuildlog import log, fatal
from .subprocess_helpers import run_sync, run_sync_get_output
from . import buildutil
class OstbuildTreeToBin(builtins.Builtin):
name = "tree-to-bin"
short_description = "Turn a tree into a binary snapshot"
class OstbuildTreeToSrc(builtins.Builtin):
name = "tree-to-src"
short_description = "Turn a tree into a source snapshot"
def __init__(self):
builtins.Builtin.__init__(self)
def bin_snapshot_to_src(self, bin_snapshot):
del bin_snapshot['00ostree-bin-snapshot-version']
src_snapshot = dict(bin_snapshot)
src_snapshot['00ostree-src-snapshot-version'] = 0
return src_snapshot
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
parser.add_argument('--prefix')
@ -50,8 +58,9 @@ class OstbuildTreeToBin(builtins.Builtin):
else:
self.load_bin_snapshot_from_current()
db = self.get_bin_snapshot_db()
path = db.store(self.bin_snapshot)
log("Binary snapshot: %s" % (path, ))
snapshot = self.bin_snapshot_to_src(self.bin_snapshot)
db = self.get_src_snapshot_db()
path = db.store(snapshot)
log("Source snapshot: %s" % (path, ))
builtins.register(OstbuildTreeToBin)
builtins.register(OstbuildTreeToSrc)

@ -93,11 +93,13 @@ class Builtin(object):
self.patchdir = os.path.join(self.workdir, 'patches')
def load_bin_snapshot_from_path(self, path):
self.bin_snapshot_path = os.path.join(path, 'contents.json')
self.bin_snapshot_path = os.path.join(path, 'ostree-meta', 'contents.json')
if not os.path.exists(self.bin_snapshot_path):
self.bin_snapshot_path = os.path.join(path, 'contents.json')
self.bin_snapshot = json.load(open(self.bin_snapshot_path))
bin_ver = self.bin_snapshot['00ostree-bin-snapshot-version']
if bin_ver != 0:
fatal("Unhandled 00ostree-bin-snapshot-version \"%d\", expected 0", bin_ver)
if bin_ver != 1:
fatal("Unhandled 00ostree-bin-snapshot-version %r, expected 1" % (bin_ver, ))
def load_bin_snapshot_from_current(self):
if self.ostree_dir is None:
@ -211,8 +213,8 @@ class Builtin(object):
self.bin_snapshot_path = path
self.bin_snapshot = json.load(open(self.bin_snapshot_path))
bin_ver = self.bin_snapshot['00ostree-bin-snapshot-version']
if bin_ver != 0:
fatal("Unhandled 00ostree-bin-snapshot-version \"%d\", expected 0" % (bin_ver, ))
if bin_ver != 1:
fatal("Unhandled 00ostree-bin-snapshot-version %r, expected 1" % (bin_ver, ))
def execute(self, args):
raise NotImplementedError()

@ -22,7 +22,6 @@ import sys
import argparse
from . import builtins
from . import builtin_bin_to_src
from . import builtin_build_components
from . import builtin_branch_prefix
from . import builtin_checkout
@ -37,7 +36,7 @@ from . import builtin_privhelper_deploy_qemu
from . import builtin_prefix
from . import builtin_resolve
from . import builtin_modify_snapshot
from . import builtin_tree_to_bin
from . import builtin_tree_to_src
from . import builtin_init
from . import builtin_status