Chromium Code Reviews| Index: pkg/kernel/bin/dartk.dart |
| diff --git a/pkg/kernel/bin/dartk.dart b/pkg/kernel/bin/dartk.dart |
| index b8666a43c45b26b7c20d994cfb14075b23e8981e..5fb24b193303fa8d97f194018e88ebb360de4094 100755 |
| --- a/pkg/kernel/bin/dartk.dart |
| +++ b/pkg/kernel/bin/dartk.dart |
| @@ -62,8 +62,6 @@ ArgParser parser = new ArgParser(allowTrailingOptions: true) |
| help: 'Print internal warnings and diagnostics to stderr.') |
| ..addFlag('print-metrics', |
| negatable: false, help: 'Print performance metrics.') |
| - ..addOption('write-dependencies', |
| - help: 'Write all the .dart that were loaded to the given file.') |
| ..addFlag('verify-ir', help: 'Perform slow internal correctness checks.') |
| ..addFlag('tolerant', |
| help: 'Generate kernel even if there are compile-time errors.', |
| @@ -77,7 +75,9 @@ ArgParser parser = new ArgParser(allowTrailingOptions: true) |
| help: 'When printing a library as text, also print its dependencies\n' |
| 'on external libraries.') |
| ..addFlag('show-offsets', |
| - help: 'When printing a library as text, also print node offsets'); |
| + help: 'When printing a library as text, also print node offsets') |
| + ..addFlag('include-sdk', |
| + help: 'Include the SDK in the output. Implied by --link.'); |
| String getUsage() => """ |
| Usage: dartk [options] FILE |
| @@ -266,27 +266,38 @@ Future<CompilerOutcome> batchMain( |
| }); |
| } |
| - if (options.rest.length != 1) { |
| - return fail('Exactly one FILE should be given.'); |
| + bool includeSdk = options['include-sdk']; |
| + |
| + List<String> inputFiles = options.rest; |
| + if (inputFiles.length < 1 && !includeSdk) { |
| + return fail('At least one file should be given.'); |
| + } |
| + |
| + bool hasBinaryInput = false; |
| + bool hasDartInput = includeSdk; |
| + for (String file in inputFiles) { |
| + checkIsFile(file, option: 'Input file'); |
| + if (file.endsWith('.dill')) { |
| + hasBinaryInput = true; |
| + } else if (file.endsWith('.dart')) { |
| + hasDartInput = true; |
| + } else { |
| + fail('Unrecognized file extension: $file'); |
| + } |
| } |
| - String file = options.rest.single; |
| - checkIsFile(file, option: 'Input file'); |
| - file = new File(file).absolute.path; |
| - Uri fileUri = new Uri(scheme: 'file', path: file); |
| + if (hasBinaryInput && hasDartInput) { |
| + fail('Mixed binary and dart input is not currently supported'); |
| + } |
| String format = options['format'] ?? defaultFormat(); |
| String outputFile = options['out'] ?? defaultOutput(); |
| List<String> urlMapping = options['url-mapping'] as List<String>; |
| var customUriMappings = parseCustomUriMappings(urlMapping); |
| - var repository = new Repository(); |
| - |
| - Program program; |
| + var program = new Program(); |
| var watch = new Stopwatch()..start(); |
| - List<String> loadedFiles; |
| - Function getLoadedFiles; |
| List errors = const []; |
| TargetFlags targetFlags = new TargetFlags(strongMode: options['strong']); |
| Target target = getTarget(options['target'], targetFlags); |
| @@ -303,40 +314,57 @@ Future<CompilerOutcome> batchMain( |
| declaredVariables[name] = value; |
| } |
| - if (file.endsWith('.dill')) { |
| - program = loadProgramFromBinary(file, repository); |
| - getLoadedFiles = () => [file]; |
| - } else { |
| - DartOptions dartOptions = new DartOptions( |
| - strongMode: target.strongMode, |
| - strongModeSdk: target.strongModeSdk, |
| - sdk: options['sdk'], |
| - packagePath: packagePath, |
| - customUriMappings: customUriMappings, |
| - declaredVariables: declaredVariables, |
| - applicationRoot: applicationRoot); |
| - String packageDiscoveryPath = batchModeState.isBatchMode ? null : file; |
| - DartLoader loader = await batchModeState.batch.getLoader( |
| - repository, dartOptions, |
| + DartLoader loader; |
| + if (hasDartInput) { |
| + String packageDiscoveryPath = |
| + batchModeState.isBatchMode || inputFiles.isEmpty |
| + ? null |
| + : inputFiles.first; |
| + loader = await batchModeState.batch.getLoader( |
| + program, |
| + new DartOptions( |
| + strongMode: target.strongMode, |
| + strongModeSdk: target.strongModeSdk, |
| + sdk: options['sdk'], |
| + packagePath: packagePath, |
| + customUriMappings: customUriMappings, |
| + declaredVariables: declaredVariables, |
| + applicationRoot: applicationRoot), |
| packageDiscoveryPath: packageDiscoveryPath); |
| - if (options['link']) { |
| - program = loader.loadProgram(fileUri, target: target); |
| - } else { |
| - var library = loader.loadLibrary(fileUri); |
| - assert(library == |
| - repository.getLibraryReference(applicationRoot.relativeUri(fileUri))); |
| - program = new Program(repository.libraries); |
| + } |
| + |
| + if (includeSdk) { |
| + for (var uri in batchModeState.batch.dartSdk.uris) { |
| + loader.loadLibrary(Uri.parse(uri)); |
| } |
| - errors = loader.errors; |
| - if (errors.isNotEmpty) { |
| - const int errorLimit = 100; |
| - stderr.writeln(errors.take(errorLimit).join('\n')); |
| - if (errors.length > errorLimit) { |
| - stderr |
| - .writeln('[error] ${errors.length - errorLimit} errors not shown'); |
| + } |
| + |
| + for (String file in inputFiles) { |
| + file = new File(file).absolute.path; |
| + Uri fileUri = new Uri(scheme: 'file', path: file); |
|
ahe
2017/02/02 16:24:01
Uri.base.resolve(file) should be able to replace t
asgerf
2017/02/03 10:31:16
Done.
|
| + |
| + if (file.endsWith('.dill')) { |
| + loadProgramFromBinary(file, program); |
| + } else { |
| + if (options['link']) { |
| + program = loader.loadProgram(fileUri, target: target); |
| + } else { |
| + var library = loader.loadLibrary(fileUri); |
| + assert(library == |
| + program.getLibraryReference(applicationRoot.relativeUri(fileUri))); |
| + program.mainMethod ??= library.procedures |
| + .firstWhere((p) => p.name.name == 'main', orElse: () => null); |
| + } |
| + errors = loader.errors; |
| + if (errors.isNotEmpty) { |
| + const int errorLimit = 100; |
| + stderr.writeln(errors.take(errorLimit).join('\n')); |
| + if (errors.length > errorLimit) { |
| + stderr.writeln( |
| + '[error] ${errors.length - errorLimit} errors not shown'); |
| + } |
| } |
| } |
| - getLoadedFiles = () => loadedFiles ??= loader.getLoadedFileNames(); |
| } |
| bool canContinueCompilation = errors.isEmpty || options['tolerant']; |
| @@ -356,9 +384,8 @@ Future<CompilerOutcome> batchMain( |
| runVerifier(); |
| } |
| - String outputDependencies = options['write-dependencies']; |
| - if (outputDependencies != null) { |
| - new File(outputDependencies).writeAsStringSync(getLoadedFiles().join('\n')); |
| + if (options['link'] && program.mainMethodName == null) { |
| + fail('[error] The program has no main method.'); |
| } |
| // Apply target-specific transformations. |