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 rpmError(RPMERR_OPEN, _("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 rpmError(RPMERR_OPEN, _("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 *buildRootURL = NULL;
94 int test = ba->noBuild;
95 const char * specFile;
102 if (ba->buildRootOverride)
103 buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
108 const char * tmpSpecFile;
111 static const char *zcmds[] = { "cat", "gunzip", "bunzip2", "cat" };
113 specDir = rpmGetPath("%{_specdir}", NULL);
116 strcpy(tfn, "rpm-spec.XXXXXX");
117 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
120 isCompressed(arg, &res);
122 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
123 sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
124 zcmds[res & 0x3], arg, tmpSpecFile);
125 if (!(fp = popen(cmd, "r"))) {
126 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m"));
131 if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
135 sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 2>&1 > %s",
136 zcmds[res & 0x3], arg, tmpSpecFile);
137 if (!(fp = popen(cmd, "r"))) {
138 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m"));
143 if (!fgets(buf, sizeof(buf) - 1, fp)) {
145 rpmError(RPMERR_READ, _("Failed to read spec file from %s"), arg);
156 if (*cmd == '/') s = cmd + 1;
162 /* remove trailing \n */
163 s = cmd + strlen(cmd) - 1;
166 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
167 sprintf(s, "%s/%s", specDir, cmd);
168 res = rename(tmpSpecFile, s);
172 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m"),
180 /* Make the directory which contains the tarball the source
181 directory for this run */
184 (void)getcwd(buf, BUFSIZ);
190 cmd = buf + strlen(buf) - 1;
191 while (*cmd != '/') cmd--;
194 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
199 specut = urlPath(specURL, &specFile);
200 if (*specFile != '/') {
201 char *s = alloca(BUFSIZ);
202 (void)getcwd(s, BUFSIZ);
208 if (specut != URL_IS_DASH) {
210 if (Stat(specURL, &st) < 0) {
211 rpmError(RPMERR_STAT, _("failed to stat %s: %m"), specURL);
215 if (! S_ISREG(st.st_mode)) {
216 rpmError(RPMERR_NOTREG, _("File %s is not a regular file."),
222 /* Try to verify that the file is actually a specfile */
223 if (!isSpecFile(specURL)) {
224 rpmError(RPMERR_BADSPEC, _("File %s does not appear to be a specfile."),
231 /* Parse the spec file */
232 #define _anyarch(_f) \
233 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
234 if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
235 cookie, _anyarch(buildAmount), force)) {
241 /* Assemble source header from parsed components */
242 initSourceHeader(spec);
244 /* Check build prerequisites */
245 if (!nodeps && checkSpec(spec->sourceHeader)) {
250 if (buildSpec(spec, buildAmount, test)) {
255 if (fromTarball) Unlink(specURL);
267 int build(const char * arg, struct rpmBuildArguments * ba,
268 const char * passPhrase, int fromTarball, char * cookie,
269 const char * rcfile, int force, int nodeps)
273 char *targets = ba->targets;
274 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
275 int cleanFlags = ba->buildAmount & buildCleanMask;
277 if (targets == NULL) {
278 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
283 /* parse up the build operators */
285 printf(_("Building target platforms: %s\n"), targets);
287 ba->buildAmount &= ~buildCleanMask;
288 for (t = targets; *t != '\0'; t = te) {
290 if ((te = strchr(t, ',')) == NULL)
292 target = alloca(te-t+1);
293 strncpy(target, t, (te-t));
297 else /* XXX Perform clean-up after last target build. */
298 ba->buildAmount |= cleanFlags;
300 printf(_("Building for target %s\n"), target);
302 /* Read in configuration for target. */
304 rpmReadConfigFiles(rcfile, target);
305 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
312 /* Restore original configuration. */
314 rpmReadConfigFiles(rcfile, NULL);