summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2019-11-11 12:27:14 +0200
committerPanu Matilainen <pmatilai@redhat.com>2019-11-18 12:46:29 +0200
commit6bf37ce21be543e0bc6cc4d161876a3826371696 (patch)
treeea2805ee7b1b59dc0ba185a6d2b38e2b9d638d58
parenta0f691b4028c23a3ed578a670660def0d5d9abd4 (diff)
downloadrpm-6bf37ce21be543e0bc6cc4d161876a3826371696.tar.gz
Only calculate buildhost and buildtime during an actual build
Commit fa303d5ba6bef5b4a44b884c6dadadc27b594caa moved buildhost and buildtime calculation out of the package generation to early spec initialization, but this broke reproducable builds: if buildtime is to be set from changelog, changelog needs to be parsed first. So either we need to do it twice or we need to do it right, and besides avoiding duplication, conceptually these values are only meaningful during a build and not a parse, so this restores that part of the original code while keeping things thread-safe. Fixes: #932 (cherry picked from commit d16b082354ad9defbdc85e9c60c7105eecb76464)
-rw-r--r--build/build.c49
-rw-r--r--build/spec.c50
2 files changed, 49 insertions, 50 deletions
diff --git a/build/build.c b/build/build.c
index d6f418793..e50c3784e 100644
--- a/build/build.c
+++ b/build/build.c
@@ -7,6 +7,8 @@
#include <errno.h>
#include <sys/wait.h>
+#include <netdb.h>
+#include <time.h>
#include <rpm/rpmlog.h>
#include <rpm/rpmfileutil.h>
@@ -16,6 +18,50 @@
#include "debug.h"
+static rpm_time_t getBuildTime(void)
+{
+ rpm_time_t buildTime = 0;
+ char *srcdate;
+ time_t epoch;
+ char *endptr;
+
+ srcdate = getenv("SOURCE_DATE_EPOCH");
+ if (srcdate && rpmExpandNumeric("%{?use_source_date_epoch_as_buildtime}")) {
+ errno = 0;
+ epoch = strtol(srcdate, &endptr, 10);
+ if (srcdate == endptr || *endptr || errno != 0)
+ rpmlog(RPMLOG_ERR, _("unable to parse SOURCE_DATE_EPOCH\n"));
+ else
+ buildTime = (int32_t) epoch;
+ } else
+ buildTime = (int32_t) time(NULL);
+
+ return buildTime;
+}
+
+static char * buildHost(void)
+{
+ char* hostname;
+ struct hostent *hbn;
+ char *bhMacro;
+
+ bhMacro = rpmExpand("%{?_buildhost}", NULL);
+ if (strcmp(bhMacro, "") != 0) {
+ rasprintf(&hostname, "%s", bhMacro);
+ } else {
+ hostname = rcalloc(1024, sizeof(*hostname));
+ (void) gethostname(hostname, 1024);
+ hbn = gethostbyname(hostname);
+ if (hbn)
+ strcpy(hostname, hbn->h_name);
+ else
+ rpmlog(RPMLOG_WARNING,
+ _("Could not canonicalize hostname: %s\n"), hostname);
+ }
+ free(bhMacro);
+ return(hostname);
+}
+
/**
*/
static rpmRC doRmSource(rpmSpec spec)
@@ -260,6 +306,9 @@ static rpmRC buildSpec(rpmts ts, BTA_t buildArgs, rpmSpec spec, int what)
}
}
+ spec->buildTime = getBuildTime();
+ spec->buildHost = buildHost();
+
/* XXX TODO: rootDir is only relevant during build, eliminate from spec */
spec->rootDir = buildArgs->rootdir;
if (!spec->recursing && spec->BACount) {
diff --git a/build/spec.c b/build/spec.c
index bf09c5a5c..6d402319f 100644
--- a/build/spec.c
+++ b/build/spec.c
@@ -5,8 +5,6 @@
#include "system.h"
#include <errno.h>
-#include <netdb.h>
-#include <time.h>
#include <rpm/header.h>
#include <rpm/rpmds.h>
@@ -199,60 +197,12 @@ rpmds * packageDependencies(Package pkg, rpmTagVal tag)
return NULL;
}
-static rpm_time_t getBuildTime(void)
-{
- rpm_time_t buildTime = 0;
- char *srcdate;
- time_t epoch;
- char *endptr;
-
- srcdate = getenv("SOURCE_DATE_EPOCH");
- if (srcdate && rpmExpandNumeric("%{?use_source_date_epoch_as_buildtime}")) {
- errno = 0;
- epoch = strtol(srcdate, &endptr, 10);
- if (srcdate == endptr || *endptr || errno != 0)
- rpmlog(RPMLOG_ERR, _("unable to parse SOURCE_DATE_EPOCH\n"));
- else
- buildTime = (int32_t) epoch;
- } else
- buildTime = (int32_t) time(NULL);
-
- return buildTime;
-}
-
-static char * buildHost(void)
-{
- char* hostname;
- struct hostent *hbn;
- char *bhMacro;
-
- bhMacro = rpmExpand("%{?_buildhost}", NULL);
- if (strcmp(bhMacro, "") != 0) {
- rasprintf(&hostname, "%s", bhMacro);
- } else {
- hostname = rcalloc(1024, sizeof(*hostname));
- (void) gethostname(hostname, 1024);
- hbn = gethostbyname(hostname);
- if (hbn)
- strcpy(hostname, hbn->h_name);
- else
- rpmlog(RPMLOG_WARNING,
- _("Could not canonicalize hostname: %s\n"), hostname);
- }
- free(bhMacro);
- return(hostname);
-}
-
-
rpmSpec newSpec(void)
{
rpmSpec spec = xcalloc(1, sizeof(*spec));
spec->specFile = NULL;
- spec->buildHost = buildHost();
- spec->buildTime = getBuildTime();
-
spec->fileStack = NULL;
spec->lbufSize = BUFSIZ * 10;
spec->lbuf = xmalloc(spec->lbufSize);