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
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmbuild.h>
|
|
|
|
#include <rpm/rpmlog.h>
|
|
|
|
#include <rpm/rpmfileutil.h>
|
1995-12-14 23:56:10 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
static int _build_debug = 0;
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
2007-09-21 20:23:02 +08:00
|
|
|
static void doRmSource(rpmSpec spec)
|
1995-11-28 06:31:21 +08:00
|
|
|
{
|
1998-07-26 05:00:26 +08:00
|
|
|
struct Source *p;
|
|
|
|
Package pkg;
|
2001-10-15 11:22:10 +08:00
|
|
|
int rc;
|
1998-07-26 05:00:26 +08:00
|
|
|
|
1999-04-30 23:55:45 +08:00
|
|
|
#if 0
|
2007-12-03 22:33:18 +08:00
|
|
|
rc = 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)) {
|
2007-12-15 16:39:15 +08:00
|
|
|
char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL);
|
2007-12-03 22:33:18 +08:00
|
|
|
rc = unlink(fn);
|
2001-04-29 09:05:43 +08:00
|
|
|
fn = _free(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)) {
|
2007-12-15 16:39:15 +08:00
|
|
|
char *fn = rpmGetPath("%{_sourcedir}/", p->source, NULL);
|
2007-12-03 22:33:18 +08:00
|
|
|
rc = unlink(fn);
|
2001-04-29 09:05:43 +08:00
|
|
|
fn = _free(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
|
|
|
/*
|
2001-01-11 22:13:04 +08:00
|
|
|
* @todo Single use by %%doc in files.c prevents static.
|
1998-09-06 04:02:08 +08:00
|
|
|
*/
|
2007-12-07 15:28:39 +08:00
|
|
|
rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name, StringBuf sb, int test)
|
1996-01-08 15:06:16 +08:00
|
|
|
{
|
2008-04-05 01:37:48 +08:00
|
|
|
const char * rootDir = spec->rootDir;
|
2007-12-16 22:25:09 +08:00
|
|
|
char *scriptName = NULL;
|
2008-04-09 13:17:48 +08:00
|
|
|
char * buildDir = rpmGenPath(rootDir, "%{_builddir}", "");
|
2007-12-15 22:03:18 +08:00
|
|
|
char * buildCmd = NULL;
|
|
|
|
char * buildTemplate = NULL;
|
|
|
|
char * buildPost = NULL;
|
1999-11-20 02:19:41 +08:00
|
|
|
const char * mTemplate = NULL;
|
2005-02-12 22:12:33 +08:00
|
|
|
const char * mCmd = NULL;
|
1999-11-20 02:19:41 +08:00
|
|
|
const char * mPost = NULL;
|
|
|
|
int argc = 0;
|
|
|
|
const char **argv = NULL;
|
|
|
|
FILE * fp = NULL;
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fd;
|
1999-11-05 05:26:08 +08:00
|
|
|
FD_t xfd;
|
2007-12-07 15:28:39 +08:00
|
|
|
pid_t pid;
|
2007-12-07 15:01:25 +08:00
|
|
|
pid_t child;
|
2007-12-07 15:28:39 +08:00
|
|
|
int status;
|
|
|
|
rpmRC rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
switch (what) {
|
2001-10-16 01:53:34 +08:00
|
|
|
case RPMBUILD_PREP:
|
1998-01-13 05:31:29 +08:00
|
|
|
name = "%prep";
|
|
|
|
sb = spec->prep;
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_prep_template}";
|
|
|
|
mPost = "%{__spec_prep_post}";
|
2005-02-12 22:12:33 +08:00
|
|
|
mCmd = "%{__spec_prep_cmd}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
2001-10-16 01:53:34 +08:00
|
|
|
case RPMBUILD_BUILD:
|
1998-01-13 05:31:29 +08:00
|
|
|
name = "%build";
|
|
|
|
sb = spec->build;
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_build_template}";
|
|
|
|
mPost = "%{__spec_build_post}";
|
2005-02-12 22:12:33 +08:00
|
|
|
mCmd = "%{__spec_build_cmd}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
2001-10-16 01:53:34 +08:00
|
|
|
case RPMBUILD_INSTALL:
|
1998-01-13 05:31:29 +08:00
|
|
|
name = "%install";
|
|
|
|
sb = spec->install;
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_install_template}";
|
|
|
|
mPost = "%{__spec_install_post}";
|
2005-02-12 22:12:33 +08:00
|
|
|
mCmd = "%{__spec_install_cmd}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
2002-12-22 04:37:37 +08:00
|
|
|
case RPMBUILD_CHECK:
|
|
|
|
name = "%check";
|
|
|
|
sb = spec->check;
|
|
|
|
mTemplate = "%{__spec_check_template}";
|
|
|
|
mPost = "%{__spec_check_post}";
|
2005-02-12 22:12:33 +08:00
|
|
|
mCmd = "%{__spec_check_cmd}";
|
2002-12-22 04:37:37 +08:00
|
|
|
break;
|
2001-10-16 01:53:34 +08:00
|
|
|
case RPMBUILD_CLEAN:
|
1998-01-13 05:31:29 +08:00
|
|
|
name = "%clean";
|
|
|
|
sb = spec->clean;
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_clean_template}";
|
|
|
|
mPost = "%{__spec_clean_post}";
|
2005-02-12 22:12:33 +08:00
|
|
|
mCmd = "%{__spec_clean_cmd}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
2001-10-16 01:53:34 +08:00
|
|
|
case RPMBUILD_RMBUILD:
|
1998-01-13 05:31:29 +08:00
|
|
|
name = "--clean";
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{__spec_clean_template}";
|
|
|
|
mPost = "%{__spec_clean_post}";
|
2005-02-12 22:12:33 +08:00
|
|
|
mCmd = "%{__spec_clean_cmd}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
2001-10-16 01:53:34 +08:00
|
|
|
case RPMBUILD_STRINGBUF:
|
|
|
|
default:
|
1999-11-20 02:19:41 +08:00
|
|
|
mTemplate = "%{___build_template}";
|
|
|
|
mPost = "%{___build_post}";
|
2005-02-12 22:12:33 +08:00
|
|
|
mCmd = "%{___build_cmd}";
|
1998-01-13 05:31:29 +08:00
|
|
|
break;
|
|
|
|
}
|
2003-05-09 04:39:29 +08:00
|
|
|
if (name == NULL) /* XXX shouldn't happen */
|
|
|
|
name = "???";
|
1999-11-01 05:38:21 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
if ((what != RPMBUILD_RMBUILD) && sb == NULL) {
|
2007-12-07 15:28:39 +08:00
|
|
|
rc = RPMRC_OK;
|
1999-11-20 02:19:41 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2008-05-03 17:34:19 +08:00
|
|
|
fd = rpmMkTempFile(rootDir, &scriptName);
|
2008-04-11 14:05:05 +08:00
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("Unable to open temp file.\n"));
|
2007-12-07 15:28:39 +08:00
|
|
|
rc = RPMRC_FAIL;
|
1999-11-20 02:19:41 +08:00
|
|
|
goto exit;
|
1996-01-08 15:06:16 +08:00
|
|
|
}
|
1999-11-20 02:19:41 +08:00
|
|
|
|
2007-10-29 15:42:21 +08:00
|
|
|
if (fdGetFILE(fd) == NULL)
|
1999-11-20 02:19:41 +08:00
|
|
|
xfd = Fdopen(fd, "w.fpio");
|
|
|
|
else
|
|
|
|
xfd = fd;
|
2001-10-16 01:53:34 +08:00
|
|
|
|
2007-10-29 15:42:21 +08:00
|
|
|
if ((fp = fdGetFILE(xfd)) == NULL) {
|
2007-12-07 15:28:39 +08:00
|
|
|
rc = RPMRC_FAIL;
|
1999-11-20 02:19:41 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
if (*rootDir == '\0') rootDir = "/";
|
1998-09-06 07:13:35 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
buildTemplate = rpmExpand(mTemplate, NULL);
|
|
|
|
buildPost = rpmExpand(mPost, NULL);
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fputs(buildTemplate, fp);
|
1999-11-20 02:19:41 +08:00
|
|
|
|
|
|
|
if (what != RPMBUILD_PREP && what != RPMBUILD_RMBUILD && spec->buildSubdir)
|
2007-08-29 20:39:55 +08:00
|
|
|
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)
|
2007-08-29 20:39:55 +08:00
|
|
|
fprintf(fp, "rm -rf '%s'\n", spec->buildSubdir);
|
2003-05-09 04:39:29 +08:00
|
|
|
} else if (sb != NULL)
|
1999-11-19 02:07:46 +08:00
|
|
|
fprintf(fp, "%s", getStringBuf(sb));
|
1999-11-20 02:19:41 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) fputs(buildPost, fp);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(xfd);
|
1995-12-28 00:54:54 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
if (test) {
|
2007-12-07 15:28:39 +08:00
|
|
|
rc = RPMRC_OK;
|
1999-11-20 02:19:41 +08:00
|
|
|
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)
|
2008-04-09 13:17:48 +08:00
|
|
|
fprintf(stderr, "*** rootDir %s buildDir %s\n", rootDir, buildDir);
|
|
|
|
if (buildDir && buildDir[0] != '/') {
|
2007-12-07 15:28:39 +08:00
|
|
|
rc = RPMRC_FAIL;
|
1999-11-20 02:19:41 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2008-04-09 13:17:48 +08:00
|
|
|
buildCmd = rpmExpand(mCmd, " ", scriptName, NULL);
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) poptParseArgvString(buildCmd, &argc, &argv);
|
1999-11-20 02:19:41 +08:00
|
|
|
|
2007-10-09 19:50:42 +08:00
|
|
|
rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd);
|
1999-11-20 02:19:41 +08:00
|
|
|
if (!(child = fork())) {
|
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
errno = 0;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) execvp(argv[0], (char *const *)argv);
|
1999-11-20 02:19:41 +08:00
|
|
|
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("Exec of %s failed (%s): %s\n"),
|
2001-01-16 07:09:42 +08:00
|
|
|
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
|
|
|
|
2007-12-07 15:01:25 +08:00
|
|
|
pid = waitpid(child, &status, 0);
|
1999-11-20 02:19:41 +08:00
|
|
|
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("Bad exit status from %s (%s)\n"),
|
1998-01-13 05:31:29 +08:00
|
|
|
scriptName, name);
|
2007-12-07 15:28:39 +08:00
|
|
|
rc = RPMRC_FAIL;
|
1999-11-20 02:19:41 +08:00
|
|
|
} else
|
2007-12-07 15:28:39 +08:00
|
|
|
rc = RPMRC_OK;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
exit:
|
|
|
|
if (scriptName) {
|
2007-12-07 15:28:39 +08:00
|
|
|
if (rc == RPMRC_OK)
|
2007-12-03 22:33:18 +08:00
|
|
|
(void) unlink(scriptName);
|
2001-04-29 09:05:43 +08:00
|
|
|
scriptName = _free(scriptName);
|
1999-11-20 02:19:41 +08:00
|
|
|
}
|
2001-04-29 09:05:43 +08:00
|
|
|
argv = _free(argv);
|
|
|
|
buildCmd = _free(buildCmd);
|
|
|
|
buildTemplate = _free(buildTemplate);
|
|
|
|
buildPost = _free(buildPost);
|
2008-04-09 13:17:48 +08:00
|
|
|
buildDir = _free(buildDir);
|
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
|
|
|
}
|
|
|
|
|
2007-12-07 15:28:39 +08:00
|
|
|
rpmRC buildSpec(rpmts ts, rpmSpec spec, int what, int test)
|
1995-12-14 23:56:10 +08:00
|
|
|
{
|
2007-12-07 15:28:39 +08:00
|
|
|
rpmRC rc = RPMRC_OK;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2001-05-07 03:17:14 +08:00
|
|
|
if (!spec->recursing && spec->BACount) {
|
2000-12-03 05:53:44 +08:00
|
|
|
int x;
|
2001-05-07 03:17:14 +08:00
|
|
|
/* When iterating over BANames, do the source */
|
1998-07-26 05:00:26 +08:00
|
|
|
/* packaging on the first run, and skip RMSOURCE altogether */
|
2001-05-07 03:17:14 +08:00
|
|
|
if (spec->BASpecs != NULL)
|
|
|
|
for (x = 0; x < spec->BACount; x++) {
|
2002-12-24 15:21:04 +08:00
|
|
|
if ((rc = buildSpec(ts, spec->BASpecs[x],
|
1998-07-26 05:00:26 +08:00
|
|
|
(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
|
|
|
|
2002-12-22 04:37:37 +08:00
|
|
|
if ((what & RPMBUILD_CHECK) &&
|
|
|
|
(rc = doScript(spec, RPMBUILD_CHECK, NULL, NULL, test)))
|
|
|
|
goto exit;
|
|
|
|
|
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-12-03 05:53:44 +08:00
|
|
|
return rc;
|
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)
|
2007-12-03 22:33:18 +08:00
|
|
|
(void) unlink(spec->specFile);
|
1999-04-30 23:55:45 +08:00
|
|
|
|
2000-09-02 05:15:40 +08:00
|
|
|
exit:
|
2007-12-07 15:28:39 +08:00
|
|
|
if (rc != RPMRC_OK && rpmlogGetNrecs() > 0) {
|
2007-10-09 19:50:42 +08:00
|
|
|
rpmlog(RPMLOG_NOTICE, _("\n\nRPM build errors:\n"));
|
2000-09-02 05:15:40 +08:00
|
|
|
rpmlogPrint(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
1995-12-20 05:08:18 +08:00
|
|
|
}
|