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

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

Issue 18341025: Rename deprecated "supplemental_dependencies" and clean up IDL dependency script (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix exec 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 #
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 28 matching lines...) Expand all
39 use IDLParser; 39 use IDLParser;
40 use CodeGeneratorV8; 40 use CodeGeneratorV8;
41 use IDLSerializer; 41 use IDLSerializer;
42 42
43 my @idlDirectories; 43 my @idlDirectories;
44 my $outputDirectory; 44 my $outputDirectory;
45 my $defines; 45 my $defines;
46 my $filename; 46 my $filename;
47 my $preprocessor; 47 my $preprocessor;
48 my $verbose; 48 my $verbose;
49 my $supplementalDependencyFile; 49 my $interfaceDependenciesFile;
50 my $additionalIdlFiles; 50 my $additionalIdlFiles;
51 my $idlAttributesFile; 51 my $idlAttributesFile;
52 my $writeFileOnlyIfChanged; 52 my $writeFileOnlyIfChanged;
53 53
54 GetOptions('include=s@' => \@idlDirectories, 54 GetOptions('include=s@' => \@idlDirectories,
55 'outputDir=s' => \$outputDirectory, 55 'outputDir=s' => \$outputDirectory,
56 'defines=s' => \$defines, 56 'defines=s' => \$defines,
57 'filename=s' => \$filename, 57 'filename=s' => \$filename,
58 'preprocessor=s' => \$preprocessor, 58 'preprocessor=s' => \$preprocessor,
59 'verbose' => \$verbose, 59 'verbose' => \$verbose,
60 'supplementalDependencyFile=s' => \$supplementalDependencyFile, 60 'interfaceDependenciesFile=s' => \$interfaceDependenciesFile,
61 'additionalIdlFiles=s' => \$additionalIdlFiles, 61 'additionalIdlFiles=s' => \$additionalIdlFiles,
62 'idlAttributesFile=s' => \$idlAttributesFile, 62 'idlAttributesFile=s' => \$idlAttributesFile,
63 'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged); 63 'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged);
64 64
65 my $targetIdlFile = $ARGV[0]; 65 my $targetIdlFile = $ARGV[0];
66 66
67 die('Must specify input file.') unless defined($targetIdlFile); 67 die('Must specify input file.') unless defined($targetIdlFile);
68 die('Must specify output directory.') unless defined($outputDirectory); 68 die('Must specify output directory.') unless defined($outputDirectory);
69 $defines = "" unless defined($defines); 69 $defines = "" unless defined($defines);
70 70
71 $targetIdlFile = Cwd::realpath($targetIdlFile); 71 $targetIdlFile = Cwd::realpath($targetIdlFile);
72 if ($verbose) { 72 if ($verbose) {
73 print "$targetIdlFile\n"; 73 print "$targetIdlFile\n";
74 } 74 }
75 my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl"); 75 my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl");
76 76
77 my $idlFound = 0; 77 my $idlFound = 0;
78 my @supplementedIdlFiles; 78 my @dependencyIdlFiles;
79 if ($supplementalDependencyFile) { 79 if ($interfaceDependenciesFile) {
80 # The format of a supplemental dependency file: 80 # The format of the interface dependencies file:
81 # 81 #
82 # Window.idl P.idl Q.idl R.idl 82 # Window.idl P.idl Q.idl R.idl
83 # Document.idl S.idl 83 # Document.idl S.idl
84 # Event.idl 84 # Event.idl
85 # ... 85 # ...
86 # 86 #
87 # The above indicates that Window.idl is supplemented by P.idl, Q.idl and R. idl, 87 # The above indicates that Window.idl depends on P.idl, Q.idl, and R.idl,
88 # Document.idl is supplemented by S.idl, and Event.idl is supplemented by no IDLs. 88 # Document.idl depends on S.idl, and Event.idl depends on no IDLs.
89 # The IDL that supplements another IDL (e.g. P.idl) never appears in the dep endency file. 89 # A dependency IDL file (one that is depended on by another IDL, e.g. P.idl
90 open FH, "< $supplementalDependencyFile" or die "Cannot open $supplementalDe pendencyFile\n"; 90 # in the above) does not have its own entry in the dependency file.
91 open FH, "< $interfaceDependenciesFile" or die "Cannot open $interfaceDepend enciesFile\n";
91 while (my $line = <FH>) { 92 while (my $line = <FH>) {
92 my ($idlFile, @followingIdlFiles) = split(/\s+/, $line); 93 my ($idlFile, @followingIdlFiles) = split(/\s+/, $line);
93 if ($idlFile and basename($idlFile) eq basename($targetIdlFile)) { 94 if ($idlFile and basename($idlFile) eq basename($targetIdlFile)) {
94 $idlFound = 1; 95 $idlFound = 1;
95 # We sort the supplemental IDL files so that the corresponding code is generated 96 # We sort the dependency IDL files so that the corresponding code is generated
96 # in a consistent order. This is important for the bindings tests. 97 # in a consistent order. This is important for the bindings tests.
97 @supplementedIdlFiles = sort @followingIdlFiles; 98 @dependencyIdlFiles = sort @followingIdlFiles;
98 } 99 }
99 } 100 }
100 close FH; 101 close FH;
101 102
102 # $additionalIdlFiles is list of IDL files which should not be included in 103 # $additionalIdlFiles is list of IDL files which should not be included in
103 # DerivedSources*.cpp (i.e. they are not described in the supplemental 104 # DerivedSources*.cpp (i.e. they are not described in the interface
104 # dependency file) but should generate .h and .cpp files. 105 # dependencies file) but should generate .h and .cpp files.
105 if (!$idlFound and $additionalIdlFiles) { 106 if (!$idlFound and $additionalIdlFiles) {
106 my @idlFiles = shellwords($additionalIdlFiles); 107 my @idlFiles = shellwords($additionalIdlFiles);
107 $idlFound = grep { $_ and basename($_) eq basename($targetIdlFile) } @id lFiles; 108 $idlFound = grep { $_ and basename($_) eq basename($targetIdlFile) } @id lFiles;
108 } 109 }
109 110
110 if (!$idlFound) { 111 if (!$idlFound) {
111 # We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created. 112 # We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created.
112 generateEmptyHeaderAndCpp($targetInterfaceName, $outputDirectory); 113 generateEmptyHeaderAndCpp($targetInterfaceName, $outputDirectory);
113 exit 0; 114 exit 0;
114 } 115 }
115 } 116 }
116 117
117 # Parse the target IDL file. 118 # Parse the target IDL file.
118 my $targetParser = IDLParser->new(!$verbose); 119 my $targetParser = IDLParser->new(!$verbose);
119 my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocesso r); 120 my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocesso r);
120 121
121 if ($idlAttributesFile) { 122 if ($idlAttributesFile) {
122 my $idlAttributes = loadIDLAttributes($idlAttributesFile); 123 my $idlAttributes = loadIDLAttributes($idlAttributesFile);
123 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile) ); 124 checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile) );
124 } 125 }
125 126
126 foreach my $idlFile (@supplementedIdlFiles) { 127 foreach my $idlFile (@dependencyIdlFiles) {
127 next if $idlFile eq $targetIdlFile; 128 next if $idlFile eq $targetIdlFile;
128 129
129 my $interfaceName = fileparse(basename($idlFile), ".idl"); 130 my $interfaceName = fileparse(basename($idlFile), ".idl");
130 my $parser = IDLParser->new(!$verbose); 131 my $parser = IDLParser->new(!$verbose);
131 my $document = $parser->Parse($idlFile, $defines, $preprocessor); 132 my $document = $parser->Parse($idlFile, $defines, $preprocessor);
132 133
133 foreach my $interface (@{$document->interfaces}) { 134 foreach my $interface (@{$document->interfaces}) {
134 if (!$interface->isPartial || $interface->name eq $targetInterfaceName) { 135 if (!$interface->isPartial || $interface->name eq $targetInterfaceName) {
135 my $targetDataNode; 136 my $targetDataNode;
136 foreach my $interface (@{$targetDocument->interfaces}) { 137 foreach my $interface (@{$targetDocument->interfaces}) {
(...skipping 30 matching lines...) Expand all
167 foreach my $constant (@{$interface->constants}) { 168 foreach my $constant (@{$interface->constants}) {
168 # Record that this constant is implemented by $interfaceName. 169 # Record that this constant is implemented by $interfaceName.
169 $constant->extendedAttributes->{"ImplementedBy"} = $interfaceNam e if $interface->isPartial; 170 $constant->extendedAttributes->{"ImplementedBy"} = $interfaceNam e if $interface->isPartial;
170 171
171 # Add interface-wide extended attributes to each constant. 172 # Add interface-wide extended attributes to each constant.
172 applyInterfaceExtendedAttributes($interface, $constant->extended Attributes); 173 applyInterfaceExtendedAttributes($interface, $constant->extended Attributes);
173 174
174 push(@{$targetDataNode->constants}, $constant); 175 push(@{$targetDataNode->constants}, $constant);
175 } 176 }
176 } else { 177 } 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"; 178 die "$idlFile is not a dependency of $targetIdlFile. There maybe a b ug in the dependency computer (compute_dependencies.py).\n";
178 } 179 }
179 } 180 }
180 } 181 }
181 182
182 # FIXME: This code will be removed once IDLParser.pm and CodeGeneratorV8.pm 183 # FIXME: This code will be removed once IDLParser.pm and CodeGeneratorV8.pm
183 # are connected via JSON files. See http://crbug.com/242795 184 # are connected via JSON files. See http://crbug.com/242795
184 $targetDocument = deserializeJSON(serializeJSON($targetDocument)); 185 $targetDocument = deserializeJSON(serializeJSON($targetDocument));
185 186
186 # Generate desired output for the target IDL file. 187 # Generate desired output for the target IDL file.
187 my @dependentIdlFiles = ($targetDocument->fileName(), @supplementedIdlFiles); 188 my @interfaceIdlFiles = ($targetDocument->fileName(), @dependencyIdlFiles);
188 my $codeGenerator = CodeGeneratorV8->new($targetDocument, \@idlDirectories, $pre processor, $defines, $verbose, \@dependentIdlFiles, $writeFileOnlyIfChanged); 189 my $codeGenerator = CodeGeneratorV8->new($targetDocument, \@idlDirectories, $pre processor, $defines, $verbose, \@interfaceIdlFiles, $writeFileOnlyIfChanged);
189 my $interfaces = $targetDocument->interfaces; 190 my $interfaces = $targetDocument->interfaces;
190 foreach my $interface (@$interfaces) { 191 foreach my $interface (@$interfaces) {
191 print "Generating bindings code for IDL interface \"" . $interface->name . " \"...\n" if $verbose; 192 print "Generating bindings code for IDL interface \"" . $interface->name . " \"...\n" if $verbose;
192 $codeGenerator->GenerateInterface($interface); 193 $codeGenerator->GenerateInterface($interface);
193 $codeGenerator->WriteData($interface, $outputDirectory); 194 $codeGenerator->WriteData($interface, $outputDirectory);
194 } 195 }
195 196
196 sub generateEmptyHeaderAndCpp 197 sub generateEmptyHeaderAndCpp
197 { 198 {
198 my ($targetInterfaceName, $outputDirectory) = @_; 199 my ($targetInterfaceName, $outputDirectory) = @_;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 last OUTER; 302 last OUTER;
302 } 303 }
303 } 304 }
304 } 305 }
305 if ($error) { 306 if ($error) {
306 die "IDL ATTRIBUTE CHECKER ERROR: $error 307 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). 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).
308 "; 309 ";
309 } 310 }
310 } 311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698