test-result-archive 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/python
  2. # Copyright (C) 2009 Apple Inc. All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. #
  8. # 1. Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. #
  14. # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  15. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  18. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. import optparse, os, shutil, subprocess, sys
  25. sourceRootDirectory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
  26. archiveFile = os.path.join(sourceRootDirectory, "layout-test-results.zip")
  27. def main():
  28. parser = optparse.OptionParser("usage: %prog [options] [action]")
  29. parser.add_option("--platform", dest="platform")
  30. parser.add_option("--debug", action="store_const", const="debug", dest="configuration")
  31. parser.add_option("--release", action="store_const", const="release", dest="configuration")
  32. options, (action, ) = parser.parse_args()
  33. if not options.platform:
  34. parser.error("Platform is required")
  35. if not options.configuration:
  36. parser.error("Configuration is required")
  37. if action not in ('archive'):
  38. parser.error("Action is required")
  39. layoutTestResultsDir = os.path.abspath(os.path.join(sourceRootDirectory, "layout-test-results"))
  40. return archiveTestResults(options.configuration, options.platform, layoutTestResultsDir)
  41. def archiveTestResults(configuration, platform, layoutTestResultsDir):
  42. assert platform in ('mac', 'win', 'wincairo', 'gtk', 'qt', 'efl')
  43. try:
  44. os.unlink(archiveFile)
  45. except OSError, e:
  46. if e.errno != 2:
  47. raise
  48. try:
  49. # Ensure that layoutTestResultsDir exists since we cannot archive a directory that does not exist
  50. os.makedirs(layoutTestResultsDir)
  51. except OSError, e:
  52. if e.errno != 17:
  53. raise
  54. open(os.path.join(layoutTestResultsDir, '.placeholder'), 'w').close()
  55. if platform == 'mac':
  56. if subprocess.call(["ditto", "-c", "-k", "--sequesterRsrc", layoutTestResultsDir, archiveFile]):
  57. return 1
  58. elif platform in ('win', 'wincairo', 'gtk', 'qt', 'efl'):
  59. if subprocess.call(["zip", "-r", archiveFile, "."], cwd=layoutTestResultsDir):
  60. return 1
  61. try:
  62. shutil.rmtree(layoutTestResultsDir)
  63. except OSError, e:
  64. # Python in Cygwin throws a mysterious exception with errno of 90
  65. # when removing the layout test result directory after successfully
  66. # deleting its contents, claiming "Directory not empty".
  67. # We can safely ignore this since it was the directory contents that
  68. # we are most interested in deleting.
  69. # Python in Cygwin will also sometimes throw errno 2 if a process is
  70. # holding a file open. There's no point in failing to create the
  71. # archive just because some other process is behaving badly. See
  72. # <http://webkit.org/b/55581>.
  73. if e.errno != 90 and e.errno != 2:
  74. raise
  75. if __name__ == '__main__':
  76. sys.exit(main())