2 #include "build/rpmbuild.h"
6 int buildplatform(char *arg, int buildAmount, char *passPhrase,
7 char *buildRoot, int fromTarball, int test, char *cookie);
9 int buildplatform(char *arg, int buildAmount, char *passPhrase,
10 char *buildRoot, int fromTarball, int test, char *cookie)
26 specDir = rpmGetVar(RPMVAR_SPECDIR);
27 tmpSpecFile = alloca(BUFSIZ);
28 sprintf(tmpSpecFile, "%s/rpm-spec-file-%d", specDir, (int) getpid());
30 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
31 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s", arg,
33 if (!(f = popen(cmd, "r"))) {
34 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
38 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
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)) {
51 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
60 if (*cmd == '/') specfile = cmd + 1;
66 /* remove trailing \n */
67 specfile = cmd + strlen(cmd) - 1;
70 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
71 sprintf(specfile, "%s/%s", specDir, cmd);
73 if (rename(tmpSpecFile, specfile)) {
74 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
75 tmpSpecFile, specfile, strerror(errno));
80 /* Make the directory which contains the tarball the source
81 directory for this run */
90 cmd = buf + strlen(buf) - 1;
91 while (*cmd != '/') cmd--;
94 rpmSetVar(RPMVAR_SOURCEDIR, buf);
95 } else if (arg[0] == '/') {
98 specfile = alloca(BUFSIZ);
99 getcwd(specfile, BUFSIZ);
100 strcat(specfile, "/");
101 strcat(specfile, arg);
104 stat(specfile, &statbuf);
105 if (! S_ISREG(statbuf.st_mode)) {
106 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
110 if ((fd = open(specfile, O_RDONLY)) < 0) {
111 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
114 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
118 if (! (isprint(*s) || isspace(*s))) {
119 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
126 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie)) {
130 if (buildSpec(spec, buildAmount, test)) {
135 if (fromTarball) unlink(specfile);
142 int build(char *arg, int buildAmount, char *passPhrase,
143 char *buildRoot, int fromTarball, int test, char *cookie,
144 char * rcfile, char * arch, char * os,
145 char *buildplatforms)
150 if (buildplatforms == NULL) {
151 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
152 fromTarball, test, cookie);
156 /* parse up the build operators */
158 printf("building these platforms: %s\n", buildplatforms);
160 while((platform = strsep(&buildplatforms,",")) != NULL) {
161 printf("building %s\n", platform);
163 rpmSetVar(RPMVAR_BUILDPLATFORM,platform);
164 rpmReadConfigFiles(rcfile, arch, os, 1, platform);
165 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
166 fromTarball, test, cookie);