Hans Wennborg | 4fdb194 | 2022-06-17 17:40:10 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Avi Drissman | 73a09d1 | 2022-09-08 20:33:38 | [diff] [blame] | 2 | # Copyright 2022 The Chromium Authors |
Hans Wennborg | 4fdb194 | 2022-06-17 17:40:10 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
Hans Wennborg | 68f3f6d | 2022-09-06 14:46:07 | [diff] [blame] | 5 | """Delete .ninja_deps if it references files inside a libc++ dir which has |
| 6 | since been reverted back to a file, and would cause Ninja fail on Windows. See |
| 7 | crbug.com/1337238""" |
Hans Wennborg | 4fdb194 | 2022-06-17 17:40:10 | [diff] [blame] | 8 | |
| 9 | import os |
| 10 | import sys |
| 11 | |
| 12 | |
| 13 | def main(): |
| 14 | os.chdir(os.path.join(os.path.dirname(__file__), '..')) |
| 15 | |
Hans Wennborg | 68f3f6d | 2022-09-06 14:46:07 | [diff] [blame] | 16 | # Paths that have switched between being a directory and regular file. |
| 17 | bad_dirs = [ |
| 18 | 'buildtools/third_party/libc++/trunk/include/__string', |
| 19 | 'buildtools/third_party/libc++/trunk/include/__tuple', |
| 20 | ] |
Hans Wennborg | 4fdb194 | 2022-06-17 17:40:10 | [diff] [blame] | 21 | |
Hans Wennborg | 68f3f6d | 2022-09-06 14:46:07 | [diff] [blame] | 22 | for bad_dir in bad_dirs: |
| 23 | if os.path.isdir(bad_dir): |
| 24 | # If it's a dir, .ninja_deps referencing files in it is not a problem. |
Hans Wennborg | 4fdb194 | 2022-06-17 17:40:10 | [diff] [blame] | 25 | continue |
| 26 | |
Hans Wennborg | 68f3f6d | 2022-09-06 14:46:07 | [diff] [blame] | 27 | for out_dir in os.listdir('out'): |
| 28 | ninja_deps = os.path.join('out', out_dir, '.ninja_deps') |
| 29 | try: |
| 30 | if str.encode(bad_dir) + b'/' in open(ninja_deps, 'rb').read(): |
| 31 | print('Deleting', ninja_deps) |
| 32 | os.remove(ninja_deps) |
| 33 | except FileNotFoundError: |
| 34 | pass |
Hans Wennborg | 4fdb194 | 2022-06-17 17:40:10 | [diff] [blame] | 35 | |
| 36 | return 0 |
| 37 | |
| 38 | |
| 39 | if __name__ == '__main__': |
| 40 | sys.exit(main()) |