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

Unified Diff: bin/verify_deps.dart

Issue 1406803003: add tool to verify dependency information (Closed) Base URL: git@github.com:hterkelsen/dart2js_info.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 | « bin/live_code_size_analysis.dart ('k') | lib/info.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/verify_deps.dart
diff --git a/bin/verify_deps.dart b/bin/verify_deps.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3da8ece9da39767e7e7d7a1b44b9104e2bc3f11b
--- /dev/null
+++ b/bin/verify_deps.dart
@@ -0,0 +1,56 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// This tools verifies that all elements that are included in the output are
+/// reachable from the program entrypoint. If there are elements that are not
+/// reachable from the entrypoint, then this indicates that we are missing
+/// dependencies. If all functions are reachable from the entrypoint, this
+/// script will return with exitcode 0. Otherwise it will list the unreachable
+/// functions and return with exitcode 1.
+library dart2js_info.bin.verify_deps;
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:dart2js_info/info.dart';
+import 'package:dart2js_info/src/graph.dart';
+import 'package:dart2js_info/src/util.dart';
+
+Future main(List<String> args) async {
+ if (args.length > 1) {
+ printUsage();
+ exit(1);
+ }
+ var json = JSON.decode(await new File(args[0]).readAsString());
+ var info = new AllInfo.fromJson(json);
+ var graph = graphFromInfo(info);
+ var entrypoint = info.program.entrypoint;
+ var reachables = findReachable(graph, entrypoint);
+
+ var unreachables = info.functions.where((func) => !reachables.contains(func));
+ if (unreachables.isNotEmpty) {
+ unreachables.forEach(print);
+ exit(1);
+ } else {
+ print('all elements are reachable from the entrypoint');
+ }
+}
+
+/// Finds the set of nodes reachable from [start] in [graph].
+Set<Info> findReachable(Graph<Info> graph, Info start) {
+ var visited = new Set<Info>();
+ var stack = <Info>[start];
+ while (stack.isNotEmpty) {
+ var next = stack.removeLast();
+ visited.add(next);
+ stack.addAll(
+ graph.targetsOf(next).where((target) => !visited.contains(target)));
+ }
+ return visited;
+}
+
+void printUsage() {
+ print('usage: dart2js_info_verify_deps <info file>');
+}
« no previous file with comments | « bin/live_code_size_analysis.dart ('k') | lib/info.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698