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, 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 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, 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;
129 const char * tmpSpecFile;
131 rpmCompressedMagic res = COMPRESSED_OTHER;
132 /*@observer@*/ static const char *zcmds[] =
133 { "cat", "gunzip", "bunzip2", "cat" };
135 specDir = rpmGetPath("%{_specdir}", NULL);
137 /* XXX Using mkstemp is difficult here. */
138 /* XXX FWIW, default %{_specdir} is root.root 0755 */
140 strcpy(tfn, "rpm-spec.XXXXXX");
142 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
146 (void) isCompressed(arg, &res);
148 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
149 sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
150 zcmds[res & 0x3], arg, tmpSpecFile);
151 if (!(fp = popen(cmd, "r"))) {
152 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
153 specDir = _free(specDir);
154 tmpSpecFile = _free(tmpSpecFile);
157 if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
161 sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 2>&1 > %s",
162 zcmds[res & 0x3], arg, tmpSpecFile);
163 if (!(fp = popen(cmd, "r"))) {
164 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
165 specDir = _free(specDir);
166 tmpSpecFile = _free(tmpSpecFile);
169 if (!fgets(buf, sizeof(buf) - 1, fp)) {
171 rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
173 (void) unlink(tmpSpecFile);
174 specDir = _free(specDir);
175 tmpSpecFile = _free(tmpSpecFile);
182 while (*cmd != '\0') {
183 if (*cmd == '/') s = cmd + 1;
189 /* remove trailing \n */
190 s = cmd + strlen(cmd) - 1;
193 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
194 sprintf(s, "%s/%s", specDir, cmd);
195 res = rename(tmpSpecFile, s);
196 specDir = _free(specDir);
199 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
201 (void) unlink(tmpSpecFile);
202 tmpSpecFile = _free(tmpSpecFile);
205 tmpSpecFile = _free(tmpSpecFile);
207 /* Make the directory which contains the tarball the source
208 directory for this run */
211 (void)getcwd(buf, BUFSIZ);
217 cmd = buf + strlen(buf) - 1;
218 while (*cmd != '/') cmd--;
221 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
227 specut = urlPath(specURL, &specFile);
228 if (*specFile != '/') {
229 char *s = alloca(BUFSIZ);
230 (void)getcwd(s, BUFSIZ);
236 if (specut != URL_IS_DASH) {
238 if (Stat(specURL, &st) < 0) {
239 rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
243 if (! S_ISREG(st.st_mode)) {
244 rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
250 /* Try to verify that the file is actually a specfile */
251 if (!isSpecFile(specURL)) {
252 rpmError(RPMERR_BADSPEC,
253 _("File %s does not appear to be a specfile.\n"), specURL);
259 /* Parse the spec file */
260 #define _anyarch(_f) \
261 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
262 if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
263 cookie, _anyarch(buildAmount), ba->force)) {
269 /* Assemble source header from parsed components */
270 initSourceHeader(spec);
272 /* Check build prerequisites */
273 if (!ba->noDeps && checkSpec(ts, spec->sourceHeader)) {
278 if (buildSpec(spec, buildAmount, ba->noBuild)) {
283 if (ba->buildMode == 't')
284 (void) Unlink(specURL);
288 spec = freeSpec(spec);
289 buildRootURL = _free(buildRootURL);
294 int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
298 char * targets = ba->targets;
299 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
300 int cleanFlags = ba->buildAmount & buildCleanMask;
301 rpmVSFlags vsflags, ovsflags;
303 vsflags = rpmExpandNumeric("%{_vsflags_build}");
304 if (ba->qva_flags & VERIFY_DIGEST)
305 vsflags |= _RPMVSF_NODIGESTS;
306 if (ba->qva_flags & VERIFY_SIGNATURE)
307 vsflags |= _RPMVSF_NOSIGNATURES;
308 if (ba->qva_flags & VERIFY_HDRCHK)
309 vsflags |= RPMVSF_NOHDRCHK;
310 ovsflags = rpmtsSetVSFlags(ts, vsflags);
312 if (targets == NULL) {
313 rc = buildForTarget(ts, arg, ba);
317 /* parse up the build operators */
319 printf(_("Building target platforms: %s\n"), targets);
321 ba->buildAmount &= ~buildCleanMask;
322 for (t = targets; *t != '\0'; t = te) {
324 if ((te = strchr(t, ',')) == NULL)
326 target = alloca(te-t+1);
327 strncpy(target, t, (te-t));
331 else /* XXX Perform clean-up after last target build. */
332 ba->buildAmount |= cleanFlags;
334 printf(_("Building for target %s\n"), target);
336 /* Read in configuration for target. */
338 (void) rpmReadConfigFiles(rcfile, target);
339 rc = buildForTarget(ts, arg, ba);
345 vsflags = rpmtsSetVSFlags(ts, ovsflags);
346 /* Restore original configuration. */
348 (void) rpmReadConfigFiles(rcfile, NULL);