[flutter_tools] use initially parsed package config for language version, sound mode determination (#70323)

This commit is contained in:
Jonah Williams
2020-11-13 09:41:11 -08:00
committed by GitHub
parent ed977dd6a4
commit 0a73ecf6df
14 changed files with 85 additions and 96 deletions

View File

@@ -143,7 +143,8 @@ void main() {
packageConfig: packageConfig,
);
expect(invalidationResult.packageConfig, isNot(packageConfig));
// Initial package config is re-used.
expect(invalidationResult.packageConfig, packageConfig);
fileSystem.file('.packages')
.writeAsStringSync('foo:lib/\n');

View File

@@ -2501,7 +2501,7 @@ void main() {
)).generator as DefaultResidentCompiler;
expect(residentCompiler.initializeFromDill,
globals.fs.path.join(getBuildDirectory(), 'cache.dill'));
globals.fs.path.join(getBuildDirectory(), 'fbbe6a61fb7a1de317d381f8df4814e5.cache.dill'));
expect(residentCompiler.librariesSpec,
globals.fs.file(globals.artifacts.getArtifactPath(Artifact.flutterWebLibrariesJson))
.uri.toString());

View File

@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/test/test_compiler.dart';
import 'package:mockito/mockito.dart';
import 'package:package_config/package_config_types.dart';
import '../src/common.dart';
import '../src/context.dart';
@@ -22,6 +23,15 @@ final Platform linuxPlatform = FakePlatform(
environment: <String, String>{},
);
final BuildInfo debugBuild = BuildInfo(
BuildMode.debug,
'',
treeShakeIcons: false,
packageConfig: PackageConfig(<Package>[
Package('test_api', Uri.parse('file:///test_api/')),
])
);
void main() {
MockResidentCompiler residentCompiler;
FileSystem fileSystem;
@@ -29,17 +39,13 @@ void main() {
setUp(() {
fileSystem = MemoryFileSystem.test();
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('.packages').writeAsStringSync('flutter_test:flutter_test/');
fileSystem.file('test/foo.dart').createSync(recursive: true);
fileSystem.file('.packages')
..createSync()
..writeAsStringSync('test_api:test_api/\n');
residentCompiler = MockResidentCompiler();
});
testUsingContext('TestCompiler reports a dill file when compile is successful', () async {
final FakeTestCompiler testCompiler = FakeTestCompiler(
BuildInfo.debug,
debugBuild,
FlutterProject.current(),
residentCompiler,
);
@@ -64,7 +70,7 @@ void main() {
testUsingContext('TestCompiler reports null when a compile fails', () async {
final FakeTestCompiler testCompiler = FakeTestCompiler(
BuildInfo.debug,
debugBuild,
FlutterProject.current(),
residentCompiler,
);
@@ -90,7 +96,7 @@ void main() {
testUsingContext('TestCompiler disposing test compiler shuts down backing compiler', () async {
final FakeTestCompiler testCompiler = FakeTestCompiler(
BuildInfo.debug,
debugBuild,
FlutterProject.current(),
residentCompiler,
);
@@ -115,7 +121,6 @@ void main() {
FlutterProject.current(),
residentCompiler,
);
fileSystem.file('.packages').writeAsStringSync('\n');
expect(await testCompiler.compile(Uri.parse('test/foo.dart')), null);
expect(testLogger.errorText, contains('Error: cannot run without a dependency on '

View File

@@ -591,14 +591,12 @@ void main() {
}));
test('Can start web server with specified assets', () => testbed.run(() async {
globals.fs.file('.packages').writeAsStringSync('\n');
final File outputFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
..createSync(recursive: true);
outputFile.parent.childFile('a.sources').writeAsStringSync('');
outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('a.metadata').writeAsStringSync('{}');
outputFile.parent.childFile('.packages').writeAsStringSync('\n');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
@@ -708,14 +706,12 @@ void main() {
}));
test('Can start web server with specified assets in sound null safety mode', () => testbed.run(() async {
globals.fs.file('.packages').writeAsStringSync('\n');
final File outputFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
..createSync(recursive: true);
outputFile.parent.childFile('a.sources').writeAsStringSync('');
outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('a.metadata').writeAsStringSync('{}');
outputFile.parent.childFile('.packages').writeAsStringSync('\n');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
@@ -739,14 +735,14 @@ void main() {
BuildMode.debug,
'',
treeShakeIcons: false,
nullSafetyMode: NullSafetyMode.autodetect,
nullSafetyMode: NullSafetyMode.sound,
),
enableDwds: false,
entrypoint: Uri.base,
testMode: true,
expressionCompiler: null,
chromiumLauncher: null,
nullSafetyMode: NullSafetyMode.autodetect,
nullSafetyMode: NullSafetyMode.sound,
);
webDevFS.requireJS.createSync(recursive: true);
webDevFS.stackTraceMapper.createSync(recursive: true);
@@ -759,13 +755,13 @@ void main() {
..createSync(recursive: true)
..writeAsStringSync('GENERATED');
final String webPrecompiledSdk = globals.artifacts
.getArtifactPath(Artifact.webPrecompiledSdk);
.getArtifactPath(Artifact.webPrecompiledSoundSdk);
final String webPrecompiledSdkSourcemaps = globals.artifacts
.getArtifactPath(Artifact.webPrecompiledSdkSourcemaps);
.getArtifactPath(Artifact.webPrecompiledSoundSdkSourcemaps);
final String webPrecompiledCanvaskitSdk = globals.artifacts
.getArtifactPath(Artifact.webPrecompiledCanvaskitSdk);
.getArtifactPath(Artifact.webPrecompiledCanvaskitSoundSdk);
final String webPrecompiledCanvaskitSdkSourcemaps = globals.artifacts
.getArtifactPath(Artifact.webPrecompiledCanvaskitSdkSourcemaps);
.getArtifactPath(Artifact.webPrecompiledCanvaskitSoundSdkSourcemaps);
globals.fs.file(webPrecompiledSdk)
..createSync(recursive: true)
..writeAsStringSync('HELLO');
@@ -823,13 +819,11 @@ void main() {
}));
test('Can start web server with hostname any', () => testbed.run(() async {
globals.fs.file('.packages').writeAsStringSync('\n');
final File outputFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
..createSync(recursive: true);
outputFile.parent.childFile('a.sources').writeAsStringSync('');
outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('.packages').writeAsStringSync('\n');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
@@ -867,13 +861,11 @@ void main() {
}));
test('Can start web server with canvaskit enabled', () => testbed.run(() async {
globals.fs.file('.packages').writeAsStringSync('\n');
final File outputFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
..createSync(recursive: true);
outputFile.parent.childFile('a.sources').writeAsStringSync('');
outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('.packages').writeAsStringSync('\n');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(
@@ -919,13 +911,11 @@ void main() {
}));
test('Can start web server with auto detect enabled', () => testbed.run(() async {
globals.fs.file('.packages').writeAsStringSync('\n');
final File outputFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
..createSync(recursive: true);
outputFile.parent.childFile('a.sources').writeAsStringSync('');
outputFile.parent.childFile('a.json').writeAsStringSync('{}');
outputFile.parent.childFile('a.map').writeAsStringSync('{}');
outputFile.parent.childFile('.packages').writeAsStringSync('\n');
final ResidentCompiler residentCompiler = MockResidentCompiler();
when(residentCompiler.recompile(