Add flag property checking

Some checks for common errors with user-provided compiler and linker
flags:

* Using -I instead of include_dirs
* Using -l<lib> in ldflags instead of host_ldlibs (or shared_libs)
* Using -L in ldflags
* Splitting a multi-word flag into two flags
* Combining two flags into one list entry
* Using a path that could search outside the source or output trees
* Using a non-whitelisted library in host_ldlibs

Maybe some of the flag checks should happen during a static analysis
pass, but we don't have one right now, and this only adds ~1/2 second to
our 73 second Mega_device runs (recompile the changed code, run
soong_build, then report unknown target).

Change-Id: Icea7436260f1caa62c0cec29817a1cfea27b3e7c
diff --git a/cc/cc.go b/cc/cc.go
index 0fa3ca9..a828d10 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1019,6 +1019,11 @@
 func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags {
 	toolchain := ctx.toolchain()
 
+	CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags)
+	CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags)
+	CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags)
+	CheckBadCompilerFlags(ctx, "asflags", compiler.Properties.Asflags)
+
 	flags.CFlags = append(flags.CFlags, compiler.Properties.Cflags...)
 	flags.CppFlags = append(flags.CppFlags, compiler.Properties.Cppflags...)
 	flags.ConlyFlags = append(flags.ConlyFlags, compiler.Properties.Conlyflags...)
@@ -1066,10 +1071,15 @@
 		ctx.ModuleErrorf("%s", err)
 	}
 
+	CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags)
+
 	// TODO: debug
 	flags.CFlags = append(flags.CFlags, compiler.Properties.Release.Cflags...)
 
 	if flags.Clang {
+		CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags)
+		CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags)
+
 		flags.CFlags = clangFilterUnknownCflags(flags.CFlags)
 		flags.CFlags = append(flags.CFlags, compiler.Properties.Clang_cflags...)
 		flags.AsFlags = append(flags.AsFlags, compiler.Properties.Clang_asflags...)
@@ -1268,10 +1278,14 @@
 		}
 
 		if ctx.Host() {
+			CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs)
+
 			flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
 		}
 	}
 
+	CheckBadLinkerFlags(ctx, "ldflags", linker.Properties.Ldflags)
+
 	flags.LdFlags = append(flags.LdFlags, linker.Properties.Ldflags...)
 
 	if ctx.Host() && !linker.static() {