mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
allow optional direct injection of Config instance into DevFS (#144002)
In service of https://github.com/flutter/flutter/issues/143348
This will make testing of asset transformation hot reload behavior easier (specifically in that we can avoid having to write a test that looks like this: 5d02c27248/packages/flutter_tools/test/general.shard/build_system/targets/assets_test.dart (L167-L249)
This commit is contained in:
parent
4e814a5f3c
commit
37c8df1690
|
@ -800,6 +800,7 @@ HostPlatform getCurrentHostPlatform() {
|
||||||
|
|
||||||
/// Returns the top-level build output directory.
|
/// Returns the top-level build output directory.
|
||||||
String getBuildDirectory([Config? config, FileSystem? fileSystem]) {
|
String getBuildDirectory([Config? config, FileSystem? fileSystem]) {
|
||||||
|
// TODO(andrewkolos): Prefer required parameters instead of falling back to globals.
|
||||||
// TODO(johnmccutchan): Stop calling this function as part of setting
|
// TODO(johnmccutchan): Stop calling this function as part of setting
|
||||||
// up command line argument processing.
|
// up command line argument processing.
|
||||||
final Config localConfig = config ?? globals.config;
|
final Config localConfig = config ?? globals.config;
|
||||||
|
@ -825,8 +826,9 @@ String getAotBuildDirectory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the asset build output directory.
|
/// Returns the asset build output directory.
|
||||||
String getAssetBuildDirectory() {
|
String getAssetBuildDirectory([Config? config, FileSystem? fileSystem]) {
|
||||||
return globals.fs.path.join(getBuildDirectory(), 'flutter_assets');
|
return (fileSystem ?? globals.fs)
|
||||||
|
.path.join(getBuildDirectory(config, fileSystem), 'flutter_assets');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the iOS build output directory.
|
/// Returns the iOS build output directory.
|
||||||
|
|
|
@ -8,6 +8,7 @@ import 'package:package_config/package_config.dart';
|
||||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||||
|
|
||||||
import 'asset.dart';
|
import 'asset.dart';
|
||||||
|
import 'base/config.dart';
|
||||||
import 'base/context.dart';
|
import 'base/context.dart';
|
||||||
import 'base/file_system.dart';
|
import 'base/file_system.dart';
|
||||||
import 'base/io.dart';
|
import 'base/io.dart';
|
||||||
|
@ -456,6 +457,7 @@ class DevFS {
|
||||||
HttpClient? httpClient,
|
HttpClient? httpClient,
|
||||||
Duration? uploadRetryThrottle,
|
Duration? uploadRetryThrottle,
|
||||||
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
|
StopwatchFactory stopwatchFactory = const StopwatchFactory(),
|
||||||
|
Config? config,
|
||||||
}) : _vmService = serviceProtocol,
|
}) : _vmService = serviceProtocol,
|
||||||
_logger = logger,
|
_logger = logger,
|
||||||
_fileSystem = fileSystem,
|
_fileSystem = fileSystem,
|
||||||
|
@ -468,13 +470,15 @@ class DevFS {
|
||||||
httpClient: httpClient ?? ((context.get<HttpClientFactory>() == null)
|
httpClient: httpClient ?? ((context.get<HttpClientFactory>() == null)
|
||||||
? HttpClient()
|
? HttpClient()
|
||||||
: context.get<HttpClientFactory>()!())),
|
: context.get<HttpClientFactory>()!())),
|
||||||
_stopwatchFactory = stopwatchFactory;
|
_stopwatchFactory = stopwatchFactory,
|
||||||
|
_config = config;
|
||||||
|
|
||||||
final FlutterVmService _vmService;
|
final FlutterVmService _vmService;
|
||||||
final _DevFSHttpWriter _httpWriter;
|
final _DevFSHttpWriter _httpWriter;
|
||||||
final Logger _logger;
|
final Logger _logger;
|
||||||
final FileSystem _fileSystem;
|
final FileSystem _fileSystem;
|
||||||
final StopwatchFactory _stopwatchFactory;
|
final StopwatchFactory _stopwatchFactory;
|
||||||
|
final Config? _config;
|
||||||
|
|
||||||
final String fsName;
|
final String fsName;
|
||||||
final Directory? rootDirectory;
|
final Directory? rootDirectory;
|
||||||
|
@ -615,8 +619,8 @@ class DevFS {
|
||||||
|
|
||||||
// The tool writes the assets into the AssetBundle working dir so that they
|
// The tool writes the assets into the AssetBundle working dir so that they
|
||||||
// are in the same location in DevFS and the iOS simulator.
|
// are in the same location in DevFS and the iOS simulator.
|
||||||
final String assetBuildDirPrefix = _asUriPath(getAssetBuildDirectory());
|
final String assetDirectory = getAssetBuildDirectory(_config, _fileSystem);
|
||||||
final String assetDirectory = getAssetBuildDirectory();
|
final String assetBuildDirPrefix = _asUriPath(assetDirectory);
|
||||||
bundle.entries.forEach((String archivePath, AssetBundleEntry entry) {
|
bundle.entries.forEach((String archivePath, AssetBundleEntry entry) {
|
||||||
// If the content is backed by a real file, isModified will file stat and return true if
|
// If the content is backed by a real file, isModified will file stat and return true if
|
||||||
// it was modified since the last time this was called.
|
// it was modified since the last time this was called.
|
||||||
|
|
|
@ -11,6 +11,7 @@ import 'package:file/memory.dart';
|
||||||
import 'package:file_testing/file_testing.dart';
|
import 'package:file_testing/file_testing.dart';
|
||||||
import 'package:flutter_tools/src/artifacts.dart';
|
import 'package:flutter_tools/src/artifacts.dart';
|
||||||
import 'package:flutter_tools/src/asset.dart';
|
import 'package:flutter_tools/src/asset.dart';
|
||||||
|
import 'package:flutter_tools/src/base/config.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/io.dart';
|
import 'package:flutter_tools/src/base/io.dart';
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
|
@ -587,15 +588,8 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Shader compilation', () {
|
group('Shader compilation', () {
|
||||||
late FileSystem fileSystem;
|
testWithoutContext('DevFS recompiles shaders', () async {
|
||||||
late ProcessManager processManager;
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
fileSystem = MemoryFileSystem.test();
|
|
||||||
processManager = FakeProcessManager.any();
|
|
||||||
});
|
|
||||||
|
|
||||||
testUsingContext('DevFS recompiles shaders', () async {
|
|
||||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
||||||
requests: <VmServiceExpectation>[createDevFSRequest],
|
requests: <VmServiceExpectation>[createDevFSRequest],
|
||||||
httpAddress: Uri.parse('http://localhost'),
|
httpAddress: Uri.parse('http://localhost'),
|
||||||
|
@ -609,6 +603,7 @@ void main() {
|
||||||
logger: logger,
|
logger: logger,
|
||||||
osUtils: FakeOperatingSystemUtils(),
|
osUtils: FakeOperatingSystemUtils(),
|
||||||
httpClient: FakeHttpClient.any(),
|
httpClient: FakeHttpClient.any(),
|
||||||
|
config: Config.test(),
|
||||||
);
|
);
|
||||||
|
|
||||||
await devFS.create();
|
await devFS.create();
|
||||||
|
@ -647,12 +642,10 @@ void main() {
|
||||||
expect(report.success, true);
|
expect(report.success, true);
|
||||||
expect(devFS.shaderPathsToEvict, <String>{'foo.frag'});
|
expect(devFS.shaderPathsToEvict, <String>{'foo.frag'});
|
||||||
expect(devFS.assetPathsToEvict, <String>{'not.frag'});
|
expect(devFS.assetPathsToEvict, <String>{'not.frag'});
|
||||||
}, overrides: <Type, Generator>{
|
|
||||||
FileSystem: () => fileSystem,
|
|
||||||
ProcessManager: () => processManager,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testUsingContext('DevFS tracks when FontManifest is updated', () async {
|
testWithoutContext('DevFS tracks when FontManifest is updated', () async {
|
||||||
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
||||||
requests: <VmServiceExpectation>[createDevFSRequest],
|
requests: <VmServiceExpectation>[createDevFSRequest],
|
||||||
httpAddress: Uri.parse('http://localhost'),
|
httpAddress: Uri.parse('http://localhost'),
|
||||||
|
@ -666,6 +659,7 @@ void main() {
|
||||||
logger: logger,
|
logger: logger,
|
||||||
osUtils: FakeOperatingSystemUtils(),
|
osUtils: FakeOperatingSystemUtils(),
|
||||||
httpClient: FakeHttpClient.any(),
|
httpClient: FakeHttpClient.any(),
|
||||||
|
config: Config.test(),
|
||||||
);
|
);
|
||||||
|
|
||||||
await devFS.create();
|
await devFS.create();
|
||||||
|
@ -702,9 +696,6 @@ void main() {
|
||||||
expect(devFS.shaderPathsToEvict, <String>{});
|
expect(devFS.shaderPathsToEvict, <String>{});
|
||||||
expect(devFS.assetPathsToEvict, <String>{'FontManifest.json'});
|
expect(devFS.assetPathsToEvict, <String>{'FontManifest.json'});
|
||||||
expect(devFS.didUpdateFontManifest, true);
|
expect(devFS.didUpdateFontManifest, true);
|
||||||
}, overrides: <Type, Generator>{
|
|
||||||
FileSystem: () => fileSystem,
|
|
||||||
ProcessManager: () => processManager,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue