Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: third_party/WebCore/WebCore.gyp/scripts/action_csspropertynames.py

Issue 12319151: WebKit IDL roll. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 # action_csspropertynames.py is a harness script to connect actions sections of
32 # gyp-based builds to makeprop.pl.
33 #
34 # usage: action_csspropertynames.py OUTPUTS -- [--defines ENABLE_FLAG1 ENABLE_FL AG2 ...] -- INPUTS
35 #
36 # Exactly two outputs must be specified: a path to each of CSSPropertyNames.cpp
37 # and CSSPropertyNames.h.
38 #
39 # Multiple inputs may be specified. One input must have a basename of
40 # makeprop.pl; this is taken as the path to makeprop.pl. All other inputs are
41 # paths to .in files that are used as input to makeprop.pl; at least one,
42 # CSSPropertyNames.in, is required.
43
44
45 import os
46 import posixpath
47 import shlex
48 import shutil
49 import subprocess
50 import sys
51
52
53 def SplitArgsIntoSections(args):
54 sections = []
55 while len(args) > 0:
56 if not '--' in args:
57 # If there is no '--' left, everything remaining is an entire sectio n.
58 dashes = len(args)
59 else:
60 dashes = args.index('--')
61
62 sections.append(args[:dashes])
63
64 # Next time through the loop, look at everything after this '--'.
65 if dashes + 1 == len(args):
66 # If the '--' is at the end of the list, we won't come back through the
67 # loop again. Add an empty section now corresponding to the nothingn ess
68 # following the final '--'.
69 args = []
70 sections.append(args)
71 else:
72 args = args[dashes + 1:]
73
74 return sections
75
76
77 def SplitDefines(options):
78 # The defines come in as one flat string. Split it up into distinct argument s.
79 if '--defines' in options:
80 definesIndex = options.index('--defines')
81 if definesIndex + 1 < len(options):
82 splitOptions = shlex.split(options[definesIndex + 1])
83 if splitOptions:
84 options[definesIndex + 1] = ' '.join(splitOptions)
85
86 def main(args):
87 outputs, options, inputs = SplitArgsIntoSections(args[1:])
88
89 SplitDefines(options)
90
91 # Make all output pathnames absolute so that they can be accessed after
92 # changing directory.
93 for index in xrange(0, len(outputs)):
94 outputs[index] = os.path.abspath(outputs[index])
95
96 outputDir = os.path.dirname(outputs[0])
97
98 # Look at the inputs and figure out which one is makeprop.pl and which are
99 # inputs to that script.
100 makepropInput = None
101 inFiles = []
102 for input in inputs:
103 # Make input pathnames absolute so they can be accessed after changing
104 # directory. On Windows, convert \ to / for inputs to the perl script to
105 # work around the intermix of activepython + cygwin perl.
106 inputAbs = os.path.abspath(input)
107 inputAbsPosix = inputAbs.replace(os.path.sep, posixpath.sep)
108 inputBasename = os.path.basename(input)
109 if inputBasename == 'makeprop.pl':
110 assert makepropInput == None
111 makepropInput = inputAbs
112 elif inputBasename.endswith('.in'):
113 inFiles.append(inputAbsPosix)
114 else:
115 assert False
116
117 assert makepropInput != None
118 assert len(inFiles) >= 1
119
120 # Change to the output directory because makeprop.pl puts output in its
121 # working directory.
122 os.chdir(outputDir)
123
124 # Merge all inFiles into a single file whose name will be the same as the
125 # first listed inFile, but in the output directory.
126 mergedPath = os.path.basename(inFiles[0])
127 merged = open(mergedPath, 'wb') # 'wb' to get \n only on windows
128
129 # Concatenate all the input files.
130 for inFilePath in inFiles:
131 inFile = open(inFilePath)
132 shutil.copyfileobj(inFile, merged)
133 inFile.close()
134
135 merged.close()
136
137 # scriptsPath is a Perl include directory, located relative to
138 # makepropInput.
139 scriptsPath = os.path.normpath(
140 os.path.join(os.path.dirname(makepropInput), os.pardir, 'bindings', 'scr ipts'))
141
142 # Build up the command.
143 command = ['perl', '-I', scriptsPath, makepropInput]
144 command.extend(options)
145
146 # Do it. checkCall is new in 2.5, so simulate its behavior with call and
147 # assert.
148 returnCode = subprocess.call(command)
149 assert returnCode == 0
150
151 # Don't leave behind the merged file or the .gperf file created by
152 # makeprop.
153 (root, ext) = os.path.splitext(mergedPath)
154 gperfPath = root + '.gperf'
155 os.unlink(gperfPath)
156 os.unlink(mergedPath)
157
158 # Go through the outputs. Any output that belongs in a different directory
159 # is moved. Do a copy and delete instead of rename for maximum portability.
160 # Note that all paths used in this section are still absolute.
161 for output in outputs:
162 thisOutputDir = os.path.dirname(output)
163 if thisOutputDir != outputDir:
164 outputBasename = os.path.basename(output)
165 src = os.path.join(outputDir, outputBasename)
166 dst = os.path.join(thisOutputDir, outputBasename)
167 shutil.copyfile(src, dst)
168 os.unlink(src)
169
170 return returnCode
171
172
173 if __name__ == '__main__':
174 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « third_party/WebCore/README ('k') | third_party/WebCore/WebCore.gyp/scripts/action_cssvaluekeywords.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698