delete-stale-build-files 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/python
  2. # Copyright (C) 2013 Apple Inc. All rights reserved.
  3. # Copyright (C) 2012 Google Inc. All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. #
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  16. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  19. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. import optparse
  26. import os
  27. import subprocess
  28. import sys
  29. def main():
  30. parser = optparse.OptionParser("usage: %prog [options]")
  31. parser.add_option("--platform")
  32. parser.add_option("--build-directory")
  33. parser.add_option("--debug", action="store_const", const="debug", dest="configuration")
  34. parser.add_option("--release", action="store_const", const="release", dest="configuration")
  35. options, parameters = parser.parse_args()
  36. if not options.platform:
  37. parser.error("Platform is required")
  38. return -1
  39. if not options.configuration:
  40. parser.error("Configuration is required")
  41. return -2
  42. genericPlatform = options.platform.split('-', 1)[0]
  43. if genericPlatform != 'mac':
  44. print 'Exited without removing any files.'
  45. return 0
  46. if options.build_directory:
  47. buildDirectory = options.build_directory
  48. else:
  49. buildDirectory = webkitBuildDirectory(genericPlatform, options.configuration)
  50. exit_code = 0
  51. for root, _, files in os.walk(buildDirectory):
  52. for name in files:
  53. full_path = os.path.join(root, name)
  54. ext = os.path.splitext(full_path)[1]
  55. try:
  56. if ext not in ('.o', '.d') or os.path.getsize(full_path):
  57. continue
  58. except OSError as exception:
  59. print exception
  60. continue
  61. try:
  62. os.remove(full_path)
  63. print 'Removed', full_path
  64. except OSError as exception:
  65. print exception
  66. exit_code += 1
  67. return exit_code
  68. def webkitBuildDirectory(platform, configuration):
  69. return subprocess.Popen(['perl', os.path.join(os.path.dirname(__file__), "..", "Scripts", "webkit-build-directory"),
  70. "--" + platform, "--" + configuration, '--top-level'], stdout=subprocess.PIPE).communicate()[0].strip()
  71. if __name__ == '__main__':
  72. sys.exit(main())