forked from firka/flutter
[flutter_tools] introduce a BuildSystem interface (#56946)
This commit is contained in:
@@ -486,8 +486,30 @@ class BuildResult {
|
||||
}
|
||||
|
||||
/// The build system is responsible for invoking and ordering [Target]s.
|
||||
class BuildSystem {
|
||||
const BuildSystem({
|
||||
abstract class BuildSystem {
|
||||
/// Const constructor to allow subclasses to be const.
|
||||
const BuildSystem();
|
||||
|
||||
/// Build [target] and all of its dependencies.
|
||||
Future<BuildResult> build(
|
||||
Target target,
|
||||
Environment environment, {
|
||||
BuildSystemConfig buildSystemConfig = const BuildSystemConfig(),
|
||||
});
|
||||
|
||||
/// Perform an incremental build of [target] and all of its dependencies.
|
||||
///
|
||||
/// If [previousBuild] is not provided, a new incremental build is
|
||||
/// initialized.
|
||||
Future<BuildResult> buildIncremental(
|
||||
Target target,
|
||||
Environment environment,
|
||||
BuildResult previousBuild,
|
||||
);
|
||||
}
|
||||
|
||||
class FlutterBuildSystem extends BuildSystem {
|
||||
const FlutterBuildSystem({
|
||||
@required FileSystem fileSystem,
|
||||
@required Platform platform,
|
||||
@required Logger logger,
|
||||
@@ -499,7 +521,7 @@ class BuildSystem {
|
||||
final Platform _platform;
|
||||
final Logger _logger;
|
||||
|
||||
/// Build `target` and all of its dependencies.
|
||||
@override
|
||||
Future<BuildResult> build(
|
||||
Target target,
|
||||
Environment environment, {
|
||||
@@ -572,10 +594,7 @@ class BuildSystem {
|
||||
|
||||
static final Expando<FileStore> _incrementalFileStore = Expando<FileStore>();
|
||||
|
||||
/// Perform an incremental build of `target` and all of its dependencies.
|
||||
///
|
||||
/// If [previousBuild] is not provided, a new incremental build is
|
||||
/// initialized.
|
||||
@override
|
||||
Future<BuildResult> buildIncremental(
|
||||
Target target,
|
||||
Environment environment,
|
||||
@@ -631,7 +650,7 @@ class BuildSystem {
|
||||
/// cleanup is only necessary when multiple different build configurations
|
||||
/// output to the same directory.
|
||||
@visibleForTesting
|
||||
static void trackSharedBuildDirectory(
|
||||
void trackSharedBuildDirectory(
|
||||
Environment environment,
|
||||
FileSystem fileSystem,
|
||||
Map<String, File> currentOutputs,
|
||||
|
||||
@@ -88,7 +88,7 @@ Future<T> runInContext<T>(
|
||||
platform: globals.platform,
|
||||
),
|
||||
AssetBundleFactory: () => AssetBundleFactory.defaultInstance,
|
||||
BuildSystem: () => BuildSystem(
|
||||
BuildSystem: () => FlutterBuildSystem(
|
||||
fileSystem: globals.fs,
|
||||
logger: globals.logger,
|
||||
platform: globals.platform,
|
||||
|
||||
@@ -464,7 +464,11 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('trackSharedBuildDirectory handles a missing .last_build_id', () {
|
||||
BuildSystem.trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
|
||||
FlutterBuildSystem(
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(),
|
||||
).trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
|
||||
|
||||
expect(environment.outputDir.childFile('.last_build_id'), exists);
|
||||
expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
|
||||
@@ -475,7 +479,11 @@ void main() {
|
||||
environment.outputDir.childFile('.last_build_id')
|
||||
..writeAsStringSync('6666cd76f96956469e7be39d750cc7d9')
|
||||
..setLastModifiedSync(DateTime(1991, 8, 23));
|
||||
BuildSystem.trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
|
||||
FlutterBuildSystem(
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(),
|
||||
).trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
|
||||
|
||||
expect(environment.outputDir.childFile('.last_build_id').lastModifiedSync(),
|
||||
DateTime(1991, 8, 23));
|
||||
@@ -491,7 +499,11 @@ void main() {
|
||||
environment.outputDir
|
||||
.childFile('stale')
|
||||
.createSync();
|
||||
BuildSystem.trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
|
||||
FlutterBuildSystem(
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(),
|
||||
).trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
|
||||
|
||||
expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
|
||||
'6666cd76f96956469e7be39d750cc7d9');
|
||||
@@ -510,7 +522,11 @@ void main() {
|
||||
..createSync();
|
||||
otherBuildDir.childFile('outputs.json')
|
||||
.writeAsStringSync(json.encode(<String>[staleFile.absolute.path]));
|
||||
BuildSystem.trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
|
||||
FlutterBuildSystem(
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(),
|
||||
).trackSharedBuildDirectory(environment, fileSystem, <String, File>{});
|
||||
|
||||
expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
|
||||
'6666cd76f96956469e7be39d750cc7d9');
|
||||
@@ -568,7 +584,7 @@ void main() {
|
||||
}
|
||||
|
||||
BuildSystem setUpBuildSystem(FileSystem fileSystem) {
|
||||
return BuildSystem(
|
||||
return FlutterBuildSystem(
|
||||
fileSystem: fileSystem,
|
||||
logger: BufferLogger.test(),
|
||||
platform: FakePlatform(operatingSystem: 'linux'),
|
||||
|
||||
Reference in New Issue
Block a user