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

Unified Diff: Source/bindings/scripts/generate-bindings.pl

Issue 15979013: Refactor partial interface resolving and merging into InterfaceMerger.pm (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Handle empties Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/scripts/InterfaceMerger.pm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/generate-bindings.pl
diff --git a/Source/bindings/scripts/generate-bindings.pl b/Source/bindings/scripts/generate-bindings.pl
index b3f3d43298ac01f3e561873f5119d564763adf41..ae1d24715b789de4128f594ac553f71a7ce18edb 100755
--- a/Source/bindings/scripts/generate-bindings.pl
+++ b/Source/bindings/scripts/generate-bindings.pl
@@ -33,20 +33,20 @@ use strict;
use File::Path;
use File::Basename;
use Getopt::Long;
-use Text::ParseWords;
use Cwd;
use IDLParser;
use CodeGeneratorV8;
+use InterfaceMerger qw(computeIdlDependencies mergePartialInterfaces);
my @idlDirectories;
my $outputDirectory;
my $outputHeadersDirectory;
-my $defines;
+my $defines = "";
my $filename;
my $preprocessor;
my $verbose;
-my $supplementalDependencyFile;
+my $dependenciesFile;
my $additionalIdlFiles;
my $idlAttributesFile;
my $writeFileOnlyIfChanged;
@@ -58,7 +58,7 @@ GetOptions('include=s@' => \@idlDirectories,
'filename=s' => \$filename,
'preprocessor=s' => \$preprocessor,
'verbose' => \$verbose,
- 'supplementalDependencyFile=s' => \$supplementalDependencyFile,
+ 'dependenciesFile=s' => \$dependenciesFile,
'additionalIdlFiles=s' => \$additionalIdlFiles,
'idlAttributesFile=s' => \$idlAttributesFile,
'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged);
@@ -67,49 +67,17 @@ my $targetIdlFile = $ARGV[0];
die('Must specify input file.') unless defined($targetIdlFile);
die('Must specify output directory.') unless defined($outputDirectory);
-$defines = "" unless defined($defines);
-
-if (!$outputHeadersDirectory) {
- $outputHeadersDirectory = $outputDirectory;
-}
+$outputHeadersDirectory = $outputHeadersDirectory || $outputDirectory;
$targetIdlFile = Cwd::realpath($targetIdlFile);
if ($verbose) {
print "$targetIdlFile\n";
}
my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl");
-my $idlFound = 0;
-my @supplementedIdlFiles;
-if ($supplementalDependencyFile) {
- # The format of a supplemental dependency file:
- #
- # DOMWindow.idl P.idl Q.idl R.idl
- # Document.idl S.idl
- # Event.idl
- # ...
- #
- # The above indicates that DOMWindow.idl is supplemented by P.idl, Q.idl and R.idl,
- # Document.idl is supplemented by S.idl, and Event.idl is supplemented by no IDLs.
- # The IDL that supplements another IDL (e.g. P.idl) never appears in the dependency file.
- open FH, "< $supplementalDependencyFile" or die "Cannot open $supplementalDependencyFile\n";
- while (my $line = <FH>) {
- my ($idlFile, @followingIdlFiles) = split(/\s+/, $line);
- if ($idlFile and basename($idlFile) eq basename($targetIdlFile)) {
- $idlFound = 1;
- @supplementedIdlFiles = @followingIdlFiles;
- }
- }
- close FH;
-
- # $additionalIdlFiles is list of IDL files which should not be included in
- # DerivedSources*.cpp (i.e. they are not described in the supplemental
- # dependency file) but should generate .h and .cpp files.
- if (!$idlFound and $additionalIdlFiles) {
- my @idlFiles = shellwords($additionalIdlFiles);
- $idlFound = grep { $_ and basename($_) eq basename($targetIdlFile) } @idlFiles;
- }
-
- if (!$idlFound) {
+my $idlDependencies = [];
+if ($dependenciesFile) {
+ $idlDependencies = computeIdlDependencies(basename($targetIdlFile), $dependenciesFile, $additionalIdlFiles);
+ if (!ref($idlDependencies)) {
# We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created.
generateEmptyHeaderAndCpp($targetInterfaceName, $outputHeadersDirectory, $outputDirectory);
exit 0;
@@ -125,67 +93,10 @@ if ($idlAttributesFile) {
checkIDLAttributes($idlAttributes, $targetDocument, basename($targetIdlFile));
}
-foreach my $idlFile (@supplementedIdlFiles) {
- next if $idlFile eq $targetIdlFile;
-
- my $interfaceName = fileparse(basename($idlFile), ".idl");
- my $parser = IDLParser->new(!$verbose);
- my $document = $parser->Parse($idlFile, $defines, $preprocessor);
-
- foreach my $interface (@{$document->interfaces}) {
- if ($interface->isPartial and $interface->name eq $targetInterfaceName) {
- my $targetDataNode;
- foreach my $interface (@{$targetDocument->interfaces}) {
- if ($interface->name eq $targetInterfaceName) {
- $targetDataNode = $interface;
- last;
- }
- }
- die "Not found an interface ${targetInterfaceName} in ${targetInterfaceName}.idl." unless defined $targetDataNode;
-
- # Support for attributes of partial interfaces.
- foreach my $attribute (@{$interface->attributes}) {
- # Record that this attribute is implemented by $interfaceName.
- $attribute->signature->extendedAttributes->{"ImplementedBy"} = $interfaceName;
-
- # Add interface-wide extended attributes to each attribute.
- foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) {
- $attribute->signature->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName};
- }
- push(@{$targetDataNode->attributes}, $attribute);
- }
-
- # Support for methods of partial interfaces.
- foreach my $function (@{$interface->functions}) {
- # Record that this method is implemented by $interfaceName.
- $function->signature->extendedAttributes->{"ImplementedBy"} = $interfaceName;
-
- # Add interface-wide extended attributes to each method.
- foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) {
- $function->signature->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName};
- }
- push(@{$targetDataNode->functions}, $function);
- }
-
- # Support for constants of partial interfaces.
- foreach my $constant (@{$interface->constants}) {
- # Record that this constant is implemented by $interfaceName.
- $constant->extendedAttributes->{"ImplementedBy"} = $interfaceName;
-
- # Add interface-wide extended attributes to each constant.
- foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) {
- $constant->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName};
- }
- push(@{$targetDataNode->constants}, $constant);
- }
- } else {
- die "$idlFile is not a supplemental dependency of $targetIdlFile. There maybe a bug in the the supplemental dependency generator (preprocess_idls.py).\n";
- }
- }
-}
+mergePartialInterfaces($targetDocument, $targetInterfaceName, $targetIdlFile, $idlDependencies, $defines, $preprocessor, $verbose);
# Generate desired output for the target IDL file.
-my @dependentIdlFiles = ($targetDocument->fileName(), @supplementedIdlFiles);
+my @dependentIdlFiles = ($targetDocument->fileName(), @$idlDependencies);
my $codeGenerator = CodeGeneratorV8->new($targetDocument, \@idlDirectories, $preprocessor, $defines, $verbose, \@dependentIdlFiles, $writeFileOnlyIfChanged);
my $interfaces = $targetDocument->interfaces;
foreach my $interface (@$interfaces) {
« no previous file with comments | « Source/bindings/scripts/InterfaceMerger.pm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698