tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH] pbulk: Report failed stage



The attached patch aims to fix

PR pkg/58992: pbulk machine-readable report should say which stage
failed
https://gnats.NetBSD.org/58992

which will enable, e.g., the bulk tracker to put links to the log of
the stage that failed, while avoiding broken links to the logs of
subsequent stages which don't exist without requiring a bunch of
background HTTP requests to the builder origin on each page load:

https://github.com/bsiegert/BulkTracker/issues/75

I will hold off on this until after the branch, but in the mean time,
review and testing welcome!
From b2274629f382ff6169622e8d09e213ee5b44b1e6 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Sun, 16 Mar 2025 23:28:12 +0000
Subject: [PATCH] pkgtools/pbulk: Update to 0.77.

New property BUILD_FAILURE_STAGE in the machine-readable bulk report
specifies which stage failed, which is currently available directly
only through the human-readable HTML report or indirectly by querying
for the log files themselves, which is troublesome for, e.g., the
bulk tracker or other tools to produce useful links to the failure
log.

The logic in create-report.awk is a little repetitive but matches
what create-report-html.awk does.  We could do it instead with
system("test -f ...") but a few extra conditionals in awk is probably
cheaper than a few extra fork/exec/wait cycles, and this is run tens
of thousands of times per report so it could make a difference.

PR pkg/58992: pbulk machine-readable report should say which stage
failed
---
 pkgtools/pbulk/Makefile                       |  2 +-
 .../files/pbulk/scripts/create-report.awk     | 53 +++++++++++++++++++
 pkgtools/pbulk/files/pbulk/scripts/report     |  2 +-
 3 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/pkgtools/pbulk/Makefile b/pkgtools/pbulk/Makefile
index 8cc9e1d73419..0a76174bdb05 100644
--- a/pkgtools/pbulk/Makefile
+++ b/pkgtools/pbulk/Makefile
@@ -1,6 +1,6 @@
 # $NetBSD: Makefile,v 1.94 2025/01/23 15:05:41 wiz Exp $
 
-PKGNAME=	pbulk-0.76
+PKGNAME=	pbulk-0.77
 COMMENT=	Modular bulk build framework
 
 .include "../../pkgtools/pbulk/Makefile.common"
diff --git a/pkgtools/pbulk/files/pbulk/scripts/create-report.awk b/pkgtools/pbulk/files/pbulk/scripts/create-report.awk
index b496ac2eab23..e20a8fc9a517 100755
--- a/pkgtools/pbulk/files/pbulk/scripts/create-report.awk
+++ b/pkgtools/pbulk/files/pbulk/scripts/create-report.awk
@@ -30,8 +30,57 @@
 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 # SUCH DAMAGE.
 
+function build_failure_stage(PKGNAME,
+    cmd,
+    has_pre_clean, has_depends, has_checksum, has_configure, has_build,
+    has_install, has_package, has_clean, has_deinstall) {
+	cmd = "ls " log_dir "/" PKGNAME " 2>/dev/null"
+	while ((cmd | getline) > 0) {
+		if ($0 == "pre-clean.log")
+			has_pre_clean = 1
+		else if ($0 == "depends.log")
+			has_depends = 1
+		else if ($0 == "checksum.log")
+			has_checksum = 1
+		else if ($0 == "configure.log")
+			has_configure = 1
+		else if ($0 == "build.log")
+			has_build = 1
+		else if ($0 == "install.log")
+			has_install = 1
+		else if ($0 == "package.log")
+			has_package = 1
+		else if ($0 == "clean.log")
+			has_clean = 1
+		else if ($0 == "deinstall.log")
+			has_deinstall = 1
+	}
+	close(cmd)
+
+	if (has_deinstall)
+		return "deinstall"
+	else if (has_clean)
+		return "clean"
+	else if (has_package)
+		return "package"
+	else if (has_install)
+		return "install"
+	else if (has_build)
+		return "build"
+	else if (has_configure)
+		return "configure"
+	else if (has_checksum)
+		return "checksum"
+	else if (has_depends)
+		return "depends"
+	else if (has_pre_clean)
+		return "pre-clean"
+	return ""
+}
+
 BEGIN {
 	meta_dir = ARGV[1]
+	log_dir = ARGV[2]
 	pbuild_file = meta_dir "/pbuild"
 	presolve_file = meta_dir "/presolve"
 	full_pbuild_file = meta_dir "/report"
@@ -84,6 +133,10 @@ BEGIN {
 		print pkg[p] > full_pbuild_file
 		print "PKG_DEPTH=" depth[p] > full_pbuild_file
 		print "BUILD_STATUS=" status[p] > full_pbuild_file
+		if (status[p] == "failed") {
+			print "BUILD_FAILURE_STAGE=" build_failure_stage(p) \
+			    > full_pbuild_file
+		}
 	}
 	close(full_pbuild_file)
 }
diff --git a/pkgtools/pbulk/files/pbulk/scripts/report b/pkgtools/pbulk/files/pbulk/scripts/report
index e207018ae89f..c00f55f9d06c 100755
--- a/pkgtools/pbulk/files/pbulk/scripts/report
+++ b/pkgtools/pbulk/files/pbulk/scripts/report
@@ -41,7 +41,7 @@ if [ "${config_version}" != "@PBULK_CONFIG_VERSION@" ]; then
 fi
 
 echo "Build reports..."
-${report_script} ${loc}
+${report_script} ${loc} ${bulklog}
 ${bzip2} -zc ${loc}/report > ${loc}/report.bz2
 ${report_html_script} ${loc} ${bulklog}
 ${report_txt_script} ${loc}


Home | Main Index | Thread Index | Old Index