OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'dart:io'; | |
6 import 'dart:async'; | |
7 | |
8 import 'package:compiler/src/apiimpl.dart'; | |
9 import 'package:compiler/src/filenames.dart'; | |
10 import 'package:compiler/src/null_compiler_output.dart'; | |
11 import 'package:compiler/src/options.dart'; | |
12 import 'package:compiler/src/serialization/json_serializer.dart'; | |
13 import 'package:compiler/src/source_file_provider.dart'; | |
14 import 'package:package_config/discovery.dart'; | |
15 import 'package:compiler/src/elements/elements.dart'; | |
16 | |
17 Future<String> resolve(List<Uri> inputs, | |
18 {List<String> deps: const <String>[], | |
19 List<String> bazelSearchPaths, | |
20 String root, | |
21 String packages, | |
22 Uri packageRoot, | |
23 String platformConfig}) async { | |
24 var resolutionInputs = deps | |
25 .map((uri) => currentDirectory.resolve(nativeToUriPath(uri))) | |
26 .toList(); | |
27 var libraryRoot = root == null | |
28 ? Platform.script.resolve('../../../sdk/') | |
29 : currentDirectory.resolve(nativeToUriPath(root)); | |
30 | |
31 var options = new CompilerOptions( | |
32 libraryRoot: libraryRoot, | |
33 resolveOnly: true, | |
34 analyzeMain: true, | |
35 resolutionInputs: resolutionInputs, | |
36 packageRoot: packageRoot, | |
37 packageConfig: | |
38 packages != null ? currentDirectory.resolve(packages) : null, | |
39 packagesDiscoveryProvider: findPackages, | |
40 platformConfigUri: | |
41 platformConfig != null ? libraryRoot.resolve(platformConfig) : null); | |
42 | |
43 var inputProvider = bazelSearchPaths != null | |
44 ? new BazelInputProvider(bazelSearchPaths) | |
45 : new CompilerSourceFileProvider(); | |
46 | |
47 var outputProvider = const NullCompilerOutput(); | |
48 var diagnostics = new FormattingDiagnosticHandler(inputProvider) | |
49 ..enableColors = !Platform.isWindows; | |
50 var compiler = | |
51 new CompilerImpl(inputProvider, outputProvider, diagnostics, options); | |
52 | |
53 await compiler.setupSdk(); | |
54 await compiler.setupPackages(inputs.first); | |
55 | |
56 var librariesToSerialize = <LibraryElement>[]; | |
57 for (var uri in inputs) { | |
58 var library = await compiler.analyzeUri(uri); | |
59 if (library != null) { | |
60 // [library] is `null` if [uri] is a part file. | |
61 librariesToSerialize.add(library); | |
62 } | |
63 } | |
64 | |
65 if (librariesToSerialize.isEmpty) { | |
66 print('no library input files'); | |
67 exit(1); | |
68 } | |
69 | |
70 var serializer = | |
71 compiler.serialization.createSerializer(librariesToSerialize); | |
72 return serializer.toText(const JsonSerializationEncoder()); | |
73 } | |
OLD | NEW |