2000-08-28 03:18:25 +08:00
|
|
|
/** \ingroup rpmbuild
|
|
|
|
* \file build/build.c
|
2000-01-25 04:02:32 +08:00
|
|
|
* Top-level build dispatcher.
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1995-12-14 23:56:10 +08:00
|
|
|
|
2000-06-10 02:57:23 +08:00
|
|
|
#include <rpmio_internal.h>
|
2000-06-20 23:54:48 +08:00
|
|
|
#include <rpmbuild.h>
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
static int _build_debug = 0;
|
|
|
|
|
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.
|
|
|
|
*/
|
2000-01-25 04:02:32 +08:00
|
|
|
/** */
|
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
|
|
|
{
|
1999-11-20 02:19:41 +08:00
|
|
|
const char * rootURL = spec->rootURL;
|
|
|
|
const char * rootDir;
|
|
|
|
const char *scriptName = NULL;
|
1999-11-24 08:03:54 +08:00
|
|
|
const char * buildDirURL = rpmGenPath(rootURL, "%{_builddir}", "");
|
1999-11-20 02:19:41 +08:00
|
|
|
const char * buildScript;
|
|
|
|
const char * buildCmd = NULL;
|
|
|
|
const char * buildTemplate = NULL;
|
|
|
|
const char * buildPost = NULL;
|
|
|
|
const char * mTemplate = NULL;
|
|
|
|
const char * mPost = NULL;
|
|
|
|
int argc = 0;
|
|
|
|
const char **argv = NULL;
|
|
|
|
FILE * fp = NULL;
|
|
|
|
urlinfo u = NULL;
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fd;
|
1999-11-05 05:26:08 +08:00
|
|
|
FD_t xfd;
|
1999-11-20 02:19:41 +08:00
|
|
|
int child;
|
1998-01-13 05:31:29 +08:00
|
|
|
int status;
|
1999-11-20 02:19:41 +08:00
|
|
|
int rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
switch (what) {
|
|
|
|
case RPMBUILD_PREP:
|
|
|
|
name = "%prep";
|
|
|
|
sb = spec->prep;
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_prep_template}";
|
|
|
|
mPost = "%{__spec_prep_post}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
|
|
|
case RPMBUILD_BUILD:
|
|
|
|
name = "%build";
|
|
|
|
sb = spec->build;
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_build_template}";
|
|
|
|
mPost = "%{__spec_build_post}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
|
|
|
case RPMBUILD_INSTALL:
|
|
|
|
name = "%install";
|
|
|
|
sb = spec->install;
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_install_template}";
|
|
|
|
mPost = "%{__spec_install_post}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
|
|
|
case RPMBUILD_CLEAN:
|
|
|
|
name = "%clean";
|
|
|
|
sb = spec->clean;
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_clean_template}";
|
|
|
|
mPost = "%{__spec_clean_post}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
|
|
|
case RPMBUILD_RMBUILD:
|
|
|
|
name = "--clean";
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_clean_template}";
|
|
|
|
mPost = "%{__spec_clean_post}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
|
|
|
case RPMBUILD_STRINGBUF:
|
1999-11-20 02:19:41 +08:00
|
|
|
default:
|
|
|
|
mTemplate = "%{___build_template}";
|
|
|
|
mPost = "%{___build_post}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
|
|
|
}
|
1999-11-01 05:38:21 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
if ((what != RPMBUILD_RMBUILD) && sb == NULL) {
|
|
|
|
rc = 0;
|
|
|
|
goto exit;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
if (makeTempFile(rootURL, &scriptName, &fd) || fd == NULL || Ferror(fd)) {
|
2000-02-29 09:57:37 +08:00
|
|
|
rpmError(RPMERR_SCRIPT, _("Unable to open temp file."));
|
1999-11-20 02:19:41 +08:00
|
|
|
rc = RPMERR_SCRIPT;
|
|
|
|
goto exit;
|
1996-01-08 15:06:16 +08:00
|
|
|
}
|
1999-11-20 02:19:41 +08:00
|
|
|
|
1999-06-18 05:35:34 +08:00
|
|
|
#ifdef HAVE_FCHMOD
|
1999-11-20 02:19:41 +08:00
|
|
|
switch (rootut) {
|
|
|
|
case URL_IS_PATH:
|
|
|
|
case URL_IS_UNKNOWN:
|
1999-11-24 08:03:54 +08:00
|
|
|
(void)fchmod(Fileno(fd), 0600);
|
1999-11-20 02:19:41 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-11-15 03:15:18 +08:00
|
|
|
#endif
|
1999-11-20 02:19:41 +08:00
|
|
|
|
|
|
|
if (fdGetFp(fd) == NULL)
|
|
|
|
xfd = Fdopen(fd, "w.fpio");
|
|
|
|
else
|
|
|
|
xfd = fd;
|
|
|
|
if ((fp = fdGetFp(xfd)) == NULL) {
|
|
|
|
rc = RPMERR_SCRIPT;
|
|
|
|
goto exit;
|
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
(void) urlPath(rootURL, &rootDir);
|
|
|
|
if (*rootDir == '\0') rootDir = "/";
|
1998-09-06 07:13:35 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
(void) urlPath(scriptName, &buildScript);
|
1998-09-06 04:02:08 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
buildTemplate = rpmExpand(mTemplate, NULL);
|
|
|
|
buildPost = rpmExpand(mPost, NULL);
|
|
|
|
|
|
|
|
fputs(buildTemplate, fp);
|
|
|
|
|
|
|
|
if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && spec->buildSubdir)
|
|
|
|
fprintf(fp, "cd %s\n", spec->buildSubdir);
|
1998-09-06 04:02:08 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (what == RPMBUILD_RMBUILD) {
|
1999-11-01 05:38:21 +08:00
|
|
|
if (spec->buildSubdir)
|
1999-11-19 02:07:46 +08:00
|
|
|
fprintf(fp, "rm -rf %s\n", spec->buildSubdir);
|
1999-11-01 05:38:21 +08:00
|
|
|
} else
|
1999-11-19 02:07:46 +08:00
|
|
|
fprintf(fp, "%s", getStringBuf(sb));
|
1999-11-20 02:19:41 +08:00
|
|
|
|
|
|
|
fputs(buildPost, fp);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-05 05:26:08 +08:00
|
|
|
Fclose(xfd);
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (test) {
|
1999-11-20 02:19:41 +08:00
|
|
|
rc = 0;
|
|
|
|
goto exit;
|
1995-12-28 00:54:54 +08:00
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
if (_build_debug)
|
|
|
|
fprintf(stderr, "*** rootURL %s buildDirURL %s\n", rootURL, buildDirURL);
|
|
|
|
if (buildDirURL && buildDirURL[0] != '/' &&
|
|
|
|
(urlSplit(buildDirURL, &u) != 0)) {
|
1999-11-20 02:19:41 +08:00
|
|
|
rc = RPMERR_SCRIPT;
|
|
|
|
goto exit;
|
|
|
|
}
|
1999-11-24 08:03:54 +08:00
|
|
|
if (u) {
|
|
|
|
switch (u->urltype) {
|
|
|
|
case URL_IS_FTP:
|
|
|
|
if (_build_debug)
|
|
|
|
fprintf(stderr, "*** addMacros\n");
|
|
|
|
addMacro(spec->macros, "_remsh", NULL, "%{__remsh}", RMIL_SPEC);
|
|
|
|
addMacro(spec->macros, "_remhost", NULL, u->host, RMIL_SPEC);
|
|
|
|
if (strcmp(rootDir, "/"))
|
|
|
|
addMacro(spec->macros, "_remroot", NULL, rootDir, RMIL_SPEC);
|
|
|
|
break;
|
|
|
|
case URL_IS_HTTP:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-11-20 02:19:41 +08:00
|
|
|
|
|
|
|
buildCmd = rpmExpand("%{___build_cmd}", " ", buildScript, NULL);
|
|
|
|
poptParseArgvString(buildCmd, &argc, &argv);
|
|
|
|
|
|
|
|
rpmMessage(RPMMESS_NORMAL, _("Executing(%s): %s\n"), name, buildCmd);
|
|
|
|
if (!(child = fork())) {
|
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
errno = 0;
|
1999-11-20 02:19:41 +08:00
|
|
|
execvp(argv[0], (char *const *)argv);
|
|
|
|
|
|
|
|
rpmError(RPMERR_SCRIPT, _("Exec of %s failed (%s): %s"), scriptName, name, strerror(errno));
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
_exit(-1);
|
1996-01-29 11:32:22 +08:00
|
|
|
}
|
1999-11-01 05:38:21 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
rc = waitpid(child, &status, 0);
|
|
|
|
|
|
|
|
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);
|
1999-11-20 02:19:41 +08:00
|
|
|
rc = RPMERR_SCRIPT;
|
|
|
|
} else
|
|
|
|
rc = 0;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
exit:
|
|
|
|
if (scriptName) {
|
|
|
|
if (!rc)
|
|
|
|
Unlink(scriptName);
|
|
|
|
xfree(scriptName);
|
|
|
|
}
|
1999-11-24 08:03:54 +08:00
|
|
|
if (u) {
|
|
|
|
switch (u->urltype) {
|
|
|
|
case URL_IS_FTP:
|
|
|
|
case URL_IS_HTTP:
|
|
|
|
if (_build_debug)
|
|
|
|
fprintf(stderr, "*** delMacros\n");
|
|
|
|
delMacro(spec->macros, "_remsh");
|
|
|
|
delMacro(spec->macros, "_remhost");
|
|
|
|
if (strcmp(rootDir, "/"))
|
|
|
|
delMacro(spec->macros, "_remroot");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-11-20 02:19:41 +08:00
|
|
|
FREE(argv);
|
|
|
|
FREE(buildCmd);
|
|
|
|
FREE(buildTemplate);
|
1999-11-24 08:03:54 +08:00
|
|
|
FREE(buildDirURL);
|
1995-12-14 23:56:10 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
return rc;
|
1995-12-14 23:56:10 +08:00
|
|
|
}
|
|
|
|
|
2000-01-25 04:02:32 +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))) {
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
1998-07-26 05:00:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
1999-11-01 05:38:21 +08:00
|
|
|
if ((what & RPMBUILD_PREP) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_PREP, NULL, NULL, test)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if ((what & RPMBUILD_BUILD) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_BUILD, NULL, NULL, test)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if ((what & RPMBUILD_INSTALL) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_INSTALL, NULL, NULL, test)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
1995-12-20 05:08:18 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if ((what & RPMBUILD_PACKAGESOURCE) &&
|
|
|
|
(rc = processSourceFiles(spec)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
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)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
1998-04-10 00:46:30 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if (((what & RPMBUILD_PACKAGESOURCE) && !test) &&
|
|
|
|
(rc = packageSources(spec)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if (((what & RPMBUILD_PACKAGEBINARY) && !test) &&
|
|
|
|
(rc = packageBinaries(spec)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
1998-07-26 05:00:26 +08:00
|
|
|
|
1999-11-01 05:38:21 +08:00
|
|
|
if ((what & RPMBUILD_CLEAN) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_CLEAN, NULL, NULL, test)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
1999-11-01 05:38:21 +08:00
|
|
|
|
|
|
|
if ((what & RPMBUILD_RMBUILD) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_RMBUILD, NULL, NULL, test)))
|
2000-09-02 05:15:40 +08:00
|
|
|
goto exit;
|
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);
|
2000-09-02 05:15:40 +08:00
|
|
|
rc = 0;
|
1999-04-30 23:55:45 +08:00
|
|
|
|
2000-09-02 05:15:40 +08:00
|
|
|
exit:
|
|
|
|
if (rc && rpmlogGetNrecs() > 0) {
|
|
|
|
rpmMessage(RPMMESS_NORMAL, _("\n\nRPM build errors:\n"));
|
|
|
|
rpmlogPrint(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
1995-12-20 05:08:18 +08:00
|
|
|
}
|