Liviu Rau | b9d3616 | 2022-03-15 10:18:14 | [diff] [blame] | 1 | #!/usr/bin/env vpython3 |
Mathias Bynens | 8555df0 | 2020-04-27 14:19:06 | [diff] [blame] | 2 | # |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 3 | # Copyright 2019 The Chromium Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """ |
| 7 | Update manually maintained dependencies from Chromium. |
| 8 | """ |
| 9 | |
| 10 | import argparse |
keno | deacf6f | 2023-01-30 08:16:29 | [diff] [blame] | 11 | import enum |
Liviu Rau | 88c99fa | 2024-07-10 14:14:15 | [diff] [blame] | 12 | import json |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 13 | import os |
| 14 | import shutil |
Yang Guo | fa871b6 | 2019-10-24 14:04:46 | [diff] [blame] | 15 | import subprocess |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 16 | import sys |
| 17 | |
Johan Bay | 8d8c684 | 2022-02-02 17:44:23 | [diff] [blame] | 18 | |
| 19 | def node_path(options): |
| 20 | try: |
| 21 | old_sys_path = sys.path[:] |
| 22 | sys.path.append( |
Liviu Rau | bd81a05 | 2024-06-04 12:50:34 | [diff] [blame] | 23 | os.path.join(options.devtools_dir, 'third_party', 'node')) |
Johan Bay | 8d8c684 | 2022-02-02 17:44:23 | [diff] [blame] | 24 | import node |
| 25 | finally: |
| 26 | sys.path = old_sys_path |
| 27 | return node.GetBinaryPath() |
| 28 | |
Liviu Rau | 18f24e0 | 2024-02-15 11:11:08 | [diff] [blame] | 29 | |
Mathias Bynens | 4ceefeb | 2020-07-24 10:04:49 | [diff] [blame] | 30 | # Files whose location within devtools-frontend matches the upstream location. |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 31 | FILES = [ |
Mathias Bynens | 4ceefeb | 2020-07-24 10:04:49 | [diff] [blame] | 32 | 'v8/include/js_protocol.pdl', |
| 33 | 'third_party/blink/renderer/core/css/css_properties.json5', |
| 34 | 'third_party/blink/renderer/core/html/aria_properties.json5', |
| 35 | 'third_party/blink/public/devtools_protocol/browser_protocol.pdl', |
Ari Chivukula | 4cea925 | 2023-02-02 09:09:43 | [diff] [blame] | 36 | 'third_party/blink/renderer/core/frame/deprecation/deprecation.json5', |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 37 | ] |
| 38 | |
Mathias Bynens | 4ceefeb | 2020-07-24 10:04:49 | [diff] [blame] | 39 | # Files whose location within devtools-frontend differs from the upstream location. |
| 40 | FILE_MAPPINGS = { |
| 41 | # chromium_path => devtools_frontend_path |
Ilya Sherman | a46c048 | 2020-08-18 22:38:39 | [diff] [blame] | 42 | 'components/variations/proto/devtools/client_variations.js': |
| 43 | 'front_end/third_party/chromium/client-variations/ClientVariations.js', |
Tim van der Lippe | ab0853c | 2020-09-11 13:34:31 | [diff] [blame] | 44 | 'third_party/axe-core/axe.d.ts': 'front_end/third_party/axe-core/axe.d.ts', |
| 45 | 'third_party/axe-core/axe.js': 'front_end/third_party/axe-core/axe.js', |
| 46 | 'third_party/axe-core/axe.min.js': |
| 47 | 'front_end/third_party/axe-core/axe.min.js', |
| 48 | 'third_party/axe-core/LICENSE': 'front_end/third_party/axe-core/LICENSE', |
Mathias Bynens | 4ceefeb | 2020-07-24 10:04:49 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | for f in FILES: |
| 52 | FILE_MAPPINGS[f] = f |
| 53 | |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 54 | |
keno | deacf6f | 2023-01-30 08:16:29 | [diff] [blame] | 55 | class ReferenceMode(enum.Enum): |
| 56 | Tot = 'tot' |
| 57 | WorkingTree = 'working-tree' |
| 58 | |
| 59 | def __str__(self): |
| 60 | return self.value |
| 61 | |
| 62 | |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 63 | def parse_options(cli_args): |
Liviu Rau | 18f24e0 | 2024-02-15 11:11:08 | [diff] [blame] | 64 | parser = argparse.ArgumentParser( |
| 65 | description='Roll dependencies from Chromium.') |
keno | deacf6f | 2023-01-30 08:16:29 | [diff] [blame] | 66 | parser.add_argument( |
| 67 | '--ref', |
| 68 | type=ReferenceMode, |
| 69 | choices=list(ReferenceMode), |
Lingqi Chi | 15da3fb | 2023-10-12 07:50:58 | [diff] [blame] | 70 | default=ReferenceMode.Tot, |
keno | deacf6f | 2023-01-30 08:16:29 | [diff] [blame] | 71 | help='Defaults to tot. ' |
| 72 | 'If tot, fetch origin/main of Chromium repository and use it. ' |
| 73 | 'If working-tree, use working tree as is.') |
Liviu Rau | b3870c1 | 2024-01-08 11:42:42 | [diff] [blame] | 74 | parser.add_argument('--update-node', |
Liviu Rau | d5933e5 | 2024-01-09 09:21:04 | [diff] [blame] | 75 | action="store_true", |
| 76 | default=False, |
Liviu Rau | b3870c1 | 2024-01-08 11:42:42 | [diff] [blame] | 77 | help='If set it syncs nodejs.') |
Liviu Rau | 88c99fa | 2024-07-10 14:14:15 | [diff] [blame] | 78 | parser.add_argument( |
| 79 | '--output', |
| 80 | default=None, |
| 81 | help= |
| 82 | 'If set it outputs information about the roll in the specified file.') |
Mathias Bynens | 4ceefeb | 2020-07-24 10:04:49 | [diff] [blame] | 83 | parser.add_argument('chromium_dir', help='path to chromium/src directory') |
| 84 | parser.add_argument('devtools_dir', |
| 85 | help='path to devtools/devtools-frontend directory') |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 86 | return parser.parse_args(cli_args) |
| 87 | |
Liviu Rau | 18f24e0 | 2024-02-15 11:11:08 | [diff] [blame] | 88 | |
Yang Guo | fa871b6 | 2019-10-24 14:04:46 | [diff] [blame] | 89 | def update(options): |
| 90 | subprocess.check_call(['git', 'fetch', 'origin'], cwd=options.chromium_dir) |
Alex Rudenko | 7d12c02 | 2021-04-07 06:11:10 | [diff] [blame] | 91 | subprocess.check_call(['git', 'checkout', 'origin/main'], |
| 92 | cwd=options.chromium_dir) |
Yang Guo | fa871b6 | 2019-10-24 14:04:46 | [diff] [blame] | 93 | subprocess.check_call(['gclient', 'sync'], cwd=options.chromium_dir) |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 94 | |
Liviu Rau | b3870c1 | 2024-01-08 11:42:42 | [diff] [blame] | 95 | |
Liviu Rau | b3870c1 | 2024-01-08 11:42:42 | [diff] [blame] | 96 | def sync_node(options): |
Simon Zünd | a92b0bb | 2024-08-09 08:57:58 | [diff] [blame] | 97 | """Node is managed as a standard GCS deps so we run gclient sync but without hooks""" |
| 98 | subprocess.check_call(['gclient', 'sync', '--nohooks'], |
| 99 | cwd=options.devtools_dir) |
Liviu Rau | b3870c1 | 2024-01-08 11:42:42 | [diff] [blame] | 100 | |
Liviu Rau | 18f24e0 | 2024-02-15 11:11:08 | [diff] [blame] | 101 | |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 102 | def copy_files(options): |
Mathias Bynens | 4ceefeb | 2020-07-24 10:04:49 | [diff] [blame] | 103 | for from_path, to_path in FILE_MAPPINGS.items(): |
| 104 | from_path = os.path.normpath(from_path) |
| 105 | to_path = os.path.normpath(to_path) |
| 106 | print('%s => %s' % (from_path, to_path)) |
| 107 | shutil.copy(os.path.join(options.chromium_dir, from_path), |
| 108 | os.path.join(options.devtools_dir, to_path)) |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 109 | |
| 110 | |
Johan Bay | 8d8c684 | 2022-02-02 17:44:23 | [diff] [blame] | 111 | def generate_signatures(options): |
Liviu Rau | bd81a05 | 2024-06-04 12:50:34 | [diff] [blame] | 112 | print('generating JavaScript native functions signatures from .idl ' |
| 113 | 'and typescript definitions') |
Johan Bay | 8d8c684 | 2022-02-02 17:44:23 | [diff] [blame] | 114 | subprocess.check_call([ |
| 115 | node_path(options), |
| 116 | os.path.join(options.devtools_dir, 'scripts', 'javascript_natives', |
| 117 | 'index.js'), options.chromium_dir, options.devtools_dir |
| 118 | ]) |
| 119 | |
| 120 | |
Ergun Erdogmus | 97a5ea3 | 2024-01-30 13:55:28 | [diff] [blame] | 121 | def generate_protocol_resources(options): |
| 122 | print('generating protocol resources') |
| 123 | subprocess.check_call([ |
| 124 | os.path.join(options.devtools_dir, 'scripts', 'deps', |
Ergun Erdogmus | f9e4033 | 2024-02-07 15:16:28 | [diff] [blame] | 125 | 'generate_protocol_resources.py'), '--node-path', |
| 126 | node_path(options) |
Ergun Erdogmus | 97a5ea3 | 2024-01-30 13:55:28 | [diff] [blame] | 127 | ], |
| 128 | cwd=options.devtools_dir) |
| 129 | |
| 130 | |
| 131 | def run_git_cl_format(options): |
| 132 | print('running `git cl format` to format generated TS files') |
Simon Zünd | cc99413 | 2024-02-15 07:34:44 | [diff] [blame] | 133 | subprocess.check_call(['git', 'cl', 'format', '--js', '--full'], |
| 134 | cwd=options.devtools_dir) |
Ergun Erdogmus | 97a5ea3 | 2024-01-30 13:55:28 | [diff] [blame] | 135 | |
| 136 | |
| 137 | def run_eslint(options): |
| 138 | print('running eslint with --fix for generated files') |
| 139 | result = subprocess.check_output( |
| 140 | ['git', 'diff', '--diff-filter=d', '--name-only'], |
| 141 | cwd=options.devtools_dir).strip() |
| 142 | generated_source_files = [] |
| 143 | for line in result.split(b'\n'): |
| 144 | if line.endswith(b'.js') or line.endswith(b'.ts'): |
| 145 | generated_source_files.append(line) |
| 146 | subprocess.check_call([ |
Nikolay Vitkov | 19958d5 | 2025-04-13 21:18:18 | [diff] [blame] | 147 | node_path(options), "--experimental-strip-types", |
| 148 | "--no-warnings=ExperimentalWarning", |
Ergun Erdogmus | 97a5ea3 | 2024-01-30 13:55:28 | [diff] [blame] | 149 | os.path.join(options.devtools_dir, 'scripts', 'test', |
Nikolay Vitkov | 2a1b3b3 | 2025-01-03 10:18:46 | [diff] [blame] | 150 | 'run_lint_check.mjs') |
Ergun Erdogmus | 97a5ea3 | 2024-01-30 13:55:28 | [diff] [blame] | 151 | ] + generated_source_files, |
| 152 | cwd=options.devtools_dir) |
| 153 | |
Liviu Rau | 18f24e0 | 2024-02-15 11:11:08 | [diff] [blame] | 154 | |
Liviu Rau | 75dccf1 | 2024-07-24 11:59:44 | [diff] [blame] | 155 | def files_changed(options): |
| 156 | return subprocess.check_output(['git', 'diff', '--name-only'], |
| 157 | cwd=options.devtools_dir, |
| 158 | text=True).strip() |
| 159 | |
| 160 | |
Liviu Rau | 88c99fa | 2024-07-10 14:14:15 | [diff] [blame] | 161 | def update_deps_revision(options): |
| 162 | print('updating DEPS revision') |
| 163 | old_revision = subprocess.check_output( |
| 164 | ['gclient', 'getdep', '--var=chromium_browser_protocol_revision'], |
| 165 | cwd=options.devtools_dir, |
| 166 | text=True).strip() |
| 167 | new_revision = subprocess.check_output( |
| 168 | ['git', 'log', '-1', '--pretty=format:%H'], |
| 169 | cwd=options.chromium_dir, |
| 170 | text=True).strip() |
| 171 | subprocess.check_call( |
| 172 | [ |
| 173 | 'gclient', 'setdep', |
| 174 | f'--var=chromium_browser_protocol_revision={new_revision}' |
| 175 | ], |
| 176 | cwd=options.devtools_dir, |
| 177 | ) |
| 178 | if options.output: |
| 179 | with open(options.output, 'w', encoding='utf-8') as f: |
| 180 | json.dump( |
| 181 | { |
| 182 | 'old_revision': old_revision, |
| 183 | 'new_revision': new_revision |
| 184 | }, f) |
| 185 | |
| 186 | |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 187 | if __name__ == '__main__': |
| 188 | OPTIONS = parse_options(sys.argv[1:]) |
keno | deacf6f | 2023-01-30 08:16:29 | [diff] [blame] | 189 | if OPTIONS.ref == ReferenceMode.Tot: |
| 190 | update(OPTIONS) |
Simon Zünd | a92b0bb | 2024-08-09 08:57:58 | [diff] [blame] | 191 | elif OPTIONS.update_node: |
Liviu Rau | b3870c1 | 2024-01-08 11:42:42 | [diff] [blame] | 192 | sync_node(OPTIONS) |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 193 | copy_files(OPTIONS) |
Johan Bay | 8d8c684 | 2022-02-02 17:44:23 | [diff] [blame] | 194 | generate_signatures(OPTIONS) |
Ergun Erdogmus | 97a5ea3 | 2024-01-30 13:55:28 | [diff] [blame] | 195 | generate_protocol_resources(OPTIONS) |
Liviu Rau | 75dccf1 | 2024-07-24 11:59:44 | [diff] [blame] | 196 | if files_changed(OPTIONS): |
| 197 | run_git_cl_format(OPTIONS) |
| 198 | run_eslint(OPTIONS) |
| 199 | update_deps_revision(OPTIONS) |