OLD | NEW |
---|---|
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 | 243 |
244 | 244 |
245 def is_mojom_dart(path): | 245 def is_mojom_dart(path): |
246 return path.endswith('.mojom.dart') | 246 return path.endswith('.mojom.dart') |
247 | 247 |
248 | 248 |
249 def is_mojom(path): | 249 def is_mojom(path): |
250 return path.endswith('.mojom') | 250 return path.endswith('.mojom') |
251 | 251 |
252 | 252 |
253 def is_generator_file(path): | |
254 return path.find('mojom_dart_generator.py') != -1 or \ | |
255 (path.find('dart_templates') != -1 and path.endswith('.tmpl')) | |
256 | |
257 | |
253 def filter_paths(paths, path_filter): | 258 def filter_paths(paths, path_filter): |
254 result = [] | 259 result = [] |
255 for path in paths: | 260 for path in paths: |
256 path = os.path.abspath(os.path.join(SRC_DIR, path)) | 261 path = os.path.abspath(os.path.join(SRC_DIR, path)) |
257 if path_filter(path): | 262 if path_filter(path): |
258 result.append(path) | 263 result.append(path) |
259 return result | 264 return result |
260 | 265 |
261 | 266 |
262 def safe_mtime(path): | 267 def safe_mtime(path): |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 path = os.path.join(SRC_DIR, filename) | 304 path = os.path.join(SRC_DIR, filename) |
300 mtime = safe_mtime(path) | 305 mtime = safe_mtime(path) |
301 if mtime > latest_mtime: | 306 if mtime > latest_mtime: |
302 latest_mtime = mtime | 307 latest_mtime = mtime |
303 return latest_mtime | 308 return latest_mtime |
304 | 309 |
305 | 310 |
306 def presubmit_check(packages, affected_files): | 311 def presubmit_check(packages, affected_files): |
307 mojoms = filter_paths(affected_files, is_mojom) | 312 mojoms = filter_paths(affected_files, is_mojom) |
308 mojom_darts = filter_paths(affected_files, is_mojom_dart) | 313 mojom_darts = filter_paths(affected_files, is_mojom_dart) |
314 generator_files = filter_paths(affected_files, is_generator_file) | |
309 | 315 |
310 if check_for_bindings_machinery_changes(affected_files): | 316 if check_for_bindings_machinery_changes(affected_files): |
zra
2015/11/24 17:34:44
Is the new code below still needed after this chec
alexfandrianto
2015/12/18 01:53:19
Not using this anymore.
| |
311 # Bindings machinery changed, perform global check instead. | 317 # Bindings machinery changed, perform global check instead. |
312 latest_mtime = bindings_machinery_latest_mtime(affected_files) | 318 latest_mtime = bindings_machinery_latest_mtime(affected_files) |
313 return global_check(packages, latest_mtime) | 319 return global_check(packages, latest_mtime) |
314 | 320 |
315 updated_mojom_dart_files = [] | 321 updated_mojom_dart_files = [] |
316 packages_with_failures = [] | 322 packages_with_failures = [] |
317 check_failure = False | 323 check_failure = False |
318 | 324 |
319 # Check for updated .mojom without updated .mojom.dart | 325 # Check for updated .mojom without updated .mojom.dart |
320 for mojom_file in mojoms: | 326 for mojom_file in mojoms: |
(...skipping 23 matching lines...) Expand all Loading... | |
344 print("Package %s has old %s" % (package, mojom_dart_path)) | 350 print("Package %s has old %s" % (package, mojom_dart_path)) |
345 if not (package in packages_with_failures): | 351 if not (package in packages_with_failures): |
346 packages_with_failures.append(package) | 352 packages_with_failures.append(package) |
347 continue | 353 continue |
348 # Remember that this .mojom.dart file was updated after the .mojom file. | 354 # Remember that this .mojom.dart file was updated after the .mojom file. |
349 # This list is used to verify that all updated .mojom.dart files were | 355 # This list is used to verify that all updated .mojom.dart files were |
350 # updated because their source .mojom file changed. | 356 # updated because their source .mojom file changed. |
351 updated_mojom_dart_files.append(mojom_dart_path) | 357 updated_mojom_dart_files.append(mojom_dart_path) |
352 | 358 |
353 # Check for updated .mojom.dart file without updated .mojom file. | 359 # Check for updated .mojom.dart file without updated .mojom file. |
354 for mojom_dart_file in mojom_darts: | 360 # If the Python generator or dart template files changed, skip this check. |
zra
2015/11/24 17:34:44
Is this case not already covered by the check_for_
alexfandrianto
2015/12/18 01:53:19
Not using this anymore.
| |
355 # mojom_dart_file is not inside //mojo/dart/packages. | 361 if len(generator_files) == 0: |
356 if not mojom_dart_file.startswith(PACKAGES_DIR): | 362 for mojom_dart_file in mojom_darts: |
357 continue | 363 # mojom_dart_file is not inside //mojo/dart/packages. |
364 if not mojom_dart_file.startswith(PACKAGES_DIR): | |
365 continue | |
358 | 366 |
359 # Path relative to //mojo/dart/packages/ | 367 # Path relative to //mojo/dart/packages/ |
360 path_relative_to_packages = os.path.relpath(mojom_dart_file, | 368 path_relative_to_packages = os.path.relpath(mojom_dart_file, |
361 start=PACKAGES_DIR) | 369 start=PACKAGES_DIR) |
362 # Package name is first element of split path. | 370 # Package name is first element of split path. |
363 package = path_relative_to_packages.split(os.sep)[0] | 371 package = path_relative_to_packages.split(os.sep)[0] |
364 # Path relative to src. | 372 # Path relative to src. |
365 mojom_dart_path = os.path.relpath(mojom_dart_file, start=SRC_DIR) | 373 mojom_dart_path = os.path.relpath(mojom_dart_file, start=SRC_DIR) |
366 # If mojom_dart_path is not in updated_mojom_dart_files, a .mojom.dart | 374 # If mojom_dart_path is not in updated_mojom_dart_files, a .mojom.dart |
367 # file was updated without updating the related .mojom file. | 375 # file was updated without updating the related .mojom file. |
368 if not (mojom_dart_path in updated_mojom_dart_files): | 376 if not (mojom_dart_path in updated_mojom_dart_files): |
369 check_failure = True | 377 check_failure = True |
370 print("Package %s has new %s without updating source .mojom file." % | 378 print("Package %s has new %s without updating source .mojom file." % |
371 (package, mojom_dart_path)) | 379 (package, mojom_dart_path)) |
372 if not (package in packages_with_failures): | 380 if not (package in packages_with_failures): |
373 packages_with_failures.append(package) | 381 packages_with_failures.append(package) |
374 | 382 |
375 for package in packages_with_failures: | 383 for package in packages_with_failures: |
376 _print_regenerate_message(package) | 384 _print_regenerate_message(package) |
377 | 385 |
378 return check_failure | 386 return check_failure |
379 | 387 |
380 | 388 |
381 def main(): | 389 def main(): |
382 parser = argparse.ArgumentParser(description='Generate a dart-pkg') | 390 parser = argparse.ArgumentParser(description='Generate a dart-pkg') |
383 parser.add_argument('--affected-files', | 391 parser.add_argument('--affected-files', |
(...skipping 17 matching lines...) Expand all Loading... | |
401 if args.affected_files: | 409 if args.affected_files: |
402 check_failure = presubmit_check(packages, args.affected_files) | 410 check_failure = presubmit_check(packages, args.affected_files) |
403 else: | 411 else: |
404 check_failure = global_check(packages) | 412 check_failure = global_check(packages) |
405 if check_failure: | 413 if check_failure: |
406 return 2 | 414 return 2 |
407 return 0 | 415 return 0 |
408 | 416 |
409 if __name__ == '__main__': | 417 if __name__ == '__main__': |
410 sys.exit(main()) | 418 sys.exit(main()) |
OLD | NEW |