OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library fasta.get_dependencies; |
| 6 |
| 7 import 'dart:async' show Future; |
| 8 |
| 9 import 'package:kernel/kernel.dart' show loadProgramFromBytes; |
| 10 |
| 11 import 'package:kernel/target/targets.dart' show Target; |
| 12 |
| 13 import '../../compiler_options.dart' show CompilerOptions; |
| 14 |
| 15 import '../../file_system.dart' show FileSystem; |
| 16 |
| 17 import '../base/processed_options.dart' show ProcessedOptions; |
| 18 |
| 19 import 'compiler_context.dart' show CompilerContext; |
| 20 |
| 21 import 'dill/dill_target.dart' show DillTarget; |
| 22 |
| 23 import 'kernel/kernel_target.dart' show KernelTarget; |
| 24 |
| 25 import 'uri_translator.dart' show UriTranslator; |
| 26 |
| 27 // TODO(sigmund): reimplement this API using the directive listener intead. |
| 28 Future<List<Uri>> getDependencies(Uri script, |
| 29 {Uri sdk, |
| 30 Uri packages, |
| 31 Uri platform, |
| 32 bool verbose: false, |
| 33 Target target}) async { |
| 34 var options = new CompilerOptions() |
| 35 ..target = target |
| 36 ..verbose = verbose |
| 37 ..packagesFileUri = packages |
| 38 ..sdkSummary = platform |
| 39 ..sdkRoot = sdk; |
| 40 var pOptions = new ProcessedOptions(options); |
| 41 return await CompilerContext.runWithOptions(pOptions, |
| 42 (CompilerContext c) async { |
| 43 FileSystem fileSystem = c.options.fileSystem; |
| 44 UriTranslator uriTranslator = await c.options.getUriTranslator(); |
| 45 c.options.ticker.logMs("Read packages file"); |
| 46 DillTarget dillTarget = |
| 47 new DillTarget(c.options.ticker, uriTranslator, c.options.target); |
| 48 if (platform != null) { |
| 49 var bytes = await fileSystem.entityForUri(platform).readAsBytes(); |
| 50 var platformProgram = loadProgramFromBytes(bytes); |
| 51 platformProgram.unbindCanonicalNames(); |
| 52 dillTarget.loader.appendLibraries(platformProgram); |
| 53 } |
| 54 KernelTarget kernelTarget = new KernelTarget( |
| 55 fileSystem, false, dillTarget, uriTranslator, c.uriToSource); |
| 56 |
| 57 kernelTarget.read(script); |
| 58 await dillTarget.buildOutlines(); |
| 59 await kernelTarget.loader.buildOutlines(); |
| 60 return await kernelTarget.loader.getDependencies(); |
| 61 }); |
| 62 } |
OLD | NEW |