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 /* the structure describing the options we take and the defaults */
258 static struct poptOption optionsTable[] = {
259 
260  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmBuildPoptTable, 0,
261  N_("Build options with [ <specfile> | <tarball> | <source package> ]:"),
262  NULL },
263 
264  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
265  N_("Common options for all rpm modes and executables:"),
266  NULL },
267 
268  POPT_AUTOALIAS
269  POPT_AUTOHELP
270  POPT_TABLEEND
271 };
272 
273 static int checkSpec(rpmts ts, rpmSpec spec)
274 {
275  int rc;
276  rpmps ps = rpmSpecCheckDeps(ts, spec);
277 
278  if (ps) {
279  rpmlog(RPMLOG_ERR, _("Failed build dependencies:\n"));
280  rpmpsPrint(NULL, ps);
281  }
282  rc = (ps != NULL);
283  rpmpsFree(ps);
284  return rc;
285 }
286 
287 static int isSpecFile(const char * specfile)
288 {
289  char buf[256];
290  const char * s;
291  FILE * f;
292  int count;
293  int checking;
294 
295  f = fopen(specfile, "r");
296  if (f == NULL) {
297  rpmlog(RPMLOG_ERR, _("Unable to open spec file %s: %s\n"),
298  specfile, strerror(errno));
299  return 0;
300  }
301  count = fread(buf, sizeof(buf[0]), sizeof(buf), f);
302  (void) fclose(f);
303 
304  if (count == 0)
305  return 0;
306 
307  checking = 1;
308  for (s = buf; count--; s++) {
309  switch (*s) {
310  case '\r':
311  case '\n':
312  checking = 1;
313  break;
314  case ':':
315  checking = 0;
316  break;
317  default:
318 #if 0
319  if (checking && !(isprint(*s) || isspace(*s))) return 0;
320  break;
321 #else
322  if (checking && !(isprint(*s) || isspace(*s)) && *(unsigned char *)s < 32) return 0;
323  break;
324 #endif
325  }
326  }
327  return 1;
328 }
329 
330 /*
331  * Try to find a spec from a tarball pointed to by arg.
332  * Return absolute path to spec name on success, otherwise NULL.
333  */
334 static char * getTarSpec(const char *arg)
335 {
336  char *specFile = NULL;
337  char *specDir;
338  char *specBase;
339  char *tmpSpecFile;
340  const char **spec;
341  char tarbuf[BUFSIZ];
342  int gotspec = 0, res;
343  static const char *tryspec[] = { "Specfile", "\\*.spec", NULL };
344 
345  specDir = rpmGetPath("%{_specdir}", NULL);
346  tmpSpecFile = rpmGetPath("%{_specdir}/", "rpm-spec.XXXXXX", NULL);
347 
348  (void) close(mkstemp(tmpSpecFile));
349 
350  for (spec = tryspec; *spec != NULL; spec++) {
351  FILE *fp;
352  char *cmd;
353  int specfiles = 0;
354 
355  cmd = rpmExpand("%{uncompress: ", arg, "} | ",
356  "%{__tar} xOvof - --wildcards ", *spec,
357  " 2>&1 > ", tmpSpecFile, NULL);
358 
359  if (!(fp = popen(cmd, "r"))) {
360  rpmlog(RPMLOG_ERR, _("Failed to open tar pipe: %m\n"));
361  } else {
362  char *fok;
363  for (;;) {
364  fok = fgets(tarbuf, sizeof(tarbuf) - 1, fp);
365  if (!fok) break;
366  /* tar sometimes prints "tar: Record size = 16" messages */
367  if (strstr(fok, "tar: ")) {
368  continue;
369  }
370  specfiles++;
371  }
372  pclose(fp);
373  gotspec = (specfiles == 1) && isSpecFile(tmpSpecFile);
374  if (specfiles > 1) {
375  rpmlog(RPMLOG_ERR, _("Found more than one spec file in %s\n"), arg);
376  goto exit;
377  }
378  }
379 
380  if (!gotspec)
381  unlink(tmpSpecFile);
382  free(cmd);
383  }
384 
385  if (!gotspec) {
386  rpmlog(RPMLOG_ERR, _("Failed to read spec file from %s\n"), arg);
387  goto exit;
388  }
389 
390  specBase = basename(tarbuf);
391  /* remove trailing \n */
392  specBase[strlen(specBase)-1] = '\0';
393 
394  rasprintf(&specFile, "%s/%s", specDir, specBase);
395  res = rename(tmpSpecFile, specFile);
396 
397  if (res) {
398  rpmlog(RPMLOG_ERR, _("Failed to rename %s to %s: %m\n"),
399  tmpSpecFile, specFile);
400  free(specFile);
401  specFile = NULL;
402  } else {
403  /* mkstemp() can give unnecessarily strict permissions, fixup */
404  mode_t mask;
405  umask(mask = umask(0));
406  (void) chmod(specFile, 0666 & ~mask);
407  }
408 
409 exit:
410  (void) unlink(tmpSpecFile);
411  free(tmpSpecFile);
412  free(specDir);
413  return specFile;
414 }
415 
416 static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
417 {
418  int buildAmount = ba->buildAmount;
419  char * buildRootURL = NULL;
420  char * specFile = NULL;
421  rpmSpec spec = NULL;
422  int rc = 1; /* assume failure */
423  int justRm = ((buildAmount & ~(RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)) == 0);
424  rpmSpecFlags specFlags = spec_flags;
425 
426  /* Override default BUILD value for _builddir */
427  if (buildInPlace) {
428  char *cwd = rpmGetCwd();
429  addMacro(NULL, "_builddir", NULL, cwd, 0);
430  free(cwd);
431  }
432 
433  if (ba->buildRootOverride)
434  buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
435 
436  /* Create build tree if necessary */
437  const char * buildtree = "%{_topdir}:%{_specdir}:%{_sourcedir}:%{_builddir}:%{_rpmdir}:%{_srcrpmdir}:%{_buildrootdir}";
438  const char * rootdir = rpmtsRootDir(ts);
439  if (rpmMkdirs(!rstreq(rootdir, "/") ? rootdir : NULL , buildtree)) {
440  goto exit;
441  }
442 
443  if (buildMode == 't') {
444  char *srcdir = NULL, *dir;
445 
446  specFile = getTarSpec(arg);
447  if (!specFile)
448  goto exit;
449 
450  /* Make the directory of the tarball %_sourcedir for this run */
451  /* dirname() may modify contents so extra hoops needed. */
452  if (*arg != '/') {
453  dir = rpmGetCwd();
454  rstrscat(&dir, "/", arg, NULL);
455  } else {
456  dir = xstrdup(arg);
457  }
458  srcdir = dirname(dir);
459  addMacro(NULL, "_sourcedir", NULL, srcdir, RMIL_TARBALL);
460  free(dir);
461  } else {
462  specFile = xstrdup(arg);
463  }
464 
465 #ifdef __KLIBC__
466  if (*specFile != '/' && specFile[1] != ':') {
467 #else
468  if (*specFile != '/') {
469 #endif
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)) {
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}");
543  vsflags |= _RPMVSF_NODIGESTS;
545  vsflags |= _RPMVSF_NOSIGNATURES;
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 */
621 
622  if (rpmcliPipeOutput && initPipe())
623  exit(EXIT_FAILURE);
624 
625  ts = rpmtsCreate();
626  (void) rpmtsSetRootDir(ts, rpmcliRootDir);
627 
628  switch (buildChar) {
629  case 'a':
631  case 'b':
634  if ((buildChar == 'b') && shortCircuit)
635  break;
636  case 'i':
639  if ((buildChar == 'i') && shortCircuit)
640  break;
641  case 'c':
643  if ((buildChar == 'c') && shortCircuit)
644  break;
645  case 'p':
646  ba->buildAmount |= RPMBUILD_PREP;
647  break;
648  case 'l':
650  break;
651  case 's':
653  break;
654  }
655  ba->buildAmount &= ~(nobuildAmount);
656 
657  switch (bigMode) {
658  case MODE_REBUILD:
659  case MODE_RECOMPILE:
660  if (bigMode == MODE_REBUILD &&
661  buildChar != 'p' &&
662  buildChar != 'c' &&
663  buildChar != 'i' &&
664  buildChar != 'l') {
668  }
669  ba->buildAmount &= ~(nobuildAmount);
670 
671  while ((pkg = poptGetArg(optCon))) {
672  char * specFile = NULL;
673 
674  ba->cookie = NULL;
675  ec = rpmInstallSource(ts, pkg, &specFile, &ba->cookie);
676  if (ec == 0) {
677  ba->rootdir = rpmcliRootDir;
678  ec = build(ts, specFile, ba, rpmcliRcfile);
679  }
680  ba->cookie = _free(ba->cookie);
681  specFile = _free(specFile);
682 
683  if (ec)
684  break;
685  }
686  break;
687  case MODE_BUILD:
688  case MODE_TARBUILD:
689 
690  while ((pkg = poptGetArg(optCon))) {
691  ba->rootdir = rpmcliRootDir;
692  ba->cookie = NULL;
693  ec = build(ts, pkg, ba, rpmcliRcfile);
694  if (ec)
695  break;
696  rpmFreeMacros(NULL);
697  (void) rpmReadConfigFiles(rpmcliRcfile, NULL);
698  }
699  break;
700  }
701 
702  rpmtsFree(ts);
703  if (finishPipe())
704  ec = EXIT_FAILURE;
705  free(ba->buildRootOverride);
707 
708  rpmcliFini(optCon);
709 
710  return RETVAL(ec);
711 }
static struct poptOption rpmBuildPoptTable[]
Definition: rpmbuild.c:135
static rpmBuildFlags nobuildAmount
Definition: rpmbuild.c:64
#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:37
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:39
#define POPT_BA
Definition: rpmbuild.c:35
#define POPT_RL
Definition: rpmbuild.c:46
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:416
char ** ARGV_t
Definition: argv.h:15
static rpmSpecFlags spec_flags
Definition: rpmbuild.c:59
static int build(rpmts ts, const char *arg, BTA_t ba, const char *rcfile)
Definition: rpmbuild.c:533
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:43
static int isSpecFile(const char *specfile)
Definition: rpmbuild.c:287
#define POPT_BUILDINPLACE
Definition: rpmbuild.c:31
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
RPM_GNUC_NORETURN void argerror(const char *desc)
Definition: cliutils.c:19
static int buildInPlace
Definition: rpmbuild.c:66
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:65
rpmBuildPkgFlags pkgFlags
Definition: rpmbuild.h:58
#define POPT_RECOMPILE
Definition: rpmbuild.c:34
const char * rpmtsRootDir(rpmts ts)
Get transaction rootDir, i.e.
int finishPipe(void)
Definition: cliutils.c:73
#define POPT_TC
Definition: rpmbuild.c:51
#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:112
#define POPT_BB
Definition: rpmbuild.c:36
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:61
static void buildArgCallback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data)
Definition: rpmbuild.c:68
#define POPT_TARGETPLATFORM
Definition: rpmbuild.c:27
#define POPT_TP
Definition: rpmbuild.c:54
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
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:250
static char * getTarSpec(const char *arg)
Definition: rpmbuild.c:334
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:53
int rpmInstallSource(rpmts ts, const char *arg, char **specFilePtr, char **cookie)
Install source rpm package.
#define POPT_RC
Definition: rpmbuild.c:44
int initPipe(void)
Definition: cliutils.c:48
#define POPT_RMBUILD
Definition: rpmbuild.c:25
#define _anyarch(_f)
static struct poptOption optionsTable[]
Definition: rpmbuild.c:258
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:40
rpmps rpmpsFree(rpmps ps)
Destroy a problem set.
int _fsm_debug
#define POPT_RI
Definition: rpmbuild.c:45
#define POPT_BS
Definition: rpmbuild.c:41
char * rpmGetPath(const char *path,...) RPM_GNUC_NULL_TERMINATED
Return (malloc&#39;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:47
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:273
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&#39;ed) concatenated macro expansion(s).
#define POPT_TI
Definition: rpmbuild.c:52
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:62
int rpmDefineMacro(rpmMacroContext mc, const char *macro, int level)
Define macro in context.
int rasprintf(char **strp, const char *fmt,...) RPM_GNUC_PRINTF(2
asprintf() clone
#define POPT_RS
Definition: rpmbuild.c:48
void rpmFreeRpmrc(void)
Destroy rpmrc arch/os compatibility tables.
#define POPT_TB
Definition: rpmbuild.c:50
static char buildChar
Definition: rpmbuild.c:63
#define RMIL_TARBALL
Definition: rpmmacro.h:41
#define _RPMVSF_NODIGESTS
Definition: rpmts.h:112
#define N_(Text)
Definition: system.h:115
#define rpmSetVerbosity(_lvl)
Definition: rpmlog.h:264
void rpmpsPrint(FILE *fp, rpmps ps)
Print problems to file handle.
#define POPT_BI
Definition: rpmbuild.c:38
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:55
Describe build request.
Definition: rpmbuild.h:57
int rpmlogSetMask(int mask)
Set the log mask level.
rpmFlags rpmBuildFlags
Definition: rpmbuild.h:42
const char * __progname
Definition: rpmbuild.c:2
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:42
char * argvJoin(ARGV_const_t argv, const char *sep)
Join an argv array into a string.
#define RPMLOG_UPTO(pri)
Definition: rpmlog.h:140
int main(int argc, char *argv[])
Definition: rpmbuild.c:591
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:33
struct rpmSpec_s * rpmSpec
Definition: rpmtypes.h:90
static int noDeps
Definition: rpmbuild.c:60
#define POPT_TA
Definition: rpmbuild.c:49