From e30eff338be5519ed8497184068504c86b670f30 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Mon, 19 Feb 2024 10:59:19 +0100 Subject: [PATCH] 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 --- build/parseSpec.c | 17 ++++++++++------- build/rpmbuild_internal.h | 8 +++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/build/parseSpec.c b/build/parseSpec.c index 9a0a1f8734..6baaffde5c 100644 --- a/build/parseSpec.c +++ b/build/parseSpec.c @@ -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, BUILDSYS); if (!rc) unlink(path); Fclose(fd); @@ -996,7 +998,7 @@ static rpmRC parseBuildsystem(rpmSpec spec) 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 == 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, GENERATED); free(specPattern); if (!rc) { rc = finalizeSpec(spec); diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h index e2d4f8d683..f71dbdca37 100644 --- a/build/rpmbuild_internal.h +++ b/build/rpmbuild_internal.h @@ -21,6 +21,11 @@ #define ALLOWED_CHARS_EVR ALLOWED_CHARS_VERREL "-:" #define LEN_AND_STR(_tag) (sizeof(_tag)-1), (_tag) +enum parseStages { + SPECFILE, + BUILDSYS, + 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.