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

Unified Diff: mojo/public/dart/third_party/csslib/lib/src/messages.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
Index: mojo/public/dart/third_party/csslib/lib/src/messages.dart
diff --git a/mojo/public/dart/third_party/csslib/lib/src/messages.dart b/mojo/public/dart/third_party/csslib/lib/src/messages.dart
new file mode 100644
index 0000000000000000000000000000000000000000..595bf6c58ac6a4c2ca296891daa38e13ca54df89
--- /dev/null
+++ b/mojo/public/dart/third_party/csslib/lib/src/messages.dart
@@ -0,0 +1,130 @@
+// Copyright (c) 2012, 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.
+
+library csslib.src.messages;
+
+import 'package:logging/logging.dart' show Level;
+import 'package:source_span/source_span.dart';
+
+import 'options.dart';
+
+// TODO(terry): Remove the global messages, use some object that tracks
+// compilation state.
+
+/** The global [Messages] for tracking info/warnings/messages. */
+Messages messages;
+
+// Color constants used for generating messages.
+final String GREEN_COLOR = '\u001b[32m';
+final String RED_COLOR = '\u001b[31m';
+final String MAGENTA_COLOR = '\u001b[35m';
+final String NO_COLOR = '\u001b[0m';
+
+/** Map between error levels and their display color. */
+final Map<Level, String> _ERROR_COLORS = (() {
+ var colorsMap = new Map<Level, String>();
+ colorsMap[Level.SEVERE] = RED_COLOR;
+ colorsMap[Level.WARNING] = MAGENTA_COLOR;
+ colorsMap[Level.INFO] = GREEN_COLOR;
+ return colorsMap;
+})();
+
+/** Map between error levels and their friendly name. */
+final Map<Level, String> _ERROR_LABEL = (() {
+ var labels = new Map<Level, String>();
+ labels[Level.SEVERE] = 'error';
+ labels[Level.WARNING] = 'warning';
+ labels[Level.INFO] = 'info';
+ return labels;
+})();
+
+/** A single message from the compiler. */
+class Message {
+ final Level level;
+ final String message;
+ final SourceSpan span;
+ final bool useColors;
+
+ Message(this.level, this.message, {SourceSpan span, bool useColors: false})
+ : this.span = span,
+ this.useColors = useColors;
+
+ String toString() {
+ var output = new StringBuffer();
+ bool colors = useColors && _ERROR_COLORS.containsKey(level);
+ var levelColor = colors ? _ERROR_COLORS[level] : null;
+ if (colors) output.write(levelColor);
+ output
+ ..write(_ERROR_LABEL[level])
+ ..write(' ');
+ if (colors) output.write(NO_COLOR);
+
+ if (span == null) {
+ output.write(message);
+ } else {
+ output.write('on ');
+ output.write(span.message(message, color: levelColor));
+ }
+
+ return output.toString();
+ }
+}
+
+typedef void PrintHandler(Message obj);
+
+/**
+ * This class tracks and prints information, warnings, and errors emitted by the
+ * compiler.
+ */
+class Messages {
+ /** Called on every error. Set to blank function to supress printing. */
+ final PrintHandler printHandler;
+
+ final PreprocessorOptions options;
+
+ final List<Message> messages = <Message>[];
+
+ Messages({PreprocessorOptions options, this.printHandler: print})
+ : options = options != null ? options : new PreprocessorOptions();
+
+ /** Report a compile-time CSS error. */
+ void error(String message, SourceSpan span) {
+ var msg = new Message(Level.SEVERE, message,
+ span: span, useColors: options.useColors);
+
+ messages.add(msg);
+
+ printHandler(msg);
+ }
+
+ /** Report a compile-time CSS warning. */
+ void warning(String message, SourceSpan span) {
+ if (options.warningsAsErrors) {
+ error(message, span);
+ } else {
+ var msg = new Message(Level.WARNING, message,
+ span: span, useColors: options.useColors);
+
+ messages.add(msg);
+ }
+ }
+
+ /** Report and informational message about what the compiler is doing. */
+ void info(String message, SourceSpan span) {
+ var msg = new Message(Level.INFO, message,
+ span: span, useColors: options.useColors);
+
+ messages.add(msg);
+
+ if (options.verbose) printHandler(msg);
+ }
+
+ /** Merge [newMessages] to this message lsit. */
+ void mergeMessages(Messages newMessages) {
+ messages.addAll(newMessages.messages);
+ newMessages.messages
+ .where((message) => message.level == Level.SEVERE || options.verbose)
+ .forEach(printHandler);
+ }
+}
« no previous file with comments | « mojo/public/dart/third_party/csslib/lib/src/css_printer.dart ('k') | mojo/public/dart/third_party/csslib/lib/src/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698