Unverified Commit 9e952497 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] introduce a BuildSystem interface (#56946)

parent 073126fd
...@@ -486,8 +486,30 @@ class BuildResult { ...@@ -486,8 +486,30 @@ class BuildResult {
} }
/// The build system is responsible for invoking and ordering [Target]s. /// The build system is responsible for invoking and ordering [Target]s.
class BuildSystem { abstract class BuildSystem {
const 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 FileSystem fileSystem,
@required Platform platform, @required Platform platform,
@required Logger logger, @required Logger logger,
...@@ -499,7 +521,7 @@ class BuildSystem { ...@@ -499,7 +521,7 @@ class BuildSystem {
final Platform _platform; final Platform _platform;
final Logger _logger; final Logger _logger;
/// Build `target` and all of its dependencies. @override
Future<BuildResult> build( Future<BuildResult> build(
Target target, Target target,
Environment environment, { Environment environment, {
...@@ -572,10 +594,7 @@ class BuildSystem { ...@@ -572,10 +594,7 @@ class BuildSystem {
static final Expando<FileStore> _incrementalFileStore = Expando<FileStore>(); static final Expando<FileStore> _incrementalFileStore = Expando<FileStore>();
/// Perform an incremental build of `target` and all of its dependencies. @override
///
/// If [previousBuild] is not provided, a new incremental build is
/// initialized.
Future<BuildResult> buildIncremental( Future<BuildResult> buildIncremental(
Target target, Target target,
Environment environment, Environment environment,
...@@ -631,7 +650,7 @@ class BuildSystem { ...@@ -631,7 +650,7 @@ class BuildSystem {
/// cleanup is only necessary when multiple different build configurations /// cleanup is only necessary when multiple different build configurations
/// output to the same directory. /// output to the same directory.
@visibleForTesting @visibleForTesting
static void trackSharedBuildDirectory( void trackSharedBuildDirectory(
Environment environment, Environment environment,
FileSystem fileSystem, FileSystem fileSystem,
Map<String, File> currentOutputs, Map<String, File> currentOutputs,
......
...@@ -88,7 +88,7 @@ Future<T> runInContext<T>( ...@@ -88,7 +88,7 @@ Future<T> runInContext<T>(
platform: globals.platform, platform: globals.platform,
), ),
AssetBundleFactory: () => AssetBundleFactory.defaultInstance, AssetBundleFactory: () => AssetBundleFactory.defaultInstance,
BuildSystem: () => BuildSystem( BuildSystem: () => FlutterBuildSystem(
fileSystem: globals.fs, fileSystem: globals.fs,
logger: globals.logger, logger: globals.logger,
platform: globals.platform, platform: globals.platform,
......
...@@ -464,7 +464,11 @@ void main() { ...@@ -464,7 +464,11 @@ void main() {
}); });
testWithoutContext('trackSharedBuildDirectory handles a missing .last_build_id', () { 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'), exists);
expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(), expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
...@@ -475,7 +479,11 @@ void main() { ...@@ -475,7 +479,11 @@ void main() {
environment.outputDir.childFile('.last_build_id') environment.outputDir.childFile('.last_build_id')
..writeAsStringSync('6666cd76f96956469e7be39d750cc7d9') ..writeAsStringSync('6666cd76f96956469e7be39d750cc7d9')
..setLastModifiedSync(DateTime(1991, 8, 23)); ..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(), expect(environment.outputDir.childFile('.last_build_id').lastModifiedSync(),
DateTime(1991, 8, 23)); DateTime(1991, 8, 23));
...@@ -491,7 +499,11 @@ void main() { ...@@ -491,7 +499,11 @@ void main() {
environment.outputDir environment.outputDir
.childFile('stale') .childFile('stale')
.createSync(); .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(), expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
'6666cd76f96956469e7be39d750cc7d9'); '6666cd76f96956469e7be39d750cc7d9');
...@@ -510,7 +522,11 @@ void main() { ...@@ -510,7 +522,11 @@ void main() {
..createSync(); ..createSync();
otherBuildDir.childFile('outputs.json') otherBuildDir.childFile('outputs.json')
.writeAsStringSync(json.encode(<String>[staleFile.absolute.path])); .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(), expect(environment.outputDir.childFile('.last_build_id').readAsStringSync(),
'6666cd76f96956469e7be39d750cc7d9'); '6666cd76f96956469e7be39d750cc7d9');
...@@ -568,7 +584,7 @@ void main() { ...@@ -568,7 +584,7 @@ void main() {
} }
BuildSystem setUpBuildSystem(FileSystem fileSystem) { BuildSystem setUpBuildSystem(FileSystem fileSystem) {
return BuildSystem( return FlutterBuildSystem(
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'linux'), platform: FakePlatform(operatingSystem: 'linux'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment