3 #include "build/rpmbuild.h"
8 int build(char *arg, int buildAmount, char *passPhrase,
9 char *buildRoot, int fromTarball, int test, char *cookie) {
23 specDir = rpmGetVar(RPMVAR_SPECDIR);
24 tmpSpecFile = alloca(BUFSIZ);
25 sprintf(tmpSpecFile, "%s/rpm-spec-file-%d", specDir, (int) getpid());
27 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
28 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s", arg,
30 if (!(f = popen(cmd, "r"))) {
31 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
35 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
39 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
41 if (!(f = popen(cmd, "r"))) {
42 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
46 if (!fgets(buf, sizeof(buf) - 1, f)) {
48 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
57 if (*cmd == '/') specfile = cmd + 1;
63 /* remove trailing \n */
64 specfile = cmd + strlen(cmd) - 1;
67 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
68 sprintf(specfile, "%s/%s", specDir, cmd);
70 if (rename(tmpSpecFile, specfile)) {
71 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
72 tmpSpecFile, specfile, strerror(errno));
77 /* Make the directory which contains the tarball the source
78 directory for this run */
87 cmd = buf + strlen(buf) - 1;
88 while (*cmd != '/') cmd--;
91 rpmSetVar(RPMVAR_SOURCEDIR, buf);
92 } else if (arg[0] == '/') {
95 specfile = alloca(BUFSIZ);
96 getcwd(specfile, BUFSIZ);
97 strcat(specfile, "/");
98 strcat(specfile, arg);
101 stat(specfile, &statbuf);
102 if (! S_ISREG(statbuf.st_mode)) {
103 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
107 if ((fd = open(specfile, O_RDONLY)) < 0) {
108 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
111 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
115 if (! (isprint(*s) || isspace(*s))) {
116 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
123 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie)) {
127 if (buildSpec(spec, buildAmount, test)) {
132 if (fromTarball) unlink(specfile);