Filter products during compile phase

Unfortunately there is no good way to deal with products in the link phase.
Products are like preprocessor defines in that they are processed early
and change the composition of the compiled unit.

Change-Id: I6d5e15ef60d29df8e83e059ba857c09333993779
diff --git a/tools/aapt2/Diagnostics.h b/tools/aapt2/Diagnostics.h
index d20ae1b..7ea26b3 100644
--- a/tools/aapt2/Diagnostics.h
+++ b/tools/aapt2/Diagnostics.h
@@ -51,12 +51,6 @@
         mMessage << value;
         return *this;
     }
-/*
-    template <typename T> DiagMessage& operator<<(
-            const ::std::function<::std::ostream&(::std::ostream&)>& f) {
-        f(mMessage);
-        return *this;
-    }*/
 
     DiagMessageActual build() const {
         return DiagMessageActual{ mSource, mMessage.str() };
@@ -72,6 +66,8 @@
 };
 
 struct StdErrDiagnostics : public IDiagnostics {
+    size_t mNumErrors = 0;
+
     void emit(const DiagMessage& msg, const char* tag) {
         DiagMessageActual actual = msg.build();
         if (!actual.source.path.empty()) {
@@ -81,7 +77,10 @@
     }
 
     void error(const DiagMessage& msg) override {
-        emit(msg, "error: ");
+        if (mNumErrors < 20) {
+            emit(msg, "error: ");
+        }
+        mNumErrors++;
     }
 
     void warn(const DiagMessage& msg) override {