Fix using aidl files from filegroups

Compute sources including from filegroup and genrule dependencies
before determining if any sources will cause flags to be added.

Test: gen_test.go
Change-Id: I0434b003bbda07a58bb2ce1a0a72997918c8fae2
diff --git a/cc/compiler.go b/cc/compiler.go
index 4112930..ca68a00 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -158,8 +158,15 @@
 	Properties BaseCompilerProperties
 	Proto      android.ProtoProperties
 	deps       android.Paths
-	srcs       android.Paths
 	flags      builderFlags
+
+	// Sources that were passed to the C/C++ compiler
+	srcs android.Paths
+
+	// Sources that were passed in the Android.bp file, including generated sources generated by
+	// other modules and filegroups. May include source files that have not yet been translated to
+	// C/C++ (.aidl, .proto, etc.)
+	srcsBeforeGen android.Paths
 }
 
 var _ compiler = (*baseCompiler)(nil)
@@ -201,9 +208,12 @@
 
 // Create a Flags struct that collects the compile flags from global values,
 // per-target values, module type values, and per-module Blueprints properties
-func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
+func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
 	tc := ctx.toolchain()
 
+	compiler.srcsBeforeGen = ctx.ExpandSources(compiler.Properties.Srcs, compiler.Properties.Exclude_srcs)
+	compiler.srcsBeforeGen = append(compiler.srcsBeforeGen, deps.GeneratedSources...)
+
 	CheckBadCompilerFlags(ctx, "cflags", compiler.Properties.Cflags)
 	CheckBadCompilerFlags(ctx, "cppflags", compiler.Properties.Cppflags)
 	CheckBadCompilerFlags(ctx, "conlyflags", compiler.Properties.Conlyflags)
@@ -458,6 +468,11 @@
 }
 
 func (compiler *baseCompiler) hasSrcExt(ext string) bool {
+	for _, src := range compiler.srcsBeforeGen {
+		if src.Ext() == ext {
+			return true
+		}
+	}
 	for _, src := range compiler.Properties.Srcs {
 		if filepath.Ext(src) == ext {
 			return true
@@ -487,11 +502,10 @@
 	pathDeps := deps.GeneratedHeaders
 	pathDeps = append(pathDeps, ndkPathDeps(ctx)...)
 
-	srcs := ctx.ExpandSources(compiler.Properties.Srcs, compiler.Properties.Exclude_srcs)
-	srcs = append(srcs, deps.GeneratedSources...)
-
 	buildFlags := flagsToBuilderFlags(flags)
 
+	srcs := append(android.Paths(nil), compiler.srcsBeforeGen...)
+
 	srcs, genDeps := genSources(ctx, srcs, buildFlags)
 
 	pathDeps = append(pathDeps, genDeps...)