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