Add parseStages enum

As we now have three different sources of spec content we need a proper
enum to tell them apart and get rid of the seconday bool parameter.

No functional change but is needed for the next patch
This commit is contained in:
Florian Festi 2024-02-19 10:59:19 +01:00 committed by Panu Matilainen
parent 26a1ccf281
commit cbf66768b0
2 changed files with 17 additions and 8 deletions

View File

@ -25,7 +25,9 @@
#define ISMACRO(s,m,len) (rstreqn((s), (m), len) && !risalpha((s)[len]))
#define ISMACROWITHARG(s,m,len) (rstreqn((s), (m), len) && (risblank((s)[len]) || !(s)[len]))
static rpmRC parseSpecParts(rpmSpec spec, const char *pattern);
static rpmRC parseSpecParts(rpmSpec spec, const char *pattern,
enum parseStages stage);
typedef struct OpenFileInfo {
char * fileName;
@ -982,7 +984,7 @@ static rpmRC parseBuildsystem(rpmSpec spec)
}
if (!rc)
rc = parseSpecParts(spec, path);
rc = parseSpecParts(spec, path, PARSE_BUILDSYS);
if (!rc)
unlink(path);
Fclose(fd);
@ -996,7 +998,7 @@ exit:
static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
const char *buildRoot, int recursing);
static rpmRC parseSpecSection(rpmSpec *specptr, int secondary)
static rpmRC parseSpecSection(rpmSpec *specptr, enum parseStages stage)
{
rpmSpec spec = *specptr;
int parsePart = PART_PREAMBLE;
@ -1160,7 +1162,7 @@ static rpmRC parseSpecSection(rpmSpec *specptr, int secondary)
}
}
if (!secondary && parseBuildsystem(spec))
if (stage == PARSE_SPECFILE && parseBuildsystem(spec))
goto errxit;
/* Add arch for each package */
@ -1299,7 +1301,8 @@ rpmSpec rpmSpecParse(const char *specFile, rpmSpecFlags flags,
return spec;
}
static rpmRC parseSpecParts(rpmSpec spec, const char *pattern)
static rpmRC parseSpecParts(rpmSpec spec, const char *pattern,
enum parseStages stage)
{
ARGV_t argv = NULL;
int argc = 0;
@ -1312,7 +1315,7 @@ static rpmRC parseSpecParts(rpmSpec spec, const char *pattern)
pushOFI(spec, argv[i]);
snprintf(spec->fileStack->readBuf, spec->fileStack->readBufLen,
"# Spec part read from %s\n\n", argv[i]);
if (parseSpecSection(&spec, 1) != RPMRC_OK) {
if (parseSpecSection(&spec, stage) != RPMRC_OK) {
rpmlog(RPMLOG_ERR, "parsing failed\n");
rc = RPMRC_FAIL;
break;
@ -1326,7 +1329,7 @@ static rpmRC parseSpecParts(rpmSpec spec, const char *pattern)
rpmRC parseGeneratedSpecs(rpmSpec spec)
{
char * specPattern = rpmGenPath("%{specpartsdir}", NULL, "*.specpart");
rpmRC rc = parseSpecParts(spec, specPattern);
rpmRC rc = parseSpecParts(spec, specPattern, PARSE_GENERATED);
free(specPattern);
if (!rc) {
rc = finalizeSpec(spec);

View File

@ -21,6 +21,11 @@
#define ALLOWED_CHARS_EVR ALLOWED_CHARS_VERREL "-:"
#define LEN_AND_STR(_tag) (sizeof(_tag)-1), (_tag)
enum parseStages {
PARSE_SPECFILE,
PARSE_BUILDSYS,
PARSE_GENERATED,
};
enum sections_e {
SECT_PREP = 0,
@ -359,10 +364,11 @@ int parsePolicies(rpmSpec spec);
* Parse tags from preamble of a spec file.
* @param spec spec file control structure
* @param initialPackage
* @param stage
* @return >= 0 next rpmParseState, < 0 on error
*/
RPM_GNUC_INTERNAL
int parsePreamble(rpmSpec spec, int initialPackage);
int parsePreamble(rpmSpec spec, int initialPackage, enum parseStages stage);
/** \ingroup rpmbuild
* Parse %%pre et al scriptlets from a spec file.