2 * Parse spec file and build package.
17 /*@access rpmts @*/ /* XXX compared with NULL @*/
18 /*@access rpmdb @*/ /* XXX compared with NULL @*/
19 /*@access FD_t @*/ /* XXX compared with NULL @*/
23 static int checkSpec(rpmts ts, Header h)
24 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
25 /*@modifies ts, h, rpmGlobalMacroContext, fileSystem, internalState @*/
30 if (!headerIsEntry(h, RPMTAG_REQUIRENAME)
31 && !headerIsEntry(h, RPMTAG_CONFLICTNAME))
34 rc = rpmtsAddInstallElement(ts, h, NULL, 0, NULL);
38 ps = rpmtsProblems(ts);
39 if (rc == 0 && rpmpsNumProblems(ps) > 0) {
40 rpmMessage(RPMMESS_ERROR, _("Failed build dependencies:\n"));
46 /* XXX nuke the added package. */
53 * Kurwa, durni ameryka?ce sobe zawsze my?l?, ?e ca?y ?wiat mówi po
56 /* XXX this is still a dumb test but at least it's i18n aware */
59 static int isSpecFile(const char * specfile)
60 /*@globals h_errno, fileSystem, internalState @*/
61 /*@modifies fileSystem, internalState @*/
69 fd = Fopen(specfile, "r.ufdio");
70 if (fd == NULL || Ferror(fd)) {
71 rpmError(RPMERR_OPEN, _("Unable to open spec file %s: %s\n"),
72 specfile, Fstrerror(fd));
75 count = Fread(buf, sizeof(buf[0]), sizeof(buf), fd);
79 for (s = buf; count--; s++) {
84 /*@switchbreak@*/ break;
87 /*@switchbreak@*/ break;
91 if (checking && !(isprint(*s) || isspace(*s))) return 0;
92 /*@switchbreak@*/ break;
94 if (checking && !(isprint(*s) || isspace(*s)) && *(unsigned char *)s < 32) return 0;
95 /*@switchbreak@*/ break;
106 static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
107 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
108 /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/
110 const char * passPhrase = ba->passPhrase;
111 const char * cookie = ba->cookie;
112 int buildAmount = ba->buildAmount;
113 const char * buildRootURL = NULL;
114 const char * specFile;
115 const char * specURL;
122 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
126 if (ba->buildRootOverride)
127 buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
130 /*@-compmempass@*/ /* FIX: static zcmds heartburn */
131 if (ba->buildMode == 't') {
133 const char * specDir;
136 rpmCompressedMagic res = COMPRESSED_OTHER;
137 /*@observer@*/ static const char *zcmds[] =
138 { "cat", "gunzip", "bunzip2", "cat" };
140 specDir = rpmGetPath("%{_specdir}", NULL);
142 tmpSpecFile = (char *) rpmGetPath("%{_specdir}/", "rpm-spec.XXXXXX", NULL);
143 #if defined(HAVE_MKSTEMP)
144 (void) close(mkstemp(tmpSpecFile));
146 (void) mktemp(tmpSpecFile);
149 (void) isCompressed(arg, &res);
151 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
152 sprintf(cmd, "%s < '%s' | tar xOvf - Specfile 2>&1 > '%s'",
153 zcmds[res & 0x3], arg, tmpSpecFile);
154 if (!(fp = popen(cmd, "r"))) {
155 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
156 specDir = _free(specDir);
157 tmpSpecFile = _free(tmpSpecFile);
160 if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
164 sprintf(cmd, "%s < '%s' | tar xOvf - --wildcards \\*.spec 2>&1 > '%s'",
165 zcmds[res & 0x3], arg, tmpSpecFile);
166 if (!(fp = popen(cmd, "r"))) {
167 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
168 specDir = _free(specDir);
169 tmpSpecFile = _free(tmpSpecFile);
172 if (!fgets(buf, sizeof(buf) - 1, fp)) {
174 rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
176 (void) unlink(tmpSpecFile);
177 specDir = _free(specDir);
178 tmpSpecFile = _free(tmpSpecFile);
185 while (*cmd != '\0') {
186 if (*cmd == '/') s = cmd + 1;
192 /* remove trailing \n */
193 s = cmd + strlen(cmd) - 1;
196 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
197 sprintf(s, "%s/%s", specDir, cmd);
198 res = rename(tmpSpecFile, s);
199 specDir = _free(specDir);
202 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
204 (void) unlink(tmpSpecFile);
205 tmpSpecFile = _free(tmpSpecFile);
208 tmpSpecFile = _free(tmpSpecFile);
210 /* Make the directory which contains the tarball the source
211 directory for this run */
214 if (!getcwd(buf, BUFSIZ)) {
215 rpmError(RPMERR_STAT, "getcwd failed: %m\n");
223 cmd = buf + strlen(buf) - 1;
224 while (*cmd != '/') cmd--;
227 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
233 specut = urlPath(specURL, &specFile);
234 if (*specFile != '/') {
235 char *s = alloca(BUFSIZ);
236 if (!getcwd(s, BUFSIZ)) {
237 rpmError(RPMERR_STAT, "getcwd failed: %m\n");
246 if (specut != URL_IS_DASH) {
248 if (Stat(specURL, &st) < 0) {
249 rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
253 if (! S_ISREG(st.st_mode)) {
254 rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
260 /* Try to verify that the file is actually a specfile */
261 if (!isSpecFile(specURL)) {
262 rpmError(RPMERR_BADSPEC,
263 _("File %s does not appear to be a specfile.\n"), specURL);
269 /* Parse the spec file */
270 #define _anyarch(_f) \
271 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
272 if (parseSpec(ts, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
273 cookie, _anyarch(buildAmount), ba->force))
279 if ((spec = rpmtsSetSpec(ts, NULL)) == NULL) {
284 /* Assemble source header from parsed components */
285 initSourceHeader(spec);
287 /* Check build prerequisites */
288 if (!ba->noDeps && checkSpec(ts, spec->sourceHeader)) {
293 if (buildSpec(ts, spec, buildAmount, ba->noBuild)) {
298 if (ba->buildMode == 't')
299 (void) Unlink(specURL);
303 spec = freeSpec(spec);
304 buildRootURL = _free(buildRootURL);
309 int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
313 char * targets = ba->targets;
314 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
315 int cleanFlags = ba->buildAmount & buildCleanMask;
316 rpmVSFlags vsflags, ovsflags;
318 vsflags = rpmExpandNumeric("%{_vsflags_build}");
319 if (ba->qva_flags & VERIFY_DIGEST)
320 vsflags |= _RPMVSF_NODIGESTS;
321 if (ba->qva_flags & VERIFY_SIGNATURE)
322 vsflags |= _RPMVSF_NOSIGNATURES;
323 if (ba->qva_flags & VERIFY_HDRCHK)
324 vsflags |= RPMVSF_NOHDRCHK;
325 ovsflags = rpmtsSetVSFlags(ts, vsflags);
327 if (targets == NULL) {
328 rc = buildForTarget(ts, arg, ba);
332 /* parse up the build operators */
334 printf(_("Building target platforms: %s\n"), targets);
336 ba->buildAmount &= ~buildCleanMask;
337 for (t = targets; *t != '\0'; t = te) {
339 if ((te = strchr(t, ',')) == NULL)
341 target = alloca(te-t+1);
342 strncpy(target, t, (te-t));
346 else /* XXX Perform clean-up after last target build. */
347 ba->buildAmount |= cleanFlags;
349 printf(_("Building for target %s\n"), target);
351 /* Read in configuration for target. */
354 (void) rpmReadConfigFiles(rcfile, target);
355 rc = buildForTarget(ts, arg, ba);
361 vsflags = rpmtsSetVSFlags(ts, ovsflags);
362 /* Restore original configuration. */
365 (void) rpmReadConfigFiles(rcfile, NULL);