Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Unified Diff: pkg/analyzer/lib/src/codegen/tools.dart

Issue 1430723002: Refactor code for checking that generated files are up to date. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/tool/task_dependency_graph/check_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/codegen/tools.dart
diff --git a/pkg/analyzer/lib/src/codegen/tools.dart b/pkg/analyzer/lib/src/codegen/tools.dart
index dac63d15281ec183d8de4b414929b26b4b787369..89bbb84896ca39d71e128ec3c6f46bd267d55b36 100644
--- a/pkg/analyzer/lib/src/codegen/tools.dart
+++ b/pkg/analyzer/lib/src/codegen/tools.dart
@@ -286,6 +286,53 @@ abstract class GeneratedContent {
* [pkgPath] is the path to the current package.
*/
FileSystemEntity output(String pkgPath);
+
+ /**
+ * Check that all of the [targets] are up to date. If they are not, print
+ * out a message instructing the user to regenerate them, and exit with a
+ * nonzero error code.
+ *
+ * [pkgPath] is the path to the current package. [generatorRelPath] is the
+ * path to a .dart script the user may use to regenerate the targets.
+ *
+ * To avoid mistakes when run on Windows, [generatorRelPath] always uses
+ * POSIX directory separators.
+ */
+ static void checkAll(String pkgPath, String generatorRelPath,
+ Iterable<GeneratedContent> targets) {
+ bool generateNeeded = false;
+ for (GeneratedContent target in targets) {
+ if (!target.check(pkgPath)) {
+ print(
+ '${target.output(pkgPath).absolute} does not have expected contents.');
+ generateNeeded = true;
+ }
+ }
+ if (generateNeeded) {
+ print('Please regenerate using:');
+ String executable = Platform.executable;
+ String packageRoot = '';
+ if (Platform.packageRoot.isNotEmpty) {
+ packageRoot = ' --package-root=${Platform.packageRoot}';
+ }
+ String generateScript =
+ join(pkgPath, joinAll(posix.split(generatorRelPath)));
+ print(' $executable$packageRoot $generateScript');
+ exit(1);
+ } else {
+ print('All generated files up to date.');
+ }
+ }
+
+ /**
+ * Regenerate all of the [targets]. [pkgPath] is the path to the current
+ * package.
+ */
+ static void generateAll(String pkgPath, Iterable<GeneratedContent> targets) {
+ for (GeneratedContent target in targets) {
+ target.generate(pkgPath);
+ }
+ }
}
/**
« no previous file with comments | « no previous file | pkg/analyzer/tool/task_dependency_graph/check_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698