Skip to content

Commit

Permalink
Add parseStages enum
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ffesti committed Mar 6, 2024
1 parent 26a1ccf commit e9d3eae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 10 additions & 7 deletions build/parseSpec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion build/rpmbuild_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit e9d3eae

Please sign in to comment.