Unverified Commit 79a985f9 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add compiler configuration to support dartdevc target (#43281)

parent 58c46a83
...@@ -40,6 +40,8 @@ enum Artifact { ...@@ -40,6 +40,8 @@ enum Artifact {
kernelWorkerSnapshot, kernelWorkerSnapshot,
/// The root of the web implementation of the dart SDK. /// The root of the web implementation of the dart SDK.
flutterWebSdk, flutterWebSdk,
/// The summary dill for the dartdevc target.
webPlatformKernelDill,
iosDeploy, iosDeploy,
ideviceinfo, ideviceinfo,
ideviceId, ideviceId,
...@@ -126,6 +128,8 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo ...@@ -126,6 +128,8 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
return 'sky_engine'; return 'sky_engine';
case Artifact.flutterMacOSPodspec: case Artifact.flutterMacOSPodspec:
return 'FlutterMacOS.podspec'; return 'FlutterMacOS.podspec';
case Artifact.webPlatformKernelDill:
return 'flutter_ddc_sdk.dill';
} }
assert(false, 'Invalid artifact $artifact.'); assert(false, 'Invalid artifact $artifact.');
return null; return null;
...@@ -290,6 +294,8 @@ class CachedArtifacts extends Artifacts { ...@@ -290,6 +294,8 @@ class CachedArtifacts extends Artifacts {
return _getFlutterPatchedSdkPath(mode); return _getFlutterPatchedSdkPath(mode);
case Artifact.flutterWebSdk: case Artifact.flutterWebSdk:
return _getFlutterWebSdkPath(); return _getFlutterWebSdkPath();
case Artifact.webPlatformKernelDill:
return fs.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact));
case Artifact.dart2jsSnapshot: case Artifact.dart2jsSnapshot:
return fs.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact)); return fs.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact));
case Artifact.dartdevcSnapshot: case Artifact.dartdevcSnapshot:
...@@ -422,6 +428,8 @@ class LocalEngineArtifacts extends Artifacts { ...@@ -422,6 +428,8 @@ class LocalEngineArtifacts extends Artifacts {
return fs.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName); return fs.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName);
case Artifact.flutterMacOSPodspec: case Artifact.flutterMacOSPodspec:
return fs.path.join(_hostEngineOutPath, _artifactToFileName(artifact)); return fs.path.join(_hostEngineOutPath, _artifactToFileName(artifact));
case Artifact.webPlatformKernelDill:
return fs.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact));
} }
assert(false, 'Invalid artifact $artifact.'); assert(false, 'Invalid artifact $artifact.');
return null; return null;
......
This diff is collapsed.
...@@ -39,6 +39,9 @@ class FeatureFlags { ...@@ -39,6 +39,9 @@ class FeatureFlags {
/// Whether the Android embedding V2 is enabled. /// Whether the Android embedding V2 is enabled.
bool get isAndroidEmbeddingV2Enabled => isEnabled(flutterAndroidEmbeddingV2Feature); bool get isAndroidEmbeddingV2Enabled => isEnabled(flutterAndroidEmbeddingV2Feature);
/// Whether the web incremental compiler is enabled.
bool get isWebIncrementalCompilerEnabled => isEnabled(flutterWebIncrementalCompiler);
/// Whether a particular feature is enabled for the current channel. /// Whether a particular feature is enabled for the current channel.
/// ///
/// Prefer using one of the specific getters above instead of this API. /// Prefer using one of the specific getters above instead of this API.
...@@ -72,6 +75,7 @@ const List<Feature> allFeatures = <Feature>[ ...@@ -72,6 +75,7 @@ const List<Feature> allFeatures = <Feature>[
flutterWindowsDesktopFeature, flutterWindowsDesktopFeature,
flutterBuildPluginAsAarFeature, flutterBuildPluginAsAarFeature,
flutterAndroidEmbeddingV2Feature, flutterAndroidEmbeddingV2Feature,
flutterWebIncrementalCompiler,
]; ];
/// The [Feature] for flutter web. /// The [Feature] for flutter web.
...@@ -143,6 +147,16 @@ const Feature flutterAndroidEmbeddingV2Feature = Feature( ...@@ -143,6 +147,16 @@ const Feature flutterAndroidEmbeddingV2Feature = Feature(
), ),
); );
/// The [Feature] for using the incremental compiler instead of build runner.
const Feature flutterWebIncrementalCompiler = Feature(
name: 'Enable the incremental compiler for web builds',
configSetting: 'enable-web-incremental-compiler',
master: FeatureChannelSetting(
available: true,
enabledByDefault: false,
),
);
/// A [Feature] is a process for conditionally enabling tool features. /// A [Feature] is a process for conditionally enabling tool features.
/// ///
/// All settings are optional, and if not provided will generally default to /// All settings are optional, and if not provided will generally default to
......
...@@ -22,6 +22,7 @@ import 'compile.dart'; ...@@ -22,6 +22,7 @@ import 'compile.dart';
import 'dart/package_map.dart'; import 'dart/package_map.dart';
import 'devfs.dart'; import 'devfs.dart';
import 'device.dart'; import 'device.dart';
import 'features.dart';
import 'globals.dart'; import 'globals.dart';
import 'project.dart'; import 'project.dart';
import 'run_cold.dart'; import 'run_cold.dart';
...@@ -65,7 +66,19 @@ class FlutterDevice { ...@@ -65,7 +66,19 @@ class FlutterDevice {
ResidentCompiler generator, ResidentCompiler generator,
}) async { }) async {
ResidentCompiler generator; ResidentCompiler generator;
if (flutterProject.hasBuilders) { if (featureFlags.isWebIncrementalCompilerEnabled &&
await device.targetPlatform == TargetPlatform.web_javascript) {
generator = ResidentCompiler(
artifacts.getArtifactPath(Artifact.flutterWebSdk, mode: buildMode),
buildMode: buildMode,
trackWidgetCreation: trackWidgetCreation,
fileSystemRoots: fileSystemRoots,
fileSystemScheme: fileSystemScheme,
targetModel: TargetModel.dartdevc,
experimentalFlags: experimentalFlags,
platformDill: artifacts.getArtifactPath(Artifact.webPlatformKernelDill, mode: buildMode),
);
} else if (flutterProject.hasBuilders) {
generator = await CodeGeneratingResidentCompiler.create( generator = await CodeGeneratingResidentCompiler.create(
buildMode: buildMode, buildMode: buildMode,
flutterProject: flutterProject, flutterProject: flutterProject,
......
...@@ -37,6 +37,10 @@ void main() { ...@@ -37,6 +37,10 @@ void main() {
expect(TargetModel('flutter_runner'), TargetModel.flutterRunner); expect(TargetModel('flutter_runner'), TargetModel.flutterRunner);
expect(TargetModel.flutterRunner.toString(), 'flutter_runner'); expect(TargetModel.flutterRunner.toString(), 'flutter_runner');
expect(TargetModel('dartdevc'), TargetModel.dartdevc);
expect(TargetModel.dartdevc.toString(), 'dartdevc');
expect(() => TargetModel('foobar'), throwsA(isInstanceOf<AssertionError>())); expect(() => TargetModel('foobar'), throwsA(isInstanceOf<AssertionError>()));
}); });
} }
...@@ -5,14 +5,18 @@ ...@@ -5,14 +5,18 @@
import 'dart:async'; import 'dart:async';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/globals.dart'; import 'package:flutter_tools/src/globals.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:flutter_tools/src/resident_runner.dart'; import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/run_cold.dart'; import 'package:flutter_tools/src/run_cold.dart';
...@@ -599,6 +603,29 @@ void main() { ...@@ -599,6 +603,29 @@ void main() {
expect(await fs.file('foo').readAsString(), testUri.toString()); expect(await fs.file('foo').readAsString(), testUri.toString());
})); }));
test('FlutterDevice uses dartdevc configuration when targeting web', () => testbed.run(() async {
final MockDevice mockDevice = MockDevice();
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.web_javascript;
});
final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
mockDevice,
buildMode: BuildMode.debug,
flutterProject: FlutterProject.current(),
target: null,
trackWidgetCreation: true,
)).generator;
expect(residentCompiler.targetModel, TargetModel.dartdevc);
expect(residentCompiler.sdkRoot,
artifacts.getArtifactPath(Artifact.flutterWebSdk, mode: BuildMode.debug) + '/');
expect(residentCompiler.platformDill,
artifacts.getArtifactPath(Artifact.webPlatformKernelDill, mode: BuildMode.debug));
}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isWebIncrementalCompilerEnabled: true),
}));
} }
class MockFlutterDevice extends Mock implements FlutterDevice {} class MockFlutterDevice extends Mock implements FlutterDevice {}
...@@ -608,6 +635,7 @@ class MockDevFS extends Mock implements DevFS {} ...@@ -608,6 +635,7 @@ class MockDevFS extends Mock implements DevFS {}
class MockIsolate extends Mock implements Isolate {} class MockIsolate extends Mock implements Isolate {}
class MockDevice extends Mock implements Device {} class MockDevice extends Mock implements Device {}
class MockUsage extends Mock implements Usage {} class MockUsage extends Mock implements Usage {}
class MockProcessManager extends Mock implements ProcessManager {}
class MockServiceEvent extends Mock implements ServiceEvent {} class MockServiceEvent extends Mock implements ServiceEvent {}
class TestFlutterDevice extends FlutterDevice { class TestFlutterDevice extends FlutterDevice {
TestFlutterDevice(Device device, this.views) TestFlutterDevice(Device device, this.views)
......
...@@ -700,6 +700,7 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -700,6 +700,7 @@ class TestFeatureFlags implements FeatureFlags {
this.isWebEnabled = false, this.isWebEnabled = false,
this.isWindowsEnabled = false, this.isWindowsEnabled = false,
this.isAndroidEmbeddingV2Enabled = false, this.isAndroidEmbeddingV2Enabled = false,
this.isWebIncrementalCompilerEnabled = false,
}); });
@override @override
...@@ -717,6 +718,9 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -717,6 +718,9 @@ class TestFeatureFlags implements FeatureFlags {
@override @override
final bool isAndroidEmbeddingV2Enabled; final bool isAndroidEmbeddingV2Enabled;
@override
final bool isWebIncrementalCompilerEnabled;
@override @override
bool isEnabled(Feature feature) { bool isEnabled(Feature feature) {
switch (feature) { switch (feature) {
...@@ -730,6 +734,8 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -730,6 +734,8 @@ class TestFeatureFlags implements FeatureFlags {
return isWindowsEnabled; return isWindowsEnabled;
case flutterAndroidEmbeddingV2Feature: case flutterAndroidEmbeddingV2Feature:
return isAndroidEmbeddingV2Enabled; return isAndroidEmbeddingV2Enabled;
case flutterWebIncrementalCompiler:
return isWebIncrementalCompilerEnabled;
} }
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment