summaryrefslogtreecommitdiffstats
path: root/rpmci/rpmci_srpm_builder_main.py
diff options
context:
space:
mode:
Diffstat (limited to 'rpmci/rpmci_srpm_builder_main.py')
-rw-r--r--rpmci/rpmci_srpm_builder_main.py77
1 files changed, 46 insertions, 31 deletions
diff --git a/rpmci/rpmci_srpm_builder_main.py b/rpmci/rpmci_srpm_builder_main.py
index 8e8c1ee..6ca7195 100644
--- a/rpmci/rpmci_srpm_builder_main.py
+++ b/rpmci/rpmci_srpm_builder_main.py
@@ -89,6 +89,18 @@ class SRPMBuilder(object):
return True
shutil.rmtree(tmpdir)
return False
+
+ def _targets_for_vcs_url(self, url):
+ targets = []
+ for iter_target,(fedora_vcs, upstream_vcs) in self._target_vcs.iteritems():
+ fedora_url = fedora_vcs.get_url_string()
+ is_fedora = (url == fedora_url)
+ if not is_fedora:
+ upstream_url = upstream_vcs.get_url_string()
+ if not url == upstream_url:
+ continue
+ targets.append(iter_target)
+ return targets
def _on_vcs_message(self, q, messages):
msg_list = list(messages)
@@ -101,43 +113,46 @@ class SRPMBuilder(object):
q.consume(msg)
logging.debug("Creating SRPMs for VCS urls: %r" % (updated_vcs_urls, ))
+
+ # This is a bit gross; we find the module-os pairs we need to rebuild,
+ # disregarding architecture. Really, we should change BuildTarget to
+ # just be module name, and have it be scoped to artifact.
+ non_arch_os_modules = set()
+ for url in updated_vcs_urls:
+ targets = self._targets_for_vcs_url(url)
+ if len(targets) == 0:
+ logging.warn("Couldn't find target for VCS url %r" % (url, ))
+ continue
+ non_arch_os_modules.add((targets[0].module, targets[0].os))
+
work_dir = tempfile.mkdtemp('.tmp', 'srpm-builder')
updated_srpms = set()
updated_srpm_names = set()
- for url in updated_vcs_urls:
- if srpm in updated_srpms:
- continue
- srpm = self._create_srpm_for_updated_vcs_url(work_dir, url)
- updated_srpms.add(srpm)
- updated_srpm_names.add(rpmutils.get_rpm_name(os.path.basename(srpm)))
+ for (iter_module, iter_os) in non_arch_os_modules:
+ found = False
+ # Now find a target (disregarding arch) for each one, which gives us a ref
+ # info the respective VCSes.
+ for target,(fedora_vcs, upstream_vcs) in self._target_vcs.iteritems():
+ if target.module == iter_module and target.os == iter_os:
+ srpm = self._create_srpm(work_dir, target.module, target.os, fedora_vcs, upstream_vcs)
+ updated_srpms.add(srpm)
+ updated_srpm_names.add(rpmutils.get_rpm_name(os.path.basename(srpm)))
+ found = True
+ break
+ assert found
+
commitid = self._srcrepo.commit_sync(updated_srpms)
logging.info("New repository revision %d updates SRPMs=%r" % (commitid, updated_srpm_names))
shutil.rmtree(work_dir)
self._srpm_msgqueue.append(msgqueue.Message(None, {'type': 'srpm'}, {'version': commitid}))
logging.debug("Processed %d messages successfully" % (num_msgs, ))
- def _create_srpm_for_updated_vcs_url(self, work_dir, url):
- is_fedora = False
- target = None
- valid_urls = []
- for iter_target,(fedora_vcs, upstream_vcs) in self._target_vcs.iteritems():
- fedora_url = fedora_vcs.get_url_string()
- is_fedora = (url == fedora_url)
- if not is_fedora:
- upstream_url = upstream_vcs.get_url_string()
- if not url == upstream_url:
- valid_urls.append(upstream_url)
- continue
- target = iter_target
- break
- assert target is not None, ("Couldn't find target for url %r; valid=%r" % (url, valid_urls))
- (fedora_vcs, upstream_vcs) = self._target_vcs[target]
-
- logging.debug("Creating new SRPM for %r in %r" % (target.module, work_dir))
- fedora_dir = os.path.join(work_dir, target.module)
+ def _create_srpm(self, work_dir, module, os_name, fedora_vcs, upstream_vcs):
+ logging.debug("Creating new SRPM for %s-%s in %r" % (module, os_name, work_dir))
+ fedora_dir = os.path.join(work_dir, module)
fedora_vcs.export_directory('HEAD', fedora_dir, sys.stderr)
- specname = target.module + '.spec'
+ specname = module + '.spec'
target_spec_path = os.path.join(fedora_dir, specname)
target_spec_obj = spec.Spec(target_spec_path)
@@ -149,7 +164,7 @@ class SRPMBuilder(object):
filename = os.path.basename(rpmpath)
assert filename.endswith('.src.rpm')
name = rpmutils.get_rpm_name(filename)
- if name == target.module:
+ if name == module:
orig_spec_path = os.path.join(work_dir, specname)
if not self._extract_specfile_from_srpm(rpmpath, orig_spec_path):
raise ValueError("Failed to extract specfile from %r" % (rpmpath, ))
@@ -163,7 +178,7 @@ class SRPMBuilder(object):
orig_version = orig_spec_obj.get_key('Version')
orig_release = orig_spec_obj.get_key('Release')
- logging.info("Will update %r from version=%r release=%r" % (target.module, orig_version, orig_release))
+ logging.info("Will update %r from version=%r release=%r" % (module, orig_version, orig_release))
target_spec_obj.set_key('Version', orig_version)
target_spec_obj.set_key('Release', orig_release)
@@ -174,18 +189,18 @@ class SRPMBuilder(object):
args = [os.path.abspath(os.path.join(exec_basedir, 'rpmci-spec-vcs')),
'--vcsdir=' + upstream_vcs.get_directory(),
'set-revision', 'HEAD']
- subtask.spawn_sync('rpmci-spec-vcs-%s' % (target.module, ),
+ subtask.spawn_sync('rpmci-spec-vcs-%s' % (module, ),
args, cwd=fedora_dir)
target_spec_obj = spec.Spec(target_spec_path)
new_version = target_spec_obj.get_key('Version')
new_release = target_spec_obj.get_key('Release')
- logging.info("Updated %r to version=%r release=%r" % (target.module, new_version, new_release))
+ logging.info("Updated %r to version=%r release=%r" % (module, new_version, new_release))
args = ['rpmbuild']
args.extend(self._get_base_rpmbuild_args(fedora_dir))
args.extend(['-bs', specname])
- subtask.spawn_sync('rpmbuild-srpm-%s' % (target.module, ),
+ subtask.spawn_sync('rpmbuild-srpm-%s' % (module, ),
args, cwd=fedora_dir)
srpm_path = None
srpm_basename = None