summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kanavin <alexander.kanavin@linux.intel.com>2017-06-12 17:58:05 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-13 10:46:33 +0100
commit84e0bb8d936f1b9094c9d5a92825e9d22e1bc7e3 (patch)
tree544403ae051a4bff263893ea8cf338e3de3caf23
parent1847d2aa40aa942b14e901634121c1bd3171c9be (diff)
downloadpoky-84e0bb8d936f1b9094c9d5a92825e9d22e1bc7e3.tar.gz
rpm: run binary package generation via thread pools
This greatly reduces build times when there is a large amount of small rpm packages to produce. The patches are rather invasive, and so will be submitted upstream. (From OE-Core rev: 964a6eb4732df462008883c4bb003f801777dfad) Signed-off-by: Alexander Kanavin <alexander.kanavin@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-devtools/rpm/files/0001-Split-binary-package-building-into-a-separate-functi.patch84
-rw-r--r--meta/recipes-devtools/rpm/files/0002-Run-binary-package-creation-via-thread-pools.patch127
-rw-r--r--meta/recipes-devtools/rpm/files/0003-rpmstrpool.c-make-operations-over-string-pools-threa.patch207
-rw-r--r--meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch337
-rw-r--r--meta/recipes-devtools/rpm/rpm_git.bb4
5 files changed, 759 insertions, 0 deletions
diff --git a/meta/recipes-devtools/rpm/files/0001-Split-binary-package-building-into-a-separate-functi.patch b/meta/recipes-devtools/rpm/files/0001-Split-binary-package-building-into-a-separate-functi.patch
new file mode 100644
index 0000000000..6e44f0b7fc
--- /dev/null
+++ b/meta/recipes-devtools/rpm/files/0001-Split-binary-package-building-into-a-separate-functi.patch
@@ -0,0 +1,84 @@
1From 721a660a507d6d062e7aecafad886c643970a5d5 Mon Sep 17 00:00:00 2001
2From: Alexander Kanavin <alex.kanavin@gmail.com>
3Date: Thu, 25 May 2017 18:15:27 +0300
4Subject: [PATCH 1/4] Split binary package building into a separate function
5
6So that it can be run as a thread pool task.
7
8Upstream-Status: Submitted [https://github.com/rpm-software-management/rpm/pull/226]
9Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
10
11---
12 build/pack.c | 33 +++++++++++++++++++++------------
13 1 file changed, 21 insertions(+), 12 deletions(-)
14
15diff --git a/build/pack.c b/build/pack.c
16index 518f4e92a..ccfd614cc 100644
17--- a/build/pack.c
18+++ b/build/pack.c
19@@ -546,18 +546,13 @@ static rpmRC checkPackages(char *pkgcheck)
20 return RPMRC_OK;
21 }
22
23-rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
24+static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int cheating, char** filename)
25 {
26- rpmRC rc;
27- const char *errorString;
28- Package pkg;
29- char *pkglist = NULL;
30-
31- for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
32- char *fn;
33+ const char *errorString;
34+ rpmRC rc = RPMRC_OK;
35
36 if (pkg->fileList == NULL)
37- continue;
38+ return rc;
39
40 if ((rc = processScriptFiles(spec, pkg)))
41 return rc;
42@@ -587,7 +582,7 @@ rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
43 headerGetString(pkg->header, RPMTAG_NAME), errorString);
44 return RPMRC_FAIL;
45 }
46- fn = rpmGetPath("%{_rpmdir}/", binRpm, NULL);
47+ *filename = rpmGetPath("%{_rpmdir}/", binRpm, NULL);
48 if ((binDir = strchr(binRpm, '/')) != NULL) {
49 struct stat st;
50 char *dn;
51@@ -609,14 +604,28 @@ rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
52 free(binRpm);
53 }
54
55- rc = writeRPM(pkg, NULL, fn, NULL);
56+ rc = writeRPM(pkg, NULL, *filename, NULL);
57 if (rc == RPMRC_OK) {
58 /* Do check each written package if enabled */
59- char *pkgcheck = rpmExpand("%{?_build_pkgcheck} ", fn, NULL);
60+ char *pkgcheck = rpmExpand("%{?_build_pkgcheck} ", *filename, NULL);
61 if (pkgcheck[0] != ' ') {
62 rc = checkPackages(pkgcheck);
63 }
64 free(pkgcheck);
65+ }
66+ return rc;
67+}
68+
69+rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
70+{
71+ rpmRC rc;
72+ Package pkg;
73+ char *pkglist = NULL;
74+
75+ for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
76+ char *fn = NULL;
77+ rc = packageBinary(spec, pkg, cookie, cheating, &fn);
78+ if (rc == RPMRC_OK) {
79 rstrcat(&pkglist, fn);
80 rstrcat(&pkglist, " ");
81 }
82--
832.11.0
84
diff --git a/meta/recipes-devtools/rpm/files/0002-Run-binary-package-creation-via-thread-pools.patch b/meta/recipes-devtools/rpm/files/0002-Run-binary-package-creation-via-thread-pools.patch
new file mode 100644
index 0000000000..d10041c2e1
--- /dev/null
+++ b/meta/recipes-devtools/rpm/files/0002-Run-binary-package-creation-via-thread-pools.patch
@@ -0,0 +1,127 @@
1From 513200cf76758de4668312c628d6362bdabfaf4b Mon Sep 17 00:00:00 2001
2From: Alexander Kanavin <alex.kanavin@gmail.com>
3Date: Thu, 25 May 2017 19:30:20 +0300
4Subject: [PATCH 1/3] Run binary package creation via thread pools.
5
6Upstream-Status: Submitted [https://github.com/rpm-software-management/rpm/pull/226]
7Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
8
9---
10 build/pack.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
11 configure.ac | 3 +++
12 2 files changed, 70 insertions(+), 14 deletions(-)
13
14diff --git a/build/pack.c b/build/pack.c
15index ccfd614cc..ed5b9ab4e 100644
16--- a/build/pack.c
17+++ b/build/pack.c
18@@ -616,25 +616,78 @@ static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int ch
19 return rc;
20 }
21
22-rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
23+struct binaryPackageTaskData
24 {
25- rpmRC rc;
26 Package pkg;
27+ char *filename;
28+ rpmRC result;
29+ struct binaryPackageTaskData *next;
30+};
31+
32+static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const char *cookie, int cheating)
33+{
34+ struct binaryPackageTaskData *tasks = NULL;
35+ struct binaryPackageTaskData *task = NULL;
36+ struct binaryPackageTaskData *prev = NULL;
37+
38+ for (Package pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
39+ task = rcalloc(1, sizeof(*task));
40+ task->pkg = pkg;
41+ if (pkg == spec->packages) {
42+ // the first package needs to be processed ahead of others, as they copy
43+ // changelog data from it, and so otherwise data races would happen
44+ task->result = packageBinary(spec, pkg, cookie, cheating, &(task->filename));
45+ rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename);
46+ tasks = task;
47+ }
48+ if (prev != NULL) {
49+ prev->next = task;
50+ }
51+ prev = task;
52+ }
53+
54+ #pragma omp parallel
55+ #pragma omp single
56+ // re-declaring task variable is necessary, or older gcc versions will produce code that segfaults
57+ for (struct binaryPackageTaskData *task = tasks; task != NULL; task = task->next) {
58+ if (task != tasks)
59+ #pragma omp task
60+ {
61+ task->result = packageBinary(spec, task->pkg, cookie, cheating, &(task->filename));
62+ rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename);
63+ }
64+ }
65+
66+ return tasks;
67+}
68+
69+static void freeBinaryPackageTasks(struct binaryPackageTaskData* tasks)
70+{
71+ while (tasks != NULL) {
72+ struct binaryPackageTaskData* next = tasks->next;
73+ rfree(tasks->filename);
74+ rfree(tasks);
75+ tasks = next;
76+ }
77+}
78+
79+rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
80+{
81 char *pkglist = NULL;
82
83- for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
84- char *fn = NULL;
85- rc = packageBinary(spec, pkg, cookie, cheating, &fn);
86- if (rc == RPMRC_OK) {
87- rstrcat(&pkglist, fn);
88- rstrcat(&pkglist, " ");
89- }
90- free(fn);
91- if (rc != RPMRC_OK) {
92- pkglist = _free(pkglist);
93- return rc;
94- }
95+ struct binaryPackageTaskData *tasks = runBinaryPackageTasks(spec, cookie, cheating);
96+
97+ for (struct binaryPackageTaskData *task = tasks; task != NULL; task = task->next) {
98+ if (task->result == RPMRC_OK) {
99+ rstrcat(&pkglist, task->filename);
100+ rstrcat(&pkglist, " ");
101+ } else {
102+ _free(pkglist);
103+ freeBinaryPackageTasks(tasks);
104+ return RPMRC_FAIL;
105+ }
106 }
107+ freeBinaryPackageTasks(tasks);
108
109 /* Now check the package set if enabled */
110 if (pkglist != NULL) {
111diff --git a/configure.ac b/configure.ac
112index a506ec819..59fa0acaf 100644
113--- a/configure.ac
114+++ b/configure.ac
115@@ -17,6 +17,9 @@ AC_DISABLE_STATIC
116
117 PKG_PROG_PKG_CONFIG
118
119+AC_OPENMP
120+RPMCFLAGS="$OPENMP_CFLAGS $RPMCFLAGS"
121+
122 dnl Checks for programs.
123 AC_PROG_CXX
124 AC_PROG_AWK
125--
1262.11.0
127
diff --git a/meta/recipes-devtools/rpm/files/0003-rpmstrpool.c-make-operations-over-string-pools-threa.patch b/meta/recipes-devtools/rpm/files/0003-rpmstrpool.c-make-operations-over-string-pools-threa.patch
new file mode 100644
index 0000000000..c348ae5330
--- /dev/null
+++ b/meta/recipes-devtools/rpm/files/0003-rpmstrpool.c-make-operations-over-string-pools-threa.patch
@@ -0,0 +1,207 @@
1From c80892f17e44331206c8318d53b63bb6a99554d0 Mon Sep 17 00:00:00 2001
2From: Alexander Kanavin <alex.kanavin@gmail.com>
3Date: Tue, 30 May 2017 13:58:30 +0300
4Subject: [PATCH 3/4] rpmstrpool.c: make operations over string pools
5 thread-safe
6
7Otherwise multithreaded rpm building explodes in various ways due
8to data races.
9
10Upstream-Status: Submitted [https://github.com/rpm-software-management/rpm/pull/226]
11Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
12
13---
14 rpmio/rpmstrpool.c | 56 +++++++++++++++++++++++++++++++++++++++++++++---------
15 1 file changed, 47 insertions(+), 9 deletions(-)
16
17diff --git a/rpmio/rpmstrpool.c b/rpmio/rpmstrpool.c
18index 30a57eb10..58ba95a02 100644
19--- a/rpmio/rpmstrpool.c
20+++ b/rpmio/rpmstrpool.c
21@@ -113,6 +113,8 @@ static poolHash poolHashCreate(int numBuckets)
22 return ht;
23 }
24
25+static const char * rpmstrPoolStrNoLock(rpmstrPool pool, rpmsid sid);
26+
27 static void poolHashResize(rpmstrPool pool, int numBuckets)
28 {
29 poolHash ht = pool->hash;
30@@ -120,7 +122,7 @@ static void poolHashResize(rpmstrPool pool, int numBuckets)
31
32 for (int i=0; i<ht->numBuckets; i++) {
33 if (!ht->buckets[i].keyid) continue;
34- unsigned int keyHash = rstrhash(rpmstrPoolStr(pool, ht->buckets[i].keyid));
35+ unsigned int keyHash = rstrhash(rpmstrPoolStrNoLock(pool, ht->buckets[i].keyid));
36 for (unsigned int j=0;;j++) {
37 unsigned int hash = hashbucket(keyHash, j) % numBuckets;
38 if (!buckets[hash].keyid) {
39@@ -149,7 +151,7 @@ static void poolHashAddHEntry(rpmstrPool pool, const char * key, unsigned int ke
40 ht->buckets[hash].keyid = keyid;
41 ht->keyCount++;
42 break;
43- } else if (!strcmp(rpmstrPoolStr(pool, ht->buckets[hash].keyid), key)) {
44+ } else if (!strcmp(rpmstrPoolStrNoLock(pool, ht->buckets[hash].keyid), key)) {
45 return;
46 }
47 }
48@@ -191,7 +193,7 @@ static void poolHashPrintStats(rpmstrPool pool)
49 int maxcollisions = 0;
50
51 for (i=0; i<ht->numBuckets; i++) {
52- unsigned int keyHash = rstrhash(rpmstrPoolStr(pool, ht->buckets[i].keyid));
53+ unsigned int keyHash = rstrhash(rpmstrPoolStrNoLock(pool, ht->buckets[i].keyid));
54 for (unsigned int j=0;;j++) {
55 unsigned int hash = hashbucket(keyHash, i) % ht->numBuckets;
56 if (hash==i) {
57@@ -221,7 +223,7 @@ static void rpmstrPoolRehash(rpmstrPool pool)
58
59 pool->hash = poolHashCreate(sizehint);
60 for (int i = 1; i <= pool->offs_size; i++)
61- poolHashAddEntry(pool, rpmstrPoolStr(pool, i), i);
62+ poolHashAddEntry(pool, rpmstrPoolStrNoLock(pool, i), i);
63 }
64
65 rpmstrPool rpmstrPoolCreate(void)
66@@ -245,6 +247,8 @@ rpmstrPool rpmstrPoolCreate(void)
67
68 rpmstrPool rpmstrPoolFree(rpmstrPool pool)
69 {
70+ #pragma omp critical(rpmstrpool)
71+ {
72 if (pool) {
73 if (pool->nrefs > 1) {
74 pool->nrefs--;
75@@ -260,18 +264,24 @@ rpmstrPool rpmstrPoolFree(rpmstrPool pool)
76 free(pool);
77 }
78 }
79+ }
80 return NULL;
81 }
82
83 rpmstrPool rpmstrPoolLink(rpmstrPool pool)
84 {
85+ #pragma omp critical(rpmstrpool)
86+ {
87 if (pool)
88 pool->nrefs++;
89+ }
90 return pool;
91 }
92
93 void rpmstrPoolFreeze(rpmstrPool pool, int keephash)
94 {
95+ #pragma omp critical(rpmstrpool)
96+ {
97 if (pool && !pool->frozen) {
98 if (!keephash) {
99 pool->hash = poolHashFree(pool->hash);
100@@ -281,16 +291,20 @@ void rpmstrPoolFreeze(rpmstrPool pool, int keephash)
101 pool->offs_alloced * sizeof(*pool->offs));
102 pool->frozen = 1;
103 }
104+ }
105 }
106
107 void rpmstrPoolUnfreeze(rpmstrPool pool)
108 {
109+ #pragma omp critical(rpmstrpool)
110+ {
111 if (pool) {
112 if (pool->hash == NULL) {
113 rpmstrPoolRehash(pool);
114 }
115 pool->frozen = 0;
116 }
117+ }
118 }
119
120 static rpmsid rpmstrPoolPut(rpmstrPool pool, const char *s, size_t slen, unsigned int hash)
121@@ -350,7 +364,7 @@ static rpmsid rpmstrPoolGet(rpmstrPool pool, const char * key, size_t keylen,
122 return 0;
123 }
124
125- s = rpmstrPoolStr(pool, ht->buckets[hash].keyid);
126+ s = rpmstrPoolStrNoLock(pool, ht->buckets[hash].keyid);
127 /* pool string could be longer than keylen, require exact matche */
128 if (strncmp(s, key, keylen) == 0 && s[keylen] == '\0')
129 return ht->buckets[hash].keyid;
130@@ -373,27 +387,31 @@ static inline rpmsid strn2id(rpmstrPool pool, const char *s, size_t slen,
131 rpmsid rpmstrPoolIdn(rpmstrPool pool, const char *s, size_t slen, int create)
132 {
133 rpmsid sid = 0;
134-
135+ #pragma omp critical(rpmstrpool)
136+ {
137 if (s != NULL) {
138 unsigned int hash = rstrnhash(s, slen);
139 sid = strn2id(pool, s, slen, hash, create);
140 }
141+ }
142 return sid;
143 }
144
145 rpmsid rpmstrPoolId(rpmstrPool pool, const char *s, int create)
146 {
147 rpmsid sid = 0;
148-
149+ #pragma omp critical(rpmstrpool)
150+ {
151 if (s != NULL) {
152 size_t slen;
153 unsigned int hash = rstrlenhash(s, &slen);
154 sid = strn2id(pool, s, slen, hash, create);
155 }
156+ }
157 return sid;
158 }
159
160-const char * rpmstrPoolStr(rpmstrPool pool, rpmsid sid)
161+static const char * rpmstrPoolStrNoLock(rpmstrPool pool, rpmsid sid)
162 {
163 const char *s = NULL;
164 if (pool && sid > 0 && sid <= pool->offs_size)
165@@ -401,12 +419,25 @@ const char * rpmstrPoolStr(rpmstrPool pool, rpmsid sid)
166 return s;
167 }
168
169+const char * rpmstrPoolStr(rpmstrPool pool, rpmsid sid)
170+{
171+ const char *s = NULL;
172+ #pragma omp critical(rpmstrpool)
173+ {
174+ s = rpmstrPoolStrNoLock(pool, sid);
175+ }
176+ return s;
177+}
178+
179 size_t rpmstrPoolStrlen(rpmstrPool pool, rpmsid sid)
180 {
181 size_t slen = 0;
182+ #pragma omp critical(rpmstrpool)
183+ {
184 if (pool && sid > 0 && sid <= pool->offs_size) {
185 slen = strlen(pool->offs[sid]);
186 }
187+ }
188 return slen;
189 }
190
191@@ -421,5 +452,12 @@ int rpmstrPoolStreq(rpmstrPool poolA, rpmsid sidA,
192
193 rpmsid rpmstrPoolNumStr(rpmstrPool pool)
194 {
195- return (pool != NULL) ? pool->offs_size : 0;
196+ rpmsid id = 0;
197+ #pragma omp critical(rpmstrpool)
198+ {
199+ if (pool) {
200+ id = pool->offs_size;
201+ }
202+ }
203+ return id;
204 }
205--
2062.11.0
207
diff --git a/meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch b/meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch
new file mode 100644
index 0000000000..64a5651f7e
--- /dev/null
+++ b/meta/recipes-devtools/rpm/files/0004-build-pack.c-remove-static-local-variables-from-buil.patch
@@ -0,0 +1,337 @@
1From ec305795a302d226343e69031ff2024dfcde69c0 Mon Sep 17 00:00:00 2001
2From: Alexander Kanavin <alex.kanavin@gmail.com>
3Date: Thu, 8 Jun 2017 17:08:09 +0300
4Subject: [PATCH 3/3] build/pack.c: remove static local variables from
5 buildHost() and getBuildTime()
6
7Their use is causing difficult to diagnoze data races when building multiple
8packages in parallel, and is a bad idea in general, as it also makes it more
9difficult to reason about code.
10
11Upstream-Status: Submitted [https://github.com/rpm-software-management/rpm/pull/226]
12Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
13
14
15Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
16---
17 build/build.c | 54 ++++++++++++++++++++++++++++--
18 build/pack.c | 84 +++++++++--------------------------------------
19 build/rpmbuild_internal.h | 8 +++--
20 3 files changed, 74 insertions(+), 72 deletions(-)
21
22diff --git a/build/build.c b/build/build.c
23index 5f99c8db7..09a1311c5 100644
24--- a/build/build.c
25+++ b/build/build.c
26@@ -6,6 +6,8 @@
27 #include "system.h"
28
29 #include <errno.h>
30+#include <netdb.h>
31+#include <time.h>
32 #include <sys/wait.h>
33
34 #include <rpm/rpmlog.h>
35@@ -16,6 +18,50 @@
36
37 #include "debug.h"
38
39+static rpm_time_t getBuildTime(void)
40+{
41+ rpm_time_t buildTime = 0;
42+ char *srcdate;
43+ time_t epoch;
44+ char *endptr;
45+
46+ srcdate = getenv("SOURCE_DATE_EPOCH");
47+ if (srcdate) {
48+ errno = 0;
49+ epoch = strtol(srcdate, &endptr, 10);
50+ if (srcdate == endptr || *endptr || errno != 0)
51+ rpmlog(RPMLOG_ERR, _("unable to parse SOURCE_DATE_EPOCH\n"));
52+ else
53+ buildTime = (int32_t) epoch;
54+ } else
55+ buildTime = (int32_t) time(NULL);
56+
57+ return buildTime;
58+}
59+
60+static char * buildHost(void)
61+{
62+ char* hostname;
63+ struct hostent *hbn;
64+ char *bhMacro;
65+
66+ bhMacro = rpmExpand("%{?_buildhost}", NULL);
67+ if (strcmp(bhMacro, "") != 0) {
68+ rasprintf(&hostname, "%s", bhMacro);
69+ } else {
70+ hostname = rcalloc(1024, sizeof(*hostname));
71+ (void) gethostname(hostname, 1024);
72+ hbn = gethostbyname(hostname);
73+ if (hbn)
74+ strcpy(hostname, hbn->h_name);
75+ else
76+ rpmlog(RPMLOG_WARNING,
77+ _("Could not canonicalize hostname: %s\n"), hostname);
78+ }
79+ free(bhMacro);
80+ return(hostname);
81+}
82+
83 /**
84 */
85 static rpmRC doRmSource(rpmSpec spec)
86@@ -203,6 +249,9 @@ static rpmRC buildSpec(BTA_t buildArgs, rpmSpec spec, int what)
87 rpmRC rc = RPMRC_OK;
88 int test = (what & RPMBUILD_NOBUILD);
89 char *cookie = buildArgs->cookie ? xstrdup(buildArgs->cookie) : NULL;
90+ const char* host = buildHost();
91+ rpm_time_t buildTime = getBuildTime();
92+
93
94 if (rpmExpandNumeric("%{?source_date_epoch_from_changelog}") &&
95 getenv("SOURCE_DATE_EPOCH") == NULL) {
96@@ -271,11 +320,11 @@ static rpmRC buildSpec(BTA_t buildArgs, rpmSpec spec, int what)
97 goto exit;
98
99 if (((what & RPMBUILD_PACKAGESOURCE) && !test) &&
100- (rc = packageSources(spec, &cookie)))
101+ (rc = packageSources(spec, &cookie, buildTime, host)))
102 return rc;
103
104 if (((what & RPMBUILD_PACKAGEBINARY) && !test) &&
105- (rc = packageBinaries(spec, cookie, (didBuild == 0))))
106+ (rc = packageBinaries(spec, cookie, (didBuild == 0), buildTime, host)))
107 goto exit;
108
109 if ((what & RPMBUILD_CLEAN) &&
110@@ -295,6 +344,7 @@ static rpmRC buildSpec(BTA_t buildArgs, rpmSpec spec, int what)
111 (void) unlink(spec->specFile);
112
113 exit:
114+ free(host);
115 free(cookie);
116 spec->rootDir = NULL;
117 if (rc != RPMRC_OK && rpmlogGetNrecs() > 0) {
118diff --git a/build/pack.c b/build/pack.c
119index ed5b9ab4e..62427065a 100644
120--- a/build/pack.c
121+++ b/build/pack.c
122@@ -6,8 +6,6 @@
123 #include "system.h"
124
125 #include <errno.h>
126-#include <netdb.h>
127-#include <time.h>
128 #include <sys/wait.h>
129
130 #include <rpm/rpmlib.h> /* RPMSIGTAG*, rpmReadPackageFile */
131@@ -151,57 +149,6 @@ exit:
132 return rc;
133 }
134
135-static rpm_time_t * getBuildTime(void)
136-{
137- static rpm_time_t buildTime[1];
138- char *srcdate;
139- time_t epoch;
140- char *endptr;
141-
142- if (buildTime[0] == 0) {
143- srcdate = getenv("SOURCE_DATE_EPOCH");
144- if (srcdate) {
145- errno = 0;
146- epoch = strtol(srcdate, &endptr, 10);
147- if (srcdate == endptr || *endptr || errno != 0)
148- rpmlog(RPMLOG_ERR, _("unable to parse SOURCE_DATE_EPOCH\n"));
149- else
150- buildTime[0] = (int32_t) epoch;
151- } else
152- buildTime[0] = (int32_t) time(NULL);
153- }
154-
155- return buildTime;
156-}
157-
158-static const char * buildHost(void)
159-{
160- static char hostname[1024];
161- static int oneshot = 0;
162- struct hostent *hbn;
163- char *bhMacro;
164-
165- if (! oneshot) {
166- bhMacro = rpmExpand("%{?_buildhost}", NULL);
167- if (strcmp(bhMacro, "") != 0 && strlen(bhMacro) < 1024) {
168- strcpy(hostname, bhMacro);
169- } else {
170- if (strcmp(bhMacro, "") != 0)
171- rpmlog(RPMLOG_WARNING, _("The _buildhost macro is too long\n"));
172- (void) gethostname(hostname, sizeof(hostname));
173- hbn = gethostbyname(hostname);
174- if (hbn)
175- strcpy(hostname, hbn->h_name);
176- else
177- rpmlog(RPMLOG_WARNING,
178- _("Could not canonicalize hostname: %s\n"), hostname);
179- }
180- free(bhMacro);
181- oneshot = 1;
182- }
183- return(hostname);
184-}
185-
186 static rpmRC processScriptFiles(rpmSpec spec, Package pkg)
187 {
188 struct TriggerFileEntry *p;
189@@ -308,7 +255,8 @@ static int haveRichDep(Package pkg)
190 }
191
192 static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
193- const char *fileName, char **cookie)
194+ const char *fileName, char **cookie,
195+ rpm_time_t buildTime, const char* buildHost)
196 {
197 FD_t fd = NULL;
198 char * rpmio_flags = NULL;
199@@ -397,7 +345,7 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
200
201 /* Create and add the cookie */
202 if (cookie) {
203- rasprintf(cookie, "%s %d", buildHost(), (int) (*getBuildTime()));
204+ rasprintf(cookie, "%s %d", buildHost, buildTime);
205 headerPutString(pkg->header, RPMTAG_COOKIE, *cookie);
206 }
207
208@@ -546,7 +494,7 @@ static rpmRC checkPackages(char *pkgcheck)
209 return RPMRC_OK;
210 }
211
212-static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int cheating, char** filename)
213+static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int cheating, char** filename, rpm_time_t buildTime, const char* buildHost)
214 {
215 const char *errorString;
216 rpmRC rc = RPMRC_OK;
217@@ -565,8 +513,8 @@ static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int ch
218 headerCopyTags(spec->packages->header, pkg->header, copyTags);
219
220 headerPutString(pkg->header, RPMTAG_RPMVERSION, VERSION);
221- headerPutString(pkg->header, RPMTAG_BUILDHOST, buildHost());
222- headerPutUint32(pkg->header, RPMTAG_BUILDTIME, getBuildTime(), 1);
223+ headerPutString(pkg->header, RPMTAG_BUILDHOST, buildHost);
224+ headerPutUint32(pkg->header, RPMTAG_BUILDTIME, &buildTime, 1);
225
226 if (spec->sourcePkgId != NULL) {
227 headerPutBin(pkg->header, RPMTAG_SOURCEPKGID, spec->sourcePkgId,16);
228@@ -604,7 +552,7 @@ static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int ch
229 free(binRpm);
230 }
231
232- rc = writeRPM(pkg, NULL, *filename, NULL);
233+ rc = writeRPM(pkg, NULL, *filename, NULL, buildTime, buildHost);
234 if (rc == RPMRC_OK) {
235 /* Do check each written package if enabled */
236 char *pkgcheck = rpmExpand("%{?_build_pkgcheck} ", *filename, NULL);
237@@ -624,7 +572,7 @@ struct binaryPackageTaskData
238 struct binaryPackageTaskData *next;
239 };
240
241-static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const char *cookie, int cheating)
242+static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const char *cookie, int cheating, rpm_time_t buildTime, char* buildHost)
243 {
244 struct binaryPackageTaskData *tasks = NULL;
245 struct binaryPackageTaskData *task = NULL;
246@@ -636,7 +584,7 @@ static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const c
247 if (pkg == spec->packages) {
248 // the first package needs to be processed ahead of others, as they copy
249 // changelog data from it, and so otherwise data races would happen
250- task->result = packageBinary(spec, pkg, cookie, cheating, &(task->filename));
251+ task->result = packageBinary(spec, pkg, cookie, cheating, &(task->filename), buildTime, buildHost);
252 rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename);
253 tasks = task;
254 }
255@@ -653,7 +601,7 @@ static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const c
256 if (task != tasks)
257 #pragma omp task
258 {
259- task->result = packageBinary(spec, task->pkg, cookie, cheating, &(task->filename));
260+ task->result = packageBinary(spec, task->pkg, cookie, cheating, &(task->filename), buildTime, buildHost);
261 rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename);
262 }
263 }
264@@ -671,11 +619,11 @@ static void freeBinaryPackageTasks(struct binaryPackageTaskData* tasks)
265 }
266 }
267
268-rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
269+rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating, rpm_time_t buildTime, char* buildHost)
270 {
271 char *pkglist = NULL;
272
273- struct binaryPackageTaskData *tasks = runBinaryPackageTasks(spec, cookie, cheating);
274+ struct binaryPackageTaskData *tasks = runBinaryPackageTasks(spec, cookie, cheating, buildTime, buildHost);
275
276 for (struct binaryPackageTaskData *task = tasks; task != NULL; task = task->next) {
277 if (task->result == RPMRC_OK) {
278@@ -702,22 +650,22 @@ rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
279 return RPMRC_OK;
280 }
281
282-rpmRC packageSources(rpmSpec spec, char **cookie)
283+rpmRC packageSources(rpmSpec spec, char **cookie, rpm_time_t buildTime, char* buildHost)
284 {
285 Package sourcePkg = spec->sourcePackage;
286 rpmRC rc;
287
288 /* Add some cruft */
289 headerPutString(sourcePkg->header, RPMTAG_RPMVERSION, VERSION);
290- headerPutString(sourcePkg->header, RPMTAG_BUILDHOST, buildHost());
291- headerPutUint32(sourcePkg->header, RPMTAG_BUILDTIME, getBuildTime(), 1);
292+ headerPutString(sourcePkg->header, RPMTAG_BUILDHOST, buildHost);
293+ headerPutUint32(sourcePkg->header, RPMTAG_BUILDTIME, &buildTime, 1);
294
295 /* XXX this should be %_srpmdir */
296 { char *fn = rpmGetPath("%{_srcrpmdir}/", spec->sourceRpmName,NULL);
297 char *pkgcheck = rpmExpand("%{?_build_pkgcheck_srpm} ", fn, NULL);
298
299 spec->sourcePkgId = NULL;
300- rc = writeRPM(sourcePkg, &spec->sourcePkgId, fn, cookie);
301+ rc = writeRPM(sourcePkg, &spec->sourcePkgId, fn, cookie, buildTime, buildHost);
302
303 /* Do check SRPM package if enabled */
304 if (rc == RPMRC_OK && pkgcheck[0] != ' ') {
305diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h
306index 8351a6a34..797337ca7 100644
307--- a/build/rpmbuild_internal.h
308+++ b/build/rpmbuild_internal.h
309@@ -408,19 +408,23 @@ rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags);
310 * @param spec spec file control structure
311 * @param cookie build identifier "cookie" or NULL
312 * @param cheating was build shortcircuited?
313+ * @param buildTime the build timestamp that goes into packages
314+ * @param buildHost the hostname where the build is happening
315 * @return RPMRC_OK on success
316 */
317 RPM_GNUC_INTERNAL
318-rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating);
319+rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating, rpm_time_t buildTime, char* buildHost);
320
321 /** \ingroup rpmbuild
322 * Generate source package.
323 * @param spec spec file control structure
324 * @retval cookie build identifier "cookie" or NULL
325+ * @param buildTime the build timestamp that goes into packages
326+ * @param buildHost the hostname where the build is happening
327 * @return RPMRC_OK on success
328 */
329 RPM_GNUC_INTERNAL
330-rpmRC packageSources(rpmSpec spec, char **cookie);
331+rpmRC packageSources(rpmSpec spec, char **cookie, rpm_time_t buildTime, char* buildHost);
332
333 RPM_GNUC_INTERNAL
334 int addLangTag(rpmSpec spec, Header h, rpmTagVal tag,
335--
3362.11.0
337
diff --git a/meta/recipes-devtools/rpm/rpm_git.bb b/meta/recipes-devtools/rpm/rpm_git.bb
index 5fe52b83ec..e721dfba0b 100644
--- a/meta/recipes-devtools/rpm/rpm_git.bb
+++ b/meta/recipes-devtools/rpm/rpm_git.bb
@@ -38,6 +38,10 @@ SRC_URI = "git://github.com/rpm-software-management/rpm \
38 file://0011-Do-not-require-that-ELF-binaries-are-executable-to-b.patch \ 38 file://0011-Do-not-require-that-ELF-binaries-are-executable-to-b.patch \
39 file://0012-Use-conditional-to-access-_docdir-in-macros.in.patch \ 39 file://0012-Use-conditional-to-access-_docdir-in-macros.in.patch \
40 file://0013-Add-a-new-option-alldeps-to-rpmdeps.patch \ 40 file://0013-Add-a-new-option-alldeps-to-rpmdeps.patch \
41 file://0001-Split-binary-package-building-into-a-separate-functi.patch \
42 file://0002-Run-binary-package-creation-via-thread-pools.patch \
43 file://0003-rpmstrpool.c-make-operations-over-string-pools-threa.patch \
44 file://0004-build-pack.c-remove-static-local-variables-from-buil.patch \
41 " 45 "
42 46
43PV = "4.13.90+git${SRCPV}" 47PV = "4.13.90+git${SRCPV}"