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 rpm database in %s\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;
103 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
106 if (ba->buildRootOverride)
107 buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
112 const char * tmpSpecFile;
114 rpmCompressedMagic res = COMPRESSED_OTHER;
115 static const char *zcmds[] = { "cat", "gunzip", "bunzip2", "cat" };
117 specDir = rpmGetPath("%{_specdir}", NULL);
120 strcpy(tfn, "rpm-spec.XXXXXX");
121 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
124 isCompressed(arg, &res);
126 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
127 sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
128 zcmds[res & 0x3], arg, tmpSpecFile);
129 if (!(fp = popen(cmd, "r"))) {
130 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m"));
135 if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
139 sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 2>&1 > %s",
140 zcmds[res & 0x3], arg, tmpSpecFile);
141 if (!(fp = popen(cmd, "r"))) {
142 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m"));
147 if (!fgets(buf, sizeof(buf) - 1, fp)) {
149 rpmError(RPMERR_READ, _("Failed to read spec file from %s"), arg);
160 if (*cmd == '/') s = cmd + 1;
166 /* remove trailing \n */
167 s = cmd + strlen(cmd) - 1;
170 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
171 sprintf(s, "%s/%s", specDir, cmd);
172 res = rename(tmpSpecFile, s);
176 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m"),
184 /* Make the directory which contains the tarball the source
185 directory for this run */
188 (void)getcwd(buf, BUFSIZ);
194 cmd = buf + strlen(buf) - 1;
195 while (*cmd != '/') cmd--;
198 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
203 specut = urlPath(specURL, &specFile);
204 if (*specFile != '/') {
205 char *s = alloca(BUFSIZ);
206 (void)getcwd(s, BUFSIZ);
212 if (specut != URL_IS_DASH) {
214 if (Stat(specURL, &st) < 0) {
215 rpmError(RPMERR_STAT, _("failed to stat %s: %m"), specURL);
219 if (! S_ISREG(st.st_mode)) {
220 rpmError(RPMERR_NOTREG, _("File %s is not a regular file."),
226 /* Try to verify that the file is actually a specfile */
227 if (!isSpecFile(specURL)) {
228 rpmError(RPMERR_BADSPEC, _("File %s does not appear to be a specfile."),
235 /* Parse the spec file */
236 #define _anyarch(_f) \
237 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
238 if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
239 cookie, _anyarch(buildAmount), force)) {
245 /* Assemble source header from parsed components */
246 initSourceHeader(spec);
248 /* Check build prerequisites */
249 if (!nodeps && checkSpec(spec->sourceHeader)) {
254 if (buildSpec(spec, buildAmount, test)) {
259 if (fromTarball) Unlink(specURL);
271 int build(const char * arg, struct rpmBuildArguments * ba,
272 const char * passPhrase, int fromTarball, char * cookie,
273 const char * rcfile, int force, int nodeps)
277 char *targets = ba->targets;
278 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
279 int cleanFlags = ba->buildAmount & buildCleanMask;
281 if (targets == NULL) {
282 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
287 /* parse up the build operators */
289 printf(_("Building target platforms: %s\n"), targets);
291 ba->buildAmount &= ~buildCleanMask;
292 for (t = targets; *t != '\0'; t = te) {
294 if ((te = strchr(t, ',')) == NULL)
296 target = alloca(te-t+1);
297 strncpy(target, t, (te-t));
301 else /* XXX Perform clean-up after last target build. */
302 ba->buildAmount |= cleanFlags;
304 printf(_("Building for target %s\n"), target);
306 /* Read in configuration for target. */
308 rpmReadConfigFiles(rcfile, target);
309 rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
316 /* Restore original configuration. */
318 rpmReadConfigFiles(rcfile, NULL);