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"),
66 specfile, Fstrerror(fd));
69 count = Fread(buf, sizeof(buf[0]), sizeof(buf), fd);
73 for (s = buf; count--; s++) {
83 if (checking && !(isprint(*s) || isspace(*s))) return 0;
90 static int buildForTarget(const char *arg, struct rpmBuildArguments *ba,
91 const char *passPhrase, char *cookie)
93 int buildAmount = ba->buildAmount;
94 const char *buildRootURL = NULL;
95 const char * specFile;
103 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
106 if (ba->buildRootOverride)
107 buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
109 if (ba->buildMode == 't') {
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\n"));
131 free((void *)specDir);
132 free((void *)tmpSpecFile);
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\n"));
143 free((void *)specDir);
144 free((void *)tmpSpecFile);
147 if (!fgets(buf, sizeof(buf) - 1, fp)) {
149 rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
152 free((void *)specDir);
153 free((void *)tmpSpecFile);
161 if (*cmd == '/') s = cmd + 1;
167 /* remove trailing \n */
168 s = cmd + strlen(cmd) - 1;
171 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
172 sprintf(s, "%s/%s", specDir, cmd);
173 res = rename(tmpSpecFile, s);
174 free((void *)specDir);
177 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
180 free((void *)tmpSpecFile);
183 free((void *)tmpSpecFile);
185 /* Make the directory which contains the tarball the source
186 directory for this run */
189 (void)getcwd(buf, BUFSIZ);
195 cmd = buf + strlen(buf) - 1;
196 while (*cmd != '/') cmd--;
199 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
204 specut = urlPath(specURL, &specFile);
205 if (*specFile != '/') {
206 char *s = alloca(BUFSIZ);
207 (void)getcwd(s, BUFSIZ);
213 if (specut != URL_IS_DASH) {
215 if (Stat(specURL, &st) < 0) {
216 rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
220 if (! S_ISREG(st.st_mode)) {
221 rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
227 /* Try to verify that the file is actually a specfile */
228 if (!isSpecFile(specURL)) {
229 rpmError(RPMERR_BADSPEC,
230 _("File %s does not appear to be a specfile.\n"), specURL);
236 /* Parse the spec file */
237 #define _anyarch(_f) \
238 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
239 if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
240 cookie, _anyarch(buildAmount), ba->force)) {
246 /* Assemble source header from parsed components */
247 initSourceHeader(spec);
249 /* Check build prerequisites */
250 if (!ba->noDeps && checkSpec(spec->sourceHeader)) {
255 if (buildSpec(spec, buildAmount, ba->noBuild)) {
260 if (ba->buildMode == 't') Unlink(specURL);
267 free((void *)buildRootURL);
271 int build(const char * arg, struct rpmBuildArguments * ba,
272 const char * passPhrase, char * cookie, const char * rcfile)
276 char *targets = ba->targets;
277 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
278 int cleanFlags = ba->buildAmount & buildCleanMask;
280 if (targets == NULL) {
281 rc = buildForTarget(arg, ba, passPhrase, cookie);
285 /* parse up the build operators */
287 printf(_("Building target platforms: %s\n"), targets);
289 ba->buildAmount &= ~buildCleanMask;
290 for (t = targets; *t != '\0'; t = te) {
292 if ((te = strchr(t, ',')) == NULL)
294 target = alloca(te-t+1);
295 strncpy(target, t, (te-t));
299 else /* XXX Perform clean-up after last target build. */
300 ba->buildAmount |= cleanFlags;
302 printf(_("Building for target %s\n"), target);
304 /* Read in configuration for target. */
306 rpmReadConfigFiles(rcfile, target);
307 rc = buildForTarget(arg, ba, passPhrase, cookie);
313 /* Restore original configuration. */
315 rpmReadConfigFiles(rcfile, NULL);