| OLD | NEW |
| (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 /// Visualization of source mappings generated and tested in |
| 6 /// 'source_mapping_test.dart'. |
| 7 |
| 8 library source_mapping.test.viewer; |
| 9 |
| 10 import 'dart:async'; |
| 11 import 'package:compiler/src/filenames.dart'; |
| 12 import 'package:compiler/src/util/util.dart'; |
| 13 import 'source_mapping_test.dart'; |
| 14 import 'sourcemap_helper.dart'; |
| 15 import 'sourcemap_html_helper.dart'; |
| 16 import 'sourcemap_html_templates.dart'; |
| 17 |
| 18 const String DEFAULT_OUTPUT_PATH = 'out.js.map.html'; |
| 19 |
| 20 main(List<String> arguments) async { |
| 21 bool measure = false; |
| 22 String outputPath = DEFAULT_OUTPUT_PATH; |
| 23 Set<String> configurations = new Set<String>(); |
| 24 Set<String> files = new Set<String>(); |
| 25 for (String argument in arguments) { |
| 26 if (argument.startsWith('-')) { |
| 27 if (argument == '-m') { |
| 28 /// Measure instead of reporting the number of missing code points. |
| 29 measure = true; |
| 30 } else if (argument.startsWith('--out=')) { |
| 31 /// Generate visualization for the first configuration. |
| 32 outputPath = argument.substring('--out='.length); |
| 33 |
| 34 } else if (argument.startsWith('-o')) { |
| 35 /// Generate visualization for the first configuration. |
| 36 outputPath = argument.substring('-o'.length); |
| 37 } else { |
| 38 print("Unknown option '$argument'."); |
| 39 return; |
| 40 } |
| 41 } else { |
| 42 if (!parseArgument(argument, configurations, files)) { |
| 43 return; |
| 44 } |
| 45 } |
| 46 } |
| 47 |
| 48 if (configurations.isEmpty) { |
| 49 configurations.addAll(TEST_CONFIGURATIONS.keys); |
| 50 if (!measure) { |
| 51 configurations.remove('old'); |
| 52 } |
| 53 } |
| 54 if (files.isEmpty) { |
| 55 files.addAll(TEST_FILES.keys); |
| 56 } |
| 57 |
| 58 OutputConfigurations outputConfigurations = |
| 59 new OutputConfigurations(configurations, files); |
| 60 bool generateMultiConfigs = false; |
| 61 if (outputPath != null) { |
| 62 if (configurations.length > 1 || files.length > 1) { |
| 63 for (String config in configurations) { |
| 64 for (String file in files) { |
| 65 String path = '$outputPath.$config.$file'; |
| 66 Uri uri = Uri.base.resolve(nativeToUriPath(path)); |
| 67 outputConfigurations.registerPathUri(config, file, path, uri); |
| 68 } |
| 69 } |
| 70 generateMultiConfigs = true; |
| 71 } else { |
| 72 outputConfigurations.registerPathUri( |
| 73 configurations.first, |
| 74 files.first, |
| 75 outputPath, |
| 76 Uri.base.resolve(nativeToUriPath(outputPath))); |
| 77 } |
| 78 } |
| 79 |
| 80 List<Measurement> measurements = <Measurement>[]; |
| 81 for (String config in configurations) { |
| 82 List<String> options = TEST_CONFIGURATIONS[config]; |
| 83 for (String file in files) { |
| 84 Measurement measurement = await runTest( |
| 85 config, TEST_FILES[file], options, |
| 86 outputUri: outputConfigurations.getUri(config, file), |
| 87 verbose: !measure); |
| 88 measurements.add(measurement); |
| 89 } |
| 90 } |
| 91 for (Measurement measurement in measurements) { |
| 92 print(measurement); |
| 93 } |
| 94 if (generateMultiConfigs) { |
| 95 outputMultiConfigs( |
| 96 Uri.base.resolve(outputPath), |
| 97 outputConfigurations); |
| 98 } |
| 99 } |
| 100 |
| 101 class OutputConfigurations implements Configurations { |
| 102 final Iterable<String> configs; |
| 103 final Iterable<String> files; |
| 104 final Map<Pair, String> pathMap = {}; |
| 105 final Map<Pair, Uri> uriMap = {}; |
| 106 |
| 107 OutputConfigurations(this.configs, this.files); |
| 108 |
| 109 void registerPathUri(String config, String file, String path, Uri uri) { |
| 110 Pair key = new Pair(config, file); |
| 111 pathMap[key] = path; |
| 112 uriMap[key] = uri; |
| 113 } |
| 114 |
| 115 Uri getUri(String config, String file) { |
| 116 Pair key = new Pair(config, file); |
| 117 return uriMap[key]; |
| 118 } |
| 119 |
| 120 @override |
| 121 String getPath(String config, String file) { |
| 122 Pair key = new Pair(config, file); |
| 123 return pathMap[key]; |
| 124 } |
| 125 } |
| 126 |
| 127 Future<Measurement> runTest( |
| 128 String config, |
| 129 String filename, |
| 130 List<String> options, |
| 131 {Uri outputUri, |
| 132 bool verbose}) async { |
| 133 TestResult result = |
| 134 await runTests(config, filename, options, verbose: verbose); |
| 135 if (outputUri != null) { |
| 136 if (result.failureMap.isNotEmpty) { |
| 137 result.failureMap.forEach((info, missingCodePoints) { |
| 138 print("Missing code points for ${info.element} in '$filename' " |
| 139 "in config '$config':"); |
| 140 for (CodePoint codePoint in missingCodePoints) { |
| 141 print(" $codePoint"); |
| 142 } |
| 143 }); |
| 144 } |
| 145 createTraceSourceMapHtml(outputUri, result.processor, result.userInfoList); |
| 146 } |
| 147 return new Measurement(config, filename, |
| 148 result.failureMap.values.fold(0, (s, i) => s + i.length), |
| 149 result.userInfoList.fold(0, (s, i) => s + i.codePoints.length)); |
| 150 } |
| 151 |
| 152 class Measurement { |
| 153 final String config; |
| 154 final String filename; |
| 155 |
| 156 final int missing; |
| 157 final int count; |
| 158 |
| 159 Measurement(this.config, this.filename, this.missing, this.count); |
| 160 |
| 161 String toString() { |
| 162 double percentage = 100 * missing / count; |
| 163 return "Config '${config}', file: '${filename}': " |
| 164 "$missing of $count ($percentage%) missing"; |
| 165 } |
| 166 } |
| OLD | NEW |