| Index: pkg/compiler/lib/src/apiimpl.dart
|
| diff --git a/pkg/compiler/lib/src/apiimpl.dart b/pkg/compiler/lib/src/apiimpl.dart
|
| index 31ce5a8b5870e0ffe5342e437e42b0f6d016241d..42eda64b5a648a23fe7d6ce3210d2c965798b88b 100644
|
| --- a/pkg/compiler/lib/src/apiimpl.dart
|
| +++ b/pkg/compiler/lib/src/apiimpl.dart
|
| @@ -30,9 +30,6 @@ import 'io/source_file.dart';
|
| import 'platform_configuration.dart' as platform_configuration;
|
| import 'script.dart';
|
|
|
| -const bool forceIncrementalSupport =
|
| - const bool.fromEnvironment('DART2JS_EXPERIMENTAL_INCREMENTAL_SUPPORT');
|
| -
|
| /// For every 'dart:' library, a corresponding environment variable is set
|
| /// to "true". The environment variable's name is the concatenation of
|
| /// this prefix and the name (without the 'dart:'.
|
| @@ -41,24 +38,13 @@ const bool forceIncrementalSupport =
|
| /// to "true".
|
| const String dartLibraryEnvironmentPrefix = 'dart.library.';
|
|
|
| -/// Locations of the platform descriptor files relative to the library root.
|
| -const String _clientPlatform = "lib/dart_client.platform";
|
| -const String _serverPlatform = "lib/dart_server.platform";
|
| -const String _sharedPlatform = "lib/dart_shared.platform";
|
| -const String _dart2dartPlatform = "lib/dart2dart.platform";
|
|
|
| /// Implements the [Compiler] using a [api.CompilerInput] for supplying the
|
| /// sources.
|
| class CompilerImpl extends Compiler {
|
| api.CompilerInput provider;
|
| api.CompilerDiagnostics handler;
|
| - final Uri platformConfigUri;
|
| - final Uri packageConfig;
|
| - final Uri packageRoot;
|
| - final api.PackagesDiscoveryProvider packagesDiscoveryProvider;
|
| Packages packages;
|
| - List<String> options;
|
| - Map<String, dynamic> environment;
|
| bool mockableLibraryUsed = false;
|
|
|
| /// A mapping of the dart: library-names to their location.
|
| @@ -70,181 +56,19 @@ class CompilerImpl extends Compiler {
|
| GenericTask userProviderTask;
|
| GenericTask userPackagesDiscoveryTask;
|
|
|
| - Uri get libraryRoot => platformConfigUri.resolve(".");
|
| -
|
| - CompilerImpl(this.provider,
|
| - api.CompilerOutput outputProvider,
|
| - this.handler,
|
| - Uri libraryRoot,
|
| - this.packageRoot,
|
| - List<String> options,
|
| - this.environment,
|
| - [this.packageConfig,
|
| - this.packagesDiscoveryProvider])
|
| - : this.options = options,
|
| - this.platformConfigUri = resolvePlatformConfig(libraryRoot, options),
|
| - super(
|
| - outputProvider: outputProvider,
|
| - enableTypeAssertions: hasOption(options, Flags.enableCheckedMode),
|
| - enableUserAssertions: hasOption(options, Flags.enableCheckedMode),
|
| - trustTypeAnnotations:
|
| - hasOption(options, Flags.trustTypeAnnotations),
|
| - trustPrimitives:
|
| - hasOption(options, Flags.trustPrimitives),
|
| - trustJSInteropTypeAnnotations:
|
| - hasOption(options, Flags.trustJSInteropTypeAnnotations),
|
| - enableMinification: hasOption(options, Flags.minify),
|
| - useFrequencyNamer:
|
| - !hasOption(options, Flags.noFrequencyBasedMinification),
|
| - preserveUris: hasOption(options, Flags.preserveUris),
|
| - enableNativeLiveTypeAnalysis:
|
| - !hasOption(options, Flags.disableNativeLiveTypeAnalysis),
|
| - emitJavaScript: !(hasOption(options, '--output-type=dart') ||
|
| - hasOption(options, '--output-type=dart-multi')),
|
| - dart2dartMultiFile: hasOption(options, '--output-type=dart-multi'),
|
| - generateSourceMap: !hasOption(options, Flags.noSourceMaps),
|
| - analyzeAllFlag: hasOption(options, Flags.analyzeAll),
|
| - analyzeOnly: hasOption(options, Flags.analyzeOnly),
|
| - analyzeMain: hasOption(options, Flags.analyzeMain),
|
| - analyzeSignaturesOnly:
|
| - hasOption(options, Flags.analyzeSignaturesOnly),
|
| - strips: extractCsvOption(options, '--force-strip='),
|
| - disableTypeInferenceFlag:
|
| - hasOption(options, Flags.disableTypeInference),
|
| - preserveComments: hasOption(options, Flags.preserveComments),
|
| - useCpsIr: hasOption(options, Flags.useCpsIr),
|
| - verbose: hasOption(options, Flags.verbose),
|
| - sourceMapUri: extractUriOption(options, '--source-map='),
|
| - outputUri: extractUriOption(options, '--out='),
|
| - deferredMapUri: extractUriOption(options, '--deferred-map='),
|
| - dumpInfo: hasOption(options, Flags.dumpInfo),
|
| - buildId: extractStringOption(
|
| - options, '--build-id=',
|
| - "build number could not be determined"),
|
| - useContentSecurityPolicy:
|
| - hasOption(options, Flags.useContentSecurityPolicy),
|
| - useStartupEmitter: hasOption(options, Flags.fastStartup),
|
| - enableConditionalDirectives:
|
| - hasOption(options, Flags.conditionalDirectives),
|
| - useNewSourceInfo: hasOption(options, Flags.useNewSourceInfo),
|
| - hasIncrementalSupport:
|
| - forceIncrementalSupport ||
|
| - hasOption(options, Flags.incrementalSupport),
|
| - diagnosticOptions: new DiagnosticOptions(
|
| - suppressWarnings: hasOption(options, Flags.suppressWarnings),
|
| - fatalWarnings: hasOption(options, Flags.fatalWarnings),
|
| - suppressHints: hasOption(options, Flags.suppressHints),
|
| - terseDiagnostics: hasOption(options, Flags.terse),
|
| - shownPackageWarnings: extractOptionalCsvOption(
|
| - options, Flags.showPackageWarnings)),
|
| - enableExperimentalMirrors:
|
| - hasOption(options, Flags.enableExperimentalMirrors),
|
| - enableAssertMessage:
|
| - hasOption(options, Flags.enableAssertMessage),
|
| - generateCodeWithCompileTimeErrors:
|
| - hasOption(options, Flags.generateCodeWithCompileTimeErrors),
|
| - testMode: hasOption(options, Flags.testMode),
|
| - allowNativeExtensions:
|
| - hasOption(options, Flags.allowNativeExtensions)) {
|
| + Uri get libraryRoot => options.platformConfigUri.resolve(".");
|
| +
|
| + CompilerImpl(this.provider, api.CompilerOutput outputProvider,
|
| + this.handler, api.CompilerOptions options)
|
| + : super(options: options, outputProvider: outputProvider) {
|
| tasks.addAll([
|
| userHandlerTask = new GenericTask('Diagnostic handler', this),
|
| userProviderTask = new GenericTask('Input provider', this),
|
| userPackagesDiscoveryTask =
|
| new GenericTask('Package discovery', this),
|
| ]);
|
| - if (libraryRoot == null) {
|
| - throw new ArgumentError("[libraryRoot] is null.");
|
| - }
|
| - if (!libraryRoot.path.endsWith("/")) {
|
| - throw new ArgumentError("[libraryRoot] must end with a /.");
|
| - }
|
| - if (packageRoot != null && packageConfig != null) {
|
| - throw new ArgumentError("Only one of [packageRoot] or [packageConfig] "
|
| - "may be given.");
|
| - }
|
| - if (packageRoot != null && !packageRoot.path.endsWith("/")) {
|
| - throw new ArgumentError("[packageRoot] must end with a /.");
|
| - }
|
| - if (!analyzeOnly) {
|
| - if (allowNativeExtensions) {
|
| - throw new ArgumentError(
|
| - "${Flags.allowNativeExtensions} is only supported in combination "
|
| - "with ${Flags.analyzeOnly}");
|
| - }
|
| - }
|
| }
|
|
|
| - static String extractStringOption(List<String> options,
|
| - String prefix,
|
| - String defaultValue) {
|
| - for (String option in options) {
|
| - if (option.startsWith(prefix)) {
|
| - return option.substring(prefix.length);
|
| - }
|
| - }
|
| - return defaultValue;
|
| - }
|
| -
|
| - static Uri extractUriOption(List<String> options, String prefix) {
|
| - var option = extractStringOption(options, prefix, null);
|
| - return (option == null) ? null : Uri.parse(option);
|
| - }
|
| -
|
| - // CSV: Comma separated values.
|
| - static List<String> extractCsvOption(List<String> options, String prefix) {
|
| - for (String option in options) {
|
| - if (option.startsWith(prefix)) {
|
| - return option.substring(prefix.length).split(',');
|
| - }
|
| - }
|
| - return const <String>[];
|
| - }
|
| -
|
| - /// Extract list of comma separated values provided for [flag]. Returns an
|
| - /// empty list if [option] contain [flag] without arguments. Returns `null` if
|
| - /// [option] doesn't contain [flag] with or without arguments.
|
| - static List<String> extractOptionalCsvOption(
|
| - List<String> options, String flag) {
|
| - String prefix = '$flag=';
|
| - for (String option in options) {
|
| - if (option == flag) {
|
| - return const <String>[];
|
| - }
|
| - if (option.startsWith(flag)) {
|
| - return option.substring(prefix.length).split(',');
|
| - }
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - static Uri resolvePlatformConfig(Uri libraryRoot,
|
| - List<String> options) {
|
| - String platformConfigPath =
|
| - extractStringOption(options, "--platform-config=", null);
|
| - if (platformConfigPath != null) {
|
| - return libraryRoot.resolve(platformConfigPath);
|
| - } else if (hasOption(options, '--output-type=dart')) {
|
| - return libraryRoot.resolve(_dart2dartPlatform);
|
| - } else {
|
| - Iterable<String> categories = extractCsvOption(options, '--categories=');
|
| - if (categories.length == 0) {
|
| - return libraryRoot.resolve(_clientPlatform);
|
| - }
|
| - assert(categories.length <= 2);
|
| - if (categories.contains("Client")) {
|
| - if (categories.contains("Server")) {
|
| - return libraryRoot.resolve(_sharedPlatform);
|
| - }
|
| - return libraryRoot.resolve(_clientPlatform);
|
| - }
|
| - assert(categories.contains("Server"));
|
| - return libraryRoot.resolve(_serverPlatform);
|
| - }
|
| - }
|
| -
|
| - static bool hasOption(List<String> options, String option) {
|
| - return options.indexOf(option) >= 0;
|
| - }
|
|
|
| void log(message) {
|
| callUserHandler(
|
| @@ -293,7 +117,7 @@ class CompilerImpl extends Compiler {
|
| Uri resourceUri = translateUri(node, readableUri);
|
| if (resourceUri == null) return synthesizeScript(node, readableUri);
|
| if (resourceUri.scheme == 'dart-ext') {
|
| - if (!allowNativeExtensions) {
|
| + if (!options.allowNativeExtensions) {
|
| reporter.withCurrentElement(element, () {
|
| reporter.reportErrorMessage(
|
| node, MessageKind.DART_EXT_NOT_SUPPORTED);
|
| @@ -350,8 +174,8 @@ class CompilerImpl extends Compiler {
|
| }
|
|
|
| /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative
|
| - /// to [platformConfigUri] according to the information in the file at
|
| - /// [platformConfigUri].
|
| + /// to `options.platformConfigUri` according to the information in the file at
|
| + /// `options.platformConfigUri`.
|
| ///
|
| /// Returns null and emits an error if the library could not be found or
|
| /// imported into [importingLibrary].
|
| @@ -451,33 +275,32 @@ class CompilerImpl extends Compiler {
|
| }
|
|
|
| Future setupPackages(Uri uri) {
|
| - if (packageRoot != null) {
|
| + if (options.packageRoot != null) {
|
| // Use "non-file" packages because the file version requires a [Directory]
|
| // and we can't depend on 'dart:io' classes.
|
| - packages = new NonFilePackagesDirectoryPackages(packageRoot);
|
| - } else if (packageConfig != null) {
|
| - return callUserProvider(packageConfig).then((packageConfigContents) {
|
| - if (packageConfigContents is String) {
|
| - packageConfigContents = UTF8.encode(packageConfigContents);
|
| + packages = new NonFilePackagesDirectoryPackages(options.packageRoot);
|
| + } else if (options.packageConfig != null) {
|
| + return callUserProvider(options.packageConfig).then((configContents) {
|
| + if (configContents is String) {
|
| + configContents = UTF8.encode(configContents);
|
| }
|
| // The input provider may put a trailing 0 byte when it reads a source
|
| // file, which confuses the package config parser.
|
| - if (packageConfigContents.length > 0 &&
|
| - packageConfigContents.last == 0) {
|
| - packageConfigContents = packageConfigContents.sublist(
|
| - 0, packageConfigContents.length - 1);
|
| + if (configContents.length > 0 &&
|
| + configContents.last == 0) {
|
| + configContents = configContents.sublist(0, configContents.length - 1);
|
| }
|
| - packages =
|
| - new MapPackages(pkgs.parse(packageConfigContents, packageConfig));
|
| + packages = new MapPackages(
|
| + pkgs.parse(configContents, options.packageConfig));
|
| }).catchError((error) {
|
| reporter.reportErrorMessage(
|
| NO_LOCATION_SPANNABLE,
|
| MessageKind.INVALID_PACKAGE_CONFIG,
|
| - {'uri': packageConfig, 'exception': error});
|
| + {'uri': options.packageConfig, 'exception': error});
|
| packages = Packages.noPackages;
|
| });
|
| } else {
|
| - if (packagesDiscoveryProvider == null) {
|
| + if (options.packagesDiscoveryProvider == null) {
|
| packages = Packages.noPackages;
|
| } else {
|
| return callUserPackagesDiscovery(uri).then((p) {
|
| @@ -490,7 +313,7 @@ class CompilerImpl extends Compiler {
|
|
|
| Future<Null> setupSdk() {
|
| if (sdkLibraries == null) {
|
| - return platform_configuration.load(platformConfigUri, provider)
|
| + return platform_configuration.load(options.platformConfigUri, provider)
|
| .then((Map<String, Uri> mapping) {
|
| sdkLibraries = mapping;
|
| });
|
| @@ -502,7 +325,7 @@ class CompilerImpl extends Compiler {
|
| }
|
|
|
| Future<bool> run(Uri uri) {
|
| - log('Using platform configuration at ${platformConfigUri}');
|
| + log('Using platform configuration at ${options.platformConfigUri}');
|
|
|
| return Future.wait([setupSdk(), setupPackages(uri)]).then((_) {
|
| assert(sdkLibraries != null);
|
| @@ -552,10 +375,8 @@ class CompilerImpl extends Compiler {
|
| }
|
| }
|
|
|
| - bool get isMockCompilation {
|
| - return mockableLibraryUsed
|
| - && (options.indexOf(Flags.allowMockCompilation) != -1);
|
| - }
|
| + bool get isMockCompilation =>
|
| + mockableLibraryUsed && options.allowMockCompilation;
|
|
|
| void callUserHandler(Message message, Uri uri, int begin, int end,
|
| String text, api.Diagnostic kind) {
|
| @@ -582,7 +403,7 @@ class CompilerImpl extends Compiler {
|
| Future<Packages> callUserPackagesDiscovery(Uri uri) {
|
| try {
|
| return userPackagesDiscoveryTask.measure(
|
| - () => packagesDiscoveryProvider(uri));
|
| + () => options.packagesDiscoveryProvider(uri));
|
| } catch (ex, s) {
|
| diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s);
|
| rethrow;
|
| @@ -593,8 +414,8 @@ class CompilerImpl extends Compiler {
|
| assert(invariant(NO_LOCATION_SPANNABLE,
|
| sdkLibraries != null, message: "setupSdk() has not been run"));
|
|
|
| - var result = environment[name];
|
| - if (result != null || environment.containsKey(name)) return result;
|
| + var result = options.environment[name];
|
| + if (result != null || options.environment.containsKey(name)) return result;
|
| if (!name.startsWith(dartLibraryEnvironmentPrefix)) return null;
|
|
|
| String libraryName = name.substring(dartLibraryEnvironmentPrefix.length);
|
| @@ -621,6 +442,6 @@ class CompilerImpl extends Compiler {
|
| }
|
|
|
| Uri resolvePatchUri(String libraryName) {
|
| - return backend.resolvePatchUri(libraryName, platformConfigUri);
|
| + return backend.resolvePatchUri(libraryName, options.platformConfigUri);
|
| }
|
| }
|
|
|