fix copy command and remove resolve sync for macOS assemble (#40294)

This commit is contained in:
Jonah Williams 2019-09-11 20:29:27 -07:00 committed by GitHub
parent b939921663
commit 270878fc50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 9 deletions

View file

@ -146,11 +146,11 @@ abstract class Target {
final File stamp = _findStampFile(environment);
final List<String> inputPaths = <String>[];
for (File input in inputs) {
inputPaths.add(input.resolveSymbolicLinksSync());
inputPaths.add(input.path);
}
final List<String> outputPaths = <String>[];
for (File output in outputs) {
outputPaths.add(output.resolveSymbolicLinksSync());
outputPaths.add(output.path);
}
final Map<String, Object> result = <String, Object>{
'inputs': inputPaths,
@ -502,7 +502,7 @@ class _BuildInstance {
outputFiles[output.path] = output;
}
} else {
printStatus('${node.target.name}: Starting');
printStatus('${node.target.name}: Starting due to ${node.invalidatedReasons}');
await node.target.build(environment);
printStatus('${node.target.name}: Complete');
@ -653,9 +653,14 @@ class Node {
/// Output file paths from the previous invocation of this build node.
final Set<String> previousOutputs = <String>{};
/// Inout file paths from the previous invocation of this build node.
/// Input file paths from the previous invocation of this build node.
final Set<String> previousInputs = <String>{};
/// One or more reasons why a task was invalidated.
///
/// May be empty if the task was skipped.
final Set<InvalidedReason> invalidatedReasons = <InvalidedReason>{};
/// Whether this node needs an action performed.
bool get dirty => _dirty;
bool _dirty = false;
@ -685,6 +690,7 @@ class Node {
if (fileHashStore.currentHashes.containsKey(absolutePath)) {
final String currentHash = fileHashStore.currentHashes[absolutePath];
if (currentHash != previousHash) {
invalidatedReasons.add(InvalidedReason.inputChanged);
_dirty = true;
}
} else {
@ -698,11 +704,13 @@ class Node {
// output paths changed.
if (!currentOutputPaths.contains(previousOutput)) {
_dirty = true;
invalidatedReasons.add(InvalidedReason.outputSetChanged);
// if this isn't a current output file there is no reason to compute the hash.
continue;
}
final File file = fs.file(previousOutput);
if (!file.existsSync()) {
invalidatedReasons.add(InvalidedReason.outputMissing);
_dirty = true;
continue;
}
@ -711,6 +719,7 @@ class Node {
if (fileHashStore.currentHashes.containsKey(absolutePath)) {
final String currentHash = fileHashStore.currentHashes[absolutePath];
if (currentHash != previousHash) {
invalidatedReasons.add(InvalidedReason.outputChanged);
_dirty = true;
}
} else {
@ -728,9 +737,25 @@ class Node {
if (sourcesToHash.isNotEmpty) {
final List<File> dirty = await fileHashStore.hashFiles(sourcesToHash);
if (dirty.isNotEmpty) {
invalidatedReasons.add(InvalidedReason.inputChanged);
_dirty = true;
}
}
return !_dirty;
}
}
/// A description of why a task was rerun.
enum InvalidedReason {
/// An input file has an updated hash.
inputChanged,
/// An output file has an updated hash.
outputChanged,
/// An output file that is expected is missing.
outputMissing,
/// The set of expected output files changed.
outputSetChanged,
}

View file

@ -122,7 +122,9 @@ abstract class UnpackMacOS extends Target {
final Directory targetDirectory = environment
.outputDir
.childDirectory('FlutterMacOS.framework');
if (targetDirectory.existsSync()) {
targetDirectory.deleteSync(recursive: true);
}
final ProcessResult result = await processManager
.run(<String>['cp', '-R', basePath, targetDirectory.path]);
if (result.exitCode != 0) {
@ -285,6 +287,7 @@ abstract class MacOSBundleFlutterAssets extends Target {
@override
List<Source> get inputs => const <Source>[
Source.pattern('{PROJECT_DIR}/pubspec.yaml'),
Source.pattern('{BUILD_DIR}/App.framework/App'),
Source.behavior(MacOSAssetBehavior())
];

View file

@ -149,7 +149,7 @@ void writeListIfChanged(List<File> files, String path) {
final StringBuffer buffer = StringBuffer();
// These files are already sorted.
for (File file in files) {
buffer.writeln(file.resolveSymbolicLinksSync());
buffer.writeln(file.path);
}
final String newContents = buffer.toString();
if (!file.existsSync()) {

View file

@ -85,11 +85,21 @@ void main() {
for (File input in inputs) {
input.createSync(recursive: true);
}
// Create output directory so we can test that it is deleted.
environment.outputDir.childDirectory(_kOutputPrefix)
.createSync(recursive: true);
when(processManager.run(any)).thenAnswer((Invocation invocation) async {
final List<String> arguments = invocation.positionalArguments.first;
final Directory source = fs.directory(arguments[arguments.length - 2]);
final Directory target = fs.directory(arguments.last)
..createSync(recursive: true);
final String sourcePath = arguments[arguments.length - 2];
final String targetPath = arguments.last;
final Directory source = fs.directory(sourcePath);
final Directory target = fs.directory(targetPath);
// verify directory was deleted by command.
expect(target.existsSync(), false);
target.createSync(recursive: true);
for (FileSystemEntity entity in source.listSync(recursive: true)) {
if (entity is File) {
final String relative = fs.path.relative(entity.path, from: source.path);
@ -163,6 +173,26 @@ void main() {
expect(fs.file(precompiledIsolate).existsSync(), false);
}));
test('release/profile macOS application updates when App.framework updates', () => testbed.run(() async {
fs.file(fs.path.join('bin', 'cache', 'artifacts', 'engine', 'darwin-x64',
'vm_isolate_snapshot.bin')).createSync(recursive: true);
fs.file(fs.path.join('bin', 'cache', 'artifacts', 'engine', 'darwin-x64',
'isolate_snapshot.bin')).createSync(recursive: true);
final File inputFramework = fs.file(fs.path.join(environment.buildDir.path, 'App.framework', 'App'))
..createSync(recursive: true)
..writeAsStringSync('ABC');
await const ProfileMacOSBundleFlutterAssets().build(environment..defines[kBuildMode] = 'profile');
final File outputFramework = fs.file(fs.path.join(environment.outputDir.path, 'App.framework', 'App'));
expect(outputFramework.readAsStringSync(), 'ABC');
inputFramework.writeAsStringSync('DEF');
await const ProfileMacOSBundleFlutterAssets().build(environment..defines[kBuildMode] = 'profile');
expect(outputFramework.readAsStringSync(), 'DEF');
}));
test('release/profile macOS compilation uses correct gen_snapshot', () => testbed.run(() async {
when(genSnapshot.run(
snapshotType: anyNamed('snapshotType'),