Permit file objects in python header constructor
[platform/upstream/rpm.git] / build / build.c
index 120ef42..a4a271a 100644 (file)
@@ -15,21 +15,18 @@ static int _build_debug = 0;
 
 /**
  */
-static void doRmSource(rpmSpec spec)
+rpmRC doRmSource(rpmSpec spec)
 {
     struct Source *p;
     Package pkg;
-    int rc;
+    int rc = 0;
     
-#if 0
-    rc = unlink(spec->specFile);
-#endif
-
     for (p = spec->sources; p != NULL; p = p->next) {
        if (! (p->flags & RPMBUILD_ISNO)) {
            char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL);
            rc = unlink(fn);
            fn = _free(fn);
+           if (rc) goto exit;
        }
     }
 
@@ -39,9 +36,12 @@ static void doRmSource(rpmSpec spec)
                char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL);
                rc = unlink(fn);
                fn = _free(fn);
+               if (rc) goto exit;
            }
        }
     }
+exit:
+    return !rc ? RPMRC_OK : RPMRC_FAIL;
 }
 
 /*
@@ -49,11 +49,9 @@ static void doRmSource(rpmSpec spec)
  */
 rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, StringBuf sb, int test)
 {
-    const char * rootURL = spec->rootURL;
-    const char * rootDir;
-    const char *scriptName = NULL;
-    char * buildDirURL = rpmGenPath(rootURL, "%{_builddir}", "");
-    const char * buildScript;
+    const char * rootDir = spec->rootDir;
+    char *scriptName = NULL;
+    char * buildDir = rpmGenPath(rootDir, "%{_builddir}", "");
     char * buildCmd = NULL;
     char * buildTemplate = NULL;
     char * buildPost = NULL;
@@ -63,7 +61,6 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, StringBuf sb,
     int argc = 0;
     const char **argv = NULL;
     FILE * fp = NULL;
-    urlinfo u = NULL;
 
     FD_t fd;
     FD_t xfd;
@@ -129,7 +126,8 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, StringBuf sb,
        goto exit;
     }
     
-    if (rpmMkTempFile(rootURL, &scriptName, &fd) || fd == NULL || Ferror(fd)) {
+    fd = rpmMkTempFile(rootDir, &scriptName);
+    if (fd == NULL || Ferror(fd)) {
        rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n"));
        rc = RPMRC_FAIL;
        goto exit;
@@ -145,11 +143,8 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, StringBuf sb,
        goto exit;
     }
     
-    (void) urlPath(rootURL, &rootDir);
     if (*rootDir == '\0') rootDir = "/";
 
-    (void) urlPath(scriptName, &buildScript);
-
     buildTemplate = rpmExpand(mTemplate, NULL);
     buildPost = rpmExpand(mPost, NULL);
 
@@ -174,34 +169,13 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, StringBuf sb,
     }
     
 if (_build_debug)
-fprintf(stderr, "*** rootURL %s buildDirURL %s\n", rootURL, buildDirURL);
-    if (buildDirURL && buildDirURL[0] != '/' &&
-       (urlSplit(buildDirURL, &u) != 0)) {
+fprintf(stderr, "*** rootDir %s buildDir %s\n", rootDir, buildDir);
+    if (buildDir && buildDir[0] != '/') {
        rc = RPMRC_FAIL;
        goto exit;
     }
-    if (u != NULL) {
-       switch (u->urltype) {
-       case URL_IS_HTTPS:
-       case URL_IS_HTTP:
-       case URL_IS_FTP:
-if (_build_debug)
-fprintf(stderr, "*** addMacros\n");
-           addMacro(spec->macros, "_remsh", NULL, "%{__remsh}", RMIL_SPEC);
-           addMacro(spec->macros, "_remhost", NULL, u->host, RMIL_SPEC);
-           if (strcmp(rootDir, "/"))
-               addMacro(spec->macros, "_remroot", NULL, rootDir, RMIL_SPEC);
-           break;
-       case URL_IS_UNKNOWN:
-       case URL_IS_DASH:
-       case URL_IS_PATH:
-       case URL_IS_HKP:
-       default:
-           break;
-       }
-    }
 
-    buildCmd = rpmExpand(mCmd, " ", buildScript, NULL);
+    buildCmd = rpmExpand(mCmd, " ", scriptName, NULL);
     (void) poptParseArgvString(buildCmd, &argc, &argv);
 
     rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd);
@@ -213,7 +187,7 @@ fprintf(stderr, "*** addMacros\n");
        rpmlog(RPMLOG_ERR, _("Exec of %s failed (%s): %s\n"),
                scriptName, name, strerror(errno));
 
-       _exit(-1);
+       _exit(127); /* exit 127 for compatibility with bash(1) */
     }
 
     pid = waitpid(child, &status, 0);
@@ -231,32 +205,11 @@ exit:
            (void) unlink(scriptName);
        scriptName = _free(scriptName);
     }
-    if (u != NULL) {
-       switch (u->urltype) {
-       case URL_IS_HTTPS:
-       case URL_IS_HTTP:
-       case URL_IS_FTP:
-if (_build_debug)
-fprintf(stderr, "*** delMacros\n");
-           delMacro(spec->macros, "_remsh");
-           delMacro(spec->macros, "_remhost");
-           if (strcmp(rootDir, "/"))
-               delMacro(spec->macros, "_remroot");
-           break;
-       case URL_IS_UNKNOWN:
-       case URL_IS_DASH:
-       case URL_IS_PATH:
-       case URL_IS_HKP:
-       default:
-           break;
-       }
-       u = urlFree(u);
-    }
     argv = _free(argv);
     buildCmd = _free(buildCmd);
     buildTemplate = _free(buildTemplate);
     buildPost = _free(buildPost);
-    buildDirURL = _free(buildDirURL);
+    buildDir = _free(buildDir);
 
     return rc;
 }