17 #include "lib/rpmlib.h"
18 #include "build/build.h"
19 #include "build/parse.h"
20 #include "build/spec.h"
22 int build(char *arg, int buildAmount, char *passPhrase,
23 char *buildRoot, int fromTarball, int test, char *cookie) {
37 specDir = rpmGetVar(RPMVAR_SPECDIR);
38 tmpSpecFile = alloca(BUFSIZ);
39 sprintf(tmpSpecFile, "%s/rpm-spec-file-%d", specDir, (int) getpid());
41 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
42 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s", arg,
44 if (!(f = popen(cmd, "r"))) {
45 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
49 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
53 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
55 if (!(f = popen(cmd, "r"))) {
56 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
60 if (!fgets(buf, sizeof(buf) - 1, f)) {
62 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
71 if (*cmd == '/') specfile = cmd + 1;
77 /* remove trailing \n */
78 specfile = cmd + strlen(cmd) - 1;
81 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
82 sprintf(specfile, "%s/%s", specDir, cmd);
84 if (rename(tmpSpecFile, specfile)) {
85 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
86 tmpSpecFile, specfile, strerror(errno));
91 /* Make the directory which contains the tarball the source
92 directory for this run */
101 cmd = buf + strlen(buf) - 1;
102 while (*cmd != '/') cmd--;
105 rpmSetVar(RPMVAR_SOURCEDIR, buf);
106 } else if (arg[0] == '/') {
109 specfile = alloca(BUFSIZ);
110 getcwd(specfile, BUFSIZ);
111 strcat(specfile, "/");
112 strcat(specfile, arg);
115 stat(specfile, &statbuf);
116 if (! S_ISREG(statbuf.st_mode)) {
117 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
121 if ((fd = open(specfile, O_RDONLY)) < 0) {
122 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
125 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
129 if (! (isprint(*s) || isspace(*s))) {
130 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
137 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie)) {
141 if (buildSpec(spec, buildAmount, test)) {
146 if (fromTarball) unlink(specfile);