[flutter_tools] surgically remove outputs from shared directory (#53962)

This commit is contained in:
Jonah Williams
2020-04-08 19:09:59 -07:00
committed by GitHub
parent b475eaf8ba
commit cb8bafb38d
5 changed files with 171 additions and 70 deletions

View File

@@ -434,6 +434,109 @@ void main() {
expect(fileSystem.file('c.txt'), isNot(exists));
expect(called, 2);
});
testWithoutContext('trackSharedBuildDirectory handles a missing .last_build_id', () {
BuildSystem.trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
expect(environment.outputDir.childFile('.last_build_id'), exists);
expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
'6666cd76f96956469e7be39d750cc7d9');
});
testWithoutContext('trackSharedBuildDirectory does not modify .last_build_id when config is identical', () {
environment.outputDir.childFile('.last_build_id')
..writeAsStringSync('6666cd76f96956469e7be39d750cc7d9')
..setLastModifiedSync(DateTime(1991, 8, 23));
BuildSystem.trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
expect(environment.outputDir.childFile('.last_build_id').lastModifiedSync(),
DateTime(1991, 8, 23));
});
testWithoutContext('trackSharedBuildDirectory does not delete files when outputs.json is missing', () {
environment.outputDir
.childFile('.last_build_id')
.writeAsStringSync('foo');
environment.buildDir.parent
.childDirectory('foo')
.createSync(recursive: true);
environment.outputDir
.childFile('stale')
.createSync();
BuildSystem.trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
'6666cd76f96956469e7be39d750cc7d9');
expect(environment.outputDir.childFile('stale'), exists);
});
testWithoutContext('trackSharedBuildDirectory deletes files in outputs.json but not in current outputs', () {
environment.outputDir
.childFile('.last_build_id')
.writeAsStringSync('foo');
final Directory otherBuildDir = environment.buildDir.parent
.childDirectory('foo')
..createSync(recursive: true);
final File staleFile = environment.outputDir
.childFile('stale')
..createSync();
otherBuildDir.childFile('outputs.json')
.writeAsStringSync(json.encode(<String>[staleFile.absolute.path]));
BuildSystem.trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
'6666cd76f96956469e7be39d750cc7d9');
expect(environment.outputDir.childFile('stale'), isNot(exists));
});
testWithoutContext('multiple builds to the same output directory do no leave stale artifacts', () async {
final BuildSystem buildSystem = setUpBuildSystem(fileSystem);
final Environment testEnvironmentDebug = Environment.test(
fileSystem.currentDirectory,
outputDir: fileSystem.directory('output'),
defines: <String, String>{
'config': 'debug',
},
artifacts: MockArtifacts(),
processManager: FakeProcessManager.any(),
logger: BufferLogger.test(),
fileSystem: fileSystem,
);
final Environment testEnvironmentProfle = Environment.test(
fileSystem.currentDirectory,
outputDir: fileSystem.directory('output'),
defines: <String, String>{
'config': 'profile',
},
artifacts: MockArtifacts(),
processManager: FakeProcessManager.any(),
logger: BufferLogger.test(),
fileSystem: fileSystem,
);
final TestTarget debugTarget = TestTarget((Environment environment) async {
environment.outputDir.childFile('debug').createSync();
})..outputs = const <Source>[Source.pattern('{OUTPUT_DIR}/debug')];
final TestTarget releaseTarget = TestTarget((Environment environment) async {
environment.outputDir.childFile('release').createSync();
})..outputs = const <Source>[Source.pattern('{OUTPUT_DIR}/release')];
await buildSystem.build(debugTarget, testEnvironmentDebug);
// Verify debug output was created
expect(fileSystem.file('output/debug'), exists);
await buildSystem.build(releaseTarget, testEnvironmentProfle);
// Last build config is updated properly
expect(testEnvironmentProfle.outputDir.childFile('.last_build_id'), exists);
expect(testEnvironmentProfle.outputDir.childFile('.last_build_id').readAsStringSync(),
'c20b3747fb2aa148cc4fd39bfbbd894f');
// Verify debug output removeds
expect(fileSystem.file('output/debug'), isNot(exists));
expect(fileSystem.file('output/release'), exists);
});
}
BuildSystem setUpBuildSystem(FileSystem fileSystem) {

View File

@@ -101,10 +101,6 @@ void main() {
final Directory source = globals.fs.directory(sourcePath);
final Directory target = globals.fs.directory(targetPath);
// verify directory was deleted by command.
expect(target.existsSync(), false);
target.createSync(recursive: true);
for (final FileSystemEntity entity in source.listSync(recursive: true)) {
if (entity is File) {
final String relative = globals.fs.path.relative(entity.path, from: source.path);
@@ -178,54 +174,6 @@ void main() {
expect(globals.fs.file(precompiledIsolate), isNot(exists));
}));
test('release/profile macOS application has no blob or precompiled runtime when '
'run ontop of different configuration', () => testbed.run(() async {
globals.fs.file(globals.fs.path.join('bin', 'cache', 'artifacts', 'engine', 'darwin-x64',
'vm_isolate_snapshot.bin')).createSync(recursive: true);
globals.fs.file(globals.fs.path.join('bin', 'cache', 'artifacts', 'engine', 'darwin-x64',
'isolate_snapshot.bin')).createSync(recursive: true);
globals.fs.file(globals.fs.path.join(environment.buildDir.path, 'App.framework', 'App'))
.createSync(recursive: true);
final String inputKernel = globals.fs.path.join(environment.buildDir.path, 'app.dill');
final String outputKernel = globals.fs.path.join('App.framework', 'Versions', 'A', 'Resources',
'flutter_assets', 'kernel_blob.bin');
globals.fs.file(inputKernel)
..createSync(recursive: true)
..writeAsStringSync('testing');
await const DebugMacOSBundleFlutterAssets().build(environment);
globals.fs.file(globals.fs.path.join('bin', 'cache', 'artifacts', 'engine', 'darwin-x64',
'vm_isolate_snapshot.bin')).createSync(recursive: true);
globals.fs.file(globals.fs.path.join('bin', 'cache', 'artifacts', 'engine', 'darwin-x64',
'isolate_snapshot.bin')).createSync(recursive: true);
final Environment testEnvironment = Environment.test(
globals.fs.currentDirectory,
defines: <String, String>{
kBuildMode: 'profile',
kTargetPlatform: 'darwin-x64',
},
artifacts: MockArtifacts(),
processManager: FakeProcessManager.any(),
logger: globals.logger,
fileSystem: globals.fs,
);
testEnvironment.buildDir.createSync(recursive: true);
globals.fs.file(globals.fs.path.join(testEnvironment.buildDir.path, 'App.framework', 'App'))
.createSync(recursive: true);
final String precompiledVm = globals.fs.path.join('App.framework', 'Resources',
'flutter_assets', 'vm_snapshot_data');
final String precompiledIsolate = globals.fs.path.join('App.framework', 'Resources',
'flutter_assets', 'isolate_snapshot_data');
await const ProfileMacOSBundleFlutterAssets().build(testEnvironment);
expect(globals.fs.file(outputKernel), isNot(exists));
expect(globals.fs.file(precompiledVm), isNot(exists));
expect(globals.fs.file(precompiledIsolate), isNot(exists));
}));
test('release/profile macOS application updates when App.framework updates', () => testbed.run(() async {
globals.fs.file(globals.fs.path.join('bin', 'cache', 'artifacts', 'engine', 'darwin-x64',
'vm_isolate_snapshot.bin')).createSync(recursive: true);