rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

build.c
Go to the documentation of this file.
1
5 #include "system.h"
6
7 #include <rpmio.h>
8 #include <rpmiotypes.h>
9 #include <rpmcb.h>
10 #include <rpmurl.h>
11
12 #include <rpmtypes.h>
13 #include <rpmtag.h>
14
15 #include <rpmbuild.h>
16
17 #include "rpmps.h"
18 #include "rpmte.h"
19 #include "rpmts.h"
20
21 #include "build.h"
22
23 #include <rpmcli.h>
24
25 #include "debug.h"
26
27 /*@access rpmts @*/ /* XXX compared with NULL @*/
28 /*@access rpmdb @*/ /* XXX compared with NULL @*/
29 /*@access FD_t @*/ /* XXX compared with NULL @*/
30
33 static int checkSpec(rpmts ts, Header h)
34 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
35 /*@modifies ts, h, rpmGlobalMacroContext, fileSystem, internalState @*/
36 {
37 int rc;
38
39 if (!headerIsEntry(h, RPMTAG_REQUIRENAME)
40 && !headerIsEntry(h, RPMTAG_CONFLICTNAME))
41 return 0;
42
43 rc = rpmtsAddInstallElement(ts, h, NULL, 0, NULL);
44
45 rc = rpmcliInstallProblems(ts, _("Failed build dependencies"), rpmtsCheck(ts));
46
47 /* XXX nuke the added package. */
48 rpmtsClean(ts);
49
50 return rc;
51 }
52
53 /*
54 * Kurwa, durni ameryka?ce sobe zawsze my?l?, ?e ca?y ?wiat mówi po
55 * angielsku...
56 */
57 /* XXX this is still a dumb test but at least it's i18n aware */
60 static int isSpecFile(const char * specfile)
61 /*@globals h_errno, fileSystem, internalState @*/
62 /*@modifies fileSystem, internalState @*/
63 {
64 char buf[256];
65 const char * s;
66 FD_t fd;
67 int count;
68 int checking;
69
70 fd = Fopen(specfile, "r");
71 if (fd == NULL || Ferror(fd)) {
72 rpmlog(RPMLOG_ERR, _("Unable to open spec file %s: %s\n"),
73 specfile, Fstrerror(fd));
74 return 0;
75 }
76 count = Fread(buf, sizeof(buf[0]), sizeof(buf), fd);
77 (void) Fclose(fd);
78
79 checking = 1;
80 for (s = buf; count--; s++) {
81 switch (*s) {
82 case '\r':
83 case '\n':
84 checking = 1;
85 /*@switchbreak@*/ break;
86 case ':':
87 checking = 0;
88 /*@switchbreak@*/ break;
89 /*@-boundsread@*/
90 default:
91 if (checking && !(isprint(*s) || isspace(*s))) return 0;
92 /*@switchbreak@*/ break;
93 /*@=boundsread@*/
94 }
95 }
96 return 1;
97 }
98
101 /*@-boundswrite@*/
102 static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
103 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
104 /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/
105 {
106 const char * passPhrase = ba->passPhrase;
107 const char * cookie = ba->cookie;
108 int buildAmount = ba->buildAmount;
109 const char * specFile = NULL;
110 const char * specURL = NULL;
111 int specut;
112 const char * s;
113 char * se;
114 size_t nb = strlen(arg) + BUFSIZ;
115 char * buf = alloca(nb);
116 Spec spec = NULL;
117 int verify = ((ba->buildAmount & RPMBUILD_TRACK) ? 0 : 1);
118 int xx;
119 int rc;
120
121 if (ba->buildMode == 't') {
122 static const char * sfpats[] = { "Specfile", "\\*.spec", NULL };
123 static const char _specfn[] = "%{mkstemp:%{_specdir}/rpm-spec.XXXXXX}";
124 char * tmpSpecFile = (char *) rpmGetPath(_specfn, NULL);
125 FILE *fp;
126 int bingo = 0;
127 int i;
128
129 for (i = 0; sfpats[i]; i++) {
130 se = rpmExpand("%{uncompress: %{u2p:", arg, "}}",
131 " | %{__tar} -xOvf - %{?__tar_wildcards} ", sfpats[i],
132 " 2>&1 > '", tmpSpecFile, "'", NULL);
133 fp = popen(se, "r");
134 se = _free(se);
135 if (fp== NULL)
136 continue;
137 s = fgets(buf, nb - 1, fp);
138 xx = pclose(fp);
139 if (!s || !*s || strstr(s, ": Not found in archive"))
140 continue;
141 bingo = 1;
142 break;
143 }
144 if (!bingo) {
145 rpmlog(RPMLOG_ERR, _("Failed to read spec file from %s\n"), arg);
146 xx = Unlink(tmpSpecFile);
147 tmpSpecFile = _free(tmpSpecFile);
148 return 1;
149 }
150
151 s = se = basename(buf);
152 se += strlen(se);
153 while (--se > s && strchr("\r\n", *se) != NULL)
154 *se = '\0';
155 specURL = rpmGetPath("%{_specdir}/", s, NULL);
156 specut = urlPath(specURL, &specFile);
157 xx = Rename(tmpSpecFile, specFile);
158 if (xx) {
159 rpmlog(RPMLOG_ERR, _("Failed to rename %s to %s: %m\n"),
160 tmpSpecFile, s);
161 (void) Unlink(tmpSpecFile);
162 }
163 tmpSpecFile = _free(tmpSpecFile);
164 if (xx)
165 return 1;
166
167 se = buf; *se = '\0';
168 se = stpcpy(se, "_sourcedir ");
169 (void) urlPath(arg, &s);
170 if (*s != '/') {
171 if (getcwd(se, nb - sizeof("_sourcedir ")) != NULL)
172 se += strlen(se);
173 else
174 se = stpcpy(se, ".");
175 } else
176 se = stpcpy(se, dirname(strcpy(se, s)));
177 while (se > buf && se[-1] == '/')
178 *se-- = '0';
179 rpmCleanPath(buf + sizeof("_sourcedir ") - 1);
180 rpmDefineMacro(NULL, buf, RMIL_TARBALL);
181 } else {
182 specut = urlPath(arg, &s);
183 se = buf; *se = '\0';
184 if (*s != '/') {
185 if (getcwd(se, nb - sizeof("_sourcedir ")) != NULL)
186 se += strlen(se);
187 else
188 se = stpcpy(se, ".");
189 *se++ = '/';
190 se += strlen(strcpy(se,strcpy(se, s)));
191 } else
192 se = stpcpy(se, s);
193 specURL = rpmGetPath(buf, NULL);
194 specut = urlPath(specURL, &specFile);
195 }
196
197 if (specut != URL_IS_DASH) {
198 struct stat sb;
199 if (Stat(specURL, &sb) < 0) {
200 rpmlog(RPMLOG_ERR, _("failed to stat %s: %m\n"), specURL);
201 rc = 1;
202 goto exit;
203 }
204 if (! S_ISREG(sb.st_mode)) {
205 rpmlog(RPMLOG_ERR, _("File %s is not a regular file.\n"),
206 specURL);
207 rc = 1;
208 goto exit;
209 }
210
211 /* Try to verify that the file is actually a specfile */
212 if (!isSpecFile(specURL)) {
213 rpmlog(RPMLOG_ERR,
214 _("File %s does not appear to be a specfile.\n"), specURL);
215 rc = 1;
216 goto exit;
217 }
218 }
219
220 /* Parse the spec file */
221 #define _anyarch(_f) \
222 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
223 if (parseSpec(ts, specURL, ba->rootdir, 0, passPhrase,
224 cookie, _anyarch(buildAmount), 0, verify))
225 {
226 rc = 1;
227 goto exit;
228 }
229 #undef _anyarch
230 if ((spec = rpmtsSetSpec(ts, NULL)) == NULL) {
231 rc = 1;
232 goto exit;
233 }
234
235 /* Assemble source header from parsed components */
236 xx = initSourceHeader(spec, NULL);
237
238 /* Check build prerequisites */
239 if (!ba->noDeps && checkSpec(ts, spec->sourceHeader)) {
240 rc = 1;
241 goto exit;
242 }
243
244 if (buildSpec(ts, spec, buildAmount, ba->noBuild)) {
245 rc = 1;
246 goto exit;
247 }
248
249 if (ba->buildMode == 't')
250 (void) Unlink(specURL);
251 rc = 0;
252
253 exit:
254 spec = freeSpec(spec);
255 specURL = _free(specURL);
256 return rc;
257 }
258 /*@=boundswrite@*/
259
260 int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
261 {
262 const char *t, *te;
263 int rc = 0;
264 const char * targets = rpmcliTargets;
265 char *target;
266 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
267 int cleanFlags = ba->buildAmount & buildCleanMask;
268 rpmVSFlags vsflags, ovsflags;
269 int nbuilds = 0;
270
271 vsflags = rpmExpandNumeric("%{_vsflags_build}");
272 if (ba->qva_flags & VERIFY_DIGEST)
273 vsflags |= _RPMVSF_NODIGESTS;
274 if (ba->qva_flags & VERIFY_SIGNATURE)
275 vsflags |= _RPMVSF_NOSIGNATURES;
276 if (ba->qva_flags & VERIFY_HDRCHK)
277 vsflags |= RPMVSF_NOHDRCHK;
278 ovsflags = rpmtsSetVSFlags(ts, vsflags);
279
280 if (targets == NULL) {
281 rc = buildForTarget(ts, arg, ba);
282 nbuilds++;
283 goto exit;
284 }
285
286 /* parse up the build operators */
287
288 printf(_("Building target platforms: %s\n"), targets);
289
290 ba->buildAmount &= ~buildCleanMask;
291 for (t = targets; *t != '\0'; t = te) {
292 /* Parse out next target platform. */
293 if ((te = strchr(t, ',')) == NULL)
294 te = t + strlen(t);
295 target = alloca(te-t+1);
296 strncpy(target, t, (te-t));
297 target[te-t] = '\0';
298 if (*te != '\0')
299 te++;
300 else /* XXX Perform clean-up after last target build. */
301 ba->buildAmount |= cleanFlags;
302
303 rpmlog(RPMLOG_DEBUG, _(" target platform: %s\n"), target);
304
305 /* Read in configuration for target. */
306 if (t != targets) {
307 rpmFreeMacros(NULL);
308 rpmFreeRpmrc();
309 (void) rpmReadConfigFiles(rcfile, target);
310 }
311 rc = buildForTarget(ts, arg, ba);
312 nbuilds++;
313 if (rc)
314 break;
315 }
316
317 exit:
318 /* Restore original configuration. */
319 if (nbuilds > 1) {
320 t = targets;
321 if ((te = strchr(t, ',')) == NULL)
322 te = t + strlen(t);
323 target = alloca(te-t+1);
324 strncpy(target, t, (te-t));
325 target[te-t] = '\0';
326 if (*te != '\0')
327 te++;
328 rpmFreeMacros(NULL);
329 rpmFreeRpmrc();
330 (void) rpmReadConfigFiles(rcfile, target);
331 }
332 vsflags = rpmtsSetVSFlags(ts, ovsflags);
333
334 return rc;
335 }