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

Side by Side Diff: utils/tests/pub/command_line_config.dart

Issue 12087008: Handle parsing the "version" file better. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « utils/pub/sdk.dart ('k') | utils/tests/pub/pub_test.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library command_line_config; 5 library command_line_config;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import '../../../pkg/path/lib/path.dart' as path;
9 import '../../../pkg/unittest/lib/unittest.dart'; 10 import '../../../pkg/unittest/lib/unittest.dart';
10 import '../../pub/utils.dart'; 11 import '../../pub/utils.dart';
11 12
12 const _GREEN = '\u001b[32m'; 13 const _GREEN = '\u001b[32m';
13 const _RED = '\u001b[31m'; 14 const _RED = '\u001b[31m';
14 const _MAGENTA = '\u001b[35m'; 15 const _MAGENTA = '\u001b[35m';
15 const _NONE = '\u001b[0m'; 16 const _NONE = '\u001b[0m';
16 17
17 /// Pretty Unicode characters! 18 /// Pretty Unicode characters!
18 const _CHECKBOX = '\u2713'; 19 const _CHECKBOX = '\u2713';
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 64 }
64 } 65 }
65 66
66 void onDone(bool success) { 67 void onDone(bool success) {
67 if (!success) exit(1); 68 if (!success) exit(1);
68 } 69 }
69 70
70 void _printStackTrace(String stackTrace) { 71 void _printStackTrace(String stackTrace) {
71 if (stackTrace == null || stackTrace == '') return; 72 if (stackTrace == null || stackTrace == '') return;
72 73
74 print('');
75
73 // Parse out each stack entry. 76 // Parse out each stack entry.
74 var stack = []; 77 var stack = [];
75 for (var line in stackTrace.split('\n')) { 78 for (var line in stackTrace.split('\n')) {
76 if (line.trim() == '') continue; 79 if (line.trim() == '') continue;
77 stack.add(new _StackFrame(line)); 80 stack.add(new _StackFrame(line));
78 } 81 }
79 82
80 if (stack.length == 0) return; 83 if (stack.length == 0) return;
81 84
82 // Find the common prefixes of the paths.
83 var common = 0;
84 while (true) {
85 var matching = true;
86 var c;
87 for (var frame in stack) {
88 if (frame.isCore) continue;
89 if (c == null) c = frame.library[common];
90
91 if (frame.library.length <= common || frame.library[common] != c) {
92 matching = false;
93 break;
94 }
95 }
96
97 if (!matching) break;
98 common++;
99 }
100
101 // Remove them.
102 if (common > 0) {
103 for (var frame in stack) {
104 if (frame.isCore) continue;
105 frame.library = frame.library.substring(common);
106 }
107 }
108
109 // Figure out the longest path so we know how much to pad. 85 // Figure out the longest path so we know how much to pad.
110 int longest = stack.mappedBy((frame) => frame.location.length).max(); 86 int longest = stack.mappedBy((frame) => frame.location.length).max();
111 87
112 // Print out the stack trace nicely formatted. 88 // Print out the stack trace nicely formatted.
113 for (var frame in stack) { 89 for (var frame in stack) {
114 print(' ${_padLeft(frame.location, longest)} ${frame.member}'); 90 print(' ${_padLeft(frame.location, longest)} ${frame.member}');
115 } 91 }
116 92
117 print(''); 93 print('');
118 } 94 }
(...skipping 12 matching lines...) Expand all
131 107
132 String _indent(String str) { 108 String _indent(String str) {
133 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. 109 // TODO(nweiz): Use this simpler code once issue 2980 is fixed.
134 // return str.replaceAll(new RegExp("^", multiLine: true), " "); 110 // return str.replaceAll(new RegExp("^", multiLine: true), " ");
135 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n"); 111 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n");
136 } 112 }
137 } 113 }
138 114
139 class _StackFrame { 115 class _StackFrame {
140 static final fileRegExp = new RegExp( 116 static final fileRegExp = new RegExp(
141 r'#\d+\s+(.*) \((file:///.+):(\d+):(\d+)\)'); 117 r'#\d+\s+(.*) \(file://(/.+):(\d+):(\d+)\)');
142 static final coreRegExp = new RegExp(r'#\d+\s+(.*) \((.+):(\d+):(\d+)\)'); 118 static final coreRegExp = new RegExp(r'#\d+\s+(.*) \((.+):(\d+):(\d+)\)');
143 119
144 /// If `true`, then this stack frame is for a library built into Dart and 120 /// If `true`, then this stack frame is for a library built into Dart and
145 /// not a regular file path. 121 /// not a regular file path.
146 final bool isCore; 122 final bool isCore;
147 123
148 /// The path to the library or the library name if a core library. 124 /// The path to the library or the library name if a core library.
149 String library; 125 String library;
150 126
151 /// The line number. 127 /// The line number.
(...skipping 13 matching lines...) Expand all
165 factory _StackFrame(String text) { 141 factory _StackFrame(String text) {
166 var match = fileRegExp.firstMatch(text); 142 var match = fileRegExp.firstMatch(text);
167 var isCore = false; 143 var isCore = false;
168 144
169 if (match == null) { 145 if (match == null) {
170 match = coreRegExp.firstMatch(text); 146 match = coreRegExp.firstMatch(text);
171 if (match == null) throw "Couldn't parse stack trace line '$text'."; 147 if (match == null) throw "Couldn't parse stack trace line '$text'.";
172 isCore = true; 148 isCore = true;
173 } 149 }
174 150
151 var library = match[2];
152 if (!isCore) {
153 // Make the library path relative to the entrypoint.
154 library = path.relative(library);
155 }
156
175 var member = match[1].replaceAll("<anonymous closure>", _LAMBDA); 157 var member = match[1].replaceAll("<anonymous closure>", _LAMBDA);
176 return new _StackFrame._(isCore, match[2], match[3], match[4], member); 158 return new _StackFrame._(isCore, library, match[3], match[4], member);
177 } 159 }
178 } 160 }
OLDNEW
« no previous file with comments | « utils/pub/sdk.dart ('k') | utils/tests/pub/pub_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698