1#!/usr/bin/env python3 2# Copyright 2022 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5"""Delete .ninja_deps if it references files inside a libc++ dir which has 6since been reverted back to a file, and would cause Ninja fail on Windows. See 7crbug.com/1337238""" 8 9import os 10import sys 11 12 13def main(): 14 os.chdir(os.path.join(os.path.dirname(__file__), '..')) 15 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 ] 21 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. 25 continue 26 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 35 36 return 0 37 38 39if __name__ == '__main__': 40 sys.exit(main()) 41