3 # Copyright (C) 2009 Google Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
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
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.
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.
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.
35 # action_derivedsourceslist.py generates a single cpp file that includes
36 # all v8 bindings cpp files generated from idls. Files can be assigned into
37 # multiple output files, to reduce maximum compilation unit size and allow
38 # parallel compilation.
40 # usage: action_derivedsourceslist.py IDL_FILES_LIST -- OUTPUT_FILE1 OUTPUT_FILE2 ...
42 # Note that IDL_FILES_LIST is a text file containing the IDL file paths.
51 # A regexp for finding Conditional attributes in interface definitions.
52 conditionalPattern = re.compile('interface[\s]*\[[^\]]*Conditional=([\_0-9a-zA-Z&|]*)')
54 copyrightTemplate = """/*
55 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT.
57 * This file was generated by the make_jni_lists.py script.
59 * Copyright (C) 2009 Google Inc. All rights reserved.
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
64 * 1. Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * 2. Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
70 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
71 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
73 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
74 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
75 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
76 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
77 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
78 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
79 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
80 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
85 # Wraps conditional with ENABLE() and replace '&','|' with '&&','||' if more than one conditional is specified.
86 def formatConditional(conditional):
87 def wrapWithEnable(s):
88 if re.match('[|&]$', s):
90 return 'ENABLE(' + s + ')'
91 return ' '.join(map(wrapWithEnable, conditional))
94 # Find the conditional interface attribute.
95 def extractConditional(idlFilePath):
98 # Read file and look for "interface [ Conditional=XXX ]".
99 idlFile = open(idlFilePath)
100 idlContents = idlFile.read().replace('\n', '')
103 match = conditionalPattern.search(idlContents)
105 conditional = match.group(1)
106 conditional = re.split('([|&])', conditional)
110 # Extracts conditional and interface name from each IDL file.
111 def extractMetaData(filePaths):
118 if not os.path.exists(f):
119 print 'WARNING: file not found: "%s"' % f
122 # Extract type name from file name
123 (parentPath, fileName) = os.path.split(f)
124 (interfaceName, ext) = os.path.splitext(fileName)
126 if not ext == '.idl':
130 'conditional': extractConditional(f),
131 'name': interfaceName,
134 metaDataList.append(metaData)
139 def generateContent(filesMetaData, partition, totalPartitions):
140 # Sort files by conditionals.
146 output.append(copyrightTemplate)
147 output.append('#define NO_IMPLICIT_ATOMICSTRING\n\n')
149 # List all includes segmented by if and endif.
150 prevConditional = None
151 for metaData in filesMetaData:
152 name = metaData['name']
153 if (hash(name) % totalPartitions) != partition:
155 conditional = metaData['conditional']
157 if prevConditional and prevConditional != conditional:
158 output.append('#endif\n')
159 if conditional and prevConditional != conditional:
160 output.append('\n#if %s\n' % formatConditional(conditional))
162 output.append('#include "bindings/V8%s.cpp"\n' % name)
164 prevConditional = conditional
167 output.append('#endif\n')
169 return ''.join(output)
172 def writeContent(content, outputFileName):
173 (parentPath, fileName) = os.path.split(outputFileName)
174 if not os.path.exists(parentPath):
177 f = open(outputFileName, 'w')
183 assert(len(args) > 3)
184 inOutBreakIndex = args.index('--')
185 inputFileName = args[1]
186 outputFileNames = args[inOutBreakIndex+1:]
188 inputFile = open(inputFileName, 'r')
189 idlFileNames = inputFile.read().split('\n')
192 filesMetaData = extractMetaData(idlFileNames)
193 for fileName in outputFileNames:
194 partition = outputFileNames.index(fileName)
195 fileContents = generateContent(filesMetaData, partition, len(outputFileNames))
196 writeContent(fileContents, fileName)
201 if __name__ == '__main__':
202 sys.exit(main(sys.argv))