Panu Matilainen c9c421
From 3a510926449f1dd779a2933dfaa17de3d03a4ea4 Mon Sep 17 00:00:00 2001
Panu Matilainen c9c421
Message-Id: <3a510926449f1dd779a2933dfaa17de3d03a4ea4.1566556207.git.pmatilai@redhat.com>
Panu Matilainen c9c421
In-Reply-To: <ad4673589428db6e3b9fecd6f151eb899500336d.1566556207.git.pmatilai@redhat.com>
Panu Matilainen c9c421
References: <ad4673589428db6e3b9fecd6f151eb899500336d.1566556207.git.pmatilai@redhat.com>
Panu Matilainen c9c421
From: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen c9c421
Date: Thu, 15 Aug 2019 14:10:07 +0300
Panu Matilainen c9c421
Subject: [PATCH 2/3] Restore strict order of build scriptlet stdout/stderr
Panu Matilainen c9c421
 output (#794)
Panu Matilainen c9c421
Panu Matilainen c9c421
Commit 18e8f4e9b2dd170d090843adf5b5084658d68cf7 and related changes
Panu Matilainen c9c421
caused us to capture and re-emit stdout of all build scriptlets,
Panu Matilainen c9c421
whether we actually use the output for anything or not. Besides doing
Panu Matilainen c9c421
a whole bunch of work for nothing, this can disrupt the output of
Panu Matilainen c9c421
build scriptlets by making the output jerky and out of order, at least
Panu Matilainen c9c421
inside mock and other tools which in turn grab rpm output. This makes
Panu Matilainen c9c421
troubleshooting failed builds unnecessarily hard for no good reason.
Panu Matilainen c9c421
Panu Matilainen c9c421
Handle the whole thing in a different way: on regular builds, don't
Panu Matilainen c9c421
capture anything where we don't actually need to. This restores the
Panu Matilainen c9c421
natural flow of output. We still need to somehow handle quiet builds
Panu Matilainen c9c421
though, and we can't use redirect to /dev/null from %___build_pre like
Panu Matilainen c9c421
we used to, because dynamic buildrequires need to provide output even
Panu Matilainen c9c421
on quiet builds. So somewhat counter-intuitively, we need to capture
Panu Matilainen c9c421
the output in order to discard it.
Panu Matilainen c9c421
Panu Matilainen c9c421
Closes: #794
Panu Matilainen c9c421
---
Panu Matilainen c9c421
 build/build.c | 19 +++++++++++--------
Panu Matilainen c9c421
 1 file changed, 11 insertions(+), 8 deletions(-)
Panu Matilainen c9c421
Panu Matilainen c9c421
diff --git a/build/build.c b/build/build.c
Panu Matilainen c9c421
index 3887457d3..dc196090f 100644
Panu Matilainen c9c421
--- a/build/build.c
Panu Matilainen c9c421
+++ b/build/build.c
Panu Matilainen c9c421
@@ -60,7 +60,6 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name,
Panu Matilainen c9c421
     int argc = 0;
Panu Matilainen c9c421
     const char **argv = NULL;
Panu Matilainen c9c421
     FILE * fp = NULL;
Panu Matilainen c9c421
-    FILE * cmdOut = rpmIsVerbose() ? stdout : NULL;
Panu Matilainen c9c421
 
Panu Matilainen c9c421
     FD_t fd = NULL;
Panu Matilainen c9c421
     rpmRC rc = RPMRC_FAIL; /* assume failure */
Panu Matilainen c9c421
@@ -156,7 +155,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name,
Panu Matilainen c9c421
 
Panu Matilainen c9c421
     rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd);
