Index: bin/debug_info.dart |
diff --git a/bin/debug_info.dart b/bin/debug_info.dart |
index 1c34ccad63f953463e0690a813940be6ce5c3b10..198eefa344c766ca975b3a1d1930f5b845880061 100644 |
--- a/bin/debug_info.dart |
+++ b/bin/debug_info.dart |
@@ -11,6 +11,7 @@ import 'dart:io'; |
import 'package:dart2js_info/info.dart'; |
import 'package:dart2js_info/src/graph.dart'; |
+import 'package:dart2js_info/src/util.dart'; |
main(args) { |
if (args.length < 1) { |
@@ -28,6 +29,18 @@ main(args) { |
debugLibName = args[2]; |
} |
+ // Validate that codesize of elements adds up to total codesize. |
Siggi Cherem (dart-lang)
2015/10/21 23:05:31
nit: let's move these comments down below as dart-
Harry Terkelsen
2015/10/21 23:07:44
Done.
|
+ validateSize(info, debugLibName); |
+ |
+ // Validate that both forms of dependency information match. |
+ compareGraphs(info); |
+ |
+ // Validate that all elements are reachable from `main` in the dependency |
+ // graph. |
+ verifyDeps(info); |
+} |
+ |
+validateSize(AllInfo info, String debugLibName) { |
// Gather data from visiting all info elements. |
var tracker = new _SizeTracker(debugLibName); |
info.accept(tracker); |
@@ -67,9 +80,6 @@ main(args) { |
var percent = (missingTotal * 100 / realTotal).toStringAsFixed(2); |
_fail('$percent% size missing in libraries (sum of elements > lib.size)'); |
} |
- |
- // Validate dependency data. |
- compareGraphs(info); |
} |
class _SizeTracker extends RecursiveInfoVisitor { |
@@ -258,5 +268,21 @@ void compareGraphs(AllInfo info) { |
} |
} |
+verifyDeps(AllInfo info) { |
+ var graph = graphFromInfo(info); |
+ var entrypoint = info.program.entrypoint; |
+ var reachables = new Set.from(graph.preOrder(entrypoint)); |
+ |
+ var functionsAndFields = []..addAll(info.functions)..addAll(info.fields); |
+ var unreachables = |
+ functionsAndFields.where((func) => !reachables.contains(func)); |
+ if (unreachables.isNotEmpty) { |
+ _fail('${unreachables.length} elements are unreachable from the ' |
+ 'entrypoint'); |
+ } else { |
+ _pass('all elements are reachable from the entrypoint'); |
+ } |
+} |
+ |
_pass(String msg) => print('\x1b[32mPASS\x1b[0m: $msg'); |
_fail(String msg) => print('\x1b[31mFAIL\x1b[0m: $msg'); |