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

Side by Side 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: changelog 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// This tools verifies that all elements that are included in the output are
6 /// reachable from the program entrypoint. If there are elements that are not
7 /// reachable from the entrypoint, then this indicates that we are missing
8 /// dependencies. If all functions are reachable from the entrypoint, this
9 /// script will not output anything and return with exitcode 0. Otherwise it
10 /// will list the unreachable functions and return with exitcode 1.
11 library dart2js_info.bin.verify_deps;
12
13 import 'dart:async';
14 import 'dart:convert';
15 import 'dart:io';
16
17 import 'package:dart2js_info/info.dart';
18 import 'package:dart2js_info/src/graph.dart';
19 import 'package:dart2js_info/src/util.dart';
20
21 Future main(List<String> args) async {
22 if (args.length > 1) {
23 printUsage();
24 exit(1);
25 }
26 var json = JSON.decode(await new File(args[0]).readAsString());
27 var info = new AllInfo.fromJson(json);
28 var graph = graphFromInfo(info);
29 var entrypoint = info.program.entrypoint;
30 var reachables = findReachable(graph, entrypoint);
31
32 var unreachables = info.functions.where((func) => !reachables.contains(func));
33 if (unreachables.isNotEmpty) {
34 unreachables.forEach(print);
35 exit(1);
36 }
37 }
38
39 /// Finds the set of nodes reachable from [start] in [graph].
40 Set<Info> findReachable(Graph<Info> graph, Info start) {
41 var visited = new Set<Info>();
42 var stack = <Info>[start];
43 while (stack.isNotEmpty) {
44 var next = stack.removeLast();
45 visited.add(next);
46 stack.addAll(
47 graph.targetsOf(next).where((target) => !visited.contains(target)));
48 }
49 return visited;
50 }
51
52 void printUsage() {
53 print('usage: dart2js_info_verify_deps <info file>');
54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698