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:
parent
a14ff0aeab
commit
2c385c0078
|
|
@ -22,6 +22,7 @@ import tempfile
|
||||||
import StringIO
|
import StringIO
|
||||||
|
|
||||||
from . import ostbuildrc
|
from . import ostbuildrc
|
||||||
|
from .ostbuildlog import log, fatal
|
||||||
from .subprocess_helpers import run_sync_get_output
|
from .subprocess_helpers import run_sync_get_output
|
||||||
|
|
||||||
BUILD_ENV = {
|
BUILD_ENV = {
|
||||||
|
|
@ -47,7 +48,8 @@ def parse_src_key(srckey):
|
||||||
|
|
||||||
|
|
||||||
def get_mirrordir(mirrordir, keytype, uri, prefix=''):
|
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)
|
parsed = urlparse.urlsplit(uri)
|
||||||
return os.path.join(mirrordir, prefix, keytype, parsed.scheme, parsed.netloc, parsed.path[1:])
|
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
|
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
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ class OstbuildBuild(builtins.Builtin):
|
||||||
f = os.fdopen(fd, 'w')
|
f = os.fdopen(fd, 'w')
|
||||||
for path in setuid_files:
|
for path in setuid_files:
|
||||||
f.write('+2048 ' + path)
|
f.write('+2048 ' + path)
|
||||||
|
f.write('\n')
|
||||||
f.close()
|
f.close()
|
||||||
args.append('--statoverride=' + statoverride_path)
|
args.append('--statoverride=' + statoverride_path)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ class OstbuildGitMirror(builtins.Builtin):
|
||||||
def execute(self, argv):
|
def execute(self, argv):
|
||||||
parser = argparse.ArgumentParser(description=self.short_description)
|
parser = argparse.ArgumentParser(description=self.short_description)
|
||||||
parser.add_argument('--prefix')
|
parser.add_argument('--prefix')
|
||||||
|
parser.add_argument('--manifest')
|
||||||
parser.add_argument('--src-snapshot')
|
parser.add_argument('--src-snapshot')
|
||||||
parser.add_argument('--start-at',
|
parser.add_argument('--start-at',
|
||||||
help="Start at the given component")
|
help="Start at the given component")
|
||||||
|
|
@ -52,7 +53,13 @@ class OstbuildGitMirror(builtins.Builtin):
|
||||||
|
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
self.parse_config()
|
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:
|
if len(args.components) == 0:
|
||||||
components = []
|
components = []
|
||||||
|
|
|
||||||
|
|
@ -40,39 +40,6 @@ class OstbuildResolve(builtins.Builtin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
builtins.Builtin.__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):
|
def execute(self, argv):
|
||||||
parser = argparse.ArgumentParser(description=self.short_description)
|
parser = argparse.ArgumentParser(description=self.short_description)
|
||||||
parser.add_argument('--manifest', required=True)
|
parser.add_argument('--manifest', required=True)
|
||||||
|
|
@ -87,7 +54,7 @@ class OstbuildResolve(builtins.Builtin):
|
||||||
self.snapshot = json.load(open(args.manifest))
|
self.snapshot = json.load(open(args.manifest))
|
||||||
self.prefix = self.snapshot['prefix']
|
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
|
self.snapshot['components'] = components
|
||||||
|
|
||||||
unique_component_names = set()
|
unique_component_names = set()
|
||||||
|
|
@ -98,14 +65,14 @@ class OstbuildResolve(builtins.Builtin):
|
||||||
fatal("Duplicate component name '%s'" % (name, ))
|
fatal("Duplicate component name '%s'" % (name, ))
|
||||||
unique_component_names.add(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
|
self.snapshot['patches'] = global_patches_meta
|
||||||
(keytype, uri) = vcs.parse_src_key(global_patches_meta['src'])
|
(keytype, uri) = vcs.parse_src_key(global_patches_meta['src'])
|
||||||
mirrordir = vcs.ensure_vcs_mirror(self.mirrordir, keytype, uri, global_patches_meta['branch'])
|
mirrordir = vcs.ensure_vcs_mirror(self.mirrordir, keytype, uri, global_patches_meta['branch'])
|
||||||
if args.fetch_patches:
|
if args.fetch_patches:
|
||||||
run_sync(['git', 'fetch'], cwd=mirrordir, log_initiation=False)
|
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:
|
if args.fetch:
|
||||||
git_mirror_args.append('--fetch')
|
git_mirror_args.append('--fetch')
|
||||||
run_sync(git_mirror_args)
|
run_sync(git_mirror_args)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue