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_makenames.py is a harness script to connect actions sections of
36 # gyp-based builds to make_names.pl.
38 # usage: action_makenames.py OUTPUTS -- INPUTS [-- OPTIONS]
40 # Multiple OUTPUTS, INPUTS, and OPTIONS may be listed. The sections are
41 # separated by -- arguments.
43 # The directory name of the first output is chosen as the directory in which
44 # make_names will run. If the directory name for any subsequent output is
45 # different, those files will be moved to the desired directory.
47 # Multiple INPUTS may be listed. An input with a basename matching
48 # "make_names.pl" is taken as the path to that script. Inputs with names
49 # ending in TagNames.in or tags.in are taken as tag inputs. Inputs with names
50 # ending in AttributeNames.in or attrs.in are taken as attribute inputs. There
51 # may be at most one tag input and one attribute input. A make_names.pl input
52 # is required and at least one tag or attribute input must be present.
54 # OPTIONS is a list of additional options to pass to make_names.pl. This
55 # section need not be present.
65 def SplitArgsIntoSections(args):
69 # If there is no '--' left, everything remaining is an entire section.
72 dashes = args.index('--')
74 sections.append(args[:dashes])
76 # Next time through the loop, look at everything after this '--'.
77 if dashes + 1 == len(args):
78 # If the '--' is at the end of the list, we won't come back through the
79 # loop again. Add an empty section now corresponding to the nothingness
80 # following the final '--'.
84 args = args[dashes + 1:]
90 sections = SplitArgsIntoSections(args[1:])
91 assert len(sections) == 2 or len(sections) == 3
92 (outputs, inputs) = sections[:2]
93 if len(sections) == 3:
98 # Make all output pathnames absolute so that they can be accessed after
100 for index in xrange(0, len(outputs)):
101 outputs[index] = os.path.abspath(outputs[index])
103 outputDir = os.path.dirname(outputs[0])
105 # Look at the inputs and figure out which ones are make_names.pl, tags, and
106 # attributes. There can be at most one of each, and those are the only
107 # input types supported. make_names.pl is required and at least one of tags
108 # and attributes is required.
109 makeNamesInput = None
113 # Make input pathnames absolute so they can be accessed after changing
114 # directory. On Windows, convert \ to / for inputs to the perl script to
115 # work around the intermix of activepython + cygwin perl.
116 inputAbs = os.path.abspath(input)
117 inputAbsPosix = inputAbs.replace(os.path.sep, posixpath.sep)
118 inputBasename = os.path.basename(input)
119 if inputBasename == 'make_names.pl':
120 assert makeNamesInput == None
121 makeNamesInput = inputAbs
122 elif inputBasename.endswith('TagNames.in') \
123 or inputBasename.endswith('tags.in'):
124 assert tagInput == None
125 tagInput = inputAbsPosix
126 elif inputBasename.endswith('AttributeNames.in') \
127 or inputBasename.endswith('attrs.in'):
128 assert attrInput == None
129 attrInput = inputAbsPosix
130 elif inputBasename.endswith('Names.in'):
131 options.append(inputAbsPosix)
135 assert makeNamesInput != None
136 assert tagInput != None or attrInput != None or ('--fonts' in options)
138 # scriptsPath is a Perl include directory, located relative to
140 scriptsPath = os.path.normpath(
141 os.path.join(os.path.dirname(makeNamesInput), os.pardir, 'bindings', 'scripts'))
143 # Change to the output directory because make_names.pl puts output in its
147 # Build up the command.
148 command = ['perl', '-I', scriptsPath, makeNamesInput]
150 command.extend(['--tags', tagInput])
151 if attrInput != None:
152 command.extend(['--attrs', attrInput])
153 command.extend(options)
155 # Do it. check_call is new in 2.5, so simulate its behavior with call and
157 returnCode = subprocess.call(command)
158 assert returnCode == 0
160 # Go through the outputs. Any output that belongs in a different directory
161 # is moved. Do a copy and delete instead of rename for maximum portability.
162 # Note that all paths used in this section are still absolute.
163 for output in outputs:
164 thisOutputDir = os.path.dirname(output)
165 if thisOutputDir != outputDir:
166 outputBasename = os.path.basename(output)
167 src = os.path.join(outputDir, outputBasename)
168 dst = os.path.join(thisOutputDir, outputBasename)
169 shutil.copyfile(src, dst)
175 if __name__ == '__main__':
176 sys.exit(main(sys.argv))