2018-06-27 22:12:16 +02:00
|
|
|
// Copyright 2018 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:path/path.dart' as p;
|
|
|
|
|
|
|
|
/// Ensures that [path] (usually a compilation artifact) has been modified more
|
|
|
|
/// recently than all this package's source files.
|
|
|
|
///
|
|
|
|
/// If [path] isn't up-to-date, this throws an error encouraging the user to run
|
|
|
|
/// [commandToRun].
|
|
|
|
void ensureUpToDate(String path, String commandToRun) {
|
|
|
|
// Ensure path is relative so the error messages are more readable.
|
|
|
|
path = p.relative(path);
|
2018-11-16 00:16:24 +01:00
|
|
|
if (!File(path).existsSync()) {
|
2018-06-27 22:12:16 +02:00
|
|
|
throw "$path does not exist. Run $commandToRun.";
|
|
|
|
}
|
|
|
|
|
2019-05-18 03:02:12 +02:00
|
|
|
var entriesToCheck = [
|
|
|
|
...Directory("lib").listSync(recursive: true),
|
2018-06-27 22:12:16 +02:00
|
|
|
|
2019-05-18 03:02:12 +02:00
|
|
|
// If we have a dependency override, "pub run" will touch the lockfile to
|
|
|
|
// mark it as newer than the pubspec, which makes it unsuitable to use for
|
|
|
|
// freshness checking.
|
|
|
|
if (File("pubspec.yaml")
|
|
|
|
.readAsStringSync()
|
|
|
|
.contains("dependency_overrides"))
|
|
|
|
File("pubspec.yaml")
|
|
|
|
else
|
|
|
|
File("pubspec.lock")
|
|
|
|
];
|
2018-06-27 22:12:16 +02:00
|
|
|
|
2019-05-18 03:02:12 +02:00
|
|
|
var lastModified = File(path).lastModifiedSync();
|
2018-06-27 22:12:16 +02:00
|
|
|
for (var entry in entriesToCheck) {
|
|
|
|
if (entry is File) {
|
|
|
|
var entryLastModified = entry.lastModifiedSync();
|
|
|
|
if (lastModified.isBefore(entryLastModified)) {
|
|
|
|
throw "${entry.path} was modified after ${p.prettyUri(p.toUri(path))} "
|
|
|
|
"was generated.\n"
|
2018-06-27 23:32:44 +02:00
|
|
|
"Run pub run grinder before-test.";
|
2018-06-27 22:12:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|