2 * Parse spec file and build package.
13 /*@access rpmTransactionSet @*/ /* XXX compared with NULL @*/
14 /*@access rpmdb @*/ /* XXX compared with NULL @*/
15 /*@access FD_t @*/ /* XXX compared with NULL @*/
19 static int checkSpec(rpmTransactionSet ts, Header h)
20 /*@globals fileSystem, internalState @*/
21 /*@modifies ts, h, fileSystem, internalState @*/
23 rpmDependencyConflict conflicts;
27 if (!headerIsEntry(h, RPMTAG_REQUIRENAME)
28 && !headerIsEntry(h, RPMTAG_CONFLICTNAME))
31 rc = rpmtransAddPackage(ts, h, NULL, NULL, 0, NULL);
33 rc = rpmdepCheck(ts, &conflicts, &numConflicts);
35 if (rc == 0 && conflicts) {
36 rpmMessage(RPMMESS_ERROR, _("failed build dependencies:\n"));
37 printDepProblems(stderr, conflicts, numConflicts);
38 conflicts = rpmdepFreeConflicts(conflicts, numConflicts);
47 * Kurwa, durni ameryka?ce sobe zawsze my?l?, ?e ca?y ?wiat mówi po
50 /* XXX this is still a dumb test but at least it's i18n aware */
53 static int isSpecFile(const char * specfile)
54 /*@globals fileSystem @*/
55 /*@modifies fileSystem @*/
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++) {
78 /*@switchbreak@*/ break;
81 /*@switchbreak@*/ break;
83 if (checking && !(isprint(*s) || isspace(*s))) return 0;
84 /*@switchbreak@*/ break;
92 static int buildForTarget(rpmTransactionSet ts, const char * arg, BTA_t ba)
93 /*@globals rpmGlobalMacroContext,
94 fileSystem, internalState @*/
95 /*@modifies ts, rpmGlobalMacroContext,
96 fileSystem, internalState @*/
98 const char * passPhrase = ba->passPhrase;
99 const char * cookie = ba->cookie;
100 int buildAmount = ba->buildAmount;
101 const char * buildRootURL = NULL;
102 const char * specFile;
103 const char * specURL;
110 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
114 if (ba->buildRootOverride)
115 buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
118 if (ba->buildMode == 't') {
120 const char * specDir;
121 const char * tmpSpecFile;
123 rpmCompressedMagic res = COMPRESSED_OTHER;
124 /*@observer@*/ static const char *zcmds[] =
125 { "cat", "gunzip", "bunzip2", "cat" };
127 specDir = rpmGetPath("%{_specdir}", NULL);
129 /* XXX Using mkstemp is difficult here. */
130 /* XXX FWIW, default %{_specdir} is root.root 0755 */
132 strcpy(tfn, "rpm-spec.XXXXXX");
134 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
138 (void) isCompressed(arg, &res);
140 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
141 sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
142 zcmds[res & 0x3], arg, tmpSpecFile);
143 if (!(fp = popen(cmd, "r"))) {
144 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
145 specDir = _free(specDir);
146 tmpSpecFile = _free(tmpSpecFile);
149 if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
153 sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 2>&1 > %s",
154 zcmds[res & 0x3], arg, tmpSpecFile);
155 if (!(fp = popen(cmd, "r"))) {
156 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
157 specDir = _free(specDir);
158 tmpSpecFile = _free(tmpSpecFile);
161 if (!fgets(buf, sizeof(buf) - 1, fp)) {
163 rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
165 (void) unlink(tmpSpecFile);
166 specDir = _free(specDir);
167 tmpSpecFile = _free(tmpSpecFile);
174 while (*cmd != '\0') {
175 if (*cmd == '/') s = cmd + 1;
181 /* remove trailing \n */
182 s = cmd + strlen(cmd) - 1;
185 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
186 sprintf(s, "%s/%s", specDir, cmd);
187 res = rename(tmpSpecFile, s);
188 specDir = _free(specDir);
191 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
193 (void) unlink(tmpSpecFile);
194 tmpSpecFile = _free(tmpSpecFile);
197 tmpSpecFile = _free(tmpSpecFile);
199 /* Make the directory which contains the tarball the source
200 directory for this run */
203 (void)getcwd(buf, BUFSIZ);
209 cmd = buf + strlen(buf) - 1;
210 while (*cmd != '/') cmd--;
213 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
218 specut = urlPath(specURL, &specFile);
219 if (*specFile != '/') {
220 char *s = alloca(BUFSIZ);
221 (void)getcwd(s, BUFSIZ);
227 if (specut != URL_IS_DASH) {
229 if (Stat(specURL, &st) < 0) {
230 rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
234 if (! S_ISREG(st.st_mode)) {
235 rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
241 /* Try to verify that the file is actually a specfile */
242 if (!isSpecFile(specURL)) {
243 rpmError(RPMERR_BADSPEC,
244 _("File %s does not appear to be a specfile.\n"), specURL);
250 /* Parse the spec file */
251 #define _anyarch(_f) \
252 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
253 if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
254 cookie, _anyarch(buildAmount), ba->force)) {
260 /* Assemble source header from parsed components */
261 initSourceHeader(spec);
263 /* Check build prerequisites */
264 if (!ba->noDeps && checkSpec(ts, spec->sourceHeader)) {
269 if (buildSpec(spec, buildAmount, ba->noBuild)) {
274 if (ba->buildMode == 't')
275 (void) Unlink(specURL);
279 spec = freeSpec(spec);
280 buildRootURL = _free(buildRootURL);
284 int build(rpmTransactionSet ts, const char * arg, BTA_t ba, const char * rcfile)
288 char * targets = ba->targets;
289 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
290 int cleanFlags = ba->buildAmount & buildCleanMask;
292 if (targets == NULL) {
293 rc = buildForTarget(ts, arg, ba);
297 /* parse up the build operators */
299 printf(_("Building target platforms: %s\n"), targets);
301 ba->buildAmount &= ~buildCleanMask;
302 for (t = targets; *t != '\0'; t = te) {
304 if ((te = strchr(t, ',')) == NULL)
306 target = alloca(te-t+1);
307 strncpy(target, t, (te-t));
311 else /* XXX Perform clean-up after last target build. */
312 ba->buildAmount |= cleanFlags;
314 printf(_("Building for target %s\n"), target);
316 /* Read in configuration for target. */
318 (void) rpmReadConfigFiles(rcfile, target);
319 rc = buildForTarget(ts, arg, ba);
325 /* Restore original configuration. */
327 (void) rpmReadConfigFiles(rcfile, NULL);