Skip to content

Commit

Permalink
Merge pull request #171 from nodejs/fix-brotli
Browse files Browse the repository at this point in the history
fix: fix parsing for newer versions of brotli
  • Loading branch information
richardlau authored Jan 5, 2024
2 parents ee111ed + cdb9268 commit 696e1fe
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 696e1fe

Please sign in to comment.