2001-03-15 07:09:09 +08:00
|
|
|
/** \ingroup rpmcli
|
|
|
|
* Parse spec file and build package.
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1998-12-02 01:18:38 +08:00
|
|
|
|
2008-04-04 18:52:59 +08:00
|
|
|
#include <libgen.h>
|
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmcli.h>
|
2008-01-30 19:53:51 +08:00
|
|
|
#include <rpm/rpmtag.h>
|
|
|
|
#include <rpm/rpmlib.h> /* rpmrc, MACHTABLE .. */
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmbuild.h>
|
1999-10-30 07:03:12 +08:00
|
|
|
|
2007-12-08 20:02:32 +08:00
|
|
|
#include <rpm/rpmps.h>
|
|
|
|
#include <rpm/rpmte.h>
|
|
|
|
#include <rpm/rpmts.h>
|
|
|
|
#include <rpm/rpmfileutil.h>
|
2008-01-30 23:05:29 +08:00
|
|
|
#include <rpm/rpmlog.h>
|
2002-04-12 00:55:19 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
#include "build.h"
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2001-03-15 07:09:09 +08:00
|
|
|
/**
|
|
|
|
*/
|
2002-05-20 02:42:25 +08:00
|
|
|
static int checkSpec(rpmts ts, Header h)
|
1999-04-17 22:23:42 +08:00
|
|
|
{
|
2002-05-20 02:42:25 +08:00
|
|
|
rpmps ps;
|
1999-04-17 22:23:42 +08:00
|
|
|
int rc;
|
|
|
|
|
2001-10-28 04:09:20 +08:00
|
|
|
if (!headerIsEntry(h, RPMTAG_REQUIRENAME)
|
|
|
|
&& !headerIsEntry(h, RPMTAG_CONFLICTNAME))
|
1999-04-17 22:23:42 +08:00
|
|
|
return 0;
|
|
|
|
|
2002-05-28 05:40:08 +08:00
|
|
|
rc = rpmtsAddInstallElement(ts, h, NULL, 0, NULL);
|
2002-05-17 00:55:21 +08:00
|
|
|
|
|
|
|
rc = rpmtsCheck(ts);
|
2002-04-12 00:55:19 +08:00
|
|
|
|
2002-05-28 05:40:08 +08:00
|
|
|
ps = rpmtsProblems(ts);
|
2002-06-12 22:54:06 +08:00
|
|
|
if (rc == 0 && rpmpsNumProblems(ps) > 0) {
|
2007-10-09 19:49:02 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("Failed build dependencies:\n"));
|
2002-06-29 05:54:24 +08:00
|
|
|
rpmpsPrint(NULL, ps);
|
1999-04-17 22:23:42 +08:00
|
|
|
rc = 1;
|
|
|
|
}
|
2002-05-20 02:42:25 +08:00
|
|
|
ps = rpmpsFree(ps);
|
1999-04-17 22:23:42 +08:00
|
|
|
|
2002-04-12 00:55:19 +08:00
|
|
|
/* XXX nuke the added package. */
|
2002-05-17 00:55:21 +08:00
|
|
|
rpmtsClean(ts);
|
2002-04-12 00:55:19 +08:00
|
|
|
|
1999-04-17 22:23:42 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2001-03-15 07:09:09 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-05-04 05:00:18 +08:00
|
|
|
static int isSpecFile(const char * specfile)
|
1999-07-23 03:38:25 +08:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
const char * s;
|
2008-03-25 01:01:29 +08:00
|
|
|
FILE * f;
|
1999-07-23 03:38:25 +08:00
|
|
|
int count;
|
|
|
|
int checking;
|
|
|
|
|
2008-03-25 01:01:29 +08:00
|
|
|
f = fopen(specfile, "r");
|
|
|
|
if (f == NULL || ferror(f)) {
|
2007-11-19 22:25:24 +08:00
|
|
|
rpmlog(RPMLOG_ERR, _("Unable to open spec file %s: %s\n"),
|
2008-03-25 01:01:29 +08:00
|
|
|
specfile, strerror(errno));
|
1999-07-23 03:38:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-03-25 01:01:29 +08:00
|
|
|
count = fread(buf, sizeof(buf[0]), sizeof(buf), f);
|
|
|
|
(void) fclose(f);
|
1999-07-23 03:38:25 +08:00
|
|
|
|
2008-04-04 16:53:07 +08:00
|
|
|
if (count == 0)
|
|
|
|
return 0;
|
|
|
|
|
1999-07-23 03:38:25 +08:00
|
|
|
checking = 1;
|
|
|
|
for (s = buf; count--; s++) {
|
|
|
|
switch (*s) {
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
checking = 1;
|
2007-09-12 01:04:11 +08:00
|
|
|
break;
|
1999-07-23 03:38:25 +08:00
|
|
|
case ':':
|
|
|
|
checking = 0;
|
2007-09-12 01:04:11 +08:00
|
|
|
break;
|
1999-07-23 03:38:25 +08:00
|
|
|
default:
|
2007-06-08 21:07:05 +08:00
|
|
|
#if 0
|
1999-07-23 03:38:25 +08:00
|
|
|
if (checking && !(isprint(*s) || isspace(*s))) return 0;
|
2007-09-12 01:04:11 +08:00
|
|
|
break;
|
2007-06-08 21:07:05 +08:00
|
|
|
#else
|
|
|
|
if (checking && !(isprint(*s) || isspace(*s)) && *(unsigned char *)s < 32) return 0;
|
2007-09-12 01:04:11 +08:00
|
|
|
break;
|
2007-06-08 21:07:05 +08:00
|
|
|
#endif
|
1999-07-23 03:38:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-04 18:52:59 +08:00
|
|
|
/*
|
|
|
|
* Try to find a spec from a tarball pointed to by arg.
|
|
|
|
* Return absolute path to spec name on success, otherwise NULL.
|
|
|
|
*/
|
|
|
|
static char * getTarSpec(const char *arg)
|
|
|
|
{
|
|
|
|
char *specFile = NULL;
|
|
|
|
char *specDir;
|
|
|
|
char *specBase;
|
|
|
|
char *tmpSpecFile;
|
|
|
|
const char **try;
|
|
|
|
char tarbuf[BUFSIZ];
|
2008-04-04 21:03:59 +08:00
|
|
|
int gotspec = 0, res;
|
2008-04-04 18:52:59 +08:00
|
|
|
static const char *tryspec[] = { "Specfile", "\\*.spec", NULL };
|
|
|
|
|
|
|
|
specDir = rpmGetPath("%{_specdir}", NULL);
|
|
|
|
tmpSpecFile = rpmGetPath("%{_specdir}/", "rpm-spec.XXXXXX", NULL);
|
|
|
|
|
|
|
|
(void) close(mkstemp(tmpSpecFile));
|
|
|
|
|
|
|
|
for (try = tryspec; *try != NULL; try++) {
|
|
|
|
FILE *fp;
|
|
|
|
char *cmd;
|
|
|
|
|
2008-04-04 21:03:59 +08:00
|
|
|
cmd = rpmExpand("%{uncompress: ", arg, "} | ",
|
|
|
|
"%{__tar} xOvf - --wildcards ", *try,
|
|
|
|
" 2>&1 > ", tmpSpecFile, NULL);
|
2008-04-04 18:52:59 +08:00
|
|
|
|
|
|
|
if (!(fp = popen(cmd, "r"))) {
|
|
|
|
rpmlog(RPMLOG_ERR, _("Failed to open tar pipe: %m\n"));
|
|
|
|
} else {
|
2008-04-04 19:33:45 +08:00
|
|
|
char *fok = fgets(tarbuf, sizeof(tarbuf) - 1, fp);
|
2008-04-04 18:52:59 +08:00
|
|
|
pclose(fp);
|
2008-04-04 19:33:45 +08:00
|
|
|
gotspec = (fok != NULL) && isSpecFile(tmpSpecFile);
|
2008-04-04 18:52:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gotspec)
|
|
|
|
unlink(tmpSpecFile);
|
|
|
|
free(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gotspec) {
|
|
|
|
rpmlog(RPMLOG_ERR, _("Failed to read spec file from %s\n"), arg);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
specBase = basename(tarbuf);
|
|
|
|
/* remove trailing \n */
|
|
|
|
specBase[strlen(specBase)-1] = '\0';
|
|
|
|
|
|
|
|
rasprintf(&specFile, "%s/%s", specDir, specBase);
|
|
|
|
res = rename(tmpSpecFile, specFile);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
rpmlog(RPMLOG_ERR, _("Failed to rename %s to %s: %m\n"),
|
|
|
|
tmpSpecFile, specFile);
|
|
|
|
free(specFile);
|
|
|
|
specFile = NULL;
|
2008-04-22 21:08:43 +08:00
|
|
|
} else {
|
|
|
|
/* mkstemp() can give unnecessarily strict permissions, fixup */
|
|
|
|
mode_t mask;
|
|
|
|
umask(mask = umask(0));
|
|
|
|
(void) chmod(specFile, 0666 & ~mask);
|
2008-04-04 18:52:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
(void) unlink(tmpSpecFile);
|
|
|
|
free(tmpSpecFile);
|
|
|
|
free(specDir);
|
|
|
|
return specFile;
|
|
|
|
}
|
|
|
|
|
2001-03-15 07:09:09 +08:00
|
|
|
/**
|
|
|
|
*/
|
2002-05-20 02:42:25 +08:00
|
|
|
static int buildForTarget(rpmts ts, const char * arg, BTA_t ba)
|
1998-08-09 06:27:08 +08:00
|
|
|
{
|
2001-10-24 00:48:20 +08:00
|
|
|
const char * passPhrase = ba->passPhrase;
|
2001-10-24 04:52:51 +08:00
|
|
|
const char * cookie = ba->cookie;
|
1999-04-17 22:23:42 +08:00
|
|
|
int buildAmount = ba->buildAmount;
|
2007-12-15 17:03:46 +08:00
|
|
|
char * buildRootURL = NULL;
|
2008-04-04 19:59:55 +08:00
|
|
|
char * specFile = NULL;
|
2007-09-21 20:23:02 +08:00
|
|
|
rpmSpec spec = NULL;
|
2008-04-04 17:06:06 +08:00
|
|
|
int rc = 1; /* assume failure */
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2000-12-03 05:53:44 +08:00
|
|
|
#ifndef DYING
|
|
|
|
rpmSetTables(RPM_MACHTABLE_BUILDARCH, RPM_MACHTABLE_BUILDOS);
|
|
|
|
#endif
|
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
if (ba->buildRootOverride)
|
|
|
|
buildRootURL = rpmGenPath(NULL, ba->buildRootOverride, NULL);
|
|
|
|
|
2001-01-02 07:14:47 +08:00
|
|
|
if (ba->buildMode == 't') {
|
2008-04-04 18:52:59 +08:00
|
|
|
char *srcdir = NULL, *dir;
|
1998-04-02 00:02:05 +08:00
|
|
|
|
2008-04-04 19:59:55 +08:00
|
|
|
specFile = getTarSpec(arg);
|
|
|
|
if (!specFile)
|
2008-04-04 18:52:59 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2008-04-04 18:52:59 +08:00
|
|
|
/* Make the directory of the tarball %_sourcedir for this run */
|
|
|
|
/* dirname() may modify contents so extra hoops needed. */
|
1998-01-13 05:31:29 +08:00
|
|
|
if (*arg != '/') {
|
2008-04-04 18:52:59 +08:00
|
|
|
srcdir = dir = rpmGetCwd();
|
|
|
|
} else {
|
|
|
|
dir = xstrdup(arg);
|
|
|
|
srcdir = dirname(dir);
|
|
|
|
}
|
|
|
|
addMacro(NULL, "_sourcedir", NULL, srcdir, RMIL_TARBALL);
|
|
|
|
free(dir);
|
1998-01-13 05:31:29 +08:00
|
|
|
} else {
|
2008-04-04 19:59:55 +08:00
|
|
|
specFile = xstrdup(arg);
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
if (*specFile != '/') {
|
2008-04-04 19:59:55 +08:00
|
|
|
char *cwd = rpmGetCwd();
|
|
|
|
char *s = NULL;
|
2008-04-04 22:00:38 +08:00
|
|
|
rasprintf(&s, "%s/%s", cwd, arg);
|
2008-04-04 19:59:55 +08:00
|
|
|
free(specFile);
|
|
|
|
specFile = s;
|
1999-11-24 08:03:54 +08:00
|
|
|
}
|
|
|
|
|
2008-04-04 19:59:55 +08:00
|
|
|
struct stat st;
|
|
|
|
if (stat(specFile, &st) < 0) {
|
|
|
|
rpmlog(RPMLOG_ERR, _("failed to stat %s: %m\n"), specFile);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (! S_ISREG(st.st_mode)) {
|
|
|
|
rpmlog(RPMLOG_ERR, _("File %s is not a regular file.\n"), specFile);
|
|
|
|
goto exit;
|
|
|
|
}
|
1999-07-23 03:38:25 +08:00
|
|
|
|
2008-04-04 19:59:55 +08:00
|
|
|
/* Try to verify that the file is actually a specfile */
|
|
|
|
if (!isSpecFile(specFile)) {
|
|
|
|
rpmlog(RPMLOG_ERR,
|
|
|
|
_("File %s does not appear to be a specfile.\n"), specFile);
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1999-07-23 03:38:25 +08:00
|
|
|
|
1999-04-17 22:23:42 +08:00
|
|
|
/* Parse the spec file */
|
1998-09-25 04:36:54 +08:00
|
|
|
#define _anyarch(_f) \
|
1998-11-08 06:05:28 +08:00
|
|
|
(((_f)&(RPMBUILD_PREP|RPMBUILD_BUILD|RPMBUILD_INSTALL|RPMBUILD_PACKAGEBINARY)) == 0)
|
2008-04-04 19:59:55 +08:00
|
|
|
if (parseSpec(ts, specFile, ba->rootdir, buildRootURL, 0, passPhrase,
|
2002-12-22 10:11:05 +08:00
|
|
|
cookie, _anyarch(buildAmount), ba->force))
|
|
|
|
{
|
1999-11-24 08:03:54 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1998-09-25 04:36:54 +08:00
|
|
|
#undef _anyarch
|
2002-12-22 10:11:05 +08:00
|
|
|
if ((spec = rpmtsSetSpec(ts, NULL)) == NULL) {
|
|
|
|
goto exit;
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-04-17 22:23:42 +08:00
|
|
|
/* Assemble source header from parsed components */
|
|
|
|
initSourceHeader(spec);
|
|
|
|
|
|
|
|
/* Check build prerequisites */
|
2001-10-28 04:09:20 +08:00
|
|
|
if (!ba->noDeps && checkSpec(ts, spec->sourceHeader)) {
|
1999-11-24 08:03:54 +08:00
|
|
|
goto exit;
|
1999-04-17 22:23:42 +08:00
|
|
|
}
|
|
|
|
|
2002-12-24 15:21:04 +08:00
|
|
|
if (buildSpec(ts, spec, buildAmount, ba->noBuild)) {
|
1999-11-24 08:03:54 +08:00
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (ba->buildMode == 't')
|
2008-04-04 19:59:55 +08:00
|
|
|
(void) unlink(specFile);
|
1999-11-24 08:03:54 +08:00
|
|
|
rc = 0;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
exit:
|
2008-04-04 19:59:55 +08:00
|
|
|
free(specFile);
|
2008-04-04 18:52:59 +08:00
|
|
|
freeSpec(spec);
|
|
|
|
free(buildRootURL);
|
1999-11-24 08:03:54 +08:00
|
|
|
return rc;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1998-08-09 06:27:08 +08:00
|
|
|
|
2002-05-20 02:42:25 +08:00
|
|
|
int build(rpmts ts, const char * arg, BTA_t ba, const char * rcfile)
|
1998-08-09 06:27:08 +08:00
|
|
|
{
|
1999-03-18 02:11:01 +08:00
|
|
|
char *t, *te;
|
1999-10-30 07:03:12 +08:00
|
|
|
int rc = 0;
|
2001-05-04 05:00:18 +08:00
|
|
|
char * targets = ba->targets;
|
1999-10-30 07:03:12 +08:00
|
|
|
#define buildCleanMask (RPMBUILD_RMSOURCE|RPMBUILD_RMSPEC)
|
|
|
|
int cleanFlags = ba->buildAmount & buildCleanMask;
|
2002-08-06 09:41:44 +08:00
|
|
|
rpmVSFlags vsflags, ovsflags;
|
2002-07-28 22:52:33 +08:00
|
|
|
|
|
|
|
vsflags = rpmExpandNumeric("%{_vsflags_build}");
|
|
|
|
if (ba->qva_flags & VERIFY_DIGEST)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NODIGESTS;
|
2002-07-28 22:52:33 +08:00
|
|
|
if (ba->qva_flags & VERIFY_SIGNATURE)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= _RPMVSF_NOSIGNATURES;
|
2002-07-28 22:52:33 +08:00
|
|
|
if (ba->qva_flags & VERIFY_HDRCHK)
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags |= RPMVSF_NOHDRCHK;
|
|
|
|
ovsflags = rpmtsSetVSFlags(ts, vsflags);
|
1998-08-09 06:27:08 +08:00
|
|
|
|
1998-12-02 07:28:26 +08:00
|
|
|
if (targets == NULL) {
|
2001-10-28 04:09:20 +08:00
|
|
|
rc = buildForTarget(ts, arg, ba);
|
1999-10-30 07:03:12 +08:00
|
|
|
goto exit;
|
1998-08-09 06:27:08 +08:00
|
|
|
}
|
|
|
|
|
1998-08-16 22:26:04 +08:00
|
|
|
/* parse up the build operators */
|
|
|
|
|
1999-04-28 22:12:55 +08:00
|
|
|
printf(_("Building target platforms: %s\n"), targets);
|
1998-08-16 22:26:04 +08:00
|
|
|
|
1999-10-30 07:03:12 +08:00
|
|
|
ba->buildAmount &= ~buildCleanMask;
|
1999-03-18 04:01:09 +08:00
|
|
|
for (t = targets; *t != '\0'; t = te) {
|
|
|
|
char *target;
|
|
|
|
if ((te = strchr(t, ',')) == NULL)
|
|
|
|
te = t + strlen(t);
|
2008-04-28 18:38:32 +08:00
|
|
|
target = xmalloc(te-t+1);
|
1999-03-18 02:11:01 +08:00
|
|
|
strncpy(target, t, (te-t));
|
|
|
|
target[te-t] = '\0';
|
2001-05-04 05:00:18 +08:00
|
|
|
if (*te != '\0')
|
1999-10-30 07:03:12 +08:00
|
|
|
te++;
|
|
|
|
else /* XXX Perform clean-up after last target build. */
|
|
|
|
ba->buildAmount |= cleanFlags;
|
|
|
|
|
1999-04-28 22:12:55 +08:00
|
|
|
printf(_("Building for target %s\n"), target);
|
1998-08-09 06:27:08 +08:00
|
|
|
|
1999-10-30 07:03:12 +08:00
|
|
|
/* Read in configuration for target. */
|
1999-12-13 05:14:05 +08:00
|
|
|
rpmFreeMacros(NULL);
|
2004-10-18 03:00:10 +08:00
|
|
|
rpmFreeRpmrc();
|
2001-05-04 05:00:18 +08:00
|
|
|
(void) rpmReadConfigFiles(rcfile, target);
|
2008-04-28 18:38:32 +08:00
|
|
|
free(target);
|
2001-10-28 04:09:20 +08:00
|
|
|
rc = buildForTarget(ts, arg, ba);
|
1998-08-09 06:27:08 +08:00
|
|
|
if (rc)
|
1999-10-30 07:03:12 +08:00
|
|
|
break;
|
1998-08-09 06:27:08 +08:00
|
|
|
}
|
|
|
|
|
1999-10-30 07:03:12 +08:00
|
|
|
exit:
|
2002-08-06 09:41:44 +08:00
|
|
|
vsflags = rpmtsSetVSFlags(ts, ovsflags);
|
1999-10-30 07:03:12 +08:00
|
|
|
/* Restore original configuration. */
|
1999-12-13 05:14:05 +08:00
|
|
|
rpmFreeMacros(NULL);
|
2004-10-18 03:00:10 +08:00
|
|
|
rpmFreeRpmrc();
|
2001-05-04 05:00:18 +08:00
|
|
|
(void) rpmReadConfigFiles(rcfile, NULL);
|
2001-10-28 04:09:20 +08:00
|
|
|
|
1999-10-30 07:03:12 +08:00
|
|
|
return rc;
|
1998-08-09 06:27:08 +08:00
|
|
|
}
|