mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
[flutter_tools] Refactor Environment and FileStore to be context-free (#48759)
This commit is contained in:
parent
c3124ff2e3
commit
79c286705c
|
@ -210,8 +210,8 @@ class AotBuilder {
|
||||||
? const ProfileCopyFlutterAotBundle()
|
? const ProfileCopyFlutterAotBundle()
|
||||||
: const ReleaseCopyFlutterAotBundle();
|
: const ReleaseCopyFlutterAotBundle();
|
||||||
|
|
||||||
final BuildResult result = await buildSystem.build(target, Environment(
|
final BuildResult result = await buildSystem.build(target, Environment.test(
|
||||||
projectDir: flutterProject.directory,
|
flutterProject.directory,
|
||||||
outputDir: globals.fs.directory(outputDir),
|
outputDir: globals.fs.directory(outputDir),
|
||||||
buildDir: flutterProject.directory
|
buildDir: flutterProject.directory
|
||||||
.childDirectory('.dart_tool')
|
.childDirectory('.dart_tool')
|
||||||
|
|
|
@ -277,12 +277,11 @@ abstract class Target {
|
||||||
/// }
|
/// }
|
||||||
class Environment {
|
class Environment {
|
||||||
/// Create a new [Environment] object.
|
/// Create a new [Environment] object.
|
||||||
///
|
|
||||||
/// Only [projectDir] is required. The remaining environment locations have
|
|
||||||
/// defaults based on it.
|
|
||||||
factory Environment({
|
factory Environment({
|
||||||
@required Directory projectDir,
|
@required Directory projectDir,
|
||||||
@required Directory outputDir,
|
@required Directory outputDir,
|
||||||
|
@required Directory cacheDir,
|
||||||
|
@required Directory flutterRootDir,
|
||||||
Directory buildDir,
|
Directory buildDir,
|
||||||
Map<String, String> defines = const <String, String>{},
|
Map<String, String> defines = const <String, String>{},
|
||||||
}) {
|
}) {
|
||||||
|
@ -308,9 +307,30 @@ class Environment {
|
||||||
projectDir: projectDir,
|
projectDir: projectDir,
|
||||||
buildDir: buildDirectory,
|
buildDir: buildDirectory,
|
||||||
rootBuildDir: rootBuildDir,
|
rootBuildDir: rootBuildDir,
|
||||||
cacheDir: globals.cache.getRoot(),
|
cacheDir: cacheDir,
|
||||||
|
defines: defines,
|
||||||
|
flutterRootDir: flutterRootDir,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new [Environment] object for unit testing.
|
||||||
|
///
|
||||||
|
/// Any directories not provided will fallback to a [testDirectory]
|
||||||
|
factory Environment.test(Directory testDirectory, {
|
||||||
|
Directory projectDir,
|
||||||
|
Directory outputDir,
|
||||||
|
Directory cacheDir,
|
||||||
|
Directory flutterRootDir,
|
||||||
|
Directory buildDir,
|
||||||
|
Map<String, String> defines = const <String, String>{},
|
||||||
|
}) {
|
||||||
|
return Environment(
|
||||||
|
projectDir: projectDir ?? testDirectory,
|
||||||
|
outputDir: outputDir ?? testDirectory,
|
||||||
|
cacheDir: cacheDir ?? testDirectory,
|
||||||
|
flutterRootDir: flutterRootDir ?? testDirectory,
|
||||||
|
buildDir: buildDir,
|
||||||
defines: defines,
|
defines: defines,
|
||||||
flutterRootDir: globals.fs.directory(Cache.flutterRoot),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,8 +430,11 @@ class BuildSystem {
|
||||||
environment.outputDir.createSync(recursive: true);
|
environment.outputDir.createSync(recursive: true);
|
||||||
|
|
||||||
// Load file hash store from previous builds.
|
// Load file hash store from previous builds.
|
||||||
final FileHashStore fileCache = FileHashStore(environment, globals.fs)
|
final FileHashStore fileCache = FileHashStore(
|
||||||
..initialize();
|
environment: environment,
|
||||||
|
fileSystem: globals.fs,
|
||||||
|
logger: globals.logger,
|
||||||
|
)..initialize();
|
||||||
|
|
||||||
// Perform sanity checks on build.
|
// Perform sanity checks on build.
|
||||||
checkCycles(target);
|
checkCycles(target);
|
||||||
|
|
|
@ -7,12 +7,13 @@ import 'dart:collection';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
import 'package:pool/pool.dart';
|
import 'package:pool/pool.dart';
|
||||||
|
|
||||||
import '../base/file_system.dart';
|
import '../base/file_system.dart';
|
||||||
|
import '../base/logger.dart';
|
||||||
import '../base/utils.dart';
|
import '../base/utils.dart';
|
||||||
import '../convert.dart';
|
import '../convert.dart';
|
||||||
import '../globals.dart' as globals;
|
|
||||||
import 'build_system.dart';
|
import 'build_system.dart';
|
||||||
|
|
||||||
/// An encoded representation of all file hashes.
|
/// An encoded representation of all file hashes.
|
||||||
|
@ -71,12 +72,18 @@ class FileHash {
|
||||||
///
|
///
|
||||||
/// The format of the file store is subject to change and not part of its API.
|
/// The format of the file store is subject to change and not part of its API.
|
||||||
class FileHashStore {
|
class FileHashStore {
|
||||||
FileHashStore(this.environment, this.fileSystem) :
|
FileHashStore({
|
||||||
_cachePath = environment.buildDir.childFile(_kFileCache).path;
|
@required Environment environment,
|
||||||
|
@required FileSystem fileSystem,
|
||||||
|
@required Logger logger,
|
||||||
|
}) : _cachePath = environment.buildDir.childFile(_kFileCache).path,
|
||||||
|
_logger = logger,
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
|
||||||
final FileSystem fileSystem;
|
final FileSystem _fileSystem;
|
||||||
final String _cachePath;
|
final String _cachePath;
|
||||||
final Environment environment;
|
final Logger _logger;
|
||||||
|
|
||||||
final HashMap<String, String> previousHashes = HashMap<String, String>();
|
final HashMap<String, String> previousHashes = HashMap<String, String>();
|
||||||
final HashMap<String, String> currentHashes = HashMap<String, String>();
|
final HashMap<String, String> currentHashes = HashMap<String, String>();
|
||||||
|
|
||||||
|
@ -88,8 +95,8 @@ class FileHashStore {
|
||||||
|
|
||||||
/// Read file hashes from disk.
|
/// Read file hashes from disk.
|
||||||
void initialize() {
|
void initialize() {
|
||||||
globals.printTrace('Initializing file store');
|
_logger.printTrace('Initializing file store');
|
||||||
final File cacheFile = fileSystem.file(_cachePath);
|
final File cacheFile = _fileSystem.file(_cachePath);
|
||||||
if (!cacheFile.existsSync()) {
|
if (!cacheFile.existsSync()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +104,7 @@ class FileHashStore {
|
||||||
try {
|
try {
|
||||||
data = cacheFile.readAsBytesSync();
|
data = cacheFile.readAsBytesSync();
|
||||||
} on FileSystemException catch (err) {
|
} on FileSystemException catch (err) {
|
||||||
globals.printError(
|
_logger.printError(
|
||||||
'Failed to read file store at ${cacheFile.path} due to $err.\n'
|
'Failed to read file store at ${cacheFile.path} due to $err.\n'
|
||||||
'Build artifacts will not be cached. Try clearing the cache directories '
|
'Build artifacts will not be cached. Try clearing the cache directories '
|
||||||
'with "flutter clean"',
|
'with "flutter clean"',
|
||||||
|
@ -109,25 +116,25 @@ class FileHashStore {
|
||||||
try {
|
try {
|
||||||
fileStorage = FileStorage.fromBuffer(data);
|
fileStorage = FileStorage.fromBuffer(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
globals.printTrace('Filestorage format changed');
|
_logger.printTrace('Filestorage format changed');
|
||||||
cacheFile.deleteSync();
|
cacheFile.deleteSync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fileStorage.version != _kVersion) {
|
if (fileStorage.version != _kVersion) {
|
||||||
globals.printTrace('file cache format updating, clearing old hashes.');
|
_logger.printTrace('file cache format updating, clearing old hashes.');
|
||||||
cacheFile.deleteSync();
|
cacheFile.deleteSync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (final FileHash fileHash in fileStorage.files) {
|
for (final FileHash fileHash in fileStorage.files) {
|
||||||
previousHashes[fileHash.path] = fileHash.hash;
|
previousHashes[fileHash.path] = fileHash.hash;
|
||||||
}
|
}
|
||||||
globals.printTrace('Done initializing file store');
|
_logger.printTrace('Done initializing file store');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Persist file hashes to disk.
|
/// Persist file hashes to disk.
|
||||||
void persist() {
|
void persist() {
|
||||||
globals.printTrace('Persisting file store');
|
_logger.printTrace('Persisting file store');
|
||||||
final File cacheFile = fileSystem.file(_cachePath);
|
final File cacheFile = _fileSystem.file(_cachePath);
|
||||||
if (!cacheFile.existsSync()) {
|
if (!cacheFile.existsSync()) {
|
||||||
cacheFile.createSync(recursive: true);
|
cacheFile.createSync(recursive: true);
|
||||||
}
|
}
|
||||||
|
@ -143,13 +150,13 @@ class FileHashStore {
|
||||||
try {
|
try {
|
||||||
cacheFile.writeAsBytesSync(buffer);
|
cacheFile.writeAsBytesSync(buffer);
|
||||||
} on FileSystemException catch (err) {
|
} on FileSystemException catch (err) {
|
||||||
globals.printError(
|
_logger.printError(
|
||||||
'Failed to persist file store at ${cacheFile.path} due to $err.\n'
|
'Failed to persist file store at ${cacheFile.path} due to $err.\n'
|
||||||
'Build artifacts will not be cached. Try clearing the cache directories '
|
'Build artifacts will not be cached. Try clearing the cache directories '
|
||||||
'with "flutter clean"',
|
'with "flutter clean"',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
globals.printTrace('Done persisting file store');
|
_logger.printTrace('Done persisting file store');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes a hash of the provided files and returns a list of entities
|
/// Computes a hash of the provided files and returns a list of entities
|
||||||
|
|
|
@ -15,6 +15,7 @@ import 'build_info.dart';
|
||||||
import 'build_system/build_system.dart';
|
import 'build_system/build_system.dart';
|
||||||
import 'build_system/depfile.dart';
|
import 'build_system/depfile.dart';
|
||||||
import 'build_system/targets/dart.dart';
|
import 'build_system/targets/dart.dart';
|
||||||
|
import 'cache.dart';
|
||||||
import 'dart/package_map.dart';
|
import 'dart/package_map.dart';
|
||||||
import 'devfs.dart';
|
import 'devfs.dart';
|
||||||
import 'globals.dart' as globals;
|
import 'globals.dart' as globals;
|
||||||
|
@ -113,6 +114,8 @@ Future<void> buildWithAssemble({
|
||||||
projectDir: flutterProject.directory,
|
projectDir: flutterProject.directory,
|
||||||
outputDir: globals.fs.directory(outputDir),
|
outputDir: globals.fs.directory(outputDir),
|
||||||
buildDir: flutterProject.dartTool.childDirectory('flutter_build'),
|
buildDir: flutterProject.dartTool.childDirectory('flutter_build'),
|
||||||
|
cacheDir: globals.cache.getRoot(),
|
||||||
|
flutterRootDir: globals.fs.directory(Cache.flutterRoot),
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kTargetFile: mainPath,
|
kTargetFile: mainPath,
|
||||||
kBuildMode: getNameForBuildMode(buildMode),
|
kBuildMode: getNameForBuildMode(buildMode),
|
||||||
|
|
|
@ -16,6 +16,7 @@ import '../build_system/targets/linux.dart';
|
||||||
import '../build_system/targets/macos.dart';
|
import '../build_system/targets/macos.dart';
|
||||||
import '../build_system/targets/web.dart';
|
import '../build_system/targets/web.dart';
|
||||||
import '../build_system/targets/windows.dart';
|
import '../build_system/targets/windows.dart';
|
||||||
|
import '../cache.dart';
|
||||||
import '../globals.dart' as globals;
|
import '../globals.dart' as globals;
|
||||||
import '../project.dart';
|
import '../project.dart';
|
||||||
import '../reporting/reporting.dart';
|
import '../reporting/reporting.dart';
|
||||||
|
@ -147,6 +148,8 @@ class AssembleCommand extends FlutterCommand {
|
||||||
.childDirectory('flutter_build'),
|
.childDirectory('flutter_build'),
|
||||||
projectDir: flutterProject.directory,
|
projectDir: flutterProject.directory,
|
||||||
defines: _parseDefines(stringsArg('define')),
|
defines: _parseDefines(stringsArg('define')),
|
||||||
|
cacheDir: globals.cache.getRoot(),
|
||||||
|
flutterRootDir: globals.fs.directory(Cache.flutterRoot),
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,9 @@ Future<void> buildWeb(
|
||||||
final Status status = globals.logger.startProgress('Compiling $target for the Web...', timeout: null);
|
final Status status = globals.logger.startProgress('Compiling $target for the Web...', timeout: null);
|
||||||
final Stopwatch sw = Stopwatch()..start();
|
final Stopwatch sw = Stopwatch()..start();
|
||||||
try {
|
try {
|
||||||
final BuildResult result = await buildSystem.build(const WebServiceWorker(), Environment(
|
final BuildResult result = await buildSystem.build(const WebServiceWorker(), Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
outputDir: globals.fs.directory(getWebBuildDirectory()),
|
outputDir: globals.fs.directory(getWebBuildDirectory()),
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
buildDir: flutterProject.directory
|
buildDir: flutterProject.directory
|
||||||
.childDirectory('.dart_tool')
|
.childDirectory('.dart_tool')
|
||||||
.childDirectory('flutter_build'),
|
.childDirectory('flutter_build'),
|
||||||
|
|
|
@ -93,9 +93,8 @@ void main() {
|
||||||
];
|
];
|
||||||
testbed = Testbed(
|
testbed = Testbed(
|
||||||
setup: () {
|
setup: () {
|
||||||
environment = Environment(
|
environment = Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
);
|
);
|
||||||
globals.fs.file('foo.dart')
|
globals.fs.file('foo.dart')
|
||||||
..createSync(recursive: true)
|
..createSync(recursive: true)
|
||||||
|
@ -335,8 +334,8 @@ void main() {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
test('output directory is an input to the build', () => testbed.run(() async {
|
test('output directory is an input to the build', () => testbed.run(() async {
|
||||||
final Environment environmentA = Environment(projectDir: globals.fs.currentDirectory, outputDir: globals.fs.directory('a'));
|
final Environment environmentA = Environment.test(globals.fs.currentDirectory, outputDir: globals.fs.directory('a'));
|
||||||
final Environment environmentB = Environment(projectDir: globals.fs.currentDirectory, outputDir: globals.fs.directory('b'));
|
final Environment environmentB = Environment.test(globals.fs.currentDirectory, outputDir: globals.fs.directory('b'));
|
||||||
|
|
||||||
expect(environmentA.buildDir.path, isNot(environmentB.buildDir.path));
|
expect(environmentA.buildDir.path, isNot(environmentB.buildDir.path));
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -4,56 +4,68 @@
|
||||||
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:file/memory.dart';
|
||||||
import 'package:flutter_tools/src/base/file_system.dart';
|
import 'package:flutter_tools/src/base/file_system.dart';
|
||||||
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
|
import 'package:flutter_tools/src/base/terminal.dart';
|
||||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||||
import 'package:flutter_tools/src/build_system/file_hash_store.dart';
|
import 'package:flutter_tools/src/build_system/file_hash_store.dart';
|
||||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
|
||||||
import 'package:mockito/mockito.dart';
|
import 'package:mockito/mockito.dart';
|
||||||
|
import 'package:platform/platform.dart';
|
||||||
|
|
||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
import '../../src/context.dart';
|
|
||||||
import '../../src/testbed.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
Testbed testbed;
|
|
||||||
Environment environment;
|
Environment environment;
|
||||||
|
FileSystem fileSystem;
|
||||||
|
BufferLogger logger;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
testbed = Testbed(setup: () {
|
fileSystem = MemoryFileSystem();
|
||||||
globals.fs.directory('build').createSync();
|
logger = BufferLogger(
|
||||||
environment = Environment(
|
outputPreferences: OutputPreferences.test(),
|
||||||
outputDir: globals.fs.currentDirectory,
|
terminal: AnsiTerminal(stdio: null, platform: FakePlatform())
|
||||||
projectDir: globals.fs.currentDirectory,
|
);
|
||||||
|
fileSystem.directory('build').createSync();
|
||||||
|
environment = Environment.test(
|
||||||
|
fileSystem.currentDirectory,
|
||||||
);
|
);
|
||||||
environment.buildDir.createSync(recursive: true);
|
environment.buildDir.createSync(recursive: true);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test('Initializes file cache', () => testbed.run(() {
|
test('Initializes file cache', () {
|
||||||
final FileHashStore fileCache = FileHashStore(environment, globals.fs);
|
final FileHashStore fileCache = FileHashStore(
|
||||||
|
environment: environment,
|
||||||
|
fileSystem: fileSystem,
|
||||||
|
logger: logger,
|
||||||
|
);
|
||||||
fileCache.initialize();
|
fileCache.initialize();
|
||||||
fileCache.persist();
|
fileCache.persist();
|
||||||
|
|
||||||
expect(globals.fs.file(globals.fs.path.join(environment.buildDir.path, '.filecache')).existsSync(), true);
|
expect(fileSystem.file(fileSystem.path.join(environment.buildDir.path, '.filecache')).existsSync(), true);
|
||||||
|
|
||||||
final Uint8List buffer = globals.fs.file(globals.fs.path.join(environment.buildDir.path, '.filecache'))
|
final Uint8List buffer = fileSystem.file(fileSystem.path.join(environment.buildDir.path, '.filecache'))
|
||||||
.readAsBytesSync();
|
.readAsBytesSync();
|
||||||
final FileStorage fileStorage = FileStorage.fromBuffer(buffer);
|
final FileStorage fileStorage = FileStorage.fromBuffer(buffer);
|
||||||
|
|
||||||
expect(fileStorage.files, isEmpty);
|
expect(fileStorage.files, isEmpty);
|
||||||
expect(fileStorage.version, 2);
|
expect(fileStorage.version, 2);
|
||||||
}));
|
});
|
||||||
|
|
||||||
test('saves and restores to file cache', () => testbed.run(() async {
|
test('saves and restores to file cache', () async {
|
||||||
final File file = globals.fs.file('foo.dart')
|
final File file = fileSystem.file('foo.dart')
|
||||||
..createSync()
|
..createSync()
|
||||||
..writeAsStringSync('hello');
|
..writeAsStringSync('hello');
|
||||||
final FileHashStore fileCache = FileHashStore(environment, globals.fs);
|
final FileHashStore fileCache = FileHashStore(
|
||||||
|
environment: environment,
|
||||||
|
fileSystem: fileSystem,
|
||||||
|
logger: logger,
|
||||||
|
);
|
||||||
fileCache.initialize();
|
fileCache.initialize();
|
||||||
await fileCache.hashFiles(<File>[file]);
|
await fileCache.hashFiles(<File>[file]);
|
||||||
fileCache.persist();
|
fileCache.persist();
|
||||||
final String currentHash = fileCache.currentHashes[file.path];
|
final String currentHash = fileCache.currentHashes[file.path];
|
||||||
final Uint8List buffer = globals.fs.file(globals.fs.path.join(environment.buildDir.path, '.filecache'))
|
final Uint8List buffer = fileSystem.file(fileSystem.path.join(environment.buildDir.path, '.filecache'))
|
||||||
.readAsBytesSync();
|
.readAsBytesSync();
|
||||||
FileStorage fileStorage = FileStorage.fromBuffer(buffer);
|
FileStorage fileStorage = FileStorage.fromBuffer(buffer);
|
||||||
|
|
||||||
|
@ -61,7 +73,11 @@ void main() {
|
||||||
expect(fileStorage.files.single.path, file.path);
|
expect(fileStorage.files.single.path, file.path);
|
||||||
|
|
||||||
|
|
||||||
final FileHashStore newFileCache = FileHashStore(environment, globals.fs);
|
final FileHashStore newFileCache = FileHashStore(
|
||||||
|
environment: environment,
|
||||||
|
fileSystem: fileSystem,
|
||||||
|
logger: logger,
|
||||||
|
);
|
||||||
newFileCache.initialize();
|
newFileCache.initialize();
|
||||||
expect(newFileCache.currentHashes, isEmpty);
|
expect(newFileCache.currentHashes, isEmpty);
|
||||||
expect(newFileCache.previousHashes['foo.dart'], currentHash);
|
expect(newFileCache.previousHashes['foo.dart'], currentHash);
|
||||||
|
@ -72,35 +88,47 @@ void main() {
|
||||||
|
|
||||||
expect(fileStorage.files.single.hash, currentHash);
|
expect(fileStorage.files.single.hash, currentHash);
|
||||||
expect(fileStorage.files.single.path, file.path);
|
expect(fileStorage.files.single.path, file.path);
|
||||||
}));
|
});
|
||||||
|
|
||||||
test('handles persisting with a missing build directory', () => testbed.run(() async {
|
test('handles persisting with a missing build directory', () async {
|
||||||
final File file = globals.fs.file('foo.dart')
|
final File file = fileSystem.file('foo.dart')
|
||||||
..createSync()
|
..createSync()
|
||||||
..writeAsStringSync('hello');
|
..writeAsStringSync('hello');
|
||||||
final FileHashStore fileCache = FileHashStore(environment, globals.fs);
|
final FileHashStore fileCache = FileHashStore(
|
||||||
|
environment: environment,
|
||||||
|
fileSystem: fileSystem,
|
||||||
|
logger: logger,
|
||||||
|
);
|
||||||
fileCache.initialize();
|
fileCache.initialize();
|
||||||
environment.buildDir.deleteSync(recursive: true);
|
environment.buildDir.deleteSync(recursive: true);
|
||||||
|
|
||||||
await fileCache.hashFiles(<File>[file]);
|
await fileCache.hashFiles(<File>[file]);
|
||||||
// Does not throw.
|
|
||||||
fileCache.persist();
|
|
||||||
}));
|
|
||||||
|
|
||||||
test('handles hashing missing files', () => testbed.run(() async {
|
expect(() => fileCache.persist(), returnsNormally);
|
||||||
final FileHashStore fileCache = FileHashStore(environment, globals.fs);
|
});
|
||||||
|
|
||||||
|
test('handles hashing missing files', () async {
|
||||||
|
final FileHashStore fileCache = FileHashStore(
|
||||||
|
environment: environment,
|
||||||
|
fileSystem: fileSystem,
|
||||||
|
logger: logger,
|
||||||
|
);
|
||||||
fileCache.initialize();
|
fileCache.initialize();
|
||||||
|
|
||||||
final List<File> results = await fileCache.hashFiles(<File>[globals.fs.file('hello.dart')]);
|
final List<File> results = await fileCache.hashFiles(<File>[fileSystem.file('hello.dart')]);
|
||||||
|
|
||||||
expect(results, hasLength(1));
|
expect(results, hasLength(1));
|
||||||
expect(results.single.path, 'hello.dart');
|
expect(results.single.path, 'hello.dart');
|
||||||
expect(fileCache.currentHashes, isNot(contains(globals.fs.path.absolute('hello.dart'))));
|
expect(fileCache.currentHashes, isNot(contains(fileSystem.path.absolute('hello.dart'))));
|
||||||
}));
|
});
|
||||||
|
|
||||||
test('handles failure to persist file cache', () => testbed.run(() async {
|
test('handles failure to persist file cache', () async {
|
||||||
final FakeForwardingFileSystem fakeForwardingFileSystem = FakeForwardingFileSystem(globals.fs);
|
final FakeForwardingFileSystem fakeForwardingFileSystem = FakeForwardingFileSystem(fileSystem);
|
||||||
final FileHashStore fileCache = FileHashStore(environment, fakeForwardingFileSystem);
|
final FileHashStore fileCache = FileHashStore(
|
||||||
|
environment: environment,
|
||||||
|
fileSystem: fakeForwardingFileSystem,
|
||||||
|
logger: logger,
|
||||||
|
);
|
||||||
final String cacheFile = environment.buildDir.childFile('.filecache').path;
|
final String cacheFile = environment.buildDir.childFile('.filecache').path;
|
||||||
final MockFile mockFile = MockFile();
|
final MockFile mockFile = MockFile();
|
||||||
when(mockFile.writeAsBytesSync(any)).thenThrow(const FileSystemException('Out of space!'));
|
when(mockFile.writeAsBytesSync(any)).thenThrow(const FileSystemException('Out of space!'));
|
||||||
|
@ -110,12 +138,16 @@ void main() {
|
||||||
fakeForwardingFileSystem.files[cacheFile] = mockFile;
|
fakeForwardingFileSystem.files[cacheFile] = mockFile;
|
||||||
fileCache.persist();
|
fileCache.persist();
|
||||||
|
|
||||||
expect(testLogger.errorText, contains('Out of space!'));
|
expect(logger.errorText, contains('Out of space!'));
|
||||||
}));
|
});
|
||||||
|
|
||||||
test('handles failure to restore file cache', () => testbed.run(() async {
|
test('handles failure to restore file cache', () async {
|
||||||
final FakeForwardingFileSystem fakeForwardingFileSystem = FakeForwardingFileSystem(globals.fs);
|
final FakeForwardingFileSystem fakeForwardingFileSystem = FakeForwardingFileSystem(fileSystem);
|
||||||
final FileHashStore fileCache = FileHashStore(environment, fakeForwardingFileSystem);
|
final FileHashStore fileCache = FileHashStore(
|
||||||
|
environment: environment,
|
||||||
|
fileSystem: fakeForwardingFileSystem,
|
||||||
|
logger: logger,
|
||||||
|
);
|
||||||
final String cacheFile = environment.buildDir.childFile('.filecache').path;
|
final String cacheFile = environment.buildDir.childFile('.filecache').path;
|
||||||
final MockFile mockFile = MockFile();
|
final MockFile mockFile = MockFile();
|
||||||
when(mockFile.readAsBytesSync()).thenThrow(const FileSystemException('Out of space!'));
|
when(mockFile.readAsBytesSync()).thenThrow(const FileSystemException('Out of space!'));
|
||||||
|
@ -124,8 +156,8 @@ void main() {
|
||||||
fakeForwardingFileSystem.files[cacheFile] = mockFile;
|
fakeForwardingFileSystem.files[cacheFile] = mockFile;
|
||||||
fileCache.initialize();
|
fileCache.initialize();
|
||||||
|
|
||||||
expect(testLogger.errorText, contains('Out of space!'));
|
expect(logger.errorText, contains('Out of space!'));
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeForwardingFileSystem extends ForwardingFileSystem {
|
class FakeForwardingFileSystem extends ForwardingFileSystem {
|
||||||
|
|
|
@ -29,10 +29,9 @@ void main() {
|
||||||
globals.fs.directory('cache').createSync();
|
globals.fs.directory('cache').createSync();
|
||||||
final Directory outputs = globals.fs.directory('outputs')
|
final Directory outputs = globals.fs.directory('outputs')
|
||||||
..createSync();
|
..createSync();
|
||||||
environment = Environment(
|
environment = Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
outputDir: outputs,
|
outputDir: outputs,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
buildDir: globals.fs.directory('build'),
|
|
||||||
);
|
);
|
||||||
visitor = SourceVisitor(environment);
|
visitor = SourceVisitor(environment);
|
||||||
environment.buildDir.createSync(recursive: true);
|
environment.buildDir.createSync(recursive: true);
|
||||||
|
|
|
@ -22,10 +22,9 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
testbed.test('debug bundle contains expected resources', () async {
|
testbed.test('debug bundle contains expected resources', () async {
|
||||||
final Environment environment = Environment(
|
final Environment environment = Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
outputDir: globals.fs.directory('out')..createSync(),
|
outputDir: globals.fs.directory('out')..createSync(),
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
buildDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'debug',
|
kBuildMode: 'debug',
|
||||||
}
|
}
|
||||||
|
@ -50,10 +49,9 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
testbed.test('profile bundle contains expected resources', () async {
|
testbed.test('profile bundle contains expected resources', () async {
|
||||||
final Environment environment = Environment(
|
final Environment environment = Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
outputDir: globals.fs.directory('out')..createSync(),
|
outputDir: globals.fs.directory('out')..createSync(),
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
buildDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'profile',
|
kBuildMode: 'profile',
|
||||||
}
|
}
|
||||||
|
@ -70,10 +68,9 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
testbed.test('release bundle contains expected resources', () async {
|
testbed.test('release bundle contains expected resources', () async {
|
||||||
final Environment environment = Environment(
|
final Environment environment = Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
outputDir: globals.fs.directory('out')..createSync(),
|
outputDir: globals.fs.directory('out')..createSync(),
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
buildDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
}
|
}
|
||||||
|
@ -90,10 +87,9 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
testbed.test('AndroidAot can build provided target platform', () async {
|
testbed.test('AndroidAot can build provided target platform', () async {
|
||||||
final Environment environment = Environment(
|
final Environment environment = Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
outputDir: globals.fs.directory('out')..createSync(),
|
outputDir: globals.fs.directory('out')..createSync(),
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
buildDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
}
|
}
|
||||||
|
@ -126,10 +122,9 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
testbed.test('kExtraGenSnapshotOptions passes values to gen_snapshot', () async {
|
testbed.test('kExtraGenSnapshotOptions passes values to gen_snapshot', () async {
|
||||||
final Environment environment = Environment(
|
final Environment environment = Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
outputDir: globals.fs.directory('out')..createSync(),
|
outputDir: globals.fs.directory('out')..createSync(),
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
buildDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
kExtraGenSnapshotOptions: 'foo,bar,baz=2',
|
kExtraGenSnapshotOptions: 'foo,bar,baz=2',
|
||||||
|
@ -161,10 +156,9 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
testbed.test('android aot bundle copies so from abi directory', () async {
|
testbed.test('android aot bundle copies so from abi directory', () async {
|
||||||
final Environment environment = Environment(
|
final Environment environment = Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
outputDir: globals.fs.directory('out')..createSync(),
|
outputDir: globals.fs.directory('out')..createSync(),
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
buildDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'release',
|
kBuildMode: 'release',
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,8 @@ void main() {
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
testbed = Testbed(setup: () {
|
testbed = Testbed(setup: () {
|
||||||
environment = Environment(
|
environment = Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
);
|
);
|
||||||
globals.fs.file(globals.fs.path.join('packages', 'flutter_tools', 'lib', 'src',
|
globals.fs.file(globals.fs.path.join('packages', 'flutter_tools', 'lib', 'src',
|
||||||
'build_system', 'targets', 'assets.dart'))
|
'build_system', 'targets', 'assets.dart'))
|
||||||
|
@ -78,9 +77,8 @@ flutter:
|
||||||
globals.fs.file('pubspec.yaml')
|
globals.fs.file('pubspec.yaml')
|
||||||
..writeAsStringSync('name: foo\ndependencies:\n foo: any\n');
|
..writeAsStringSync('name: foo\ndependencies:\n foo: any\n');
|
||||||
|
|
||||||
await const FlutterPlugins().build(Environment(
|
await const FlutterPlugins().build(Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
));
|
));
|
||||||
|
|
||||||
expect(globals.fs.file('.flutter-plugins').existsSync(), true);
|
expect(globals.fs.file('.flutter-plugins').existsSync(), true);
|
||||||
|
|
|
@ -39,17 +39,15 @@ void main() {
|
||||||
mockXcode = MockXcode();
|
mockXcode = MockXcode();
|
||||||
mockProcessManager = MockProcessManager();
|
mockProcessManager = MockProcessManager();
|
||||||
testbed = Testbed(setup: () {
|
testbed = Testbed(setup: () {
|
||||||
androidEnvironment = Environment(
|
androidEnvironment = Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: getNameForBuildMode(BuildMode.profile),
|
kBuildMode: getNameForBuildMode(BuildMode.profile),
|
||||||
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
|
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
iosEnvironment = Environment(
|
iosEnvironment = Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: getNameForBuildMode(BuildMode.profile),
|
kBuildMode: getNameForBuildMode(BuildMode.profile),
|
||||||
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.ios),
|
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.ios),
|
||||||
|
@ -264,9 +262,8 @@ flutter_tools:lib/''');
|
||||||
return const CompilerOutput('example', 0, <Uri>[]);
|
return const CompilerOutput('example', 0, <Uri>[]);
|
||||||
});
|
});
|
||||||
|
|
||||||
await const KernelSnapshot().build(Environment(
|
await const KernelSnapshot().build(Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'debug',
|
kBuildMode: 'debug',
|
||||||
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
|
kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
|
||||||
|
|
|
@ -33,9 +33,8 @@ void main() {
|
||||||
when(mockPlatform.environment).thenReturn(Map<String, String>.unmodifiable(<String, String>{}));
|
when(mockPlatform.environment).thenReturn(Map<String, String>.unmodifiable(<String, String>{}));
|
||||||
testbed = Testbed(setup: () {
|
testbed = Testbed(setup: () {
|
||||||
Cache.flutterRoot = '';
|
Cache.flutterRoot = '';
|
||||||
environment = Environment(
|
environment = Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'debug',
|
kBuildMode: 'debug',
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,9 +67,8 @@ void main() {
|
||||||
globals.fs.file(globals.fs.path.join('bin', 'cache', 'pkg', 'sky_engine', 'sdk_ext',
|
globals.fs.file(globals.fs.path.join('bin', 'cache', 'pkg', 'sky_engine', 'sdk_ext',
|
||||||
'vmservice_io.dart')).createSync(recursive: true);
|
'vmservice_io.dart')).createSync(recursive: true);
|
||||||
|
|
||||||
environment = Environment(
|
environment = Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kBuildMode: 'debug',
|
kBuildMode: 'debug',
|
||||||
kTargetPlatform: 'darwin-x64',
|
kTargetPlatform: 'darwin-x64',
|
||||||
|
|
|
@ -45,10 +45,10 @@ void main() {
|
||||||
PackageMap.globalPackagesPath = packagesFile.path;
|
PackageMap.globalPackagesPath = packagesFile.path;
|
||||||
globals.fs.currentDirectory.childDirectory('bar').createSync();
|
globals.fs.currentDirectory.childDirectory('bar').createSync();
|
||||||
|
|
||||||
environment = Environment(
|
environment = Environment.test(
|
||||||
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory.childDirectory('foo'),
|
projectDir: globals.fs.currentDirectory.childDirectory('foo'),
|
||||||
outputDir: globals.fs.currentDirectory.childDirectory('bar'),
|
outputDir: globals.fs.currentDirectory.childDirectory('bar'),
|
||||||
buildDir: globals.fs.currentDirectory,
|
|
||||||
defines: <String, String>{
|
defines: <String, String>{
|
||||||
kTargetFile: globals.fs.path.join('foo', 'lib', 'main.dart'),
|
kTargetFile: globals.fs.path.join('foo', 'lib', 'main.dart'),
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,8 @@ void main() {
|
||||||
when(platform.isLinux).thenReturn(false);
|
when(platform.isLinux).thenReturn(false);
|
||||||
when(platform.pathSeparator).thenReturn(r'\');
|
when(platform.pathSeparator).thenReturn(r'\');
|
||||||
testbed = Testbed(setup: () {
|
testbed = Testbed(setup: () {
|
||||||
environment = Environment(
|
environment = Environment.test(
|
||||||
outputDir: globals.fs.currentDirectory,
|
globals.fs.currentDirectory,
|
||||||
projectDir: globals.fs.currentDirectory,
|
|
||||||
);
|
);
|
||||||
globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').createSync(recursive: true);
|
globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_export.h').createSync(recursive: true);
|
||||||
globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h').createSync();
|
globals.fs.file(r'C:\bin\cache\artifacts\engine\windows-x64\flutter_messenger.h').createSync();
|
||||||
|
|
Loading…
Reference in a new issue