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