Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
idlsync.py
Go to the documentation of this file.
1# Upgrading Dart's SDK for HTML (blink IDLs).
2#
3# Typically this is done using the Dart WebCore branch (as it has to be
4# staged to get most things working).
5#
6# Enlist in third_party/WebCore:
7# > cd src/dart/third_party
8# > rm -rf WebCore (NOTE: Normally detached head using gclient sync)
9# > git clone https://github.com/dart-lang/webcore.git WebCore
10#
11# To update all *.idl, *.py, LICENSE files, and IDLExtendedAttributes.txt:
12# > cd sdk
13# > python3 tools/dom/scripts/idlsync.py
14#
15# Display blink files to delete, copy, update, and collisions to review:
16# > python3 tools/dom/scripts/idlsync.py --check
17#
18# Bring over all blink files to dart/third_party/WebCore (*.py, *.idl, and
19# IDLExtendedAttributes.txt):
20# > python3 tools/dom/scripts/idlsync.py
21#
22# Update the DEPS file SHA for "WebCore_rev" with the committed changes of files
23# in WebCore e.g., "WebCore_rev": "@NNNNNNNNNNNNNNNNNNNNNNNNN"
24#
25# Generate the sdk/*.dart files from the new IDLs and PYTHON IDL parsing code
26# copied to in dart/third_party/WebCore from src/third_party/WebKit (blink).
27#
28# > cd src/dart/tools/dom/script
29# > ./go.sh
30#
31# Finally, commit the files in dart/third_party/WebCore.
32
33import errno
34import optparse
35import os.path
36import re
37import requests
38import subprocess
39import sys
40import time
41
42from shutil import copyfile
43
44# Dart DEPS file checked into the dart-lang/sdk master.
45DEPS_GIT = "https://raw.githubusercontent.com/dart-lang/sdk/master/DEPS"
46CHROME_TRUNK = "https://chromium.googlesource.com"
47WEBKIT_SHA_PATTERN = r'"WebCore_rev": "(\S+)",'
48
49# Chromium remote (GIT repository)
50GIT_REMOTES_CHROMIUM = 'https://chromium.googlesource.com/chromium/src.git'
51
52# location of this file
53SOURCE_FILE_DIR = 'tools/dom/scripts'
54
55WEBKIT_SOURCE = 'src/third_party/WebKit/Source'
56WEBCORE_SOURCE = 'third_party/WebCore'
57
58WEBKIT_BLINK_SOURCE = 'src/third_party/blink'
59WEBCORE_BLINK_SOURCE = 'third_party/WebCore/blink'
60
61# Never automatically git add bindings/IDLExtendedAttributes.txt this file has
62# been modified by Dart but is usually changed by WebKit blink too.
63IDL_EXTENDED_ATTRIBUTES_FILE = 'IDLExtendedAttributes.txt'
64
65# Don't automatically update, delete or add anything in this directory:
66# bindings/dart/scripts
67# The scripts in the above directory is the source for our Dart generators that
68# is driven from the blink IDL parser AST
69DART_SDK_GENERATOR_SCRIPTS = 'bindings/dart/scripts'
70
71# The __init__.py files allow Python to treat directories as packages. Used to
72# allow Dart's Python scripts to interact with Chrome's IDL parsing scripts.
73PYTHON_INITS = '__init__.py'
74
75# sub directories containing IDLs (core and modules) from the base directory
76# src/third_party/WebKit/Source
77SUBDIRS = [
78 'bindings',
79 'core',
80 'modules',
81]
82IDL_EXT = '.idl'
83PY_EXT = '.py'
84LICENSE_FILE_PREFIX = 'LICENSE' # e.g., LICENSE-APPLE, etc.
85
86# Look in any file in WebCore we copy from WebKit if this comment is in the file
87# then flag this as a special .py or .idl file that needs to be looked at.
88DART_CHANGES = ' FIXMEDART: '
89
90# application options passed in.
91options = None
92
93warning_messages = []
94
95
96# Is --dry_run passed in.
98 global options
99 return options['dry_run'] is not None
100
101
102# Is --verbose passed in.
104 global options
105 return options['verbose'] is not None
106
107
108# If --WebKit= is specified then compute the directory of the Chromium
109# source.
111 global options
112 if options['chromium_dir'] is not None:
113 return os.path.expanduser(options['chromium_dir'])
114 return os.cwd()
115
116
117def RunCommand(cmd, valid_exits=[0]):
118 """Executes a shell command and return its stdout."""
119 if isVerbose():
120 print(' '.join(cmd))
121 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
122 output = pipe.communicate()
123 if pipe.returncode in valid_exits:
124 return output[0]
125 else:
126 print(output[1])
127 print('FAILED. RET_CODE=%d' % pipe.returncode)
128 sys.exit(pipe.returncode)
129
130
131# returns True if // FIXMEDART: is in the file.
132def anyDartFixMe(filepath):
133 if os.path.exists(filepath):
134 data = open(filepath, 'r').read()
135 return data.find(DART_CHANGES) != -1
136 else:
137 return False
138
139
140# Give a base_dir compute the trailing directory after base_dir
141# returns the subpath from base_dir for the path passed in.
142def subpath(path, base_dir):
143 dir_portion = ''
144 head = path
145 while True:
146 head, tail = os.path.split(head)
147 dir_portion = os.path.join(tail, dir_portion)
148 if head == base_dir or tail == '':
149 break
150 return dir_portion
151
152
153# Copy any file in source_dir (WebKit) to destination_dir (dart/third_party/WebCore)
154# source_dir is the src/third_party/WebKit/Source location (blink)
155# destination_dir is the src/dart/third_party/WebCore location
156# returns idls_copied, py_copied, other_copied
157def copy_files(source_dir, src_prefix, destination_dir):
158 original_cwd = os.getcwd()
159 try:
160 os.makedirs(destination_dir)
161 except OSError as e:
162 if e.errno != errno.EEXIST:
163 raise
164 os.chdir(destination_dir)
165
166 idls = 0 # *.idl files copied
167 pys = 0 # *.py files copied
168 others = 0 # all other files copied
169
170 for (root, _, files) in os.walk(source_dir, topdown=False):
171 dir_portion = subpath(root, source_dir)
172 for f in files:
173 # Never automatically add any Dart generator scripts (these are the original
174 # sources in WebCore) from WebKit to WebCore.
175 if dir_portion != DART_SDK_GENERATOR_SCRIPTS:
176 if (f.endswith(IDL_EXT) or f == IDL_EXTENDED_ATTRIBUTES_FILE or
177 f.endswith(PY_EXT) or
178 f.startswith(LICENSE_FILE_PREFIX)):
179 if f.endswith(IDL_EXT):
180 idls += 1
181 elif f.endswith(PY_EXT):
182 pys += 1
183 else:
184 others += 1
185 src_file = os.path.join(root, f)
186
187 # Compute the destination path using sdk/third_party/WebCore
188 subdir_root = src_file[src_file.rfind(src_prefix) +
189 len(src_prefix):]
190 if subdir_root.startswith(os.path.sep):
191 subdir_root = subdir_root[1:]
192 dst_file = os.path.join(destination_dir, subdir_root)
193
194 # Need to make src/third_party/WebKit/Source/* to sdk/third_party/WebCore/*
195
196 destination = os.path.dirname(dst_file)
197 if not os.path.exists(destination):
198 os.makedirs(destination)
199
200 has_Dart_fix_me = anyDartFixMe(dst_file)
201
202 if not isDryRun():
203 copyfile(src_file, dst_file)
204 if isVerbose():
205 #print('...copying %s' % os.path.split(dst_file)[1])
206 print('...copying %s' % dst_file)
207 if f == IDL_EXTENDED_ATTRIBUTES_FILE:
208 warning_messages.append(dst_file)
209 else:
210 if has_Dart_fix_me:
211 warning_messages.append(dst_file)
212 if not (isDryRun() or has_Dart_fix_me):
213 # git add the file
214 RunCommand(['git', 'add', dst_file])
215
216 os.chdir(original_cwd)
217
218 return [idls, pys, others]
219
220
221# Remove any file in webcore_dir that no longer exist in the webkit_dir
222# webcore_dir src/dart/third_party/WebCore location
223# webkit_dir src/third_party/WebKit/Source location (blink)
224# only check if the subdir off from webcore_dir
225# return list of files deleted
226def remove_obsolete_webcore_files(webcore_dir, webkit_dir, subdir):
227 files_to_delete = []
228
229 original_cwd = os.getcwd()
230
231 if os.path.exists(webcore_dir):
232 os.chdir(webcore_dir)
233
234 for (root, _, files) in os.walk(
235 os.path.join(webcore_dir, subdir), topdown=False):
236 dir_portion = subpath(root, webcore_dir)
237 for f in files:
238 # Never automatically deleted any Dart generator scripts (these are the
239 # original sources in WebCore).
240 if dir_portion != DART_SDK_GENERATOR_SCRIPTS:
241 check_file = os.path.join(dir_portion, f)
242 check_file_full_path = os.path.join(webkit_dir, check_file)
243 if not os.path.exists(check_file_full_path) and \
244 not(check_file_full_path.endswith(PYTHON_INITS)):
245 if not isDryRun():
246 # Remove the file using git
247 RunCommand(['git', 'rm', check_file])
248 files_to_delete.append(check_file)
249
250 os.chdir(original_cwd)
251
252 return files_to_delete
253
254
256 parser = optparse.OptionParser()
257 parser.add_option(
258 '--chromium',
259 '-c',
260 dest='chromium_dir',
261 action='store',
262 type='string',
263 help='WebKit Chrome directory (e.g., --chromium=~/chrome63',
264 default=None)
265 parser.add_option(
266 '--verbose',
267 '-v',
268 dest='verbose',
269 action='store_true',
270 help='Dump all information',
271 default=None)
272 parser.add_option(
273 '--dry_run',
274 '-d',
275 dest='dry_run',
276 action='store_true',
277 help='Display results without adding, updating or deleting any files',
278 default=None)
279 args, _ = parser.parse_args()
280
281 argOptions = {}
282 argOptions['chromium_dir'] = args.chromium_dir
283 argOptions['verbose'] = args.verbose
284 argOptions['dry_run'] = args.dry_run
285 return argOptions
286
287
288# Fetch the DEPS file in src/dart/tools/deps/dartium.deps/DEPS from the GIT repro.
290 req = requests.get(DEPS_GIT)
291 return req.text
292
293
295 #origin https://chromium.googlesource.com/dart/dartium/src.git (fetch)
296 remotes_list = RunCommand(['git', 'remote', '--verbose']).split()
297 if (len(remotes_list) > 2 and remotes_list[0] == 'origin' and
298 remotes_list[1] == GIT_REMOTES_CHROMIUM):
299 return True
300
301 print('ERROR: Unable to find dart/dartium/src repository %s' %
302 GIT_REMOTES_CHROMIUM)
303 return False
304
305
307 cwd = os.getcwd()
308 chromiumDir = chromiumDirectory()
309
310 webkit_dir = os.path.join(chromiumDir, WEBKIT_SOURCE)
311 os.chdir(webkit_dir)
312
314 chromium_sha = RunCommand(['git', 'log', '--format=format:%H', '-1'])
315 else:
316 chromium_sha = -1
317
318 os.chdir(cwd)
319 return chromium_sha
320
321
323 cwd = os.getcwd()
324
325 if cwd.endswith('dart'):
326 # In src/dart
327 src_dir, _ = os.path.split(cwd)
328 elif cwd.endswith('sdk'):
329 src_dir = cwd
330 else:
331 src_dir = os.path.join(cwd, 'sdk')
332 os.chdir(src_dir)
333
335 dart_sha = RunCommand(['git', 'log', '--format=format:%H', '-1'])
336 else:
337 dart_sha = -1
338
339 os.chdir(cwd)
340 return dart_sha
341
342
343# Returns the SHA of the Dartium/Chromium in the DEPS file.
344def GetDEPSWebCoreGitRevision(deps, component):
345 """Returns a tuple with the (dartium chromium repo, latest revision)."""
346 foundIt = re.search(WEBKIT_SHA_PATTERN, deps)
347 #url_base, url_pattern = DEPS_PATTERNS[component]
348 #url = url_base + re.search(url_pattern, deps).group(1)
349 # Get the SHA for the Chromium/WebKit changes for Dartium.
350 #revision = url[len(url_base):]
351 revision = foundIt.group(1)[1:]
352 print('%s' % revision)
353 return revision
354
355
356def copy_subdir(src, src_prefix, dest, subdir):
357 idls_deleted = remove_obsolete_webcore_files(dest, src, subdir)
358 print("%s files removed in WebCore %s" % (idls_deleted.__len__(), subdir))
359 if isVerbose():
360 for delete_file in idls_deleted:
361 print(" %s" % delete_file)
362
363 idls_copied, py_copied, other_copied = copy_files(
364 os.path.join(src, subdir), src_prefix, dest)
365 if idls_copied > 0:
366 print("Copied %s IDLs to %s" % (idls_copied, subdir))
367 if py_copied > 0:
368 print("Copied %s PYs to %s" % (py_copied, subdir))
369 if other_copied > 0:
370 print("Copied %s other to %s\n" % (other_copied, subdir))
371
372
373def main():
374 global options
375 options = ParseOptions()
376
377 current_dir = os.path.dirname(os.path.abspath(__file__))
378 if not current_dir.endswith(SOURCE_FILE_DIR):
379 print('ERROR: idlsync.py not run in proper directory (%s)\n',
380 current_dir)
381
382 base_directory = current_dir[:current_dir.rfind(SOURCE_FILE_DIR)]
383
384 # Validate DEPS WebCore_rev SHA DOES NOT match the SHA of chromium master.
385 deps = GetDepsFromGit()
386 webcore_revision = GetDEPSWebCoreGitRevision(deps, 'webkit')
387 chromium_sha = getChromiumSHA()
388 if webcore_revision == chromium_sha:
389 print("ERROR: Nothing to update in WebCore, WebCore_rev SHA in DEPS "
390 "matches Chromium GIT master SHA in %s" % options['webkit_dir'])
391 return
392
393 start_time = time.time()
394
395 # Copy scripts from third_party/blink/tools to third_party/WebCore/blink/tools
396 #
397 # This also implies that the files:
398 # WebCore/bindings/scripts/code_generator_web_agent_api.py
399 # WebCore/bindings/scripts/utilities.py
400 #
401 # Need to have sys.path.append at beginning of the above files changed from:
402 #
403 # sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..',
404 # 'third_party', 'blink', 'tools'))
405 # to
406 #
407 # sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..',
408 # 'blink', 'tools'))
409 #
410 webkit_blink_dir = os.path.join(chromiumDirectory(), WEBKIT_BLINK_SOURCE)
411 webcore_blink_dir = os.path.join(base_directory, WEBCORE_BLINK_SOURCE)
412 copy_subdir(webkit_blink_dir, WEBKIT_BLINK_SOURCE, webcore_blink_dir, "")
413
414 chromium_webkit_dir = os.path.join(chromiumDirectory(), WEBKIT_SOURCE)
415 dart_webcore_dir = os.path.join(base_directory, WEBCORE_SOURCE)
416 for subdir in SUBDIRS:
417 copy_subdir(chromium_webkit_dir, WEBKIT_SOURCE, dart_webcore_dir,
418 subdir)
419
420 end_time = time.time()
421
422 print(
423 'WARNING: File(s) contain FIXMEDART and are NOT "git add " please review:'
424 )
425 for warning in warning_messages:
426 print(' %s' % warning)
427
428 print('\nDone idlsync completed in %s seconds' %
429 round(end_time - start_time, 2))
430
431
432if __name__ == '__main__':
433 sys.exit(main())
static void round(SkPoint *p)
static bool read(SkStream *stream, void *buffer, size_t amount)
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1
subpath(path, base_dir)
Definition idlsync.py:142
RunCommand(cmd, valid_exits=[0])
Definition idlsync.py:117
anyDartFixMe(filepath)
Definition idlsync.py:132
GetDEPSWebCoreGitRevision(deps, component)
Definition idlsync.py:344
copy_subdir(src, src_prefix, dest, subdir)
Definition idlsync.py:356
remove_obsolete_webcore_files(webcore_dir, webkit_dir, subdir)
Definition idlsync.py:226
copy_files(source_dir, src_prefix, destination_dir)
Definition idlsync.py:157