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 
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 
60 static int noDeps = 0;
61 static int shortCircuit = 0;
62 static char buildMode = 0;
63 static char buildChar = 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 
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:
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 #ifdef __OS2__
470  if (*specFile != '/' && specFile[1] != ':') {
471 #else
472  if (*specFile != '/') {
473 #endif
474  char *cwd = rpmGetCwd();
475  char *s = NULL;
476  rasprintf(&s, "%s/%s", cwd, specFile);
477  free(cwd);
478  free(specFile);
479  specFile = s;
480  }
481 
482  struct stat st;
483  if (stat(specFile, &st) < 0) {
484  rpmlog(RPMLOG_ERR, _("failed to stat %s: %m\n"), specFile);
485  goto exit;
486  }
487  if (! S_ISREG(st.st_mode)) {
488  rpmlog(RPMLOG_ERR, _("File %s is not a regular file.\n"), specFile);
489  goto exit;
490  }
491 
492  /* Try to verify that the file is actually a specfile */
493  if (!isSpecFile(specFile)) {
495  _("File %s does not appear to be a specfile.\n"), specFile);
496  goto exit;
497  }
498 
499  /* Don't parse spec if only its removal is requested */
500  if (ba->buildAmount == RPMBUILD_RMSPEC) {
501  rc = unlink(specFile);
502  goto exit;
503  }
504 
505  /* Parse the spec file */
506 #define _anyarch(_f) \
507 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
508  if (_anyarch(buildAmount))
509  specFlags |= RPMSPEC_ANYARCH;
510 #undef _anyarch
511 
512  spec = rpmSpecParse(specFile, specFlags, buildRootURL);
513  if (spec == NULL) {
514  goto exit;
515  }
516 
517  /* Check build prerequisites if necessary, unless disabled */
518  if (!justRm && !noDeps && checkSpec(ts, spec)) {
519  goto exit;
520  }
521 
522  if (rpmSpecBuild(spec, ba)) {
523  goto exit;
524  }
525 
526  if (buildMode == 't')
527  (void) unlink(specFile);
528  rc = 0;
529 
530 exit:
531  free(specFile);
532  rpmSpecFree(spec);
533  free(buildRootURL);
534  return rc;
535 }
536 
537 static int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
538 {
539  int rc = 0;
540  char * targets = argvJoin(build_targets, ",");
541 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
542  int cleanFlags = ba->buildAmount & buildCleanMask;
543  rpmVSFlags vsflags, ovsflags;
544 
545  vsflags = rpmExpandNumeric("%{_vsflags_build}");
547  vsflags |= _RPMVSF_NODIGESTS;
549  vsflags |= _RPMVSF_NOSIGNATURES;
551  vsflags |= RPMVSF_NOHDRCHK;
552  ovsflags = rpmtsSetVSFlags(ts, vsflags);
553 
554  if (build_targets == NULL) {
555  rc = buildForTarget(ts, arg, ba);
556  goto exit;
557  }
558 
559  /* parse up the build operators */
560 
561  printf(_("Building target platforms: %s\n"), targets);
562 
563  ba->buildAmount &= ~buildCleanMask;
565  /* Perform clean-up after last target build. */
566  if (*(target + 1) == NULL)
567  ba->buildAmount |= cleanFlags;
568 
569  printf(_("Building for target %s\n"), *target);
570 
571  /* Read in configuration for target. */
572  rpmFreeMacros(NULL);
573  if (buildInPlace) {
574  /* Need to redefine this after freeing all the macros */
575  rpmDefineMacro(NULL, "_build_in_place 1", 0);
576  }
577  rpmFreeRpmrc();
578  (void) rpmReadConfigFiles(rcfile, *target);
579  rc = buildForTarget(ts, arg, ba);
580  if (rc)
581  break;
582  }
583 
584 exit:
585  rpmtsSetVSFlags(ts, ovsflags);
586  /* Restore original configuration. */
587  rpmFreeMacros(NULL);
588  rpmFreeRpmrc();
589  (void) rpmReadConfigFiles(rcfile, NULL);
590  free(targets);
591 
592  return rc;
593 }
594 
595 int main(int argc, char *argv[])
596 {
597  rpmts ts = NULL;
598  enum modes bigMode = MODE_BUILD;
599  BTA_t ba = &rpmBTArgs;
600 
601  const char *pkg = NULL;
602  int ec = 0;
603  poptContext optCon = rpmcliInit(argc, argv, optionsTable);
604 
605  /* Args required only when building, let lone --eval etc through */
606  if (ba->buildAmount && poptPeekArg(optCon) == NULL) {
607  printUsage(optCon, stderr, 0);
608  exit(EXIT_FAILURE);
609  }
610 
611  switch (buildMode) {
612  case 'b': bigMode = MODE_BUILD; break;
613  case 't': bigMode = MODE_TARBUILD; break;
614  case 'B': bigMode = MODE_REBUILD; break;
615  case 'C': bigMode = MODE_RECOMPILE; break;
616  }
617 
618  if (rpmcliRootDir && rpmcliRootDir[0] != '/') {
619  argerror(_("arguments to --root (-r) must begin with a /"));
620  }
621 
622  /* rpmbuild is rather chatty by default */
624 
625  if (rpmcliPipeOutput && initPipe())
626  exit(EXIT_FAILURE);
627 
628  ts = rpmtsCreate();
629  (void) rpmtsSetRootDir(ts, rpmcliRootDir);
630 
631  switch (buildChar) {
632  case 'a':
634  case 'b':
637  if ((buildChar == 'b') && shortCircuit)
638  break;
639  case 'i':
642  if ((buildChar == 'i') && shortCircuit)
643  break;
644  case 'c':
646  if ((buildChar == 'c') && shortCircuit)
647  break;
648  case 'p':
649  ba->buildAmount |= RPMBUILD_PREP;
650  break;
651  case 'l':
653  break;
654  case 's':
656  break;
657  }
658  ba->buildAmount &= ~(nobuildAmount);
659 
660  switch (bigMode) {
661  case MODE_REBUILD:
662  case MODE_RECOMPILE:
663  if (bigMode == MODE_REBUILD &&
664  buildChar != 'p' &&
665  buildChar != 'c' &&
666  buildChar != 'i' &&
667  buildChar != 'l') {
671  }
672  ba->buildAmount &= ~(nobuildAmount);
673 
674  while ((pkg = poptGetArg(optCon))) {
675  char * specFile = NULL;
676 
677  ba->cookie = NULL;
678  ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
679  if (ec == 0) {
680  ba->rootdir = rpmcliRootDir;
681  ec = build(ts, specFile, ba, rpmcliRcfile);
682  }
683  ba->cookie = _free(ba->cookie);
684  specFile = _free(specFile);
685 
686  if (ec)
687  break;
688  }
689  break;
690  case MODE_BUILD:
691  case MODE_TARBUILD:
692 
693  while ((pkg = poptGetArg(optCon))) {
694  ba->rootdir = rpmcliRootDir;
695  ba->cookie = NULL;
696  ec = build(ts, pkg, ba, rpmcliRcfile);
697  if (ec)
698  break;
699  rpmFreeMacros(NULL);
700  (void) rpmReadConfigFiles(rpmcliRcfile, NULL);
701  }
702  break;
703  }
704 
705  rpmtsFree(ts);
706  if (finishPipe())
707  ec = EXIT_FAILURE;
708  free(ba->buildRootOverride);
710 
711  rpmcliFini(optCon);
712 
713  return RETVAL(ec);
714 }
rpmBuildArguments_s::buildRootOverride
char * buildRootOverride
Definition: rpmbuild.h:60
RPMBUILD_RMSOURCE
@ RPMBUILD_RMSOURCE
Definition: rpmbuild.h:31
_RPMVSF_NOSIGNATURES
#define _RPMVSF_NOSIGNATURES
Definition: rpmts.h:118
argvSplit
int argvSplit(ARGV_t *argvp, const char *str, const char *seps)
_
#define _(Text)
Definition: system.h:112
POPT_RB
#define POPT_RB
Definition: rpmbuild.c:43
POPT_BUILDINPLACE
#define POPT_BUILDINPLACE
Definition: rpmbuild.c:31
POPT_RECOMPILE
#define POPT_RECOMPILE
Definition: rpmbuild.c:34
POPT_BI
#define POPT_BI
Definition: rpmbuild.c:38
RPMBUILD_CHECK
@ RPMBUILD_CHECK
Definition: rpmbuild.h:26
RPMBUILD_PKG_NODIRTOKENS
@ RPMBUILD_PKG_NODIRTOKENS
Definition: rpmbuild.h:49
POPT_BUILDROOT
#define POPT_BUILDROOT
Definition: rpmbuild.c:26
POPT_NODIRTOKENS
#define POPT_NODIRTOKENS
Definition: rpmbuild.c:30
RPMBUILD_PACKAGEBINARY
@ RPMBUILD_PACKAGEBINARY
Definition: rpmbuild.h:30
rpmSpecBuild
rpmRC rpmSpecBuild(rpmSpec spec, BTA_t buildArgs)
POPT_TS
#define POPT_TS
Definition: rpmbuild.c:55
rpmSpec
struct rpmSpec_s * rpmSpec
Definition: rpmtypes.h:90
shortCircuit
static int shortCircuit
Definition: rpmbuild.c:61
POPT_REBUILD
#define POPT_REBUILD
Definition: rpmbuild.c:33
rpmSpecFree
rpmSpec rpmSpecFree(rpmSpec spec)
rpmlog
void rpmlog(int code, const char *fmt,...) RPM_GNUC_PRINTF(2
rpmGenPath
char * rpmGenPath(const char *urlroot, const char *urlmdir, const char *urlfile)
nobuildAmount
static rpmBuildFlags nobuildAmount
Definition: rpmbuild.c:64
POPT_BC
#define POPT_BC
Definition: rpmbuild.c:37
RETVAL
#define RETVAL(rc)
Definition: cliutils.h:9
rpmpsPrint
void rpmpsPrint(FILE *fp, rpmps ps)
MODE_BUILD
@ MODE_BUILD
Definition: rpmbuild.c:251
rpmGetCwd
char * rpmGetCwd(void)
rpmtsCreate
rpmts rpmtsCreate(void)
POPT_TA
#define POPT_TA
Definition: rpmbuild.c:49
MODE_REBUILD
@ MODE_REBUILD
Definition: rpmbuild.c:252
rpmGetPath
char * rpmGetPath(const char *path,...) RPM_GNUC_NULL_TERMINATED
POPT_BA
#define POPT_BA
Definition: rpmbuild.c:35
ARGV_const_t
char *const * ARGV_const_t
Definition: argv.h:16
RPMSPEC_ANYARCH
@ RPMSPEC_ANYARCH
Definition: rpmspec.h:36
RPMBUILD_CLEAN
@ RPMBUILD_CLEAN
Definition: rpmbuild.h:27
rpmBuildArguments_s::buildAmount
rpmBuildFlags buildAmount
Definition: rpmbuild.h:59
POPT_NOLANG
#define POPT_NOLANG
Definition: rpmbuild.c:23
getTarSpec
static char * getTarSpec(const char *arg)
Definition: rpmbuild.c:338
buildForTarget
static int buildForTarget(rpmts ts, const char *arg, BTA_t ba)
Definition: rpmbuild.c:420
rpmtsRootDir
const char * rpmtsRootDir(rpmts ts)
rpmcliPipeOutput
const char * rpmcliPipeOutput
rpmts
struct rpmts_s * rpmts
Definition: rpmtypes.h:63
rpmDefineMacro
int rpmDefineMacro(rpmMacroContext mc, const char *macro, int level)
rpmBuildArguments_s::cookie
char * cookie
Definition: rpmbuild.h:61
rpmSetVerbosity
#define rpmSetVerbosity(_lvl)
Definition: rpmlog.h:264
RPMBUILD_NOBUILD
@ RPMBUILD_NOBUILD
Definition: rpmbuild.h:39
isSpecFile
static int isSpecFile(const char *specfile)
Definition: rpmbuild.c:291
POPT_RMBUILD
#define POPT_RMBUILD
Definition: rpmbuild.c:25
_anyarch
#define _anyarch(_f)
optionsTable
static struct poptOption optionsTable[]
Definition: rpmbuild.c:260
rpmBuildFlags
rpmFlags rpmBuildFlags
Definition: rpmbuild.h:42
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
_RPMVSF_NODIGESTS
#define _RPMVSF_NODIGESTS
Definition: rpmts.h:112
rpmExpand
char * rpmExpand(const char *arg,...) RPM_GNUC_NULL_TERMINATED
target
const char * target
Definition: rpmspec.c:21
ARGV_t
char ** ARGV_t
Definition: argv.h:15
RPMLOG_INFO
@ RPMLOG_INFO
Definition: rpmlog.h:36
RPMCLI_POPT_FORCE
#define RPMCLI_POPT_FORCE
Definition: rpmcli.h:62
build_targets
static ARGV_t build_targets
Definition: rpmbuild.c:65
rpmFreeRpmrc
void rpmFreeRpmrc(void)
initPipe
int initPipe(void)
Definition: cliutils.c:48
rasprintf
int rasprintf(char **strp, const char *fmt,...) RPM_GNUC_PRINTF(2
rpmcliRootDir
const char * rpmcliRootDir
RMIL_TARBALL
#define RMIL_TARBALL
Definition: rpmmacro.h:41
RPMBUILD_BUILD
@ RPMBUILD_BUILD
Definition: rpmbuild.h:24
__progname
#define __progname
Definition: system.h:97
POPT_BB
#define POPT_BB
Definition: rpmbuild.c:36
POPT_TC
#define POPT_TC
Definition: rpmbuild.c:51
POPT_BP
#define POPT_BP
Definition: rpmbuild.c:40
POPT_RMSPEC
#define POPT_RMSPEC
Definition: rpmbuild.c:29
rpmSpecCheckDeps
rpmps rpmSpecCheckDeps(rpmts ts, rpmSpec spec)
rpmReadConfigFiles
int rpmReadConfigFiles(const char *file, const char *target)
POPT_NOBUILD
#define POPT_NOBUILD
Definition: rpmbuild.c:28
RPMBUILD_PACKAGESOURCE
@ RPMBUILD_PACKAGESOURCE
Definition: rpmbuild.h:29
rpmps
struct rpmps_s * rpmps
Definition: rpmtypes.h:71
buildArgCallback
static void buildArgCallback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
Definition: rpmbuild.c:68
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
POPT_TP
#define POPT_TP
Definition: rpmbuild.c:54
VERIFY_HDRCHK
@ VERIFY_HDRCHK
Definition: rpmvf.h:68
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
rpmpsFree
rpmps rpmpsFree(rpmps ps)
VERIFY_SIGNATURE
@ VERIFY_SIGNATURE
Definition: rpmvf.h:66
buildMode
static char buildMode
Definition: rpmbuild.c:62
RPMBUILD_FILECHECK
@ RPMBUILD_FILECHECK
Definition: rpmbuild.h:28
RPMSPEC_NOLANG
@ RPMSPEC_NOLANG
Definition: rpmspec.h:38
rpmSpecParse
rpmSpec rpmSpecParse(const char *specFile, rpmSpecFlags flags, const char *buildRoot)
POPT_TARGETPLATFORM
#define POPT_TARGETPLATFORM
Definition: rpmbuild.c:27
POPT_TI
#define POPT_TI
Definition: rpmbuild.c:52
POPT_RS
#define POPT_RS
Definition: rpmbuild.c:48
RPMLOG_ERR
@ RPMLOG_ERR
Definition: rpmlog.h:33
rpmExpandNumeric
int rpmExpandNumeric(const char *arg)
RPMBUILD_RMBUILD
@ RPMBUILD_RMBUILD
Definition: rpmbuild.h:32
modes
modes
Definition: rpmbuild.c:250
finishPipe
int finishPipe(void)
Definition: cliutils.c:77
rpmBuildArguments_s
Definition: rpmbuild.h:57
MODE_TARBUILD
@ MODE_TARBUILD
Definition: rpmbuild.c:254
system.h
xstrdup
#define xstrdup(_str)
Definition: system.h:86
POPT_TB
#define POPT_TB
Definition: rpmbuild.c:50
RPMVSF_NOHDRCHK
@ RPMVSF_NOHDRCHK
Definition: rpmts.h:95
argvJoin
char * argvJoin(ARGV_const_t argv, const char *sep)
RPMBUILD_INSTALL
@ RPMBUILD_INSTALL
Definition: rpmbuild.h:25
POPT_TL
#define POPT_TL
Definition: rpmbuild.c:53
RPMBUILD_PREP
@ RPMBUILD_PREP
Definition: rpmbuild.h:23
rpmInstallSource
int rpmInstallSource(rpmts ts, const char *arg, char **specFilePtr, char **cookie)
rpmSpecFlags
rpmFlags rpmSpecFlags
Definition: rpmspec.h:42
buildCleanMask
#define buildCleanMask
RPMBUILD_RMSPEC
@ RPMBUILD_RMSPEC
Definition: rpmbuild.h:34
rstrscat
char * rstrscat(char **dest, const char *arg,...) RPM_GNUC_NULL_TERMINATED
POPT_RA
#define POPT_RA
Definition: rpmbuild.c:42
rpmtsSetVSFlags
rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags)
POPT_RC
#define POPT_RC
Definition: rpmbuild.c:44
rpmMkdirs
int rpmMkdirs(const char *root, const char *pathstr)
main
int main(int argc, char *argv[])
Definition: rpmbuild.c:595
_free
#define _free(_ptr)
Definition: system.h:87
RPMSPEC_FORCE
@ RPMSPEC_FORCE
Definition: rpmspec.h:37
RPMLOG_WARNING
@ RPMLOG_WARNING
Definition: rpmlog.h:34
_fsm_debug
int _fsm_debug
POPT_RI
#define POPT_RI
Definition: rpmbuild.c:45
POPT_BS
#define POPT_BS
Definition: rpmbuild.c:41
rpmBuildArguments_s::pkgFlags
rpmBuildPkgFlags pkgFlags
Definition: rpmbuild.h:58
quiet
static int quiet
Definition: rpmbuild.c:257
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
noDeps
static int noDeps
Definition: rpmbuild.c:60
rpmVSFlags
rpmFlags rpmVSFlags
Definition: rpmts.h:110
POPT_BL
#define POPT_BL
Definition: rpmbuild.c:39
rpmBuildPoptTable
static struct poptOption rpmBuildPoptTable[]
Definition: rpmbuild.c:135
POPT_RP
#define POPT_RP
Definition: rpmbuild.c:47
rstreq
static int rstreq(const char *s1, const char *s2)
Test for string equality.
Definition: rpmstring.h:113
argvFree
ARGV_t argvFree(ARGV_t argv)
POPT_RL
#define POPT_RL
Definition: rpmbuild.c:46
rpmcliQueryFlags
rpmQueryFlags rpmcliQueryFlags
checkSpec
static int checkSpec(rpmts ts, rpmSpec spec)
Definition: rpmbuild.c:277
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
rpmFreeMacros
void rpmFreeMacros(rpmMacroContext mc)
cliutils.h
rpmBuildArguments_s::rootdir
const char * rootdir
Definition: rpmbuild.h:62
VERIFY_DIGEST
@ VERIFY_DIGEST
Definition: rpmvf.h:65
rpmtsSetRootDir
int rpmtsSetRootDir(rpmts ts, const char *rootDir)
POPT_RMSOURCE
#define POPT_RMSOURCE
Definition: rpmbuild.c:24
addMacro
void addMacro(rpmMacroContext mc, const char *n, const char *o, const char *b, int level)
N_
#define N_(Text)
Definition: system.h:115
rpmBTArgs
static struct rpmBuildArguments_s rpmBTArgs
Definition: rpmbuild.c:21
spec_flags
static rpmSpecFlags spec_flags
Definition: rpmbuild.c:59
debug.h
rpmtsFree
rpmts rpmtsFree(rpmts ts)
build
static int build(rpmts ts, const char *arg, BTA_t ba, const char *rcfile)
Definition: rpmbuild.c:537
buildChar
static char buildChar
Definition: rpmbuild.c:63
rpmcliRcfile
const char * rpmcliRcfile
MODE_RECOMPILE
@ MODE_RECOMPILE
Definition: rpmbuild.c:253
buildInPlace
static int buildInPlace
Definition: rpmbuild.c:66