Fix --local-engine for the new web/wasm mode (#113759)
This commit is contained in:
@@ -273,6 +273,13 @@ void main() {
|
||||
.childDirectory('ios-arm64_armv7')
|
||||
.childDirectory('Flutter.framework')
|
||||
.createSync(recursive: true);
|
||||
fileSystem
|
||||
.directory('out')
|
||||
.childDirectory('host_debug_unopt')
|
||||
.childDirectory('dart-sdk')
|
||||
.childDirectory('bin')
|
||||
.createSync(recursive: true);
|
||||
|
||||
expect(
|
||||
artifacts.getArtifactPath(
|
||||
Artifact.flutterFramework,
|
||||
@@ -325,6 +332,75 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('falls back to prebuilt dart sdk', () {
|
||||
final String failureMessage = 'Unable to find a built dart sdk at:'
|
||||
' "${fileSystem.path.join('/out', 'host_debug_unopt', 'dart-sdk')}"'
|
||||
' or a prebuilt dart sdk at:'
|
||||
' "${fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk')}"';
|
||||
|
||||
expect(
|
||||
() => artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
|
||||
throwsToolExit(message: failureMessage),
|
||||
);
|
||||
expect(
|
||||
() => artifacts.getHostArtifact(HostArtifact.engineDartSdkPath),
|
||||
throwsToolExit(message: failureMessage),
|
||||
);
|
||||
expect(
|
||||
() => artifacts.getHostArtifact(HostArtifact.engineDartBinary),
|
||||
throwsToolExit(message: failureMessage),
|
||||
);
|
||||
expect(
|
||||
() => artifacts.getHostArtifact(HostArtifact.dart2jsSnapshot),
|
||||
throwsToolExit(message: failureMessage),
|
||||
);
|
||||
expect(
|
||||
() => artifacts.getHostArtifact(HostArtifact.dartdevcSnapshot),
|
||||
throwsToolExit(message: failureMessage),
|
||||
);
|
||||
expect(
|
||||
() => artifacts.getHostArtifact(HostArtifact.kernelWorkerSnapshot),
|
||||
throwsToolExit(message: failureMessage),
|
||||
);
|
||||
|
||||
fileSystem
|
||||
.directory('flutter')
|
||||
.childDirectory('prebuilts')
|
||||
.childDirectory('linux-x64')
|
||||
.childDirectory('dart-sdk')
|
||||
.childDirectory('bin')
|
||||
.createSync(recursive: true);
|
||||
|
||||
expect(
|
||||
artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
|
||||
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk', 'bin',
|
||||
'snapshots', 'frontend_server.dart.snapshot'),
|
||||
);
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path,
|
||||
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk'),
|
||||
);
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.engineDartBinary).path,
|
||||
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk', 'bin', 'dart'),
|
||||
);
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.dart2jsSnapshot).path,
|
||||
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk',
|
||||
'bin', 'snapshots', 'dart2js.dart.snapshot'),
|
||||
);
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.dartdevcSnapshot).path,
|
||||
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk',
|
||||
'bin', 'snapshots', 'dartdevc.dart.snapshot'),
|
||||
);
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.kernelWorkerSnapshot).path,
|
||||
fileSystem.path.join('/flutter', 'prebuilts', 'linux-x64', 'dart-sdk',
|
||||
'bin', 'snapshots', 'kernel_worker.dart.snapshot'),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('getEngineType', () {
|
||||
expect(
|
||||
artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug),
|
||||
@@ -351,11 +427,81 @@ void main() {
|
||||
operatingSystemUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
|
||||
expect(artifacts.getHostArtifact(HostArtifact.engineDartBinary).path, contains('.exe'));
|
||||
fileSystem
|
||||
.directory('out')
|
||||
.childDirectory('host_debug_unopt')
|
||||
.childDirectory('dart-sdk')
|
||||
.childDirectory('bin')
|
||||
.createSync(recursive: true);
|
||||
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.engineDartBinary).path,
|
||||
fileSystem.path.join('/out', 'host_debug_unopt', 'dart-sdk', 'bin', 'dart.exe'),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('Looks up dart on linux platforms', () async {
|
||||
expect(artifacts.getHostArtifact(HostArtifact.engineDartBinary).path, isNot(contains('.exe')));
|
||||
fileSystem
|
||||
.directory('/out')
|
||||
.childDirectory('host_debug_unopt')
|
||||
.childDirectory('dart-sdk')
|
||||
.childDirectory('bin')
|
||||
.createSync(recursive: true);
|
||||
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.engineDartBinary).path,
|
||||
fileSystem.path.join('/out', 'host_debug_unopt', 'dart-sdk', 'bin', 'dart'),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('Finds dart-sdk in windows prebuilts', () async {
|
||||
artifacts = LocalEngineArtifacts(
|
||||
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'android_debug_unopt'),
|
||||
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'host_debug_unopt'),
|
||||
cache: cache,
|
||||
fileSystem: fileSystem,
|
||||
platform: FakePlatform(operatingSystem: 'windows'),
|
||||
processManager: FakeProcessManager.any(),
|
||||
operatingSystemUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
|
||||
fileSystem
|
||||
.directory('/flutter')
|
||||
.childDirectory('prebuilts')
|
||||
.childDirectory('windows-x64')
|
||||
.childDirectory('dart-sdk')
|
||||
.childDirectory('bin')
|
||||
.createSync(recursive: true);
|
||||
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.engineDartBinary).path,
|
||||
fileSystem.path.join('/flutter', 'prebuilts', 'windows-x64', 'dart-sdk', 'bin', 'dart.exe'),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('Finds dart-sdk in macos prebuilts', () async {
|
||||
artifacts = LocalEngineArtifacts(
|
||||
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'android_debug_unopt'),
|
||||
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'host_debug_unopt'),
|
||||
cache: cache,
|
||||
fileSystem: fileSystem,
|
||||
platform: FakePlatform(operatingSystem: 'macos'),
|
||||
processManager: FakeProcessManager.any(),
|
||||
operatingSystemUtils: FakeOperatingSystemUtils(),
|
||||
);
|
||||
|
||||
fileSystem
|
||||
.directory('/flutter')
|
||||
.childDirectory('prebuilts')
|
||||
.childDirectory('macos-x64')
|
||||
.childDirectory('dart-sdk')
|
||||
.childDirectory('bin')
|
||||
.createSync(recursive: true);
|
||||
|
||||
expect(
|
||||
artifacts.getHostArtifact(HostArtifact.engineDartBinary).path,
|
||||
fileSystem.path.join('/flutter', 'prebuilts', 'macos-x64', 'dart-sdk', 'bin', 'dart'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:flutter_tools/src/artifacts.dart';
|
||||
import 'package:flutter_tools/src/asset.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/bundle_builder.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
@@ -457,6 +458,82 @@ flutter:
|
||||
),
|
||||
]),
|
||||
});
|
||||
|
||||
testUsingContext('Included shaders are not compiled for the web', () async {
|
||||
fileSystem.file('.packages').createSync();
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
flutter:
|
||||
shaders:
|
||||
- assets/shader.frag
|
||||
''');
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
|
||||
expect(await bundle.build(packagesPath: '.packages', targetPlatform: TargetPlatform.web_javascript), 0);
|
||||
|
||||
await writeBundle(
|
||||
output,
|
||||
bundle.entries,
|
||||
bundle.entryKinds,
|
||||
loggerOverride: testLogger,
|
||||
);
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
Artifacts: () => artifacts,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
|
||||
// No impeller commands are expected here because shader compilation is
|
||||
// not supposed to happen for the web.
|
||||
]),
|
||||
});
|
||||
|
||||
testUsingContext('Material shaders are not compiled for the web', () async {
|
||||
fileSystem.file('.packages').createSync();
|
||||
|
||||
final String materialIconsPath = fileSystem.path.join(
|
||||
getFlutterRoot(),
|
||||
'bin', 'cache', 'artifacts', 'material_fonts',
|
||||
'MaterialIcons-Regular.otf',
|
||||
);
|
||||
fileSystem.file(materialIconsPath).createSync(recursive: true);
|
||||
|
||||
final String materialPath = fileSystem.path.join(
|
||||
getFlutterRoot(),
|
||||
'packages', 'flutter', 'lib', 'src', 'material',
|
||||
);
|
||||
final Directory materialDir = fileSystem.directory(materialPath)..createSync(recursive: true);
|
||||
for (final String shader in kMaterialShaders) {
|
||||
materialDir.childFile(shader).createSync(recursive: true);
|
||||
}
|
||||
|
||||
fileSystem.file('pubspec.yaml')
|
||||
..createSync()
|
||||
..writeAsStringSync(r'''
|
||||
name: example
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
''');
|
||||
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
||||
|
||||
expect(await bundle.build(packagesPath: '.packages', targetPlatform: TargetPlatform.web_javascript), 0);
|
||||
|
||||
await writeBundle(
|
||||
output,
|
||||
bundle.entries,
|
||||
bundle.entryKinds,
|
||||
loggerOverride: testLogger,
|
||||
);
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
Artifacts: () => artifacts,
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
|
||||
// No impeller commands are expected here because shader compilation is
|
||||
// not supposed to happen for the web.
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
testUsingContext('Does not insert dummy file into additionalDependencies '
|
||||
|
||||
@@ -216,6 +216,52 @@ void main() {
|
||||
contains('Unable to detect local Flutter engine src directory'),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('works for local web engine', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Directory localWasmEngine = fileSystem
|
||||
.directory('$kArbitraryEngineRoot/src/out/wasm_whatever/')
|
||||
..createSync(recursive: true);
|
||||
final Directory localWebEngine = fileSystem
|
||||
.directory('$kArbitraryEngineRoot/src/out/web_whatever/')
|
||||
..createSync(recursive: true);
|
||||
|
||||
final BufferLogger wasmLogger = BufferLogger.test();
|
||||
final LocalEngineLocator localWasmEngineLocator = LocalEngineLocator(
|
||||
fileSystem: fileSystem,
|
||||
flutterRoot: 'flutter/flutter',
|
||||
logger: wasmLogger,
|
||||
userMessages: UserMessages(),
|
||||
platform: FakePlatform(environment: <String, String>{}),
|
||||
);
|
||||
|
||||
expect(
|
||||
await localWasmEngineLocator.findEnginePath(null, localWasmEngine.path, null),
|
||||
matchesEngineBuildPaths(
|
||||
hostEngine: '/arbitrary/engine/src/out/wasm_whatever',
|
||||
targetEngine: '/arbitrary/engine/src/out/wasm_whatever',
|
||||
),
|
||||
);
|
||||
expect(wasmLogger.traceText, contains('Local engine source at /arbitrary/engine/src'));
|
||||
|
||||
final BufferLogger webLogger = BufferLogger.test();
|
||||
final LocalEngineLocator localWebEngineLocator = LocalEngineLocator(
|
||||
fileSystem: fileSystem,
|
||||
flutterRoot: 'flutter/flutter',
|
||||
logger: webLogger,
|
||||
userMessages: UserMessages(),
|
||||
platform: FakePlatform(environment: <String, String>{}),
|
||||
);
|
||||
|
||||
expect(
|
||||
await localWebEngineLocator.findEnginePath(null, localWebEngine.path, null),
|
||||
matchesEngineBuildPaths(
|
||||
hostEngine: '/arbitrary/engine/src/out/web_whatever',
|
||||
targetEngine: '/arbitrary/engine/src/out/web_whatever',
|
||||
),
|
||||
);
|
||||
expect(webLogger.traceText, contains('Local engine source at /arbitrary/engine/src'));
|
||||
});
|
||||
}
|
||||
|
||||
Matcher matchesEngineBuildPaths({
|
||||
|
||||
Reference in New Issue
Block a user