Ensure snapshot rebuild logic takes main path into account (#11924)
This commit is contained in:
parent
39680ebfbd
commit
14016523ed
@ -7,7 +7,7 @@ import 'dart:convert' show JSON;
|
||||
|
||||
import 'package:crypto/crypto.dart' show md5;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:quiver/core.dart' show hash4;
|
||||
import 'package:quiver/core.dart' show hash2;
|
||||
|
||||
import '../artifacts.dart';
|
||||
import '../build_info.dart';
|
||||
@ -21,7 +21,9 @@ GenSnapshot get genSnapshot => context.putIfAbsent(GenSnapshot, () => const GenS
|
||||
|
||||
/// A snapshot build configuration.
|
||||
class SnapshotType {
|
||||
const SnapshotType(this.platform, this.mode);
|
||||
SnapshotType(this.platform, this.mode) {
|
||||
assert(mode != null);
|
||||
}
|
||||
|
||||
final TargetPlatform platform;
|
||||
final BuildMode mode;
|
||||
@ -55,84 +57,70 @@ class GenSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
/// A collection of checksums for a set of input files.
|
||||
/// A fingerprint for a set of build input files and properties.
|
||||
///
|
||||
/// This class can be used during build actions to compute a checksum of the
|
||||
/// This class can be used during build actions to compute a fingerprint of the
|
||||
/// build action inputs, and if unchanged from the previous build, skip the
|
||||
/// build step. This assumes that build outputs are strictly a product of the
|
||||
/// input files.
|
||||
class Checksum {
|
||||
Checksum.fromFiles(SnapshotType type, this._mainPath, Set<String> inputPaths) {
|
||||
/// fingerprint inputs.
|
||||
class Fingerprint {
|
||||
Fingerprint.fromBuildInputs(Map<String, String> properties, Iterable<String> inputPaths) {
|
||||
final Iterable<File> files = inputPaths.map(fs.file);
|
||||
final Iterable<File> missingInputs = files.where((File file) => !file.existsSync());
|
||||
if (missingInputs.isNotEmpty)
|
||||
throw new ArgumentError('Missing input files:\n' + missingInputs.join('\n'));
|
||||
|
||||
_buildMode = type.mode.toString();
|
||||
_targetPlatform = type.platform?.toString() ?? '';
|
||||
_checksums = <String, String>{};
|
||||
for (File file in files) {
|
||||
final List<int> bytes = file.readAsBytesSync();
|
||||
_checksums[file.path] = md5.convert(bytes).toString();
|
||||
}
|
||||
_properties = <String, String>{}..addAll(properties);
|
||||
}
|
||||
|
||||
/// Creates a checksum from serialized JSON.
|
||||
/// Creates a Fingerprint from serialized JSON.
|
||||
///
|
||||
/// Throws [ArgumentError] in the following cases:
|
||||
/// * Version mismatch between the serializing framework and this framework.
|
||||
/// * buildMode is unspecified.
|
||||
/// * targetPlatform is unspecified.
|
||||
/// * File checksum map is unspecified.
|
||||
Checksum.fromJson(String json) {
|
||||
/// Throws [ArgumentError], if there is a version mismatch between the
|
||||
/// serializing framework and this framework.
|
||||
Fingerprint.fromJson(String json) {
|
||||
final Map<String, dynamic> content = JSON.decode(json);
|
||||
|
||||
final String version = content['version'];
|
||||
if (version != FlutterVersion.instance.frameworkRevision)
|
||||
throw new ArgumentError('Incompatible checksum version: $version');
|
||||
|
||||
_buildMode = content['buildMode'];
|
||||
if (_buildMode == null || _buildMode.isEmpty)
|
||||
throw new ArgumentError('Build mode unspecified in checksum JSON');
|
||||
|
||||
_targetPlatform = content['targetPlatform'];
|
||||
if (_targetPlatform == null)
|
||||
throw new ArgumentError('Target platform unspecified in checksum JSON');
|
||||
|
||||
_mainPath = content['entrypoint'];
|
||||
if (_mainPath == null)
|
||||
throw new ArgumentError('Entrypoint unspecified in checksum JSON');
|
||||
|
||||
_checksums = content['files'];
|
||||
if (_checksums == null)
|
||||
throw new ArgumentError('File checksums unspecified in checksum JSON');
|
||||
throw new ArgumentError('Incompatible fingerprint version: $version');
|
||||
_checksums = content['files'] ?? <String, String>{};
|
||||
_properties = content['properties'] ?? <String, String>{};
|
||||
}
|
||||
|
||||
String _mainPath;
|
||||
String _buildMode;
|
||||
String _targetPlatform;
|
||||
Map<String, String> _checksums;
|
||||
Map<String, String> _properties;
|
||||
|
||||
String toJson() => JSON.encode(<String, dynamic>{
|
||||
'version': FlutterVersion.instance.frameworkRevision,
|
||||
'buildMode': _buildMode,
|
||||
'entrypoint': _mainPath,
|
||||
'targetPlatform': _targetPlatform,
|
||||
'properties': _properties,
|
||||
'files': _checksums,
|
||||
});
|
||||
|
||||
@override
|
||||
bool operator==(dynamic other) {
|
||||
return other is Checksum &&
|
||||
_buildMode == other._buildMode &&
|
||||
_targetPlatform == other._targetPlatform &&
|
||||
_mainPath == other._mainPath &&
|
||||
_checksums.length == other._checksums.length &&
|
||||
_checksums.keys.every((String key) => _checksums[key] == other._checksums[key]);
|
||||
if (identical(other, this))
|
||||
return true;
|
||||
if (other.runtimeType != runtimeType)
|
||||
return false;
|
||||
final Fingerprint typedOther = other;
|
||||
return _equalMaps(typedOther._checksums, _checksums)
|
||||
&& _equalMaps(typedOther._properties, _properties);
|
||||
}
|
||||
|
||||
bool _equalMaps(Map<String, String> a, Map<String, String> b) {
|
||||
return a.length == b.length
|
||||
&& a.keys.every((String key) => a[key] == b[key]);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => hash4(_buildMode, _targetPlatform, _mainPath, _checksums);
|
||||
// Ignore map entries here to avoid becoming inconsistent with equals
|
||||
// due to differences in map entry order.
|
||||
int get hashCode => hash2(_properties.length, _checksums.length);
|
||||
}
|
||||
|
||||
final RegExp _separatorExpr = new RegExp(r'([^\\]) ');
|
||||
@ -177,14 +165,14 @@ class Snapshotter {
|
||||
@required String depfilePath,
|
||||
@required String packagesPath
|
||||
}) async {
|
||||
const SnapshotType type = const SnapshotType(null, BuildMode.debug);
|
||||
final SnapshotType type = new SnapshotType(null, BuildMode.debug);
|
||||
final List<String> args = <String>[
|
||||
'--snapshot_kind=script',
|
||||
'--script_snapshot=$snapshotPath',
|
||||
mainPath,
|
||||
];
|
||||
|
||||
final String checksumsPath = '$depfilePath.checksums';
|
||||
final String fingerprintPath = '$depfilePath.fingerprint';
|
||||
final int exitCode = await _build(
|
||||
snapshotType: type,
|
||||
outputSnapshotPath: snapshotPath,
|
||||
@ -192,11 +180,11 @@ class Snapshotter {
|
||||
snapshotArgs: args,
|
||||
depfilePath: depfilePath,
|
||||
mainPath: mainPath,
|
||||
checksumsPath: checksumsPath,
|
||||
fingerprintPath: fingerprintPath,
|
||||
);
|
||||
if (exitCode != 0)
|
||||
return exitCode;
|
||||
await _writeChecksum(type, snapshotPath, depfilePath, mainPath, checksumsPath);
|
||||
await _writeFingerprint(type, snapshotPath, depfilePath, mainPath, fingerprintPath);
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
@ -212,10 +200,10 @@ class Snapshotter {
|
||||
@required String packagesPath,
|
||||
@required String depfilePath,
|
||||
@required String mainPath,
|
||||
@required String checksumsPath,
|
||||
@required String fingerprintPath,
|
||||
}) async {
|
||||
if (!await _isBuildRequired(snapshotType, outputSnapshotPath, depfilePath, mainPath, checksumsPath)) {
|
||||
printTrace('Skipping snapshot build. Checksums match.');
|
||||
if (!await _isBuildRequired(snapshotType, outputSnapshotPath, depfilePath, mainPath, fingerprintPath)) {
|
||||
printTrace('Skipping snapshot build. Fingerprints match.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -229,41 +217,49 @@ class Snapshotter {
|
||||
if (exitCode != 0)
|
||||
return exitCode;
|
||||
|
||||
_writeChecksum(snapshotType, outputSnapshotPath, depfilePath, mainPath, checksumsPath);
|
||||
_writeFingerprint(snapshotType, outputSnapshotPath, depfilePath, mainPath, fingerprintPath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Future<bool> _isBuildRequired(SnapshotType type, String outputSnapshotPath, String depfilePath, String mainPath, String checksumsPath) async {
|
||||
final File checksumFile = fs.file(checksumsPath);
|
||||
Future<bool> _isBuildRequired(SnapshotType type, String outputSnapshotPath, String depfilePath, String mainPath, String fingerprintPath) async {
|
||||
final File fingerprintFile = fs.file(fingerprintPath);
|
||||
final File outputSnapshotFile = fs.file(outputSnapshotPath);
|
||||
final File depfile = fs.file(depfilePath);
|
||||
if (!outputSnapshotFile.existsSync() || !depfile.existsSync() || !checksumFile.existsSync())
|
||||
if (!outputSnapshotFile.existsSync() || !depfile.existsSync() || !fingerprintFile.existsSync())
|
||||
return true;
|
||||
|
||||
try {
|
||||
if (checksumFile.existsSync()) {
|
||||
final Checksum oldChecksum = new Checksum.fromJson(await checksumFile.readAsString());
|
||||
final Set<String> checksumPaths = await readDepfile(depfilePath)
|
||||
..addAll(<String>[outputSnapshotPath, mainPath]);
|
||||
final Checksum newChecksum = new Checksum.fromFiles(type, mainPath, checksumPaths);
|
||||
return oldChecksum != newChecksum;
|
||||
if (fingerprintFile.existsSync()) {
|
||||
final Fingerprint oldFingerprint = new Fingerprint.fromJson(await fingerprintFile.readAsString());
|
||||
final Set<String> inputFilePaths = await readDepfile(depfilePath)..addAll(<String>[outputSnapshotPath, mainPath]);
|
||||
final Fingerprint newFingerprint = createFingerprint(type, mainPath, inputFilePaths);
|
||||
return oldFingerprint != newFingerprint;
|
||||
}
|
||||
} catch (e) {
|
||||
// Log exception and continue, this step is a performance improvement only.
|
||||
printTrace('Rebuilding snapshot due to checksum validation error: $e');
|
||||
printTrace('Rebuilding snapshot due to fingerprint check error: $e');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<Null> _writeChecksum(SnapshotType type, String outputSnapshotPath, String depfilePath, String mainPath, String checksumsPath) async {
|
||||
Future<Null> _writeFingerprint(SnapshotType type, String outputSnapshotPath, String depfilePath, String mainPath, String fingerprintPath) async {
|
||||
try {
|
||||
final Set<String> checksumPaths = await readDepfile(depfilePath)
|
||||
final Set<String> inputFilePaths = await readDepfile(depfilePath)
|
||||
..addAll(<String>[outputSnapshotPath, mainPath]);
|
||||
final Checksum checksum = new Checksum.fromFiles(type, mainPath, checksumPaths);
|
||||
await fs.file(checksumsPath).writeAsString(checksum.toJson());
|
||||
final Fingerprint fingerprint = createFingerprint(type, mainPath, inputFilePaths);
|
||||
await fs.file(fingerprintPath).writeAsString(fingerprint.toJson());
|
||||
} catch (e, s) {
|
||||
// Log exception and continue, this step is a performance improvement only.
|
||||
printTrace('Error during snapshot checksum output: $e\n$s');
|
||||
print('Error during snapshot fingerprinting: $e\n$s');
|
||||
}
|
||||
}
|
||||
|
||||
static Fingerprint createFingerprint(SnapshotType type, String mainPath, Iterable<String> inputFilePaths) {
|
||||
final Map<String, String> properties = <String, String>{
|
||||
'buildMode': type.mode.toString(),
|
||||
'targetPlatform': type.platform?.toString() ?? '',
|
||||
'entryPoint': mainPath,
|
||||
};
|
||||
return new Fingerprint.fromBuildInputs(properties, inputFilePaths);
|
||||
}
|
||||
}
|
||||
|
@ -286,25 +286,25 @@ Future<String> _buildAotSnapshot(
|
||||
genSnapshotCmd.add(mainPath);
|
||||
|
||||
final SnapshotType snapshotType = new SnapshotType(platform, buildMode);
|
||||
final File checksumFile = fs.file('$dependencies.checksum');
|
||||
final List<File> checksumFiles = <File>[checksumFile, fs.file(dependencies)]
|
||||
final File fingerprintFile = fs.file('$dependencies.fingerprint');
|
||||
final List<File> fingerprintFiles = <File>[fingerprintFile, fs.file(dependencies)]
|
||||
..addAll(inputPaths.map(fs.file))
|
||||
..addAll(outputPaths.map(fs.file));
|
||||
if (checksumFiles.every((File file) => file.existsSync())) {
|
||||
if (fingerprintFiles.every((File file) => file.existsSync())) {
|
||||
try {
|
||||
final String json = await checksumFile.readAsString();
|
||||
final Checksum oldChecksum = new Checksum.fromJson(json);
|
||||
final String json = await fingerprintFile.readAsString();
|
||||
final Fingerprint oldFingerprint = new Fingerprint.fromJson(json);
|
||||
final Set<String> snapshotInputPaths = await readDepfile(dependencies)
|
||||
..add(mainPath)
|
||||
..addAll(outputPaths);
|
||||
final Checksum newChecksum = new Checksum.fromFiles(snapshotType, mainPath, snapshotInputPaths);
|
||||
if (oldChecksum == newChecksum) {
|
||||
printTrace('Skipping AOT snapshot build. Checksums match.');
|
||||
final Fingerprint newFingerprint = Snapshotter.createFingerprint(snapshotType, mainPath, snapshotInputPaths);
|
||||
if (oldFingerprint == newFingerprint) {
|
||||
printStatus('Skipping AOT snapshot build. Fingerprint match.');
|
||||
return outputPath;
|
||||
}
|
||||
} catch (e) {
|
||||
// Log exception and continue, this step is a performance improvement only.
|
||||
printTrace('Rebuilding snapshot due to checksum validation error: $e');
|
||||
printTrace('Rebuilding snapshot due to fingerprint check error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@ -370,16 +370,16 @@ Future<String> _buildAotSnapshot(
|
||||
await runCheckedAsync(linkCommand);
|
||||
}
|
||||
|
||||
// Compute and record checksums.
|
||||
// Compute and record build fingerprint.
|
||||
try {
|
||||
final Set<String> snapshotInputPaths = await readDepfile(dependencies)
|
||||
..add(mainPath)
|
||||
..addAll(outputPaths);
|
||||
final Checksum checksum = new Checksum.fromFiles(snapshotType, mainPath, snapshotInputPaths);
|
||||
await checksumFile.writeAsString(checksum.toJson());
|
||||
final Fingerprint fingerprint = Snapshotter.createFingerprint(snapshotType, mainPath, snapshotInputPaths);
|
||||
await fingerprintFile.writeAsString(fingerprint.toJson());
|
||||
} catch (e, s) {
|
||||
// Log exception and continue, this step is a performance improvement only.
|
||||
printTrace('Error during AOT snapshot checksum output: $e\n$s');
|
||||
printStatus('Error during AOT snapshot fingerprinting: $e\n$s');
|
||||
}
|
||||
|
||||
return outputPath;
|
||||
|
@ -24,14 +24,12 @@ class _FakeGenSnapshot implements GenSnapshot {
|
||||
this.succeed: true,
|
||||
this.snapshotPath: 'output.snapshot',
|
||||
this.snapshotContent: '',
|
||||
this.depfilePath: 'output.snapshot.d',
|
||||
this.depfileContent: 'output.snapshot.d : main.dart',
|
||||
});
|
||||
|
||||
final bool succeed;
|
||||
final String snapshotPath;
|
||||
final String snapshotContent;
|
||||
final String depfilePath;
|
||||
final String depfileContent;
|
||||
int _callCount = 0;
|
||||
|
||||
@ -55,7 +53,18 @@ class _FakeGenSnapshot implements GenSnapshot {
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('Checksum', () {
|
||||
group('SnapshotType', () {
|
||||
test('throws, if build mode is null', () {
|
||||
expect(
|
||||
() => new SnapshotType(TargetPlatform.android_x64, null),
|
||||
throwsA(anything),
|
||||
);
|
||||
});
|
||||
test('does not throw, if target platform is null', () {
|
||||
expect(new SnapshotType(null, BuildMode.release), isNotNull);
|
||||
});
|
||||
});
|
||||
group('Fingerprint', () {
|
||||
MockFlutterVersion mockVersion;
|
||||
const String kVersion = '123456abcdef';
|
||||
|
||||
@ -64,7 +73,7 @@ void main() {
|
||||
when(mockVersion.frameworkRevision).thenReturn(kVersion);
|
||||
});
|
||||
|
||||
group('fromFiles', () {
|
||||
group('fromBuildInputs', () {
|
||||
MemoryFileSystem fs;
|
||||
|
||||
setUp(() {
|
||||
@ -73,78 +82,69 @@ void main() {
|
||||
|
||||
testUsingContext('throws if any input file does not exist', () async {
|
||||
await fs.file('a.dart').create();
|
||||
const SnapshotType snapshotType = const SnapshotType(TargetPlatform.ios, BuildMode.debug);
|
||||
expect(
|
||||
() => new Checksum.fromFiles(snapshotType, 'a.dart', <String>['a.dart', 'b.dart'].toSet()),
|
||||
throwsA(anything),
|
||||
);
|
||||
}, overrides: <Type, Generator>{ FileSystem: () => fs });
|
||||
|
||||
testUsingContext('throws if any build mode is null', () async {
|
||||
await fs.file('a.dart').create();
|
||||
const SnapshotType snapshotType = const SnapshotType(TargetPlatform.ios, null);
|
||||
expect(
|
||||
() => new Checksum.fromFiles(snapshotType, 'a.dart', <String>['a.dart', 'b.dart'].toSet()),
|
||||
throwsA(anything),
|
||||
);
|
||||
}, overrides: <Type, Generator>{ FileSystem: () => fs });
|
||||
|
||||
testUsingContext('does not throw if any target platform is null', () async {
|
||||
await fs.file('a.dart').create();
|
||||
const SnapshotType snapshotType = const SnapshotType(null, BuildMode.debug);
|
||||
expect(
|
||||
new Checksum.fromFiles(snapshotType, 'a.dart', <String>['a.dart'].toSet()),
|
||||
isNotNull,
|
||||
() => new Fingerprint.fromBuildInputs(<String, String>{}, <String>['a.dart', 'b.dart']),
|
||||
throwsArgumentError,
|
||||
);
|
||||
}, overrides: <Type, Generator>{ FileSystem: () => fs });
|
||||
|
||||
testUsingContext('populates checksums for valid files', () async {
|
||||
await fs.file('a.dart').writeAsString('This is a');
|
||||
await fs.file('b.dart').writeAsString('This is b');
|
||||
const SnapshotType snapshotType = const SnapshotType(TargetPlatform.ios, BuildMode.debug);
|
||||
final Checksum checksum = new Checksum.fromFiles(snapshotType, 'a.dart', <String>['a.dart', 'b.dart'].toSet());
|
||||
final Fingerprint fingerprint = new Fingerprint.fromBuildInputs(<String, String>{}, <String>['a.dart', 'b.dart']);
|
||||
|
||||
final Map<String, dynamic> json = JSON.decode(checksum.toJson());
|
||||
expect(json, hasLength(5));
|
||||
expect(json['version'], mockVersion.frameworkRevision);
|
||||
expect(json['buildMode'], BuildMode.debug.toString());
|
||||
expect(json['targetPlatform'], TargetPlatform.ios.toString());
|
||||
expect(json['entrypoint'], 'a.dart');
|
||||
final Map<String, dynamic> json = JSON.decode(fingerprint.toJson());
|
||||
expect(json['files'], hasLength(2));
|
||||
expect(json['files']['a.dart'], '8a21a15fad560b799f6731d436c1b698');
|
||||
expect(json['files']['b.dart'], '6f144e08b58cd0925328610fad7ac07c');
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
}, overrides: <Type, Generator>{ FileSystem: () => fs });
|
||||
|
||||
testUsingContext('includes framework version', () {
|
||||
final Fingerprint fingerprint = new Fingerprint.fromBuildInputs(<String, String>{}, <String>[]);
|
||||
|
||||
final Map<String, dynamic> json = JSON.decode(fingerprint.toJson());
|
||||
expect(json['version'], mockVersion.frameworkRevision);
|
||||
}, overrides: <Type, Generator>{ FlutterVersion: () => mockVersion });
|
||||
|
||||
testUsingContext('includes provided properties', () {
|
||||
final Fingerprint fingerprint = new Fingerprint.fromBuildInputs(<String, String>{'a': 'A', 'b': 'B'}, <String>[]);
|
||||
|
||||
final Map<String, dynamic> json = JSON.decode(fingerprint.toJson());
|
||||
expect(json['properties'], hasLength(2));
|
||||
expect(json['properties']['a'], 'A');
|
||||
expect(json['properties']['b'], 'B');
|
||||
}, overrides: <Type, Generator>{ FlutterVersion: () => mockVersion });
|
||||
});
|
||||
|
||||
group('fromJson', () {
|
||||
testUsingContext('throws if JSON is invalid', () async {
|
||||
expect(() => new Checksum.fromJson('<xml></xml>'), throwsA(anything));
|
||||
expect(() => new Fingerprint.fromJson('<xml></xml>'), throwsA(anything));
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('populates checksums for valid JSON', () async {
|
||||
testUsingContext('creates fingerprint from valid JSON', () async {
|
||||
final String json = JSON.encode(<String, dynamic>{
|
||||
'version': kVersion,
|
||||
'buildMode': BuildMode.release.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entrypoint': 'a.dart',
|
||||
'properties': <String, String>{
|
||||
'buildMode': BuildMode.release.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entryPoint': 'a.dart',
|
||||
},
|
||||
'files': <String, dynamic>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07c',
|
||||
},
|
||||
});
|
||||
final Checksum checksum = new Checksum.fromJson(json);
|
||||
|
||||
final Map<String, dynamic> content = JSON.decode(checksum.toJson());
|
||||
expect(content, hasLength(5));
|
||||
final Fingerprint fingerprint = new Fingerprint.fromJson(json);
|
||||
final Map<String, dynamic> content = JSON.decode(fingerprint.toJson());
|
||||
expect(content, hasLength(3));
|
||||
expect(content['version'], mockVersion.frameworkRevision);
|
||||
expect(content['buildMode'], BuildMode.release.toString());
|
||||
expect(content['targetPlatform'], TargetPlatform.ios.toString());
|
||||
expect(content['entrypoint'], 'a.dart');
|
||||
expect(content['properties'], hasLength(3));
|
||||
expect(content['properties']['buildMode'], BuildMode.release.toString());
|
||||
expect(content['properties']['targetPlatform'], TargetPlatform.ios.toString());
|
||||
expect(content['properties']['entryPoint'], 'a.dart');
|
||||
expect(content['files'], hasLength(2));
|
||||
expect(content['files']['a.dart'], '8a21a15fad560b799f6731d436c1b698');
|
||||
expect(content['files']['b.dart'], '6f144e08b58cd0925328610fad7ac07c');
|
||||
}, overrides: <Type, Generator>{
|
||||
@ -154,81 +154,56 @@ void main() {
|
||||
testUsingContext('throws ArgumentError for unknown versions', () async {
|
||||
final String json = JSON.encode(<String, dynamic>{
|
||||
'version': 'bad',
|
||||
'buildMode': BuildMode.release.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entrypoint': 'a.dart',
|
||||
'files': <String, dynamic>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07c',
|
||||
},
|
||||
'properties':<String, String>{},
|
||||
'files':<String, String>{},
|
||||
});
|
||||
expect(() => new Checksum.fromJson(json), throwsArgumentError);
|
||||
expect(() => new Fingerprint.fromJson(json), throwsArgumentError);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('throws ArgumentError if version is not present', () async {
|
||||
final String json = JSON.encode(<String, dynamic>{
|
||||
'properties':<String, String>{},
|
||||
'files':<String, String>{},
|
||||
});
|
||||
expect(() => new Fingerprint.fromJson(json), throwsArgumentError);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('treats missing properties and files entries as if empty', () async {
|
||||
final String json = JSON.encode(<String, dynamic>{
|
||||
'version': kVersion,
|
||||
});
|
||||
expect(new Fingerprint.fromJson(json), new Fingerprint.fromBuildInputs(<String, String>{}, <String>[]));
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
});
|
||||
|
||||
group('operator ==', () {
|
||||
testUsingContext('reports not equal if build modes do not match', () async {
|
||||
testUsingContext('reports not equal if properties do not match', () async {
|
||||
final Map<String, dynamic> a = <String, dynamic>{
|
||||
'version': kVersion,
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entrypoint': 'a.dart',
|
||||
'files': <String, dynamic>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07c',
|
||||
'properties': <String, String>{
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
},
|
||||
'files': <String, dynamic>{},
|
||||
};
|
||||
final Map<String, dynamic> b = new Map<String, dynamic>.from(a);
|
||||
b['buildMode'] = BuildMode.release.toString();
|
||||
expect(new Checksum.fromJson(JSON.encode(a)) == new Checksum.fromJson(JSON.encode(b)), isFalse);
|
||||
b['properties'] = <String, String>{
|
||||
'buildMode': BuildMode.release.toString(),
|
||||
};
|
||||
expect(new Fingerprint.fromJson(JSON.encode(a)) == new Fingerprint.fromJson(JSON.encode(b)), isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('reports not equal if target platforms do not match', () async {
|
||||
testUsingContext('reports not equal if file checksums do not match', () async {
|
||||
final Map<String, dynamic> a = <String, dynamic>{
|
||||
'version': kVersion,
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entrypoint': 'a.dart',
|
||||
'files': <String, dynamic>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07c',
|
||||
},
|
||||
};
|
||||
final Map<String, dynamic> b = new Map<String, dynamic>.from(a);
|
||||
b['targetPlatform'] = TargetPlatform.android_arm.toString();
|
||||
expect(new Checksum.fromJson(JSON.encode(a)) == new Checksum.fromJson(JSON.encode(b)), isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('reports not equal if entrypoints do not match', () async {
|
||||
final Map<String, dynamic> a = <String, dynamic>{
|
||||
'version': kVersion,
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entrypoint': 'a.dart',
|
||||
'files': <String, dynamic>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07c',
|
||||
},
|
||||
};
|
||||
final Map<String, dynamic> b = new Map<String, dynamic>.from(a);
|
||||
b['entrypoint'] = 'b.dart';
|
||||
expect(new Checksum.fromJson(JSON.encode(a)) == new Checksum.fromJson(JSON.encode(b)), isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('reports not equal if checksums do not match', () async {
|
||||
final Map<String, dynamic> a = <String, dynamic>{
|
||||
'version': kVersion,
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entrypoint': 'a.dart',
|
||||
'properties': <String, String>{},
|
||||
'files': <String, dynamic>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07c',
|
||||
@ -239,17 +214,15 @@ void main() {
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07d',
|
||||
};
|
||||
expect(new Checksum.fromJson(JSON.encode(a)) == new Checksum.fromJson(JSON.encode(b)), isFalse);
|
||||
expect(new Fingerprint.fromJson(JSON.encode(a)) == new Fingerprint.fromJson(JSON.encode(b)), isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('reports not equal if keys do not match', () async {
|
||||
testUsingContext('reports not equal if file paths do not match', () async {
|
||||
final Map<String, dynamic> a = <String, dynamic>{
|
||||
'version': kVersion,
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entrypoint': 'a.dart',
|
||||
'properties': <String, String>{},
|
||||
'files': <String, dynamic>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07c',
|
||||
@ -260,27 +233,40 @@ void main() {
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'c.dart': '6f144e08b58cd0925328610fad7ac07d',
|
||||
};
|
||||
expect(new Checksum.fromJson(JSON.encode(a)) == new Checksum.fromJson(JSON.encode(b)), isFalse);
|
||||
expect(new Fingerprint.fromJson(JSON.encode(a)) == new Fingerprint.fromJson(JSON.encode(b)), isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('reports equal if all checksums match', () async {
|
||||
testUsingContext('reports equal if properties and file checksums match', () async {
|
||||
final Map<String, dynamic> a = <String, dynamic>{
|
||||
'version': kVersion,
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entrypoint': 'a.dart',
|
||||
'properties': <String, String>{
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': TargetPlatform.ios.toString(),
|
||||
'entryPoint': 'a.dart',
|
||||
},
|
||||
'files': <String, dynamic>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07c',
|
||||
},
|
||||
};
|
||||
expect(new Checksum.fromJson(JSON.encode(a)) == new Checksum.fromJson(JSON.encode(a)), isTrue);
|
||||
expect(new Fingerprint.fromJson(JSON.encode(a)) == new Fingerprint.fromJson(JSON.encode(a)), isTrue);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
});
|
||||
group('hashCode', () {
|
||||
testUsingContext('is consistent with equals, even if map entries are reordered', () async {
|
||||
final Fingerprint a = new Fingerprint.fromJson('{"version":"$kVersion","properties":{"a":"A","b":"B"},"files":{}}');
|
||||
final Fingerprint b = new Fingerprint.fromJson('{"version":"$kVersion","properties":{"b":"B","a":"A"},"files":{}}');
|
||||
expect(a, b);
|
||||
expect(a.hashCode, b.hashCode);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
group('readDepfile', () {
|
||||
@ -351,7 +337,7 @@ void main() {
|
||||
|
||||
expect(genSnapshot.callCount, 1);
|
||||
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.checksums').readAsString());
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.fingerprint').readAsString());
|
||||
expect(json['files'], hasLength(2));
|
||||
expect(json['files']['main.dart'], '27f5ebf0f8c559b2af9419d190299a5e');
|
||||
expect(json['files']['output.snapshot'], 'd41d8cd98f00b204e9800998ecf8427e');
|
||||
@ -365,7 +351,7 @@ void main() {
|
||||
await fs.file('main.dart').writeAsString('void main() {}');
|
||||
await fs.file('output.snapshot').create();
|
||||
await fs.file('output.snapshot.d').writeAsString('output.snapshot : main.dart');
|
||||
await fs.file('output.snapshot.d.checksums').writeAsString(JSON.encode(<String, dynamic>{
|
||||
await fs.file('output.snapshot.d.fingerprint').writeAsString(JSON.encode(<String, dynamic>{
|
||||
'version': '$kVersion',
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'files': <String, dynamic>{
|
||||
@ -382,7 +368,7 @@ void main() {
|
||||
|
||||
expect(genSnapshot.callCount, 1);
|
||||
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.checksums').readAsString());
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.fingerprint').readAsString());
|
||||
expect(json['files'], hasLength(2));
|
||||
expect(json['files']['main.dart'], '27f5ebf0f8c559b2af9419d190299a5e');
|
||||
expect(json['files']['output.snapshot'], 'd41d8cd98f00b204e9800998ecf8427e');
|
||||
@ -395,9 +381,13 @@ void main() {
|
||||
testUsingContext('builds snapshot and checksums when checksums match but previous snapshot not present', () async {
|
||||
await fs.file('main.dart').writeAsString('void main() {}');
|
||||
await fs.file('output.snapshot.d').writeAsString('output.snapshot : main.dart');
|
||||
await fs.file('output.snapshot.d.checksums').writeAsString(JSON.encode(<String, dynamic>{
|
||||
await fs.file('output.snapshot.d.fingerprint').writeAsString(JSON.encode(<String, dynamic>{
|
||||
'version': '$kVersion',
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'properties': <String, String>{
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': '',
|
||||
'entryPoint': 'main.dart',
|
||||
},
|
||||
'files': <String, dynamic>{
|
||||
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
|
||||
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
|
||||
@ -412,7 +402,7 @@ void main() {
|
||||
|
||||
expect(genSnapshot.callCount, 1);
|
||||
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.checksums').readAsString());
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.fingerprint').readAsString());
|
||||
expect(json['files'], hasLength(2));
|
||||
expect(json['files']['main.dart'], '27f5ebf0f8c559b2af9419d190299a5e');
|
||||
expect(json['files']['output.snapshot'], 'd41d8cd98f00b204e9800998ecf8427e');
|
||||
@ -422,10 +412,9 @@ void main() {
|
||||
GenSnapshot: () => genSnapshot,
|
||||
});
|
||||
|
||||
testUsingContext('builds snapshot and checksums when main entry point changes', () async {
|
||||
testUsingContext('builds snapshot and fingerprint when main entry point changes to other dependency', () async {
|
||||
final _FakeGenSnapshot genSnapshot = new _FakeGenSnapshot(
|
||||
snapshotPath: 'output.snapshot',
|
||||
depfilePath: 'output.snapshot.d',
|
||||
depfileContent: 'output.snapshot : main.dart other.dart',
|
||||
);
|
||||
context.setVariable(GenSnapshot, genSnapshot);
|
||||
@ -434,10 +423,13 @@ void main() {
|
||||
await fs.file('other.dart').writeAsString('import "main.dart";\nvoid main() {}');
|
||||
await fs.file('output.snapshot').create();
|
||||
await fs.file('output.snapshot.d').writeAsString('output.snapshot : main.dart');
|
||||
await fs.file('output.snapshot.d.checksums').writeAsString(JSON.encode(<String, dynamic>{
|
||||
'version': '$kVersion',
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': '',
|
||||
await fs.file('output.snapshot.d.fingerprint').writeAsString(JSON.encode(<String, dynamic>{
|
||||
'version': kVersion,
|
||||
'properties': <String, String>{
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': '',
|
||||
'entryPoint': 'main.dart',
|
||||
},
|
||||
'files': <String, dynamic>{
|
||||
'main.dart': 'bc096b33f14dde5e0ffaf93a1d03395c',
|
||||
'other.dart': 'e0c35f083f0ad76b2d87100ec678b516',
|
||||
@ -452,7 +444,8 @@ void main() {
|
||||
);
|
||||
|
||||
expect(genSnapshot.callCount, 1);
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.checksums').readAsString());
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.fingerprint').readAsString());
|
||||
expect(json['properties']['entryPoint'], 'other.dart');
|
||||
expect(json['files'], hasLength(3));
|
||||
expect(json['files']['main.dart'], 'bc096b33f14dde5e0ffaf93a1d03395c');
|
||||
expect(json['files']['other.dart'], 'e0c35f083f0ad76b2d87100ec678b516');
|
||||
@ -462,15 +455,17 @@ void main() {
|
||||
FlutterVersion: () => mockVersion,
|
||||
});
|
||||
|
||||
testUsingContext('skips snapshot when checksums match and previous snapshot is present', () async {
|
||||
testUsingContext('skips snapshot when fingerprints match and previous snapshot is present', () async {
|
||||
await fs.file('main.dart').writeAsString('void main() {}');
|
||||
await fs.file('output.snapshot').create();
|
||||
await fs.file('output.snapshot.d').writeAsString('output.snapshot : main.dart');
|
||||
await fs.file('output.snapshot.d.checksums').writeAsString(JSON.encode(<String, dynamic>{
|
||||
'version': '$kVersion',
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': '',
|
||||
'entrypoint': 'main.dart',
|
||||
await fs.file('output.snapshot.d.fingerprint').writeAsString(JSON.encode(<String, dynamic>{
|
||||
'version': kVersion,
|
||||
'properties': <String, String>{
|
||||
'buildMode': BuildMode.debug.toString(),
|
||||
'targetPlatform': '',
|
||||
'entryPoint': 'main.dart',
|
||||
},
|
||||
'files': <String, dynamic>{
|
||||
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
|
||||
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
|
||||
@ -485,7 +480,7 @@ void main() {
|
||||
|
||||
expect(genSnapshot.callCount, 0);
|
||||
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.checksums').readAsString());
|
||||
final Map<String, dynamic> json = JSON.decode(await fs.file('output.snapshot.d.fingerprint').readAsString());
|
||||
expect(json['files'], hasLength(2));
|
||||
expect(json['files']['main.dart'], '27f5ebf0f8c559b2af9419d190299a5e');
|
||||
expect(json['files']['output.snapshot'], 'd41d8cd98f00b204e9800998ecf8427e');
|
||||
@ -494,5 +489,46 @@ void main() {
|
||||
FlutterVersion: () => mockVersion,
|
||||
GenSnapshot: () => genSnapshot,
|
||||
});
|
||||
|
||||
group('createFingerprint', () {
|
||||
test('creates fingerprint with target platform', () {
|
||||
final Fingerprint fingerprint = Snapshotter.createFingerprint(
|
||||
new SnapshotType(TargetPlatform.android_x64, BuildMode.release),
|
||||
'a.dart',
|
||||
<String>[],
|
||||
);
|
||||
expect(fingerprint, new Fingerprint.fromBuildInputs(<String, String>{
|
||||
'buildMode': 'BuildMode.release',
|
||||
'targetPlatform': 'TargetPlatform.android_x64',
|
||||
'entryPoint': 'a.dart',
|
||||
}, <String>[]));
|
||||
});
|
||||
test('creates fingerprint without target platform', () {
|
||||
final Fingerprint fingerprint = Snapshotter.createFingerprint(
|
||||
new SnapshotType(null, BuildMode.release),
|
||||
'a.dart',
|
||||
<String>[],
|
||||
);
|
||||
expect(fingerprint, new Fingerprint.fromBuildInputs(<String, String>{
|
||||
'buildMode': 'BuildMode.release',
|
||||
'targetPlatform': '',
|
||||
'entryPoint': 'a.dart',
|
||||
}, <String>[]));
|
||||
});
|
||||
testUsingContext('creates fingerprint with file checksums', () async {
|
||||
await fs.file('a.dart').create();
|
||||
await fs.file('b.dart').create();
|
||||
final Fingerprint fingerprint = Snapshotter.createFingerprint(
|
||||
new SnapshotType(TargetPlatform.android_x64, BuildMode.release),
|
||||
'a.dart',
|
||||
<String>['a.dart', 'b.dart'],
|
||||
);
|
||||
expect(fingerprint, new Fingerprint.fromBuildInputs(<String, String>{
|
||||
'buildMode': 'BuildMode.release',
|
||||
'targetPlatform': 'TargetPlatform.android_x64',
|
||||
'entryPoint': 'a.dart',
|
||||
}, <String>['a.dart', 'b.dart']));
|
||||
}, overrides: <Type, Generator>{ FileSystem: () => fs });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user