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.
36 # action_useragentstylesheets.py OUTPUTS INPUTS -- MAINSCRIPT MODULES -- OPTIONS
38 # OUTPUTS must contain two items, in order: a path to UserAgentStyleSheets.h
39 # and a path to UserAgentStyleSheetsData.cpp.
40 # INPUTS contains one or more CSS files.
42 # MAINSCRIPT is the path to make-css-file-arrays.pl. MODULES may contain
43 # multiple paths to additional perl modules.
45 # OPTIONS are passed as-is to MAINSCRIPT as additional arguments.
54 def SplitArgsIntoSections(args):
58 # If there is no '--' left, everything remaining is an entire section.
61 dashes = args.index('--')
63 sections.append(args[:dashes])
65 # Next time through the loop, look at everything after this '--'.
66 if dashes + 1 == len(args):
67 # If the '--' is at the end of the list, we won't come back through the
68 # loop again. Add an empty section now corresponding to the nothingness
69 # following the final '--'.
73 args = args[dashes + 1:]
79 sections = SplitArgsIntoSections(args[1:])
80 assert len(sections) == 3
81 (outputsInputs, scripts, options) = sections
83 assert len(outputsInputs) >= 3
84 outputH = outputsInputs[0]
85 outputCpp = outputsInputs[1]
86 styleSheets = outputsInputs[2:]
88 assert len(scripts) >= 1
89 makeCssFileArrays = scripts[0]
90 perlModules = scripts[1:]
93 for perlModule in perlModules:
94 includeDir = os.path.dirname(perlModule)
95 if not includeDir in includeDirs:
96 includeDirs.append(includeDir)
98 # The defines come in as one flat string. Split it up into distinct arguments.
99 if '--defines' in options:
100 definesIndex = options.index('--defines')
101 if definesIndex + 1 < len(options):
102 splitOptions = shlex.split(options[definesIndex + 1])
104 options[definesIndex + 1] = ' '.join(splitOptions)
106 # Build up the command.
108 for includeDir in includeDirs:
109 command.extend(['-I', includeDir])
110 command.append(makeCssFileArrays)
111 command.extend(options)
112 command.extend([outputH, outputCpp])
113 command.extend(styleSheets)
115 # Do it. check_call is new in 2.5, so simulate its behavior with call and
117 returnCode = subprocess.call(command)
118 assert returnCode == 0
123 if __name__ == '__main__':
124 sys.exit(main(sys.argv))