10 static int checkSpec(Header h)
16 struct rpmDependencyConflict * conflicts;
20 if (!headerIsEntry(h, RPMTAG_REQUIREFLAGS))
23 if (rpmdbOpen(rootdir, &db, mode, 0644)) {
25 dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL);
26 rpmError(RPMERR_OPEN, _("cannot open rpm database in %s\n"), dn);
30 ts = rpmtransCreateSet(db, rootdir);
32 rc = rpmtransAddPackage(ts, h, NULL, NULL, 0, NULL);
34 rc = rpmdepCheck(ts, &conflicts, &numConflicts);
35 if (rc == 0 && conflicts) {
36 rpmMessage(RPMMESS_ERROR, _("failed build dependencies:\n"));
37 printDepProblems(stderr, conflicts, numConflicts);
38 rpmdepFreeConflicts(conflicts, numConflicts);
51 * Kurwa, durni ameryka?ce sobe zawsze my?l?, ?e ca?y ?wiat mówi po
54 /* XXX this is still a dumb test but at least it's i18n aware */
55 static int isSpecFile(const char *specfile)
63 fd = Fopen(specfile, "r.ufdio");
64 if (fd == NULL || Ferror(fd)) {
65 rpmError(RPMERR_OPEN, _("Unable to open spec file %s: %s\n"), specfile, Fstrerror(fd));
68 count = Fread(buf, sizeof(buf[0]), sizeof(buf), 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, char *cookie)
92 int buildAmount = ba->buildAmount;
93 const char *buildRootURL = NULL;
94 const char * specFile;
102 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
105 if (ba->buildRootOverride)
106 buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
108 if (ba->buildMode == 't') {
111 const char * tmpSpecFile;
113 rpmCompressedMagic res = COMPRESSED_OTHER;
114 static const char *zcmds[] = { "cat", "gunzip", "bunzip2", "cat" };
116 specDir = rpmGetPath("%{_specdir}", NULL);
119 strcpy(tfn, "rpm-spec.XXXXXX");
120 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
123 isCompressed(arg, &res);
125 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
126 sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
127 zcmds[res & 0x3], arg, tmpSpecFile);
128 if (!(fp = popen(cmd, "r"))) {
129 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m"));
130 free((void *)specDir);
131 free((void *)tmpSpecFile);
134 if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
138 sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 2>&1 > %s",
139 zcmds[res & 0x3], arg, tmpSpecFile);
140 if (!(fp = popen(cmd, "r"))) {
141 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m"));
142 free((void *)specDir);
143 free((void *)tmpSpecFile);
146 if (!fgets(buf, sizeof(buf) - 1, fp)) {
148 rpmError(RPMERR_READ, _("Failed to read spec file from %s"), arg);
150 free((void *)specDir);
151 free((void *)tmpSpecFile);
159 if (*cmd == '/') s = cmd + 1;
165 /* remove trailing \n */
166 s = cmd + strlen(cmd) - 1;
169 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
170 sprintf(s, "%s/%s", specDir, cmd);
171 res = rename(tmpSpecFile, s);
172 free((void *)specDir);
175 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m"),
178 free((void *)tmpSpecFile);
181 free((void *)tmpSpecFile);
183 /* Make the directory which contains the tarball the source
184 directory for this run */
187 (void)getcwd(buf, BUFSIZ);
193 cmd = buf + strlen(buf) - 1;
194 while (*cmd != '/') cmd--;
197 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
202 specut = urlPath(specURL, &specFile);
203 if (*specFile != '/') {
204 char *s = alloca(BUFSIZ);
205 (void)getcwd(s, BUFSIZ);
211 if (specut != URL_IS_DASH) {
213 if (Stat(specURL, &st) < 0) {
214 rpmError(RPMERR_STAT, _("failed to stat %s: %m"), specURL);
218 if (! S_ISREG(st.st_mode)) {
219 rpmError(RPMERR_NOTREG, _("File %s is not a regular file."),
225 /* Try to verify that the file is actually a specfile */
226 if (!isSpecFile(specURL)) {
227 rpmError(RPMERR_BADSPEC, _("File %s does not appear to be a specfile."),
234 /* Parse the spec file */
235 #define _anyarch(_f) \
236 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
237 if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
238 cookie, _anyarch(buildAmount), ba->force)) {
244 /* Assemble source header from parsed components */
245 initSourceHeader(spec);
247 /* Check build prerequisites */
248 if (!ba->noDeps && checkSpec(spec->sourceHeader)) {
253 if (buildSpec(spec, buildAmount, ba->noBuild)) {
258 if (ba->buildMode == 't') Unlink(specURL);
265 free((void *)buildRootURL);
269 int build(const char * arg, struct rpmBuildArguments * ba,
270 const char * passPhrase, char * cookie, const char * rcfile)
274 char *targets = ba->targets;
275 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
276 int cleanFlags = ba->buildAmount & buildCleanMask;
278 if (targets == NULL) {
279 rc = buildForTarget(arg, ba, passPhrase, 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, cookie);
311 /* Restore original configuration. */
313 rpmReadConfigFiles(rcfile, NULL);