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
|
|
|
|
|
1999-10-30 07:03:12 +08:00
|
|
|
|
#include <rpmbuild.h>
|
|
|
|
|
#include <rpmurl.h>
|
|
|
|
|
|
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
|
|
|
|
/**
|
|
|
|
|
*/
|
1999-04-17 22:23:42 +08:00
|
|
|
|
static int checkSpec(Header h)
|
|
|
|
|
{
|
|
|
|
|
char *rootdir = NULL;
|
|
|
|
|
rpmdb db = NULL;
|
|
|
|
|
int mode = O_RDONLY;
|
|
|
|
|
rpmTransactionSet ts;
|
|
|
|
|
struct rpmDependencyConflict * conflicts;
|
|
|
|
|
int numConflicts;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
if (!headerIsEntry(h, RPMTAG_REQUIREFLAGS))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (rpmdbOpen(rootdir, &db, mode, 0644)) {
|
|
|
|
|
const char *dn;
|
|
|
|
|
dn = rpmGetPath( (rootdir ? rootdir : ""), "%{_dbpath}", NULL);
|
2000-12-03 05:53:44 +08:00
|
|
|
|
rpmError(RPMERR_OPEN, _("cannot open rpm database in %s\n"), dn);
|
2000-12-13 04:03:45 +08:00
|
|
|
|
free((void *)dn);
|
1999-04-17 22:23:42 +08:00
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
ts = rpmtransCreateSet(db, rootdir);
|
|
|
|
|
|
|
|
|
|
rc = rpmtransAddPackage(ts, h, NULL, NULL, 0, NULL);
|
|
|
|
|
|
|
|
|
|
rc = rpmdepCheck(ts, &conflicts, &numConflicts);
|
|
|
|
|
if (rc == 0 && conflicts) {
|
1999-05-26 12:05:33 +08:00
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("failed build dependencies:\n"));
|
1999-04-17 22:23:42 +08:00
|
|
|
|
printDepProblems(stderr, conflicts, numConflicts);
|
|
|
|
|
rpmdepFreeConflicts(conflicts, numConflicts);
|
|
|
|
|
rc = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ts)
|
|
|
|
|
rpmtransFree(ts);
|
|
|
|
|
if (db)
|
|
|
|
|
rpmdbClose(db);
|
|
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-23 03:38:25 +08:00
|
|
|
|
/*
|
|
|
|
|
* Kurwa, durni ameryka?ce sobe zawsze my?l?, ?e ca?y ?wiat m<EFBFBD>wi po
|
|
|
|
|
* angielsku...
|
|
|
|
|
*/
|
|
|
|
|
/* XXX this is still a dumb test but at least it's i18n aware */
|
2001-03-15 07:09:09 +08:00
|
|
|
|
/**
|
|
|
|
|
*/
|
1999-07-23 03:38:25 +08:00
|
|
|
|
static int isSpecFile(const char *specfile)
|
|
|
|
|
{
|
|
|
|
|
char buf[256];
|
|
|
|
|
const char * s;
|
|
|
|
|
FD_t fd;
|
|
|
|
|
int count;
|
|
|
|
|
int checking;
|
|
|
|
|
|
1999-11-05 05:26:08 +08:00
|
|
|
|
fd = Fopen(specfile, "r.ufdio");
|
1999-11-19 02:07:46 +08:00
|
|
|
|
if (fd == NULL || Ferror(fd)) {
|
2001-01-16 07:09:42 +08:00
|
|
|
|
rpmError(RPMERR_OPEN, _("Unable to open spec file %s: %s\n"),
|
|
|
|
|
specfile, Fstrerror(fd));
|
1999-07-23 03:38:25 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
1999-11-11 06:09:49 +08:00
|
|
|
|
count = Fread(buf, sizeof(buf[0]), sizeof(buf), fd);
|
1999-10-28 07:18:10 +08:00
|
|
|
|
Fclose(fd);
|
1999-07-23 03:38:25 +08:00
|
|
|
|
|
|
|
|
|
checking = 1;
|
|
|
|
|
for (s = buf; count--; s++) {
|
|
|
|
|
switch (*s) {
|
|
|
|
|
case '\r':
|
|
|
|
|
case '\n':
|
|
|
|
|
checking = 1;
|
|
|
|
|
break;
|
|
|
|
|
case ':':
|
|
|
|
|
checking = 0;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (checking && !(isprint(*s) || isspace(*s))) return 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-15 07:09:09 +08:00
|
|
|
|
/**
|
|
|
|
|
*/
|
1999-04-17 22:23:42 +08:00
|
|
|
|
static int buildForTarget(const char *arg, struct rpmBuildArguments *ba,
|
2001-01-02 07:14:47 +08:00
|
|
|
|
const char *passPhrase, char *cookie)
|
1998-08-09 06:27:08 +08:00
|
|
|
|
{
|
1999-04-17 22:23:42 +08:00
|
|
|
|
int buildAmount = ba->buildAmount;
|
1999-11-24 08:03:54 +08:00
|
|
|
|
const char *buildRootURL = NULL;
|
|
|
|
|
const char * specFile;
|
|
|
|
|
const char * specURL;
|
|
|
|
|
int specut;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
Spec spec = NULL;
|
1999-11-24 08:03:54 +08:00
|
|
|
|
int rc;
|
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') {
|
1999-11-24 08:03:54 +08:00
|
|
|
|
FILE *fp;
|
1999-01-06 07:13:56 +08:00
|
|
|
|
const char *specDir;
|
|
|
|
|
const char * tmpSpecFile;
|
1999-01-07 01:33:50 +08:00
|
|
|
|
char * cmd, *s;
|
2000-12-03 05:53:44 +08:00
|
|
|
|
rpmCompressedMagic res = COMPRESSED_OTHER;
|
2000-01-17 22:03:44 +08:00
|
|
|
|
static const char *zcmds[] = { "cat", "gunzip", "bunzip2", "cat" };
|
1998-09-06 05:54:05 +08:00
|
|
|
|
|
1999-01-06 07:13:56 +08:00
|
|
|
|
specDir = rpmGetPath("%{_specdir}", NULL);
|
|
|
|
|
|
2001-01-21 23:43:32 +08:00
|
|
|
|
/* XXX Using mkstemp is difficult here. */
|
|
|
|
|
/* XXX FWIW, default %{_specdir} is root.root 0755 */
|
1999-01-14 03:28:12 +08:00
|
|
|
|
{ char tfn[64];
|
|
|
|
|
strcpy(tfn, "rpm-spec.XXXXXX");
|
1999-01-27 23:40:06 +08:00
|
|
|
|
tmpSpecFile = rpmGetPath("%{_specdir}/", mktemp(tfn), NULL);
|
1999-01-14 03:28:12 +08:00
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
2000-01-15 22:17:07 +08:00
|
|
|
|
isCompressed(arg, &res);
|
|
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
|
cmd = alloca(strlen(arg) + 50 + strlen(tmpSpecFile));
|
2000-01-15 22:17:07 +08:00
|
|
|
|
sprintf(cmd, "%s < %s | tar xOvf - Specfile 2>&1 > %s",
|
|
|
|
|
zcmds[res & 0x3], arg, tmpSpecFile);
|
1999-11-24 08:03:54 +08:00
|
|
|
|
if (!(fp = popen(cmd, "r"))) {
|
2001-01-16 07:09:42 +08:00
|
|
|
|
rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
|
2000-12-13 04:03:45 +08:00
|
|
|
|
free((void *)specDir);
|
|
|
|
|
free((void *)tmpSpecFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
1999-11-24 08:03:54 +08:00
|
|
|
|
if ((!fgets(buf, sizeof(buf) - 1, fp)) || !strchr(buf, '/')) {
|
1998-04-02 00:02:05 +08:00
|
|
|
|
/* Try again */
|
1999-11-24 08:03:54 +08:00
|
|
|
|
pclose(fp);
|
1998-04-02 00:02:05 +08:00
|
|
|
|
|
2000-01-25 06:03:52 +08:00
|
|
|
|
sprintf(cmd, "%s < %s | tar xOvf - \\*.spec 2>&1 > %s",
|
|
|
|
|
zcmds[res & 0x3], arg, tmpSpecFile);
|
1999-11-24 08:03:54 +08:00
|
|
|
|
if (!(fp = popen(cmd, "r"))) {
|
2001-01-16 07:09:42 +08:00
|
|
|
|
rpmError(RPMERR_POPEN, _("Failed to open tar pipe: %m\n"));
|
2000-12-13 04:03:45 +08:00
|
|
|
|
free((void *)specDir);
|
|
|
|
|
free((void *)tmpSpecFile);
|
1998-04-02 00:02:05 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
1999-11-24 08:03:54 +08:00
|
|
|
|
if (!fgets(buf, sizeof(buf) - 1, fp)) {
|
1998-04-02 00:02:05 +08:00
|
|
|
|
/* Give up */
|
2001-01-16 07:09:42 +08:00
|
|
|
|
rpmError(RPMERR_READ, _("Failed to read spec file from %s\n"),
|
|
|
|
|
arg);
|
1998-04-02 00:02:05 +08:00
|
|
|
|
unlink(tmpSpecFile);
|
2000-12-13 04:03:45 +08:00
|
|
|
|
free((void *)specDir);
|
|
|
|
|
free((void *)tmpSpecFile);
|
1999-01-07 01:33:50 +08:00
|
|
|
|
return 1;
|
1998-04-02 00:02:05 +08:00
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
}
|
1999-11-24 08:03:54 +08:00
|
|
|
|
pclose(fp);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
|
cmd = s = buf;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
while (*cmd) {
|
1999-01-07 01:33:50 +08:00
|
|
|
|
if (*cmd == '/') s = cmd + 1;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
cmd++;
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-07 01:33:50 +08:00
|
|
|
|
cmd = s;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
|
|
/* remove trailing \n */
|
1999-01-07 01:33:50 +08:00
|
|
|
|
s = cmd + strlen(cmd) - 1;
|
|
|
|
|
*s = '\0';
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
|
specURL = s = alloca(strlen(specDir) + strlen(cmd) + 5);
|
1999-01-07 01:33:50 +08:00
|
|
|
|
sprintf(s, "%s/%s", specDir, cmd);
|
1999-10-30 00:06:01 +08:00
|
|
|
|
res = rename(tmpSpecFile, s);
|
2000-12-13 04:03:45 +08:00
|
|
|
|
free((void *)specDir);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
1999-10-30 00:06:01 +08:00
|
|
|
|
if (res) {
|
2001-01-16 07:09:42 +08:00
|
|
|
|
rpmError(RPMERR_RENAME, _("Failed to rename %s to %s: %m\n"),
|
2000-12-03 05:53:44 +08:00
|
|
|
|
tmpSpecFile, s);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
unlink(tmpSpecFile);
|
2000-12-13 04:03:45 +08:00
|
|
|
|
free((void *)tmpSpecFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2000-12-13 04:03:45 +08:00
|
|
|
|
free((void *)tmpSpecFile);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
|
|
/* Make the directory which contains the tarball the source
|
|
|
|
|
directory for this run */
|
|
|
|
|
|
|
|
|
|
if (*arg != '/') {
|
1998-11-17 05:40:28 +08:00
|
|
|
|
(void)getcwd(buf, BUFSIZ);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
strcat(buf, "/");
|
|
|
|
|
strcat(buf, arg);
|
|
|
|
|
} else
|
|
|
|
|
strcpy(buf, arg);
|
|
|
|
|
|
|
|
|
|
cmd = buf + strlen(buf) - 1;
|
|
|
|
|
while (*cmd != '/') cmd--;
|
|
|
|
|
*cmd = '\0';
|
|
|
|
|
|
1999-04-02 06:26:44 +08:00
|
|
|
|
addMacro(NULL, "_sourcedir", NULL, buf, RMIL_TARBALL);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
} else {
|
1999-11-24 08:03:54 +08:00
|
|
|
|
specURL = arg;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
|
specut = urlPath(specURL, &specFile);
|
|
|
|
|
if (*specFile != '/') {
|
|
|
|
|
char *s = alloca(BUFSIZ);
|
|
|
|
|
(void)getcwd(s, BUFSIZ);
|
|
|
|
|
strcat(s, "/");
|
|
|
|
|
strcat(s, arg);
|
|
|
|
|
specURL = s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (specut != URL_IS_DASH) {
|
|
|
|
|
struct stat st;
|
2000-09-02 05:15:40 +08:00
|
|
|
|
if (Stat(specURL, &st) < 0) {
|
2001-01-16 07:09:42 +08:00
|
|
|
|
rpmError(RPMERR_STAT, _("failed to stat %s: %m\n"), specURL);
|
2000-09-02 05:15:40 +08:00
|
|
|
|
rc = 1;
|
|
|
|
|
goto exit;
|
|
|
|
|
}
|
1999-11-24 08:03:54 +08:00
|
|
|
|
if (! S_ISREG(st.st_mode)) {
|
2001-01-16 07:09:42 +08:00
|
|
|
|
rpmError(RPMERR_NOTREG, _("File %s is not a regular file.\n"),
|
2000-09-02 05:15:40 +08:00
|
|
|
|
specURL);
|
1999-11-24 08:03:54 +08:00
|
|
|
|
rc = 1;
|
|
|
|
|
goto exit;
|
1999-10-30 07:03:12 +08:00
|
|
|
|
}
|
1999-07-23 03:38:25 +08:00
|
|
|
|
|
1999-10-30 07:03:12 +08:00
|
|
|
|
/* Try to verify that the file is actually a specfile */
|
1999-11-24 08:03:54 +08:00
|
|
|
|
if (!isSpecFile(specURL)) {
|
2001-01-16 07:09:42 +08:00
|
|
|
|
rpmError(RPMERR_BADSPEC,
|
|
|
|
|
_("File %s does not appear to be a specfile.\n"), specURL);
|
1999-11-24 08:03:54 +08:00
|
|
|
|
rc = 1;
|
|
|
|
|
goto exit;
|
1999-10-30 07:03:12 +08:00
|
|
|
|
}
|
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)
|
1999-11-24 08:03:54 +08:00
|
|
|
|
if (parseSpec(&spec, specURL, ba->rootdir, buildRootURL, 0, passPhrase,
|
2001-01-02 07:14:47 +08:00
|
|
|
|
cookie, _anyarch(buildAmount), ba->force)) {
|
1999-11-24 08:03:54 +08:00
|
|
|
|
rc = 1;
|
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
}
|
1998-09-25 04:36:54 +08:00
|
|
|
|
#undef _anyarch
|
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-01-02 07:14:47 +08:00
|
|
|
|
if (!ba->noDeps && checkSpec(spec->sourceHeader)) {
|
1999-11-24 08:03:54 +08:00
|
|
|
|
rc = 1;
|
|
|
|
|
goto exit;
|
1999-04-17 22:23:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-02 07:14:47 +08:00
|
|
|
|
if (buildSpec(spec, buildAmount, ba->noBuild)) {
|
1999-11-24 08:03:54 +08:00
|
|
|
|
rc = 1;
|
|
|
|
|
goto exit;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-02 07:14:47 +08:00
|
|
|
|
if (ba->buildMode == 't') Unlink(specURL);
|
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:
|
|
|
|
|
if (spec)
|
|
|
|
|
freeSpec(spec);
|
|
|
|
|
if (buildRootURL)
|
2000-12-13 04:03:45 +08:00
|
|
|
|
free((void *)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
|
|
|
|
|
1999-12-20 02:59:46 +08:00
|
|
|
|
int build(const char * arg, struct rpmBuildArguments * ba,
|
2001-01-02 07:14:47 +08:00
|
|
|
|
const char * passPhrase, char * cookie, 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;
|
1999-04-17 22:23:42 +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;
|
1998-08-09 06:27:08 +08:00
|
|
|
|
|
1998-12-02 07:28:26 +08:00
|
|
|
|
if (targets == NULL) {
|
2001-01-02 07:14:47 +08:00
|
|
|
|
rc = buildForTarget(arg, ba, passPhrase, cookie);
|
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);
|
|
|
|
|
target = alloca(te-t+1);
|
1999-03-18 02:11:01 +08:00
|
|
|
|
strncpy(target, t, (te-t));
|
|
|
|
|
target[te-t] = '\0';
|
1999-10-30 07:03:12 +08:00
|
|
|
|
if (*te)
|
|
|
|
|
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);
|
1998-12-02 07:28:26 +08:00
|
|
|
|
rpmReadConfigFiles(rcfile, target);
|
2001-01-02 07:14:47 +08:00
|
|
|
|
rc = buildForTarget(arg, ba, passPhrase, cookie);
|
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:
|
|
|
|
|
/* Restore original configuration. */
|
1999-12-13 05:14:05 +08:00
|
|
|
|
rpmFreeMacros(NULL);
|
1999-10-30 07:03:12 +08:00
|
|
|
|
rpmReadConfigFiles(rcfile, NULL);
|
|
|
|
|
return rc;
|
1998-08-09 06:27:08 +08:00
|
|
|
|
}
|