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 - \\*.spec 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)) {
50 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
58 if (*cmd == '/') specfile = cmd + 1;
64 /* remove trailing \n */
65 specfile = cmd + strlen(cmd) - 1;
68 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
69 sprintf(specfile, "%s/%s", specDir, cmd);
71 if (rename(tmpSpecFile, specfile)) {
72 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
73 tmpSpecFile, specfile, strerror(errno));
78 /* Make the directory which contains the tarball the source
79 directory for this run */
88 cmd = buf + strlen(buf) - 1;
89 while (*cmd != '/') cmd--;
92 rpmSetVar(RPMVAR_SOURCEDIR, buf);
93 } else if (arg[0] == '/') {
96 specfile = alloca(BUFSIZ);
97 getcwd(specfile, BUFSIZ);
98 strcat(specfile, "/");
99 strcat(specfile, arg);
102 stat(specfile, &statbuf);
103 if (! S_ISREG(statbuf.st_mode)) {
104 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
108 if (!(fd = open(specfile, O_RDONLY))) {
109 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
112 count = read(fd, buf, sizeof(buf));
116 if (! (isprint(*s) || isspace(*s))) {
117 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
124 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie)) {
128 if (buildSpec(spec, buildAmount, test)) {
133 if (fromTarball) unlink(specfile);