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 build(char *arg, int buildAmount, char *passPhrase,
10 char *buildRoot, int fromTarball, int test, char *cookie,
11 char * rcfile, char * arch, char * os,
12 char *buildplatforms) {
16 /* parse up the build operators */
18 printf("building these platforms: %s\n",buildplatforms);
21 while(platform = strsep(&buildplatforms,",")) {
22 printf("building %s\n",platform);
24 rpmSetVar(RPMVAR_BUILDPLATFORM,platform);
25 rpmReadConfigFiles(rcfile, arch, os, 1,platform);
26 buildplatform(arg,buildAmount,passPhrase,buildRoot,
27 fromTarball,test,cookie);
30 buildplatform(arg,buildAmount,passPhrase,buildRoot,
31 fromTarball,test,cookie);
36 int buildplatform(char *arg, int buildAmount, char *passPhrase,
37 char *buildRoot, int fromTarball, int test, char *cookie) {
52 specDir = rpmGetVar(RPMVAR_SPECDIR);
53 tmpSpecFile = alloca(BUFSIZ);
54 sprintf(tmpSpecFile, "%s/rpm-spec-file-%d", specDir, (int) getpid());
56 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
57 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s", arg,
59 if (!(f = popen(cmd, "r"))) {
60 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
64 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
68 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
70 if (!(f = popen(cmd, "r"))) {
71 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
75 if (!fgets(buf, sizeof(buf) - 1, f)) {
77 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
86 if (*cmd == '/') specfile = cmd + 1;
92 /* remove trailing \n */
93 specfile = cmd + strlen(cmd) - 1;
96 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
97 sprintf(specfile, "%s/%s", specDir, cmd);
99 if (rename(tmpSpecFile, specfile)) {
100 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
101 tmpSpecFile, specfile, strerror(errno));
106 /* Make the directory which contains the tarball the source
107 directory for this run */
116 cmd = buf + strlen(buf) - 1;
117 while (*cmd != '/') cmd--;
120 rpmSetVar(RPMVAR_SOURCEDIR, buf);
121 } else if (arg[0] == '/') {
124 specfile = alloca(BUFSIZ);
125 getcwd(specfile, BUFSIZ);
126 strcat(specfile, "/");
127 strcat(specfile, arg);
130 stat(specfile, &statbuf);
131 if (! S_ISREG(statbuf.st_mode)) {
132 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
136 if ((fd = open(specfile, O_RDONLY)) < 0) {
137 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
140 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
144 if (! (isprint(*s) || isspace(*s))) {
145 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
152 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie)) {
156 if (buildSpec(spec, buildAmount, test)) {
161 if (fromTarball) unlink(specfile);