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

Side by Side Diff: webkit/build/rule_binding.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/build/action_useragentstylesheets.py ('k') | webkit/build/rule_bison.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:executable
+ *
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 # usage: rule_binding.py INPUT CPPDIR HDIR -- INPUTS -- OPTIONS
8 #
9 # INPUT is an IDL file, such as Whatever.idl.
10 #
11 # CPPDIR is the directory into which V8Whatever.cpp will be placed. HDIR is
12 # the directory into which V8Whatever.h will be placed.
13 #
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.
16 #
17 # OPTIONS are passed as-is to generate-bindings.pl as additional arguments.
18
19
20 import errno
21 import os
22 import shutil
23 import subprocess
24 import sys
25
26
27 def SplitArgsIntoSections(args):
28 sections = []
29 while len(args) > 0:
30 if not '--' in args:
31 # If there is no '--' left, everything remaining is an entire section.
32 dashes = len(args)
33 else:
34 dashes = args.index('--')
35
36 sections.append(args[:dashes])
37
38 # Next time through the loop, look at everything after this '--'.
39 if dashes + 1 == len(args):
40 # If the '--' is at the end of the list, we won't come back through the
41 # loop again. Add an empty section now corresponding to the nothingness
42 # following the final '--'.
43 args = []
44 sections.append(args)
45 else:
46 args = args[dashes + 1:]
47
48 return sections
49
50
51 def main(args):
52 sections = SplitArgsIntoSections(args[1:])
53 assert len(sections) == 3
54 (base, inputs, options) = sections
55
56 assert len(base) == 3
57 input = base[0]
58 cppdir = base[1]
59 hdir = base[2]
60
61 assert len(inputs) > 1
62 generate_bindings = inputs[0]
63 perl_modules = inputs[1:]
64
65 include_dirs = []
66 for perl_module in perl_modules:
67 include_dir = os.path.dirname(perl_module)
68 if not include_dir in include_dirs:
69 include_dirs.append(include_dir)
70
71 # Build up the command.
72 command = ['perl', '-w']
73 for include_dir in include_dirs:
74 command.extend(['-I', include_dir])
75 command.append(generate_bindings)
76 command.extend(options)
77 command.extend(['--outputdir', cppdir, input])
78
79 # Do it. check_call is new in 2.5, so simulate its behavior with call and
80 # assert.
81 return_code = subprocess.call(command)
82 assert return_code == 0
83
84 # Both the .cpp and .h were generated in cppdir, but if hdir is different,
85 # the .h needs to move. Copy it instead of using os.rename for maximum
86 # portability in all cases.
87 if cppdir != hdir:
88 input_basename = os.path.basename(input)
89 (root, ext) = os.path.splitext(input_basename)
90 hname = 'V8%s.h' % root
91 hsrc = os.path.join(cppdir, hname)
92 hdst = os.path.join(hdir, hname)
93 shutil.copyfile(hsrc, hdst)
94 os.unlink(hsrc)
95
96 return return_code
97
98
99 if __name__ == '__main__':
100 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « webkit/build/action_useragentstylesheets.py ('k') | webkit/build/rule_bison.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698