Skip to content

Commit

Permalink
fix: fix parsing for newer versions of brotli
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richardlau committed Jan 4, 2024
1 parent ee111ed commit cdb9268
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions dep_checker/versions_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@ def get_acorn_version(repo_path: Path) -> str:

def get_brotli_version(repo_path: Path) -> str:
with open(repo_path / "deps/brotli/c/common/version.h", "r") as f:
matches = re.search("#define BROTLI_VERSION (?P<version>.*)", f.read())
header_contents = f.read()
# Newer versions of brotli define MAJOR, MINOR, PATCH separately.
matches = re.search(
"#define BROTLI_VERSION_MAJOR (?P<major>.*)\n"
"#define BROTLI_VERSION_MINOR (?P<minor>.*)\n"
"#define BROTLI_VERSION_PATCH (?P<patch>.*)",
header_contents,
re.MULTILINE,
)
if matches is None:
raise RuntimeError("Error extracting version number for brotli")
hex_version = matches.groupdict()["version"]
major_version = int(hex_version, 16) >> 24
minor_version = int(hex_version, 16) >> 12 & 0xFF
patch_version = int(hex_version, 16) & 0xFFFFF
return f"{major_version}.{minor_version}.{patch_version}"
# Older versions of brotli hex encode the version as a literal.
matches = re.search("#define BROTLI_VERSION (?P<version>.*)", header_contents)
if matches is None:
raise RuntimeError("Error extracting version number for brotli")
hex_version = matches.groupdict()["version"]
major_version = int(hex_version, 16) >> 24
minor_version = int(hex_version, 16) >> 12 & 0xFF
patch_version = int(hex_version, 16) & 0xFFFFF
return f"{major_version}.{minor_version}.{patch_version}"
versions = matches.groupdict()
return f"{versions['major']}.{versions['minor']}.{versions['patch']}"


def get_c_ares_version(repo_path: Path) -> str:
Expand Down

0 comments on commit cdb9268

Please sign in to comment.