diff options
Diffstat (limited to 'build/build.c')
-rw-r--r-- | build/build.c | 49 |
1 files changed, 49 insertions, 0 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) { |