PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/webview/native/Source/WebCore/WebCore.gyp/scripts/action_derivedsourcesallinone.py

https://bitbucket.org/shemnon/openjfx-8-master-rt
Python | 225 lines | 179 code | 4 blank | 42 comment | 0 complexity | e1db9b81d05aadd7d10008f898037fc6 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, BSD-3-Clause, LGPL-2.1
  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2009 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 are
  7. # met:
  8. #
  9. # * Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. # * Neither the name of Google Inc. nor the names of its
  16. # contributors may be used to endorse or promote products derived from
  17. # this software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #
  31. # Copyright (c) 2009 The Chromium Authors. All rights reserved.
  32. # Use of this source code is governed by a BSD-style license that can be
  33. # found in the LICENSE file.
  34. # action_derivedsourcesallinone.py generates a single cpp file that includes
  35. # all v8 bindings cpp files generated from idls. Files can be assigned into
  36. # multiple output files, to reduce maximum compilation unit size and allow
  37. # parallel compilation.
  38. #
  39. # usage: action_derivedsourcesallinone.py IDL_FILES_LIST -- OUTPUT_FILE1 OUTPUT_FILE2 ...
  40. #
  41. # Note that IDL_FILES_LIST is a text file containing the IDL file paths.
  42. import errno
  43. import os
  44. import os.path
  45. import re
  46. import subprocess
  47. import sys
  48. # A regexp for finding Conditional attributes in interface definitions.
  49. conditionalPattern = re.compile('interface[\s]*\[[^\]]*Conditional=([\_0-9a-zA-Z&|]*)')
  50. copyrightTemplate = """/*
  51. * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT.
  52. *
  53. * This file was generated by the make_jni_lists.py script.
  54. *
  55. * Copyright (C) 2009 Google Inc. All rights reserved.
  56. *
  57. * Redistribution and use in source and binary forms, with or without
  58. * modification, are permitted provided that the following conditions
  59. * are met:
  60. * 1. Redistributions of source code must retain the above copyright
  61. * notice, this list of conditions and the following disclaimer.
  62. * 2. Redistributions in binary form must reproduce the above copyright
  63. * notice, this list of conditions and the following disclaimer in the
  64. * documentation and/or other materials provided with the distribution.
  65. *
  66. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  67. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  68. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  69. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  70. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  71. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  72. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  73. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  74. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  75. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  76. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  77. */
  78. """
  79. # Wraps conditional with ENABLE() and replace '&','|' with '&&','||' if more than one conditional is specified.
  80. def formatConditional(conditional):
  81. def wrapWithEnable(s):
  82. if re.match('[|&]$', s):
  83. return s * 2
  84. return 'ENABLE(' + s + ')'
  85. return ' '.join(map(wrapWithEnable, conditional))
  86. # Find the conditional interface attribute.
  87. def extractConditional(idlFilePath):
  88. conditional = None
  89. # Read file and look for "interface [ Conditional=XXX ]".
  90. idlFile = open(idlFilePath)
  91. idlContents = idlFile.read().replace('\n', '')
  92. idlFile.close()
  93. match = conditionalPattern.search(idlContents)
  94. if match:
  95. conditional = match.group(1)
  96. conditional = re.split('([|&])', conditional)
  97. return conditional
  98. # Extracts conditional and interface name from each IDL file.
  99. def extractMetaData(filePaths):
  100. metaDataList = []
  101. for f in filePaths:
  102. metaData = {}
  103. if len(f) == 0:
  104. continue
  105. if not os.path.exists(f):
  106. print 'WARNING: file not found: "%s"' % f
  107. continue
  108. # Extract type name from file name
  109. (parentPath, fileName) = os.path.split(f)
  110. (interfaceName, ext) = os.path.splitext(fileName)
  111. if not ext == '.idl':
  112. continue
  113. metaData = {
  114. 'conditional': extractConditional(f),
  115. 'name': interfaceName,
  116. }
  117. metaDataList.append(metaData)
  118. return metaDataList
  119. def generateContent(filesMetaData, partition, totalPartitions):
  120. # Sort files by conditionals.
  121. filesMetaData.sort()
  122. output = []
  123. # Add fixed content.
  124. output.append(copyrightTemplate)
  125. output.append('#define NO_IMPLICIT_ATOMICSTRING\n\n')
  126. # List all includes segmented by if and endif.
  127. prevConditional = None
  128. for metaData in filesMetaData:
  129. name = metaData['name']
  130. if (hash(name) % totalPartitions) != partition:
  131. continue
  132. conditional = metaData['conditional']
  133. if prevConditional and prevConditional != conditional:
  134. output.append('#endif\n')
  135. if conditional and prevConditional != conditional:
  136. output.append('\n#if %s\n' % formatConditional(conditional))
  137. output.append('#include "bindings/V8%s.cpp"\n' % name)
  138. prevConditional = conditional
  139. if prevConditional:
  140. output.append('#endif\n')
  141. return ''.join(output)
  142. def writeContent(content, outputFileName):
  143. (parentPath, fileName) = os.path.split(outputFileName)
  144. if not os.path.exists(parentPath):
  145. print parentPath
  146. os.mkdir(parentPath)
  147. f = open(outputFileName, 'w')
  148. f.write(content)
  149. f.close()
  150. def resolveCygpath(cygdriveNames):
  151. cmd = ['cygpath', '-f', '-', '-wa']
  152. process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  153. idlFileNames = []
  154. for fileName in cygdriveNames:
  155. process.stdin.write("%s\n" % fileName)
  156. process.stdin.flush()
  157. idlFileNames.append(process.stdout.readline().rstrip())
  158. process.stdin.close()
  159. process.wait()
  160. return idlFileNames
  161. def main(args):
  162. assert(len(args) > 3)
  163. inOutBreakIndex = args.index('--')
  164. inputFileName = args[1]
  165. outputFileNames = args[inOutBreakIndex+1:]
  166. inputFile = open(inputFileName, 'r')
  167. idlFileNames = []
  168. cygdriveNames = []
  169. for line in inputFile:
  170. idlFileName = line.rstrip().split(' ')[0]
  171. if idlFileName.startswith("/cygdrive"):
  172. cygdriveNames.append(idlFileName)
  173. else:
  174. idlFileNames.append(idlFileName)
  175. if cygdriveNames:
  176. idlFileNames.extend(resolveCygpath(cygdriveNames))
  177. inputFile.close()
  178. filesMetaData = extractMetaData(idlFileNames)
  179. for fileName in outputFileNames:
  180. partition = outputFileNames.index(fileName)
  181. fileContents = generateContent(filesMetaData, partition, len(outputFileNames))
  182. writeContent(fileContents, fileName)
  183. return 0
  184. if __name__ == '__main__':
  185. sys.exit(main(sys.argv))