Black-list for clang LibTooling Cflags.

Add a list of flags which are not understood by clang LibTooling tools
and filter them out of the Cflags the tools are invoked with.

Test: In frameworks/av, make libmedia vendor_available (this invokes
header-abi-dumper on this module), mm -j64.

Bug: 62447349

Change-Id: I46f017212b89f4331145c999103d0ed44da0abaf
diff --git a/cc/sabi.go b/cc/sabi.go
index 01ef737..92fc7cf 100644
--- a/cc/sabi.go
+++ b/cc/sabi.go
@@ -15,6 +15,8 @@
 package cc
 
 import (
+	"strings"
+
 	"android/soong/android"
 	"github.com/google/blueprint"
 
@@ -40,7 +42,31 @@
 	return deps
 }
 
+func inListWithPrefixSearch(flag string, filter []string) bool {
+	// Assuming the filter is small enough.
+	// If the suffix of a filter element is *, try matching prefixes as well.
+	for _, f := range filter {
+		if (f == flag) || (strings.HasSuffix(f, "*") && strings.HasPrefix(flag, strings.TrimSuffix(f, "*"))) {
+			return true
+		}
+	}
+	return false
+}
+
+func filterOutWithPrefix(list []string, filter []string) (remainder []string) {
+	// Go through the filter, matching and optionally doing a prefix search for list elements.
+	for _, l := range list {
+		if !inListWithPrefixSearch(l, filter) {
+			remainder = append(remainder, l)
+		}
+	}
+	return
+}
+
 func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
+	// Assuming that the cflags which clang LibTooling tools cannot
+	// understand have not been converted to ninja variables yet.
+	flags.ToolingCFlags = filterOutWithPrefix(flags.CFlags, config.ClangLibToolingUnknownCflags)
 	return flags
 }