Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Side by Side Diff: webkit/build/action_csspropertynames.py

Issue 27158: Import .gyp files into the Chromium tree (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webkit/activex_shim_dll/activex_shim_dll.gyp ('k') | webkit/build/action_cssvaluekeywords.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 # action_csspropertynames.py is a harness script to connect actions sections of
8 # gyp-based builds to makeprop.pl.
9 #
10 # usage: action_makenames.py OUTPUTS -- INPUTS
11 #
12 # Exactly two outputs must be specified: a path to each of CSSPropertyNames.cpp
13 # and CSSPropertyNames.h.
14 #
15 # Multiple inputs may be specified. One input must have a basename of
16 # makeprop.pl; this is taken as the path to makeprop.pl. All other inputs are
17 # paths to .in files that are used as input to makeprop.pl; at least one,
18 # CSSPropertyNames.in, is required.
19
20
21 import os
22 import posixpath
23 import shutil
24 import subprocess
25 import sys
26
27
28 def SplitArgsIntoSections(args):
29 sections = []
30 while len(args) > 0:
31 if not '--' in args:
32 # If there is no '--' left, everything remaining is an entire section.
33 dashes = len(args)
34 else:
35 dashes = args.index('--')
36
37 sections.append(args[:dashes])
38
39 # Next time through the loop, look at everything after this '--'.
40 if dashes + 1 == len(args):
41 # If the '--' is at the end of the list, we won't come back through the
42 # loop again. Add an empty section now corresponding to the nothingness
43 # following the final '--'.
44 args = []
45 sections.append(args)
46 else:
47 args = args[dashes + 1:]
48
49 return sections
50
51
52 def main(args):
53 (outputs, inputs) = SplitArgsIntoSections(args[1:])
54
55 # Make all output pathnames absolute so that they can be accessed after
56 # changing directory.
57 for index in xrange(0, len(outputs)):
58 outputs[index] = os.path.abspath(outputs[index])
59
60 output_dir = os.path.dirname(outputs[0])
61
62 # Look at the inputs and figure out which one is makeprop.pl and which are
63 # inputs to that script.
64 makeprop_input = None
65 in_files = []
66 for input in inputs:
67 # Make input pathnames absolute so they can be accessed after changing
68 # directory. On Windows, convert \ to / for inputs to the perl script to
69 # work around the intermix of activepython + cygwin perl.
70 input_abs = os.path.abspath(input)
71 input_abs_posix = input_abs.replace(os.path.sep, posixpath.sep)
72 input_basename = os.path.basename(input)
73 if input_basename == 'makeprop.pl':
74 assert makeprop_input == None
75 makeprop_input = input_abs
76 elif input_basename.endswith('.in'):
77 in_files.append(input_abs_posix)
78 else:
79 assert False
80
81 assert makeprop_input != None
82 assert len(in_files) >= 1
83
84 # Change to the output directory because makeprop.pl puts output in its
85 # working directory.
86 os.chdir(output_dir)
87
88 # Merge all in_files into a single file whose name will be the same as the
89 # first listed in_file, but in the output directory.
90 merged_path = os.path.basename(in_files[0])
91 merged = open(merged_path, 'wb') # 'wb' to get \n only on windows
92
93 # Make sure there aren't any duplicate lines in the in files.
94 line_dict = {}
95 for in_file_path in in_files:
96 in_file = open(in_file_path)
97 for line in in_file:
98 line = line.rstrip()
99 if line.startswith('#'):
100 line = ''
101 if line == '':
102 continue
103 if line in line_dict:
104 raise KeyError, 'Duplicate value %s' % line
105 line_dict[line] = True
106 print >>merged, line
107 in_file.close()
108
109 merged.close()
110
111 # Build up the command.
112 command = ['perl', makeprop_input]
113
114 # Do it. check_call is new in 2.5, so simulate its behavior with call and
115 # assert.
116 return_code = subprocess.call(command)
117 assert return_code == 0
118
119 # Don't leave behind the merged file or the .gperf file created by
120 # makeprop.
121 (root, ext) = os.path.splitext(merged_path)
122 gperf_path = root + '.gperf'
123 os.unlink(gperf_path)
124 os.unlink(merged_path)
125
126 # Go through the outputs. Any output that belongs in a different directory
127 # is moved. Do a copy and delete instead of rename for maximum portability.
128 # Note that all paths used in this section are still absolute.
129 for output in outputs:
130 this_output_dir = os.path.dirname(output)
131 if this_output_dir != output_dir:
132 output_basename = os.path.basename(output)
133 src = os.path.join(output_dir, output_basename)
134 dst = os.path.join(this_output_dir, output_basename)
135 shutil.copyfile(src, dst)
136 os.unlink(src)
137
138 return return_code
139
140
141 if __name__ == '__main__':
142 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « webkit/activex_shim_dll/activex_shim_dll.gyp ('k') | webkit/build/action_cssvaluekeywords.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698