Chromium Code Reviews| Index: pkg/compiler/lib/src/dart2js.dart |
| diff --git a/pkg/compiler/lib/src/dart2js.dart b/pkg/compiler/lib/src/dart2js.dart |
| index 336dfc6f59ad3f416e7b1e6cb8ef5950ca544b4a..dc12d846259a2606567547fc2de8430895bd5175 100644 |
| --- a/pkg/compiler/lib/src/dart2js.dart |
| +++ b/pkg/compiler/lib/src/dart2js.dart |
| @@ -10,10 +10,11 @@ import 'dart:io' show exit, File, FileMode, Platform, stdin, stderr; |
| import 'package:package_config/discovery.dart' show findPackages; |
| -import '../compiler.dart' as api; |
| +import '../compiler_new.dart' as api; |
| import 'commandline_options.dart'; |
| import 'filenames.dart'; |
| import 'io/source_file.dart'; |
| +import 'options.dart' show CompilerOptions; |
| import 'source_file_provider.dart'; |
| import 'util/command_line.dart'; |
| import 'util/uri_extras.dart'; |
| @@ -104,6 +105,8 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| Uri libraryRoot = currentDirectory; |
| Uri out = currentDirectory.resolve('out.js'); |
| Uri sourceMapOut = currentDirectory.resolve('out.js.map'); |
| + Uri serializationSource; |
| + Uri serializationTarget; |
| Uri packageConfig = null; |
| Uri packageRoot = null; |
| List<String> options = new List<String>(); |
| @@ -127,26 +130,26 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| diagnosticHandler = new FormattingDiagnosticHandler(inputProvider); |
| Map<String, dynamic> environment = new Map<String, dynamic>(); |
| - passThrough(String argument) => options.add(argument); |
| + void passThrough(String argument) => options.add(argument); |
| if (BUILD_ID != null) { |
| passThrough("--build-id=$BUILD_ID"); |
| } |
| - setLibraryRoot(String argument) { |
| + void setLibraryRoot(String argument) { |
| libraryRoot = currentDirectory.resolve(extractPath(argument)); |
| } |
| - setPackageRoot(String argument) { |
| + void setPackageRoot(String argument) { |
| packageRoot = currentDirectory.resolve(extractPath(argument)); |
| } |
| - setPackageConfig(String argument) { |
| + void setPackageConfig(String argument) { |
| packageConfig = |
| currentDirectory.resolve(extractPath(argument, isDirectory: false)); |
| } |
| - setOutput(Iterator<String> arguments) { |
| + void setOutput(Iterator<String> arguments) { |
| optionsImplyCompilation.add(arguments.current); |
| String path; |
| if (arguments.current == '-o') { |
| @@ -162,7 +165,7 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| sourceMapOut = Uri.parse('$out.map'); |
| } |
| - setOutputType(String argument) { |
| + void setOutputType(String argument) { |
| optionsImplyCompilation.add(argument); |
| if (argument == '--output-type=dart' || |
| argument == '--output-type=dart-multi') { |
| @@ -182,75 +185,85 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| passThrough(argument); |
| } |
| + void setSerializationSource(String argument) { |
| + serializationSource = |
| + currentDirectory.resolve(extractPath(argument, isDirectory: false)); |
| + } |
| + |
| + void setSerializationTarget(String argument) { |
| + serializationTarget = |
| + currentDirectory.resolve(extractPath(argument, isDirectory: false)); |
| + } |
| + |
| String getDepsOutput(Map<Uri, SourceFile> sourceFiles) { |
| var filenames = sourceFiles.keys.map((uri) => '$uri').toList(); |
| filenames.sort(); |
| return filenames.join("\n"); |
| } |
| - setStrip(String argument) { |
| + void setStrip(String argument) { |
| optionsImplyCompilation.add(argument); |
| stripArgumentSet = true; |
| passThrough(argument); |
| } |
| - setAnalyzeOnly(String argument) { |
| + void setAnalyzeOnly(String argument) { |
| analyzeOnly = true; |
| passThrough(argument); |
| } |
| - setAnalyzeAll(String argument) { |
| + void setAnalyzeAll(String argument) { |
| analyzeAll = true; |
| passThrough(argument); |
| } |
| - setAllowNativeExtensions(String argument) { |
| + void setAllowNativeExtensions(String argument) { |
| allowNativeExtensions = true; |
| passThrough(argument); |
| } |
| - setVerbose(_) { |
| + void setVerbose(_) { |
| diagnosticHandler.verbose = true; |
| passThrough('--verbose'); |
| } |
| - implyCompilation(String argument) { |
| + void implyCompilation(String argument) { |
| optionsImplyCompilation.add(argument); |
| passThrough(argument); |
| } |
| - setDumpInfo(String argument) { |
| + void setDumpInfo(String argument) { |
| implyCompilation(argument); |
| dumpInfo = true; |
| } |
| - setTrustTypeAnnotations(String argument) { |
| + void setTrustTypeAnnotations(String argument) { |
| trustTypeAnnotations = true; |
| implyCompilation(argument); |
| } |
| - setTrustJSInteropTypeAnnotations(String argument) { |
| + void setTrustJSInteropTypeAnnotations(String argument) { |
| trustJSInteropTypeAnnotations = true; |
| implyCompilation(argument); |
| } |
| - setTrustPrimitives(String argument) { |
| + void setTrustPrimitives(String argument) { |
| implyCompilation(argument); |
| } |
| - setCheckedMode(String argument) { |
| + void setCheckedMode(String argument) { |
| checkedMode = true; |
| passThrough(argument); |
| } |
| - addInEnvironment(String argument) { |
| + void addInEnvironment(String argument) { |
| int eqIndex = argument.indexOf('='); |
| String name = argument.substring(2, eqIndex); |
| String value = argument.substring(eqIndex + 1); |
| environment[name] = value; |
| } |
| - setCategories(String argument) { |
| + void setCategories(String argument) { |
| List<String> categories = extractParameter(argument).split(','); |
| if (categories.contains('all')) { |
| categories = ["Client", "Server"]; |
| @@ -273,7 +286,7 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| } |
| } |
| - handleShortOptions(String argument) { |
| + void handleShortOptions(String argument) { |
| var shortOptions = argument.substring(1).split(""); |
| for (var shortOption in shortOptions) { |
| switch (shortOption) { |
| @@ -342,6 +355,8 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| new OptionHandler(Flags.analyzeAll, setAnalyzeAll), |
| new OptionHandler(Flags.analyzeOnly, setAnalyzeOnly), |
| new OptionHandler(Flags.noSourceMaps, passThrough), |
| + new OptionHandler(Option.serializationSource, setSerializationSource), |
| + new OptionHandler(Option.serializationTarget, setSerializationTarget), |
| new OptionHandler(Flags.analyzeSignaturesOnly, setAnalyzeOnly), |
| new OptionHandler(Flags.disableNativeLiveTypeAnalysis, passThrough), |
| new OptionHandler('--categories=.*', setCategories), |
| @@ -355,6 +370,7 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| new OptionHandler(Flags.useContentSecurityPolicy, passThrough), |
| new OptionHandler(Flags.enableExperimentalMirrors, passThrough), |
| new OptionHandler(Flags.enableAssertMessage, passThrough), |
| + |
| // TODO(floitsch): remove conditional directives flag. |
| // We don't provide the info-message yet, since we haven't publicly |
| // launched the feature yet. |
| @@ -427,8 +443,18 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| helpAndFail("Cannot specify both '--package-root' and '--packages."); |
| } |
| - if ((analyzeOnly || analyzeAll) && !optionsImplyCompilation.isEmpty) { |
| - if (!analyzeOnly) { |
| + if ((analyzeOnly || analyzeAll || serializationTarget != null) && |
| + !optionsImplyCompilation.isEmpty) { |
| + if (serializationTarget != null) { |
| + if (!analyzeAll) { |
| + diagnosticHandler.info( |
| + "Option '${Option.serializationTarget}' implies " |
| + "'${Flags.analyzeAll}'.", |
| + api.Diagnostic.INFO); |
| + analyzeAll = true; |
| + } |
|
Siggi Cherem (dart-lang)
2016/05/17 21:54:25
maybe set analyzeOnly here too?
That way we don't
Johnni Winther
2016/05/18 09:52:41
Done.
|
| + } |
| + if (analyzeAll && !analyzeOnly) { |
| diagnosticHandler.info( |
| "Option '${Flags.analyzeAll}' implies '${Flags.analyzeOnly}'.", |
| api.Diagnostic.INFO); |
| @@ -455,7 +481,9 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| RandomAccessFileOutputProvider outputProvider = |
| new RandomAccessFileOutputProvider(out, sourceMapOut, |
| - onInfo: diagnosticHandler.info, onFailure: fail); |
| + onInfo: diagnosticHandler.info, |
| + onFailure: fail, |
| + serializationTarget: serializationTarget); |
| api.CompilationResult compilationDone(api.CompilationResult result) { |
| if (analyzeOnly) return result; |
| @@ -484,18 +512,19 @@ Future<api.CompilationResult> compile(List<String> argv) { |
| return result; |
| } |
| - Uri uri = currentDirectory.resolve(arguments[0]); |
| + Uri script = currentDirectory.resolve(arguments[0]); |
| + CompilerOptions compilerOptions = new CompilerOptions.parse( |
| + entryPoint: script, |
| + libraryRoot: libraryRoot, |
| + packageRoot: packageRoot, |
| + packageConfig: packageConfig, |
| + packagesDiscoveryProvider: findPackages, |
| + serializationSource: serializationSource, |
| + serializationTarget: serializationTarget, |
| + options: options, |
| + environment: environment); |
| return compileFunc( |
| - uri, |
| - libraryRoot, |
| - packageRoot, |
| - inputProvider, |
| - diagnosticHandler, |
| - options, |
| - outputProvider, |
| - environment, |
| - packageConfig, |
| - findPackages) |
| + compilerOptions, inputProvider, diagnosticHandler, outputProvider) |
| .then(compilationDone); |
| } |
| @@ -706,8 +735,15 @@ void main(List<String> arguments) { |
| internalMain(arguments); |
| } |
| -var exitFunc = exit; |
| -var compileFunc = api.compile; |
| +typedef void ExitFunc(int exitCode); |
| +typedef Future<api.CompilationResult> CompileFunc( |
| + CompilerOptions compilerOptions, |
| + api.CompilerInput compilerInput, |
| + api.CompilerDiagnostics compilerDiagnostics, |
| + api.CompilerOutput compilerOutput); |
| + |
| +ExitFunc exitFunc = exit; |
| +CompileFunc compileFunc = api.compile; |
| Future<api.CompilationResult> internalMain(List<String> arguments) { |
| Future onError(exception, trace) { |