| Index: pkg/kernel/bin/dartk.dart
|
| diff --git a/pkg/kernel/bin/dartk.dart b/pkg/kernel/bin/dartk.dart
|
| index 84fbf77a4d0e6627cfb4ea944b56c6c767ab4e4e..5893aa0c9de6ff31262c55e0b334a5fe1af2b889 100755
|
| --- a/pkg/kernel/bin/dartk.dart
|
| +++ b/pkg/kernel/bin/dartk.dart
|
| @@ -68,8 +68,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.',
|
| @@ -84,6 +82,8 @@ ArgParser parser = new ArgParser(allowTrailingOptions: true)
|
| 'on external libraries.')
|
| ..addFlag('show-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.')
|
| ..addFlag('tree-shake',
|
| defaultsTo: false, help: 'Enable tree-shaking if the target supports it');
|
|
|
| @@ -274,14 +274,29 @@ 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();
|
| @@ -294,13 +309,9 @@ Future<CompilerOutcome> batchMain(
|
| List<ProgramRoot> programRoots =
|
| parseProgramRoots(embedderEntryPointManifests);
|
|
|
| - 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'],
|
| @@ -320,41 +331,54 @@ 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);
|
| - loader.loadSdkInterface(program, target);
|
| - 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');
|
| + loader.loadSdkInterface(program, target);
|
| + }
|
| +
|
| + for (String file in inputFiles) {
|
| + Uri fileUri = Uri.base.resolve(file);
|
| +
|
| + if (file.endsWith('.dill')) {
|
| + loadProgramFromBinary(file, program);
|
| + } else {
|
| + if (options['link']) {
|
| + loader.loadProgram(fileUri, target: target);
|
| + } else {
|
| + var library = loader.loadLibrary(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'];
|
| @@ -374,9 +398,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.
|
|
|