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

Side by Side Diff: Source/bindings/scripts/idl-to-json.pl

Issue 15959019: Rewrite generate-bindings.pl in Python (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/perl -w -I../../core/scripts
2 # Copyright (C) 2013 Google Inc. All rights reserved. 2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer 11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the 12 # in the documentation and/or other materials provided with the
13 # distribution. 13 # distribution.
14 # * Neither the name of Google Inc. nor the names of its 14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from 15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission. 16 # this software without specific prior written permission.
17 # 17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 import os.path
31 import sys
32 30
33 import in_generator 31 # Wrapper script to parse a file and dump to stdout as JSON
34 import make_runtime_features
35 32
33 use strict;
34 use warnings;
36 35
37 # We want exactly the same parsing as RuntimeFeatureWriter 36 use Cwd;
38 # but generate different files. 37 use Getopt::Long;
39 class InternalRuntimeFlagsWriter(make_runtime_features.RuntimeFeatureWriter): 38 use JSON -convert_blessed_universally; # IDLParser returns blessed objects
40 class_name = "InternalRuntimeFlags"
41 39
42 def generate_idl(self): 40 use IDLParser;
43 return {
44 'features': self._features,
45 }
46 41
47 def generate_header(self): 42 # Get options
48 return { 43 my $defines;
49 'features': self._features, 44 my $preprocessor;
50 'feature_sets': self._feature_sets(), 45 my $verbose;
51 }
52 46
53 def generate_implementation(self): 47 GetOptions('defines=s' => \$defines,
54 return None 48 'preprocessor=s' => \$preprocessor,
49 'verbose' => \$verbose);
55 50
51 my $targetIdlFile = $ARGV[0];
56 52
57 if __name__ == "__main__": 53 $defines = "" unless defined($defines);
58 in_generator.Maker(InternalRuntimeFlagsWriter).main(sys.argv) 54 die('Must specify input file.') unless defined($targetIdlFile);
55 $targetIdlFile = Cwd::realpath($targetIdlFile);
56
57 if ($verbose) {
58 print "$targetIdlFile\n";
59 }
60
61 # Parse file
62 my $targetParser = IDLParser->new(!$verbose);
63 my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocesso r);
64
65 # Convert to JSON
66 my $json = JSON->new->utf8;
67 $json = $json->allow_blessed->convert_blessed();
68 my $json_text= $json->encode($targetDocument);
69 print $json_text . "\n";
OLDNEW
« no previous file with comments | « Source/bindings/scripts/generate_bindings.py ('k') | Source/bindings/scripts/interface_merger.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698