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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 import 'dart:async'; |
6 | 7 |
7 import 'package:args/args.dart'; | |
8 import 'package:compiler/src/apiimpl.dart'; | 8 import 'package:compiler/src/apiimpl.dart'; |
9 import 'package:compiler/src/filenames.dart'; | 9 import 'package:compiler/src/filenames.dart'; |
10 import 'package:compiler/src/null_compiler_output.dart'; | 10 import 'package:compiler/src/null_compiler_output.dart'; |
11 import 'package:compiler/src/options.dart'; | 11 import 'package:compiler/src/options.dart'; |
12 import 'package:compiler/src/serialization/json_serializer.dart'; | 12 import 'package:compiler/src/serialization/json_serializer.dart'; |
13 import 'package:compiler/src/source_file_provider.dart'; | 13 import 'package:compiler/src/source_file_provider.dart'; |
14 import 'package:package_config/discovery.dart'; | 14 import 'package:package_config/discovery.dart'; |
15 | 15 |
16 main(var argv) async { | 16 Future<String> resolve(List<Uri> inputs, |
17 var parser = new ArgParser(); | 17 {List<String> deps: const <String>[], |
18 parser.addOption('deps', abbr: 'd', allowMultiple: true); | 18 List<String> bazelSearchPaths, |
19 parser.addOption('out', abbr: 'o'); | 19 String root, |
20 parser.addOption('library-root', abbr: 'l'); | 20 String packages, |
21 parser.addOption('packages', abbr: 'p'); | 21 Uri packageRoot, |
22 parser.addOption('bazel-paths', abbr: 'I', allowMultiple: true); | 22 String platformConfig}) async { |
23 var args = parser.parse(argv); | 23 var resolutionInputs = deps |
24 | |
25 var resolutionInputs = args['deps'] | |
26 .map((uri) => currentDirectory.resolve(nativeToUriPath(uri))) | 24 .map((uri) => currentDirectory.resolve(nativeToUriPath(uri))) |
27 .toList(); | 25 .toList(); |
28 var root = args['library-root']; | |
29 var libraryRoot = root == null | 26 var libraryRoot = root == null |
30 ? Platform.script.resolve('../../../sdk/') | 27 ? Platform.script.resolve('../../../sdk/') |
31 : currentDirectory.resolve(nativeToUriPath(root)); | 28 : currentDirectory.resolve(nativeToUriPath(root)); |
32 | 29 |
33 var options = new CompilerOptions( | 30 var options = new CompilerOptions( |
34 libraryRoot: libraryRoot, | 31 libraryRoot: libraryRoot, |
35 packageConfig: args['packages'] == null | |
36 ? null | |
37 : currentDirectory.resolve(args['packages']), | |
38 resolveOnly: true, | 32 resolveOnly: true, |
| 33 analyzeMain: true, |
39 resolutionInputs: resolutionInputs, | 34 resolutionInputs: resolutionInputs, |
40 packagesDiscoveryProvider: findPackages); | 35 packageRoot: packageRoot, |
| 36 packageConfig: |
| 37 packages != null ? currentDirectory.resolve(packages) : null, |
| 38 packagesDiscoveryProvider: findPackages, |
| 39 platformConfigUri: |
| 40 platformConfig != null ? libraryRoot.resolve(platformConfig) : null); |
41 | 41 |
42 var bazelSearchPaths = args['bazel-paths']; | |
43 var inputProvider = bazelSearchPaths != null | 42 var inputProvider = bazelSearchPaths != null |
44 ? new BazelInputProvider(bazelSearchPaths) | 43 ? new BazelInputProvider(bazelSearchPaths) |
45 : new CompilerSourceFileProvider(); | 44 : new CompilerSourceFileProvider(); |
46 | 45 |
47 var outputProvider = const NullCompilerOutput(); | 46 var outputProvider = const NullCompilerOutput(); |
48 var diagnostics = new FormattingDiagnosticHandler(inputProvider) | 47 var diagnostics = new FormattingDiagnosticHandler(inputProvider) |
49 ..enableColors = true; | 48 ..enableColors = !Platform.isWindows; |
50 var compiler = | 49 var compiler = |
51 new CompilerImpl(inputProvider, outputProvider, diagnostics, options); | 50 new CompilerImpl(inputProvider, outputProvider, diagnostics, options); |
52 | 51 |
53 if (args.rest.isEmpty) { | |
54 print('missing input files'); | |
55 exit(1); | |
56 } | |
57 | |
58 var inputs = args.rest | |
59 .map((uri) => currentDirectory.resolve(nativeToUriPath(uri))) | |
60 .toList(); | |
61 | |
62 await compiler.setupSdk(); | 52 await compiler.setupSdk(); |
63 await compiler.setupPackages(inputs.first); | 53 await compiler.setupPackages(inputs.first); |
64 | 54 |
65 for (var library in inputs) { | 55 var librariesToSerialize = []; |
66 await compiler.libraryLoader.loadLibrary(library); | 56 for (var uri in inputs) { |
| 57 var library = await compiler.analyzeUri(uri); |
| 58 if (library != null) { |
| 59 // [library] is `null` if [uri] is a part file. |
| 60 librariesToSerialize.add(library); |
| 61 } |
67 } | 62 } |
68 | 63 |
69 for (var library in inputs) { | 64 if (librariesToSerialize.isEmpty) { |
70 compiler.fullyEnqueueLibrary(compiler.libraryLoader.lookupLibrary(library), | 65 print('no library input files'); |
71 compiler.enqueuer.resolution); | 66 exit(1); |
72 } | 67 } |
73 | 68 |
74 compiler.processQueue(compiler.enqueuer.resolution, null); | |
75 | |
76 var librariesToSerialize = | |
77 inputs.map((lib) => compiler.libraryLoader.lookupLibrary(lib)).toList(); | |
78 | |
79 var serializer = | 69 var serializer = |
80 compiler.serialization.createSerializer(librariesToSerialize); | 70 compiler.serialization.createSerializer(librariesToSerialize); |
81 var text = serializer.toText(const JsonSerializationEncoder()); | 71 return serializer.toText(const JsonSerializationEncoder()); |
82 | |
83 var outFile = args['out'] ?? 'out.data'; | |
84 | |
85 await new File(outFile).writeAsString(text); | |
86 } | 72 } |
OLD | NEW |