Only calculate buildhost and buildtime during an actual build
Commit fa303d5ba6
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
This commit is contained in:
parent
2bef1d463e
commit
d16b082354
|
@ -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) {
|
||||
|
|
50
build/spec.c
50
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);
|
||||
|
|
Loading…
Reference in New Issue