1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
#include <rpmbuild.h>
|
|
|
|
#include <rpmurl.h>
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
static void doRmSource(Spec spec)
|
1995-11-28 06:31:21 +08:00
|
|
|
{
|
1998-07-26 05:00:26 +08:00
|
|
|
struct Source *p;
|
|
|
|
Package pkg;
|
|
|
|
|
1999-04-30 23:55:45 +08:00
|
|
|
#if 0
|
1998-07-26 05:00:26 +08:00
|
|
|
unlink(spec->specFile);
|
1999-04-30 23:55:45 +08:00
|
|
|
#endif
|
1995-12-18 22:53:14 +08:00
|
|
|
|
1998-11-08 08:15:33 +08:00
|
|
|
for (p = spec->sources; p != NULL; p = p->next) {
|
1998-07-26 05:00:26 +08:00
|
|
|
if (! (p->flags & RPMBUILD_ISNO)) {
|
1999-01-06 07:13:56 +08:00
|
|
|
const char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL);
|
|
|
|
unlink(fn);
|
|
|
|
xfree(fn);
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-07-26 05:00:26 +08:00
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-11-08 08:15:33 +08:00
|
|
|
for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
|
|
|
|
for (p = pkg->icon; p != NULL; p = p->next) {
|
1998-07-26 05:00:26 +08:00
|
|
|
if (! (p->flags & RPMBUILD_ISNO)) {
|
1999-01-06 07:13:56 +08:00
|
|
|
const char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL);
|
|
|
|
unlink(fn);
|
|
|
|
xfree(fn);
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-07-26 05:00:26 +08:00
|
|
|
}
|
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-09-06 04:02:08 +08:00
|
|
|
/*
|
|
|
|
* The _preScript string is expanded to export values to a script environment.
|
|
|
|
*/
|
|
|
|
|
1998-09-06 07:13:35 +08:00
|
|
|
static char *_preScriptEnvironment = "%{_preScriptEnvironment}";
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-09-06 04:02:08 +08:00
|
|
|
static char *_preScriptChdir =
|
|
|
|
"umask 022\n"
|
|
|
|
"cd %{_builddir}\n"
|
|
|
|
;
|
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
int doScript(Spec spec, int what, const char *name, StringBuf sb, int test)
|
1996-01-08 15:06:16 +08:00
|
|
|
{
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fd;
|
1998-01-13 05:31:29 +08:00
|
|
|
FILE *f;
|
1999-01-07 01:33:50 +08:00
|
|
|
const char *scriptName;
|
1998-01-13 05:31:29 +08:00
|
|
|
int pid;
|
|
|
|
int status;
|
1998-09-06 07:13:35 +08:00
|
|
|
char buf[BUFSIZ];
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
switch (what) {
|
|
|
|
case RPMBUILD_PREP:
|
|
|
|
name = "%prep";
|
|
|
|
sb = spec->prep;
|
|
|
|
break;
|
|
|
|
case RPMBUILD_BUILD:
|
|
|
|
name = "%build";
|
|
|
|
sb = spec->build;
|
|
|
|
break;
|
|
|
|
case RPMBUILD_INSTALL:
|
|
|
|
name = "%install";
|
|
|
|
sb = spec->install;
|
|
|
|
break;
|
|
|
|
case RPMBUILD_CLEAN:
|
|
|
|
name = "%clean";
|
|
|
|
sb = spec->clean;
|
|
|
|
break;
|
|
|
|
case RPMBUILD_RMBUILD:
|
|
|
|
name = "--clean";
|
|
|
|
break;
|
|
|
|
case RPMBUILD_STRINGBUF:
|
|
|
|
break;
|
|
|
|
}
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if ((what != RPMBUILD_RMBUILD) && sb == NULL)
|
1998-01-13 05:31:29 +08:00
|
|
|
return 0;
|
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if (makeTempFile(spec->rootdir, &scriptName, &fd)) {
|
1999-10-28 07:18:10 +08:00
|
|
|
Fclose(fd);
|
1998-11-19 05:41:05 +08:00
|
|
|
FREE(scriptName);
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_SCRIPT, _("Unable to open temp file"));
|
1998-09-06 07:13:35 +08:00
|
|
|
return RPMERR_SCRIPT;
|
1996-01-08 15:06:16 +08:00
|
|
|
}
|
1999-06-18 05:35:34 +08:00
|
|
|
#ifdef HAVE_FCHMOD
|
1999-10-31 00:43:29 +08:00
|
|
|
(void)fchmod(Fileno(fd), 0600);
|
1999-06-18 05:35:34 +08:00
|
|
|
#endif
|
1998-11-21 04:18:22 +08:00
|
|
|
f = fdFdopen(fd, "w");
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-09-06 07:13:35 +08:00
|
|
|
strcpy(buf, _preScriptEnvironment);
|
|
|
|
expandMacros(spec, spec->macros, buf, sizeof(buf));
|
|
|
|
strcat(buf, "\n");
|
|
|
|
fputs(buf, f);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
fprintf(f, rpmIsVerbose() ? "set -x\n\n" : "exec > /dev/null\n\n");
|
1998-09-06 04:02:08 +08:00
|
|
|
|
|
|
|
/* XXX umask 022; cd %{_builddir} */
|
|
|
|
strcpy(buf, _preScriptChdir);
|
|
|
|
expandMacros(spec, spec->macros, buf, sizeof(buf));
|
|
|
|
fputs(buf, f);
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD) {
|
1999-11-01 05:38:21 +08:00
|
|
|
if (spec->buildSubdir)
|
1998-01-15 06:02:01 +08:00
|
|
|
fprintf(f, "cd %s\n", spec->buildSubdir);
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
if (what == RPMBUILD_RMBUILD) {
|
1999-11-01 05:38:21 +08:00
|
|
|
if (spec->buildSubdir)
|
1998-04-08 22:22:41 +08:00
|
|
|
fprintf(f, "rm -rf %s\n", spec->buildSubdir);
|
1999-11-01 05:38:21 +08:00
|
|
|
} else
|
1998-01-13 05:31:29 +08:00
|
|
|
fprintf(f, "%s", getStringBuf(sb));
|
|
|
|
fprintf(f, "\nexit 0\n");
|
|
|
|
|
|
|
|
fclose(f);
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (test) {
|
|
|
|
FREE(scriptName);
|
|
|
|
return 0;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmMessage(RPMMESS_NORMAL, _("Executing: %s\n"), name);
|
1998-01-13 05:31:29 +08:00
|
|
|
if (!(pid = fork())) {
|
1999-03-21 05:09:47 +08:00
|
|
|
const char *buildShell = rpmGetPath("%{_buildshell}", NULL);
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if (spec->rootdir)
|
|
|
|
Chroot(spec->rootdir);
|
|
|
|
chdir("/");
|
|
|
|
|
|
|
|
switch (urlIsURL(scriptName)) {
|
|
|
|
case URL_IS_PATH:
|
|
|
|
scriptName += sizeof("file://") - 1;
|
|
|
|
scriptName = strchr(scriptName, '/');
|
|
|
|
/*@fallthrough@*/
|
|
|
|
case URL_IS_UNKNOWN:
|
|
|
|
execl(buildShell, buildShell, "-e", scriptName, scriptName, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpmError(RPMERR_SCRIPT, _("Exec of %s failed (%s)"), scriptName, name);
|
|
|
|
_exit(-1);
|
1996-01-29 11:32:22 +08:00
|
|
|
}
|
1999-11-01 05:38:21 +08:00
|
|
|
|
1998-11-17 05:40:28 +08:00
|
|
|
(void)wait(&status);
|
1998-01-13 05:31:29 +08:00
|
|
|
if (! WIFEXITED(status) || WEXITSTATUS(status)) {
|
1998-09-28 06:03:52 +08:00
|
|
|
rpmError(RPMERR_SCRIPT, _("Bad exit status from %s (%s)"),
|
1998-01-13 05:31:29 +08:00
|
|
|
scriptName, name);
|
1998-09-06 07:13:35 +08:00
|
|
|
#if HACK
|
1999-11-01 05:38:21 +08:00
|
|
|
Unlink(scriptName);
|
1998-09-06 07:13:35 +08:00
|
|
|
#endif
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(scriptName);
|
|
|
|
return RPMERR_SCRIPT;
|
1997-04-15 04:05:12 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
Unlink(scriptName);
|
1998-01-13 05:31:29 +08:00
|
|
|
FREE(scriptName);
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
return 0;
|
1995-12-14 23:56:10 +08:00
|
|
|
}
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
int buildSpec(Spec spec, int what, int test)
|
1995-12-14 23:56:10 +08:00
|
|
|
{
|
1998-07-26 05:00:26 +08:00
|
|
|
int x, rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
if (!spec->inBuildArchitectures && spec->buildArchitectureCount) {
|
|
|
|
/* When iterating over buildArchitectures, do the source */
|
|
|
|
/* packaging on the first run, and skip RMSOURCE altogether */
|
1999-04-17 22:23:42 +08:00
|
|
|
for (x = 0; x < spec->buildArchitectureCount; x++) {
|
1998-07-26 05:00:26 +08:00
|
|
|
if ((rc = buildSpec(spec->buildArchitectureSpecs[x],
|
|
|
|
(what & ~RPMBUILD_RMSOURCE) |
|
|
|
|
(x ? 0 : (what & RPMBUILD_PACKAGESOURCE)),
|
|
|
|
test))) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
1999-11-01 05:38:21 +08:00
|
|
|
if ((what & RPMBUILD_PREP) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_PREP, NULL, NULL, test)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if ((what & RPMBUILD_BUILD) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_BUILD, NULL, NULL, test)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if ((what & RPMBUILD_INSTALL) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_INSTALL, NULL, NULL, test)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
1995-12-20 05:08:18 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if ((what & RPMBUILD_PACKAGESOURCE) &&
|
|
|
|
(rc = processSourceFiles(spec)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
1995-12-20 05:08:18 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if (((what & RPMBUILD_INSTALL) || (what & RPMBUILD_PACKAGEBINARY) ||
|
|
|
|
(what & RPMBUILD_FILECHECK)) &&
|
|
|
|
(rc = processBinaryFiles(spec, what & RPMBUILD_INSTALL, test)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
1998-04-10 00:46:30 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if (((what & RPMBUILD_PACKAGESOURCE) && !test) &&
|
|
|
|
(rc = packageSources(spec)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if (((what & RPMBUILD_PACKAGEBINARY) && !test) &&
|
|
|
|
(rc = packageBinaries(spec)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if ((what & RPMBUILD_CLEAN) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_CLEAN, NULL, NULL, test)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if ((what & RPMBUILD_RMBUILD) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_RMBUILD, NULL, NULL, test)))
|
1998-07-26 05:00:26 +08:00
|
|
|
return rc;
|
1998-04-10 00:46:30 +08:00
|
|
|
}
|
1998-07-26 05:00:26 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if (what & RPMBUILD_RMSOURCE)
|
1998-07-26 05:00:26 +08:00
|
|
|
doRmSource(spec);
|
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if (what & RPMBUILD_RMSPEC)
|
1999-04-30 23:55:45 +08:00
|
|
|
unlink(spec->specFile);
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
return 0;
|
1995-12-20 05:08:18 +08:00
|
|
|
}
|