- Grand Renaming of rpm data types.
[platform/upstream/rpm.git] / build.c
diff --git a/build.c b/build.c
index 86ef8b7..5e2e1d8 100644 (file)
--- a/build.c
+++ b/build.c
@@ -6,54 +6,45 @@
 
 #include <rpmcli.h>
 #include <rpmbuild.h>
-#include <rpmurl.h>
+
+#include "rpmps.h"
+#include "rpmte.h"
+#include "rpmts.h"
 
 #include "build.h"
 #include "debug.h"
 
-/*@access rpmTransactionSet @*/        /* XXX compared with NULL @*/
+/*@access rpmts @*/    /* XXX compared with NULL @*/
 /*@access rpmdb @*/            /* XXX compared with NULL @*/
 /*@access FD_t @*/             /* XXX compared with NULL @*/
 
 /**
  */
-static int checkSpec(Header h)
-       /*@modifies h, fileSystem @*/
+static int checkSpec(rpmts ts, Header h)
+       /*@globals fileSystem, internalState @*/
+       /*@modifies ts, h, fileSystem, internalState @*/
 {
-    const char * rootdir = NULL;
-    rpmdb db = NULL;
-    int mode = O_RDONLY;
-    rpmTransactionSet ts;
-    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);
-       rpmError(RPMERR_OPEN, _("cannot open rpm database in %s\n"), dn);
-       dn = _free(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);
-       conflicts = 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 != NULL)
-       rpmtransFree(ts);
-    if (db != NULL)
-       (void) rpmdbClose(db);
+    /* XXX nuke the added package. */
+    rpmtsClean(ts);
 
     return rc;
 }
@@ -66,6 +57,7 @@ static int checkSpec(Header h)
 /**
  */
 static int isSpecFile(const char * specfile)
+       /*@globals fileSystem @*/
        /*@modifies fileSystem @*/
 {
     char buf[256];
@@ -89,13 +81,13 @@ static int isSpecFile(const char * specfile)
        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;
@@ -103,10 +95,14 @@ static int isSpecFile(const char * specfile)
 
 /**
  */
-static int buildForTarget(const char * arg, BTA_t ba,
-               const char * passPhrase, char * cookie)
-       /*@modifies fileSystem @*/
+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;
     const char * specFile;
@@ -120,9 +116,12 @@ static int buildForTarget(const char * arg, BTA_t ba,
     rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
 #endif
 
+    /*@-branchstate@*/
     if (ba->buildRootOverride)
        buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
+    /*@=branchstate@*/
 
+    /*@-compmempass@*/ /* FIX: static zcmds heartburn */
     if (ba->buildMode == 't') {
        FILE *fp;
        const char * specDir;
@@ -222,6 +221,7 @@ static int buildForTarget(const char * arg, BTA_t ba,
     } else {
        specURL = arg;
     }
+    /*@=compmempass@*/
 
     specut = urlPath(specURL, &specFile);
     if (*specFile != '/') {
@@ -269,7 +269,7 @@ static int buildForTarget(const char * arg, BTA_t ba,
     initSourceHeader(spec);
 
     /* Check build prerequisites */
-    if (!ba->noDeps && checkSpec(spec->sourceHeader)) {
+    if (!ba->noDeps && checkSpec(ts, spec->sourceHeader)) {
        rc = 1;
        goto exit;
     }
@@ -289,8 +289,7 @@ exit:
     return rc;
 }
 
-int build(const char * arg, BTA_t ba,
-       const char * passPhrase, char * cookie, const char * rcfile)
+int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
 {
     char *t, *te;
     int rc = 0;
@@ -299,7 +298,7 @@ int build(const char * arg, BTA_t ba,
     int cleanFlags = ba->buildAmount & buildCleanMask;
 
     if (targets == NULL) {
-       rc =  buildForTarget(arg, ba, passPhrase, cookie);
+       rc =  buildForTarget(ts, arg, ba);
        goto exit;
     }
 
@@ -325,7 +324,7 @@ int build(const char * arg, BTA_t ba,
        /* Read in configuration for target. */
        rpmFreeMacros(NULL);
        (void) rpmReadConfigFiles(rcfile, target);
-       rc = buildForTarget(arg, ba, passPhrase, cookie);
+       rc = buildForTarget(ts, arg, ba);
        if (rc)
            break;
     }
@@ -334,5 +333,6 @@ exit:
     /* Restore original configuration. */
     rpmFreeMacros(NULL);
     (void) rpmReadConfigFiles(rcfile, NULL);
+
     return rc;
 }