[ostree/wip/ostbuild-v2] ostbuild: Make prefix concept more robust
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/ostbuild-v2] ostbuild: Make prefix concept more robust
- Date: Wed, 25 Apr 2012 13:47:26 +0000 (UTC)
commit 16f99a68afcc5de5ac8852e7052342ef77f8c74d
Author: Colin Walters <walters verbum org>
Date: Wed Apr 25 09:04:01 2012 -0400
ostbuild: Make prefix concept more robust
Makefile-ostbuild.am | 1 +
gnomeos/3.4/gnomeos-3.4-src.json | 9 ++-
src/ostbuild/pyostbuild/builtin_bin_to_src.py | 3 +-
.../pyostbuild/builtin_build_components.py | 3 +-
src/ostbuild/pyostbuild/builtin_checkout.py | 9 ++-
.../pyostbuild/builtin_chroot_compile_one.py | 3 +-
src/ostbuild/pyostbuild/builtin_compose.py | 3 +-
src/ostbuild/pyostbuild/builtin_modify_snapshot.py | 3 +-
src/ostbuild/pyostbuild/builtin_prefix.py | 73 ++++++++++++++++++++
src/ostbuild/pyostbuild/builtin_resolve.py | 12 ++--
src/ostbuild/pyostbuild/builtins.py | 27 ++++++--
src/ostbuild/pyostbuild/main.py | 1 +
12 files changed, 123 insertions(+), 24 deletions(-)
---
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am
index 95441c2..b4b1a1f 100644
--- a/Makefile-ostbuild.am
+++ b/Makefile-ostbuild.am
@@ -29,6 +29,7 @@ pyostbuild_PYTHON = \
src/ostbuild/pyostbuild/builtin_chroot_compile_one.py \
src/ostbuild/pyostbuild/builtin_compile_one.py \
src/ostbuild/pyostbuild/builtin_pull_components.py \
+ src/ostbuild/pyostbuild/builtin_prefix.py \
src/ostbuild/pyostbuild/builtin_resolve.py \
src/ostbuild/pyostbuild/builtin_modify_snapshot.py \
src/ostbuild/pyostbuild/builtin_status.py \
diff --git a/gnomeos/3.4/gnomeos-3.4-src.json b/gnomeos/3.4/gnomeos-3.4-src.json
index 257bc74..dda0d71 100644
--- a/gnomeos/3.4/gnomeos-3.4-src.json
+++ b/gnomeos/3.4/gnomeos-3.4-src.json
@@ -1,7 +1,10 @@
{
- "name-prefix": "gnomeos-3.4",
+ "prefix": "gnomeos-3.4",
"architectures": ["i686"],
- "base-prefix": "yocto/gnomeos-3.4",
+ "base": {
+ "name": "yocto",
+ "src": "cgwalters:poky"
+ },
"config-opts": ["--disable-static", "--disable-silent-rules"],
@@ -24,7 +27,7 @@
"cgwalters": "git:git://github.com/cgwalters/"},
"patches": {"src": "gnome:ostree",
- "prefix": "gnomeos/3.4"},
+ "subdir": "gnomeos/3.4"},
"components": [
{"src": "cgwalters:ginitscripts",
diff --git a/src/ostbuild/pyostbuild/builtin_bin_to_src.py b/src/ostbuild/pyostbuild/builtin_bin_to_src.py
index 95addde..b8cbb0a 100755
--- a/src/ostbuild/pyostbuild/builtin_bin_to_src.py
+++ b/src/ostbuild/pyostbuild/builtin_bin_to_src.py
@@ -63,11 +63,12 @@ class OstbuildBinToSrc(builtins.Builtin):
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.bin_snapshot)
+ self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
snapshot = self.bin_snapshot_to_src(self.bin_snapshot)
json.dump(snapshot, sys.stdout, indent=4, sort_keys=True)
diff --git a/src/ostbuild/pyostbuild/builtin_build_components.py b/src/ostbuild/pyostbuild/builtin_build_components.py
index 5cc2bcc..463c7ee 100755
--- a/src/ostbuild/pyostbuild/builtin_build_components.py
+++ b/src/ostbuild/pyostbuild/builtin_build_components.py
@@ -182,6 +182,7 @@ class OstbuildBuildComponents(builtins.Builtin):
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
parser.add_argument('--skip-built', action='store_true')
+ parser.add_argument('--prefix')
parser.add_argument('--src-snapshot')
parser.add_argument('--skip-compose', action='store_true')
parser.add_argument('--start-at')
@@ -193,7 +194,7 @@ class OstbuildBuildComponents(builtins.Builtin):
self.args = args
self.parse_config()
- self.parse_snapshot(args.src_snapshot)
+ self.parse_snapshot(args.prefix, args.src_snapshot)
log("Using source snapshot: %s" % (os.path.basename(self.snapshot_path), ))
diff --git a/src/ostbuild/pyostbuild/builtin_checkout.py b/src/ostbuild/pyostbuild/builtin_checkout.py
index a4e2613..5e2ca52 100755
--- a/src/ostbuild/pyostbuild/builtin_checkout.py
+++ b/src/ostbuild/pyostbuild/builtin_checkout.py
@@ -40,6 +40,7 @@ class OstbuildCheckout(builtins.Builtin):
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
parser.add_argument('--overwrite', action='store_true')
+ parser.add_argument('--prefix')
parser.add_argument('--snapshot')
parser.add_argument('-a', '--active-tree', action='store_true')
parser.add_argument('-l', '--latest-snapshot', action='store_true')
@@ -57,7 +58,7 @@ class OstbuildCheckout(builtins.Builtin):
checkout_components = [os.path.basename(os.getcwd())]
if args.snapshot or args.latest_snapshot:
- self.parse_snapshot(args.snapshot)
+ self.parse_snapshot(args.prefix, args.snapshot)
elif args.active_tree:
self.parse_active_branch()
else:
@@ -91,9 +92,9 @@ class OstbuildCheckout(builtins.Builtin):
self.patchdir, patches['branch'],
overwrite=True)
- patch_prefix = patches.get('prefix', None)
- if patch_prefix is not None:
- patchdir = os.path.join(self.patchdir, patch_prefix)
+ patch_subdir = patches.get('subdir', None)
+ if patch_subdir is not None:
+ patchdir = os.path.join(self.patchdir, patch_subdir)
else:
patchdir = self.patchdir
for patch in patches['files']:
diff --git a/src/ostbuild/pyostbuild/builtin_chroot_compile_one.py b/src/ostbuild/pyostbuild/builtin_chroot_compile_one.py
index 594936b..6efc727 100755
--- a/src/ostbuild/pyostbuild/builtin_chroot_compile_one.py
+++ b/src/ostbuild/pyostbuild/builtin_chroot_compile_one.py
@@ -78,6 +78,7 @@ class OstbuildChrootCompileOne(builtins.Builtin):
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
parser.add_argument('--pristine', action='store_true')
+ parser.add_argument('--prefix')
parser.add_argument('--snapshot', required=True)
parser.add_argument('--name')
parser.add_argument('--arch', required=True)
@@ -86,7 +87,7 @@ class OstbuildChrootCompileOne(builtins.Builtin):
args = parser.parse_args(argv)
self.parse_config()
- self.parse_snapshot(args.snapshot)
+ self.parse_snapshot(args.prefix, args.snapshot)
if args.name:
component_name = args.name
diff --git a/src/ostbuild/pyostbuild/builtin_compose.py b/src/ostbuild/pyostbuild/builtin_compose.py
index 61a8d19..00935ca 100755
--- a/src/ostbuild/pyostbuild/builtin_compose.py
+++ b/src/ostbuild/pyostbuild/builtin_compose.py
@@ -95,6 +95,7 @@ class OstbuildCompose(builtins.Builtin):
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
+ parser.add_argument('--prefix')
parser.add_argument('--bin-snapshot')
parser.add_argument('--no-print-diff', action='store_true')
@@ -102,7 +103,7 @@ class OstbuildCompose(builtins.Builtin):
self.args = args
self.parse_config()
- self.parse_bin_snapshot(args.bin_snapshot)
+ self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
log("Using binary snapshot: %s" % (os.path.basename(self.bin_snapshot_path), ))
diff --git a/src/ostbuild/pyostbuild/builtin_modify_snapshot.py b/src/ostbuild/pyostbuild/builtin_modify_snapshot.py
index e1b2df5..b438a9a 100755
--- a/src/ostbuild/pyostbuild/builtin_modify_snapshot.py
+++ b/src/ostbuild/pyostbuild/builtin_modify_snapshot.py
@@ -34,12 +34,13 @@ class OstbuildModifySnapshot(builtins.Builtin):
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
+ parser.add_argument('--prefix')
parser.add_argument('--src-snapshot')
args = parser.parse_args(argv)
self.parse_config()
- self.parse_snapshot(args.src_snapshot)
+ self.parse_snapshot(args.prefix, args.src_snapshot)
component_name = self.get_component_from_cwd()
current_meta = self.get_component_meta(component_name)
diff --git a/src/ostbuild/pyostbuild/builtin_prefix.py b/src/ostbuild/pyostbuild/builtin_prefix.py
new file mode 100755
index 0000000..4ffa981
--- /dev/null
+++ b/src/ostbuild/pyostbuild/builtin_prefix.py
@@ -0,0 +1,73 @@
+# 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 OstbuildPrefix(builtins.Builtin):
+ name = "prefix"
+ short_description = "Display or modify \"prefix\" (build target)"
+
+ def __init__(self):
+ builtins.Builtin.__init__(self)
+
+ def _set_prefix(self, prefix):
+ f = open(self.path, 'w')
+ f.write(prefix)
+ f.write('\n')
+ f.close()
+ log("Prefix is now %r" % (prefix, ))
+
+ def execute(self, argv):
+ parser = argparse.ArgumentParser(description=self.short_description)
+ parser.add_argument('-a', '--active', action='store_true')
+ parser.add_argument('prefix', nargs='?', default=None)
+
+ args = parser.parse_args(argv)
+
+ self.path = os.path.expanduser('~/.config/ostbuild-prefix')
+ if args.prefix is None and not args.active:
+ if os.path.exists(self.path):
+ f = open(self.path)
+ print "%s" % (f.read().strip(), )
+ f.close()
+ else:
+ log("No currently active prefix")
+ elif args.prefix is not None and args.active:
+ fatal("Can't specify -a with prefix")
+ elif args.prefix is not None:
+ self._set_prefix(args.prefix)
+ else:
+ assert args.active
+
+ self.parse_active_branch()
+
+ active_prefix = self.active_branch_contents['prefix']
+
+ self._set_prefix(active_prefix)
+
+builtins.register(OstbuildPrefix)
diff --git a/src/ostbuild/pyostbuild/builtin_resolve.py b/src/ostbuild/pyostbuild/builtin_resolve.py
index ef2293c..4ddd1ad 100755
--- a/src/ostbuild/pyostbuild/builtin_resolve.py
+++ b/src/ostbuild/pyostbuild/builtin_resolve.py
@@ -196,10 +196,10 @@ class OstbuildResolve(builtins.Builtin):
component['patches'] = copy.deepcopy(global_patches_meta)
component['patches']['files'] = patch_files
- name_prefix = snapshot['name-prefix']
- base_prefix = snapshot['base-prefix']
-
manifest_architectures = snapshot['architectures']
+
+ ostree_prefix = snapshot['prefix']
+ base_prefix = '%s/%s' % (snapshot['base']['name'], ostree_prefix)
snapshot['architecture-buildroots'] = {}
for architecture in manifest_architectures:
@@ -216,7 +216,7 @@ class OstbuildResolve(builtins.Builtin):
for component in component_source_list:
base_name = component['name']
- name = '%s/%s' % (name_prefix, base_name)
+ name = '%s/%s' % (ostree_prefix, base_name)
component['name'] = name
components_by_name[name] = component
@@ -244,8 +244,6 @@ class OstbuildResolve(builtins.Builtin):
builds[name] = component_arches
# We expanded these keys
- del snapshot['name-prefix']
- del snapshot['base-prefix']
del snapshot['config-opts']
del snapshot['vcsconfig']
del snapshot['patches']
@@ -257,7 +255,7 @@ class OstbuildResolve(builtins.Builtin):
for architecture in manifest_architectures:
target = {}
targets_list.append(target)
- target['name'] = '%s-%s-%s' % (name_prefix, architecture, target_component_type)
+ target['name'] = '%s-%s-%s' % (ostree_prefix, architecture, target_component_type)
base_ref = '%s-%s-%s' % (base_prefix, architecture, target_component_type)
target['base'] = {'name': base_ref}
diff --git a/src/ostbuild/pyostbuild/builtins.py b/src/ostbuild/pyostbuild/builtins.py
index 4027411..05ae2bc 100755
--- a/src/ostbuild/pyostbuild/builtins.py
+++ b/src/ostbuild/pyostbuild/builtins.py
@@ -37,6 +37,7 @@ class Builtin(object):
def __init__(self):
self._meta_cache = {}
+ self.prefix = None
self.manifest = None
self.snapshot = None
self.bin_snapshot = None
@@ -98,6 +99,8 @@ class Builtin(object):
if not os.path.isdir(repo_path):
fatal("Repository '%s' doesn't exist" % (repo_path, ))
self.repo = repo_path
+ if self.active_branch is None:
+ fatal("No \"current\" link found")
branch_path = os.path.join(self.ostree_dir, self.active_branch)
contents_path = os.path.join(branch_path, 'contents.json')
f = open(contents_path)
@@ -133,8 +136,18 @@ class Builtin(object):
self._meta_cache[name] = meta
return meta
+ def get_prefix(self):
+ if self.prefix is None:
+ path = os.path.expanduser('~/.config/ostbuild-prefix')
+ if not os.path.exists(path):
+ fatal("No prefix set; use \"ostbuild prefix\" to set one")
+ f = open(path)
+ self.prefix = f.read().strip()
+ f.close()
+ return self.prefix
+
def _create_db(self, dbsuffix):
- prefix = ostbuildrc.get_key('prefix')
+ prefix = self.get_prefix()
name = '%s-%s' % (prefix, dbsuffix)
fileutil.ensure_dir(self.snapshot_dir)
return jsondb.JsonDB(self.snapshot_dir, prefix=name)
@@ -149,12 +162,14 @@ class Builtin(object):
self._bin_snapshots = self._create_db('bin-snapshot')
return self._bin_snapshots
- def parse_snapshot(self, path):
+ def parse_snapshot(self, prefix, path):
+ if prefix is not None:
+ self.prefix = prefix
self.repo = ostbuildrc.get_key('repo')
if path is None:
latest_path = self.get_src_snapshot_db().get_latest_path()
if latest_path is None:
- raise Exception("No source snapshot found")
+ raise Exception("No source snapshot found for prefix %r" % (self.prefix, ))
self.snapshot_path = latest_path
else:
self.snapshot_path = path
@@ -163,12 +178,14 @@ class Builtin(object):
if src_ver != 0:
fatal("Unhandled 00ostree-src-snapshot-version \"%d\", expected 0", src_ver)
- def parse_bin_snapshot(self, path):
+ def parse_bin_snapshot(self, prefix, path):
+ if prefix is not None:
+ self.prefix = prefix
self.repo = ostbuildrc.get_key('repo')
if path is None:
latest_path = self.get_bin_snapshot_db().get_latest_path()
if latest_path is None:
- raise Exception("No binary snapshot found")
+ raise Exception("No binary snapshot found for prefix %r" % (self.prefix, ))
self.bin_snapshot_path = latest_path
else:
self.bin_snapshot_path = path
diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py
index 1ca2d95..60ad2c7 100755
--- a/src/ostbuild/pyostbuild/main.py
+++ b/src/ostbuild/pyostbuild/main.py
@@ -29,6 +29,7 @@ from . import builtin_chroot_compile_one
from . import builtin_compose
from . import builtin_compile_one
from . import builtin_pull_components
+from . import builtin_prefix
from . import builtin_resolve
from . import builtin_modify_snapshot
from . import builtin_status
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]