Preserves the version block and concatenates all included domain .pdl files.
(file_path, chrome_version)
| 71 | |
| 72 | |
| 73 | def flatten_browser_pdl(file_path, chrome_version): |
| 74 | """Preserves the version block and concatenates all included domain .pdl files.""" |
| 75 | with open(file_path) as file: |
| 76 | content = file.read() |
| 77 | # Extract version block |
| 78 | version_match = re.search(r"(version\s+major\s+\d+\s+minor\s+\d+)", content) |
| 79 | version_block = version_match.group(1) + "\n\n" if version_match else "" |
| 80 | # Find all include lines |
| 81 | includes = re.findall(r"include domains/([A-Za-z0-9_]+\.pdl)", content) |
| 82 | base_url = ( |
| 83 | "https://api.github.com/repos/chromium/chromium/contents/third_party/blink/public/devtools_protocol/domains/" |
| 84 | ) |
| 85 | concatenated = "" |
| 86 | for domain_file in includes: |
| 87 | url = f"{base_url}{domain_file}?ref={chrome_version}" |
| 88 | response = github_get(url) |
| 89 | if response.status != 200: |
| 90 | raise ValueError(f"Fetch failed (HTTP {response.status}): {url}") |
| 91 | concatenated += response.data.decode("utf-8") + "\n" |
| 92 | # Overwrite the file with version block + concatenated domains |
| 93 | with open(file_path, "w") as file: |
| 94 | file.write(version_block + concatenated) |
| 95 | |
| 96 | |
| 97 | def add_pdls(chrome_milestone): |