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

Side by Side Diff: Source/bindings/scripts/deprecated_generate_bindings.pl

Issue 18190004: Add Python flow to bindings generation, move dummy-generating IDL files over (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revised Created 7 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/perl -w 1 #!/usr/bin/perl -w
2 # 2 #
3 # Copyright (C) 2005 Apple Computer, Inc. 3 # Copyright (C) 2005 Apple Computer, Inc.
4 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> 4 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
5 # 5 #
Nils Barth (inactive) 2013/07/09 08:48:16 Presubmit check complained about trailing whitespa
6 # This file is part of WebKit 6 # This file is part of WebKit
7 # 7 #
8 # This library is free software; you can redistribute it and/or 8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Library General Public 9 # modify it under the terms of the GNU Library General Public
10 # License as published by the Free Software Foundation; either 10 # License as published by the Free Software Foundation; either
11 # version 2 of the License, or (at your option) any later version. 11 # version 2 of the License, or (at your option) any later version.
12 # 12 #
13 # This library is distributed in the hope that it will be useful, 13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Library General Public License for more details. 16 # Library General Public License for more details.
17 # 17 #
18 # You should have received a copy of the GNU Library General Public License 18 # You should have received a copy of the GNU Library General Public License
19 # along with this library; see the file COPYING.LIB. If not, write to 19 # along with this library; see the file COPYING.LIB. If not, write to
20 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 # Boston, MA 02110-1301, USA. 21 # Boston, MA 02110-1301, USA.
22 # 22 #
23
24 # This script is a temporary hack.
25 # Files are generated in the source directory, when they really should go
26 # to the DerivedSources directory.
27 # This should also eventually be a build rule driven off of .idl files
28 # however a build rule only solution is blocked by several radars:
29 # <rdar://problems/4251781&4251785>
30 23
31 use strict; 24 use strict;
32 25
33 use File::Path; 26 use File::Path;
34 use File::Basename; 27 use File::Basename;
35 use Getopt::Long; 28 use Getopt::Long;
36 use Text::ParseWords; 29 use Text::ParseWords;
37 use Cwd; 30 use Cwd;
38 31
39 use IDLParser; 32 use deprecated_idl_parser;
40 use CodeGeneratorV8; 33 use deprecated_code_generator_v8;
41 use IDLSerializer; 34 use deprecated_idl_serializer;
42 35
43 my @idlDirectories; 36 my @idlDirectories;
44 my $outputDirectory; 37 my $outputDirectory;
45 my $defines;
46 my $filename;
47 my $preprocessor; 38 my $preprocessor;
48 my $verbose; 39 my $verbose;
49 my $supplementalDependencyFile; 40 my $supplementalDependencyFile;
50 my $additionalIdlFiles; 41 my $additionalIdlFiles;
51 my $idlAttributesFile; 42 my $idlAttributesFile;
52 my $writeFileOnlyIfChanged; 43 my $writeFileOnlyIfChanged;
53 44
54 GetOptions('include=s@' => \@idlDirectories, 45 GetOptions('include=s@' => \@idlDirectories,
55 'outputDir=s' => \$outputDirectory, 46 'outputDir=s' => \$outputDirectory,
56 'defines=s' => \$defines,
57 'filename=s' => \$filename,
58 'preprocessor=s' => \$preprocessor, 47 'preprocessor=s' => \$preprocessor,
59 'verbose' => \$verbose, 48 'verbose' => \$verbose,
60 'supplementalDependencyFile=s' => \$supplementalDependencyFile, 49 'supplementalDependencyFile=s' => \$supplementalDependencyFile,
61 'additionalIdlFiles=s' => \$additionalIdlFiles, 50 'additionalIdlFiles=s' => \$additionalIdlFiles,
62 'idlAttributesFile=s' => \$idlAttributesFile, 51 'idlAttributesFile=s' => \$idlAttributesFile,
63 'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged); 52 'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged);
64 53
65 my $targetIdlFile = $ARGV[0]; 54 my $targetIdlFile = $ARGV[0];
66 55
67 die('Must specify input file.') unless defined($targetIdlFile); 56 die('Must specify input file.') unless defined($targetIdlFile);
68 die('Must specify output directory.') unless defined($outputDirectory); 57 die('Must specify output directory.') unless defined($outputDirectory);
69 $defines = "" unless defined($defines);
70 58
71 $targetIdlFile = Cwd::realpath($targetIdlFile); 59 $targetIdlFile = Cwd::realpath($targetIdlFile);
72 if ($verbose) { 60 if ($verbose) {
73 print "$targetIdlFile\n"; 61 print "$targetIdlFile\n";
74 } 62 }
75 my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl"); 63 my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl");
76 64
77 my $idlFound = 0; 65 my $idlFound = 0;
78 my @supplementedIdlFiles; 66 my @supplementedIdlFiles;
79 if ($supplementalDependencyFile) { 67 if ($supplementalDependencyFile) {
(...skipping 28 matching lines...) Expand all
108 } 96 }
109 97
110 if (!$idlFound) { 98 if (!$idlFound) {
111 # We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created. 99 # We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created.
112 generateEmptyHeaderAndCpp($targetInterfaceName, $outputDirectory); 100 generateEmptyHeaderAndCpp($targetInterfaceName, $outputDirectory);
113 exit 0; 101 exit 0;
114 } 102 }
115 } 103 }
116 104
117 # Parse the target IDL file. 105 # Parse the target IDL file.
118 my $targetParser = IDLParser->new(!$verbose); 106 my $targetParser = deprecated_idl_parser->new(!$verbose);
119 my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocesso r); 107 my $targetDocument = $targetParser->Parse($targetIdlFile, $preprocessor);
120 108
121 if ($idlAttributesFile) { 109 if ($idlAttributesFile) {
122 my $idlAttributes = loadIDLAttributes($idlAttributesFile); 110 my $idlAttributes = loadIDLAttributes($idlAttributesFile);
123 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile) ); 111 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile) );
124 } 112 }
125 113
126 foreach my $idlFile (@supplementedIdlFiles) { 114 foreach my $idlFile (@supplementedIdlFiles) {
127 next if $idlFile eq $targetIdlFile; 115 next if $idlFile eq $targetIdlFile;
128 116
129 my $interfaceName = fileparse(basename($idlFile), ".idl"); 117 my $interfaceName = fileparse(basename($idlFile), ".idl");
130 my $parser = IDLParser->new(!$verbose); 118 my $parser = deprecated_idl_parser->new(!$verbose);
131 my $document = $parser->Parse($idlFile, $defines, $preprocessor); 119 my $document = $parser->Parse($idlFile, $preprocessor);
132 120
133 foreach my $interface (@{$document->interfaces}) { 121 foreach my $interface (@{$document->interfaces}) {
134 if (!$interface->isPartial || $interface->name eq $targetInterfaceName) { 122 if (!$interface->isPartial || $interface->name eq $targetInterfaceName) {
135 my $targetDataNode; 123 my $targetDataNode;
136 foreach my $interface (@{$targetDocument->interfaces}) { 124 foreach my $interface (@{$targetDocument->interfaces}) {
137 if ($interface->name eq $targetInterfaceName) { 125 if ($interface->name eq $targetInterfaceName) {
138 $targetDataNode = $interface; 126 $targetDataNode = $interface;
139 last; 127 last;
140 } 128 }
141 } 129 }
(...skipping 30 matching lines...) Expand all
172 applyInterfaceExtendedAttributes($interface, $constant->extended Attributes); 160 applyInterfaceExtendedAttributes($interface, $constant->extended Attributes);
173 161
174 push(@{$targetDataNode->constants}, $constant); 162 push(@{$targetDataNode->constants}, $constant);
175 } 163 }
176 } else { 164 } else {
177 die "$idlFile is not a supplemental dependency of $targetIdlFile. Th ere maybe a bug in the the supplemental dependency generator (preprocess_idls.py ).\n"; 165 die "$idlFile is not a supplemental dependency of $targetIdlFile. Th ere maybe a bug in the the supplemental dependency generator (preprocess_idls.py ).\n";
178 } 166 }
179 } 167 }
180 } 168 }
181 169
182 # FIXME: This code will be removed once IDLParser.pm and CodeGeneratorV8.pm 170 # Serialize to and from JSON to ensure Perl and Python parsers are equivalent,
183 # are connected via JSON files. See http://crbug.com/242795 171 # as part of porting compiler to Python. See http://crbug.com/242795
184 $targetDocument = deserializeJSON(serializeJSON($targetDocument)); 172 $targetDocument = deserializeJSON(serializeJSON($targetDocument));
185 173
186 # Generate desired output for the target IDL file. 174 # Generate desired output for the target IDL file.
187 my @dependentIdlFiles = ($targetDocument->fileName(), @supplementedIdlFiles); 175 my @dependentIdlFiles = ($targetDocument->fileName(), @supplementedIdlFiles);
188 my $codeGenerator = CodeGeneratorV8->new($targetDocument, \@idlDirectories, $pre processor, $defines, $verbose, \@dependentIdlFiles, $writeFileOnlyIfChanged); 176 my $codeGenerator = deprecated_code_generator_v8->new($targetDocument, \@idlDire ctories, $preprocessor, $verbose, \@dependentIdlFiles, $writeFileOnlyIfChanged);
189 my $interfaces = $targetDocument->interfaces; 177 my $interfaces = $targetDocument->interfaces;
190 foreach my $interface (@$interfaces) { 178 foreach my $interface (@$interfaces) {
191 print "Generating bindings code for IDL interface \"" . $interface->name . " \"...\n" if $verbose; 179 print "Generating bindings code for IDL interface \"" . $interface->name . " \"...\n" if $verbose;
192 $codeGenerator->GenerateInterface($interface); 180 $codeGenerator->GenerateInterface($interface);
193 $codeGenerator->WriteData($interface, $outputDirectory); 181 $codeGenerator->WriteData($interface, $outputDirectory);
194 } 182 }
195 183
196 sub generateEmptyHeaderAndCpp 184 sub generateEmptyHeaderAndCpp
197 { 185 {
198 my ($targetInterfaceName, $outputDirectory) = @_; 186 my ($targetInterfaceName, $outputDirectory) = @_;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 last OUTER; 289 last OUTER;
302 } 290 }
303 } 291 }
304 } 292 }
305 if ($error) { 293 if ($error) {
306 die "IDL ATTRIBUTE CHECKER ERROR: $error 294 die "IDL ATTRIBUTE CHECKER ERROR: $error
307 If you want to add a new IDL attribute, you need to add it to bindings/scripts/I DLAttributes.txt and add explanations to the Blink IDL document (http://chromium .org/blink/webidl). 295 If you want to add a new IDL attribute, you need to add it to bindings/scripts/I DLAttributes.txt and add explanations to the Blink IDL document (http://chromium .org/blink/webidl).
308 "; 296 ";
309 } 297 }
310 } 298 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698