Skip to content

Commit

Permalink
Move functions from parsePreamble to parseSpec
Browse files Browse the repository at this point in the history
and drop them from the internal header
  • Loading branch information
ffesti committed Sep 19, 2023
1 parent 0cbf646 commit 184808c
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 210 deletions.
191 changes: 0 additions & 191 deletions build/parsePreamble.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,6 @@
#define SKIPWHITE(_x) {while (*(_x) && (risspace(*_x) || *(_x) == ',')) (_x)++;}
#define SKIPNONWHITE(_x){while (*(_x) &&!(risspace(*_x) || *(_x) == ',')) (_x)++;}

/**
*/
static const rpmTagVal copyTagsDuringParse[] = {
RPMTAG_EPOCH,
RPMTAG_VERSION,
RPMTAG_RELEASE,
RPMTAG_LICENSE,
RPMTAG_PACKAGER,
RPMTAG_DISTRIBUTION,
RPMTAG_DISTURL,
RPMTAG_VENDOR,
RPMTAG_ICON,
RPMTAG_URL,
RPMTAG_VCS,
RPMTAG_CHANGELOGTIME,
RPMTAG_CHANGELOGNAME,
RPMTAG_CHANGELOGTEXT,
RPMTAG_PREFIXES,
RPMTAG_DISTTAG,
RPMTAG_BUGURL,
RPMTAG_TRANSLATIONURL,
RPMTAG_UPSTREAMRELEASES,
RPMTAG_GROUP,
RPMTAG_MODULARITYLABEL,
0
};

/**
*/
static const rpmTagVal requiredTags[] = {
RPMTAG_NAME,
RPMTAG_VERSION,
RPMTAG_RELEASE,
RPMTAG_SUMMARY,
RPMTAG_LICENSE,
0
};

/**
*/
static rpmRC addOrAppendListEntry(Header h, rpmTagVal tag, const char * line)
Expand Down Expand Up @@ -413,159 +375,6 @@ static inline char * findLastChar(char * s)
return res;
}

/**
*/
int isMemberInEntry(Header h, const char *name, rpmTagVal tag)
{
struct rpmtd_s td;
int found = 0;
const char *str;

if (!headerGet(h, tag, &td, HEADERGET_MINMEM))
return -1;

while ((str = rpmtdNextString(&td))) {
if (!rstrcasecmp(str, name)) {
found = 1;
break;
}
}
rpmtdFreeData(&td);

return found;
}

/**
*/
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) {
rpmlog(RPMLOG_ERR, _("Architecture is excluded: %s\n"), arch);
goto exit;
}
if (isMemberInEntry(spec->buildRestrictions,
arch, RPMTAG_EXCLUSIVEARCH) == 0) {
rpmlog(RPMLOG_ERR, _("Architecture is not included: %s\n"), arch);
goto exit;
}
if (isMemberInEntry(spec->buildRestrictions,
os, RPMTAG_EXCLUDEOS) == 1) {
rpmlog(RPMLOG_ERR, _("OS is excluded: %s\n"), os);
goto exit;
}
if (isMemberInEntry(spec->buildRestrictions,
os, RPMTAG_EXCLUSIVEOS) == 0) {
rpmlog(RPMLOG_ERR, _("OS is not included: %s\n"), os);
goto exit;
}
rc = RPMRC_OK;

exit:
free(arch);
free(os);

return rc;
}

/**
* Check that required tags are present in header.
* @param h header
* @param NVR package name-version-release
* @return RPMRC_OK if OK
*/
int checkForRequired(Header h)
{
int res = RPMRC_OK;
const rpmTagVal * p;

for (p = requiredTags; *p != 0; p++) {
if (!headerIsEntry(h, *p)) {
rpmlog(RPMLOG_ERR,
_("%s field must be present in package: %s\n"),
rpmTagGetName(*p), headerGetString(h, RPMTAG_NAME));
res = RPMRC_FAIL;
}
}

return res;
}

/**
* Check that no duplicate tags are present in header.
* @param h header
* @param NVR package name-version-release
* @return RPMRC_OK if OK
*/
int checkForDuplicates(Header h)
{
int res = RPMRC_OK;
rpmTagVal tag, lastTag = RPMTAG_NOT_FOUND;
HeaderIterator hi = headerInitIterator(h);

while ((tag = headerNextTag(hi)) != RPMTAG_NOT_FOUND) {
if (tag == lastTag) {
rpmlog(RPMLOG_ERR, _("Duplicate %s entries in package: %s\n"),
rpmTagGetName(tag), headerGetString(h, RPMTAG_NAME));
res = RPMRC_FAIL;
}
lastTag = tag;
}
headerFreeIterator(hi);

return res;
}

/**
*/
static struct optionalTag {
rpmTagVal ot_tag;
const char * ot_mac;
} const optionalTags[] = {
{ RPMTAG_VENDOR, "%{vendor}" },
{ RPMTAG_PACKAGER, "%{packager}" },
{ RPMTAG_DISTRIBUTION, "%{distribution}" },
{ RPMTAG_DISTURL, "%{disturl}" },
{ RPMTAG_DISTTAG, "%{disttag}" },
{ RPMTAG_BUGURL, "%{bugurl}" },
{ RPMTAG_TRANSLATIONURL, "%{translationurl}" },
{ RPMTAG_UPSTREAMRELEASES, "%{upstreamreleases}" },
{ RPMTAG_MODULARITYLABEL, "%{modularitylabel}"},
{ -1, NULL }
};

/**
*/
void fillOutMainPackage(Header h)
{
const struct optionalTag *ot;

for (ot = optionalTags; ot->ot_mac != NULL; ot++) {
if (!headerIsEntry(h, ot->ot_tag)) {
char *val = rpmExpand(ot->ot_mac, NULL);
if (val && *val != '%') {
headerPutString(h, ot->ot_tag, val);
}
free(val);
}
}
}

/**
*/
void copyInheritedTags(Header h, Header fromh)
{
headerCopyTags(fromh, h, (rpmTagVal *)copyTagsDuringParse);
}

/**
*/
Expand Down
Loading

0 comments on commit 184808c

Please sign in to comment.