del_ninja_deps_cache.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2022 The Chromium Authors. All rights reserved.
  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 libc++'s __string dir,
  6. which has since been reverted back to a file, and would cause Ninja fail on
  7. Windows. See crbug.com/1337238 ..."""
  8. import os
  9. import sys
  10. def main():
  11. os.chdir(os.path.join(os.path.dirname(__file__), '..'))
  12. if os.path.isdir('buildtools/third_party/libc++/trunk/include/__string'):
  13. # If __string is a dir, Ninja will not fail.
  14. return 0
  15. for d in os.listdir('out'):
  16. obj_file = os.path.join(
  17. 'out', d,
  18. 'obj/buildtools/third_party/libc++/libc++/legacy_debug_handler.obj')
  19. if not os.path.exists(obj_file):
  20. # It seems we have not done a build with the libc++ roll.
  21. continue
  22. try:
  23. deps = os.path.join('out', d, '.ninja_deps')
  24. if b'__string/char_traits.h' in open(deps, 'rb').read():
  25. print('Deleting ', deps)
  26. os.remove(deps)
  27. print('Deleting ', obj_file)
  28. os.remove(obj_file)
  29. except FileNotFoundError:
  30. pass
  31. return 0
  32. if __name__ == '__main__':
  33. sys.exit(main())