9 static int checkSpec(Header h)
15 struct rpmDependencyConflict * conflicts;
19 if (!headerIsEntry(h, RPMTAG_REQUIREFLAGS))
22 if (rpmdbOpen(rootdir, &db, mode, 0644)) {
24 dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL);
25 rpmMessage(RPMMESS_ERROR, _("cannot open %s/packages.rpm\n"), dn);
29 ts = rpmtransCreateSet(db, rootdir);
31 rc = rpmtransAddPackage(ts, h, NULL, NULL, 0, NULL);
33 rc = rpmdepCheck(ts, &conflicts, &numConflicts);
34 if (rc == 0 && conflicts) {
35 rpmMessage(RPMMESS_ERROR, _("failed build dependencies:\n"));
36 printDepProblems(stderr, conflicts, numConflicts);
37 rpmdepFreeConflicts(conflicts, numConflicts);
50 * Kurwa, durni ameryka?ce sobe zawsze my?l?, ?e ca?y ?wiat mówi po
53 /* XXX this is still a dumb test but at least it's i18n aware */
54 static int isSpecFile(const char *specfile)
62 fd = Fopen(specfile, "r.ufdio");
65 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
68 count = Fread(buf, sizeof(buf), 1, fd);
72 for (s = buf; count--; s++) {
82 if (checking && !(isprint(*s) || isspace(*s))) return 0;
89 static int buildForTarget(const char *arg, struct rpmBuildArguments *ba,
90 const char *passPhrase, int fromTarball, char *cookie,
91 int force, int nodeps)
93 int buildAmount = ba->buildAmount;
94 const char *buildRoot = ba->buildRootOverride;
95 int test = ba->noBuild;
97 const char * specfile;
102 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
106 const char * tmpSpecFile;
110 specDir = rpmGetPath("%{_specdir}", NULL);
113 strcpy(tfn, "rpm-spec.XXXXXX");
114 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
117 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
118 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s",
120 if (!(f = popen(cmd, "r"))) {
121 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
127 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
131 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
133 if (!(f = popen(cmd, "r"))) {
134 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
140 if (!fgets(buf, sizeof(buf) - 1, f)) {
142 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
153 if (*cmd == '/') s = cmd + 1;
159 /* remove trailing \n */
160 s = cmd + strlen(cmd) - 1;
163 specfile = s = alloca(strlen(specDir) + strlen(cmd) + 5);
164 sprintf(s, "%s/%s", specDir, cmd);
165 res = rename(tmpSpecFile, s);
170 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
171 tmpSpecFile, s, strerror(errno));
176 /* Make the directory which contains the tarball the source
177 directory for this run */
180 (void)getcwd(buf, BUFSIZ);
186 cmd = buf + strlen(buf) - 1;
187 while (*cmd != '/') cmd--;
190 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
195 switch (urlIsURL(specfile)) {
200 char *s = alloca(BUFSIZ);
201 (void)getcwd(s, BUFSIZ);
206 stat(specfile, &statbuf);
207 if (! S_ISREG(statbuf.st_mode)) {
208 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
212 /* Try to verify that the file is actually a specfile */
213 if (!isSpecFile(specfile)) {
214 fprintf(stderr, _("File %s does not appear to be a specfile.\n"),
223 /* Parse the spec file */
224 #define _anyarch(_f) \
225 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
226 if (parseSpec(&spec, specfile, ba->rootdir, buildRoot, 0, passPhrase,
227 cookie, _anyarch(buildAmount), force)) {
232 /* Assemble source header from parsed components */
233 initSourceHeader(spec);
235 /* Check build prerequisites */
236 if (!nodeps && checkSpec(spec->sourceHeader)) {
241 if (buildSpec(spec, buildAmount, test)) {
246 if (fromTarball) unlink(specfile);
253 int build(const char *arg, struct rpmBuildArguments *ba, const char *passPhrase,
254 int fromTarball, char *cookie, const char * rcfile, int force,
259 char *targets = ba->targets;
260 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
261 int cleanFlags = ba->buildAmount & buildCleanMask;
263 if (targets == NULL) {
264 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
269 /* parse up the build operators */
271 printf(_("Building target platforms: %s\n"), targets);
273 ba->buildAmount &= ~buildCleanMask;
274 for (t = targets; *t != '\0'; t = te) {
276 if ((te = strchr(t, ',')) == NULL)
278 target = alloca(te-t+1);
279 strncpy(target, t, (te-t));
283 else /* XXX Perform clean-up after last target build. */
284 ba->buildAmount |= cleanFlags;
286 printf(_("Building for target %s\n"), target);
288 /* Read in configuration for target. */
289 freeMacros(NULL); /* XXX macros from CLI are destroyed too */
290 rpmReadConfigFiles(rcfile, target);
291 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
298 /* Restore original configuration. */
299 freeMacros(NULL); /* XXX macros from CLI are destroyed too */
300 rpmReadConfigFiles(rcfile, NULL);
304 #define POPT_USECATALOG 1000
305 #define POPT_NOLANG 1001
306 #define POPT_RMSOURCE 1002
307 #define POPT_RMBUILD 1003
308 #define POPT_BUILDROOT 1004
309 #define POPT_BUILDARCH 1005
310 #define POPT_BUILDOS 1006
311 #define POPT_TARGETPLATFORM 1007
312 #define POPT_NOBUILD 1008
313 #define POPT_SHORTCIRCUIT 1009
314 #define POPT_RMSPEC 1010
317 static int noBuild = 0;
318 static int useCatalog = 0;
320 static void buildArgCallback( /*@unused@*/ poptContext con,
321 /*@unused@*/ enum poptCallbackReason reason,
322 const struct poptOption * opt, const char * arg, const void * data)
324 struct rpmBuildArguments * rba = (struct rpmBuildArguments *) data;
327 case POPT_USECATALOG: rba->useCatalog = 1; break;
328 case POPT_NOBUILD: rba->noBuild = 1; break;
329 case POPT_NOLANG: rba->noLang = 1; break;
330 case POPT_SHORTCIRCUIT: rba->shortCircuit = 1; break;
331 case POPT_RMSOURCE: rba->buildAmount |= RPMBUILD_RMSOURCE; break;
332 case POPT_RMSPEC: rba->buildAmount |= RPMBUILD_RMSPEC; break;
333 case POPT_RMBUILD: rba->buildAmount |= RPMBUILD_RMBUILD; break;
335 if (rba->buildRootOverride) {
336 fprintf(stderr, _("buildroot already specified"));
340 rba->buildRootOverride = xstrdup(arg);
343 fprintf(stderr, _("--buildarch has been obsoleted. Use the --target option instead.\n"));
345 /*@notreached@*/ break;
347 fprintf(stderr, _("--buildos has been obsoleted. Use the --target option instead.\n"));
349 /*@notreached@*/ break;
350 case POPT_TARGETPLATFORM:
352 int len = strlen(rba->targets) + 1 + strlen(arg) + 1;
353 rba->targets = xrealloc(rba->targets, len);
354 strcat(rba->targets, ",");
356 rba->targets = xmalloc(strlen(arg) + 1);
357 rba->targets[0] = '\0';
359 strcat(rba->targets, arg);
364 struct poptOption rpmBuildPoptTable[] = {
365 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
366 buildArgCallback, 0, NULL, NULL },
367 { "buildarch", '\0', POPT_ARG_STRING, 0, POPT_BUILDARCH,
368 N_("override build architecture"), "ARCH" },
369 { "buildos", '\0', POPT_ARG_STRING, 0, POPT_BUILDOS,
370 N_("override build operating system"), "OS" },
371 { "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
372 N_("override build root"), "DIRECTORY" },
373 { "clean", '\0', 0, 0, POPT_RMBUILD,
374 N_("remove build tree when done"), NULL},
375 { "nobuild", '\0', 0, &noBuild, POPT_NOBUILD,
376 N_("do not execute any stages of the build"), NULL },
377 { "nolang", '\0', 0, &noLang, POPT_NOLANG,
378 N_("do not accept I18N msgstr's from specfile"), NULL},
379 { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
380 N_("remove sources when done"), NULL},
381 { "rmspec", '\0', 0, 0, POPT_RMSPEC,
382 N_("remove specfile when done"), NULL},
383 { "short-circuit", '\0', 0, 0, POPT_SHORTCIRCUIT,
384 N_("skip straight to specified stage (only for c,i)"), NULL },
385 { "target", '\0', POPT_ARG_STRING, 0, POPT_TARGETPLATFORM,
386 N_("override target platform"), "CPU-VENDOR-OS" },
387 { "usecatalog", '\0', 0, &useCatalog, POPT_USECATALOG,
388 N_("lookup I18N strings in specfile catalog"), NULL},
389 { 0, 0, 0, 0, 0, NULL, NULL }