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# 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.
34
35# usage: action_useragentstylesheets.py OUTPUTS -- INPUTS
36#
37# Multiple OUTPUTS and INPUTS may be listed. The sections are separated by
38# -- arguments.
39#
40# OUTPUTS must contain two items, in order: a path to UserAgentStyleSheets.h
41# and a path to UserAgentStyleSheetsData.cpp.
42#
43# INPUTS must contain at least two items. The first item must be the path to
44# make-css-file-arrays.pl. The remaining items are paths to style sheets to
45# be fed to that script.
46
47
48import os
49import subprocess
50import sys
51
52
53def 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 section.
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 nothingness
68            # following the final '--'.
69            args = []
70            sections.append(args)
71        else:
72            args = args[dashes + 1:]
73
74    return sections
75
76
77def main(args):
78    sections = SplitArgsIntoSections(args[1:])
79    assert len(sections) == 2
80    (outputs, inputs) = sections
81
82    assert len(outputs) == 2
83    outputH = outputs[0]
84    outputCpp = outputs[1]
85
86    makeCssFileArrays = inputs[0]
87    styleSheets = inputs[1:]
88
89    # Build up the command.
90    command = ['perl', makeCssFileArrays, outputH, outputCpp]
91    command.extend(styleSheets)
92
93    # Do it. check_call is new in 2.5, so simulate its behavior with call and
94    # assert.
95    returnCode = subprocess.call(command)
96    assert returnCode == 0
97
98    return returnCode
99
100
101if __name__ == '__main__':
102    sys.exit(main(sys.argv))
103