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");
63 if (fd == NULL || Ferror(fd)) {
64 fprintf(stderr, _("Unable to open spec file %s: %s\n"), specfile, Fstrerror(fd));
67 count = Fread(buf, sizeof(buf[0]), sizeof(buf), fd);
71 for (s = buf; count--; s++) {
81 if (checking && !(isprint(*s) || isspace(*s))) return 0;
88 static int buildForTarget(const char *arg, struct rpmBuildArguments *ba,
89 const char *passPhrase, int fromTarball, char *cookie,
90 int force, int nodeps)
92 int buildAmount = ba->buildAmount;
93 const char *buildRoot = ba->buildRootOverride;
94 int test = ba->noBuild;
96 const char * specfile;
101 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
105 const char * tmpSpecFile;
109 specDir = rpmGetPath("%{_specdir}", NULL);
112 strcpy(tfn, "rpm-spec.XXXXXX");
113 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
116 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
117 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s",
119 if (!(f = popen(cmd, "r"))) {
120 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
126 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
130 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
132 if (!(f = popen(cmd, "r"))) {
133 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
139 if (!fgets(buf, sizeof(buf) - 1, f)) {
141 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
152 if (*cmd == '/') s = cmd + 1;
158 /* remove trailing \n */
159 s = cmd + strlen(cmd) - 1;
162 specfile = s = alloca(strlen(specDir) + strlen(cmd) + 5);
163 sprintf(s, "%s/%s", specDir, cmd);
164 res = rename(tmpSpecFile, s);
169 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
170 tmpSpecFile, s, strerror(errno));
175 /* Make the directory which contains the tarball the source
176 directory for this run */
179 (void)getcwd(buf, BUFSIZ);
185 cmd = buf + strlen(buf) - 1;
186 while (*cmd != '/') cmd--;
189 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
194 switch (urlIsURL(specfile)) {
199 char *s = alloca(BUFSIZ);
200 (void)getcwd(s, BUFSIZ);
205 stat(specfile, &statbuf);
206 if (! S_ISREG(statbuf.st_mode)) {
207 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
211 /* Try to verify that the file is actually a specfile */
212 if (!isSpecFile(specfile)) {
213 fprintf(stderr, _("File %s does not appear to be a specfile.\n"),
222 /* Parse the spec file */
223 #define _anyarch(_f) \
224 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
225 if (parseSpec(&spec, specfile, ba->rootdir, buildRoot, 0, passPhrase,
226 cookie, _anyarch(buildAmount), force)) {
231 /* Assemble source header from parsed components */
232 initSourceHeader(spec);
234 /* Check build prerequisites */
235 if (!nodeps && checkSpec(spec->sourceHeader)) {
240 if (buildSpec(spec, buildAmount, test)) {
245 if (fromTarball) unlink(specfile);
252 int build(const char *arg, struct rpmBuildArguments *ba, const char *passPhrase,
253 int fromTarball, char *cookie, const char * rcfile, int force,
258 char *targets = ba->targets;
259 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
260 int cleanFlags = ba->buildAmount & buildCleanMask;
262 if (targets == NULL) {
263 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
268 /* parse up the build operators */
270 printf(_("Building target platforms: %s\n"), targets);
272 ba->buildAmount &= ~buildCleanMask;
273 for (t = targets; *t != '\0'; t = te) {
275 if ((te = strchr(t, ',')) == NULL)
277 target = alloca(te-t+1);
278 strncpy(target, t, (te-t));
282 else /* XXX Perform clean-up after last target build. */
283 ba->buildAmount |= cleanFlags;
285 printf(_("Building for target %s\n"), target);
287 /* Read in configuration for target. */
288 freeMacros(NULL); /* XXX macros from CLI are destroyed too */
289 rpmReadConfigFiles(rcfile, target);
290 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
297 /* Restore original configuration. */
298 freeMacros(NULL); /* XXX macros from CLI are destroyed too */
299 rpmReadConfigFiles(rcfile, NULL);
303 #define POPT_USECATALOG 1000
304 #define POPT_NOLANG 1001
305 #define POPT_RMSOURCE 1002
306 #define POPT_RMBUILD 1003
307 #define POPT_BUILDROOT 1004
308 #define POPT_BUILDARCH 1005
309 #define POPT_BUILDOS 1006
310 #define POPT_TARGETPLATFORM 1007
311 #define POPT_NOBUILD 1008
312 #define POPT_SHORTCIRCUIT 1009
313 #define POPT_RMSPEC 1010
316 static int noBuild = 0;
317 static int useCatalog = 0;
319 static void buildArgCallback( /*@unused@*/ poptContext con,
320 /*@unused@*/ enum poptCallbackReason reason,
321 const struct poptOption * opt, const char * arg, const void * data)
323 struct rpmBuildArguments * rba = (struct rpmBuildArguments *) data;
326 case POPT_USECATALOG: rba->useCatalog = 1; break;
327 case POPT_NOBUILD: rba->noBuild = 1; break;
328 case POPT_NOLANG: rba->noLang = 1; break;
329 case POPT_SHORTCIRCUIT: rba->shortCircuit = 1; break;
330 case POPT_RMSOURCE: rba->buildAmount |= RPMBUILD_RMSOURCE; break;
331 case POPT_RMSPEC: rba->buildAmount |= RPMBUILD_RMSPEC; break;
332 case POPT_RMBUILD: rba->buildAmount |= RPMBUILD_RMBUILD; break;
334 if (rba->buildRootOverride) {
335 fprintf(stderr, _("buildroot already specified"));
339 rba->buildRootOverride = xstrdup(arg);
342 fprintf(stderr, _("--buildarch has been obsoleted. Use the --target option instead.\n"));
344 /*@notreached@*/ break;
346 fprintf(stderr, _("--buildos has been obsoleted. Use the --target option instead.\n"));
348 /*@notreached@*/ break;
349 case POPT_TARGETPLATFORM:
351 int len = strlen(rba->targets) + 1 + strlen(arg) + 1;
352 rba->targets = xrealloc(rba->targets, len);
353 strcat(rba->targets, ",");
355 rba->targets = xmalloc(strlen(arg) + 1);
356 rba->targets[0] = '\0';
358 strcat(rba->targets, arg);
363 struct poptOption rpmBuildPoptTable[] = {
364 { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
365 buildArgCallback, 0, NULL, NULL },
366 { "buildarch", '\0', POPT_ARG_STRING, 0, POPT_BUILDARCH,
367 N_("override build architecture"), "ARCH" },
368 { "buildos", '\0', POPT_ARG_STRING, 0, POPT_BUILDOS,
369 N_("override build operating system"), "OS" },
370 { "buildroot", '\0', POPT_ARG_STRING, 0, POPT_BUILDROOT,
371 N_("override build root"), "DIRECTORY" },
372 { "clean", '\0', 0, 0, POPT_RMBUILD,
373 N_("remove build tree when done"), NULL},
374 { "nobuild", '\0', 0, &noBuild, POPT_NOBUILD,
375 N_("do not execute any stages of the build"), NULL },
376 { "nolang", '\0', 0, &noLang, POPT_NOLANG,
377 N_("do not accept I18N msgstr's from specfile"), NULL},
378 { "rmsource", '\0', 0, 0, POPT_RMSOURCE,
379 N_("remove sources when done"), NULL},
380 { "rmspec", '\0', 0, 0, POPT_RMSPEC,
381 N_("remove specfile when done"), NULL},
382 { "short-circuit", '\0', 0, 0, POPT_SHORTCIRCUIT,
383 N_("skip straight to specified stage (only for c,i)"), NULL },
384 { "target", '\0', POPT_ARG_STRING, 0, POPT_TARGETPLATFORM,
385 N_("override target platform"), "CPU-VENDOR-OS" },
386 { "usecatalog", '\0', 0, &useCatalog, POPT_USECATALOG,
387 N_("lookup I18N strings in specfile catalog"), NULL},
388 { 0, 0, 0, 0, 0, NULL, NULL }