summaryrefslogtreecommitdiff
path: root/build/parsePreamble.c
diff options
context:
space:
mode:
authorbiao716.wang <biao716.wang@samsung.com>2021-01-05 14:51:28 +0900
committerbiao716.wang <biao716.wang@samsung.com>2021-01-05 14:51:28 +0900
commit9de33a8a7cd9eae05c3c1df4b2c0e1e4cd2bd40a (patch)
tree03067d36d530c3eeb623e601b0c12a98f744376d /build/parsePreamble.c
parent287097d4d8079b4485870c08cf5675b0bdd37ed9 (diff)
downloadrpm-9de33a8a7cd9eae05c3c1df4b2c0e1e4cd2bd40a.tar.gz
rpm-9de33a8a7cd9eae05c3c1df4b2c0e1e4cd2bd40a.tar.bz2
rpm-9de33a8a7cd9eae05c3c1df4b2c0e1e4cd2bd40a.zip
Change-Id: Iab5438d6e4d45c937b191c03e9ef5dd3fad165c8 Signed-off-by: biao716.wang <biao716.wang@samsung.com>
Diffstat (limited to 'build/parsePreamble.c')
-rw-r--r--build/parsePreamble.c258
1 files changed, 194 insertions, 64 deletions
diff --git a/build/parsePreamble.c b/build/parsePreamble.c
index f02e14e92..96bf9c035 100644
--- a/build/parsePreamble.c
+++ b/build/parsePreamble.c
@@ -19,8 +19,8 @@
#define SKIPSPACE(s) { while (*(s) && risspace(*(s))) (s)++; }
#define SKIPNONSPACE(s) { while (*(s) && !risspace(*(s))) (s)++; }
-#define SKIPWHITE(_x) {while(*(_x) && (risspace(*_x) || *(_x) == ',')) (_x)++;}
-#define SKIPNONWHITE(_x){while(*(_x) &&!(risspace(*_x) || *(_x) == ',')) (_x)++;}
+#define SKIPWHITE(_x) {while (*(_x) && (risspace(*_x) || *(_x) == ',')) (_x)++;}
+#define SKIPNONWHITE(_x){while (*(_x) &&!(risspace(*_x) || *(_x) == ',')) (_x)++;}
/**
*/
@@ -92,7 +92,7 @@ static int parseSimplePart(const char *line, char **name, int *flag)
*name = NULL;
if (!(tok = strtok(NULL, " \t\n"))) {
- rc = 0;
+ rc = 1;
goto exit;
}
@@ -299,14 +299,14 @@ static int addSource(rpmSpec spec, Package pkg, const char *field, rpmTagVal tag
rasprintf(&buf, "%s%d",
(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
- addMacro(spec->macros, buf, NULL, body, RMIL_SPEC);
+ rpmPushMacro(spec->macros, buf, NULL, body, RMIL_SPEC);
free(buf);
rasprintf(&buf, "%sURL%d",
(flag & RPMBUILD_ISPATCH) ? "PATCH" : "SOURCE", num);
- addMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
+ rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
free(buf);
#ifdef WITH_LUA
- if (!spec->recursing) {
+ {
rpmlua lua = NULL; /* global state */
const char * what = (flag & RPMBUILD_ISPATCH) ? "patches" : "sources";
rpmluaPushTable(lua, what);
@@ -428,6 +428,11 @@ static rpmRC checkForValidArchitectures(rpmSpec spec)
char *arch = rpmExpand("%{_target_cpu}", NULL);
char *os = rpmExpand("%{_target_os}", NULL);
rpmRC rc = RPMRC_FAIL; /* assume failure */
+
+ if (!strcmp(arch, "noarch")) {
+ free(arch);
+ arch = rpmExpand("%{_build_cpu}", NULL);
+ }
if (isMemberInEntry(spec->buildRestrictions,
arch, RPMTAG_EXCLUDEARCH) == 1) {
@@ -539,6 +544,13 @@ static void fillOutMainPackage(Header h)
/**
*/
+void copyInheritedTags(Header h, Header fromh)
+{
+ headerCopyTags(fromh, h, (rpmTagVal *)copyTagsDuringParse);
+}
+
+/**
+ */
static rpmRC readIcon(Header h, const char * file)
{
char *fn = NULL;
@@ -598,36 +610,113 @@ if (multiToken) { \
return RPMRC_FAIL; \
}
+static void specLog(rpmSpec spec, int lvl, const char *line, const char *msg)
+{
+ if (spec) {
+ rpmlog(lvl, _("line %d: %s in: %s\n"), spec->lineNum, msg, spec->line);
+ } else {
+ rpmlog(lvl, _("%s in: %s\n"), msg, line);
+ }
+}
+
/**
* Check for inappropriate characters. All alphanums are considered sane.
- * @param spec spec
+ * @param spec spec (or NULL)
* @param field string to check
- * @param fsize size of string to check
* @param whitelist string of permitted characters
* @return RPMRC_OK if OK
*/
-rpmRC rpmCharCheck(rpmSpec spec, const char *field, size_t fsize, const char *whitelist)
+rpmRC rpmCharCheck(rpmSpec spec, const char *field, const char *whitelist)
{
- const char *ch, *stop = &field[fsize];
+ const char *ch;
+ char *err = NULL;
+ rpmRC rc = RPMRC_OK;
- for (ch=field; *ch && ch < stop; ch++) {
+ for (ch=field; *ch; ch++) {
if (risalnum(*ch) || strchr(whitelist, *ch)) continue;
- if (isprint(*ch)) {
- rpmlog(RPMLOG_ERR, _("line %d: Illegal char '%c' in: %s\n"),
- spec->lineNum, *ch, spec->line);
- } else {
- rpmlog(RPMLOG_ERR, _("line %d: Illegal char in: %s\n"),
- spec->lineNum, spec->line);
+ rasprintf(&err, _("Illegal char '%c' (0x%x)"),
+ isprint(*ch) ? *ch : '?', *ch);
+ }
+ for (ch=field; *ch; ch++) {
+ if (strchr("%{}", *ch)) {
+ specLog(spec, RPMLOG_WARNING, field,
+ _("Possible unexpanded macro"));
+ break;
}
- return RPMRC_FAIL;
}
- if (strstr(field, "..") != NULL) {
- rpmlog(RPMLOG_ERR, _("line %d: Illegal sequence \"..\" in: %s\n"),
- spec->lineNum, spec->line);
- return RPMRC_FAIL;
+
+ if (err == NULL && strstr(field, "..") != NULL) {
+ rasprintf(&err, _("Illegal sequence \"..\""));
}
-
- return RPMRC_OK;
+
+ if (err) {
+ specLog(spec, RPMLOG_ERR, field, err);
+ free(err);
+ rc = RPMRC_FAIL;
+ }
+ return rc;
+}
+
+static int haveLangTag(Header h, rpmTagVal tag, const char *lang)
+{
+ int rc = 0; /* assume tag not present */
+ int langNum = -1;
+
+ if (lang && *lang) {
+ /* See if the language is in header i18n table */
+ struct rpmtd_s langtd;
+ const char *s = NULL;
+ headerGet(h, RPMTAG_HEADERI18NTABLE, &langtd, HEADERGET_MINMEM);
+ while ((s = rpmtdNextString(&langtd)) != NULL) {
+ if (rstreq(s, lang)) {
+ langNum = rpmtdGetIndex(&langtd);
+ break;
+ }
+ }
+ rpmtdFreeData(&langtd);
+ } else {
+ /* C locale */
+ langNum = 0;
+ }
+
+ /* If locale is present, check the actual tag content */
+ if (langNum >= 0) {
+ struct rpmtd_s td;
+ headerGet(h, tag, &td, HEADERGET_MINMEM|HEADERGET_RAW);
+ if (rpmtdSetIndex(&td, langNum) == langNum) {
+ const char *s = rpmtdGetString(&td);
+ /* non-empty string means a dupe */
+ if (s && *s)
+ rc = 1;
+ }
+ rpmtdFreeData(&td);
+ };
+
+ return rc;
+}
+
+int addLangTag(rpmSpec spec, Header h, rpmTagVal tag,
+ const char *field, const char *lang)
+{
+ int skip = 0;
+
+ if (haveLangTag(h, tag, lang)) {
+ /* Turn this into an error eventually */
+ rpmlog(RPMLOG_WARNING, _("line %d: second %s\n"),
+ spec->lineNum, rpmTagGetName(tag));
+ }
+
+ if (!*lang) {
+ headerPutString(h, tag, field);
+ } else {
+ skip = ((spec->flags & RPMSPEC_NOLANG) &&
+ !rstreq(lang, RPMBUILD_DEFAULT_LANG));
+ if (skip)
+ return 0;
+ headerAddI18NString(h, tag, field, lang);
+ }
+
+ return 0;
}
static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
@@ -669,14 +758,17 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
switch (tag) {
case RPMTAG_NAME:
SINGLE_TOKEN_ONLY;
- if (rpmCharCheck(spec, field, strlen(field), ".-_+%{}"))
+ if (rpmCharCheck(spec, field, WHITELIST_NAME))
goto exit;
headerPutString(pkg->header, tag, field);
+ /* Main pkg name is unknown at the start, populate as soon as we can */
+ if (pkg == spec->packages)
+ pkg->name = rpmstrPoolId(spec->pool, field, 1);
break;
case RPMTAG_VERSION:
case RPMTAG_RELEASE:
SINGLE_TOKEN_ONLY;
- if (rpmCharCheck(spec, field, strlen(field), "._+%{}~"))
+ if (rpmCharCheck(spec, field, "._+%{}~"))
goto exit;
headerPutString(pkg->header, tag, field);
break;
@@ -694,11 +786,8 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
case RPMTAG_VENDOR:
case RPMTAG_LICENSE:
case RPMTAG_PACKAGER:
- if (!*lang) {
- headerPutString(pkg->header, tag, field);
- } else if (!((spec->flags & RPMSPEC_NOLANG) &&
- !rstreq(lang, RPMBUILD_DEFAULT_LANG)))
- headerAddI18NString(pkg->header, tag, field, lang);
+ if (addLangTag(spec, pkg->header, tag, field, lang))
+ goto exit;
break;
case RPMTAG_BUILDROOT:
/* just silently ignore BuildRoot */
@@ -731,8 +820,8 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
goto exit;
}
macro = NULL;
- delMacro(NULL, "_docdir");
- addMacro(NULL, "_docdir", NULL, field, RMIL_SPEC);
+ rpmPopMacro(NULL, "_docdir");
+ rpmPushMacro(NULL, "_docdir", NULL, field, RMIL_SPEC);
break;
case RPMTAG_EPOCH: {
SINGLE_TOKEN_ONLY;
@@ -773,8 +862,8 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
if (parseNoSource(spec, field, tag))
goto exit;
break;
- case RPMTAG_ORDERFLAGS:
- case RPMTAG_REQUIREFLAGS:
+ case RPMTAG_ORDERNAME:
+ case RPMTAG_REQUIRENAME:
if (parseBits(lang, installScriptBits, &tagflags)) {
rpmlog(RPMLOG_ERR, _("line %d: Bad %s: qualifiers: %s\n"),
spec->lineNum, rpmTagGetName(tag), spec->line);
@@ -782,17 +871,24 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
}
/* fallthrough */
case RPMTAG_PREREQ:
+ case RPMTAG_RECOMMENDNAME:
+ case RPMTAG_SUGGESTNAME:
+ case RPMTAG_SUPPLEMENTNAME:
+ case RPMTAG_ENHANCENAME:
+ case RPMTAG_CONFLICTNAME:
+ case RPMTAG_OBSOLETENAME:
+ case RPMTAG_PROVIDENAME:
+ if (parseRCPOT(spec, pkg, field, tag, 0, tagflags, addReqProvPkg, NULL))
+ goto exit;
+ break;
case RPMTAG_BUILDPREREQ:
case RPMTAG_BUILDREQUIRES:
case RPMTAG_BUILDCONFLICTS:
- case RPMTAG_CONFLICTFLAGS:
- case RPMTAG_OBSOLETEFLAGS:
- case RPMTAG_PROVIDEFLAGS:
- if (parseRCPOT(spec, pkg, field, tag, 0, tagflags))
+ if (parseRCPOT(spec, spec->sourcePackage, field, tag, 0, tagflags, addReqProvPkg, NULL))
goto exit;
break;
- case RPMTAG_SUGGESTSFLAGS:
- case RPMTAG_ENHANCESFLAGS:
+ case RPMTAG_OLDSUGGESTSFLAGS:
+ case RPMTAG_OLDENHANCESFLAGS:
case RPMTAG_BUILDSUGGESTS:
case RPMTAG_BUILDENHANCES:
tagflags = RPMSENSE_MISSINGOK;
@@ -800,7 +896,7 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
tagflags |= RPMSENSE_STRONG;
if (macro && (!strcmp(macro, "supplements") || !strcmp(macro, "buildsupplements")))
tagflags |= RPMSENSE_STRONG;
- if ((rc = parseRCPOT(spec, pkg, field, tag, 0, tagflags)))
+ if (parseRCPOT(spec, pkg, field, tag, 0, tagflags, addReqProvPkg, NULL))
return rc;
break;
case RPMTAG_EXCLUDEARCH:
@@ -820,6 +916,13 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
goto exit;
}
if (spec->packages == pkg) {
+ if (spec->BANames) {
+ rpmlog(RPMLOG_ERR,
+ _("line %d: Duplicate BuildArch entry: %s\n"),
+ spec->lineNum, spec->line);
+ BANames = _free(BANames);
+ goto exit;
+ }
spec->BACount = BACount;
spec->BANames = BANames;
} else {
@@ -836,8 +939,10 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
spec->BANames = _free(spec->BANames);
break;
}
- case RPMTAG_COLLECTIONS:
- case RPMTAG_BUILDINFO:
+ case RPMTAG_REMOVEPATHPOSTFIXES:
+ argvSplit(&pkg->removePostfixes, field, ":");
+ break;
+ case RPMTAG_BUILDINFO:
if (addOrAppendListEntry(pkg->header, tag, field))
goto exit;
break;
@@ -846,8 +951,17 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
goto exit;
}
- if (macro)
- addMacro(spec->macros, macro, NULL, field, RMIL_SPEC);
+ if (macro) {
+ rpmPushMacro(spec->macros, macro, NULL, field, RMIL_SPEC);
+ /* Add a separate uppercase macro for tags from the main package */
+ if (pkg == spec->packages) {
+ char *m = xstrdup(macro);
+ for (char *p = m; *p; ++p)
+ *p = rtoupper(*p);
+ rpmPushMacro(spec->macros, m, NULL, field, RMIL_SPEC);
+ free(m);
+ }
+ }
rc = RPMRC_OK;
exit:
return rc;
@@ -881,7 +995,7 @@ static struct PreambleRec_s const preambleList[] = {
{RPMTAG_GROUP, 1, 0, LEN_AND_STR("group")},
{RPMTAG_PACKAGER, 0, 0, LEN_AND_STR("packager")},
{RPMTAG_URL, 0, 0, LEN_AND_STR("url")},
- {RPMTAG_VCS, 0, 0, LEN_AND_STR("vcs")},
+ {RPMTAG_VCS, 0, 0, LEN_AND_STR("vcs")},
{RPMTAG_SOURCE, 0, 0, LEN_AND_STR("source")},
{RPMTAG_PATCH, 0, 0, LEN_AND_STR("patch")},
{RPMTAG_NOSOURCE, 0, 0, LEN_AND_STR("nosource")},
@@ -891,11 +1005,15 @@ static struct PreambleRec_s const preambleList[] = {
{RPMTAG_EXCLUDEOS, 0, 0, LEN_AND_STR("excludeos")},
{RPMTAG_EXCLUSIVEOS, 0, 0, LEN_AND_STR("exclusiveos")},
{RPMTAG_ICON, 0, 0, LEN_AND_STR("icon")},
- {RPMTAG_PROVIDEFLAGS, 0, 0, LEN_AND_STR("provides")},
- {RPMTAG_REQUIREFLAGS, 2, 0, LEN_AND_STR("requires")},
+ {RPMTAG_PROVIDENAME, 0, 0, LEN_AND_STR("provides")},
+ {RPMTAG_REQUIRENAME, 2, 0, LEN_AND_STR("requires")},
+ {RPMTAG_RECOMMENDNAME, 0, 0, LEN_AND_STR("recommends")},
+ {RPMTAG_SUGGESTNAME, 0, 0, LEN_AND_STR("suggests")},
+ {RPMTAG_SUPPLEMENTNAME, 0, 0, LEN_AND_STR("supplements")},
+ {RPMTAG_ENHANCENAME, 0, 0, LEN_AND_STR("enhances")},
{RPMTAG_PREREQ, 2, 1, LEN_AND_STR("prereq")},
- {RPMTAG_CONFLICTFLAGS, 0, 0, LEN_AND_STR("conflicts")},
- {RPMTAG_OBSOLETEFLAGS, 0, 0, LEN_AND_STR("obsoletes")},
+ {RPMTAG_CONFLICTNAME, 0, 0, LEN_AND_STR("conflicts")},
+ {RPMTAG_OBSOLETENAME, 0, 0, LEN_AND_STR("obsoletes")},
{RPMTAG_PREFIXES, 0, 0, LEN_AND_STR("prefixes")},
{RPMTAG_PREFIXES, 0, 0, LEN_AND_STR("prefix")},
{RPMTAG_BUILDROOT, 0, 0, LEN_AND_STR("buildroot")},
@@ -910,18 +1028,19 @@ static struct PreambleRec_s const preambleList[] = {
{RPMTAG_DOCDIR, 0, 0, LEN_AND_STR("docdir")},
{RPMTAG_DISTTAG, 0, 0, LEN_AND_STR("disttag")},
{RPMTAG_BUGURL, 0, 0, LEN_AND_STR("bugurl")},
- {RPMTAG_COLLECTIONS, 0, 0, LEN_AND_STR("collections")},
{RPMTAG_ORDERFLAGS, 2, 0, LEN_AND_STR("orderwithrequires")},
- {RPMTAG_SUGGESTSFLAGS, 0, 0, LEN_AND_STR("recommends")},
- {RPMTAG_SUGGESTSFLAGS, 0, 0, LEN_AND_STR("suggests")},
- {RPMTAG_ENHANCESFLAGS, 0, 0, LEN_AND_STR("supplements")},
- {RPMTAG_ENHANCESFLAGS, 0, 0, LEN_AND_STR("enhances")},
+ {RPMTAG_OLDSUGGESTSFLAGS, 0, 0, LEN_AND_STR("recommends")},
+ {RPMTAG_OLDSUGGESTSFLAGS, 0, 0, LEN_AND_STR("suggests")},
+ {RPMTAG_OLDENHANCESFLAGS, 0, 0, LEN_AND_STR("supplements")},
+ {RPMTAG_OLDENHANCESFLAGS, 0, 0, LEN_AND_STR("enhances")},
{RPMTAG_BUILDSUGGESTS, 0, 0, LEN_AND_STR("buildrecommends")},
{RPMTAG_BUILDSUGGESTS, 0, 0, LEN_AND_STR("buildsuggests")},
{RPMTAG_BUILDENHANCES, 0, 0, LEN_AND_STR("buildsupplements")},
{RPMTAG_BUILDENHANCES, 0, 0, LEN_AND_STR("buildenhances")},
{RPMTAG_SECMANIFEST, 0, 0, LEN_AND_STR("manifest")},
- {RPMTAG_BUILDINFO, 0, 0, LEN_AND_STR("buildinfo")},
+ {RPMTAG_ORDERNAME, 2, 0, LEN_AND_STR("orderwithrequires")},
+ {RPMTAG_REMOVEPATHPOSTFIXES,0, 0, LEN_AND_STR("removepathpostfixes")},
+ {RPMTAG_BUILDINFO, 0, 0, LEN_AND_STR("buildinfo")},
{0, 0, 0, 0}
};
@@ -995,8 +1114,6 @@ int parsePreamble(rpmSpec spec, int initialPackage)
char *NVR = NULL;
char lang[BUFSIZ];
- pkg = newPackage(spec);
-
if (! initialPackage) {
/* There is one option to %package: <pkg> or -n <pkg> */
if (parseSimplePart(spec->line, &name, &flag)) {
@@ -1004,9 +1121,11 @@ int parsePreamble(rpmSpec spec, int initialPackage)
spec->line);
goto exit;
}
+
+ //if (rpmCharCheck(spec, name, WHITELIST_NAME))
+ // goto exit;
if (!lookupPackage(spec, name, flag, NULL)) {
- rpmlog(RPMLOG_ERR, _("Package already exists: %s\n"), spec->line);
free(name);
goto exit;
}
@@ -1018,9 +1137,13 @@ int parsePreamble(rpmSpec spec, int initialPackage)
} else
NVR = xstrdup(name);
free(name);
+ pkg = newPackage(NVR, spec->pool, &spec->packages);
headerPutString(pkg->header, RPMTAG_NAME, NVR);
} else {
NVR = xstrdup("(main package)");
+ pkg = newPackage(NULL, spec->pool, &spec->packages);
+ spec->sourcePackage = newPackage(NULL, spec->pool, NULL);
+
}
if ((rc = readLine(spec, STRIP_TRAILINGSPACE | STRIP_COMMENTS)) > 0) {
@@ -1037,6 +1160,14 @@ int parsePreamble(rpmSpec spec, int initialPackage)
SKIPSPACE(linep);
if (*linep != '\0') {
if (findPreambleTag(spec, &tag, &macro, lang)) {
+ if (spec->lineNum == 1 &&
+ (unsigned char)(spec->line[0]) == 0xed &&
+ (unsigned char)(spec->line[1]) == 0xab &&
+ (unsigned char)(spec->line[2]) == 0xee &&
+ (unsigned char)(spec->line[3]) == 0xdb) {
+ rpmlog(RPMLOG_ERR, _("Binary rpm package found. Expected spec file!\n"));
+ goto exit;
+ }
rpmlog(RPMLOG_ERR, _("line %d: Unknown tag: %s\n"),
spec->lineNum, spec->line);
goto exit;
@@ -1060,7 +1191,7 @@ int parsePreamble(rpmSpec spec, int initialPackage)
}
}
- /*
+ /*
* Expand buildroot one more time to get %{version} and the like
* from the main package, validate sanity. The spec->buildRoot could
* still contain unexpanded macros but it cannot be empty or '/', and it
@@ -1078,7 +1209,7 @@ int parsePreamble(rpmSpec spec, int initialPackage)
}
free(spec->buildRoot);
spec->buildRoot = buildRoot;
- addMacro(spec->macros, "buildroot", NULL, spec->buildRoot, RMIL_SPEC);
+ rpmPushMacro(spec->macros, "buildroot", NULL, spec->buildRoot, RMIL_SPEC);
}
/* XXX Skip valid arch check if not building binary package */
@@ -1100,8 +1231,7 @@ int parsePreamble(rpmSpec spec, int initialPackage)
}
if (pkg != spec->packages) {
- headerCopyTags(spec->packages->header, pkg->header,
- (rpmTagVal *)copyTagsDuringParse);
+ copyInheritedTags(pkg->header, spec->packages->header);
}
if (checkForRequired(pkg->header, NVR)) {