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;
90 if (checking && !(isprint(*s) || isspace(*s))) return 0;
91 /*@switchbreak@*/ break;
101 static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
102 /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
103 /*@modifies ts, rpmGlobalMacroContext, fileSystem, internalState @*/
105 const char * passPhrase = ba->passPhrase;
106 const char * cookie = ba->cookie;
107 int buildAmount = ba->buildAmount;
108 const char * buildRootURL = NULL;
109 const char * specFile;
110 const char * specURL;
117 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
121 if (ba->buildRootOverride)
122 buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
125 /*@-compmempass@*/ /* FIX: static zcmds heartburn */
126 if (ba->buildMode == 't') {
128 const char * specDir;
131 rpmCompressedMagic res = COMPRESSED_OTHER;
132 /*@observer@*/ static const char *zcmds[] =
133 { "cat", "gunzip", "bunzip2", "cat" };
135 specDir = rpmGetPath("%{_specdir}", NULL);
137 tmpSpecFile = rpmGetPath("%{_specdir}/", "rpm-spec.XXXXXX", NULL);
138 #if defined(HAVE_MKSTEMP)
139 (void) close(mkstemp(tmpSpecFile));
141 (void) mktemp(tmpSpecFile);
144 (void) isCompressed(arg, &res);
146 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
147 sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
148 zcmds[res & 0x3], arg, tmpSpecFile);
149 if (!(fp = popen(cmd, "r"))) {
150 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
151 specDir = _free(specDir);
152 tmpSpecFile = _free(tmpSpecFile);
155 if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
159 sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 2>&1 > %s",
160 zcmds[res & 0x3], arg, tmpSpecFile);
161 if (!(fp = popen(cmd, "r"))) {
162 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
163 specDir = _free(specDir);
164 tmpSpecFile = _free(tmpSpecFile);
167 if (!fgets(buf, sizeof(buf) - 1, fp)) {
169 rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
171 (void) unlink(tmpSpecFile);
172 specDir = _free(specDir);
173 tmpSpecFile = _free(tmpSpecFile);
180 while (*cmd != '\0') {
181 if (*cmd == '/') s = cmd + 1;
187 /* remove trailing \n */
188 s = cmd + strlen(cmd) - 1;
191 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
192 sprintf(s, "%s/%s", specDir, cmd);
193 res = rename(tmpSpecFile, s);
194 specDir = _free(specDir);
197 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
199 (void) unlink(tmpSpecFile);
200 tmpSpecFile = _free(tmpSpecFile);
203 tmpSpecFile = _free(tmpSpecFile);
205 /* Make the directory which contains the tarball the source
206 directory for this run */
209 (void)getcwd(buf, BUFSIZ);
215 cmd = buf + strlen(buf) - 1;
216 while (*cmd != '/') cmd--;
219 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
225 specut = urlPath(specURL, &specFile);
226 if (*specFile != '/') {
227 char *s = alloca(BUFSIZ);
228 (void)getcwd(s, BUFSIZ);
234 if (specut != URL_IS_DASH) {
236 if (Stat(specURL, &st) < 0) {
237 rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
241 if (! S_ISREG(st.st_mode)) {
242 rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
248 /* Try to verify that the file is actually a specfile */
249 if (!isSpecFile(specURL)) {
250 rpmError(RPMERR_BADSPEC,
251 _("File %s does not appear to be a specfile.\n"), specURL);
257 /* Parse the spec file */
258 #define _anyarch(_f) \
259 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
260 if (parseSpec(ts, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
261 cookie, _anyarch(buildAmount), ba->force))
267 if ((spec = rpmtsSetSpec(ts, NULL)) == NULL) {
272 /* Assemble source header from parsed components */
273 initSourceHeader(spec);
275 /* Check build prerequisites */
276 if (!ba->noDeps && checkSpec(ts, spec->sourceHeader)) {
281 if (buildSpec(ts, spec, buildAmount, ba->noBuild)) {
286 if (ba->buildMode == 't')
287 (void) Unlink(specURL);
291 spec = freeSpec(spec);
292 buildRootURL = _free(buildRootURL);
297 int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
301 char * targets = ba->targets;
302 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
303 int cleanFlags = ba->buildAmount & buildCleanMask;
304 rpmVSFlags vsflags, ovsflags;
306 vsflags = rpmExpandNumeric("%{_vsflags_build}");
307 if (ba->qva_flags & VERIFY_DIGEST)
308 vsflags |= _RPMVSF_NODIGESTS;
309 if (ba->qva_flags & VERIFY_SIGNATURE)
310 vsflags |= _RPMVSF_NOSIGNATURES;
311 if (ba->qva_flags & VERIFY_HDRCHK)
312 vsflags |= RPMVSF_NOHDRCHK;
313 ovsflags = rpmtsSetVSFlags(ts, vsflags);
315 if (targets == NULL) {
316 rc = buildForTarget(ts, arg, ba);
320 /* parse up the build operators */
322 printf(_("Building target platforms: %s\n"), targets);
324 ba->buildAmount &= ~buildCleanMask;
325 for (t = targets; *t != '\0'; t = te) {
327 if ((te = strchr(t, ',')) == NULL)
329 target = alloca(te-t+1);
330 strncpy(target, t, (te-t));
334 else /* XXX Perform clean-up after last target build. */
335 ba->buildAmount |= cleanFlags;
337 printf(_("Building for target %s\n"), target);
339 /* Read in configuration for target. */
341 (void) rpmReadConfigFiles(rcfile, target);
342 rc = buildForTarget(ts, arg, ba);
348 vsflags = rpmtsSetVSFlags(ts, ovsflags);
349 /* Restore original configuration. */
351 (void) rpmReadConfigFiles(rcfile, NULL);