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);
119 /* XXX Using mkstemp is difficult here. */
120 /* XXX FWIW, default %{_specdir} is root.root 0755 */
122 strcpy(tfn, "rpm-spec.XXXXXX");
123 tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
126 isCompressed(arg, &res);
128 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
129 sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
130 zcmds[res & 0x3], arg, tmpSpecFile);
131 if (!(fp = popen(cmd, "r"))) {
132 rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
133 free((void *)specDir);
134 free((void *)tmpSpecFile);
137 if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
141 sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 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 free((void *)specDir);
146 free((void *)tmpSpecFile);
149 if (!fgets(buf, sizeof(buf) - 1, fp)) {
151 rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
154 free((void *)specDir);
155 free((void *)tmpSpecFile);
163 if (*cmd == '/') s = cmd + 1;
169 /* remove trailing \n */
170 s = cmd + strlen(cmd) - 1;
173 specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
174 sprintf(s, "%s/%s", specDir, cmd);
175 res = rename(tmpSpecFile, s);
176 free((void *)specDir);
179 rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
182 free((void *)tmpSpecFile);
185 free((void *)tmpSpecFile);
187 /* Make the directory which contains the tarball the source
188 directory for this run */
191 (void)getcwd(buf, BUFSIZ);
197 cmd = buf + strlen(buf) - 1;
198 while (*cmd != '/') cmd--;
201 addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
206 specut = urlPath(specURL, &specFile);
207 if (*specFile != '/') {
208 char *s = alloca(BUFSIZ);
209 (void)getcwd(s, BUFSIZ);
215 if (specut != URL_IS_DASH) {
217 if (Stat(specURL, &st) < 0) {
218 rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
222 if (! S_ISREG(st.st_mode)) {
223 rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
229 /* Try to verify that the file is actually a specfile */
230 if (!isSpecFile(specURL)) {
231 rpmError(RPMERR_BADSPEC,
232 _("File %s does not appear to be a specfile.\n"), specURL);
238 /* Parse the spec file */
239 #define _anyarch(_f) \
240 (((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
241 if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
242 cookie, _anyarch(buildAmount), ba->force)) {
248 /* Assemble source header from parsed components */
249 initSourceHeader(spec);
251 /* Check build prerequisites */
252 if (!ba->noDeps && checkSpec(spec->sourceHeader)) {
257 if (buildSpec(spec, buildAmount, ba->noBuild)) {
262 if (ba->buildMode == 't') Unlink(specURL);
269 free((void *)buildRootURL);
273 int build(const char * arg, struct rpmBuildArguments * ba,
274 const char * passPhrase, char * cookie, const char * rcfile)
278 char *targets = ba->targets;
279 #define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
280 int cleanFlags = ba->buildAmount & buildCleanMask;
282 if (targets == NULL) {
283 rc = buildForTarget(arg, ba, passPhrase, cookie);
287 /* parse up the build operators */
289 printf(_("Building target platforms: %s\n"), targets);
291 ba->buildAmount &= ~buildCleanMask;
292 for (t = targets; *t != '\0'; t = te) {
294 if ((te = strchr(t, ',')) == NULL)
296 target = alloca(te-t+1);
297 strncpy(target, t, (te-t));
301 else /* XXX Perform clean-up after last target build. */
302 ba->buildAmount |= cleanFlags;
304 printf(_("Building for target %s\n"), target);
306 /* Read in configuration for target. */
308 rpmReadConfigFiles(rcfile, target);
309 rc = buildForTarget(arg, ba, passPhrase, cookie);
315 /* Restore original configuration. */
317 rpmReadConfigFiles(rcfile, NULL);