[Rpm-maint] [PATCH 1/2] export latest ChangeLog date in rpmbuild env
bmorbach at redhat.com
bmorbach at redhat.com
Wed Aug 13 12:12:16 UTC 2014
From: Benedikt Morbach <bmorbach at redhat.com>
could be used e.g. to set mtime for .py files, to make python builds
reproducible. (possibly also replace the heuristic used to set
timestamps in .jar files, haven't talked to java people about that yet)
---
build/Makefile.am | 1 +
build/build.c | 1 +
build/buildEnv.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
build/rpmbuild_internal.h | 8 ++++++++
4 files changed, 59 insertions(+)
create mode 100644 build/buildEnv.c
diff --git a/build/Makefile.am b/build/Makefile.am
index 03d16c6..9e6a754 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -16,6 +16,7 @@ librpmbuild_la_SOURCES = \
parseFiles.c parsePreamble.c parsePrep.c parseReqs.c parseScript.c \
parseSpec.c reqprov.c rpmfc.c spec.c \
parsePolicies.c policies.c \
+ buildEnv.c \
rpmbuild_internal.h rpmbuild_misc.h
librpmbuild_la_LDFLAGS = -version-info $(rpm_version_info)
diff --git a/build/build.c b/build/build.c
index 04b039c..38d5fb3 100644
--- a/build/build.c
+++ b/build/build.c
@@ -160,6 +160,7 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name,
rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd);
if (!(child = fork())) {
+ setBuildEnvironment(spec);
/* NSPR messes with SIGPIPE, reset to default for the kids */
signal(SIGPIPE, SIG_DFL);
errno = 0;
diff --git a/build/buildEnv.c b/build/buildEnv.c
new file mode 100644
index 0000000..0f9dab2
--- /dev/null
+++ b/build/buildEnv.c
@@ -0,0 +1,49 @@
+/** \ingroup rpmbuild
+ * \file build/buildEnv.c
+ * Set certain environment variables in the for the rpm build process based on the spec file
+ */
+
+#include <stdlib.h>
+#include <inttypes.h>
+#include <math.h>
+
+#include <rpm/rpmtypes.h>
+#include <rpm/header.h>
+#include <rpm/rpmtd.h>
+#include <rpm/rpmbuild.h>
+#include "build/rpmbuild_internal.h"
+
+static char * uint32tostring(uint32_t number) {
+ char * string = NULL;
+ size_t len = 2;
+
+ len = (ceil(log10(number)) + 1) * sizeof(char);
+ string = malloc(len);
+ snprintf(string, len, "%" PRIu32, number);
+
+ return string;
+}
+
+static char * getChangelogTime(rpmSpec spec) {
+ uint32_t changelogTime = 0;
+ char * timestring = NULL;
+ rpmtd times;
+
+ if (headerGet(rpmSpecSourceHeader(spec), RPMTAG_CHANGELOGTIME, ×, HEADERGET_DEFAULT)) {
+ if (times.count >= 1)
+ changelogTime = ((uint32_t*)times.data)[0];
+ }
+
+ timestring = uint32tostring(changelogTime);
+
+ return timestring;
+}
+
+void setBuildEnvironment(rpmSpec spec) {
+ char * timestring = getChangelogTime(spec);
+
+ setenv("RPM_CHANGELOG_DATE", timestring, 1);
+
+ free(timestring);
+}
+
diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h
index 9d2a280..081117e 100644
--- a/build/rpmbuild_internal.h
+++ b/build/rpmbuild_internal.h
@@ -297,6 +297,14 @@ RPM_GNUC_INTERNAL
int parseExpressionBoolean(const char * expr);
/** \ingroup rpmbuild
+ * Set environment variables for the build.
+ *
+ * @param spec spec file control structure
+ */
+RPM_GNUC_INTERNAL
+void setBuildEnvironment(rpmSpec spec);
+
+/** \ingroup rpmbuild
* Run a build script, assembled from spec file scriptlet section.
*
* @param spec spec file control structure
--
2.0.4
More information about the Rpm-maint
mailing list