Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: mojo/dart/tools/presubmit/check_mojom_dart.py

Issue 1433183002: Generate Mojom Types for Dart (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Add test_included_unions to the _mojo_for_test_only package Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Checks that released mojom.dart files in the source tree are up to date""" 6 """Checks that released mojom.dart files in the source tree are up to date"""
7 7
8 import argparse 8 import argparse
9 import os 9 import os
10 import subprocess 10 import subprocess
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 231
232 232
233 def is_mojom_dart(path): 233 def is_mojom_dart(path):
234 return path.endswith('.mojom.dart') 234 return path.endswith('.mojom.dart')
235 235
236 236
237 def is_mojom(path): 237 def is_mojom(path):
238 return path.endswith('.mojom') 238 return path.endswith('.mojom')
239 239
240 240
241 def is_generator_file(path):
242 return path.find('mojom_dart_generator.py') != -1 or \
243 (path.find('dart_templates') != -1 and path.endswith('.tmpl'))
244
245
241 def filter_paths(paths, path_filter): 246 def filter_paths(paths, path_filter):
242 result = [] 247 result = []
243 for path in paths: 248 for path in paths:
244 path = os.path.abspath(os.path.join(SRC_DIR, path)) 249 path = os.path.abspath(os.path.join(SRC_DIR, path))
245 if path_filter(path): 250 if path_filter(path):
246 result.append(path) 251 result.append(path)
247 return result 252 return result
248 253
249 254
250 def safe_mtime(path): 255 def safe_mtime(path):
(...skipping 14 matching lines...) Expand all
265 # Dart generation script changed. 270 # Dart generation script changed.
266 if (filename == 271 if (filename ==
267 'mojo/public/tools/bindings/generators/mojom_dart_generator.py'): 272 'mojo/public/tools/bindings/generators/mojom_dart_generator.py'):
268 return True 273 return True
269 return False 274 return False
270 275
271 276
272 def presubmit_check(packages, affected_files): 277 def presubmit_check(packages, affected_files):
273 mojoms = filter_paths(affected_files, is_mojom) 278 mojoms = filter_paths(affected_files, is_mojom)
274 mojom_darts = filter_paths(affected_files, is_mojom_dart) 279 mojom_darts = filter_paths(affected_files, is_mojom_dart)
280 generator_files = filter_paths(affected_files, is_generator_file)
275 281
276 if (check_for_bindings_machinery_changes(affected_files) and 282 if (check_for_bindings_machinery_changes(affected_files) and
277 (len(mojom_darts) == 0)): 283 (len(mojom_darts) == 0)):
278 print('Bindings generation script or templates have changed but ' 284 print('Bindings generation script or templates have changed but '
279 'no .mojom.dart files have been regenerated.') 285 'no .mojom.dart files have been regenerated.')
280 # All packages need to be regenerated. 286 # All packages need to be regenerated.
281 for package in packages: 287 for package in packages:
282 _print_regenerate_message(package) 288 _print_regenerate_message(package)
283 return True 289 return True
284 290
285
286 updated_mojom_dart_files = [] 291 updated_mojom_dart_files = []
287 packages_with_failures = [] 292 packages_with_failures = []
288 check_failure = False 293 check_failure = False
289 294
290 # Check for updated .mojom without updated .mojom.dart 295 # Check for updated .mojom without updated .mojom.dart
291 for mojom_file in mojoms: 296 for mojom_file in mojoms:
292 try: 297 try:
293 mojom = _load_mojom(mojom_file) 298 mojom = _load_mojom(mojom_file)
294 except Exception: 299 except Exception:
295 # Could not load .mojom file 300 # Could not load .mojom file
(...skipping 19 matching lines...) Expand all
315 print("Package %s has old %s" % (package, mojom_dart_path)) 320 print("Package %s has old %s" % (package, mojom_dart_path))
316 if not (package in packages_with_failures): 321 if not (package in packages_with_failures):
317 packages_with_failures.append(package) 322 packages_with_failures.append(package)
318 continue 323 continue
319 # Remember that this .mojom.dart file was updated after the .mojom file. 324 # Remember that this .mojom.dart file was updated after the .mojom file.
320 # This list is used to verify that all updated .mojom.dart files were 325 # This list is used to verify that all updated .mojom.dart files were
321 # updated because their source .mojom file changed. 326 # updated because their source .mojom file changed.
322 updated_mojom_dart_files.append(mojom_dart_path) 327 updated_mojom_dart_files.append(mojom_dart_path)
323 328
324 # Check for updated .mojom.dart file without updated .mojom file. 329 # Check for updated .mojom.dart file without updated .mojom file.
325 for mojom_dart_file in mojom_darts: 330 # If the Python generator or dart template files changed, skip this check.
326 # mojom_dart_file is not inside //mojo/dart/packages. 331 if len(generator_files) == 0:
327 if not mojom_dart_file.startswith(PACKAGES_DIR): 332 for mojom_dart_file in mojom_darts:
328 continue 333 # mojom_dart_file is not inside //mojo/dart/packages.
334 if not mojom_dart_file.startswith(PACKAGES_DIR):
335 continue
329 336
330 # Path relative to //mojo/dart/packages/ 337 # Path relative to //mojo/dart/packages/
331 path_relative_to_packages = os.path.relpath(mojom_dart_file, 338 path_relative_to_packages = os.path.relpath(mojom_dart_file,
332 start=PACKAGES_DIR) 339 start=PACKAGES_DIR)
333 # Package name is first element of split path. 340 # Package name is first element of split path.
334 package = path_relative_to_packages.split(os.sep)[0] 341 package = path_relative_to_packages.split(os.sep)[0]
335 # Path relative to src. 342 # Path relative to src.
336 mojom_dart_path = os.path.relpath(mojom_dart_file, start=SRC_DIR) 343 mojom_dart_path = os.path.relpath(mojom_dart_file, start=SRC_DIR)
337 # If mojom_dart_path is not in updated_mojom_dart_files, a .mojom.dart 344 # If mojom_dart_path is not in updated_mojom_dart_files, a .mojom.dart
338 # file was updated without updating the related .mojom file. 345 # file was updated without updating the related .mojom file.
339 if not (mojom_dart_path in updated_mojom_dart_files): 346 if not (mojom_dart_path in updated_mojom_dart_files):
340 check_failure = True 347 check_failure = True
341 print("Package %s has new %s without updating source .mojom file." % 348 print("Package %s has new %s without updating source .mojom file." %
342 (package, mojom_dart_path)) 349 (package, mojom_dart_path))
343 if not (package in packages_with_failures): 350 if not (package in packages_with_failures):
344 packages_with_failures.append(package) 351 packages_with_failures.append(package)
345 352
346 for package in packages_with_failures: 353 for package in packages_with_failures:
347 _print_regenerate_message(package) 354 _print_regenerate_message(package)
348 355
349 return check_failure 356 return check_failure
350 357
351 358
352 def main(): 359 def main():
353 parser = argparse.ArgumentParser(description='Generate a dart-pkg') 360 parser = argparse.ArgumentParser(description='Generate a dart-pkg')
354 parser.add_argument('--affected-files', 361 parser.add_argument('--affected-files',
(...skipping 17 matching lines...) Expand all
372 if args.affected_files: 379 if args.affected_files:
373 check_failure = presubmit_check(packages, args.affected_files) 380 check_failure = presubmit_check(packages, args.affected_files)
374 else: 381 else:
375 check_failure = global_check(packages) 382 check_failure = global_check(packages)
376 if check_failure: 383 if check_failure:
377 return 2 384 return 2
378 return 0 385 return 0
379 386
380 if __name__ == '__main__': 387 if __name__ == '__main__':
381 sys.exit(main()) 388 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698