[projects/pld-builder.new] rpm_builder: stop a build when its request is skipped
arekm
arekm at pld-linux.org
Sun Nov 15 01:57:56 CET 2026
commit eda6f4d5bf132e3dd0d7cff6f80b7023fc0402ab
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Nov 14 22:51:24 2026 +0100
rpm_builder: stop a build when its request is skipped
rpmbuild ran to its end, hours for some packages, however early the skip
came. chroot.run() can now be stopped halfway, and rpm_builder stops
rpmbuild within seconds of the flag reaching the builder. Installing
BuildRequires is not stopped; the flag is checked after it.
PLD_Builder/chroot.py | 26 +++++++++++++++++++++++---
PLD_Builder/rpm_builder.py | 35 ++++++++++++++++++++++-------------
2 files changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/PLD_Builder/chroot.py b/PLD_Builder/chroot.py
index f89d7d0..10eea8a 100644
--- a/PLD_Builder/chroot.py
+++ b/PLD_Builder/chroot.py
@@ -49,12 +49,32 @@ def popen(cmd, user = "builder", mode = "r", encoding = None, nonet=True):
p = subprocess.Popen(command(cmd, user, nonet=nonet), shell=True, stdin=subprocess.PIPE, close_fds=True, encoding=encoding)
return Pipe(p, p.stdin)
-def run(cmd, user = "builder", logfile = None, nonet=True):
- """Run cmd in the chroot as user, its output appended to logfile; the exit code, negative for a signal"""
+# seconds between asking stop() of run() whether to go on
+stop_check = 15
+
+def run(cmd, user = "builder", logfile = None, nonet=True, stop=None):
+ """Run cmd in the chroot as user, its output appended to logfile; the exit code, negative for a signal.
+ Meanwhile stop() is asked every stop_check seconds: once true, every process of user is killed"""
+ # kill_all() refuses root: refused here before cmd runs
+ assert stop is None or user != "root"
c = command(cmd, user, nostdin=True, nonet=nonet)
if logfile != None:
c = f"{c} >> {logfile} 2>&1"
- return subprocess.run(c, check=False, shell=True, stdout=subprocess.DEVNULL).returncode
+ p = subprocess.Popen(c, shell=True, stdout=subprocess.DEVNULL)
+ while True:
+ try:
+ return p.wait(timeout=stop_check if stop else None)
+ except subprocess.TimeoutExpired:
+ try:
+ stopping = stop()
+ except BaseException:
+ # cmd is not left running with nobody to stop it
+ kill_all(user, logfile)
+ p.wait()
+ raise
+ if stopping:
+ kill_all(user, logfile)
+ return p.wait()
def kill_all(user = "builder", logfile = None):
"""Kill every process of user"""
diff --git a/PLD_Builder/rpm_builder.py b/PLD_Builder/rpm_builder.py
index bfbff36..69874e4 100644
--- a/PLD_Builder/rpm_builder.py
+++ b/PLD_Builder/rpm_builder.py
@@ -220,6 +220,10 @@ def build_rpm(r, b):
install.cleanup_stale_packages(b)
if ("no-install-br" not in r.flags) and not install.install_br(r, b):
res = "FAIL_DEPS_INSTALL"
+ # installing BuildRequires is not stopped halfway: it changes the rpm database
+ if not res and skip_requested(r):
+ b.log_line("build skipped due to src builder request")
+ res = "SKIP_REQUESTED"
if not res:
max_jobs = max(min(int(os.sysconf('SC_NPROCESSORS_ONLN') + 1), config.max_jobs), 1)
if r.max_jobs > 0:
@@ -230,23 +234,28 @@ def build_rpm(r, b):
f"--define '_pld_builder 1' {b.rpmbuild_opts()} {b.get_topdir()}/{b.spec}"
b.log_line(f"building RPM using: {cmd}")
begin_time = time.time()
- res = chroot.run(cmd, logfile = b.logfile)
+ res = chroot.run(cmd, logfile = b.logfile, stop = lambda: skip_requested(r))
end_time = time.time()
b.log_line(f"ended at: {time.asctime()}, done in {datetime.timedelta(0, end_time - begin_time)}")
- files = util.collect_files(b.logfile, basedir = b.get_topdir())
- if len(files) > 0:
- r.chroot_files.extend(files)
+ if skip_requested(r):
+ b.log_line("build stopped due to src builder request")
+ res = "SKIP_REQUESTED"
+ b.files = []
else:
- b.log_line("error: No files produced.")
- if res or not files:
- # the status names the rpm section the build stopped in
- last_section = util.find_last_section(b.logfile)
- if last_section == None:
- res = "FAIL"
+ files = util.collect_files(b.logfile, basedir = b.get_topdir())
+ if len(files) > 0:
+ r.chroot_files.extend(files)
else:
- res = f"FAIL_{last_section.upper()}"
- # the rpms a failed build managed to write stay in the chroot: they are removed with the rest
- b.files = [] if res else files
+ b.log_line("error: No files produced.")
+ if res or not files:
+ # the status names the rpm section the build stopped in
+ last_section = util.find_last_section(b.logfile)
+ if last_section == None:
+ res = "FAIL"
+ else:
+ res = f"FAIL_{last_section.upper()}"
+ # the rpms a failed build managed to write stay in the chroot: they are removed with the rest
+ b.files = [] if res else files
# cleanup tmp and build files
chroot.run("""
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/eda6f4d5bf132e3dd0d7cff6f80b7023fc0402ab
More information about the pld-cvs-commit
mailing list