Skip to content

Commit 43b7121

Browse files
committed
warn on file modified during build
1 parent c404cc1 commit 43b7121

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ ${e.message}
540540
}
541541
} else {
542542
cache.reset();
543-
await cache.hashFiles(
543+
final modifiedDuringBuild = await cache.hashFiles(
544544
[
545545
...result.dependencies,
546546
// Also depend on the hook source code.
@@ -549,6 +549,9 @@ ${e.message}
549549
validBeforeLastModified: cacheCutoffTime,
550550
);
551551
await cache.persist();
552+
if (modifiedDuringBuild != null) {
553+
logger.severe('File modified during build. Build must be rerun.');
554+
}
552555
}
553556
return result;
554557
},
@@ -717,11 +720,14 @@ ${e.message}
717720
.map(Uri.file)
718721
.toList();
719722
cache.reset();
720-
await cache.hashFiles(
723+
final modifiedDuringBuild = await cache.hashFiles(
721724
dartSources,
722725
validBeforeLastModified: cacheCutoffTime,
723726
);
724727
await cache.persist();
728+
if (modifiedDuringBuild != null) {
729+
logger.severe('File modified during build. Build must be rerun.');
730+
}
725731
} else {
726732
await cacheFile.delete();
727733
}

pkgs/native_assets_builder/lib/src/file_system_cache/file_system_cache.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,19 @@ class FileSystemCache {
3535
///
3636
/// If [validBeforeLastModified] is provided, any entities that were modified
3737
/// after [validBeforeLastModified] will get a dummy hash so that they will
38-
/// show up as outdated.
39-
Future<void> hashFiles(
38+
/// show up as outdated. If any such entity exists, its uri will be returned.
39+
Future<Uri?> hashFiles(
4040
List<Uri> fileSystemEntities, {
4141
DateTime? validBeforeLastModified,
4242
}) async {
43+
Uri? modifiedAfterTimeStamp;
4344
for (final uri in fileSystemEntities) {
4445
int hash;
4546
if (validBeforeLastModified != null &&
4647
(await uri.fileSystemEntity.lastModified())
4748
.isAfter(validBeforeLastModified)) {
4849
hash = _hashLastModifiedAfterCutoff;
50+
modifiedAfterTimeStamp = uri;
4951
} else {
5052
if (_isDirectoryPath(uri.path)) {
5153
hash = await _hashDirectory(uri);
@@ -55,6 +57,7 @@ class FileSystemCache {
5557
}
5658
_hashes.files.add(FilesystemEntityHash(uri, hash));
5759
}
60+
return modifiedAfterTimeStamp;
5861
}
5962

6063
Future<void> persist() =>

0 commit comments

Comments
 (0)