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

Side by Side Diff: Source/bindings/scripts/generate-bindings.pl

Issue 16296004: JSON export/import in generate-bindings.pl (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: IDL: Perl to/from JSON export/import 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/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
(...skipping 20 matching lines...) Expand all
31 use strict; 31 use strict;
32 32
33 use File::Path; 33 use File::Path;
34 use File::Basename; 34 use File::Basename;
35 use Getopt::Long; 35 use Getopt::Long;
36 use Text::ParseWords; 36 use Text::ParseWords;
37 use Cwd; 37 use Cwd;
38 38
39 use IDLParser; 39 use IDLParser;
40 use CodeGeneratorV8; 40 use CodeGeneratorV8;
41 use IRToFromJSON qw(IRToJSON JSONToIR);
41 42
42 my @idlDirectories; 43 my @idlDirectories;
43 my $outputDirectory; 44 my $outputDirectory;
44 my $outputHeadersDirectory; 45 my $outputHeadersDirectory;
45 my $defines; 46 my $defines;
46 my $filename; 47 my $filename;
47 my $preprocessor; 48 my $preprocessor;
48 my $verbose; 49 my $verbose;
49 my $supplementalDependencyFile; 50 my $supplementalDependencyFile;
50 my $additionalIdlFiles; 51 my $additionalIdlFiles;
51 my $idlAttributesFile; 52 my $idlAttributesFile;
52 my $writeFileOnlyIfChanged; 53 my $writeFileOnlyIfChanged;
54 my $dumpJson = '';
55 my $compileJson = '';
53 56
54 GetOptions('include=s@' => \@idlDirectories, 57 GetOptions('include=s@' => \@idlDirectories,
55 'outputDir=s' => \$outputDirectory, 58 'outputDir=s' => \$outputDirectory,
56 'outputHeadersDir=s' => \$outputHeadersDirectory, 59 'outputHeadersDir=s' => \$outputHeadersDirectory,
57 'defines=s' => \$defines, 60 'defines=s' => \$defines,
58 'filename=s' => \$filename, 61 'filename=s' => \$filename,
59 'preprocessor=s' => \$preprocessor, 62 'preprocessor=s' => \$preprocessor,
60 'verbose' => \$verbose, 63 'verbose' => \$verbose,
61 'supplementalDependencyFile=s' => \$supplementalDependencyFile, 64 'supplementalDependencyFile=s' => \$supplementalDependencyFile,
62 'additionalIdlFiles=s' => \$additionalIdlFiles, 65 'additionalIdlFiles=s' => \$additionalIdlFiles,
63 'idlAttributesFile=s' => \$idlAttributesFile, 66 'idlAttributesFile=s' => \$idlAttributesFile,
64 'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged); 67 'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged,
68 'dump-json' => \$dumpJson,
69 'compile-json' => \$compileJson);
haraken 2013/06/12 03:20:21 Are these options needed?
Nils Barth (inactive) 2013/06/12 03:57:43 Already removed in Patch Set 5. We can make the b
65 70
66 my $targetIdlFile = $ARGV[0]; 71 my $targetIdlFile = $ARGV[0];
67 72
68 die('Must specify input file.') unless defined($targetIdlFile); 73 die('Must specify input file.') unless defined($targetIdlFile);
69 die('Must specify output directory.') unless defined($outputDirectory); 74 die('Must specify output directory.') unless defined($outputDirectory);
70 $defines = "" unless defined($defines); 75 $defines = "" unless defined($defines);
71 76
72 if (!$outputHeadersDirectory) { 77 if (!$outputHeadersDirectory) {
73 $outputHeadersDirectory = $outputDirectory; 78 $outputHeadersDirectory = $outputDirectory;
74 } 79 }
75 $targetIdlFile = Cwd::realpath($targetIdlFile); 80 $targetIdlFile = Cwd::realpath($targetIdlFile);
76 if ($verbose) { 81 if ($verbose) {
77 print "$targetIdlFile\n"; 82 print "$targetIdlFile\n";
78 } 83 }
79 my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl"); 84 my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl");
85 my $jsonFilename = "${targetInterfaceName}.json";
80 86
81 my $idlFound = 0; 87 my $idlFound = 0;
82 my @supplementedIdlFiles; 88 my @supplementedIdlFiles;
83 if ($supplementalDependencyFile) { 89 if ($supplementalDependencyFile) {
84 # The format of a supplemental dependency file: 90 # The format of a supplemental dependency file:
85 # 91 #
86 # DOMWindow.idl P.idl Q.idl R.idl 92 # DOMWindow.idl P.idl Q.idl R.idl
87 # Document.idl S.idl 93 # Document.idl S.idl
88 # Event.idl 94 # Event.idl
89 # ... 95 # ...
(...skipping 19 matching lines...) Expand all
109 $idlFound = grep { $_ and basename($_) eq basename($targetIdlFile) } @id lFiles; 115 $idlFound = grep { $_ and basename($_) eq basename($targetIdlFile) } @id lFiles;
110 } 116 }
111 117
112 if (!$idlFound) { 118 if (!$idlFound) {
113 # We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created. 119 # We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created.
114 generateEmptyHeaderAndCpp($targetInterfaceName, $outputHeadersDirectory, $outputDirectory); 120 generateEmptyHeaderAndCpp($targetInterfaceName, $outputHeadersDirectory, $outputDirectory);
115 exit 0; 121 exit 0;
116 } 122 }
117 } 123 }
118 124
125 my $targetDocument;
dominicc (has gone to gerrit) 2013/06/11 22:56:30 Can we instead wrap up the thing that sources the
Nils Barth (inactive) 2013/06/12 02:56:12 For now removed --dump-json/--compile-json from ge
126 if ($compileJson) {
127 open FH, "< ${outputDirectory}/${jsonFilename}" or die "Cannot open $jsonFil ename\n";
128 my @jsonLines = <FH>;
129 close FH;
130 my $jsonContents = join('', @jsonLines);
131 $targetDocument = JSONToIR($jsonContents);
132 goto COMPILE;
haraken 2013/06/12 03:20:21 You can make this change in the next CL.
Nils Barth (inactive) 2013/06/12 03:57:43 Yes, that's what we're doing.
133 }
134
119 # Parse the target IDL file. 135 # Parse the target IDL file.
120 my $targetParser = IDLParser->new(!$verbose); 136 my $targetParser = IDLParser->new(!$verbose);
121 my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocesso r); 137 $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocessor);
122 138
123 if ($idlAttributesFile) { 139 if ($idlAttributesFile) {
124 my $idlAttributes = loadIDLAttributes($idlAttributesFile); 140 my $idlAttributes = loadIDLAttributes($idlAttributesFile);
125 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile) ); 141 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile) );
126 } 142 }
127 143
128 foreach my $idlFile (@supplementedIdlFiles) { 144 foreach my $idlFile (@supplementedIdlFiles) {
129 next if $idlFile eq $targetIdlFile; 145 next if $idlFile eq $targetIdlFile;
130 146
131 my $interfaceName = fileparse(basename($idlFile), ".idl"); 147 my $interfaceName = fileparse(basename($idlFile), ".idl");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 $constant->extendedAttributes->{$extendedAttributeName} = $i nterface->extendedAttributes->{$extendedAttributeName}; 193 $constant->extendedAttributes->{$extendedAttributeName} = $i nterface->extendedAttributes->{$extendedAttributeName};
178 } 194 }
179 push(@{$targetDataNode->constants}, $constant); 195 push(@{$targetDataNode->constants}, $constant);
180 } 196 }
181 } else { 197 } else {
182 die "$idlFile is not a supplemental dependency of $targetIdlFile. Th ere maybe a bug in the the supplemental dependency generator (preprocess_idls.py ).\n"; 198 die "$idlFile is not a supplemental dependency of $targetIdlFile. Th ere maybe a bug in the the supplemental dependency generator (preprocess_idls.py ).\n";
183 } 199 }
184 } 200 }
185 } 201 }
186 202
203 # If dumping JSON, generate JSON output and exit
dominicc (has gone to gerrit) 2013/06/11 22:56:30 I will say this again, but I think you should do t
Nils Barth (inactive) 2013/06/12 02:56:12 Removed.
haraken 2013/06/12 03:20:21 Yes, this should be in the next CL.
Nils Barth (inactive) 2013/06/12 03:57:43 ACK.
204 if ($dumpJson) {
205 my $jsonText = IRToJSON($targetDocument);
206 open FH, "> ${outputDirectory}/${jsonFilename}" or die "Cannot open $jsonFil ename\n";
207 print FH $jsonText;
208 close FH;
209 exit 0;
210 }
211
212 # Roundtrip to/from JSON to verify code
haraken 2013/06/12 03:20:21 Instead you can say: # FIXME: This code will be s
Nils Barth (inactive) 2013/06/12 03:57:43 Done.
213 $targetDocument = JSONToIR(IRToJSON($targetDocument));
214
187 # Generate desired output for the target IDL file. 215 # Generate desired output for the target IDL file.
216 COMPILE:
188 my @dependentIdlFiles = ($targetDocument->fileName(), @supplementedIdlFiles); 217 my @dependentIdlFiles = ($targetDocument->fileName(), @supplementedIdlFiles);
189 my $codeGenerator = CodeGeneratorV8->new($targetDocument, \@idlDirectories, $pre processor, $defines, $verbose, \@dependentIdlFiles, $writeFileOnlyIfChanged); 218 my $codeGenerator = CodeGeneratorV8->new($targetDocument, \@idlDirectories, $pre processor, $defines, $verbose, \@dependentIdlFiles, $writeFileOnlyIfChanged);
190 my $interfaces = $targetDocument->interfaces; 219 my $interfaces = $targetDocument->interfaces;
191 foreach my $interface (@$interfaces) { 220 foreach my $interface (@$interfaces) {
192 print "Generating bindings code for IDL interface \"" . $interface->name . " \"...\n" if $verbose; 221 print "Generating bindings code for IDL interface \"" . $interface->name . " \"...\n" if $verbose;
193 $codeGenerator->GenerateInterface($interface); 222 $codeGenerator->GenerateInterface($interface);
194 $codeGenerator->WriteData($interface, $outputDirectory, $outputHeadersDirect ory); 223 $codeGenerator->WriteData($interface, $outputDirectory, $outputHeadersDirect ory);
195 } 224 }
196 225
197 sub generateEmptyHeaderAndCpp 226 sub generateEmptyHeaderAndCpp
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 last OUTER; 320 last OUTER;
292 } 321 }
293 } 322 }
294 } 323 }
295 if ($error) { 324 if ($error) {
296 die "IDL ATTRIBUTE CHECKER ERROR: $error 325 die "IDL ATTRIBUTE CHECKER ERROR: $error
297 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). 326 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).
298 "; 327 ";
299 } 328 }
300 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698