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

Side by Side Diff: bin/deferred_library_check.dart

Issue 1411153009: move deferred_library_check functionality to a library (Closed) Base URL: git@github.com:dart-lang/dart2js_info.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « CHANGELOG.md ('k') | lib/deferred_library_check.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// A command-line tool that verifies that deferred libraries split the code as 5 /// A command-line tool that verifies that deferred libraries split the code as
6 /// expected. 6 /// expected.
7 /// This tool checks that the output from dart2js meets a given specification, 7 /// This tool checks that the output from dart2js meets a given specification,
8 /// given in a YAML file. The format of the YAML file is: 8 /// given in a YAML file. The format of the YAML file is:
9 /// 9 ///
10 /// main: 10 /// main:
(...skipping 22 matching lines...) Expand all
33 /// The names for parts given in the specification YAML file (besides "main") 33 /// The names for parts given in the specification YAML file (besides "main")
34 /// are arbitrary and just used for reporting when the output does not meet the 34 /// are arbitrary and just used for reporting when the output does not meet the
35 /// specification. 35 /// specification.
36 library dart2js_info.bin.deferred_library_check; 36 library dart2js_info.bin.deferred_library_check;
37 37
38 import 'dart:async'; 38 import 'dart:async';
39 import 'dart:convert'; 39 import 'dart:convert';
40 import 'dart:io'; 40 import 'dart:io';
41 41
42 import 'package:dart2js_info/info.dart'; 42 import 'package:dart2js_info/info.dart';
43 import 'package:quiver/collection.dart'; 43 import 'package:dart2js_info/deferred_library_check.dart';
44 import 'package:yaml/yaml.dart'; 44 import 'package:yaml/yaml.dart';
45 45
46 Future main(List<String> args) async { 46 Future main(List<String> args) async {
47 if (args.length < 2) { 47 if (args.length < 2) {
48 usage(); 48 usage();
49 exit(1); 49 exit(1);
50 } 50 }
51 var info = await infoFromFile(args[0]); 51 var info = await infoFromFile(args[0]);
52 var manifest = await manifestFromFile(args[1]); 52 var manifest = await manifestFromFile(args[1]);
53 53
54 // For each part in the manifest, record the expected "packages" for that 54 var failures = checkDeferredLibraryManifest(info, manifest);
55 // part. 55 failures.forEach(print);
56 var packages = <String, String>{}; 56 if (failures.isNotEmpty) exitCode = 1;
57 for (var part in manifest.keys) {
58 for (var package in manifest[part]['packages']) {
59 if (packages.containsKey(package)) {
60 print('You cannot specify that package "$package" maps to both parts '
61 '"$part" and "${packages[package]}".');
62 exit(1);
63 }
64 packages[package] = part;
65 }
66 }
67
68 var guessedPartMapping = new BiMap<String, String>();
69 guessedPartMapping['main'] = 'main';
70
71 bool anyFailed = false;
72
73 checkInfo(BasicInfo info) {
74 var lib = getLibraryOf(info);
75 if (lib != null && isPackageUri(lib.uri)) {
76 var packageName = getPackageName(lib.uri);
77 var outputUnitName = info.outputUnit.name;
78 var expectedPart;
79 if (packages.containsKey(packageName)) {
80 expectedPart = packages[packageName];
81 } else {
82 expectedPart = 'main';
83 }
84 var expectedOutputUnit = guessedPartMapping[expectedPart];
85 if (expectedOutputUnit == null) {
86 guessedPartMapping[expectedPart] = outputUnitName;
87 } else {
88 if (expectedOutputUnit != outputUnitName) {
89 // TODO(het): add options for how to treat unspecified packages
90 if (!packages.containsKey(packageName)) {
91 print('"${info.name}" from package "$packageName" was not declared '
92 'to be in an explicit part but was not in the main part');
93 } else {
94 var actualPart = guessedPartMapping.inverse[outputUnitName];
95 print('"${info.name}" from package "$packageName" was specified to '
96 'be in part $expectedPart but is in part $actualPart');
97 }
98 anyFailed = true;
99 }
100 }
101 }
102 }
103
104 info.functions.forEach(checkInfo);
105 info.fields.forEach(checkInfo);
106 if (anyFailed) {
107 print('The dart2js output did not meet the specification.');
108 } else {
109 print('The dart2js output meets the specification');
110 }
111 }
112
113 LibraryInfo getLibraryOf(Info info) {
114 var current = info;
115 while (current is! LibraryInfo) {
116 if (current == null) {
117 return null;
118 }
119 current = current.parent;
120 }
121 return current;
122 }
123
124 bool isPackageUri(Uri uri) => uri.scheme == 'package';
125
126 String getPackageName(Uri uri) {
127 assert(isPackageUri(uri));
128 return uri.pathSegments.first;
129 } 57 }
130 58
131 Future<AllInfo> infoFromFile(String fileName) async { 59 Future<AllInfo> infoFromFile(String fileName) async {
132 var file = await new File(fileName).readAsString(); 60 var file = await new File(fileName).readAsString();
133 return new AllInfoJsonCodec().decode(JSON.decode(file)); 61 return new AllInfoJsonCodec().decode(JSON.decode(file));
134 } 62 }
135 63
136 Future manifestFromFile(String fileName) async { 64 Future manifestFromFile(String fileName) async {
137 var file = await new File(fileName).readAsString(); 65 var file = await new File(fileName).readAsString();
138 return loadYaml(file); 66 return loadYaml(file);
139 } 67 }
140 68
141 void usage() { 69 void usage() {
142 print(''' 70 print('''
143 usage: dart2js_info_deferred_library_check dump.info.json manifest.yaml'''); 71 usage: dart2js_info_deferred_library_check dump.info.json manifest.yaml''');
144 } 72 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | lib/deferred_library_check.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698