built-product-archive 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/usr/bin/python
  2. # Copyright (C) 2009 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 shutil
  28. import subprocess
  29. import sys
  30. import zipfile
  31. _buildDirectory = None
  32. def main():
  33. parser = optparse.OptionParser("usage: %prog [options] [action]")
  34. parser.add_option("--platform", dest="platform")
  35. parser.add_option("--debug", action="store_const", const="debug", dest="configuration")
  36. parser.add_option("--release", action="store_const", const="release", dest="configuration")
  37. options, (action, ) = parser.parse_args()
  38. if not options.platform:
  39. parser.error("Platform is required")
  40. return 1
  41. if not options.configuration:
  42. parser.error("Configuration is required")
  43. return 1
  44. if action not in ('archive', 'extract'):
  45. parser.error("Action is required")
  46. return 1
  47. genericPlatform = options.platform.split('-', 1)[0]
  48. if not determineWebKitBuildDirectory(genericPlatform, options.configuration):
  49. print >> sys.stderr, "Could not determine build directory"
  50. return 1
  51. if action == 'archive':
  52. return archiveBuiltProduct(options.configuration, genericPlatform, options.platform)
  53. else:
  54. return extractBuiltProduct(options.configuration, genericPlatform)
  55. def determineWebKitBuildDirectory(platform, configuration):
  56. global _buildDirectory
  57. _buildDirectory = subprocess.Popen(['perl', os.path.join(os.path.dirname(__file__), "..", "Scripts", "webkit-build-directory"),
  58. "--" + platform, "--" + configuration, '--top-level'], stdout=subprocess.PIPE).communicate()[0].strip()
  59. return _buildDirectory
  60. def removeDirectoryIfExists(thinDirectory):
  61. if os.path.isdir(thinDirectory):
  62. shutil.rmtree(thinDirectory)
  63. def copyBuildFiles(source, destination, patterns):
  64. shutil.copytree(source, destination, ignore=shutil.ignore_patterns(*patterns))
  65. def createZipManually(directoryToZip, archiveFile):
  66. archiveZip = zipfile.ZipFile(archiveFile, "w")
  67. for path, dirNames, fileNames in os.walk(directoryToZip):
  68. relativePath = os.path.relpath(path, directoryToZip)
  69. for fileName in fileNames:
  70. archiveZip.write(os.path.join(path, fileName), os.path.join(relativePath, fileName))
  71. archiveZip.close()
  72. def createZip(directoryToZip, configuration, archiveConfigurationOnMac=False):
  73. archiveDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "WebKitBuild"))
  74. archiveFile = os.path.join(archiveDir, configuration + ".zip")
  75. try:
  76. os.unlink(archiveFile)
  77. except OSError, e:
  78. if e.errno != 2:
  79. raise
  80. if sys.platform == 'darwin':
  81. if archiveConfigurationOnMac:
  82. return subprocess.call(["ditto", "-c", "-k", "--keepParent", "--sequesterRsrc", directoryToZip, archiveFile])
  83. return subprocess.call(["ditto", "-c", "-k", "--sequesterRsrc", directoryToZip, archiveFile])
  84. elif sys.platform == 'cygwin':
  85. return subprocess.call(["zip", "-r", archiveFile, "bin32"], cwd=directoryToZip)
  86. elif sys.platform == 'win32':
  87. createZipManually(directoryToZip, archiveFile)
  88. return 0
  89. elif sys.platform.startswith('linux'):
  90. return subprocess.call(["zip", "-y", "-r", archiveFile, "."], cwd=directoryToZip)
  91. def archiveBuiltProduct(configuration, platform, fullPlatform):
  92. assert platform in ('mac', 'win', 'qt', 'gtk', 'efl')
  93. configurationBuildDirectory = os.path.join(_buildDirectory, configuration.title())
  94. if platform == 'mac':
  95. return createZip(configurationBuildDirectory, configuration, archiveConfigurationOnMac=True)
  96. elif platform == 'win':
  97. binDirectory = os.path.join(configurationBuildDirectory, "bin32")
  98. thinDirectory = os.path.join(configurationBuildDirectory, "thin")
  99. thinBinDirectory = os.path.join(thinDirectory, "bin32")
  100. removeDirectoryIfExists(thinDirectory)
  101. copyBuildFiles(binDirectory, thinBinDirectory, ['*.ilk'])
  102. if createZip(thinDirectory, configuration):
  103. return 1
  104. shutil.rmtree(thinDirectory)
  105. elif platform == 'qt' or platform == 'gtk' or platform == 'efl':
  106. thinDirectory = os.path.join(configurationBuildDirectory, "thin")
  107. removeDirectoryIfExists(thinDirectory)
  108. os.mkdir(thinDirectory)
  109. if platform == 'qt' or platform == 'efl':
  110. neededDirectories = ["bin", "lib"]
  111. elif platform == 'gtk':
  112. neededDirectories = ["Programs", ".libs", "Libraries", "TestNetscapePlugin"]
  113. for dirname in neededDirectories:
  114. fromDir = os.path.join(configurationBuildDirectory, dirname, ".")
  115. toDir = os.path.join(thinDirectory, dirname)
  116. os.makedirs(toDir)
  117. if subprocess.call('cp -R %s %s' % (fromDir, toDir), shell=True):
  118. return 1
  119. for root, dirs, files in os.walk(thinDirectory, topdown=False):
  120. for name in files:
  121. if name.endswith(".o"):
  122. os.remove(os.path.join(root, name))
  123. if createZip(thinDirectory, configuration):
  124. return 1
  125. def unzipArchive(directoryToExtractTo, configuration):
  126. archiveDir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "WebKitBuild"))
  127. assert os.path.isdir(archiveDir)
  128. archiveFile = os.path.join(archiveDir, configuration + ".zip")
  129. if sys.platform == 'darwin':
  130. if subprocess.call(["ditto", "-x", "-k", archiveFile, directoryToExtractTo]):
  131. return 1
  132. elif sys.platform == 'cygwin' or sys.platform.startswith('linux'):
  133. if subprocess.call(["unzip", "-o", archiveFile], cwd=directoryToExtractTo):
  134. return 1
  135. elif sys.platform == 'win32':
  136. archive = zipfile.ZipFile(archiveFile, "r")
  137. archive.extractall(directoryToExtractTo)
  138. archive.close()
  139. os.unlink(archiveFile)
  140. def extractBuiltProduct(configuration, platform):
  141. assert platform in ('mac', 'win', 'qt', 'gtk', 'efl')
  142. archiveFile = os.path.join(_buildDirectory, configuration + ".zip")
  143. configurationBuildDirectory = os.path.join(_buildDirectory, configuration.title())
  144. removeDirectoryIfExists(configurationBuildDirectory)
  145. os.makedirs(configurationBuildDirectory)
  146. if platform == 'mac':
  147. return unzipArchive(_buildDirectory, configuration)
  148. elif platform == 'win':
  149. binDirectory = os.path.join(configurationBuildDirectory, "bin32")
  150. os.makedirs(binDirectory)
  151. safariPath = subprocess.Popen('cygpath -w "$PROGRAMFILES"/Safari',
  152. shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
  153. if subprocess.call('cp -R "%s"/*.dll "%s"/*.resources %s' % (safariPath, safariPath, binDirectory), shell=True):
  154. return 1
  155. return unzipArchive(configurationBuildDirectory, configuration)
  156. elif platform == 'qt' or platform == 'gtk' or platform == 'efl':
  157. print "Extracting", configurationBuildDirectory
  158. return unzipArchive(configurationBuildDirectory, configuration)
  159. if __name__ == '__main__':
  160. sys.exit(main())