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
# action_csspropertynames.py is a harness script to connect actions sections of
32
# gyp-based builds to makeprop.pl.
34
# usage: action_csspropertynames.py OUTPUTS -- [--defines ENABLE_FLAG1 ENABLE_FLAG2 ...] -- INPUTS
36
# Exactly two outputs must be specified: a path to each of CSSPropertyNames.cpp
37
# and CSSPropertyNames.h.
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.
53
def SplitArgsIntoSections(args):
57
# If there is no '--' left, everything remaining is an entire section.
60
dashes = args.index('--')
62
sections.append(args[:dashes])
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 nothingness
68
# following the final '--'.
72
args = args[dashes + 1:]
77
def SplitDefines(options):
78
# The defines come in as one flat string. Split it up into distinct arguments.
79
if '--defines' in options:
80
definesIndex = options.index('--defines')
81
if definesIndex + 1 < len(options):
82
splitOptions = shlex.split(options[definesIndex + 1])
84
options[definesIndex + 1] = ' '.join(splitOptions)
87
outputs, options, inputs = SplitArgsIntoSections(args[1:])
91
# Make all output pathnames absolute so that they can be accessed after
93
for index in xrange(0, len(outputs)):
94
outputs[index] = os.path.abspath(outputs[index])
96
outputDir = os.path.dirname(outputs[0])
98
# Look at the inputs and figure out which one is makeprop.pl and which are
99
# inputs to that script.
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)
117
assert makepropInput != None
118
assert len(inFiles) >= 1
120
# Change to the output directory because makeprop.pl puts output in its
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
129
# Concatenate all the input files.
130
for inFilePath in inFiles:
131
inFile = open(inFilePath)
132
shutil.copyfileobj(inFile, merged)
137
# scriptsPath is a Perl include directory, located relative to
139
scriptsPath = os.path.normpath(
140
os.path.join(os.path.dirname(makepropInput), os.pardir, 'bindings', 'scripts'))
142
# Build up the command.
143
command = ['perl', '-I', scriptsPath, makepropInput]
144
command.extend(options)
146
# Do it. checkCall is new in 2.5, so simulate its behavior with call and
148
returnCode = subprocess.call(command)
149
assert returnCode == 0
151
# Don't leave behind the merged file or the .gperf file created by
153
(root, ext) = os.path.splitext(mergedPath)
154
gperfPath = root + '.gperf'
156
os.unlink(mergedPath)
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)
173
if __name__ == '__main__':
174
sys.exit(main(sys.argv))