| OLD | NEW | 
|---|
|  | (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 # 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 # action_makenames.py is a harness script to connect actions sections of |  | 
| 36 # gyp-based builds to make_names.pl. |  | 
| 37 # |  | 
| 38 # usage: action_makenames.py OUTPUTS -- INPUTS [-- OPTIONS] |  | 
| 39 # |  | 
| 40 # Multiple OUTPUTS, INPUTS, and OPTIONS may be listed. The sections are |  | 
| 41 # separated by -- arguments. |  | 
| 42 # |  | 
| 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. |  | 
| 46 # |  | 
| 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. |  | 
| 53 # |  | 
| 54 # OPTIONS is a list of additional options to pass to make_names.pl. This |  | 
| 55 # section need not be present. |  | 
| 56 |  | 
| 57 |  | 
| 58 import os |  | 
| 59 import posixpath |  | 
| 60 import shutil |  | 
| 61 import subprocess |  | 
| 62 import sys |  | 
| 63 |  | 
| 64 |  | 
| 65 def SplitArgsIntoSections(args): |  | 
| 66     sections = [] |  | 
| 67     while len(args) > 0: |  | 
| 68         if not '--' in args: |  | 
| 69             # If there is no '--' left, everything remaining is an entire sectio
     n. |  | 
| 70             dashes = len(args) |  | 
| 71         else: |  | 
| 72             dashes = args.index('--') |  | 
| 73 |  | 
| 74         sections.append(args[:dashes]) |  | 
| 75 |  | 
| 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 nothingn
     ess |  | 
| 80             # following the final '--'. |  | 
| 81             args = [] |  | 
| 82             sections.append(args) |  | 
| 83         else: |  | 
| 84             args = args[dashes + 1:] |  | 
| 85 |  | 
| 86     return sections |  | 
| 87 |  | 
| 88 |  | 
| 89 def main(args): |  | 
| 90     sections = SplitArgsIntoSections(args[1:]) |  | 
| 91     assert len(sections) == 2 or len(sections) == 3 |  | 
| 92     (outputs, inputs) = sections[:2] |  | 
| 93     if len(sections) == 3: |  | 
| 94         options = sections[2] |  | 
| 95     else: |  | 
| 96         options = [] |  | 
| 97 |  | 
| 98     # Make all output pathnames absolute so that they can be accessed after |  | 
| 99     # changing directory. |  | 
| 100     for index in xrange(0, len(outputs)): |  | 
| 101         outputs[index] = os.path.abspath(outputs[index]) |  | 
| 102 |  | 
| 103     outputDir = os.path.dirname(outputs[0]) |  | 
| 104 |  | 
| 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 |  | 
| 110     tagInput = None |  | 
| 111     attrInput = None |  | 
| 112     eventsInput = None |  | 
| 113     for input in inputs: |  | 
| 114         # Make input pathnames absolute so they can be accessed after changing |  | 
| 115         # directory. On Windows, convert \ to / for inputs to the perl script to |  | 
| 116         # work around the intermix of activepython + cygwin perl. |  | 
| 117         inputAbs = os.path.abspath(input) |  | 
| 118         inputAbsPosix = inputAbs.replace(os.path.sep, posixpath.sep) |  | 
| 119         inputBasename = os.path.basename(input) |  | 
| 120         if inputBasename in ('make_names.pl', 'make_dom_exceptions.pl', 'make_se
     ttings.pl'): |  | 
| 121             assert makeNamesInput == None |  | 
| 122             makeNamesInput = inputAbs |  | 
| 123         elif inputBasename.endswith('TagNames.in'): |  | 
| 124             assert tagInput == None |  | 
| 125             tagInput = inputAbsPosix |  | 
| 126         elif inputBasename.endswith('AttributeNames.in') or inputBasename.endswi
     th('attrs.in'): |  | 
| 127             assert attrInput == None |  | 
| 128             attrInput = inputAbsPosix |  | 
| 129         elif (inputBasename.endswith('EventTargetFactory.in') or inputBasename.e
     ndswith('DOMExceptions.in') or inputBasename.endswith('Settings.in')): |  | 
| 130             eventsInput = inputAbsPosix |  | 
| 131         elif inputBasename.endswith('Names.in'): |  | 
| 132             options.append(inputAbsPosix) |  | 
| 133         elif inputBasename.endswith('.pm'): |  | 
| 134             continue |  | 
| 135         else: |  | 
| 136             assert False |  | 
| 137 |  | 
| 138     assert makeNamesInput != None |  | 
| 139     assert tagInput != None or attrInput != None or eventsInput != None or ('--f
     onts' in options) |  | 
| 140 |  | 
| 141     # scriptsPath is a Perl include directory, located relative to |  | 
| 142     # makeNamesInput. |  | 
| 143     scriptsPath = os.path.normpath( |  | 
| 144         os.path.join(os.path.dirname(makeNamesInput), os.pardir, 'scripts')) |  | 
| 145 |  | 
| 146     # Change to the output directory because make_names.pl puts output in its |  | 
| 147     # working directory. |  | 
| 148     os.chdir(outputDir) |  | 
| 149 |  | 
| 150     # Build up the command. |  | 
| 151     command = ['perl', '-I', scriptsPath, makeNamesInput] |  | 
| 152     if tagInput != None: |  | 
| 153         command.extend(['--tags', tagInput]) |  | 
| 154     if attrInput != None: |  | 
| 155         command.extend(['--attrs', attrInput]) |  | 
| 156     if eventsInput != None: |  | 
| 157         command.extend(['--input', eventsInput]) |  | 
| 158     command.extend(options) |  | 
| 159 |  | 
| 160     # Do it. check_call is new in 2.5, so simulate its behavior with call and |  | 
| 161     # assert. |  | 
| 162     returnCode = subprocess.call(command) |  | 
| 163     assert returnCode == 0 |  | 
| 164 |  | 
| 165     # Go through the outputs. Any output that belongs in a different directory |  | 
| 166     # is moved. Do a copy and delete instead of rename for maximum portability. |  | 
| 167     # Note that all paths used in this section are still absolute. |  | 
| 168     for output in outputs: |  | 
| 169         thisOutputDir = os.path.dirname(output) |  | 
| 170         if thisOutputDir != outputDir: |  | 
| 171             outputBasename = os.path.basename(output) |  | 
| 172             src = os.path.join(outputDir, outputBasename) |  | 
| 173             dst = os.path.join(thisOutputDir, outputBasename) |  | 
| 174             shutil.copyfile(src, dst) |  | 
| 175             os.unlink(src) |  | 
| 176 |  | 
| 177     return returnCode |  | 
| 178 |  | 
| 179 |  | 
| 180 if __name__ == '__main__': |  | 
| 181     sys.exit(main(sys.argv)) |  | 
| OLD | NEW | 
|---|