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)
25 rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
28 specDir = alloca(BUFSIZ);
29 strcpy(specDir, "%{_specdir}");
30 /* XXX can't use spec->macros yet */
31 expandMacros(NULL, &globalMacroContext, specDir, BUFSIZ);
33 tmpSpecFile = alloca(BUFSIZ);
34 sprintf(tmpSpecFile, "%s/rpm-spec-file-%d", specDir, (int) getpid());
36 cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
37 sprintf(cmd, "gunzip < %s | tar xOvf - Specfile 2>&1 > %s", arg,
39 if (!(f = popen(cmd, "r"))) {
40 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
44 if ((!fgets(buf, sizeof(buf) - 1, f)) || !strchr(buf, '/')) {
48 sprintf(cmd, "gunzip < %s | tar xOvf - \\*.spec 2>&1 > %s", arg,
50 if (!(f = popen(cmd, "r"))) {
51 fprintf(stderr, _("Failed to open tar pipe: %s\n"),
55 if (!fgets(buf, sizeof(buf) - 1, f)) {
57 fprintf(stderr, _("Failed to read spec file from %s\n"), arg);
66 if (*cmd == '/') specfile = cmd + 1;
72 /* remove trailing \n */
73 specfile = cmd + strlen(cmd) - 1;
76 specfile = alloca(strlen(specDir) + strlen(cmd) + 5);
77 sprintf(specfile, "%s/%s", specDir, cmd);
79 if (rename(tmpSpecFile, specfile)) {
80 fprintf(stderr, _("Failed to rename %s to %s: %s\n"),
81 tmpSpecFile, specfile, strerror(errno));
86 /* Make the directory which contains the tarball the source
87 directory for this run */
96 cmd = buf + strlen(buf) - 1;
97 while (*cmd != '/') cmd--;
100 addMacro(&globalMacroContext, "_sourcedir", NULL, buf, RMIL_TARBALL);
101 } else if (arg[0] == '/') {
104 specfile = alloca(BUFSIZ);
105 getcwd(specfile, BUFSIZ);
106 strcat(specfile, "/");
107 strcat(specfile, arg);
110 stat(specfile, &statbuf);
111 if (! S_ISREG(statbuf.st_mode)) {
112 fprintf(stderr, _("File is not a regular file: %s\n"), specfile);
116 if ((fd = open(specfile, O_RDONLY)) < 0) {
117 fprintf(stderr, _("Unable to open spec file: %s\n"), specfile);
120 count = read(fd, buf, sizeof(buf) < 128 ? sizeof(buf) : 128);
124 if (! (isprint(*s) || isspace(*s))) {
125 fprintf(stderr, _("File contains non-printable characters(%c): %s\n"), *s,
132 if (parseSpec(&spec, specfile, buildRoot, 0, passPhrase, cookie)) {
136 if (buildSpec(spec, buildAmount, test)) {
141 if (fromTarball) unlink(specfile);
148 int build(char *arg, int buildAmount, char *passPhrase,
149 char *buildRoot, int fromTarball, int test, char *cookie,
150 char * rcfile, char * arch, char * os,
151 char *buildplatforms)
156 if (buildplatforms == NULL) {
157 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
158 fromTarball, test, cookie);
162 /* parse up the build operators */
164 printf("building these platforms: %s\n", buildplatforms);
167 while((platform = strtok(t, ",")) != NULL) {
169 printf("building %s\n", platform);
171 rpmSetVar(RPMVAR_BUILDPLATFORM,platform);
172 rpmReadConfigFiles(rcfile, arch, os, 1, platform);
173 rc = buildplatform(arg, buildAmount, passPhrase, buildRoot,
174 fromTarball, test, cookie);