2000-08-28 03:18:25 +08:00
|
|
|
/** \ingroup rpmbuild
|
|
|
|
* \file build/parseSpec.c
|
2000-01-25 04:02:32 +08:00
|
|
|
* Top level dispatcher for spec file parsing.
|
|
|
|
*/
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@unchecked@*/
|
1999-11-24 08:03:54 +08:00
|
|
|
static int _debug = 0;
|
|
|
|
|
2000-06-10 02:57:23 +08:00
|
|
|
#include <rpmio_internal.h>
|
2000-06-20 23:54:48 +08:00
|
|
|
#include <rpmbuild.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
|
|
|
/*@access FD_t @*/ /* compared with NULL */
|
|
|
|
|
2000-08-31 01:47:53 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@unchecked@*/
|
1998-07-31 06:09:42 +08:00
|
|
|
static struct PartRec {
|
|
|
|
int part;
|
|
|
|
int len;
|
2001-05-04 05:00:18 +08:00
|
|
|
/*@observer@*/ /*@null@*/ const char * token;
|
1998-07-31 06:09:42 +08:00
|
|
|
} partList[] = {
|
2000-08-31 01:47:53 +08:00
|
|
|
{ PART_PREAMBLE, 0, "%package"},
|
|
|
|
{ PART_PREP, 0, "%prep"},
|
|
|
|
{ PART_BUILD, 0, "%build"},
|
|
|
|
{ PART_INSTALL, 0, "%install"},
|
|
|
|
{ PART_CLEAN, 0, "%clean"},
|
|
|
|
{ PART_PREUN, 0, "%preun"},
|
|
|
|
{ PART_POSTUN, 0, "%postun"},
|
|
|
|
{ PART_PRE, 0, "%pre"},
|
|
|
|
{ PART_POST, 0, "%post"},
|
|
|
|
{ PART_FILES, 0, "%files"},
|
|
|
|
{ PART_CHANGELOG, 0, "%changelog"},
|
|
|
|
{ PART_DESCRIPTION, 0, "%description"},
|
|
|
|
{ PART_TRIGGERPOSTUN, 0, "%triggerpostun"},
|
|
|
|
{ PART_TRIGGERUN, 0, "%triggerun"},
|
|
|
|
{ PART_TRIGGERIN, 0, "%triggerin"},
|
|
|
|
{ PART_TRIGGERIN, 0, "%trigger"},
|
|
|
|
{ PART_VERIFYSCRIPT, 0, "%verifyscript"},
|
1998-07-31 06:09:42 +08:00
|
|
|
{0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
1999-05-15 02:48:12 +08:00
|
|
|
static inline void initParts(struct PartRec *p)
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@modifies p->len @*/
|
1998-07-31 06:09:42 +08:00
|
|
|
{
|
1999-05-15 02:48:12 +08:00
|
|
|
for (; p->token != NULL; p++)
|
1998-07-31 06:09:42 +08:00
|
|
|
p->len = strlen(p->token);
|
|
|
|
}
|
|
|
|
|
2000-08-31 01:47:53 +08:00
|
|
|
rpmParseState isPart(const char *line)
|
1998-07-31 06:09:42 +08:00
|
|
|
{
|
1999-05-15 02:48:12 +08:00
|
|
|
struct PartRec *p;
|
1998-07-31 06:09:42 +08:00
|
|
|
|
1999-05-15 02:48:12 +08:00
|
|
|
if (partList[0].len == 0)
|
|
|
|
initParts(partList);
|
1998-07-31 06:09:42 +08:00
|
|
|
|
1999-05-15 02:48:12 +08:00
|
|
|
for (p = partList; p->token != NULL; p++) {
|
2000-11-12 19:11:49 +08:00
|
|
|
char c;
|
2001-01-04 04:19:27 +08:00
|
|
|
if (xstrncasecmp(line, p->token, p->len))
|
2000-11-12 19:11:49 +08:00
|
|
|
continue;
|
|
|
|
c = *(line + p->len);
|
2001-04-29 09:05:43 +08:00
|
|
|
if (c == '\0' || xisspace(c))
|
2000-11-12 19:11:49 +08:00
|
|
|
break;
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
2000-11-12 19:11:49 +08:00
|
|
|
return (p->token ? p->part : PART_NONE);
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
1999-05-15 02:48:12 +08:00
|
|
|
static int matchTok(const char *token, const char *line)
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@*/
|
1998-07-31 06:09:42 +08:00
|
|
|
{
|
1999-05-15 02:48:12 +08:00
|
|
|
const char *b, *be = line;
|
1999-09-07 04:59:39 +08:00
|
|
|
size_t toklen = strlen(token);
|
1999-05-15 02:48:12 +08:00
|
|
|
int rc = 0;
|
1998-07-31 06:09:42 +08:00
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
while ( *(b = be) != '\0' ) {
|
1999-05-15 02:48:12 +08:00
|
|
|
SKIPSPACE(b);
|
|
|
|
be = b;
|
|
|
|
SKIPNONSPACE(be);
|
|
|
|
if (be == b)
|
|
|
|
break;
|
2001-01-04 04:19:27 +08:00
|
|
|
if (toklen != (be-b) || xstrncasecmp(token, b, (be-b)))
|
1999-05-15 02:48:12 +08:00
|
|
|
continue;
|
|
|
|
rc = 1;
|
|
|
|
break;
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
1999-05-15 02:48:12 +08:00
|
|
|
return rc;
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleComments(char *s)
|
|
|
|
{
|
|
|
|
SKIPSPACE(s);
|
2000-11-12 19:11:49 +08:00
|
|
|
if (*s == '#')
|
1998-07-31 06:09:42 +08:00
|
|
|
*s = '\0';
|
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
1998-10-07 07:16:29 +08:00
|
|
|
static void forceIncludeFile(Spec spec, const char * fileName)
|
2001-10-14 03:35:58 +08:00
|
|
|
/*@modifies spec->fileStack @*/
|
1998-10-07 07:16:29 +08:00
|
|
|
{
|
1999-07-20 02:39:48 +08:00
|
|
|
OFI_t * ofi;
|
1998-10-07 07:16:29 +08:00
|
|
|
|
|
|
|
ofi = newOpenFileInfo();
|
1999-09-21 11:22:53 +08:00
|
|
|
ofi->fileName = xstrdup(fileName);
|
1998-10-07 07:16:29 +08:00
|
|
|
ofi->next = spec->fileStack;
|
|
|
|
spec->fileStack = ofi;
|
|
|
|
}
|
|
|
|
|
2001-01-11 22:13:04 +08:00
|
|
|
/**
|
|
|
|
*/
|
1999-07-20 02:39:48 +08:00
|
|
|
static int copyNextLine(Spec spec, OFI_t *ofi, int strip)
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@globals rpmGlobalMacroContext,
|
2001-10-18 00:43:36 +08:00
|
|
|
fileSystem @*/
|
|
|
|
/*@modifies spec->nextline, spec->nextpeekc, spec->lbuf, spec->line,
|
|
|
|
ofi->readPtr,
|
|
|
|
rpmGlobalMacroContext, fileSystem @*/
|
1999-07-20 02:39:48 +08:00
|
|
|
{
|
|
|
|
char *last;
|
|
|
|
char ch;
|
|
|
|
|
1999-07-21 04:48:29 +08:00
|
|
|
/* Restore 1st char in (possible) next line */
|
1999-07-27 05:51:03 +08:00
|
|
|
if (spec->nextline != NULL && spec->nextpeekc != '\0') {
|
1999-07-21 04:48:29 +08:00
|
|
|
*spec->nextline = spec->nextpeekc;
|
|
|
|
spec->nextpeekc = '\0';
|
|
|
|
}
|
1999-07-20 02:39:48 +08:00
|
|
|
/* Expand next line from file into line buffer */
|
|
|
|
if (!(spec->nextline && *spec->nextline)) {
|
|
|
|
char *from, *to;
|
1999-07-20 05:25:53 +08:00
|
|
|
to = last = spec->lbuf;
|
1999-07-20 02:39:48 +08:00
|
|
|
from = ofi->readPtr;
|
1999-07-20 05:25:53 +08:00
|
|
|
ch = ' ';
|
|
|
|
while (*from && ch != '\n')
|
|
|
|
ch = *to++ = *from++;
|
1999-07-20 02:39:48 +08:00
|
|
|
*to++ = '\0';
|
|
|
|
ofi->readPtr = from;
|
|
|
|
|
2000-06-22 07:28:50 +08:00
|
|
|
/* Don't expand macros (eg. %define) in false branch of %if clause */
|
|
|
|
if (spec->readStack->reading &&
|
|
|
|
expandMacros(spec, spec->macros, spec->lbuf, sizeof(spec->lbuf))) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("line %d: %s\n"),
|
|
|
|
spec->lineNum, spec->lbuf);
|
1999-07-20 02:39:48 +08:00
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
1999-07-20 05:25:53 +08:00
|
|
|
spec->nextline = spec->lbuf;
|
1999-07-20 02:39:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find next line in expanded line buffer */
|
1999-07-20 05:25:53 +08:00
|
|
|
spec->line = last = spec->nextline;
|
|
|
|
ch = ' ';
|
|
|
|
while (*spec->nextline && ch != '\n') {
|
|
|
|
ch = *spec->nextline++;
|
2001-04-29 09:05:43 +08:00
|
|
|
if (!xisspace(ch))
|
1999-07-20 02:39:48 +08:00
|
|
|
last = spec->nextline;
|
|
|
|
}
|
1999-07-21 04:48:29 +08:00
|
|
|
|
|
|
|
/* Save 1st char of next line in order to terminate current line. */
|
2001-05-01 06:32:22 +08:00
|
|
|
if (*spec->nextline != '\0') {
|
1999-07-20 05:25:53 +08:00
|
|
|
spec->nextpeekc = *spec->nextline;
|
|
|
|
*spec->nextline = '\0';
|
|
|
|
}
|
1999-07-20 02:39:48 +08:00
|
|
|
|
|
|
|
if (strip & STRIP_COMMENTS)
|
|
|
|
handleComments(spec->line);
|
|
|
|
|
|
|
|
if (strip & STRIP_TRAILINGSPACE)
|
|
|
|
*last = '\0';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
int readLine(Spec spec, int strip)
|
|
|
|
{
|
2000-08-28 03:18:25 +08:00
|
|
|
#ifdef DYING
|
1999-12-20 03:55:14 +08:00
|
|
|
const char *arch;
|
|
|
|
const char *os;
|
2000-08-28 03:18:25 +08:00
|
|
|
#endif
|
1999-10-28 07:18:10 +08:00
|
|
|
char *s;
|
1998-07-31 06:09:42 +08:00
|
|
|
int match;
|
|
|
|
struct ReadLevelEntry *rl;
|
1999-07-20 02:39:48 +08:00
|
|
|
OFI_t *ofi = spec->fileStack;
|
|
|
|
int rc;
|
1998-07-31 06:09:42 +08:00
|
|
|
|
1998-10-07 01:34:58 +08:00
|
|
|
retry:
|
1999-07-20 02:39:48 +08:00
|
|
|
/* Make sure the current file is open */
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
1999-11-05 05:26:08 +08:00
|
|
|
if (ofi->fd == NULL) {
|
1999-11-19 02:07:46 +08:00
|
|
|
ofi->fd = Fopen(ofi->fileName, "r.fpio");
|
|
|
|
if (ofi->fd == NULL || Ferror(ofi->fd)) {
|
1999-10-30 07:03:12 +08:00
|
|
|
/* XXX Fstrerror */
|
1999-11-15 03:15:18 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("Unable to open %s: %s\n"),
|
|
|
|
ofi->fileName, Fstrerror(ofi->fd));
|
1998-07-31 06:09:42 +08:00
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
1998-10-07 01:34:58 +08:00
|
|
|
spec->lineNum = ofi->lineNum = 0;
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
1998-07-31 06:09:42 +08:00
|
|
|
|
|
|
|
/* Make sure we have something in the read buffer */
|
1999-07-20 02:39:48 +08:00
|
|
|
if (!(ofi->readPtr && *(ofi->readPtr))) {
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@-type@*/ /* FIX: cast? */
|
2001-05-04 05:00:18 +08:00
|
|
|
FILE * f = fdGetFp(ofi->fd);
|
2001-10-17 01:42:18 +08:00
|
|
|
/*@=type@*/
|
2001-05-04 05:00:18 +08:00
|
|
|
if (f == NULL || !fgets(ofi->readBuf, BUFSIZ, f)) {
|
1998-07-31 06:09:42 +08:00
|
|
|
/* EOF */
|
|
|
|
if (spec->readStack->next) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_UNMATCHEDIF, _("Unclosed %%if\n"));
|
1998-07-31 06:09:42 +08:00
|
|
|
return RPMERR_UNMATCHEDIF;
|
|
|
|
}
|
1998-10-07 01:34:58 +08:00
|
|
|
|
|
|
|
/* remove this file from the stack */
|
|
|
|
spec->fileStack = ofi->next;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(ofi->fd);
|
2001-04-29 09:05:43 +08:00
|
|
|
ofi->fileName = _free(ofi->fileName);
|
|
|
|
ofi = _free(ofi);
|
1998-10-07 01:34:58 +08:00
|
|
|
|
|
|
|
/* only on last file do we signal EOF to caller */
|
|
|
|
ofi = spec->fileStack;
|
|
|
|
if (ofi == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* otherwise, go back and try the read again. */
|
|
|
|
goto retry;
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
1998-10-07 01:34:58 +08:00
|
|
|
ofi->readPtr = ofi->readBuf;
|
|
|
|
ofi->lineNum++;
|
|
|
|
spec->lineNum = ofi->lineNum;
|
1999-02-23 01:44:57 +08:00
|
|
|
if (spec->sl) {
|
2001-05-07 03:17:14 +08:00
|
|
|
speclines sl = spec->sl;
|
1999-02-23 01:44:57 +08:00
|
|
|
if (sl->sl_nlines == sl->sl_nalloc) {
|
|
|
|
sl->sl_nalloc += 100;
|
1999-09-21 11:22:53 +08:00
|
|
|
sl->sl_lines = (char **) xrealloc(sl->sl_lines,
|
1999-02-23 01:44:57 +08:00
|
|
|
sl->sl_nalloc * sizeof(*(sl->sl_lines)));
|
|
|
|
}
|
1999-09-21 11:22:53 +08:00
|
|
|
sl->sl_lines[sl->sl_nlines++] = xstrdup(ofi->readBuf);
|
1999-02-23 01:44:57 +08:00
|
|
|
}
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
2000-08-28 03:18:25 +08:00
|
|
|
#ifdef DYING
|
1999-12-20 03:55:14 +08:00
|
|
|
arch = NULL;
|
1998-07-31 06:09:42 +08:00
|
|
|
rpmGetArchInfo(&arch, NULL);
|
1999-12-20 03:55:14 +08:00
|
|
|
os = NULL;
|
1998-07-31 06:09:42 +08:00
|
|
|
rpmGetOsInfo(&os, NULL);
|
2000-08-28 03:18:25 +08:00
|
|
|
#endif
|
1998-10-08 01:06:10 +08:00
|
|
|
|
1999-07-20 02:39:48 +08:00
|
|
|
/* Copy next file line into the spec line buffer */
|
|
|
|
if ((rc = copyNextLine(spec, ofi, strip)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
s = spec->line;
|
|
|
|
SKIPSPACE(s);
|
1999-07-20 02:39:48 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
match = -1;
|
1999-09-08 06:49:45 +08:00
|
|
|
if (! strncmp("%ifarch", s, sizeof("%ifarch")-1)) {
|
2000-08-28 03:18:25 +08:00
|
|
|
const char *arch = rpmExpand("%{_target_cpu}", NULL);
|
1999-05-15 02:48:12 +08:00
|
|
|
s += 7;
|
1998-07-31 06:09:42 +08:00
|
|
|
match = matchTok(arch, s);
|
2001-04-29 09:05:43 +08:00
|
|
|
arch = _free(arch);
|
1999-09-08 06:49:45 +08:00
|
|
|
} else if (! strncmp("%ifnarch", s, sizeof("%ifnarch")-1)) {
|
2000-08-28 03:18:25 +08:00
|
|
|
const char *arch = rpmExpand("%{_target_cpu}", NULL);
|
1999-05-15 02:48:12 +08:00
|
|
|
s += 8;
|
1998-07-31 06:09:42 +08:00
|
|
|
match = !matchTok(arch, s);
|
2001-04-29 09:05:43 +08:00
|
|
|
arch = _free(arch);
|
1999-09-08 06:49:45 +08:00
|
|
|
} else if (! strncmp("%ifos", s, sizeof("%ifos")-1)) {
|
2000-08-28 03:18:25 +08:00
|
|
|
const char *os = rpmExpand("%{_target_os}", NULL);
|
1999-05-15 02:48:12 +08:00
|
|
|
s += 5;
|
1998-07-31 06:09:42 +08:00
|
|
|
match = matchTok(os, s);
|
2001-04-29 09:05:43 +08:00
|
|
|
os = _free(os);
|
1999-09-08 06:49:45 +08:00
|
|
|
} else if (! strncmp("%ifnos", s, sizeof("%ifnos")-1)) {
|
2000-08-28 03:18:25 +08:00
|
|
|
const char *os = rpmExpand("%{_target_os}", NULL);
|
1999-05-15 02:48:12 +08:00
|
|
|
s += 6;
|
1998-07-31 06:09:42 +08:00
|
|
|
match = !matchTok(os, s);
|
2001-04-29 09:05:43 +08:00
|
|
|
os = _free(os);
|
1999-09-08 06:49:45 +08:00
|
|
|
} else if (! strncmp("%if", s, sizeof("%if")-1)) {
|
1999-05-15 02:48:12 +08:00
|
|
|
s += 3;
|
1999-07-19 21:22:21 +08:00
|
|
|
match = parseExpressionBoolean(spec, s);
|
|
|
|
if (match < 0) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_UNMATCHEDIF,
|
|
|
|
_("%s:%d: parseExpressionBoolean returns %d\n"),
|
|
|
|
ofi->fileName, ofi->lineNum, match);
|
1999-07-19 21:22:21 +08:00
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
1999-09-08 06:49:45 +08:00
|
|
|
} else if (! strncmp("%else", s, sizeof("%else")-1)) {
|
1999-05-15 02:48:12 +08:00
|
|
|
s += 5;
|
1998-07-31 06:09:42 +08:00
|
|
|
if (! spec->readStack->next) {
|
|
|
|
/* Got an else with no %if ! */
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_UNMATCHEDIF,
|
|
|
|
_("%s:%d: Got a %%else with no %%if\n"),
|
|
|
|
ofi->fileName, ofi->lineNum);
|
1998-07-31 06:09:42 +08:00
|
|
|
return RPMERR_UNMATCHEDIF;
|
|
|
|
}
|
|
|
|
spec->readStack->reading =
|
|
|
|
spec->readStack->next->reading && ! spec->readStack->reading;
|
|
|
|
spec->line[0] = '\0';
|
1999-09-08 06:49:45 +08:00
|
|
|
} else if (! strncmp("%endif", s, sizeof("%endif")-1)) {
|
1999-05-15 02:48:12 +08:00
|
|
|
s += 6;
|
1998-07-31 06:09:42 +08:00
|
|
|
if (! spec->readStack->next) {
|
|
|
|
/* Got an end with no %if ! */
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_UNMATCHEDIF,
|
|
|
|
_("%s:%d: Got a %%endif with no %%if\n"),
|
|
|
|
ofi->fileName, ofi->lineNum);
|
1998-07-31 06:09:42 +08:00
|
|
|
return RPMERR_UNMATCHEDIF;
|
|
|
|
}
|
|
|
|
rl = spec->readStack;
|
|
|
|
spec->readStack = spec->readStack->next;
|
|
|
|
free(rl);
|
|
|
|
spec->line[0] = '\0';
|
1999-09-08 06:49:45 +08:00
|
|
|
} else if (! strncmp("%include", s, sizeof("%include")-1)) {
|
1999-05-15 02:48:12 +08:00
|
|
|
char *fileName, *endFileName, *p;
|
1998-10-07 01:34:58 +08:00
|
|
|
|
1999-05-15 02:48:12 +08:00
|
|
|
s += 8;
|
|
|
|
fileName = s;
|
2001-04-29 09:05:43 +08:00
|
|
|
if (! xisspace(*fileName)) {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("malformed %%include statement\n"));
|
1998-10-07 01:34:58 +08:00
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
1999-05-15 02:48:12 +08:00
|
|
|
SKIPSPACE(fileName);
|
1998-10-07 01:34:58 +08:00
|
|
|
endFileName = fileName;
|
1999-05-15 02:48:12 +08:00
|
|
|
SKIPNONSPACE(endFileName);
|
1998-10-07 01:34:58 +08:00
|
|
|
p = endFileName;
|
|
|
|
SKIPSPACE(p);
|
|
|
|
if (*p != '\0') {
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("malformed %%include statement\n"));
|
1998-10-07 01:34:58 +08:00
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
*endFileName = '\0';
|
1999-05-15 02:48:12 +08:00
|
|
|
|
1998-10-07 01:34:58 +08:00
|
|
|
forceIncludeFile(spec, fileName);
|
|
|
|
|
|
|
|
ofi = spec->fileStack;
|
|
|
|
goto retry;
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
1999-05-15 02:48:12 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
if (match != -1) {
|
2001-10-16 22:58:57 +08:00
|
|
|
rl = xmalloc(sizeof(*rl));
|
1998-07-31 06:09:42 +08:00
|
|
|
rl->reading = spec->readStack->reading && match;
|
|
|
|
rl->next = spec->readStack;
|
|
|
|
spec->readStack = rl;
|
|
|
|
spec->line[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! spec->readStack->reading) {
|
|
|
|
spec->line[0] = '\0';
|
|
|
|
}
|
|
|
|
|
2002-01-19 06:51:30 +08:00
|
|
|
/*@-compmempass@*/ /* FIX: spec->readStack->next should be dependent */
|
1998-07-31 06:09:42 +08:00
|
|
|
return 0;
|
2002-01-19 06:51:30 +08:00
|
|
|
/*@=compmempass@*/
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void closeSpec(Spec spec)
|
|
|
|
{
|
1999-07-20 02:39:48 +08:00
|
|
|
OFI_t *ofi;
|
1998-10-07 01:34:58 +08:00
|
|
|
|
|
|
|
while (spec->fileStack) {
|
|
|
|
ofi = spec->fileStack;
|
|
|
|
spec->fileStack = spec->fileStack->next;
|
2001-05-01 06:32:22 +08:00
|
|
|
if (ofi->fd) (void) Fclose(ofi->fd);
|
2001-04-29 09:05:43 +08:00
|
|
|
ofi->fileName = _free(ofi->fileName);
|
|
|
|
ofi = _free(ofi);
|
1998-07-31 06:09:42 +08:00
|
|
|
}
|
1998-10-07 01:34:58 +08:00
|
|
|
}
|
|
|
|
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@-redecl@*/
|
2001-10-15 11:22:10 +08:00
|
|
|
/*@unchecked@*/
|
2000-06-01 13:36:14 +08:00
|
|
|
extern int noLang; /* XXX FIXME: pass as arg */
|
2001-06-04 21:55:58 +08:00
|
|
|
/*@=redecl@*/
|
1998-08-12 02:24:48 +08:00
|
|
|
|
2001-05-07 03:17:14 +08:00
|
|
|
/*@todo Skip parse recursion if os is not compatible. @*/
|
1999-11-20 02:19:41 +08:00
|
|
|
int parseSpec(Spec *specp, const char *specFile, const char *rootURL,
|
2001-05-07 03:17:14 +08:00
|
|
|
const char *buildRootURL, int recursing, const char *passPhrase,
|
1999-11-01 05:38:21 +08:00
|
|
|
char *cookie, int anyarch, int force)
|
1998-01-13 05:31:29 +08:00
|
|
|
{
|
2000-08-31 01:47:53 +08:00
|
|
|
rpmParseState parsePart = PART_PREAMBLE;
|
1998-01-13 05:31:29 +08:00
|
|
|
int initialPackage = 1;
|
2000-08-28 03:18:25 +08:00
|
|
|
#ifdef DYING
|
1999-10-28 07:18:10 +08:00
|
|
|
const char *saveArch;
|
2000-08-28 03:18:25 +08:00
|
|
|
#endif
|
1998-01-13 05:31:29 +08:00
|
|
|
Package pkg;
|
|
|
|
Spec spec;
|
|
|
|
|
|
|
|
/* Set up a new Spec structure with no packages. */
|
|
|
|
spec = newSpec();
|
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
/*
|
|
|
|
* Note: rpmGetPath should guarantee a "canonical" path. That means
|
|
|
|
* that the following pathologies should be weeded out:
|
|
|
|
* //bin//sh
|
|
|
|
* //usr//bin/
|
|
|
|
* /.././../usr/../bin//./sh (XXX FIXME: dots not handled yet)
|
|
|
|
*/
|
|
|
|
spec->specFile = rpmGetPath(specFile, NULL);
|
1998-10-07 07:11:54 +08:00
|
|
|
spec->fileStack = newOpenFileInfo();
|
1999-11-24 08:03:54 +08:00
|
|
|
spec->fileStack->fileName = xstrdup(spec->specFile);
|
|
|
|
if (buildRootURL) {
|
1999-11-20 02:19:41 +08:00
|
|
|
const char * buildRoot;
|
1999-11-24 08:03:54 +08:00
|
|
|
(void) urlPath(buildRootURL, &buildRoot);
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
1999-11-24 08:03:54 +08:00
|
|
|
if (*buildRoot == '\0') buildRoot = "/";
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
1999-11-24 08:03:54 +08:00
|
|
|
if (!strcmp(buildRoot, "/")) {
|
|
|
|
rpmError(RPMERR_BADSPEC,
|
2001-01-16 07:09:42 +08:00
|
|
|
_("BuildRoot can not be \"/\": %s\n"), buildRootURL);
|
1999-11-24 08:03:54 +08:00
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
spec->gotBuildRootURL = 1;
|
1999-12-17 03:38:28 +08:00
|
|
|
spec->buildRootURL = xstrdup(buildRootURL);
|
1999-06-15 22:46:31 +08:00
|
|
|
addMacro(spec->macros, "buildroot", NULL, buildRoot, RMIL_SPEC);
|
1999-11-24 08:03:54 +08:00
|
|
|
if (_debug)
|
1999-12-17 03:38:28 +08:00
|
|
|
fprintf(stderr, "*** PS buildRootURL(%s) %p macro set to %s\n", spec->buildRootURL, spec->buildRootURL, buildRoot);
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
1999-04-02 06:26:44 +08:00
|
|
|
addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC);
|
2001-05-07 03:17:14 +08:00
|
|
|
spec->recursing = recursing;
|
1998-11-20 08:29:46 +08:00
|
|
|
spec->anyarch = anyarch;
|
|
|
|
spec->force = force;
|
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
if (rootURL)
|
|
|
|
spec->rootURL = xstrdup(rootURL);
|
1999-11-01 05:38:21 +08:00
|
|
|
if (passPhrase)
|
1999-09-21 11:22:53 +08:00
|
|
|
spec->passPhrase = xstrdup(passPhrase);
|
1999-11-01 05:38:21 +08:00
|
|
|
if (cookie)
|
1999-09-21 11:22:53 +08:00
|
|
|
spec->cookie = xstrdup(cookie);
|
1998-01-13 05:31:29 +08:00
|
|
|
|
1999-11-24 08:03:54 +08:00
|
|
|
spec->timeCheck = rpmExpandNumeric("%{_timecheck}");
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* All the parse*() functions expect to have a line pre-read */
|
|
|
|
/* in the spec's line buffer. Except for parsePreamble(), */
|
|
|
|
/* which handles the initial entry into a spec file. */
|
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@-infloops@*/ /* LCL: parsePart is modified @*/
|
2001-01-11 22:13:04 +08:00
|
|
|
while (parsePart < PART_LAST && parsePart != PART_NONE) {
|
1998-01-13 05:31:29 +08:00
|
|
|
switch (parsePart) {
|
2001-06-06 03:26:22 +08:00
|
|
|
case PART_PREAMBLE:
|
1998-11-20 08:29:46 +08:00
|
|
|
parsePart = parsePreamble(spec, initialPackage);
|
1998-01-13 05:31:29 +08:00
|
|
|
initialPackage = 0;
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2001-06-06 03:26:22 +08:00
|
|
|
case PART_PREP:
|
1998-11-20 08:29:46 +08:00
|
|
|
parsePart = parsePrep(spec);
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2001-06-06 03:26:22 +08:00
|
|
|
case PART_BUILD:
|
|
|
|
case PART_INSTALL:
|
|
|
|
case PART_CLEAN:
|
1998-01-13 05:31:29 +08:00
|
|
|
parsePart = parseBuildInstallClean(spec, parsePart);
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2001-06-06 03:26:22 +08:00
|
|
|
case PART_CHANGELOG:
|
1998-01-13 05:31:29 +08:00
|
|
|
parsePart = parseChangelog(spec);
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
2001-06-06 03:26:22 +08:00
|
|
|
case PART_DESCRIPTION:
|
1998-01-13 05:31:29 +08:00
|
|
|
parsePart = parseDescription(spec);
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
1998-03-21 06:38:00 +08:00
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
case PART_PRE:
|
|
|
|
case PART_POST:
|
|
|
|
case PART_PREUN:
|
|
|
|
case PART_POSTUN:
|
|
|
|
case PART_VERIFYSCRIPT:
|
|
|
|
case PART_TRIGGERIN:
|
|
|
|
case PART_TRIGGERUN:
|
|
|
|
case PART_TRIGGERPOSTUN:
|
1998-01-13 05:31:29 +08:00
|
|
|
parsePart = parseScript(spec, parsePart);
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
case PART_FILES:
|
1998-01-13 05:31:29 +08:00
|
|
|
parsePart = parseFiles(spec);
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
1998-01-13 05:31:29 +08:00
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
case PART_NONE: /* XXX avoid gcc whining */
|
|
|
|
case PART_LAST:
|
|
|
|
case PART_BUILDARCHITECTURES:
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@switchbreak@*/ break;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
|
|
|
|
2001-01-16 21:09:35 +08:00
|
|
|
if (parsePart >= PART_LAST) {
|
2001-05-07 03:17:14 +08:00
|
|
|
spec = freeSpec(spec);
|
1998-01-13 05:31:29 +08:00
|
|
|
return parsePart;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parsePart == PART_BUILDARCHITECTURES) {
|
2001-05-07 03:17:14 +08:00
|
|
|
int index;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
closeSpec(spec);
|
|
|
|
|
2001-10-16 22:58:57 +08:00
|
|
|
/* LCL: sizeof(spec->BASpecs[0]) -nullderef whine here */
|
|
|
|
spec->BASpecs = xcalloc(spec->BACount, sizeof(*spec->BASpecs));
|
1998-01-13 05:31:29 +08:00
|
|
|
index = 0;
|
2001-05-07 03:17:14 +08:00
|
|
|
if (spec->BANames != NULL)
|
|
|
|
for (x = 0; x < spec->BACount; x++) {
|
|
|
|
|
|
|
|
/* Skip if not arch is not compatible. */
|
|
|
|
if (!rpmMachineScore(RPM_MACHTABLE_BUILDARCH, spec->BANames[x]))
|
2001-10-14 06:01:38 +08:00
|
|
|
/*@innercontinue@*/ continue;
|
2000-08-28 03:18:25 +08:00
|
|
|
#ifdef DYING
|
2001-05-07 03:17:14 +08:00
|
|
|
rpmGetMachine(&saveArch, NULL);
|
|
|
|
saveArch = xstrdup(saveArch);
|
|
|
|
rpmSetMachine(spec->BANames[x], NULL);
|
2000-08-28 03:18:25 +08:00
|
|
|
#else
|
2001-05-07 03:17:14 +08:00
|
|
|
addMacro(NULL, "_target_cpu", NULL, spec->BANames[x], RMIL_RPMRC);
|
2000-08-28 03:18:25 +08:00
|
|
|
#endif
|
2001-09-25 05:53:14 +08:00
|
|
|
spec->BASpecs[index] = NULL;
|
2001-05-07 03:17:14 +08:00
|
|
|
if (parseSpec(&(spec->BASpecs[index]),
|
1999-11-24 08:03:54 +08:00
|
|
|
specFile, spec->rootURL, buildRootURL, 1,
|
2001-05-07 03:17:14 +08:00
|
|
|
passPhrase, cookie, anyarch, force))
|
|
|
|
{
|
|
|
|
spec->BACount = index;
|
|
|
|
spec = freeSpec(spec);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADSPEC;
|
2001-05-07 03:17:14 +08:00
|
|
|
}
|
2000-08-28 03:18:25 +08:00
|
|
|
#ifdef DYING
|
2001-05-07 03:17:14 +08:00
|
|
|
rpmSetMachine(saveArch, NULL);
|
|
|
|
saveArch = _free(saveArch);
|
2000-08-28 03:18:25 +08:00
|
|
|
#else
|
2001-05-07 03:17:14 +08:00
|
|
|
delMacro(NULL, "_target_cpu");
|
2000-08-28 03:18:25 +08:00
|
|
|
#endif
|
2001-05-07 03:17:14 +08:00
|
|
|
index++;
|
1998-01-13 05:31:29 +08:00
|
|
|
}
|
2001-05-07 03:17:14 +08:00
|
|
|
|
|
|
|
spec->BACount = index;
|
1998-01-13 05:31:29 +08:00
|
|
|
if (! index) {
|
2001-05-07 03:17:14 +08:00
|
|
|
spec = freeSpec(spec);
|
|
|
|
rpmError(RPMERR_BADSPEC,
|
|
|
|
_("No compatible architectures found for build\n"));
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
1999-03-13 02:20:06 +08:00
|
|
|
|
2001-05-07 03:17:14 +08:00
|
|
|
/*
|
|
|
|
* Return the 1st child's fully parsed Spec structure.
|
1999-03-17 04:04:26 +08:00
|
|
|
* The restart of the parse when encountering BuildArch
|
2001-05-07 03:17:14 +08:00
|
|
|
* causes problems for "rpm -q --specfile". This is
|
|
|
|
* still a hack because there may be more than 1 arch
|
|
|
|
* specified (unlikely but possible.) There's also the
|
|
|
|
* further problem that the macro context, particularly
|
|
|
|
* %{_target_cpu}, disagrees with the info in the header.
|
1999-03-17 04:04:26 +08:00
|
|
|
*/
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@-branchstate@*/
|
2001-05-07 03:17:14 +08:00
|
|
|
if (spec->BACount >= 1) {
|
|
|
|
Spec nspec = spec->BASpecs[0];
|
|
|
|
spec->BASpecs = _free(spec->BASpecs);
|
|
|
|
spec = freeSpec(spec);
|
|
|
|
spec = nspec;
|
1999-03-13 02:20:06 +08:00
|
|
|
}
|
2001-10-16 01:53:34 +08:00
|
|
|
/*@=branchstate@*/
|
1999-03-13 02:20:06 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
*specp = spec;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2001-06-06 03:26:22 +08:00
|
|
|
/*@=infloops@*/ /* LCL: parsePart is modified @*/
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
/* Check for description in each package and add arch and os */
|
2000-12-03 05:53:44 +08:00
|
|
|
{
|
2000-08-28 03:18:25 +08:00
|
|
|
#ifdef DYING
|
|
|
|
const char *arch = NULL;
|
|
|
|
const char *os = NULL;
|
|
|
|
char *myos = NULL;
|
|
|
|
|
|
|
|
rpmGetArchInfo(&arch, NULL);
|
|
|
|
rpmGetOsInfo(&os, NULL);
|
|
|
|
/*
|
|
|
|
* XXX Capitalizing the 'L' is needed to insure that old
|
|
|
|
* XXX os-from-uname (e.g. "Linux") is compatible with the new
|
|
|
|
* XXX os-from-platform (e.g "linux" from "sparc-*-linux").
|
|
|
|
* XXX A copy of this string is embedded in headers.
|
|
|
|
*/
|
|
|
|
if (!strcmp(os, "linux")) {
|
1999-10-28 07:18:10 +08:00
|
|
|
myos = xstrdup(os);
|
|
|
|
*myos = 'L';
|
|
|
|
os = myos;
|
2000-08-28 03:18:25 +08:00
|
|
|
}
|
|
|
|
#else
|
2001-11-07 06:46:26 +08:00
|
|
|
const char *platform = rpmExpand("%{_target_platform}", NULL);
|
2000-08-28 03:18:25 +08:00
|
|
|
const char *arch = rpmExpand("%{_target_cpu}", NULL);
|
|
|
|
const char *os = rpmExpand("%{_target_os}", NULL);
|
|
|
|
#endif
|
1998-10-08 01:06:10 +08:00
|
|
|
|
2001-11-07 06:46:26 +08:00
|
|
|
for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
|
1998-01-13 05:31:29 +08:00
|
|
|
if (!headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) {
|
2000-04-13 17:07:08 +08:00
|
|
|
const char * name;
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerNVR(pkg->header, &name, NULL, NULL);
|
2001-01-16 07:09:42 +08:00
|
|
|
rpmError(RPMERR_BADSPEC, _("Package has no %%description: %s\n"),
|
|
|
|
name);
|
2001-05-07 03:17:14 +08:00
|
|
|
spec = freeSpec(spec);
|
1998-01-13 05:31:29 +08:00
|
|
|
return RPMERR_BADSPEC;
|
|
|
|
}
|
|
|
|
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_OS, RPM_STRING_TYPE, os, 1);
|
2001-11-07 06:46:26 +08:00
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_ARCH,
|
|
|
|
RPM_STRING_TYPE, arch, 1);
|
|
|
|
if (!headerIsEntry(pkg->header, RPMTAG_RHNPLATFORM))
|
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_RHNPLATFORM,
|
|
|
|
RPM_STRING_TYPE, arch, 1);
|
|
|
|
(void) headerAddEntry(pkg->header, RPMTAG_PLATFORM,
|
|
|
|
RPM_STRING_TYPE, platform, 1);
|
|
|
|
}
|
|
|
|
|
2000-08-28 03:18:25 +08:00
|
|
|
#ifdef DYING
|
2001-04-29 09:05:43 +08:00
|
|
|
myos = _free(myos);
|
2000-08-28 03:18:25 +08:00
|
|
|
#else
|
2001-11-07 06:46:26 +08:00
|
|
|
platform = _free(platform);
|
2001-04-29 09:05:43 +08:00
|
|
|
arch = _free(arch);
|
|
|
|
os = _free(os);
|
2000-08-28 03:18:25 +08:00
|
|
|
#endif
|
|
|
|
}
|
1998-01-13 05:31:29 +08:00
|
|
|
|
|
|
|
closeSpec(spec);
|
|
|
|
*specp = spec;
|
1998-05-18 23:16:16 +08:00
|
|
|
|
1998-01-13 05:31:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|