Revert "[flutter_tools] surgically remove outputs from shared directory (#53773)" (#53956)

This reverts commit 8a3bede1d3.
This commit is contained in:
Jonah Williams
2020-04-03 14:22:37 -07:00
committed by GitHub
parent d5795b6ffa
commit 58acf4e7b0
5 changed files with 73 additions and 170 deletions

View File

@@ -394,11 +394,8 @@ class Environment {
/// The `BUILD_DIR` environment variable.
///
/// The root of the output directory where build step intermediates and
/// outputs are written. Current usages of assemble configure ths to be
/// a unique directory under `.dart_tool/flutter_build`, though it can
/// be placed anywhere. The uniqueness is only enforced by callers, and
/// is currently done by hashing the build configuration.
/// Defaults to `{PROJECT_ROOT}/build`. The root of the output directory where
/// build step intermediates and outputs are written.
final Directory buildDir;
/// The `CACHE_DIR` environment variable.
@@ -522,12 +519,6 @@ class BuildSystem {
path.contains('.dart_tool');
});
}
trackSharedBuildDirectory(
environment, _fileSystem, buildInstance.outputFiles,
);
environment.buildDir.childFile('outputs.json')
.writeAsStringSync(json.encode(buildInstance.outputFiles.keys.toList()));
return BuildResult(
success: passed,
exceptions: buildInstance.exceptionMeasurements,
@@ -538,61 +529,6 @@ class BuildSystem {
..sort((File a, File b) => a.path.compareTo(b.path)),
);
}
/// Write the identifier of the last build into the output directory and
/// remove the previous build's output.
///
/// The build identifier is the basename of the build directory where
/// outputs and intermediaries are written, under `.dart_tool/flutter_build`.
/// This is computed from a hash of the build's configuration.
///
/// This identifier is used to perform a targeted cleanup of the last output
/// files, if these were not already covered by the built-in cleanup. This
/// cleanup is only necessary when multiple different build configurations
/// output to the same directory.
@visibleForTesting
static void trackSharedBuildDirectory(
Environment environment,
FileSystem fileSystem,
Map<String, File> currentOutputs,
) {
final String currentBuildId = fileSystem.path.basename(environment.buildDir.path);
final File lastBuildIdFile = environment.outputDir.childFile('.last_build_id');
if (!lastBuildIdFile.existsSync()) {
lastBuildIdFile.writeAsStringSync(currentBuildId);
// No config file, either output was cleaned or this is the first build.
return;
}
final String lastBuildId = lastBuildIdFile.readAsStringSync().trim();
if (lastBuildId == currentBuildId) {
// The last build was the same configuration as the current build
return;
}
// Update the output dir with the latest config.
lastBuildIdFile
..createSync()
..writeAsStringSync(currentBuildId);
final File outputsFile = environment.buildDir
.parent
.childDirectory(lastBuildId)
.childFile('outputs.json');
if (!outputsFile.existsSync()) {
// There is no output list. This could happen if the user manually
// edited .last_config or deleted .dart_tool.
return;
}
final List<String> lastOutputs = (json.decode(outputsFile.readAsStringSync()) as List<Object>)
.cast<String>();
for (final String lastOutput in lastOutputs) {
if (!currentOutputs.containsKey(lastOutput)) {
final File lastOutputFile = fileSystem.file(lastOutput);
if (lastOutputFile.existsSync()) {
lastOutputFile.deleteSync();
}
}
}
}
}

View File

@@ -276,6 +276,13 @@ abstract class IosAssetBundle extends Target {
final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
final Directory assetDirectory = frameworkDirectory.childDirectory('flutter_assets');
frameworkDirectory.createSync(recursive: true);
// This is necessary because multiple different build configurations will
// output different files here. Build cleaning only works when the files
// change within a build configuration.
if (assetDirectory.existsSync()) {
assetDirectory.deleteSync(recursive: true);
}
assetDirectory.createSync();
// Only copy the prebuilt runtimes and kernel blob in debug mode.

View File

@@ -56,7 +56,12 @@ abstract class UnpackMacOS extends Target {
final Directory targetDirectory = environment
.outputDir
.childDirectory('FlutterMacOS.framework');
targetDirectory.createSync(recursive: true);
// This is necessary because multiple different build configurations will
// output different files here. Build cleaning only works when the files
// change within a build configuration.
if (targetDirectory.existsSync()) {
targetDirectory.deleteSync(recursive: true);
}
final List<File> inputs = globals.fs.directory(basePath)
.listSync(recursive: true)
.whereType<File>()
@@ -286,6 +291,12 @@ abstract class MacOSBundleFlutterAssets extends Target {
final Directory assetDirectory = outputDirectory
.childDirectory('Resources')
.childDirectory('flutter_assets');
// This is necessary because multiple different build configurations will
// output different files here. Build cleaning only works when the files
// change within a build configuration.
if (assetDirectory.existsSync()) {
assetDirectory.deleteSync(recursive: true);
}
assetDirectory.createSync(recursive: true);
final Depfile depfile = await copyAssets(environment, assetDirectory);
final DepfileService depfileService = DepfileService(