Skip to content

Commit

Permalink
Fix parsing of sections and tags from RPM sources
Browse files Browse the repository at this point in the history
Signed-off-by: Nikola Forró <[email protected]>
  • Loading branch information
nforro committed May 10, 2024
1 parent 0e46977 commit 0b60086
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions scripts/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ def extract_sections(filename: Path) -> List[str]:
static const struct PartRec {
int part;
int prebuildonly;
size_t len;
const char * token;
} partList[] = {
{ PART_PREAMBLE, LEN_AND_STR("%package")},
{ PART_PREP, LEN_AND_STR("%prep")},
{ PART_PREAMBLE, 0, LEN_AND_STR("%package")},
{ PART_PREP, 1, LEN_AND_STR("%prep")},
...
{0, 0, 0}
};
Expand All @@ -50,7 +51,8 @@ def extract_sections(filename: Path) -> List[str]:
constant = Word(srange("[A-Z_]")).suppress()
name = dbl_quoted_string.set_parse_action(remove_quotes)
macro = "LEN_AND_STR(" + name + ")"
item = "{" + Suppress(constant) + "," + macro + "}"
number = pyparsing_common.number
item = "{" + Suppress(constant) + "," + number.suppress() + "," + macro + "}"
sentinel = Suppress("{" + delimited_list(Literal("0")) + "}")
parser = (
Suppress("partList[]") + "=" + "{" + delimited_list(item) + "," + sentinel + "}"
Expand All @@ -67,8 +69,8 @@ def extract_tags(filename: Path, with_args: bool = False) -> List[str]:
Extracts tag names from a constant array looking like this:
static struct PreambleRec_s const preambleList[] = {
{RPMTAG_NAME, 0, 0, 1, LEN_AND_STR("name")},
{RPMTAG_VERSION, 0, 0, 1, LEN_AND_STR("version")},
{RPMTAG_NAME, 0, 0, 1, 0, LEN_AND_STR("name")},
{RPMTAG_VERSION, 0, 0, 1, 0, LEN_AND_STR("version")},
...
{0, 0, 0, 0}
};
Expand All @@ -94,6 +96,8 @@ def extract_tags(filename: Path, with_args: bool = False) -> List[str]:
+ ","
+ number.suppress()
+ ","
+ number.suppress()
+ ","
+ macro
+ "}"
)
Expand Down

0 comments on commit 0b60086

Please sign in to comment.