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