Panu Matilainen c9c421
     if (rpmfcExec((ARGV_const_t)argv, NULL, sb_stdoutp, 1,
Panu Matilainen c9c421
-		  spec->buildSubdir, cmdOut)) {
Panu Matilainen c9c421
+		  spec->buildSubdir, NULL)) {
Panu Matilainen c9c421
 	rpmlog(RPMLOG_ERR, _("Bad exit status from %s (%s)\n"),
Panu Matilainen c9c421
 		scriptName, name);
Panu Matilainen c9c421
 	goto exit;
Panu Matilainen c9c421
@@ -242,6 +241,9 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
Panu Matilainen c9c421
     int missing_buildreqs = 0;
Panu Matilainen c9c421
     int test = (what & RPMBUILD_NOBUILD);
Panu Matilainen c9c421
     char *cookie = buildArgs->cookie ? xstrdup(buildArgs->cookie) : NULL;
Panu Matilainen c9c421
+    /* handle quiet mode by capturing the output into a sink buffer */
Panu Matilainen c9c421
+    StringBuf sink = NULL;
Panu Matilainen c9c421
+    StringBuf *sbp = rpmIsVerbose() ? NULL : &sin;;
Panu Matilainen c9c421
 
Panu Matilainen c9c421
     if (rpmExpandNumeric("%{?source_date_epoch_from_changelog}") &&
Panu Matilainen c9c421
 	getenv("SOURCE_DATE_EPOCH") == NULL) {
Panu Matilainen c9c421
@@ -292,7 +294,7 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
Panu Matilainen c9c421
 
Panu Matilainen c9c421
 	if ((what & RPMBUILD_PREP) &&
Panu Matilainen c9c421
 	    (rc = doScript(spec, RPMBUILD_PREP, "%prep",
Panu Matilainen c9c421
-			   getStringBuf(spec->prep), test, NULL)))
Panu Matilainen c9c421
+			   getStringBuf(spec->prep), test, sbp)))
Panu Matilainen c9c421
 		goto exit;
Panu Matilainen c9c421
 
Panu Matilainen c9c421
 	if (what & RPMBUILD_BUILDREQUIRES)
Panu Matilainen c9c421
@@ -321,17 +323,17 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
Panu Matilainen c9c421
 
Panu Matilainen c9c421
 	if ((what & RPMBUILD_BUILD) &&
Panu Matilainen c9c421
 	    (rc = doScript(spec, RPMBUILD_BUILD, "%build",
Panu Matilainen c9c421
-			   getStringBuf(spec->build), test, NULL)))
Panu Matilainen c9c421
+			   getStringBuf(spec->build), test, sbp)))
Panu Matilainen c9c421
 		goto exit;
Panu Matilainen c9c421
 
Panu Matilainen c9c421
 	if ((what & RPMBUILD_INSTALL) &&
Panu Matilainen c9c421
 	    (rc = doScript(spec, RPMBUILD_INSTALL, "%install",
Panu Matilainen c9c421
-			   getStringBuf(spec->install), test, NULL)))
Panu Matilainen c9c421
+			   getStringBuf(spec->install), test, sbp)))
Panu Matilainen c9c421
 		goto exit;
Panu Matilainen c9c421
 
Panu Matilainen c9c421
 	if ((what & RPMBUILD_CHECK) &&
Panu Matilainen c9c421
 	    (rc = doScript(spec, RPMBUILD_CHECK, "%check",
Panu Matilainen c9c421
-			   getStringBuf(spec->check), test, NULL)))
Panu Matilainen c9c421
+			   getStringBuf(spec->check), test, sbp)))
Panu Matilainen c9c421
 		goto exit;
Panu Matilainen c9c421
 
Panu Matilainen c9c421
 	if ((what & RPMBUILD_PACKAGESOURCE) &&
Panu Matilainen c9c421
@@ -358,11 +360,11 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
Panu Matilainen c9c421
 	
Panu Matilainen c9c421
 	if ((what & RPMBUILD_CLEAN) &&
Panu Matilainen c9c421
 	    (rc = doScript(spec, RPMBUILD_CLEAN, "%clean",
Panu Matilainen c9c421
-			   getStringBuf(spec->clean), test, NULL)))
Panu Matilainen c9c421
+			   getStringBuf(spec->clean), test, sbp)))
Panu Matilainen c9c421
 		goto exit;
Panu Matilainen c9c421
 
Panu Matilainen c9c421
 	if ((what & RPMBUILD_RMBUILD) &&
Panu Matilainen c9c421
-	    (rc = doScript(spec, RPMBUILD_RMBUILD, "--clean", NULL, test, NULL)))
Panu Matilainen c9c421
+	    (rc = doScript(spec, RPMBUILD_RMBUILD, "--clean", NULL, test, sbp)))
Panu Matilainen c9c421
 		goto exit;
Panu Matilainen c9c421
     }
Panu Matilainen c9c421
 
Panu Matilainen c9c421
@@ -373,6 +375,7 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
Panu Matilainen c9c421
 	(void) unlink(spec->specFile);
Panu Matilainen c9c421
 
Panu Matilainen c9c421
 exit:
Panu Matilainen c9c421
+    freeStringBuf(sink);
Panu Matilainen c9c421
     free(cookie);
Panu Matilainen c9c421
     spec->rootDir = NULL;
Panu Matilainen c9c421
     if (rc != RPMRC_OK && rc != RPMRC_MISSINGBUILDREQUIRES &&
Panu Matilainen c9c421
-- 
Panu Matilainen c9c421
2.21.0
Panu Matilainen c9c421