Skip to content

Commit

Permalink
Store spec section string buffers as an array
Browse files Browse the repository at this point in the history
Where there's more than one of a kind, sooner or later you'll want
to manipulate them programmatically. Use an array where array is
called for. No functional changes.

Note that the parsed spec contents is not a section, so we store it
separately.
  • Loading branch information
pmatilai committed Dec 11, 2023
1 parent a939bee commit 159a96e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
28 changes: 17 additions & 11 deletions build/parseSpec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
21 changes: 13 additions & 8 deletions build/rpmbuild_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
41 changes: 18 additions & 23 deletions build/spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 159a96e

Please sign in to comment.