diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-25 21:26:55 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-25 21:26:55 +0000 |
commit | 2f80c3109c9fc7724740f405b3ef739d4a68ac81 (patch) | |
tree | ff089a486e0f5fcd197d3f555400f31fc7ebb8e0 /webkit/build/action_cssvaluekeywords.py | |
parent | a2318cda8a1092f127ed6b88b12fad8208608ad1 (diff) | |
download | chromium_src-2f80c3109c9fc7724740f405b3ef739d4a68ac81.zip chromium_src-2f80c3109c9fc7724740f405b3ef739d4a68ac81.tar.gz chromium_src-2f80c3109c9fc7724740f405b3ef739d4a68ac81.tar.bz2 |
Import .gyp files into the Chromium tree
Review URL: http://codereview.chromium.org/27158
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10380 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/build/action_cssvaluekeywords.py')
-rwxr-xr-x | webkit/build/action_cssvaluekeywords.py | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/webkit/build/action_cssvaluekeywords.py b/webkit/build/action_cssvaluekeywords.py new file mode 100755 index 0000000..12b0f40 --- /dev/null +++ b/webkit/build/action_cssvaluekeywords.py @@ -0,0 +1,144 @@ +#!/usr/bin/python + +# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# action_cssvaluekeywords.py is a harness script to connect actions sections of +# gyp-based builds to makevalues.pl. +# +# usage: action_cssvaluekeywords.py OUTPUTS -- INPUTS +# +# Exactly two outputs must be specified: a path to each of CSSValueKeywords.c +# and CSSValueKeywords.h. +# +# Multiple inputs may be specified. One input must have a basename of +# makevalues.pl; this is taken as the path to makevalues.pl. All other inputs +# are paths to .in files that are used as input to makevalues.pl; at least +# one, CSSValueKeywords.in, is required. + + +import os +import posixpath +import shutil +import subprocess +import sys + + +def SplitArgsIntoSections(args): + sections = [] + while len(args) > 0: + if not '--' in args: + # If there is no '--' left, everything remaining is an entire section. + dashes = len(args) + else: + dashes = args.index('--') + + sections.append(args[:dashes]) + + # Next time through the loop, look at everything after this '--'. + if dashes + 1 == len(args): + # If the '--' is at the end of the list, we won't come back through the + # loop again. Add an empty section now corresponding to the nothingness + # following the final '--'. + args = [] + sections.append(args) + else: + args = args[dashes + 1:] + + return sections + + +def main(args): + (outputs, inputs) = SplitArgsIntoSections(args[1:]) + + # Make all output pathnames absolute so that they can be accessed after + # changing directory. + for index in xrange(0, len(outputs)): + outputs[index] = os.path.abspath(outputs[index]) + + output_dir = os.path.dirname(outputs[0]) + + # Look at the inputs and figure out which one is makevalues.pl and which are + # inputs to that script. + makevalues_input = None + in_files = [] + for input in inputs: + # Make input pathnames absolute so they can be accessed after changing + # directory. On Windows, convert \ to / for inputs to the perl script to + # work around the intermix of activepython + cygwin perl. + input_abs = os.path.abspath(input) + input_abs_posix = input_abs.replace(os.path.sep, posixpath.sep) + input_basename = os.path.basename(input) + if input_basename == 'makevalues.pl': + assert makevalues_input == None + makevalues_input = input_abs + elif input_basename.endswith('.in'): + in_files.append(input_abs_posix) + else: + assert False + + assert makevalues_input != None + assert len(in_files) >= 1 + + # Change to the output directory because makevalues.pl puts output in its + # working directory. + os.chdir(output_dir) + + # Merge all in_files into a single file whose name will be the same as the + # first listed in_file, but in the output directory. + merged_path = os.path.basename(in_files[0]) + merged = open(merged_path, 'wb') # 'wb' to get \n only on windows + + # Make sure there aren't any duplicate lines in the in files. Lowercase + # everything because CSS values are case-insensitive. + line_dict = {} + for in_file_path in in_files: + in_file = open(in_file_path) + for line in in_file: + line = line.rstrip() + if line.startswith('#'): + line = '' + if line == '': + continue + line = line.lower() + if line in line_dict: + raise KeyError, 'Duplicate value %s' % line + line_dict[line] = True + print >>merged, line + in_file.close() + + merged.close() + + # Build up the command. + command = ['perl', makevalues_input] + + # Do it. check_call is new in 2.5, so simulate its behavior with call and + # assert. + return_code = subprocess.call(command) + assert return_code == 0 + + # Don't leave behind the merged file or the .gperf file created by + # makevalues. + (root, ext) = os.path.splitext(merged_path) + gperf_path = root + '.gperf' + os.unlink(gperf_path) + os.unlink(merged_path) + + # Go through the outputs. Any output that belongs in a different directory + # is moved. Do a copy and delete instead of rename for maximum portability. + # Note that all paths used in this section are still absolute. + for output in outputs: + this_output_dir = os.path.dirname(output) + if this_output_dir != output_dir: + output_basename = os.path.basename(output) + src = os.path.join(output_dir, output_basename) + dst = os.path.join(this_output_dir, output_basename) + shutil.copyfile(src, dst) + os.unlink(src) + + return return_code + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) |