diff --git a/build/parseSpec.c b/build/parseSpec.c index ed6418a070..c660d47eee 100644 --- a/build/parseSpec.c +++ b/build/parseSpec.c @@ -596,7 +596,7 @@ int parseLines(rpmSpec spec, int strip, ARGV_t *avp, StringBuf *sbp) while (! (nextPart = isPart(spec->line))) { /* HACK: Emit a legible error on the obsolete %patchN form for now */ - if (sbp == &(spec->prep)) { + if (sbp == &(spec->sections[SECT_PREP])) { size_t slen = strlen(spec->line); if (slen >= 7 && risdigit(spec->line[6]) && rstreqn(spec->line, "%patch", 6)) @@ -933,28 +933,34 @@ static rpmRC parseSpecSection(rpmSpec *specptr, int secondary) case PART_PREP: rpmPushMacroAux(NULL, "setup", "-", doSetupMacro, spec, -1, 0, 0); rpmPushMacroAux(NULL, "patch", "-", doPatchMacro, spec, -1, 0, 0); - parsePart = parseSimpleScript(spec, "%prep", &(spec->prep)); + parsePart = parseSimpleScript(spec, "%prep", + &(spec->sections[SECT_PREP])); rpmPopMacro(NULL, "patch"); rpmPopMacro(NULL, "setup"); break; case PART_CONF: - parsePart = parseSimpleScript(spec, "%conf", &(spec->conf)); + parsePart = parseSimpleScript(spec, "%conf", + &(spec->sections[SECT_CONF])); break; case PART_BUILDREQUIRES: parsePart = parseSimpleScript(spec, "%generate_buildrequires", - &(spec->buildrequires)); + &(spec->sections[SECT_BUILDREQUIRES])); break; case PART_BUILD: - parsePart = parseSimpleScript(spec, "%build", &(spec->build)); + parsePart = parseSimpleScript(spec, "%build", + &(spec->sections[SECT_BUILD])); break; case PART_INSTALL: - parsePart = parseSimpleScript(spec, "%install", &(spec->install)); + parsePart = parseSimpleScript(spec, "%install", + &(spec->sections[SECT_INSTALL])); break; case PART_CHECK: - parsePart = parseSimpleScript(spec, "%check", &(spec->check)); + parsePart = parseSimpleScript(spec, "%check", + &(spec->sections[SECT_CHECK])); break; case PART_CLEAN: - parsePart = parseSimpleScript(spec, "%clean", &(spec->clean)); + parsePart = parseSimpleScript(spec, "%clean", + &(spec->sections[SECT_CLEAN])); break; case PART_CHANGELOG: parsePart = parseChangelog(spec); @@ -1105,10 +1111,10 @@ static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags, if (parseSpecSection(&spec, 0) != RPMRC_OK) goto errxit; - if (spec->clean == NULL) { + if (spec->sections[SECT_CLEAN] == NULL) { char *body = rpmExpand("%{?buildroot: %{__rm} -rf %{buildroot}}", NULL); - spec->clean = newStringBuf(); - appendLineStringBuf(spec->clean, body); + spec->sections[SECT_CLEAN] = newStringBuf(); + appendLineStringBuf(spec->sections[SECT_CLEAN], body); free(body); } diff --git a/build/rpmbuild_internal.h b/build/rpmbuild_internal.h index 349adacfd7..279a329de2 100644 --- a/build/rpmbuild_internal.h +++ b/build/rpmbuild_internal.h @@ -21,6 +21,18 @@ #define ALLOWED_CHARS_EVR ALLOWED_CHARS_VERREL "-:" #define LEN_AND_STR(_tag) (sizeof(_tag)-1), (_tag) + +enum sections_e { + SECT_PREP = 0, + SECT_CONF = 1, + SECT_BUILDREQUIRES = 2, + SECT_BUILD = 3, + SECT_INSTALL = 4, + SECT_CHECK = 5, + SECT_CLEAN = 6, +}; +#define NR_SECT 7 + struct TriggerFileEntry { int index; char * fileName; @@ -137,14 +149,7 @@ struct rpmSpec_s { rpmMacroContext macros; rpmstrPool pool; - StringBuf prep; /*!< %prep scriptlet. */ - StringBuf conf; /*!< %conf scriptlet. */ - StringBuf buildrequires; /*!< %buildrequires scriptlet. */ - StringBuf build; /*!< %build scriptlet. */ - StringBuf install; /*!< %install scriptlet. */ - StringBuf check; /*!< %check scriptlet. */ - StringBuf clean; /*!< %clean scriptlet. */ - + StringBuf sections[NR_SECT]; /*!< spec sections (%prep etc) */ StringBuf parsed; /*!< parsed spec contents */ Package packages; /*!< Package list. */ diff --git a/build/spec.c b/build/spec.c index b1a0f5a75b..824afba27f 100644 --- a/build/spec.c +++ b/build/spec.c @@ -217,13 +217,6 @@ rpmSpec newSpec(void) spec->readStack->readable = 1; spec->rootDir = NULL; - spec->prep = NULL; - spec->conf = NULL; - spec->build = NULL; - spec->install = NULL; - spec->check = NULL; - spec->clean = NULL; - spec->parsed = NULL; spec->sources = NULL; spec->packages = NULL; @@ -258,14 +251,9 @@ rpmSpec rpmSpecFree(rpmSpec spec) if (spec == NULL) return NULL; - spec->prep = freeStringBuf(spec->prep); - spec->conf = freeStringBuf(spec->conf); - spec->build = freeStringBuf(spec->build); - spec->install = freeStringBuf(spec->install); - spec->check = freeStringBuf(spec->check); - spec->clean = freeStringBuf(spec->clean); - spec->parsed = freeStringBuf(spec->parsed); - spec->buildrequires = freeStringBuf(spec->buildrequires); + for (int i = 0; i < NR_SECT; i++) + freeStringBuf(spec->sections[i]); + freeStringBuf(spec->parsed); spec->buildRoot = _free(spec->buildRoot); spec->specFile = _free(spec->specFile); @@ -431,15 +419,22 @@ const char * rpmSpecGetSection(rpmSpec spec, int section) { if (spec) { switch (section) { - case RPMBUILD_NONE: return getStringBuf(spec->parsed); - case RPMBUILD_PREP: return getStringBuf(spec->prep); - case RPMBUILD_CONF: return getStringBuf(spec->conf); + case RPMBUILD_NONE: + return getStringBuf(spec->parsed); + case RPMBUILD_PREP: + return getStringBuf(spec->sections[SECT_PREP]); + case RPMBUILD_CONF: + return getStringBuf(spec->sections[SECT_CONF]); case RPMBUILD_BUILDREQUIRES: - return getStringBuf(spec->buildrequires); - case RPMBUILD_BUILD: return getStringBuf(spec->build); - case RPMBUILD_INSTALL: return getStringBuf(spec->install); - case RPMBUILD_CHECK: return getStringBuf(spec->check); - case RPMBUILD_CLEAN: return getStringBuf(spec->clean); + return getStringBuf(spec->sections[SECT_BUILDREQUIRES]); + case RPMBUILD_BUILD: + return getStringBuf(spec->sections[SECT_BUILD]); + case RPMBUILD_INSTALL: + return getStringBuf(spec->sections[SECT_INSTALL]); + case RPMBUILD_CHECK: + return getStringBuf(spec->sections[SECT_CHECK]); + case RPMBUILD_CLEAN: + return getStringBuf(spec->sections[SECT_CLEAN]); } } return NULL;