From cbaa3ba32aad5483888ffcc1d40be92b944f8752 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald <jakemac@google.com> Date: Fri, 28 Apr 2017 13:59:11 -0700 Subject: [PATCH] Add --compiler=dart2js|dartdevc flag (#1575) Throws UnimplementedError if passing dartdevc today --- lib/src/barback/asset_environment.dart | 105 +++++++++++------- lib/src/barback/compiler.dart | 32 ++++++ lib/src/barback/load_all_transformers.dart | 3 +- lib/src/barback/pub_package_provider.dart | 7 +- lib/src/barback/transformer_loader.dart | 21 ++-- lib/src/command/barback.dart | 28 +++++ lib/src/command/build.dart | 2 +- lib/src/command/serve.dart | 9 +- lib/src/entrypoint.dart | 5 +- lib/src/executable.dart | 3 +- lib/src/global_packages.dart | 3 +- lib/src/package_graph.dart | 18 ++- .../allows_import_in_dart_code_test.dart | 0 test/compiler/compiler_flag_test.dart | 62 +++++++++++ ...iles_entrypoints_in_root_package_test.dart | 0 .../compiles_generated_dart_file_test.dart | 0 ...file_from_dependency_outside_web_test.dart | 0 ...s_generated_file_from_dependency_test.dart | 0 ...compiles_imported_generated_file_test.dart | 0 ...nverts_isolate_entrypoint_in_web_test.dart | 0 .../does_not_compile_if_disabled_test.dart | 0 ...le_until_its_output_is_requested_test.dart | 0 ...nvalid_command_line_options_type_test.dart | 0 ...support_invalid_environment_type_test.dart | 0 .../does_not_support_invalid_option_test.dart | 0 ..._invalid_type_for_boolean_option_test.dart | 0 .../environment_constant_test.dart | 0 ...ignores_entrypoint_in_dependency_test.dart | 0 .../ignores_entrypoints_in_lib_test.dart | 0 ...gnores_non_entrypoint_dart_files_test.dart | 0 ...s_source_maps_if_sourceMaps_true_test.dart | 0 .../includes_source_maps_in_debug_test.dart | 0 .../minifies_in_release_mode_test.dart | 0 ...ify_configuration_overrides_mode_test.dart | 0 ...s_source_map_if_sourceMaps_false_test.dart | 0 .../omits_source_map_in_release_test.dart | 0 ..._can_be_consumed_by_successive_phases.dart | 0 .../outputs_deferred_libraries_test.dart | 0 ...sses_along_environment_constants_test.dart | 0 .../reports_dart_parse_errors_test.dart | 0 .../source_maps_are_self_contained_test.dart | 0 ...nclude_core_libs_in_subdirectory_test.dart | 0 .../source_maps_include_core_libs_test.dart | 0 ...upports_configuration_with_build_test.dart | 0 .../supports_valid_options_test.dart | 0 .../unminified_in_nonrelease_mode_test.dart | 0 46 files changed, 228 insertions(+), 70 deletions(-) create mode 100644 lib/src/barback/compiler.dart rename test/{dart2js => compiler}/allows_import_in_dart_code_test.dart (100%) create mode 100644 test/compiler/compiler_flag_test.dart rename test/{dart2js => compiler}/compiles_entrypoints_in_root_package_test.dart (100%) rename test/{dart2js => compiler}/compiles_generated_dart_file_test.dart (100%) rename test/{dart2js => compiler}/compiles_generated_file_from_dependency_outside_web_test.dart (100%) rename test/{dart2js => compiler}/compiles_generated_file_from_dependency_test.dart (100%) rename test/{dart2js => compiler}/compiles_imported_generated_file_test.dart (100%) rename test/{dart2js => compiler}/converts_isolate_entrypoint_in_web_test.dart (100%) rename test/{dart2js => compiler}/does_not_compile_if_disabled_test.dart (100%) rename test/{dart2js => compiler}/does_not_compile_until_its_output_is_requested_test.dart (100%) rename test/{dart2js => compiler}/does_not_support_invalid_command_line_options_type_test.dart (100%) rename test/{dart2js => compiler}/does_not_support_invalid_environment_type_test.dart (100%) rename test/{dart2js => compiler}/does_not_support_invalid_option_test.dart (100%) rename test/{dart2js => compiler}/doesnt_support_invalid_type_for_boolean_option_test.dart (100%) rename test/{dart2js => compiler}/environment_constant_test.dart (100%) rename test/{dart2js => compiler}/ignores_entrypoint_in_dependency_test.dart (100%) rename test/{dart2js => compiler}/ignores_entrypoints_in_lib_test.dart (100%) rename test/{dart2js => compiler}/ignores_non_entrypoint_dart_files_test.dart (100%) rename test/{dart2js => compiler}/includes_source_maps_if_sourceMaps_true_test.dart (100%) rename test/{dart2js => compiler}/includes_source_maps_in_debug_test.dart (100%) rename test/{dart2js => compiler}/minifies_in_release_mode_test.dart (100%) rename test/{dart2js => compiler}/minify_configuration_overrides_mode_test.dart (100%) rename test/{dart2js => compiler}/omits_source_map_if_sourceMaps_false_test.dart (100%) rename test/{dart2js => compiler}/omits_source_map_in_release_test.dart (100%) rename test/{dart2js => compiler}/output_can_be_consumed_by_successive_phases.dart (100%) rename test/{dart2js => compiler}/outputs_deferred_libraries_test.dart (100%) rename test/{dart2js => compiler}/passes_along_environment_constants_test.dart (100%) rename test/{dart2js => compiler}/reports_dart_parse_errors_test.dart (100%) rename test/{dart2js => compiler}/source_maps_are_self_contained_test.dart (100%) rename test/{dart2js => compiler}/source_maps_include_core_libs_in_subdirectory_test.dart (100%) rename test/{dart2js => compiler}/source_maps_include_core_libs_test.dart (100%) rename test/{dart2js => compiler}/supports_configuration_with_build_test.dart (100%) rename test/{dart2js => compiler}/supports_valid_options_test.dart (100%) rename test/{dart2js => compiler}/unminified_in_nonrelease_mode_test.dart (100%) diff --git a/lib/src/barback/asset_environment.dart b/lib/src/barback/asset_environment.dart index 93b07469..0a7e5957 100644 --- a/lib/src/barback/asset_environment.dart +++ b/lib/src/barback/asset_environment.dart @@ -20,6 +20,7 @@ import '../source/cached.dart'; import '../utils.dart'; import 'admin_server.dart'; import 'barback_server.dart'; +import 'compiler.dart'; import 'dart_forwarding_transformer.dart'; import 'dart2js_transformer.dart'; import 'load_all_transformers.dart'; @@ -41,8 +42,8 @@ class AssetEnvironment { /// to [hostname] and have ports based on [basePort]. If omitted, they /// default to "localhost" and "0" (use ephemeral ports), respectively. /// - /// Loads all used transformers using [mode] (including dart2js if - /// [useDart2JS] is true). + /// Loads all used transformers using [mode] (including dart2js or dartdevc + /// based on [compiler]). /// /// This will only add the root package's "lib" directory to the environment. /// Other directories can be added to the environment using [serveDirectory]. @@ -70,21 +71,22 @@ class AssetEnvironment { Iterable<String> packages, Iterable<AssetId> entrypoints, Map<String, String> environmentConstants, - bool useDart2JS: true}) { - if (watcherType == null) watcherType = WatcherType.NONE; - if (hostname == null) hostname = "localhost"; - if (basePort == null) basePort = 0; - if (environmentConstants == null) environmentConstants = {}; + Compiler compiler}) { + watcherType ??= WatcherType.NONE; + hostname ??= "localhost"; + basePort ??= 0; + environmentConstants ??= {}; + compiler ??= Compiler.dart2Js; return log.progress("Loading asset environment", () async { var graph = _adjustPackageGraph(entrypoint.packageGraph, mode, packages); - var barback = new Barback(new PubPackageProvider(graph)); + var barback = new Barback(new PubPackageProvider(graph, compiler)); barback.log.listen(_log); var environment = new AssetEnvironment._(graph, barback, mode, - watcherType, hostname, basePort, environmentConstants); + watcherType, hostname, basePort, environmentConstants, compiler); - await environment._load(entrypoints: entrypoints, useDart2JS: useDart2JS); + await environment._load(entrypoints: entrypoints); return environment; }, fine: true); } @@ -135,10 +137,6 @@ class AssetEnvironment { /// Constants to passed to the built-in dart2js transformer. final Map<String, String> environmentConstants; - /// The [Transformer]s that should be appended by default to the root - /// package's transformer cascade. Will be empty if there are none. - final _builtInTransformers = <Transformer>[]; - /// How source files should be watched. final WatcherType _watcherType; @@ -167,21 +165,55 @@ class AssetEnvironment { /// go to barback immediately. Set<AssetId> _modifiedSources; + /// The compiler mode for this environment. + final Compiler compiler; + AssetEnvironment._(this.graph, this.barback, this.mode, this._watcherType, - this._hostname, this._basePort, this.environmentConstants); + this._hostname, this._basePort, this.environmentConstants, this.compiler); - /// Gets the built-in [Transformer]s that should be added to [package]. + /// Gets the built-in [Transformer]s or [AggregateTransformer]s that should be + /// added to [package]. + /// + /// These are returned as an [Iterable<Set>] to represent each phase (the + /// outer [Iterable]), and the transformers that should be ran in each phase ( + /// the inner [Set]). /// /// Returns `null` if there are none. - Iterable<Transformer> getBuiltInTransformers(Package package) { - // Built-in transformers only apply to the root package. - if (package.name != rootPackage.name) return null; + Iterable<Set> getBuiltInTransformers(Package package) { + var transformers = <Set>[]; - // The built-in transformers are for dart2js and forwarding assets around - // dart2js. - if (_builtInTransformers.isEmpty) return null; + if (compiler == Compiler.dartDevc) { + // TODO(jakemac53): Implement dartdevc! + throw new UnimplementedError( + 'The dartdevc compiler is not yet supported.'); + } - return _builtInTransformers; + // These transformers are just for the root package. + if (package.name == rootPackage.name) { + switch (compiler) { + case Compiler.dart2Js: + // If the entrypoint package manually configures the dart2js + // transformer, don't include it in the built-in transformer list. + // + // TODO(nweiz): if/when we support more built-in transformers, make + // this more general. + var containsDart2JS = graph.entrypoint.root.pubspec.transformers.any( + (transformers) => transformers + .any((config) => config.id.package == '\$dart2js')); + + if (!containsDart2JS && compiler == Compiler.dart2Js) { + transformers.add([ + new Dart2JSTransformer(this, mode), + new DartForwardingTransformer(), + ].toSet()); + } + break; + default: + break; + } + } + + return transformers; } /// Starts up the admin server on an appropriate port and returns it. @@ -431,32 +463,19 @@ class AssetEnvironment { /// in packages in [graph] and re-runs them as necessary when any input files /// change. /// - /// If [useDart2JS] is `true`, then the [Dart2JSTransformer] is implicitly + /// If [Compiler.dart2Js], then the [Dart2JSTransformer] is implicitly /// added to end of the root package's transformer phases. /// + /// if [Compiler.dartDevc], then the [DevCompilerTransformer] is + /// implicitly added to the end of all package's transformer phases. + /// /// If [entrypoints] is passed, only transformers necessary to run those /// entrypoints will be loaded. /// /// Returns a [Future] that completes once all inputs and transformers are /// loaded. - Future _load({Iterable<AssetId> entrypoints, bool useDart2JS}) { + Future _load({Iterable<AssetId> entrypoints}) { return log.progress("Initializing barback", () async { - // If the entrypoint package manually configures the dart2js - // transformer, don't include it in the built-in transformer list. - // - // TODO(nweiz): if/when we support more built-in transformers, make - // this more general. - var containsDart2JS = graph.entrypoint.root.pubspec.transformers.any( - (transformers) => - transformers.any((config) => config.id.package == '\$dart2js')); - - if (!containsDart2JS && useDart2JS) { - _builtInTransformers.addAll([ - new Dart2JSTransformer(this, mode), - new DartForwardingTransformer() - ]); - } - // Bind a server that we can use to load the transformers. var transformerServer = await BarbackServer.bind(this, _hostname, 0); @@ -509,7 +528,9 @@ class AssetEnvironment { // other build directories in the root package by calling // [serveDirectory]. await Future.wait(graph.packages.values.map((package) async { - if (graph.isPackageStatic(package.name)) return; + if (graph.isPackageStatic(package.name, compiler)) { + return; + } await _provideDirectorySources(package, "lib"); })); } diff --git a/lib/src/barback/compiler.dart b/lib/src/barback/compiler.dart new file mode 100644 index 00000000..c376075e --- /dev/null +++ b/lib/src/barback/compiler.dart @@ -0,0 +1,32 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +const _dart2JsName = 'dart2js'; +const _dartDevcName = 'dartdevc'; +const _noneName = 'none'; + +/// The compiler currently being used (or none). +/// +/// This is controlled by the `--compiler=$name` flag. +class Compiler { + static const dart2Js = const Compiler._(_dart2JsName); + static const dartDevc = const Compiler._(_dartDevcName); + static const none = const Compiler._(_noneName); + + static final all = [dart2Js, dartDevc, none]; + static Iterable<String> get names => all.map((compiler) => compiler.name); + + final String name; + + const Compiler._(this.name); + + static Compiler byName(String name) => + all.firstWhere((compiler) => compiler.name == name, orElse: () { + throw new ArgumentError( + 'Unrecognized compiler `$name`, supported compilers are ' + '`${names.join(", ")}`.'); + }); + + String toString() => name; +} diff --git a/lib/src/barback/load_all_transformers.dart b/lib/src/barback/load_all_transformers.dart index 18856827..d4cbda29 100644 --- a/lib/src/barback/load_all_transformers.dart +++ b/lib/src/barback/load_all_transformers.dart @@ -103,8 +103,7 @@ Future loadAllTransformers( await Future.wait(environment.graph.packages.values.map((package) async { var phases = await loader.transformersForPhases(package.pubspec.transformers); - var transformers = environment.getBuiltInTransformers(package); - if (transformers != null) phases.add(transformers); + phases.addAll(environment.getBuiltInTransformers(package)); if (phases.isEmpty) return; // TODO(nweiz): remove the [newFuture] here when issue 17305 is fixed. diff --git a/lib/src/barback/pub_package_provider.dart b/lib/src/barback/pub_package_provider.dart index 0e50ceea..d614a5bb 100644 --- a/lib/src/barback/pub_package_provider.dart +++ b/lib/src/barback/pub_package_provider.dart @@ -12,6 +12,7 @@ import 'package:path/path.dart' as p; import 'package:package_resolver/package_resolver.dart'; import 'package:pub_semver/pub_semver.dart'; +import 'compiler.dart'; import '../io.dart'; import '../package.dart'; import '../package_graph.dart'; @@ -43,10 +44,10 @@ class PubPackageProvider implements StaticPackageProvider { Iterable<String> get packages => _graph.packages.keys.toSet().difference(staticPackages.toSet()); - PubPackageProvider(PackageGraph graph) + PubPackageProvider(PackageGraph graph, Compiler compiler) : _graph = graph, - staticPackages = [r"$pub", r"$sdk"] - ..addAll(graph.packages.keys.where(graph.isPackageStatic)); + staticPackages = [r"$pub", r"$sdk"]..addAll(graph.packages.keys + .where((p) => graph.isPackageStatic(p, compiler))); Future<Asset> getAsset(AssetId id) async { // "$pub" is a psuedo-package that allows pub's transformer-loading diff --git a/lib/src/barback/transformer_loader.dart b/lib/src/barback/transformer_loader.dart index 28c87b6e..d1d1ef5a 100644 --- a/lib/src/barback/transformer_loader.dart +++ b/lib/src/barback/transformer_loader.dart @@ -10,6 +10,7 @@ import '../log.dart' as log; import '../utils.dart'; import 'asset_environment.dart'; import 'barback_server.dart'; +import 'compiler.dart'; import 'dart2js_transformer.dart'; import 'excluding_transformer.dart'; import 'transformer_config.dart'; @@ -99,22 +100,28 @@ class TransformerLoader { var transformer; try { - transformer = new Dart2JSTransformer.withSettings(_environment, - new BarbackSettings(config.configuration, _environment.mode)); + if (_environment.compiler == Compiler.dart2Js) { + transformer = new Dart2JSTransformer.withSettings(_environment, + new BarbackSettings(config.configuration, _environment.mode)); + // Handle any exclusions. + _transformers[config] = + new Set.from([ExcludingTransformer.wrap(transformer, config)]); + } else { + // Empty set if dart2js is disabled based on compiler flag. + _transformers[config] = new Set(); + } } on FormatException catch (error, stackTrace) { fail(error.message, error, stackTrace); } - // Handle any exclusions. - _transformers[config] = - new Set.from([ExcludingTransformer.wrap(transformer, config)]); return _transformers[config]; } - /// Loads all transformers defined in each phase of [phases]. + /// Loads all [Transformer]s or [AggregateTransformer]s defined in each phase + /// of [phases]. /// /// If any library hasn't yet been loaded via [load], it will be ignored. - Future<List<Set<Transformer>>> transformersForPhases( + Future<List<Set>> transformersForPhases( Iterable<Set<TransformerConfig>> phases) async { var result = await Future.wait(phases.map((phase) async { var transformers = await waitAndPrintErrors(phase.map(transformersFor)); diff --git a/lib/src/command/barback.dart b/lib/src/command/barback.dart index e5bde558..08313adb 100644 --- a/lib/src/command/barback.dart +++ b/lib/src/command/barback.dart @@ -7,6 +7,7 @@ import 'dart:async'; import 'package:barback/barback.dart'; import 'package:path/path.dart' as path; +import '../barback/compiler.dart'; import '../command.dart'; import '../io.dart'; import '../log.dart' as log; @@ -24,6 +25,28 @@ abstract class BarbackCommand extends PubCommand { /// The build mode. BarbackMode get mode => new BarbackMode(argResults["mode"]); + /// The current compiler mode. + Compiler get compiler { + if (argResults.options.contains('dart2js') && + argResults.wasParsed('dart2js')) { + if (argResults.options.contains("compiler") && + argResults.wasParsed("compiler")) { + usageException( + "The --dart2js flag can't be used with the --compiler arg. " + "Prefer using the --compiler arg as --[no]-dart2js is deprecated."); + } + if (argResults['dart2js']) { + return Compiler.dart2Js; + } else { + return Compiler.none; + } + } else if (argResults.options.contains("compiler")) { + return Compiler.byName(argResults["compiler"]); + } else { + return Compiler.dart2Js; + } + } + /// The directories in the entrypoint package that should be added to the /// build environment. final sourceDirectories = new Set<String>(); @@ -44,6 +67,11 @@ abstract class BarbackCommand extends PubCommand { help: "Use all default source directories.", defaultsTo: false, negatable: false); + + argParser.addOption("compiler", + allowed: Compiler.names, + defaultsTo: 'dart2js', + help: 'The JavaScript compiler to use to build the app.'); } Future run() { diff --git a/lib/src/command/build.dart b/lib/src/command/build.dart index f8ce3821..5805b152 100644 --- a/lib/src/command/build.dart +++ b/lib/src/command/build.dart @@ -67,7 +67,7 @@ class BuildCommand extends BarbackCommand { // user-facing, just use an IPv4 address to avoid a weird bug on the OS X // buildbots. var environment = await AssetEnvironment.create(entrypoint, mode, - environmentConstants: environmentConstants, useDart2JS: true); + environmentConstants: environmentConstants, compiler: compiler); var hasError = false; // Show in-progress errors, but not results. Those get handled diff --git a/lib/src/command/serve.dart b/lib/src/command/serve.dart index 60b788f1..2a785315 100644 --- a/lib/src/command/serve.dart +++ b/lib/src/command/serve.dart @@ -38,9 +38,6 @@ class ServeCommand extends BarbackCommand { return adminPort == null ? null : parseInt(adminPort, 'admin port'); } - /// `true` if Dart entrypoints should be compiled to JavaScript. - bool get useDart2JS => argResults['dart2js']; - /// `true` if the admin server URL should be displayed on startup. bool get logAdminUrl => argResults['log-admin-url']; @@ -74,7 +71,9 @@ class ServeCommand extends BarbackCommand { argParser.addOption('admin-port', hide: true); argParser.addFlag('dart2js', - defaultsTo: true, help: 'Compile Dart to JavaScript.'); + defaultsTo: true, + help: 'Deprecated: Use --compiler=none to disable js compilation.', + hide: true); argParser.addFlag('force-poll', defaultsTo: false, help: 'Force the use of a polling filesystem watcher.'); @@ -98,7 +97,7 @@ class ServeCommand extends BarbackCommand { watcherType: watcherType, hostname: hostname, basePort: port, - useDart2JS: useDart2JS, + compiler: compiler, environmentConstants: environmentConstants); var directoryLength = sourceDirectories.map((dir) => dir.length).reduce(math.max); diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart index b8cfc311..d2a154cf 100644 --- a/lib/src/entrypoint.dart +++ b/lib/src/entrypoint.dart @@ -11,6 +11,7 @@ import 'package:path/path.dart' as p; import 'package:pub_semver/pub_semver.dart'; import 'barback/asset_environment.dart'; +import 'barback/compiler.dart'; import 'dart.dart' as dart; import 'exceptions.dart'; import 'flutter.dart' as flutter; @@ -258,7 +259,7 @@ class Entrypoint { .toSet(); var environment = await AssetEnvironment.create(this, BarbackMode.DEBUG, - packages: packagesToLoad, useDart2JS: false); + packages: packagesToLoad, compiler: Compiler.none); /// Ignore barback errors since they'll be emitted via [getAllAssets] /// below. @@ -408,7 +409,7 @@ class Entrypoint { var environment = await AssetEnvironment.create(this, BarbackMode.RELEASE, packages: packagesToLoad.map((package) => package.name), entrypoints: executableIds, - useDart2JS: false); + compiler: Compiler.none); environment.barback.errors.listen((error) { log.error(log.red("Build error:\n$error")); }); diff --git a/lib/src/executable.dart b/lib/src/executable.dart index bb8cbb47..4c52b778 100644 --- a/lib/src/executable.dart +++ b/lib/src/executable.dart @@ -10,6 +10,7 @@ import 'package:barback/barback.dart'; import 'package:path/path.dart' as p; import 'barback/asset_environment.dart'; +import 'barback/compiler.dart'; import 'entrypoint.dart'; import 'exit_codes.dart' as exit_codes; import 'io.dart'; @@ -136,7 +137,7 @@ Future<Uri> _executableUrl(Entrypoint entrypoint, String package, String path, // TODO(nweiz): Use [packages] to only load assets from packages that the // executable might load. var environment = await AssetEnvironment - .create(entrypoint, mode, useDart2JS: false, entrypoints: [id]); + .create(entrypoint, mode, compiler: Compiler.none, entrypoints: [id]); environment.barback.errors.listen((error) { log.error(log.red("Build error:\n$error")); }); diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index 23bfd61e..e44e0ebf 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart @@ -10,6 +10,7 @@ import 'package:barback/barback.dart'; import 'package:pub_semver/pub_semver.dart'; import 'barback/asset_environment.dart'; +import 'barback/compiler.dart'; import 'dart.dart' as dart; import 'entrypoint.dart'; import 'exceptions.dart'; @@ -248,7 +249,7 @@ class GlobalPackages { Entrypoint entrypoint, Package package, String dir) async { var environment = await AssetEnvironment.create( entrypoint, BarbackMode.RELEASE, - entrypoints: package.executableIds, useDart2JS: false); + entrypoints: package.executableIds, compiler: Compiler.none); environment.barback.errors.listen((error) { log.error(log.red("Build error:\n$error")); }); diff --git a/lib/src/package_graph.dart b/lib/src/package_graph.dart index f0bd549a..12f30bce 100644 --- a/lib/src/package_graph.dart +++ b/lib/src/package_graph.dart @@ -4,6 +4,7 @@ import 'package:collection/collection.dart'; +import 'barback/compiler.dart'; import 'barback/transformer_cache.dart'; import 'entrypoint.dart'; import 'lock_file.dart'; @@ -44,12 +45,13 @@ class PackageGraph { factory PackageGraph.fromSolveResult( Entrypoint entrypoint, SolveResult result) { var packages = new Map<String, Package>.fromIterable(result.packages, - key: (id) => id.name, value: (id) { - if (id.name == entrypoint.root.name) return entrypoint.root; + key: (id) => id.name, + value: (id) { + if (id.name == entrypoint.root.name) return entrypoint.root; - return new Package(result.pubspecs[id.name], - entrypoint.cache.source(id.source).getDirectory(id)); - }); + return new Package(result.pubspecs[id.name], + entrypoint.cache.source(id.source).getDirectory(id)); + }); return new PackageGraph(entrypoint, result.lockFile, packages); } @@ -151,9 +153,13 @@ class PackageGraph { /// from a cached source. Static packages don't need to be fully processed by /// barback. /// + /// If [compiler] is [Compiler.dartDevc] then no package is static because the + /// transformer will be added to all packages. + /// /// Note that a static package isn't the same as an immutable package (see /// [isPackageMutable]). - bool isPackageStatic(String package) { + bool isPackageStatic(String package, Compiler compiler) { + if (compiler == Compiler.dartDevc) return false; var id = lockFile.packages[package]; if (id == null) return false; if (entrypoint.cache.source(id.source) is! CachedSource) return false; diff --git a/test/dart2js/allows_import_in_dart_code_test.dart b/test/compiler/allows_import_in_dart_code_test.dart similarity index 100% rename from test/dart2js/allows_import_in_dart_code_test.dart rename to test/compiler/allows_import_in_dart_code_test.dart diff --git a/test/compiler/compiler_flag_test.dart b/test/compiler/compiler_flag_test.dart new file mode 100644 index 00000000..91cb0a2a --- /dev/null +++ b/test/compiler/compiler_flag_test.dart @@ -0,0 +1,62 @@ +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS d.file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:scheduled_test/scheduled_stream.dart'; + +import 'package:pub/src/exit_codes.dart'; + +import '../descriptor.dart' as d; +import '../test_pub.dart'; +import '../serve/utils.dart'; + +main() { + integration("compiler flag switches compilers", () { + d.dir(appPath, [ + d.appPubspec(), + d.dir("lib", [ + d.file("hello.dart", "hello() => print('hello');"), + ]) + ]).create(); + + pubGet(); + var process = startPubServe(args: ['--compiler', 'dartdevc']); + // TODO(jakemac53): Update when dartdevc is supported. + process.shouldExit(1); + process.stderr + .expect(consumeThrough('The dartdevc compiler is not yet supported.')); + }); + + integration("invalid compiler flag gives an error", () { + d.dir(appPath, [ + d.appPubspec(), + ]).create(); + + pubGet(); + var process = startPubServe(args: ['--compiler', 'invalid']); + process.shouldExit(USAGE); + process.stderr.expect(consumeThrough( + '"invalid" is not an allowed value for option "compiler".')); + }); + + integration("--dart2js with --compiler is invalid", () { + d.dir(appPath, [ + d.appPubspec(), + ]).create(); + + pubGet(); + var argCombos = [ + ['--dart2js', '--compiler=dartdevc'], + ['--no-dart2js', '--compiler=dartdevc'], + ['--dart2js', '--compiler=dart2js'], + ['--no-dart2js', '--compiler=dart2js'], + ]; + for (var args in argCombos) { + var process = startPubServe(args: args); + process.shouldExit(USAGE); + process.stderr.expect(consumeThrough( + "The --dart2js flag can't be used with the --compiler arg. Prefer " + "using the --compiler arg as --[no]-dart2js is deprecated.")); + } + }); +} diff --git a/test/dart2js/compiles_entrypoints_in_root_package_test.dart b/test/compiler/compiles_entrypoints_in_root_package_test.dart similarity index 100% rename from test/dart2js/compiles_entrypoints_in_root_package_test.dart rename to test/compiler/compiles_entrypoints_in_root_package_test.dart diff --git a/test/dart2js/compiles_generated_dart_file_test.dart b/test/compiler/compiles_generated_dart_file_test.dart similarity index 100% rename from test/dart2js/compiles_generated_dart_file_test.dart rename to test/compiler/compiles_generated_dart_file_test.dart diff --git a/test/dart2js/compiles_generated_file_from_dependency_outside_web_test.dart b/test/compiler/compiles_generated_file_from_dependency_outside_web_test.dart similarity index 100% rename from test/dart2js/compiles_generated_file_from_dependency_outside_web_test.dart rename to test/compiler/compiles_generated_file_from_dependency_outside_web_test.dart diff --git a/test/dart2js/compiles_generated_file_from_dependency_test.dart b/test/compiler/compiles_generated_file_from_dependency_test.dart similarity index 100% rename from test/dart2js/compiles_generated_file_from_dependency_test.dart rename to test/compiler/compiles_generated_file_from_dependency_test.dart diff --git a/test/dart2js/compiles_imported_generated_file_test.dart b/test/compiler/compiles_imported_generated_file_test.dart similarity index 100% rename from test/dart2js/compiles_imported_generated_file_test.dart rename to test/compiler/compiles_imported_generated_file_test.dart diff --git a/test/dart2js/converts_isolate_entrypoint_in_web_test.dart b/test/compiler/converts_isolate_entrypoint_in_web_test.dart similarity index 100% rename from test/dart2js/converts_isolate_entrypoint_in_web_test.dart rename to test/compiler/converts_isolate_entrypoint_in_web_test.dart diff --git a/test/dart2js/does_not_compile_if_disabled_test.dart b/test/compiler/does_not_compile_if_disabled_test.dart similarity index 100% rename from test/dart2js/does_not_compile_if_disabled_test.dart rename to test/compiler/does_not_compile_if_disabled_test.dart diff --git a/test/dart2js/does_not_compile_until_its_output_is_requested_test.dart b/test/compiler/does_not_compile_until_its_output_is_requested_test.dart similarity index 100% rename from test/dart2js/does_not_compile_until_its_output_is_requested_test.dart rename to test/compiler/does_not_compile_until_its_output_is_requested_test.dart diff --git a/test/dart2js/does_not_support_invalid_command_line_options_type_test.dart b/test/compiler/does_not_support_invalid_command_line_options_type_test.dart similarity index 100% rename from test/dart2js/does_not_support_invalid_command_line_options_type_test.dart rename to test/compiler/does_not_support_invalid_command_line_options_type_test.dart diff --git a/test/dart2js/does_not_support_invalid_environment_type_test.dart b/test/compiler/does_not_support_invalid_environment_type_test.dart similarity index 100% rename from test/dart2js/does_not_support_invalid_environment_type_test.dart rename to test/compiler/does_not_support_invalid_environment_type_test.dart diff --git a/test/dart2js/does_not_support_invalid_option_test.dart b/test/compiler/does_not_support_invalid_option_test.dart similarity index 100% rename from test/dart2js/does_not_support_invalid_option_test.dart rename to test/compiler/does_not_support_invalid_option_test.dart diff --git a/test/dart2js/doesnt_support_invalid_type_for_boolean_option_test.dart b/test/compiler/doesnt_support_invalid_type_for_boolean_option_test.dart similarity index 100% rename from test/dart2js/doesnt_support_invalid_type_for_boolean_option_test.dart rename to test/compiler/doesnt_support_invalid_type_for_boolean_option_test.dart diff --git a/test/dart2js/environment_constant_test.dart b/test/compiler/environment_constant_test.dart similarity index 100% rename from test/dart2js/environment_constant_test.dart rename to test/compiler/environment_constant_test.dart diff --git a/test/dart2js/ignores_entrypoint_in_dependency_test.dart b/test/compiler/ignores_entrypoint_in_dependency_test.dart similarity index 100% rename from test/dart2js/ignores_entrypoint_in_dependency_test.dart rename to test/compiler/ignores_entrypoint_in_dependency_test.dart diff --git a/test/dart2js/ignores_entrypoints_in_lib_test.dart b/test/compiler/ignores_entrypoints_in_lib_test.dart similarity index 100% rename from test/dart2js/ignores_entrypoints_in_lib_test.dart rename to test/compiler/ignores_entrypoints_in_lib_test.dart diff --git a/test/dart2js/ignores_non_entrypoint_dart_files_test.dart b/test/compiler/ignores_non_entrypoint_dart_files_test.dart similarity index 100% rename from test/dart2js/ignores_non_entrypoint_dart_files_test.dart rename to test/compiler/ignores_non_entrypoint_dart_files_test.dart diff --git a/test/dart2js/includes_source_maps_if_sourceMaps_true_test.dart b/test/compiler/includes_source_maps_if_sourceMaps_true_test.dart similarity index 100% rename from test/dart2js/includes_source_maps_if_sourceMaps_true_test.dart rename to test/compiler/includes_source_maps_if_sourceMaps_true_test.dart diff --git a/test/dart2js/includes_source_maps_in_debug_test.dart b/test/compiler/includes_source_maps_in_debug_test.dart similarity index 100% rename from test/dart2js/includes_source_maps_in_debug_test.dart rename to test/compiler/includes_source_maps_in_debug_test.dart diff --git a/test/dart2js/minifies_in_release_mode_test.dart b/test/compiler/minifies_in_release_mode_test.dart similarity index 100% rename from test/dart2js/minifies_in_release_mode_test.dart rename to test/compiler/minifies_in_release_mode_test.dart diff --git a/test/dart2js/minify_configuration_overrides_mode_test.dart b/test/compiler/minify_configuration_overrides_mode_test.dart similarity index 100% rename from test/dart2js/minify_configuration_overrides_mode_test.dart rename to test/compiler/minify_configuration_overrides_mode_test.dart diff --git a/test/dart2js/omits_source_map_if_sourceMaps_false_test.dart b/test/compiler/omits_source_map_if_sourceMaps_false_test.dart similarity index 100% rename from test/dart2js/omits_source_map_if_sourceMaps_false_test.dart rename to test/compiler/omits_source_map_if_sourceMaps_false_test.dart diff --git a/test/dart2js/omits_source_map_in_release_test.dart b/test/compiler/omits_source_map_in_release_test.dart similarity index 100% rename from test/dart2js/omits_source_map_in_release_test.dart rename to test/compiler/omits_source_map_in_release_test.dart diff --git a/test/dart2js/output_can_be_consumed_by_successive_phases.dart b/test/compiler/output_can_be_consumed_by_successive_phases.dart similarity index 100% rename from test/dart2js/output_can_be_consumed_by_successive_phases.dart rename to test/compiler/output_can_be_consumed_by_successive_phases.dart diff --git a/test/dart2js/outputs_deferred_libraries_test.dart b/test/compiler/outputs_deferred_libraries_test.dart similarity index 100% rename from test/dart2js/outputs_deferred_libraries_test.dart rename to test/compiler/outputs_deferred_libraries_test.dart diff --git a/test/dart2js/passes_along_environment_constants_test.dart b/test/compiler/passes_along_environment_constants_test.dart similarity index 100% rename from test/dart2js/passes_along_environment_constants_test.dart rename to test/compiler/passes_along_environment_constants_test.dart diff --git a/test/dart2js/reports_dart_parse_errors_test.dart b/test/compiler/reports_dart_parse_errors_test.dart similarity index 100% rename from test/dart2js/reports_dart_parse_errors_test.dart rename to test/compiler/reports_dart_parse_errors_test.dart diff --git a/test/dart2js/source_maps_are_self_contained_test.dart b/test/compiler/source_maps_are_self_contained_test.dart similarity index 100% rename from test/dart2js/source_maps_are_self_contained_test.dart rename to test/compiler/source_maps_are_self_contained_test.dart diff --git a/test/dart2js/source_maps_include_core_libs_in_subdirectory_test.dart b/test/compiler/source_maps_include_core_libs_in_subdirectory_test.dart similarity index 100% rename from test/dart2js/source_maps_include_core_libs_in_subdirectory_test.dart rename to test/compiler/source_maps_include_core_libs_in_subdirectory_test.dart diff --git a/test/dart2js/source_maps_include_core_libs_test.dart b/test/compiler/source_maps_include_core_libs_test.dart similarity index 100% rename from test/dart2js/source_maps_include_core_libs_test.dart rename to test/compiler/source_maps_include_core_libs_test.dart diff --git a/test/dart2js/supports_configuration_with_build_test.dart b/test/compiler/supports_configuration_with_build_test.dart similarity index 100% rename from test/dart2js/supports_configuration_with_build_test.dart rename to test/compiler/supports_configuration_with_build_test.dart diff --git a/test/dart2js/supports_valid_options_test.dart b/test/compiler/supports_valid_options_test.dart similarity index 100% rename from test/dart2js/supports_valid_options_test.dart rename to test/compiler/supports_valid_options_test.dart diff --git a/test/dart2js/unminified_in_nonrelease_mode_test.dart b/test/compiler/unminified_in_nonrelease_mode_test.dart similarity index 100% rename from test/dart2js/unminified_in_nonrelease_mode_test.dart rename to test/compiler/unminified_in_nonrelease_mode_test.dart -- GitLab