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