+/** \ingroup rpmcli
+ * Parse spec file and build package.
+ */
+
#include "system.h"
+#include <rpmcli.h>
#include <rpmbuild.h>
-#include <rpmurl.h>
+
+#include "rpmps.h"
+#include "rpmte.h"
+#include "rpmts.h"
#include "build.h"
-#include "install.h"
+#include "debug.h"
-static int checkSpec(Header h)
+/*@access rpmts @*/ /* XXX compared with NULL @*/
+/*@access rpmdb @*/ /* XXX compared with NULL @*/
+/*@access FD_t @*/ /* XXX compared with NULL @*/
+
+/**
+ */
+static int checkSpec(rpmts ts, Header h)
+ /*@globals fileSystem, internalState @*/
+ /*@modifies ts, h, fileSystem, internalState @*/
{
- char *rootdir = NULL;
- rpmdb db = NULL;
- int mode = O_RDONLY;
- rpmTransactionSet ts;
- struct rpmDependencyConflict * conflicts;
- int numConflicts;
+ rpmps ps;
int rc;
- if (!headerIsEntry(h, RPMTAG_REQUIREFLAGS))
+ if (!headerIsEntry(h, RPMTAG_REQUIRENAME)
+ && !headerIsEntry(h, RPMTAG_CONFLICTNAME))
return 0;
- if (rpmdbOpen(rootdir, &db, mode, 0644)) {
- const char *dn;
- dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL);
- rpmMessage(RPMMESS_ERROR, _("cannot open %s/packages.rpm\n"), dn);
- xfree(dn);
- exit(EXIT_FAILURE);
- }
- ts = rpmtransCreateSet(db, rootdir);
+ rc = rpmtsAddPackage(ts, h, NULL, 0, NULL);
- rc = rpmtransAddPackage(ts, h, NULL, NULL, 0, NULL);
+ rc = rpmtsCheck(ts);
- rc = rpmdepCheck(ts, &conflicts, &numConflicts);
- if (rc == 0 && conflicts) {
- rpmMessage(RPMMESS_ERROR, _("failed build dependencies:\n"));
- printDepProblems(stderr, conflicts, numConflicts);
- rpmdepFreeConflicts(conflicts, numConflicts);
+ ps = rpmtsGetProblems(ts);
+ if (rc == 0 && ps) {
+ rpmMessage(RPMMESS_ERROR, _("Failed build dependencies:\n"));
+ printDepProblems(stderr, ps);
rc = 1;
}
+ ps = rpmpsFree(ps);
- if (ts)
- rpmtransFree(ts);
- if (db)
- rpmdbClose(db);
+ /* XXX nuke the added package. */
+ rpmtsClean(ts);
return rc;
}
* angielsku...
*/
/* XXX this is still a dumb test but at least it's i18n aware */
-static int isSpecFile(const char *specfile)
+/**
+ */
+static int isSpecFile(const char * specfile)
+ /*@globals fileSystem @*/
+ /*@modifies fileSystem @*/
{
char buf[256];
const char * s;
fd = Fopen(specfile, "r.ufdio");
if (fd == NULL || Ferror(fd)) {
- fprintf(stderr, _("Unable to open spec file %s: %s\n"), specfile, Fstrerror(fd));
+ rpmError(RPMERR_OPEN, _("Unable to open spec file %s: %s\n"),
+ specfile, Fstrerror(fd));
return 0;
}
count = Fread(buf, sizeof(buf[0]), sizeof(buf), fd);
- Fclose(fd);
+ (void) Fclose(fd);
checking = 1;
for (s = buf; count--; s++) {
case '\r':
case '\n':
checking = 1;
- break;
+ /*@switchbreak@*/ break;
case ':':
checking = 0;
- break;
+ /*@switchbreak@*/ break;
default:
if (checking && !(isprint(*s) || isspace(*s))) return 0;
- break;
+ /*@switchbreak@*/ break;
}
}
return 1;
}
-static int buildForTarget(const char *arg, struct rpmBuildArguments *ba,
- const char *passPhrase, int fromTarball, char *cookie,
- int force, int nodeps)
+/**
+ */
+static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
+ /*@globals rpmGlobalMacroContext,
+ fileSystem, internalState @*/
+ /*@modifies ts, rpmGlobalMacroContext,
+ fileSystem, internalState @*/
{
+ const char * passPhrase = ba->passPhrase;
+ const char * cookie = ba->cookie;
int buildAmount = ba->buildAmount;
- const char *buildRootURL = NULL;
- int test = ba->noBuild;
+ const char * buildRootURL = NULL;
const char * specFile;
const char * specURL;
int specut;
Spec spec = NULL;
int rc;
+#ifndef DYING
rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
+#endif
+ /*@-branchstate@*/
if (ba->buildRootOverride)
buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
+ /*@=branchstate@*/
- if (fromTarball) {
+ /*@-compmempass@*/ /* FIX: static zcmds heartburn */
+ if (ba->buildMode == 't') {
FILE *fp;
- const char *specDir;
+ const char * specDir;
const char * tmpSpecFile;
- char * cmd, *s;
- int res;
- static const char *zcmds[] = { "cat", "gunzip", "bunzip2", "cat" };
+ char * cmd, * s;
+ rpmCompressedMagic res = COMPRESSED_OTHER;
+ /*@observer@*/ static const char *zcmds[] =
+ { "cat", "gunzip", "bunzip2", "cat" };
specDir = rpmGetPath("%{_specdir}", NULL);
+ /* XXX Using mkstemp is difficult here. */
+ /* XXX FWIW, default %{_specdir} is root.root 0755 */
{ char tfn[64];
strcpy(tfn, "rpm-spec.XXXXXX");
+ /*@-unrecog@*/
tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
+ /*@=unrecog@*/
}
- isCompressed(arg, &res);
+ (void) isCompressed(arg, &res);
cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
zcmds[res & 0x3], arg, tmpSpecFile);
if (!(fp = popen(cmd, "r"))) {
- fprintf(stderr, _("Failed to open tar pipe: %s\n"),
- strerror(errno));
- xfree(specDir);
- xfree(tmpSpecFile);
+ rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
+ specDir = _free(specDir);
+ tmpSpecFile = _free(tmpSpecFile);
return 1;
}
if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
/* Try again */
- pclose(fp);
+ (void) pclose(fp);
sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 2>&1 > %s",
zcmds[res & 0x3], arg, tmpSpecFile);
if (!(fp = popen(cmd, "r"))) {
- fprintf(stderr, _("Failed to open tar pipe: %s\n"),
- strerror(errno));
- xfree(specDir);
- xfree(tmpSpecFile);
+ rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
+ specDir = _free(specDir);
+ tmpSpecFile = _free(tmpSpecFile);
return 1;
}
if (!fgets(buf, sizeof(buf) - 1, fp)) {
/* Give up */
- fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
- unlink(tmpSpecFile);
- xfree(specDir);
- xfree(tmpSpecFile);
+ rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
+ arg);
+ (void) unlink(tmpSpecFile);
+ specDir = _free(specDir);
+ tmpSpecFile = _free(tmpSpecFile);
return 1;
}
}
- pclose(fp);
+ (void) pclose(fp);
cmd = s = buf;
- while (*cmd) {
+ while (*cmd != '\0') {
if (*cmd == '/') s = cmd + 1;
cmd++;
}
specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
sprintf(s, "%s/%s", specDir, cmd);
res = rename(tmpSpecFile, s);
- xfree(specDir);
+ specDir = _free(specDir);
if (res) {
- fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
- tmpSpecFile, s, strerror(errno));
- unlink(tmpSpecFile);
- xfree(tmpSpecFile);
+ rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
+ tmpSpecFile, s);
+ (void) unlink(tmpSpecFile);
+ tmpSpecFile = _free(tmpSpecFile);
return 1;
}
- xfree(tmpSpecFile);
+ tmpSpecFile = _free(tmpSpecFile);
/* Make the directory which contains the tarball the source
directory for this run */
} else {
specURL = arg;
}
+ /*@=compmempass@*/
specut = urlPath(specURL, &specFile);
if (*specFile != '/') {
if (specut != URL_IS_DASH) {
struct stat st;
- Stat(specURL, &st);
+ if (Stat(specURL, &st) < 0) {
+ rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
+ rc = 1;
+ goto exit;
+ }
if (! S_ISREG(st.st_mode)) {
- fprintf(stderr, _("File is not a regular file: %s\n"), specURL);
+ rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
+ specURL);
rc = 1;
goto exit;
}
/* Try to verify that the file is actually a specfile */
if (!isSpecFile(specURL)) {
- fprintf(stderr, _("File %s does not appear to be a specfile.\n"),
- specURL);
+ rpmError(RPMERR_BADSPEC,
+ _("File %s does not appear to be a specfile.\n"), specURL);
rc = 1;
goto exit;
}
#define _anyarch(_f) \
(((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
- cookie, _anyarch(buildAmount), force)) {
+ cookie, _anyarch(buildAmount), ba->force)) {
rc = 1;
goto exit;
}
initSourceHeader(spec);
/* Check build prerequisites */
- if (!nodeps && checkSpec(spec->sourceHeader)) {
+ if (!ba->noDeps && checkSpec(ts, spec->sourceHeader)) {
rc = 1;
goto exit;
}
- if (buildSpec(spec, buildAmount, test)) {
+ if (buildSpec(spec, buildAmount, ba->noBuild)) {
rc = 1;
goto exit;
}
- if (fromTarball) Unlink(specURL);
+ if (ba->buildMode == 't')
+ (void) Unlink(specURL);
rc = 0;
exit:
- if (spec)
- freeSpec(spec);
- if (buildRootURL)
- xfree(buildRootURL);
+ spec = freeSpec(spec);
+ buildRootURL = _free(buildRootURL);
return rc;
}
-/** */
-int build(const char * arg, struct rpmBuildArguments * ba,
- const char * passPhrase, int fromTarball, char * cookie,
- const char * rcfile, int force, int nodeps)
+int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
{
char *t, *te;
int rc = 0;
- char *targets = ba->targets;
+ char * targets = ba->targets;
#define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
int cleanFlags = ba->buildAmount & buildCleanMask;
if (targets == NULL) {
- rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
- force, nodeps);
+ rc = buildForTarget(ts, arg, ba);
goto exit;
}
target = alloca(te-t+1);
strncpy(target, t, (te-t));
target[te-t] = '\0';
- if (*te)
+ if (*te != '\0')
te++;
else /* XXX Perform clean-up after last target build. */
ba->buildAmount |= cleanFlags;
/* Read in configuration for target. */
rpmFreeMacros(NULL);
- rpmReadConfigFiles(rcfile, target);
- rc = buildForTarget(arg, ba, passPhrase, fromTarball, cookie,
- force, nodeps);
+ (void) rpmReadConfigFiles(rcfile, target);
+ rc = buildForTarget(ts, arg, ba);
if (rc)
break;
}
exit:
/* Restore original configuration. */
rpmFreeMacros(NULL);
- rpmReadConfigFiles(rcfile, NULL);
+ (void) rpmReadConfigFiles(rcfile, NULL);
+
return rc;
}