Skip to content

Commit cdb9268

Browse files
committed
fix: fix parsing for newer versions of brotli
Newer versions of brotli have changed how it defines version macros in `c/common/version.h`. Attempt to decode the new definitions first, falling back to the previous code to allow the parser to parse the version from both older and newer versions of brotli.
1 parent ee111ed commit cdb9268

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

dep_checker/versions_parser.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,27 @@ def get_acorn_version(repo_path: Path) -> str:
1818

1919
def get_brotli_version(repo_path: Path) -> str:
2020
with open(repo_path / "deps/brotli/c/common/version.h", "r") as f:
21-
matches = re.search("#define BROTLI_VERSION (?P<version>.*)", f.read())
21+
header_contents = f.read()
22+
# Newer versions of brotli define MAJOR, MINOR, PATCH separately.
23+
matches = re.search(
24+
"#define BROTLI_VERSION_MAJOR (?P<major>.*)\n"
25+
"#define BROTLI_VERSION_MINOR (?P<minor>.*)\n"
26+
"#define BROTLI_VERSION_PATCH (?P<patch>.*)",
27+
header_contents,
28+
re.MULTILINE,
29+
)
2230
if matches is None:
23-
raise RuntimeError("Error extracting version number for brotli")
24-
hex_version = matches.groupdict()["version"]
25-
major_version = int(hex_version, 16) >> 24
26-
minor_version = int(hex_version, 16) >> 12 & 0xFF
27-
patch_version = int(hex_version, 16) & 0xFFFFF
28-
return f"{major_version}.{minor_version}.{patch_version}"
31+
# Older versions of brotli hex encode the version as a literal.
32+
matches = re.search("#define BROTLI_VERSION (?P<version>.*)", header_contents)
33+
if matches is None:
34+
raise RuntimeError("Error extracting version number for brotli")
35+
hex_version = matches.groupdict()["version"]
36+
major_version = int(hex_version, 16) >> 24
37+
minor_version = int(hex_version, 16) >> 12 & 0xFF
38+
patch_version = int(hex_version, 16) & 0xFFFFF
39+
return f"{major_version}.{minor_version}.{patch_version}"
40+
versions = matches.groupdict()
41+
return f"{versions['major']}.{versions['minor']}.{versions['patch']}"
2942

3043

3144
def get_c_ares_version(repo_path: Path) -> str:

0 commit comments

Comments
 (0)