ostbuild: Fix circular dependency between resolve and git-mirror

git-mirror was looking for the latest snapshot, which we don't
have until we resolve.

This leads to some code duplication.
This commit is contained in:
Colin Walters 2012-06-06 12:56:48 -04:00
parent a14ff0aeab
commit 2c385c0078
4 changed files with 47 additions and 38 deletions

View File

@ -22,6 +22,7 @@ import tempfile
import StringIO
from . import ostbuildrc
from .ostbuildlog import log, fatal
from .subprocess_helpers import run_sync_get_output
BUILD_ENV = {
@ -47,7 +48,8 @@ def parse_src_key(srckey):
def get_mirrordir(mirrordir, keytype, uri, prefix=''):
assert keytype == 'git'
if keytype != 'git':
fatal("Unhandled keytype '%s' for uri '%s'" % (keytype, uri))
parsed = urlparse.urlsplit(uri)
return os.path.join(mirrordir, prefix, keytype, parsed.scheme, parsed.netloc, parsed.path[1:])
@ -151,3 +153,35 @@ def get_base_user_chroot_args():
return args
def resolve_component_meta(snapshot, component_meta):
result = dict(component_meta)
orig_src = component_meta['src']
did_expand = False
for (vcsprefix, expansion) in snapshot['vcsconfig'].iteritems():
prefix = vcsprefix + ':'
if orig_src.startswith(prefix):
result['src'] = expansion + orig_src[len(prefix):]
did_expand = True
break
name = component_meta.get('name')
if name is None:
if did_expand:
src = orig_src
idx = src.rindex(':')
name = src[idx+1:]
else:
src = result['src']
idx = src.rindex('/')
name = src[idx+1:]
if name.endswith('.git'):
name = name[:-4]
name = name.replace('/', '-')
result['name'] = name
branch_or_tag = result.get('branch') or result.get('tag')
if branch_or_tag is None:
result['branch'] = 'master'
return result

View File

@ -167,6 +167,7 @@ class OstbuildBuild(builtins.Builtin):
f = os.fdopen(fd, 'w')
for path in setuid_files:
f.write('+2048 ' + path)
f.write('\n')
f.close()
args.append('--statoverride=' + statoverride_path)

View File

@ -39,6 +39,7 @@ class OstbuildGitMirror(builtins.Builtin):
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
parser.add_argument('--prefix')
parser.add_argument('--manifest')
parser.add_argument('--src-snapshot')
parser.add_argument('--start-at',
help="Start at the given component")
@ -52,7 +53,13 @@ class OstbuildGitMirror(builtins.Builtin):
args = parser.parse_args(argv)
self.parse_config()
self.parse_snapshot(args.prefix, args.src_snapshot)
if args.manifest:
self.snapshot = json.load(open(args.manifest))
components = map(lambda x: buildutil.resolve_component_meta(self.snapshot, x), self.snapshot['components'])
self.snapshot['components'] = components
self.snapshot['patches'] = buildutil.resolve_component_meta(self.snapshot, self.snapshot['patches'])
else:
self.parse_snapshot(args.prefix, args.src_snapshot)
if len(args.components) == 0:
components = []

View File

@ -40,39 +40,6 @@ class OstbuildResolve(builtins.Builtin):
def __init__(self):
builtins.Builtin.__init__(self)
def _resolve_component_meta(self, component_meta):
result = dict(component_meta)
orig_src = component_meta['src']
did_expand = False
for (vcsprefix, expansion) in self.snapshot['vcsconfig'].iteritems():
prefix = vcsprefix + ':'
if orig_src.startswith(prefix):
result['src'] = expansion + orig_src[len(prefix):]
did_expand = True
break
name = component_meta.get('name')
if name is None:
if did_expand:
src = orig_src
idx = src.rindex(':')
name = src[idx+1:]
else:
src = result['src']
idx = src.rindex('/')
name = src[idx+1:]
if name.endswith('.git'):
name = name[:-4]
name = name.replace('/', '-')
result['name'] = name
branch_or_tag = result.get('branch') or result.get('tag')
if branch_or_tag is None:
result['branch'] = 'master'
return result
def execute(self, argv):
parser = argparse.ArgumentParser(description=self.short_description)
parser.add_argument('--manifest', required=True)
@ -87,7 +54,7 @@ class OstbuildResolve(builtins.Builtin):
self.snapshot = json.load(open(args.manifest))
self.prefix = self.snapshot['prefix']
components = map(self._resolve_component_meta, self.snapshot['components'])
components = map(lambda x: buildutil.resolve_component_meta(self.snapshot, x), self.snapshot['components'])
self.snapshot['components'] = components
unique_component_names = set()
@ -98,14 +65,14 @@ class OstbuildResolve(builtins.Builtin):
fatal("Duplicate component name '%s'" % (name, ))
unique_component_names.add(name)
global_patches_meta = self._resolve_component_meta(self.snapshot['patches'])
global_patches_meta = buildutil.resolve_component_meta(self.snapshot, self.snapshot['patches'])
self.snapshot['patches'] = global_patches_meta
(keytype, uri) = vcs.parse_src_key(global_patches_meta['src'])
mirrordir = vcs.ensure_vcs_mirror(self.mirrordir, keytype, uri, global_patches_meta['branch'])
if args.fetch_patches:
run_sync(['git', 'fetch'], cwd=mirrordir, log_initiation=False)
git_mirror_args = ['ostbuild', 'git-mirror']
git_mirror_args = ['ostbuild', 'git-mirror', '--manifest=' + args.manifest]
if args.fetch:
git_mirror_args.append('--fetch')
run_sync(git_mirror_args)