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

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

Issue 149207: Proper fix for the "thousands of macro names must be identifiers" bug.... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: Removed obsolete comment. Created 11 years, 5 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # usage: rule_binding.py INPUT CPPDIR HDIR -- INPUTS -- OPTIONS 7 # usage: rule_binding.py INPUT CPPDIR HDIR -- INPUTS -- OPTIONS
8 # 8 #
9 # INPUT is an IDL file, such as Whatever.idl. 9 # INPUT is an IDL file, such as Whatever.idl.
10 # 10 #
11 # CPPDIR is the directory into which V8Whatever.cpp will be placed. HDIR is 11 # CPPDIR is the directory into which V8Whatever.cpp will be placed. HDIR is
12 # the directory into which V8Whatever.h will be placed. 12 # the directory into which V8Whatever.h will be placed.
13 # 13 #
14 # The first item in INPUTS is the path to generate-bindings.pl. Remaining 14 # The first item in INPUTS is the path to generate-bindings.pl. Remaining
15 # items in INPUTS are used to build the Perl module include path. 15 # items in INPUTS are used to build the Perl module include path.
16 # 16 #
17 # OPTIONS are passed as-is to generate-bindings.pl as additional arguments. 17 # OPTIONS are passed as-is to generate-bindings.pl as additional arguments.
18 18
19 19
20 import errno 20 import errno
21 import os 21 import os
22 import shlex
22 import shutil 23 import shutil
23 import subprocess 24 import subprocess
24 import sys 25 import sys
25 26
26 27
27 def SplitArgsIntoSections(args): 28 def SplitArgsIntoSections(args):
28 sections = [] 29 sections = []
29 while len(args) > 0: 30 while len(args) > 0:
30 if not '--' in args: 31 if not '--' in args:
31 # If there is no '--' left, everything remaining is an entire section. 32 # If there is no '--' left, everything remaining is an entire section.
(...skipping 29 matching lines...) Expand all
61 assert len(inputs) > 1 62 assert len(inputs) > 1
62 generate_bindings = inputs[0] 63 generate_bindings = inputs[0]
63 perl_modules = inputs[1:] 64 perl_modules = inputs[1:]
64 65
65 include_dirs = [] 66 include_dirs = []
66 for perl_module in perl_modules: 67 for perl_module in perl_modules:
67 include_dir = os.path.dirname(perl_module) 68 include_dir = os.path.dirname(perl_module)
68 if not include_dir in include_dirs: 69 if not include_dir in include_dirs:
69 include_dirs.append(include_dir) 70 include_dirs.append(include_dir)
70 71
72 # The defines come in as one flat string. Split it up into distinct arguments.
73 if '--defines' in options:
74 defines_index = options.index('--defines')
75 if defines_index + 1 < len(options):
76 split_options = shlex.split(options[defines_index + 1])
77 if split_options:
78 options[defines_index + 1:defines_index + 2] = \
Mark Mentovai 2009/07/06 18:26:47 If we're just doing ' '.join, you don't need to sp
79 [' '.join(split_options)]
80
71 # Build up the command. 81 # Build up the command.
72 command = ['perl', '-w'] 82 command = ['perl', '-w']
73 for include_dir in include_dirs: 83 for include_dir in include_dirs:
74 command.extend(['-I', include_dir]) 84 command.extend(['-I', include_dir])
75 command.append(generate_bindings) 85 command.append(generate_bindings)
76 # Remove any qouble qoutes that may have gotten in here. We know that none of 86 command.extend(options)
77 # the options will have meaningful double qoutes.
78 command.extend([option.replace('"', '') for option in options])
79 command.extend(['--outputDir', cppdir, input]) 87 command.extend(['--outputDir', cppdir, input])
80 88
81 # Do it. check_call is new in 2.5, so simulate its behavior with call and 89 # Do it. check_call is new in 2.5, so simulate its behavior with call and
82 # assert. 90 # assert.
83 return_code = subprocess.call(command) 91 return_code = subprocess.call(command)
84 assert return_code == 0 92 assert return_code == 0
85 93
86 # Both the .cpp and .h were generated in cppdir, but if hdir is different, 94 # Both the .cpp and .h were generated in cppdir, but if hdir is different,
87 # the .h needs to move. Copy it instead of using os.rename for maximum 95 # the .h needs to move. Copy it instead of using os.rename for maximum
88 # portability in all cases. 96 # portability in all cases.
89 if cppdir != hdir: 97 if cppdir != hdir:
90 input_basename = os.path.basename(input) 98 input_basename = os.path.basename(input)
91 (root, ext) = os.path.splitext(input_basename) 99 (root, ext) = os.path.splitext(input_basename)
92 hname = 'V8%s.h' % root 100 hname = 'V8%s.h' % root
93 hsrc = os.path.join(cppdir, hname) 101 hsrc = os.path.join(cppdir, hname)
94 hdst = os.path.join(hdir, hname) 102 hdst = os.path.join(hdir, hname)
95 shutil.copyfile(hsrc, hdst) 103 shutil.copyfile(hsrc, hdst)
96 os.unlink(hsrc) 104 os.unlink(hsrc)
97 105
98 return return_code 106 return return_code
99 107
100 108
101 if __name__ == '__main__': 109 if __name__ == '__main__':
102 sys.exit(main(sys.argv)) 110 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698