| OLD | NEW |
| 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 # |
| 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 $interfaceDependenciesFile; | 40 my $interfaceDependenciesFile; |
| 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 'interfaceDependenciesFile=s' => \$interfaceDependenciesFile, | 49 'interfaceDependenciesFile=s' => \$interfaceDependenciesFile, |
| 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 @dependencyIdlFiles; | 66 my @dependencyIdlFiles; |
| 79 if ($interfaceDependenciesFile) { | 67 if ($interfaceDependenciesFile) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 109 } | 97 } |
| 110 | 98 |
| 111 if (!$idlFound) { | 99 if (!$idlFound) { |
| 112 # We generate empty .h and .cpp files just to tell build scripts that .h
and .cpp files are created. | 100 # We generate empty .h and .cpp files just to tell build scripts that .h
and .cpp files are created. |
| 113 generateEmptyHeaderAndCpp($targetInterfaceName, $outputDirectory); | 101 generateEmptyHeaderAndCpp($targetInterfaceName, $outputDirectory); |
| 114 exit 0; | 102 exit 0; |
| 115 } | 103 } |
| 116 } | 104 } |
| 117 | 105 |
| 118 # Parse the target IDL file. | 106 # Parse the target IDL file. |
| 119 my $targetParser = IDLParser->new(!$verbose); | 107 my $targetParser = deprecated_idl_parser->new(!$verbose); |
| 120 my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocesso
r); | 108 my $targetDocument = $targetParser->Parse($targetIdlFile, $preprocessor); |
| 121 | 109 |
| 122 if ($idlAttributesFile) { | 110 if ($idlAttributesFile) { |
| 123 my $idlAttributes = loadIDLAttributes($idlAttributesFile); | 111 my $idlAttributes = loadIDLAttributes($idlAttributesFile); |
| 124 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile)
); | 112 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile)
); |
| 125 } | 113 } |
| 126 | 114 |
| 127 foreach my $idlFile (@dependencyIdlFiles) { | 115 foreach my $idlFile (@dependencyIdlFiles) { |
| 128 next if $idlFile eq $targetIdlFile; | 116 next if $idlFile eq $targetIdlFile; |
| 129 | 117 |
| 130 my $interfaceName = fileparse(basename($idlFile), ".idl"); | 118 my $interfaceName = fileparse(basename($idlFile), ".idl"); |
| 131 my $parser = IDLParser->new(!$verbose); | 119 my $parser = deprecated_idl_parser->new(!$verbose); |
| 132 my $document = $parser->Parse($idlFile, $defines, $preprocessor); | 120 my $document = $parser->Parse($idlFile, $preprocessor); |
| 133 | 121 |
| 134 foreach my $interface (@{$document->interfaces}) { | 122 foreach my $interface (@{$document->interfaces}) { |
| 135 if (!$interface->isPartial || $interface->name eq $targetInterfaceName)
{ | 123 if (!$interface->isPartial || $interface->name eq $targetInterfaceName)
{ |
| 136 my $targetDataNode; | 124 my $targetDataNode; |
| 137 foreach my $interface (@{$targetDocument->interfaces}) { | 125 foreach my $interface (@{$targetDocument->interfaces}) { |
| 138 if ($interface->name eq $targetInterfaceName) { | 126 if ($interface->name eq $targetInterfaceName) { |
| 139 $targetDataNode = $interface; | 127 $targetDataNode = $interface; |
| 140 last; | 128 last; |
| 141 } | 129 } |
| 142 } | 130 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 173 applyInterfaceExtendedAttributes($interface, $constant->extended
Attributes); | 161 applyInterfaceExtendedAttributes($interface, $constant->extended
Attributes); |
| 174 | 162 |
| 175 push(@{$targetDataNode->constants}, $constant); | 163 push(@{$targetDataNode->constants}, $constant); |
| 176 } | 164 } |
| 177 } else { | 165 } else { |
| 178 die "$idlFile is not a dependency of $targetIdlFile. There maybe a b
ug in the dependency computer (compute_dependencies.py).\n"; | 166 die "$idlFile is not a dependency of $targetIdlFile. There maybe a b
ug in the dependency computer (compute_dependencies.py).\n"; |
| 179 } | 167 } |
| 180 } | 168 } |
| 181 } | 169 } |
| 182 | 170 |
| 183 # FIXME: This code will be removed once IDLParser.pm and CodeGeneratorV8.pm | 171 # Serialize to and from JSON to ensure Perl and Python parsers are equivalent, |
| 184 # are connected via JSON files. See http://crbug.com/242795 | 172 # as part of porting compiler to Python. See http://crbug.com/242795 |
| 185 $targetDocument = deserializeJSON(serializeJSON($targetDocument)); | 173 $targetDocument = deserializeJSON(serializeJSON($targetDocument)); |
| 186 | 174 |
| 187 # Generate desired output for the target IDL file. | 175 # Generate desired output for the target IDL file. |
| 188 my @interfaceIdlFiles = ($targetDocument->fileName(), @dependencyIdlFiles); | 176 my @interfaceIdlFiles = ($targetDocument->fileName(), @dependencyIdlFiles); |
| 189 my $codeGenerator = CodeGeneratorV8->new($targetDocument, \@idlDirectories, $pre
processor, $defines, $verbose, \@interfaceIdlFiles, $writeFileOnlyIfChanged); | 177 my $codeGenerator = deprecated_code_generator_v8->new($targetDocument, \@idlDire
ctories, $preprocessor, $verbose, \@interfaceIdlFiles, $writeFileOnlyIfChanged); |
| 190 my $interfaces = $targetDocument->interfaces; | 178 my $interfaces = $targetDocument->interfaces; |
| 191 foreach my $interface (@$interfaces) { | 179 foreach my $interface (@$interfaces) { |
| 192 print "Generating bindings code for IDL interface \"" . $interface->name . "
\"...\n" if $verbose; | 180 print "Generating bindings code for IDL interface \"" . $interface->name . "
\"...\n" if $verbose; |
| 193 $codeGenerator->GenerateInterface($interface); | 181 $codeGenerator->GenerateInterface($interface); |
| 194 $codeGenerator->WriteData($interface, $outputDirectory); | 182 $codeGenerator->WriteData($interface, $outputDirectory); |
| 195 } | 183 } |
| 196 | 184 |
| 197 sub generateEmptyHeaderAndCpp | 185 sub generateEmptyHeaderAndCpp |
| 198 { | 186 { |
| 199 my ($targetInterfaceName, $outputDirectory) = @_; | 187 my ($targetInterfaceName, $outputDirectory) = @_; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 last OUTER; | 290 last OUTER; |
| 303 } | 291 } |
| 304 } | 292 } |
| 305 } | 293 } |
| 306 if ($error) { | 294 if ($error) { |
| 307 die "IDL ATTRIBUTE CHECKER ERROR: $error | 295 die "IDL ATTRIBUTE CHECKER ERROR: $error |
| 308 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). | 296 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). |
| 309 "; | 297 "; |
| 310 } | 298 } |
| 311 } | 299 } |
| OLD | NEW |