| OLD | NEW | 
|---|
| 1 // Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file | 
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a | 
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 /// Tests code generation. | 5 /// Tests code generation. | 
| 6 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks | 6 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks | 
| 7 /// that the output is what we expected. | 7 /// that the output is what we expected. | 
| 8 library dev_compiler.test.codegen_test; | 8 library dev_compiler.test.codegen_test; | 
| 9 | 9 | 
| 10 import 'dart:convert' show JSON; | 10 import 'dart:convert' show JSON; | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 154 | 154 | 
| 155       var outPath = path.join(expectDir, path.withoutExtension(uriPath)); | 155       var outPath = path.join(expectDir, path.withoutExtension(uriPath)); | 
| 156       _writeModule(outPath, built); | 156       _writeModule(outPath, built); | 
| 157     }); | 157     }); | 
| 158   } | 158   } | 
| 159 } | 159 } | 
| 160 | 160 | 
| 161 void _buildMatcher(ModuleCompiler compiler, String expectDir) { | 161 void _buildMatcher(ModuleCompiler compiler, String expectDir) { | 
| 162   var options = new CompilerOptions(sourceMap: false, summarizeApi: false); | 162   var options = new CompilerOptions(sourceMap: false, summarizeApi: false); | 
| 163 | 163 | 
| 164   var filePath = path.join(inputDir, 'packages', 'matcher', 'matcher.dart'); | 164   var packageRoot = path.join(inputDir, 'packages'); | 
|  | 165   var filePath = path.join(packageRoot, 'matcher', 'matcher.dart'); | 
| 165   var contents = new File(filePath).readAsStringSync(); | 166   var contents = new File(filePath).readAsStringSync(); | 
| 166 | 167 | 
| 167   // Collect any other files we've imported. | 168   // Collect any other files we've imported. | 
| 168   var files = new Set<String>(); | 169   var files = new Set<String>(); | 
| 169   _collectTransitiveImports(contents, files, from: filePath); | 170   _collectTransitiveImports(contents, files, | 
|  | 171       packageRoot: packageRoot, from: filePath); | 
| 170 | 172 | 
| 171   var unit = new BuildUnit('matcher', files.toList(), _moduleForLibrary); | 173   var unit = new BuildUnit('matcher', files.toList(), _moduleForLibrary); | 
| 172   var module = compiler.compile(unit, options); | 174   var module = compiler.compile(unit, options); | 
| 173 | 175 | 
| 174   var outPath = path.join(expectDir, 'matcher', 'matcher'); | 176   var outPath = path.join(expectDir, 'matcher', 'matcher'); | 
| 175   _writeModule(outPath, module); | 177   _writeModule(outPath, module); | 
| 176 } | 178 } | 
| 177 | 179 | 
| 178 String _moduleForLibrary(Source source) { | 180 String _moduleForLibrary(Source source) { | 
| 179   var scheme = source.uri.scheme; | 181   var scheme = source.uri.scheme; | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 240         .where((p) => p.endsWith('_test.dart') || p.endsWith('_multi.dart')); | 242         .where((p) => p.endsWith('_test.dart') || p.endsWith('_multi.dart')); | 
| 241   } | 243   } | 
| 242   return files; | 244   return files; | 
| 243 } | 245 } | 
| 244 | 246 | 
| 245 /// Parse directives from [contents] and find the complete set of transitive | 247 /// Parse directives from [contents] and find the complete set of transitive | 
| 246 /// imports, reading files as needed. | 248 /// imports, reading files as needed. | 
| 247 /// | 249 /// | 
| 248 /// This will not include dart:* libraries, as those are implicitly available. | 250 /// This will not include dart:* libraries, as those are implicitly available. | 
| 249 void _collectTransitiveImports(String contents, Set<String> libraries, | 251 void _collectTransitiveImports(String contents, Set<String> libraries, | 
| 250     {String from}) { | 252     {String packageRoot, String from}) { | 
| 251   if (!libraries.add(from)) return; | 253   var uri = from; | 
|  | 254   if (packageRoot != null && path.isWithin(packageRoot, from)) { | 
|  | 255     uri = 'package:${path.relative(from, from: packageRoot)}'; | 
|  | 256   } | 
|  | 257   if (!libraries.add(uri)) return; | 
| 252 | 258 | 
| 253   var unit = parseDirectives(contents, name: from, suppressErrors: true); | 259   var unit = parseDirectives(contents, name: from, suppressErrors: true); | 
| 254   for (var d in unit.directives) { | 260   for (var d in unit.directives) { | 
| 255     if (d is ImportDirective || d is ExportDirective) { | 261     if (d is ImportDirective || d is ExportDirective) { | 
| 256       String uri = _resolveDirective(d); | 262       String uri = _resolveDirective(d); | 
| 257       if (uri == null || | 263       if (uri == null || | 
| 258           uri.startsWith('dart:') || | 264           uri.startsWith('dart:') || | 
| 259           uri.startsWith('package:')) { | 265           uri.startsWith('package:')) { | 
| 260         continue; | 266         continue; | 
| 261       } | 267       } | 
| 262 | 268 | 
| 263       var f = new File(path.join(path.dirname(from), uri)); | 269       var f = new File(path.join(path.dirname(from), uri)); | 
| 264       if (f.existsSync()) { | 270       if (f.existsSync()) { | 
| 265         _collectTransitiveImports(f.readAsStringSync(), libraries, | 271         _collectTransitiveImports(f.readAsStringSync(), libraries, | 
| 266             from: f.path); | 272             packageRoot: packageRoot, from: f.path); | 
| 267       } | 273       } | 
| 268     } | 274     } | 
| 269   } | 275   } | 
| 270 } | 276 } | 
| 271 | 277 | 
| 272 /// Simplified from ParseDartTask.resolveDirective. | 278 /// Simplified from ParseDartTask.resolveDirective. | 
| 273 String _resolveDirective(UriBasedDirective directive) { | 279 String _resolveDirective(UriBasedDirective directive) { | 
| 274   StringLiteral uriLiteral = directive.uri; | 280   StringLiteral uriLiteral = directive.uri; | 
| 275   String uriContent = uriLiteral.stringValue; | 281   String uriContent = uriLiteral.stringValue; | 
| 276   if (uriContent != null) { | 282   if (uriContent != null) { | 
| 277     uriContent = uriContent.trim(); | 283     uriContent = uriContent.trim(); | 
| 278     directive.uriContent = uriContent; | 284     directive.uriContent = uriContent; | 
| 279   } | 285   } | 
| 280   return directive.validate() == null ? uriContent : null; | 286   return directive.validate() == null ? uriContent : null; | 
| 281 } | 287 } | 
| OLD | NEW | 
|---|