mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

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
122 lines
4.2 KiB
Dart
122 lines
4.2 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/build_info.dart';
|
|
import 'package:flutter_tools/src/device.dart';
|
|
import 'package:flutter_tools/src/features.dart';
|
|
import 'package:flutter_tools/src/globals.dart' as globals;
|
|
import 'package:flutter_tools/src/resident_devtools_handler.dart';
|
|
import 'package:flutter_tools/src/resident_runner.dart';
|
|
import 'package:flutter_tools/src/run_hot.dart';
|
|
import 'package:unified_analytics/unified_analytics.dart';
|
|
|
|
import '../../src/common.dart';
|
|
import '../../src/context.dart';
|
|
import '../../src/fake_vm_services.dart';
|
|
import '../../src/fakes.dart';
|
|
import '../../src/testbed.dart';
|
|
import '../resident_runner_helpers.dart';
|
|
import 'fake_native_assets_build_runner.dart';
|
|
|
|
void main() {
|
|
late Testbed testbed;
|
|
late FakeFlutterDevice flutterDevice;
|
|
late FakeDevFS devFS;
|
|
late ResidentRunner residentRunner;
|
|
late FakeDevice device;
|
|
late FakeAnalytics fakeAnalytics;
|
|
FakeVmServiceHost? fakeVmServiceHost;
|
|
|
|
setUp(() {
|
|
testbed = Testbed(setup: () {
|
|
fakeAnalytics = getInitializedFakeAnalyticsInstance(
|
|
fs: globals.fs,
|
|
fakeFlutterVersion: FakeFlutterVersion(),
|
|
);
|
|
|
|
globals.fs.file('.packages')
|
|
.writeAsStringSync('\n');
|
|
globals.fs.file(globals.fs.path.join('build', 'app.dill'))
|
|
..createSync(recursive: true)
|
|
..writeAsStringSync('ABC');
|
|
residentRunner = HotRunner(
|
|
<FlutterDevice>[
|
|
flutterDevice,
|
|
],
|
|
stayResident: false,
|
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
|
target: 'main.dart',
|
|
devtoolsHandler: createNoOpHandler,
|
|
analytics: fakeAnalytics,
|
|
);
|
|
});
|
|
device = FakeDevice();
|
|
devFS = FakeDevFS();
|
|
flutterDevice = FakeFlutterDevice()
|
|
..testUri = testUri
|
|
..vmServiceHost = (() => fakeVmServiceHost)
|
|
..device = device
|
|
..fakeDevFS = devFS;
|
|
});
|
|
|
|
testUsingContext(
|
|
'use the nativeAssetsYamlFile when provided',
|
|
() => testbed.run(() async {
|
|
final FakeDevice device = FakeDevice(
|
|
targetPlatform: TargetPlatform.darwin,
|
|
sdkNameAndVersion: 'Macos',
|
|
);
|
|
final FakeResidentCompiler residentCompiler = FakeResidentCompiler();
|
|
final FakeFlutterDevice flutterDevice = FakeFlutterDevice()
|
|
..testUri = testUri
|
|
..vmServiceHost = (() => fakeVmServiceHost)
|
|
..device = device
|
|
..fakeDevFS = devFS
|
|
..targetPlatform = TargetPlatform.darwin
|
|
..generator = residentCompiler;
|
|
|
|
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
|
listViews,
|
|
listViews,
|
|
]);
|
|
globals.fs
|
|
.file(globals.fs.path.join('lib', 'main.dart'))
|
|
.createSync(recursive: true);
|
|
final FakeNativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner();
|
|
residentRunner = HotRunner(
|
|
<FlutterDevice>[
|
|
flutterDevice,
|
|
],
|
|
stayResident: false,
|
|
debuggingOptions: DebuggingOptions.enabled(const BuildInfo(
|
|
BuildMode.debug,
|
|
'',
|
|
treeShakeIcons: false,
|
|
trackWidgetCreation: true,
|
|
)),
|
|
target: 'main.dart',
|
|
devtoolsHandler: createNoOpHandler,
|
|
nativeAssetsBuilder: FakeHotRunnerNativeAssetsBuilder(buildRunner),
|
|
analytics: fakeAnalytics,
|
|
nativeAssetsYamlFile: 'foo.yaml',
|
|
);
|
|
|
|
final int? result = await residentRunner.run();
|
|
expect(result, 0);
|
|
|
|
expect(buildRunner.buildInvocations, 0);
|
|
expect(buildRunner.dryRunInvocations, 0);
|
|
expect(buildRunner.hasPackageConfigInvocations, 0);
|
|
expect(buildRunner.packagesWithNativeAssetsInvocations, 0);
|
|
|
|
expect(residentCompiler.recompileCalled, true);
|
|
expect(residentCompiler.receivedNativeAssetsYaml, globals.fs.path.toUri('foo.yaml'));
|
|
}),
|
|
overrides: <Type, Generator>{
|
|
ProcessManager: () => FakeProcessManager.any(),
|
|
FeatureFlags: () => TestFeatureFlags(isNativeAssetsEnabled: true, isMacOSEnabled: true),
|
|
});
|
|
}
|