blob: 94d35f1df90dc3143ec91d0d16360f21af002ebd [file] [log] [blame]
Liviu Raub9d36162022-03-15 10:18:141#!/usr/bin/env vpython3
Mathias Bynens8555df02020-04-27 14:19:062#
Yang Guo4fd355c2019-09-19 08:59:033# 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"""
7Update manually maintained dependencies from Chromium.
8"""
9
10import argparse
kenodeacf6f2023-01-30 08:16:2911import enum
Liviu Rau88c99fa2024-07-10 14:14:1512import json
Yang Guo4fd355c2019-09-19 08:59:0313import os
14import shutil
Yang Guofa871b62019-10-24 14:04:4615import subprocess
Yang Guo4fd355c2019-09-19 08:59:0316import sys
17
Johan Bay8d8c6842022-02-02 17:44:2318
19def node_path(options):
20 try:
21 old_sys_path = sys.path[:]
22 sys.path.append(
Liviu Raubd81a052024-06-04 12:50:3423 os.path.join(options.devtools_dir, 'third_party', 'node'))
Johan Bay8d8c6842022-02-02 17:44:2324 import node
25 finally:
26 sys.path = old_sys_path
27 return node.GetBinaryPath()
28
Liviu Rau18f24e02024-02-15 11:11:0829
Mathias Bynens4ceefeb2020-07-24 10:04:4930# Files whose location within devtools-frontend matches the upstream location.
Yang Guo4fd355c2019-09-19 08:59:0331FILES = [
Mathias Bynens4ceefeb2020-07-24 10:04:4932 '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 Chivukula4cea9252023-02-02 09:09:4336 'third_party/blink/renderer/core/frame/deprecation/deprecation.json5',
Yang Guo4fd355c2019-09-19 08:59:0337]
38
Mathias Bynens4ceefeb2020-07-24 10:04:4939# Files whose location within devtools-frontend differs from the upstream location.
40FILE_MAPPINGS = {
41 # chromium_path => devtools_frontend_path
Ilya Shermana46c0482020-08-18 22:38:3942 'components/variations/proto/devtools/client_variations.js':
43 'front_end/third_party/chromium/client-variations/ClientVariations.js',
Tim van der Lippeab0853c2020-09-11 13:34:3144 '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 Bynens4ceefeb2020-07-24 10:04:4949}
50
51for f in FILES:
52 FILE_MAPPINGS[f] = f
53
Yang Guo4fd355c2019-09-19 08:59:0354
kenodeacf6f2023-01-30 08:16:2955class ReferenceMode(enum.Enum):
56 Tot = 'tot'
57 WorkingTree = 'working-tree'
58
59 def __str__(self):
60 return self.value
61
62
Yang Guo4fd355c2019-09-19 08:59:0363def parse_options(cli_args):
Liviu Rau18f24e02024-02-15 11:11:0864 parser = argparse.ArgumentParser(
65 description='Roll dependencies from Chromium.')
kenodeacf6f2023-01-30 08:16:2966 parser.add_argument(
67 '--ref',
68 type=ReferenceMode,
69 choices=list(ReferenceMode),
Lingqi Chi15da3fb2023-10-12 07:50:5870 default=ReferenceMode.Tot,
kenodeacf6f2023-01-30 08:16:2971 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 Raub3870c12024-01-08 11:42:4274 parser.add_argument('--update-node',
Liviu Raud5933e52024-01-09 09:21:0475 action="store_true",
76 default=False,
Liviu Raub3870c12024-01-08 11:42:4277 help='If set it syncs nodejs.')
Liviu Rau88c99fa2024-07-10 14:14:1578 parser.add_argument(
79 '--output',
80 default=None,
81 help=
82 'If set it outputs information about the roll in the specified file.')
Mathias Bynens4ceefeb2020-07-24 10:04:4983 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 Guo4fd355c2019-09-19 08:59:0386 return parser.parse_args(cli_args)
87
Liviu Rau18f24e02024-02-15 11:11:0888
Yang Guofa871b62019-10-24 14:04:4689def update(options):
90 subprocess.check_call(['git', 'fetch', 'origin'], cwd=options.chromium_dir)
Alex Rudenko7d12c022021-04-07 06:11:1091 subprocess.check_call(['git', 'checkout', 'origin/main'],
92 cwd=options.chromium_dir)
Yang Guofa871b62019-10-24 14:04:4693 subprocess.check_call(['gclient', 'sync'], cwd=options.chromium_dir)
Yang Guo4fd355c2019-09-19 08:59:0394
Liviu Raub3870c12024-01-08 11:42:4295
Liviu Raub3870c12024-01-08 11:42:4296def sync_node(options):
Simon Zünda92b0bb2024-08-09 08:57:5897 """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 Raub3870c12024-01-08 11:42:42100
Liviu Rau18f24e02024-02-15 11:11:08101
Yang Guo4fd355c2019-09-19 08:59:03102def copy_files(options):
Mathias Bynens4ceefeb2020-07-24 10:04:49103 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 Guo4fd355c2019-09-19 08:59:03109
110
Johan Bay8d8c6842022-02-02 17:44:23111def generate_signatures(options):
Liviu Raubd81a052024-06-04 12:50:34112 print('generating JavaScript native functions signatures from .idl '
113 'and typescript definitions')
Johan Bay8d8c6842022-02-02 17:44:23114 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 Erdogmus97a5ea32024-01-30 13:55:28121def generate_protocol_resources(options):
122 print('generating protocol resources')
123 subprocess.check_call([
124 os.path.join(options.devtools_dir, 'scripts', 'deps',
Ergun Erdogmusf9e40332024-02-07 15:16:28125 'generate_protocol_resources.py'), '--node-path',
126 node_path(options)
Ergun Erdogmus97a5ea32024-01-30 13:55:28127 ],
128 cwd=options.devtools_dir)
129
130
131def run_git_cl_format(options):
132 print('running `git cl format` to format generated TS files')
Simon Zündcc994132024-02-15 07:34:44133 subprocess.check_call(['git', 'cl', 'format', '--js', '--full'],
134 cwd=options.devtools_dir)
Ergun Erdogmus97a5ea32024-01-30 13:55:28135
136
137def 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 Vitkov19958d52025-04-13 21:18:18147 node_path(options), "--experimental-strip-types",
148 "--no-warnings=ExperimentalWarning",
Ergun Erdogmus97a5ea32024-01-30 13:55:28149 os.path.join(options.devtools_dir, 'scripts', 'test',
Nikolay Vitkov2a1b3b32025-01-03 10:18:46150 'run_lint_check.mjs')
Ergun Erdogmus97a5ea32024-01-30 13:55:28151 ] + generated_source_files,
152 cwd=options.devtools_dir)
153
Liviu Rau18f24e02024-02-15 11:11:08154
Liviu Rau75dccf12024-07-24 11:59:44155def files_changed(options):
156 return subprocess.check_output(['git', 'diff', '--name-only'],
157 cwd=options.devtools_dir,
158 text=True).strip()
159
160
Liviu Rau88c99fa2024-07-10 14:14:15161def 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 Guo4fd355c2019-09-19 08:59:03187if __name__ == '__main__':
188 OPTIONS = parse_options(sys.argv[1:])
kenodeacf6f2023-01-30 08:16:29189 if OPTIONS.ref == ReferenceMode.Tot:
190 update(OPTIONS)
Simon Zünda92b0bb2024-08-09 08:57:58191 elif OPTIONS.update_node:
Liviu Raub3870c12024-01-08 11:42:42192 sync_node(OPTIONS)
Yang Guo4fd355c2019-09-19 08:59:03193 copy_files(OPTIONS)
Johan Bay8d8c6842022-02-02 17:44:23194 generate_signatures(OPTIONS)
Ergun Erdogmus97a5ea32024-01-30 13:55:28195 generate_protocol_resources(OPTIONS)
Liviu Rau75dccf12024-07-24 11:59:44196 if files_changed(OPTIONS):
197 run_git_cl_format(OPTIONS)
198 run_eslint(OPTIONS)
199 update_deps_revision(OPTIONS)