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

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

Issue 1765013002: Handle case of deleted mojom file in Dart bindings presubmit script (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 def presubmit_check(packages, affected_files): 303 def presubmit_check(packages, affected_files):
304 mojoms = filter_paths(affected_files, is_mojom) 304 mojoms = filter_paths(affected_files, is_mojom)
305 mojom_darts = filter_paths(affected_files, is_mojom_dart) 305 mojom_darts = filter_paths(affected_files, is_mojom_dart)
306 306
307 if check_for_bindings_machinery_changes(affected_files): 307 if check_for_bindings_machinery_changes(affected_files):
308 # Bindings machinery changed, perform global check instead. 308 # Bindings machinery changed, perform global check instead.
309 latest_mtime = bindings_machinery_latest_mtime(affected_files) 309 latest_mtime = bindings_machinery_latest_mtime(affected_files)
310 return global_check(packages, latest_mtime) 310 return global_check(packages, latest_mtime)
311 311
312 updated_mojom_dart_files = [] 312 updated_mojom_dart_files = []
313 deleted_mojom_files = []
314 deleted_mojom_dart_files = []
313 packages_with_failures = [] 315 packages_with_failures = []
314 check_failure = False 316 check_failure = False
315 317
316 # Check for updated .mojom without updated .mojom.dart 318 # Check for updated .mojom without updated .mojom.dart
317 for mojom_file in mojoms: 319 for mojom_file in mojoms:
320 if not os.path.exists(mojom_file):
321 # File no longer exists. We cannot calculate the path of the associated
322 # .mojom.dart file, skip.
323 deleted_mojom_files.append(os.path.relpath(mojom_file, start=SRC_DIR))
324 continue
325
318 try: 326 try:
319 mojom = _load_mojom(mojom_file) 327 mojom = _load_mojom(mojom_file)
320 except Exception: 328 except Exception:
321 # Could not load .mojom file 329 # Could not load .mojom file
322 print("Could not load mojom file: %s" % mojom_file) 330 print("Could not load mojom file: %s" % mojom_file)
323 return True 331 return True
324 332
325 package = _mojom_package(mojom) 333 package = _mojom_package(mojom)
326 # If a mojom doesn't have a package, ignore it. 334 # If a mojom doesn't have a package, ignore it.
327 if not package: 335 if not package:
328 continue 336 continue
329 package_dir = packages.get(package) 337 package_dir = packages.get(package)
330 # If the package isn't a known package, ignore it. 338 # If the package isn't a known package, ignore it.
331 if not package_dir: 339 if not package_dir:
332 continue 340 continue
333 # Expected output path relative to src. 341 # Expected output path relative to src.
334 mojom_dart_path = os.path.relpath( 342 mojom_dart_path = os.path.relpath(
335 os.path.join(package_dir, _mojom_output_path(mojom)), start=SRC_DIR) 343 os.path.join(package_dir, _mojom_output_path(mojom)), start=SRC_DIR)
336 344
337 mojom_mtime = safe_mtime(mojom_file) 345 mojom_mtime = safe_mtime(mojom_file)
338 mojom_dart_mtime = safe_mtime(os.path.join(SRC_DIR, mojom_dart_path)) 346 mojom_dart_mtime = safe_mtime(os.path.join(SRC_DIR, mojom_dart_path))
339 347
340 if mojom_mtime > mojom_dart_mtime: 348 if mojom_mtime > mojom_dart_mtime:
341 check_failure = True 349 check_failure = True
342 print("Package %s has old %s" % (package, mojom_dart_path)) 350 if mojom_dart_mtime == 0:
351 print("Package %s is missing %s" % (package, mojom_dart_path))
352 else:
353 print("Package %s has old %s" % (package, mojom_dart_path))
343 if not (package in packages_with_failures): 354 if not (package in packages_with_failures):
344 packages_with_failures.append(package) 355 packages_with_failures.append(package)
345 continue 356 continue
357
346 # Remember that this .mojom.dart file was updated after the .mojom file. 358 # Remember that this .mojom.dart file was updated after the .mojom file.
347 # This list is used to verify that all updated .mojom.dart files were 359 # This list is used to verify that all updated .mojom.dart files were
348 # updated because their source .mojom file changed. 360 # updated because their source .mojom file changed.
349 updated_mojom_dart_files.append(mojom_dart_path) 361 updated_mojom_dart_files.append(mojom_dart_path)
350 362
351 # Check for updated .mojom.dart file without updated .mojom file. 363 # Check for updated .mojom.dart file without updated .mojom file.
352 for mojom_dart_file in mojom_darts: 364 for mojom_dart_file in mojom_darts:
353 # mojom_dart_file is not inside //mojo/dart/packages. 365 # mojom_dart_file is not inside //mojo/dart/packages.
354 if not mojom_dart_file.startswith(PACKAGES_DIR): 366 if not mojom_dart_file.startswith(PACKAGES_DIR):
355 continue 367 continue
356 368
357 # Path relative to //mojo/dart/packages/ 369 # Path relative to //mojo/dart/packages/
358 path_relative_to_packages = os.path.relpath(mojom_dart_file, 370 path_relative_to_packages = os.path.relpath(mojom_dart_file,
359 start=PACKAGES_DIR) 371 start=PACKAGES_DIR)
360 # Package name is first element of split path. 372 # Package name is first element of split path.
361 package = path_relative_to_packages.split(os.sep)[0] 373 package = path_relative_to_packages.split(os.sep)[0]
362 # Path relative to src. 374 # Path relative to src.
363 mojom_dart_path = os.path.relpath(mojom_dart_file, start=SRC_DIR) 375 mojom_dart_path = os.path.relpath(mojom_dart_file, start=SRC_DIR)
376
364 # If mojom_dart_path is not in updated_mojom_dart_files, a .mojom.dart 377 # If mojom_dart_path is not in updated_mojom_dart_files, a .mojom.dart
365 # file was updated without updating the related .mojom file. 378 # file was updated without updating the related .mojom file.
366 if not (mojom_dart_path in updated_mojom_dart_files): 379 if not (mojom_dart_path in updated_mojom_dart_files):
380 if not os.path.exists(mojom_dart_file):
381 deleted_mojom_dart_files.append(mojom_dart_path)
382 continue
367 check_failure = True 383 check_failure = True
368 print("Package %s has new %s without updating source .mojom file." % 384 print("Package %s has new %s without updating source .mojom file." %
369 (package, mojom_dart_path)) 385 (package, mojom_dart_path))
370 if not (package in packages_with_failures): 386 if not (package in packages_with_failures):
371 packages_with_failures.append(package) 387 packages_with_failures.append(package)
372 388
389 # TODO(johnmccutchan): Fuzzy detection of a deleted .mojom file without a
390 # deleted .mojom.dart file.
391
373 for package in packages_with_failures: 392 for package in packages_with_failures:
374 _print_regenerate_message(package) 393 _print_regenerate_message(package)
375 394
376 return check_failure 395 return check_failure
377 396
378 397
379 def main(): 398 def main():
380 parser = argparse.ArgumentParser(description='Generate a dart-pkg') 399 parser = argparse.ArgumentParser(description='Generate a dart-pkg')
381 parser.add_argument('--affected-files', 400 parser.add_argument('--affected-files',
382 action='store', 401 action='store',
(...skipping 16 matching lines...) Expand all
399 if args.affected_files: 418 if args.affected_files:
400 check_failure = presubmit_check(packages, args.affected_files) 419 check_failure = presubmit_check(packages, args.affected_files)
401 else: 420 else:
402 check_failure = global_check(packages) 421 check_failure = global_check(packages)
403 if check_failure: 422 if check_failure:
404 return 2 423 return 2
405 return 0 424 return 0
406 425
407 if __name__ == '__main__': 426 if __name__ == '__main__':
408 sys.exit(main()) 427 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698