rpm: rpmbuild.c Source File

rpm 4.13.0

rpmbuild.c
Go to the documentation of this file.
1 #include "system.h"
2 const char *__progname;
3
4 #include <errno.h>
5 #include <libgen.h>
6 #include <ctype.h>
7
8 #include <rpm/rpmcli.h>
9 #include <rpm/rpmlib.h> /* RPMSIGTAG, rpmReadPackageFile .. */
10 #include <rpm/rpmbuild.h>
11 #include <rpm/rpmlog.h>
12 #include <rpm/rpmfileutil.h>
13 #include <rpm/rpmdb.h>
14 #include <rpm/rpmps.h>
15 #include <rpm/rpmts.h>
16 #include "lib/signature.h"
17 #include "cliutils.h"
18
19 #include "debug.h"
20
21 static struct rpmBuildArguments_s rpmBTArgs;
22
23 #define POPT_NOLANG -1012
24 #define POPT_RMSOURCE -1013
25 #define POPT_RMBUILD -1014
26 #define POPT_BUILDROOT -1015
27 #define POPT_TARGETPLATFORM -1016
28 #define POPT_NOBUILD -1017
29 #define POPT_RMSPEC -1019
30 #define POPT_NODIRTOKENS -1020
31 #define POPT_BUILDINPLACE -1021
32
33 #define POPT_REBUILD 0x4262 /* Bb */
34 #define POPT_RECOMPILE 0x4369 /* Ci */
35 #define POPT_BA 0x6261
36 #define POPT_BB 0x6262
37 #define POPT_BC 0x6263
38 #define POPT_BI 0x6269
39 #define POPT_BL 0x626c
40 #define POPT_BP 0x6270
41 #define POPT_BS 0x6273
42 #define POPT_RA 0x4261
43 #define POPT_RB 0x4262
44 #define POPT_RC 0x4263
45 #define POPT_RI 0x4269
46 #define POPT_RL 0x426c
47 #define POPT_RP 0x4270
48 #define POPT_RS 0x4273
49 #define POPT_TA 0x7461
50 #define POPT_TB 0x7462
51 #define POPT_TC 0x7463
52 #define POPT_TI 0x7469
53 #define POPT_TL 0x746c
54 #define POPT_TP 0x7470
55 #define POPT_TS 0x7473
56
57 extern int _fsm_debug;
58
59 static rpmSpecFlags spec_flags = 0;
60 static int noDeps = 0;
61 static int shortCircuit = 0;
62 static char buildMode = 0;
63 static char buildChar = 0;
64 static rpmBuildFlags nobuildAmount = 0;
65 static ARGV_t build_targets = NULL;
66 static int buildInPlace = 0;
68 static void buildArgCallback( poptContext con,
69 enum poptCallbackReason reason,
70 const struct poptOption * opt, const char * arg,
71 const void * data)
72 {
73 BTA_t rba = &rpmBTArgs;
74
75 switch (opt->val) {
76 case POPT_REBUILD:
77 case POPT_RECOMPILE:
78 case POPT_BA:
79 case POPT_BB:
80 case POPT_BC:
81 case POPT_BI:
82 case POPT_BL:
83 case POPT_BP:
84 case POPT_BS:
85 case POPT_RA:
86 /* case POPT_RB: same value as POPT_REBUILD */
87 case POPT_RC:
88 case POPT_RI:
89 case POPT_RL:
90 case POPT_RP:
91 case POPT_RS:
92 case POPT_TA:
93 case POPT_TB:
94 case POPT_TC:
95 case POPT_TI:
96 case POPT_TL:
97 case POPT_TP:
98 case POPT_TS:
99 if (opt->val == POPT_BS || opt->val == POPT_TS)
100 noDeps = 1;
101 if (buildMode == '\0' && buildChar == '\0') {
102 buildMode = (((unsigned)opt->val) >> 8) & 0xff;
103 buildChar = (opt->val ) & 0xff;
104 }
105 break;
106
107 case POPT_NODIRTOKENS: rba->pkgFlags |= RPMBUILD_PKG_NODIRTOKENS; break;
108 case POPT_NOBUILD: rba->buildAmount |= RPMBUILD_NOBUILD; break;
109 case POPT_NOLANG: spec_flags |= RPMSPEC_NOLANG; break;
110 case POPT_RMSOURCE: rba->buildAmount |= RPMBUILD_RMSOURCE; break;
111 case POPT_RMSPEC: rba->buildAmount |= RPMBUILD_RMSPEC; break;
112 case POPT_RMBUILD: rba->buildAmount |= RPMBUILD_RMBUILD; break;
113 case POPT_BUILDROOT:
114 if (rba->buildRootOverride) {
115 rpmlog(RPMLOG_ERR, _("buildroot already specified, ignoring %s\n"), arg);
116 break;
117 }
118 rba->buildRootOverride = xstrdup(arg);
119 break;
120 case POPT_TARGETPLATFORM:
121 argvSplit(&build_targets, arg, ",");
122 break;
123
124 case RPMCLI_POPT_FORCE:
125 spec_flags |= RPMSPEC_FORCE;
126 break;
127
128 case POPT_BUILDINPLACE:
129 rpmDefineMacro(NULL, "_build_in_place 1", 0);
130 buildInPlace = 1;
131 break;
132 }
133 }
134
135 static struct poptOption rpmBuildPoptTable[] = {
136 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | POPT_CBFLAG_CONTINUE,
137 buildArgCallback, 0, NULL, NULL },
138
139 { "bp", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BP,
140 N_("build through %prep (unpack sources and apply patches) from <specfile>"),
141 N_("<specfile>") },
142 { "bc", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BC,
143 N_("build through %build (%prep, then compile) from <specfile>"),
144 N_("<specfile>") },
145 { "bi", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BI,
146 N_("build through %install (%prep, %build, then install) from <specfile>"),
147 N_("<specfile>") },
148 { "bl", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BL,
149 N_("verify %files section from <specfile>"),
150 N_("<specfile>") },
151 { "ba", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BA,
152 N_("build source and binary packages from <specfile>"),
153 N_("<specfile>") },
154 { "bb", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BB,
155 N_("build binary package only from <specfile>"),
156 N_("<specfile>") },
157 { "bs", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_BS,
158 N_("build source package only from <specfile>"),
159 N_("<specfile>") },
160
161 { "rp", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_RP,
162 N_("build through %prep (unpack sources and apply patches) from <source package>"),
163 N_("<source package>") },
164 { "rc", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_RC,
165 N_("build through %build (%prep, then compile) from <source package>"),
166 N_("<source package>") },
167 { "ri", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_RI,
168 N_("build through %install (%prep, %build, then install) from <source package>"),
169 N_("<source package>") },
170 { "rl", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_RL,
171 N_("verify %files section from <source package>"),
172 N_("<source package>") },
173 { "ra", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_RA,
174 N_("build source and binary packages from <source package>"),
175 N_("<source package>") },
176 { "rb", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_RB,
177 N_("build binary package only from <source package>"),
178 N_("<source package>") },
179 { "rs", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_RS,
180 N_("build source package only from <source package>"),
181 N_("<source package>") },
182
183 { "tp", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TP,
184 N_("build through %prep (unpack sources and apply patches) from <tarball>"),
185 N_("<tarball>") },
186 { "tc", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TC,
187 N_("build through %build (%prep, then compile) from <tarball>"),
188 N_("<tarball>") },
189 { "ti", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TI,
190 N_("build through %install (%prep, %build, then install) from <tarball>"),
191 N_("<tarball>") },
192 { "tl", 0, POPT_ARGFLAG_ONEDASH|POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_TL,
193 N_("verify %files section from <tarball>"),
194 N_("<tarball>") },
195 { "ta", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TA,
196 N_("build source and binary packages from <tarball>"),
197 N_("<tarball>") },
198 { "tb", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TB,
199 N_("build binary package only from <tarball>"),
200 N_("<tarball>") },
201 { "ts", 0, POPT_ARGFLAG_ONEDASH, 0, POPT_TS,
202 N_("build source package only from <tarball>"),
203 N_("<tarball>") },
204
205 { "rebuild", '\0', 0, 0, POPT_REBUILD,
206 N_("build binary package from <source package>"),
207 N_("<source package>") },
208 { "recompile", '\0', 0, 0, POPT_RECOMPILE,
209 N_("build through %install (%prep, %build, then install) from <source package>"),
210 N_("<source package>") },
211
212 { "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
213 N_("override build root"), "DIRECTORY" },
214 { "build-in-place", '\0', 0, 0, POPT_BUILDINPLACE,
215 N_("run build in current directory"), NULL },
216 { "clean", '\0', 0, 0, POPT_RMBUILD,
217 N_("remove build tree when done"), NULL},
218 { "force", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, RPMCLI_POPT_FORCE,
219 N_("ignore ExcludeArch: directives from spec file"), NULL},
220 { "fsmdebug", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN), &_fsm_debug, -1,
221 N_("debug file state machine"), NULL},
222 { "nobuild", '\0', 0, 0, POPT_NOBUILD,
223 N_("do not execute any stages of the build"), NULL },
224 { "nodeps", '\0', POPT_ARG_VAL, &noDeps, 1,
225 N_("do not verify build dependencies"), NULL },
226 { "nodirtokens", '\0', 0, 0, POPT_NODIRTOKENS,
227 N_("generate package header(s) compatible with (legacy) rpm v3 packaging"),
228 NULL},
229
230 { "noclean", '\0', POPT_BIT_SET, &nobuildAmount, RPMBUILD_CLEAN,
231 N_("do not execute %clean stage of the build"), NULL },
232 { "noprep", '\0', POPT_BIT_SET, &nobuildAmount, RPMBUILD_PREP,
233 N_("do not execute %prep stage of the build"), NULL },
234 { "nocheck", '\0', POPT_BIT_SET, &nobuildAmount, RPMBUILD_CHECK,
235 N_("do not execute %check stage of the build"), NULL },
236
237 { "nolang", '\0', POPT_ARGFLAG_DOC_HIDDEN, 0, POPT_NOLANG,
238 N_("do not accept i18N msgstr's from specfile"), NULL},
239 { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
240 N_("remove sources when done"), NULL},
241 { "rmspec", '\0', 0, 0, POPT_RMSPEC,
242 N_("remove specfile when done"), NULL},
243 { "short-circuit", '\0', POPT_ARG_VAL, &shortCircuit, 1,
244 N_("skip straight to specified stage (only for c,i)"), NULL },
245 { "target", '\0', POPT_ARG_STRING, 0, POPT_TARGETPLATFORM,
246 N_("override target platform"), "CPU-VENDOR-OS" },
247 POPT_TABLEEND
248 };
249
250 enum modes {
251 MODE_BUILD = (1 << 4),
252 MODE_REBUILD = (1 << 5),
253 MODE_RECOMPILE = (1 << 8),
254 MODE_TARBUILD = (1 << 11),
255 };
256
257 static int quiet;
258
259 /* the structure describing the options we take and the defaults */
260 static struct poptOption optionsTable[] = {
261
262 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
263 N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
264 NULL },
265
266 { "quiet", '\0', POPT_ARGFLAG_DOC_HIDDEN, &quiet, 0, NULL, NULL},
267
268 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
269 N_("Common options for all rpm modes and executables:"),
270 NULL },
271
272 POPT_AUTOALIAS
273 POPT_AUTOHELP
274 POPT_TABLEEND
275 };
276
277 static int checkSpec(rpmts ts, rpmSpec spec)
278 {
279 int rc;
280 rpmps ps = rpmSpecCheckDeps(ts, spec);
281
282 if (ps) {
283 rpmlog(RPMLOG_ERR, _("Failed build dependencies:\n"));
284 rpmpsPrint(NULL, ps);
285 }
286 rc = (ps != NULL);
287 rpmpsFree(ps);
288 return rc;
289 }
290
291 static int isSpecFile(const char * specfile)
292 {
293 char buf[256];
294 const char * s;
295 FILE * f;
296 int count;
297 int checking;
298
299 f = fopen(specfile, "r");
300 if (f == NULL) {
301 rpmlog(RPMLOG_ERR, _("Unable to open spec file %s: %s\n"),
302 specfile, strerror(errno));
303 return 0;
304 }
305 count = fread(buf, sizeof(buf[0]), sizeof(buf), f);
306 (void) fclose(f);
307
308 if (count == 0)
309 return 0;
310
311 checking = 1;
312 for (s = buf; count--; s++) {
313 switch (*s) {
314 case '\r':
315 case '\n':
316 checking = 1;
317 break;
318 case ':':
319 checking = 0;
320 break;
321 default:
322 #if 0
323 if (checking && !(isprint(*s) || isspace(*s))) return 0;
324 break;
325 #else
326 if (checking && !(isprint(*s) || isspace(*s)) && *(unsigned char *)s < 32) return 0;
327 break;
328 #endif
329 }
330 }
331 return 1;
332 }
333
334 /*
335 * Try to find a spec from a tarball pointed to by arg.
336 * Return absolute path to spec name on success, otherwise NULL.
337 */
338 static char * getTarSpec(const char *arg)
339 {
340 char *specFile = NULL;
341 char *specDir;
342 char *specBase;
343 char *tmpSpecFile;
344 const char **spec;
345 char tarbuf[BUFSIZ];
346 int gotspec = 0, res;
347 static const char *tryspec[] = { "Specfile", "\\*.spec", NULL };
348
349 specDir = rpmGetPath("%{_specdir}", NULL);
350 tmpSpecFile = rpmGetPath("%{_specdir}/", "rpm-spec.XXXXXX", NULL);
351
352 (void) close(mkstemp(tmpSpecFile));
353
354 for (spec = tryspec; *spec != NULL; spec++) {
355 FILE *fp;
356 char *cmd;
357 int specfiles = 0;
358
359 cmd = rpmExpand("%{uncompress: ", arg, "} | ",
360 "%{__tar} xOvof - --wildcards ", *spec,
361 " 2>&1 > ", tmpSpecFile, NULL);
362
363 if (!(fp = popen(cmd, "r"))) {
364 rpmlog(RPMLOG_ERR, _("Failed to open tar pipe: %m\n"));
365 } else {
366 char *fok;
367 for (;;) {
368 fok = fgets(tarbuf, sizeof(tarbuf) - 1, fp);
369 if (!fok) break;
370 /* tar sometimes prints "tar: Record size = 16" messages */
371 if (strstr(fok, "tar: ")) {
372 continue;
373 }
374 specfiles++;
375 }
376 pclose(fp);
377 gotspec = (specfiles == 1) && isSpecFile(tmpSpecFile);
378 if (specfiles > 1) {
379 rpmlog(RPMLOG_ERR, _("Found more than one spec file in %s\n"), arg);
380 goto exit;
381 }
382 }
383
384 if (!gotspec)
385 unlink(tmpSpecFile);
386 free(cmd);
387 }
388
389 if (!gotspec) {
390 rpmlog(RPMLOG_ERR, _("Failed to read spec file from %s\n"), arg);
391 goto exit;
392 }
393
394 specBase = basename(tarbuf);
395 /* remove trailing \n */
396 specBase[strlen(specBase)-1] = '\0';
397
398 rasprintf(&specFile, "%s/%s", specDir, specBase);
399 res = rename(tmpSpecFile, specFile);
400
401 if (res) {
402 rpmlog(RPMLOG_ERR, _("Failed to rename %s to %s: %m\n"),
403 tmpSpecFile, specFile);
404 free(specFile);
405 specFile = NULL;
406 } else {
407 /* mkstemp() can give unnecessarily strict permissions, fixup */
408 mode_t mask;
409 umask(mask = umask(0));
410 (void) chmod(specFile, 0666 & ~mask);
411 }
412
413 exit:
414 (void) unlink(tmpSpecFile);
415 free(tmpSpecFile);
416 free(specDir);
417 return specFile;
418 }
419
420 static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
421 {
422 int buildAmount = ba->buildAmount;
423 char * buildRootURL = NULL;
424 char * specFile = NULL;
425 rpmSpec spec = NULL;
426 int rc = 1; /* assume failure */
427 int justRm = ((buildAmount & ~(RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)) == 0);
428 rpmSpecFlags specFlags = spec_flags;
429
430 /* Override default BUILD value for _builddir */
431 if (buildInPlace) {
432 char *cwd = rpmGetCwd();
433 addMacro(NULL, "_builddir", NULL, cwd, 0);
434 free(cwd);
435 }
436
437 if (ba->buildRootOverride)
438 buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
439
440 /* Create build tree if necessary */
441 const char * buildtree = "%{_topdir}:%{_specdir}:%{_sourcedir}:%{_builddir}:%{_rpmdir}:%{_srcrpmdir}:%{_buildrootdir}";
442 const char * rootdir = rpmtsRootDir(ts);
443 if (rpmMkdirs(!rstreq(rootdir, "/") ? rootdir : NULL , buildtree)) {
444 goto exit;
445 }
446
447 if (buildMode == 't') {
448 char *srcdir = NULL, *dir;
449
450 specFile = getTarSpec(arg);
451 if (!specFile)
452 goto exit;
453
454 /* Make the directory of the tarball %_sourcedir for this run */
455 /* dirname() may modify contents so extra hoops needed. */
456 if (*arg != '/') {
457 dir = rpmGetCwd();
458 rstrscat(&dir, "/", arg, NULL);
459 } else {
460 dir = xstrdup(arg);
461 }
462 srcdir = dirname(dir);
463 addMacro(NULL, "_sourcedir", NULL, srcdir, RMIL_TARBALL);
464 free(dir);
465 } else {
466 specFile = xstrdup(arg);
467 }
468
469 if (*specFile != '/') {
470 char *cwd = rpmGetCwd();
471 char *s = NULL;
472 rasprintf(&s, "%s/%s", cwd, specFile);
473 free(cwd);
474 free(specFile);
475 specFile = s;
476 }
477
478 struct stat st;
479 if (stat(specFile, &st) < 0) {
480 rpmlog(RPMLOG_ERR, _("failed to stat %s: %m\n"), specFile);
481 goto exit;
482 }
483 if (! S_ISREG(st.st_mode)) {
484 rpmlog(RPMLOG_ERR, _("File %s is not a regular file.\n"), specFile);
485 goto exit;
486 }
487
488 /* Try to verify that the file is actually a specfile */
489 if (!isSpecFile(specFile)) {
490 rpmlog(RPMLOG_ERR,
491 _("File %s does not appear to be a specfile.\n"), specFile);
492 goto exit;
493 }
494
495 /* Don't parse spec if only its removal is requested */
496 if (ba->buildAmount == RPMBUILD_RMSPEC) {
497 rc = unlink(specFile);
498 goto exit;
499 }
500
501 /* Parse the spec file */
502 #define _anyarch(_f) \
503 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
504 if (_anyarch(buildAmount))
505 specFlags |= RPMSPEC_ANYARCH;
506 #undef _anyarch
507
508 spec = rpmSpecParse(specFile, specFlags, buildRootURL);
509 if (spec == NULL) {
510 goto exit;
511 }
512
513 /* Check build prerequisites if necessary, unless disabled */
514 if (!justRm && !noDeps && checkSpec(ts, spec)) {
515 goto exit;
516 }
517
518 if (rpmSpecBuild(spec, ba)) {
519 goto exit;
520 }
521
522 if (buildMode == 't')
523 (void) unlink(specFile);
524 rc = 0;
525
526 exit:
527 free(specFile);
528 rpmSpecFree(spec);
529 free(buildRootURL);
530 return rc;
531 }
532
533 static int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
534 {
535 int rc = 0;
536 char * targets = argvJoin(build_targets, ",");
537 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
538 int cleanFlags = ba->buildAmount & buildCleanMask;
539 rpmVSFlags vsflags, ovsflags;
540
541 vsflags = rpmExpandNumeric("%{_vsflags_build}");
542 if (rpmcliQueryFlags & VERIFY_DIGEST)
543 vsflags |= _RPMVSF_NODIGESTS;
544 if (rpmcliQueryFlags & VERIFY_SIGNATURE)
545 vsflags |= _RPMVSF_NOSIGNATURES;
546 if (rpmcliQueryFlags & VERIFY_HDRCHK)
547 vsflags |= RPMVSF_NOHDRCHK;
548 ovsflags = rpmtsSetVSFlags(ts, vsflags);
549
550 if (build_targets == NULL) {
551 rc = buildForTarget(ts, arg, ba);
552 goto exit;
553 }
554
555 /* parse up the build operators */
556
557 printf(_("Building target platforms: %s\n"), targets);
558
559 ba->buildAmount &= ~buildCleanMask;
560 for (ARGV_const_t target = build_targets; target && *target; target++) {
561 /* Perform clean-up after last target build. */
562 if (*(target + 1) == NULL)
563 ba->buildAmount |= cleanFlags;
564
565 printf(_("Building for target %s\n"), *target);
566
567 /* Read in configuration for target. */
568 rpmFreeMacros(NULL);
569 if (buildInPlace) {
570 /* Need to redefine this after freeing all the macros */
571 rpmDefineMacro(NULL, "_build_in_place 1", 0);
572 }
573 rpmFreeRpmrc();
574 (void) rpmReadConfigFiles(rcfile, *target);
575 rc = buildForTarget(ts, arg, ba);
576 if (rc)
577 break;
578 }
579
580 exit:
581 rpmtsSetVSFlags(ts, ovsflags);
582 /* Restore original configuration. */
583 rpmFreeMacros(NULL);
584 rpmFreeRpmrc();
585 (void) rpmReadConfigFiles(rcfile, NULL);
586 free(targets);
587
588 return rc;
589 }
590
591 int main(int argc, char *argv[])
592 {
593 rpmts ts = NULL;
594 enum modes bigMode = MODE_BUILD;
595 BTA_t ba = &rpmBTArgs;
596
597 const char *pkg = NULL;
598 int ec = 0;
599 poptContext optCon = rpmcliInit(argc, argv, optionsTable);
600
601 /* Args required only when building, let lone --eval etc through */
602 if (ba->buildAmount && poptPeekArg(optCon) == NULL) {
603 printUsage(optCon, stderr, 0);
604 exit(EXIT_FAILURE);
605 }
606
607 switch (buildMode) {
608 case 'b': bigMode = MODE_BUILD; break;
609 case 't': bigMode = MODE_TARBUILD; break;
610 case 'B': bigMode = MODE_REBUILD; break;
611 case 'C': bigMode = MODE_RECOMPILE; break;
612 }
613
614 if (rpmcliRootDir && rpmcliRootDir[0] != '/') {
615 argerror(_("arguments to --root (-r) must begin with a /"));
616 }
617
618 /* rpmbuild is rather chatty by default */
619 rpmSetVerbosity(quiet ? RPMLOG_WARNING : RPMLOG_INFO);
620
621 if (rpmcliPipeOutput && initPipe())
622 exit(EXIT_FAILURE);
623
624 ts = rpmtsCreate();
625 (void) rpmtsSetRootDir(ts, rpmcliRootDir);
626
627 switch (buildChar) {
628 case 'a':
629 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
630 case 'b':
631 ba->buildAmount |= RPMBUILD_PACKAGEBINARY;
632 ba->buildAmount |= RPMBUILD_CLEAN;
633 if ((buildChar == 'b') && shortCircuit)
634 break;
635 case 'i':
636 ba->buildAmount |= RPMBUILD_INSTALL;
637 ba->buildAmount |= RPMBUILD_CHECK;
638 if ((buildChar == 'i') && shortCircuit)
639 break;
640 case 'c':
641 ba->buildAmount |= RPMBUILD_BUILD;
642 if ((buildChar == 'c') && shortCircuit)
643 break;
644 case 'p':
645 ba->buildAmount |= RPMBUILD_PREP;
646 break;
647 case 'l':
648 ba->buildAmount |= RPMBUILD_FILECHECK;
649 break;
650 case 's':
651 ba->buildAmount |= RPMBUILD_PACKAGESOURCE;
652 break;
653 }
654 ba->buildAmount &= ~(nobuildAmount);
655
656 switch (bigMode) {
657 case MODE_REBUILD:
658 case MODE_RECOMPILE:
659 if (bigMode == MODE_REBUILD &&
660 buildChar != 'p' &&
661 buildChar != 'c' &&
662 buildChar != 'i' &&
663 buildChar != 'l') {
664 ba->buildAmount |= RPMBUILD_RMSOURCE;
665 ba->buildAmount |= RPMBUILD_RMSPEC;
666 ba->buildAmount |= RPMBUILD_RMBUILD;
667 }
668 ba->buildAmount &= ~(nobuildAmount);
669
670 while ((pkg = poptGetArg(optCon))) {
671 char * specFile = NULL;
672
673 ba->cookie = NULL;
674 ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
675 if (ec == 0) {
676 ba->rootdir = rpmcliRootDir;
677 ec = build(ts, specFile, ba, rpmcliRcfile);
678 }
679 ba->cookie = _free(ba->cookie);
680 specFile = _free(specFile);
681
682 if (ec)
683 break;
684 }
685 break;
686 case MODE_BUILD:
687 case MODE_TARBUILD:
688
689 while ((pkg = poptGetArg(optCon))) {
690 ba->rootdir = rpmcliRootDir;
691 ba->cookie = NULL;
692 ec = build(ts, pkg, ba, rpmcliRcfile);
693 if (ec)
694 break;
695 rpmFreeMacros(NULL);
696 (void) rpmReadConfigFiles(rpmcliRcfile, NULL);
697 }
698 break;
699 }
700
701 rpmtsFree(ts);
702 if (finishPipe())
703 ec = EXIT_FAILURE;
704 free(ba->buildRootOverride);
705 argvFree(build_targets);
706
707 rpmcliFini(optCon);
708
709 return RETVAL(ec);
710 }
rpmBuildPoptTable
static struct poptOption rpmBuildPoptTable[]
Definition: rpmbuild.c:135
nobuildAmount
static rpmBuildFlags nobuildAmount
Definition: rpmbuild.c:64
RETVAL
#define RETVAL(rc)
Definition: cliutils.h:9
rpmcliRcfile
const char * rpmcliRcfile
rpmtsSetRootDir
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
Set transaction rootDir, i.e.
POPT_BC
#define POPT_BC
Definition: rpmbuild.c:37
RPMLOG_WARNING
Definition: rpmlog.h:34
rpmcliQueryFlags
rpmQueryFlags rpmcliQueryFlags
Bit(s) from common command line options.
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
POPT_BL
#define POPT_BL
Definition: rpmbuild.c:39
POPT_BA
#define POPT_BA
Definition: rpmbuild.c:35
RPMBUILD_FILECHECK
Definition: rpmbuild.h:28
POPT_RL
#define POPT_RL
Definition: rpmbuild.c:46
rpmSpecCheckDeps
rpmps rpmSpecCheckDeps(rpmts ts, rpmSpec spec)
Verify build depencies of a spec against.
POPT_NOLANG
#define POPT_NOLANG
Definition: rpmbuild.c:23
buildForTarget
static int buildForTarget(rpmts ts, const char *arg, BTA_t ba)
Definition: rpmbuild.c:420
ARGV_t
char ** ARGV_t
Definition: argv.h:15
spec_flags
static rpmSpecFlags spec_flags
Definition: rpmbuild.c:59
debug.h
build
static int build(rpmts ts, const char *arg, BTA_t ba, const char *rcfile)
Definition: rpmbuild.c:533
RPMLOG_INFO
Definition: rpmlog.h:36
rpmBTArgs
static struct rpmBuildArguments_s rpmBTArgs
Definition: rpmbuild.c:21
rstrscat
char * rstrscat(char **dest, const char *arg,...) RPM_GNUC_NULL_TERMINATED
Concatenate multiple strings with dynamically (re)allocated memory.
RPMSPEC_FORCE
Definition: rpmspec.h:37
POPT_RB
#define POPT_RB
Definition: rpmbuild.c:43
isSpecFile
static int isSpecFile(const char *specfile)
Definition: rpmbuild.c:291
POPT_BUILDINPLACE
#define POPT_BUILDINPLACE
Definition: rpmbuild.c:31
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
buildInPlace
static int buildInPlace
Definition: rpmbuild.c:66
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
rpmSpecFree
rpmSpec rpmSpecFree(rpmSpec spec)
Destroy Spec structure.
RPMBUILD_NOBUILD
Definition: rpmbuild.h:39
build_targets
static ARGV_t build_targets
Definition: rpmbuild.c:65
cliutils.h
rpmBuildArguments_s::pkgFlags
rpmBuildPkgFlags pkgFlags
Definition: rpmbuild.h:58
POPT_RECOMPILE
#define POPT_RECOMPILE
Definition: rpmbuild.c:34
rpmtsRootDir
const char * rpmtsRootDir(rpmts ts)
Get transaction rootDir, i.e.
finishPipe
int finishPipe(void)
Definition: cliutils.c:73
RPMLOG_ERR
Definition: rpmlog.h:33
POPT_TC
#define POPT_TC
Definition: rpmbuild.c:51
POPT_BUILDROOT
#define POPT_BUILDROOT
Definition: rpmbuild.c:26
POPT_RMSPEC
#define POPT_RMSPEC
Definition: rpmbuild.c:29
POPT_NODIRTOKENS
#define POPT_NODIRTOKENS
Definition: rpmbuild.c:30
_
#define _(Text)
Definition: system.h:110
MODE_BUILD
Definition: rpmbuild.c:251
MODE_REBUILD
Definition: rpmbuild.c:252
RPMBUILD_RMBUILD
Definition: rpmbuild.h:32
POPT_BB
#define POPT_BB
Definition: rpmbuild.c:36
rpmSpecBuild
rpmRC rpmSpecBuild(rpmSpec spec, BTA_t buildArgs)
Spec build stages state machine driver.
rpmReadConfigFiles
int rpmReadConfigFiles(const char *file, const char *target)
Read macro configuration file(s) for a target.
POPT_NOBUILD
#define POPT_NOBUILD
Definition: rpmbuild.c:28
shortCircuit
static int shortCircuit
Definition: rpmbuild.c:61
buildArgCallback
static void buildArgCallback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
Definition: rpmbuild.c:68
POPT_TARGETPLATFORM
#define POPT_TARGETPLATFORM
Definition: rpmbuild.c:27
RPMBUILD_INSTALL
Definition: rpmbuild.h:25
POPT_TP
#define POPT_TP
Definition: rpmbuild.c:54
RPMBUILD_PACKAGESOURCE
Definition: rpmbuild.h:29
rpmBuildArguments_s::rootdir
const char * rootdir
Definition: rpmbuild.h:62
argvSplit
int argvSplit(ARGV_t *argvp, const char *str, const char *seps)
Split a string into an argv array.
RPMBUILD_PACKAGEBINARY
Definition: rpmbuild.h:30
rpmcliPipeOutput
const char * rpmcliPipeOutput
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
rpmBuildArguments_s::buildAmount
rpmBuildFlags buildAmount
Definition: rpmbuild.h:59
VERIFY_SIGNATURE
Definition: rpmvf.h:66
rstreq
static int rstreq(const char *s1, const char *s2)
Test for string equality.
Definition: rpmstring.h:113
modes
modes
Definition: rpmbuild.c:250
getTarSpec
static char * getTarSpec(const char *arg)
Definition: rpmbuild.c:338
rpmBuildArguments_s::buildRootOverride
char * buildRootOverride
Definition: rpmbuild.h:60
xstrdup
#define xstrdup(_str)
Definition: system.h:86
rpmExpandNumeric
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
rpmps
struct rpmps_s * rpmps
Definition: rpmtypes.h:71
POPT_TL
#define POPT_TL
Definition: rpmbuild.c:53
rpmInstallSource
int rpmInstallSource(rpmts ts, const char *arg, char **specFilePtr, char **cookie)
Install source rpm package.
POPT_RC
#define POPT_RC
Definition: rpmbuild.c:44
initPipe
int initPipe(void)
Definition: cliutils.c:48
RPMBUILD_CHECK
Definition: rpmbuild.h:26
POPT_RMBUILD
#define POPT_RMBUILD
Definition: rpmbuild.c:25
_anyarch
#define _anyarch(_f)
RPMSPEC_ANYARCH
Definition: rpmspec.h:36
optionsTable
static struct poptOption optionsTable[]
Definition: rpmbuild.c:260
rpmVSFlags
rpmFlags rpmVSFlags
Definition: rpmts.h:110
VERIFY_DIGEST
Definition: rpmvf.h:65
target
const char * target
Definition: rpmspec.c:21
rpmMkdirs
int rpmMkdirs(const char *root, const char *pathstr)
Create several directories (including parents if needed) in one go.
rpmcliRootDir
const char * rpmcliRootDir
POPT_BP
#define POPT_BP
Definition: rpmbuild.c:40
rpmpsFree
rpmps rpmpsFree(rpmps ps)
Destroy a problem set.
_fsm_debug
int _fsm_debug
POPT_RI
#define POPT_RI
Definition: rpmbuild.c:45
POPT_BS
#define POPT_BS
Definition: rpmbuild.c:41
rpmGetPath
char * rpmGetPath(const char *path,...) RPM_GNUC_NULL_TERMINATED
Return (malloc&#39;ed) expanded, canonicalized, file path.
RPMCLI_POPT_FORCE
#define RPMCLI_POPT_FORCE
Definition: rpmcli.h:62
addMacro
void addMacro(rpmMacroContext mc, const char *n, const char *o, const char *b, int level)
Add macro to context.
POPT_RP
#define POPT_RP
Definition: rpmbuild.c:47
argvFree
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
ARGV_const_t
char *const * ARGV_const_t
Definition: argv.h:16
_free
#define _free(_ptr)
Definition: system.h:87
_RPMVSF_NOSIGNATURES
#define _RPMVSF_NOSIGNATURES
Definition: rpmts.h:118
rpmtsFree
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
POPT_RMSOURCE
#define POPT_RMSOURCE
Definition: rpmbuild.c:24
checkSpec
static int checkSpec(rpmts ts, rpmSpec spec)
Definition: rpmbuild.c:277
rpmFreeMacros
void rpmFreeMacros(rpmMacroContext mc)
Destroy macro context.
rpmSpecParse
rpmSpec rpmSpecParse(const char *specFile, rpmSpecFlags flags, const char *buildRoot)
Parse spec file into spec control structure.
rpmtsSetVSFlags
rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags)
Set verify signatures flag(s).
rpmExpand
char * rpmExpand(const char *arg,...) RPM_GNUC_NULL_TERMINATED
Return (malloc&#39;ed) concatenated macro expansion(s).
POPT_TI
#define POPT_TI
Definition: rpmbuild.c:52
rpmts
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
rpmSpecFlags
rpmFlags rpmSpecFlags
Definition: rpmspec.h:42
system.h
buildMode
static char buildMode
Definition: rpmbuild.c:62
RPMBUILD_PREP
Definition: rpmbuild.h:23
rpmDefineMacro
int rpmDefineMacro(rpmMacroContext mc, const char *macro, int level)
Define macro in context.
rasprintf
int rasprintf(char **strp, const char *fmt,...) RPM_GNUC_PRINTF(2
asprintf() clone
RPMBUILD_BUILD
Definition: rpmbuild.h:24
POPT_RS
#define POPT_RS
Definition: rpmbuild.c:48
rpmFreeRpmrc
void rpmFreeRpmrc(void)
Destroy rpmrc arch/os compatibility tables.
RPMVSF_NOHDRCHK
Definition: rpmts.h:95
POPT_TB
#define POPT_TB
Definition: rpmbuild.c:50
buildChar
static char buildChar
Definition: rpmbuild.c:63
rpmBuildArguments_s::cookie
char * cookie
Definition: rpmbuild.h:61
RMIL_TARBALL
#define RMIL_TARBALL
Definition: rpmmacro.h:41
__progname
#define __progname
Definition: system.h:96
_RPMVSF_NODIGESTS
#define _RPMVSF_NODIGESTS
Definition: rpmts.h:112
VERIFY_HDRCHK
Definition: rpmvf.h:68
RPMBUILD_RMSPEC
Definition: rpmbuild.h:34
N_
#define N_(Text)
Definition: system.h:113
MODE_RECOMPILE
Definition: rpmbuild.c:253
rpmSetVerbosity
#define rpmSetVerbosity(_lvl)
Definition: rpmlog.h:264
RPMBUILD_RMSOURCE
Definition: rpmbuild.h:31
rpmpsPrint
void rpmpsPrint(FILE *fp, rpmps ps)
Print problems to file handle.
POPT_BI
#define POPT_BI
Definition: rpmbuild.c:38
RPMSPEC_NOLANG
Definition: rpmspec.h:38
rpmtsCreate
rpmts rpmtsCreate(void)
Create an empty transaction set.
buildCleanMask
#define buildCleanMask
rpmGenPath
char * rpmGenPath(const char *urlroot, const char *urlmdir, const char *urlfile)
Merge 3 args into path, any or all of which may be a url.
POPT_TS
#define POPT_TS
Definition: rpmbuild.c:55
rpmBuildArguments_s
Describe build request.
Definition: rpmbuild.h:57
RPMBUILD_CLEAN
Definition: rpmbuild.h:27
rpmBuildFlags
rpmFlags rpmBuildFlags
Definition: rpmbuild.h:42
RPMBUILD_PKG_NODIRTOKENS
Definition: rpmbuild.h:49
rpmGetCwd
char * rpmGetCwd(void)
Like getcwd() but the result is malloced.
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
POPT_RA
#define POPT_RA
Definition: rpmbuild.c:42
MODE_TARBUILD
Definition: rpmbuild.c:254
argvJoin
char * argvJoin(ARGV_const_t argv, const char *sep)
Join an argv array into a string.
main
int main(int argc, char *argv[])
Definition: rpmbuild.c:591
quiet
static int quiet
Definition: rpmbuild.c:257
rpmlog
void rpmlog(int code, const char *fmt,...) RPM_GNUC_PRINTF(2
Generate a log message using FMT string and option arguments.
POPT_REBUILD
#define POPT_REBUILD
Definition: rpmbuild.c:33
rpmSpec
struct rpmSpec_s * rpmSpec
Definition: rpmtypes.h:90
noDeps
static int noDeps
Definition: rpmbuild.c:60
POPT_TA
#define POPT_TA
Definition: rpmbuild.c:49