flutter/packages/flutter_tools/test/general.shard/hot_shared.dart
Daco Harkes 4e70bfae2b
Reland "Move native assets to isolated/ directory" (#143055)
Reland of https://github.com/flutter/flutter/pull/142709.

The revert of the revert is in the first commit, the fix in the commit on top.

The move of the fakes for packages/flutter_tools/test/general.shard/resident_runner_test.dart was erroneous before, as it was trying to use setters instead of a private field. This PR changes the private `_devFS` field in the fake to be a public `fakeDevFS` in line with other fakes.

## Original PR description

Native assets in other build systems are not built with `package:native_assets_builder` invoking `build.dart` scripts. Instead all packages have their own blaze rules. Therefore we'd like to not depend on `package:native_assets_builder` from flutter tools in g3 at all.

This PR aims to move the imports of `native_assets_builder` and `native_assets_cli` into the `isolated/` directory and into the files with a `main` function that are not used in with other build systems.

In order to be able to remove all imports in files used by other build systems, two new interfaces are added `HotRunnerNativeAssetsBuilder` and `TestCompilerNativeAssetsBuilder`. New parameters are then piped all the way through from the entry points:

* bin/fuchsia_tester.dart
* lib/executable.dart

The build_system/targets dir is already excluded in other build systems.

So, after this PR only the two above files and build_system/targets import from `isolated/native_assets/` and only `isolated/native_assets/` import `package:native_assets_cli` and `package:native_assets_builder`.

Context:

* https://github.com/flutter/flutter/issues/142041
2024-02-08 17:49:48 +00:00

232 lines
5.9 KiB
Dart

// Copyright 2014 The Flutter Authors. 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:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/tools/shader_compiler.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/run_hot.dart';
import 'package:flutter_tools/src/vmservice.dart';
import 'package:package_config/package_config.dart';
import 'package:test/fake.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
class FakeDevFs extends Fake implements DevFS {
@override
Future<void> destroy() async { }
@override
List<Uri> sources = <Uri>[];
@override
DateTime? lastCompiled;
@override
PackageConfig? lastPackageConfig;
@override
Set<String> assetPathsToEvict = <String>{};
@override
Set<String> shaderPathsToEvict= <String>{};
@override
Set<String> scenePathsToEvict= <String>{};
@override
Uri? baseUri;
}
class FakeDevice extends Fake implements Device {
FakeDevice({
TargetPlatform targetPlatform = TargetPlatform.tester,
}) : _targetPlatform = targetPlatform;
final TargetPlatform _targetPlatform;
bool disposed = false;
@override
bool isSupported() => true;
@override
bool supportsHotReload = true;
@override
bool supportsHotRestart = true;
@override
bool supportsFlutterExit = true;
@override
Future<TargetPlatform> get targetPlatform async => _targetPlatform;
@override
Future<String> get sdkNameAndVersion async => 'Tester';
@override
Future<bool> get isLocalEmulator async => false;
@override
String get name => 'Fake Device';
@override
Future<bool> stopApp(
ApplicationPackage? app, {
String? userIdentifier,
}) async {
return true;
}
@override
Future<void> dispose() async {
disposed = true;
}
}
class FakeFlutterDevice extends Fake implements FlutterDevice {
FakeFlutterDevice(this.device);
bool stoppedEchoingDeviceLog = false;
late Future<UpdateFSReport> Function() updateDevFSReportCallback;
@override
final FakeDevice device;
@override
Future<void> stopEchoingDeviceLog() async {
stoppedEchoingDeviceLog = true;
}
@override
DevFS? devFS = FakeDevFs();
@override
FlutterVmService get vmService => FakeFlutterVmService();
@override
ResidentCompiler? generator;
@override
Future<UpdateFSReport> updateDevFS({
Uri? mainUri,
String? target,
AssetBundle? bundle,
DateTime? firstBuildTime,
bool bundleFirstUpload = false,
bool bundleDirty = false,
bool fullRestart = false,
String? projectRootPath,
String? pathToReload,
required String dillOutputPath,
required List<Uri> invalidatedFiles,
required PackageConfig packageConfig,
}) => updateDevFSReportCallback();
@override
TargetPlatform? get targetPlatform => device._targetPlatform;
}
class TestFlutterDevice extends FlutterDevice {
TestFlutterDevice({
required Device device,
required this.exception,
required ResidentCompiler generator,
}) : super(device, buildInfo: BuildInfo.debug, generator: generator, developmentShaderCompiler: const FakeShaderCompiler());
/// The exception to throw when the connect method is called.
final Exception exception;
@override
Future<void> connect({
ReloadSources? reloadSources,
Restart? restart,
CompileExpression? compileExpression,
GetSkSLMethod? getSkSLMethod,
FlutterProject? flutterProject,
PrintStructuredErrorLogMethod? printStructuredErrorLogMethod,
bool disableServiceAuthCodes = false,
bool enableDds = true,
bool cacheStartupProfile = false,
bool? ipv6 = false,
int? hostVmServicePort,
int? ddsPort,
bool allowExistingDdsInstance = false,
}) async {
throw exception;
}
}
class TestHotRunnerConfig extends HotRunnerConfig {
TestHotRunnerConfig({this.successfulHotRestartSetup, this.successfulHotReloadSetup});
bool? successfulHotRestartSetup;
bool? successfulHotReloadSetup;
bool shutdownHookCalled = false;
bool updateDevFSCompleteCalled = false;
@override
Future<bool?> setupHotRestart() async {
assert(successfulHotRestartSetup != null, 'setupHotRestart is not expected to be called in this test.');
return successfulHotRestartSetup;
}
@override
Future<bool?> setupHotReload() async {
assert(successfulHotReloadSetup != null, 'setupHotReload is not expected to be called in this test.');
return successfulHotReloadSetup;
}
@override
void updateDevFSComplete() {
updateDevFSCompleteCalled = true;
}
@override
Future<void> runPreShutdownOperations() async {
shutdownHookCalled = true;
}
}
class FakeResidentCompiler extends Fake implements ResidentCompiler {
@override
void accept() {}
}
class FakeFlutterVmService extends Fake implements FlutterVmService {
@override
vm_service.VmService get service => FakeVmService();
@override
Future<List<FlutterView>> getFlutterViews({bool returnEarly = false, Duration delay = const Duration(milliseconds: 50)}) async {
return <FlutterView>[];
}
}
class FakeVmService extends Fake implements vm_service.VmService {
@override
Future<vm_service.VM> getVM() async => FakeVm();
}
class FakeVm extends Fake implements vm_service.VM {
@override
List<vm_service.IsolateRef> get isolates => <vm_service.IsolateRef>[];
}
class FakeShaderCompiler implements DevelopmentShaderCompiler {
const FakeShaderCompiler();
@override
void configureCompiler(TargetPlatform? platform) { }
@override
Future<DevFSContent> recompileShader(DevFSContent inputShader) {
throw UnimplementedError();
}
}