Always move built rpms, even under partial failure

When a build command fails (due to a package causing
problems) we potentially have already built a set of
other packages (especially when building is done in
parallel), so even when failure occurs we need to move
the rpms that have been build to the target repository.

Fixes bug 1355442

Change-Id: I9f346e189db964bfd9679d452ba9637192a6697c
This commit is contained in:
Joshua Harlow 2014-08-14 15:21:00 -07:00
parent d55076583b
commit c83be383a7

View File

@ -181,11 +181,14 @@ class YumDependencyHandler(base.DependencyHandler):
if not sh.isdir(target_dir): if not sh.isdir(target_dir):
sh.mkdirslist(target_dir, tracewriter=self.tracewriter) sh.mkdirslist(target_dir, tracewriter=self.tracewriter)
if not sh.isdir(source_dir): if not sh.isdir(source_dir):
return return 0
moved = 0
for filename in sh.listdir(source_dir, recursive=True, files_only=True): for filename in sh.listdir(source_dir, recursive=True, files_only=True):
if not filename.lower().endswith(".rpm"): if not filename.lower().endswith(".rpm"):
continue continue
sh.move(filename, target_dir, force=True) sh.move(filename, target_dir, force=True)
moved += 1
return moved
def build_binary(self): def build_binary(self):
def is_src_rpm(path): def is_src_rpm(path):
@ -203,6 +206,18 @@ class YumDependencyHandler(base.DependencyHandler):
path_files = sh.listdir(path, filter_func=is_src_rpm) path_files = sh.listdir(path, filter_func=is_src_rpm)
return sorted(path_files) return sorted(path_files)
def move_rpms(repo_name):
repo_dir = sh.joinpths(self.anvil_repo_dir, repo_name)
search_dirs = [
sh.joinpths(self.rpmbuild_dir, "RPMS"),
]
for sub_dir in sh.listdir(self.rpmbuild_dir, dirs_only=True):
search_dirs.append(sh.joinpths(sub_dir, "RPMS"))
moved = 0
for d in search_dirs:
moved += self._move_rpm_files(d, repo_dir)
return moved
build_requirements = self.requirements.get("build-requires") build_requirements = self.requirements.get("build-requires")
if build_requirements: if build_requirements:
utils.log_iterable(build_requirements, utils.log_iterable(build_requirements,
@ -226,21 +241,25 @@ class YumDependencyHandler(base.DependencyHandler):
rpmbuild_flags += " --define 'usr_only 1'" rpmbuild_flags += " --define 'usr_only 1'"
with sh.remove_before_after(self.rpmbuild_dir): with sh.remove_before_after(self.rpmbuild_dir):
self._create_rpmbuild_subdirs() self._create_rpmbuild_subdirs()
self.py2rpm_helper.build_all_binaries(repo_name, src_repo_dir, try:
rpmbuild_flags, self.tracewriter, self.py2rpm_helper.build_all_binaries(repo_name,
self.jobs) src_repo_dir,
repo_dir = sh.joinpths(self.anvil_repo_dir, repo_name) rpmbuild_flags,
for d in sh.listdir(self.rpmbuild_dir, dirs_only=True): self.tracewriter,
self._move_rpm_files(sh.joinpths(d, "RPMS"), repo_dir) self.jobs)
self._move_rpm_files(sh.joinpths(self.rpmbuild_dir, "RPMS"), repo_dir) finally:
self._create_repo(repo_name) # If we made any rpms (even if a failure happened, make
# sure that we move them to the right target repo).
if move_rpms(repo_name) > 0:
self._create_repo(repo_name)
def _move_srpms(self, repo_name, rpmbuild_dir=None): def _move_srpms(self, repo_name, rpmbuild_dir=None):
if rpmbuild_dir is None: if rpmbuild_dir is None:
rpmbuild_dir = self.rpmbuild_dir rpmbuild_dir = self.rpmbuild_dir
src_repo_name = self.SRC_REPOS[repo_name] src_repo_name = self.SRC_REPOS[repo_name]
src_repo_dir = sh.joinpths(self.anvil_repo_dir, src_repo_name) src_repo_dir = sh.joinpths(self.anvil_repo_dir, src_repo_name)
self._move_rpm_files(sh.joinpths(rpmbuild_dir, "SRPMS"), src_repo_dir) return self._move_rpm_files(sh.joinpths(rpmbuild_dir, "SRPMS"),
src_repo_dir)
def _create_repo(self, repo_name): def _create_repo(self, repo_name):
repo_dir = sh.joinpths(self.anvil_repo_dir, repo_name) repo_dir = sh.joinpths(self.anvil_repo_dir, repo_name)