Preserves the version block and concatenates all included domain .pdl files.
(file_path, chrome_version)
| 66 | |
| 67 | |
| 68 | def flatten_browser_pdl(file_path, chrome_version): |
| 69 | """Preserves the version block and concatenates all included domain .pdl files.""" |
| 70 | with open(file_path) as file: |
| 71 | content = file.read() |
| 72 | # Extract version block |
| 73 | version_match = re.search(r"(version\s+major\s+\d+\s+minor\s+\d+)", content) |
| 74 | version_block = version_match.group(1) + "\n\n" if version_match else "" |
| 75 | # Find all include lines |
| 76 | includes = re.findall(r"include domains/([A-Za-z0-9_]+\.pdl)", content) |
| 77 | base_url = f"https://raw.githubusercontent.com/chromium/chromium/{chrome_version}/third_party/blink/public/devtools_protocol/domains/" |
| 78 | concatenated = "" |
| 79 | for domain_file in includes: |
| 80 | url = base_url + domain_file |
| 81 | response = http.request("GET", url) |
| 82 | concatenated += response.data.decode("utf-8") + "\n" |
| 83 | # Overwrite the file with version block + concatenated domains |
| 84 | with open(file_path, "w") as file: |
| 85 | file.write(version_block + concatenated) |
| 86 | |
| 87 | |
| 88 | def add_pdls(chrome_milestone): |