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

Side by Side Diff: mojo/dart/packages/mojom/lib/src/generate.dart

Issue 1539673003: Generate Mojom Types in Dart (Take 2) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Merge with master Created 4 years, 10 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /// This library generates Mojo bindings for a Dart package. 5 /// This library generates Mojo bindings for a Dart package.
6 6
7 library generate; 7 library generate;
8 8
9 import 'dart:async'; 9 import 'dart:async';
10 import 'dart:convert'; 10 import 'dart:convert';
11 import 'dart:developer' as dev; 11 import 'dart:developer' as dev;
12 import 'dart:io'; 12 import 'dart:io';
13 13
14 import 'package:mojom/src/utils.dart'; 14 import 'package:mojom/src/utils.dart';
15 import 'package:path/path.dart' as path; 15 import 'package:path/path.dart' as path;
16 16
17 part 'mojom_finder.dart'; 17 part 'mojom_finder.dart';
18 18
19 const String mojoTestPackage = '_mojo_for_test_only';
20
19 class MojomGenerator { 21 class MojomGenerator {
20 static dev.Counter _genMs; 22 static dev.Counter _genMs;
21 final bool _errorOnDuplicate; 23 final bool _errorOnDuplicate;
22 final bool _dryRun; 24 final bool _dryRun;
23 final bool _force; 25 final bool _force;
24 final Directory _mojoSdk; 26 final Directory _mojoSdk;
25 27
26 Map<String, String> _duplicateDetection; 28 Map<String, String> _duplicateDetection;
27 int _generationMs; 29 int _generationMs;
28 30
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 156
155 final script = path.join( 157 final script = path.join(
156 _mojoSdk.path, 'tools', 'bindings', 'mojom_bindings_generator.py'); 158 _mojoSdk.path, 'tools', 'bindings', 'mojom_bindings_generator.py');
157 final sdkInc = path.normalize(path.join(_mojoSdk.path, '..', '..')); 159 final sdkInc = path.normalize(path.join(_mojoSdk.path, '..', '..'));
158 final outputDir = await Directory.systemTemp.createTemp(); 160 final outputDir = await Directory.systemTemp.createTemp();
159 try { 161 try {
160 final output = outputDir.path; 162 final output = outputDir.path;
161 163
162 final servicesPath = _sniffForMojoServicesInclude(mojom.path); 164 final servicesPath = _sniffForMojoServicesInclude(mojom.path);
163 165
166 // Force type information to be generated for the test package.
167 // TODO(afandria): Is there a better way to accomplish this goal?
168 // https://github.com/domokit/mojo/issues/641
169 final generateTypeInfoFlag = packageName == mojoTestPackage ?
170 '--generate-type-info' : '--no-generate-type-info';
171
164 final arguments = [ 172 final arguments = [
165 '--use_bundled_pylibs', 173 '--use_bundled_pylibs',
166 '-g', 174 '-g',
167 'dart', 175 'dart',
168 '-o', 176 '-o',
169 output, 177 output,
170 '-I', 178 '-I',
171 sdkInc, 179 sdkInc,
172 '-I', 180 '-I',
173 importDir.path, 181 importDir.path,
174 '--no-gen-imports' 182 '--no-gen-imports',
183 generateTypeInfoFlag
175 ]; 184 ];
176 if (servicesPath != null) { 185 if (servicesPath != null) {
177 arguments.add('-I'); 186 arguments.add('-I');
178 arguments.add(servicesPath); 187 arguments.add(servicesPath);
179 } 188 }
180 arguments.add(mojom.path); 189 arguments.add(mojom.path);
181 190
182 log.info('Generating $mojom'); 191 log.info('Generating $mojom');
183 log.info('$script ${arguments.join(" ")}'); 192 log.info('$script ${arguments.join(" ")}');
184 log.info('dryRun = $_dryRun'); 193 log.info('dryRun = $_dryRun');
185 if (!_dryRun) { 194 if (!_dryRun) {
186 final result = await _runBindingsGeneration(script, arguments); 195 final result = await _runBindingsGeneration(script, arguments);
187 if (result.exitCode != 0) { 196 if (result.exitCode != 0) {
188 log.info("bindings generation result = ${result.exitCode}"); 197 log.info("bindings generation result = ${result.exitCode}");
189 await outputDir.delete(recursive: true); 198 await outputDir.delete(recursive: true);
190 throw new GenerationError("$script failed:\n" 199 throw new GenerationError("$script failed:\n"
191 "code: ${result.exitCode}\n" 200 "code: ${result.exitCode}\n"
192 "stderr: ${result.stderr}\n" 201 "stderr: ${result.stderr}\n"
193 "stdout: ${result.stdout}"); 202 "stdout: ${result.stdout}");
194 } else { 203 } else {
195 log.info("bindings generation result = 0"); 204 log.info("bindings generation result = 0");
196 } 205 }
197 206
198 // Generated .mojom.dart is under $output/dart-gen/$PACKAGE/lib/$X 207 // Generated .mojom.dart is under $output/dart-gen/$PACKAGE/lib/$X
199 // Move $X to |destination|/lib/$X. 208 // Move $X to |destination|/lib/$X.
200 // Throw an exception if $PACKGE != [packageName]. 209 // Throw an exception if $PACKAGE != [packageName].
201 final generatedDirName = path.join(output, 'dart-gen'); 210 final generatedDirName = path.join(output, 'dart-gen');
202 final generatedDir = new Directory(generatedDirName); 211 final generatedDir = new Directory(generatedDirName);
203 log.info("generatedDir= $generatedDir"); 212 log.info("generatedDir= $generatedDir");
204 assert(await generatedDir.exists()); 213 assert(await generatedDir.exists());
205 await for (var genpack in generatedDir.list()) { 214 await for (var genpack in generatedDir.list()) {
206 if (genpack is! Directory) continue; 215 if (genpack is! Directory) continue;
207 log.info("genpack = $genpack"); 216 log.info("genpack = $genpack");
208 var libDir = new Directory(path.join(genpack.path, 'lib')); 217 var libDir = new Directory(path.join(genpack.path, 'lib'));
209 var name = path.relative(genpack.path, from: generatedDirName); 218 var name = path.relative(genpack.path, from: generatedDirName);
210 log.info("Found generated lib dir: $libDir"); 219 log.info("Found generated lib dir: $libDir");
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 '\t$dart $packRoot $scriptPath single -m $mojoSdk -r $root ' 446 '\t$dart $packRoot $scriptPath single -m $mojoSdk -r $root '
438 '-p $packagePath $skips'); 447 '-p $packagePath $skips');
439 _errors++; 448 _errors++;
440 return; 449 return;
441 } 450 }
442 } 451 }
443 } 452 }
444 453
445 bool _shouldSkip(File f) => containsPrefix(f.path, _skip); 454 bool _shouldSkip(File f) => containsPrefix(f.path, _skip);
446 } 455 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698