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

Unified 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 side-by-side diff with in-line comments
Download patch
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..a4e08d405b9cb8fedf68e998a9da34843aed8f6c 100755
--- a/Source/bindings/scripts/generate-bindings.pl
+++ b/Source/bindings/scripts/generate-bindings.pl
@@ -38,6 +38,7 @@ use Cwd;
use IDLParser;
use CodeGeneratorV8;
+use IRToFromJSON qw(IRToJSON JSONToIR);
my @idlDirectories;
my $outputDirectory;
@@ -50,6 +51,8 @@ my $supplementalDependencyFile;
my $additionalIdlFiles;
my $idlAttributesFile;
my $writeFileOnlyIfChanged;
+my $dumpJson = '';
+my $compileJson = '';
GetOptions('include=s@' => \@idlDirectories,
'outputDir=s' => \$outputDirectory,
@@ -61,7 +64,9 @@ GetOptions('include=s@' => \@idlDirectories,
'supplementalDependencyFile=s' => \$supplementalDependencyFile,
'additionalIdlFiles=s' => \$additionalIdlFiles,
'idlAttributesFile=s' => \$idlAttributesFile,
- 'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged);
+ 'write-file-only-if-changed=s' => \$writeFileOnlyIfChanged,
+ 'dump-json' => \$dumpJson,
+ '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
my $targetIdlFile = $ARGV[0];
@@ -77,6 +82,7 @@ if ($verbose) {
print "$targetIdlFile\n";
}
my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl");
+my $jsonFilename = "${targetInterfaceName}.json";
my $idlFound = 0;
my @supplementedIdlFiles;
@@ -116,9 +122,19 @@ if ($supplementalDependencyFile) {
}
}
+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
+if ($compileJson) {
+ open FH, "< ${outputDirectory}/${jsonFilename}" or die "Cannot open $jsonFilename\n";
+ my @jsonLines = <FH>;
+ close FH;
+ my $jsonContents = join('', @jsonLines);
+ $targetDocument = JSONToIR($jsonContents);
+ 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.
+}
+
# Parse the target IDL file.
my $targetParser = IDLParser->new(!$verbose);
-my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocessor);
+$targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocessor);
if ($idlAttributesFile) {
my $idlAttributes = loadIDLAttributes($idlAttributesFile);
@@ -184,7 +200,20 @@ foreach my $idlFile (@supplementedIdlFiles) {
}
}
+# 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.
+if ($dumpJson) {
+ my $jsonText = IRToJSON($targetDocument);
+ open FH, "> ${outputDirectory}/${jsonFilename}" or die "Cannot open $jsonFilename\n";
+ print FH $jsonText;
+ close FH;
+ exit 0;
+}
+
+# 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.
+$targetDocument = JSONToIR(IRToJSON($targetDocument));
+
# Generate desired output for the target IDL file.
+COMPILE:
my @dependentIdlFiles = ($targetDocument->fileName(), @supplementedIdlFiles);
my $codeGenerator = CodeGeneratorV8->new($targetDocument, \@idlDirectories, $preprocessor, $defines, $verbose, \@dependentIdlFiles, $writeFileOnlyIfChanged);
my $interfaces = $targetDocument->interfaces;

Powered by Google App Engine
This is Rietveld 408576698