aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2017-11-16 14:33:08 -0800
committerColin Cross <ccross@android.com>2017-11-17 11:22:08 -0800
commitf18e11074dc8bd5bd04554b5b088b1d8cc40bc35 (patch)
tree33e7afddedb5a798ab2e1a8788c55d63d942377a
parentad59e75a567f0638bae504543664a57582326a58 (diff)
downloadbuild_soong-f18e11074dc8bd5bd04554b5b088b1d8cc40bc35.tar.gz
build_soong-f18e11074dc8bd5bd04554b5b088b1d8cc40bc35.tar.bz2
build_soong-f18e11074dc8bd5bd04554b5b088b1d8cc40bc35.zip
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
-rw-r--r--Android.bp1
-rw-r--r--cc/cc.go13
-rw-r--r--cc/cc_test.go5
-rw-r--r--cc/compiler.go24
-rw-r--r--cc/gen_test.go63
-rw-r--r--cc/library.go4
-rw-r--r--cc/llndk_library.go4
-rw-r--r--cc/ndk_library.go4
8 files changed, 101 insertions, 17 deletions
diff --git a/Android.bp b/Android.bp
index a69c1ea2..b57b0cc9 100644
--- a/Android.bp
+++ b/Android.bp
@@ -158,6 +158,7 @@ bootstrap_go_package {
],
testSrcs: [
"cc/cc_test.go",
+ "cc/gen_test.go",
"cc/library_test.go",
"cc/test_data_test.go",
],
diff --git a/cc/cc.go b/cc/cc.go
index 86a60c9e..384b2407 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -230,7 +230,7 @@ type feature interface {
type compiler interface {
compilerInit(ctx BaseModuleContext)
compilerDeps(ctx DepsContext, deps Deps) Deps
- compilerFlags(ctx ModuleContext, flags Flags) Flags
+ compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
compilerProps() []interface{}
appendCflags([]string)
@@ -589,12 +589,17 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
}
ctx.ctx = ctx
+ deps := c.depsToPaths(ctx)
+ if ctx.Failed() {
+ return
+ }
+
flags := Flags{
Toolchain: c.toolchain(ctx),
Clang: c.clang(ctx),
}
if c.compiler != nil {
- flags = c.compiler.compilerFlags(ctx, flags)
+ flags = c.compiler.compilerFlags(ctx, flags, deps)
}
if c.linker != nil {
flags = c.linker.linkerFlags(ctx, flags)
@@ -625,10 +630,6 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
- deps := c.depsToPaths(ctx)
- if ctx.Failed() {
- return
- }
flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
c.flags = flags
// We need access to all the flags seen by a source file.
diff --git a/cc/cc_test.go b/cc/cc_test.go
index b451f17c..60c33c2f 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -2,6 +2,8 @@ package cc
import (
"android/soong/android"
+ "android/soong/genrule"
+
"fmt"
"io/ioutil"
"os"
@@ -42,9 +44,11 @@ func testCc(t *testing.T, bp string) *android.TestContext {
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(LibraryFactory))
+ ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(LibrarySharedFactory))
ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(toolchainLibraryFactory))
ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(llndkLibraryFactory))
ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(objectFactory))
+ ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(genrule.FileGroupFactory))
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("image", vendorMutator).Parallel()
ctx.BottomUp("link", linkageMutator).Parallel()
@@ -119,6 +123,7 @@ func testCc(t *testing.T, bp string) *android.TestContext {
"foo.c": nil,
"bar.c": nil,
"a.proto": nil,
+ "b.aidl": nil,
})
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
diff --git a/cc/compiler.go b/cc/compiler.go
index 4112930a..ca68a00a 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -158,8 +158,15 @@ type baseCompiler struct {
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 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
// 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) compilerFlags(ctx ModuleContext, flags Flags) Flag
}
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 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
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...)
diff --git a/cc/gen_test.go b/cc/gen_test.go
new file mode 100644
index 00000000..a0f7308c
--- /dev/null
+++ b/cc/gen_test.go
@@ -0,0 +1,63 @@
+// Copyright 2017 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+import (
+ "testing"
+)
+
+func TestGen(t *testing.T) {
+ t.Run("simple", func(t *testing.T) {
+ ctx := testCc(t, `
+ cc_library_shared {
+ name: "libfoo",
+ srcs: [
+ "foo.c",
+ "b.aidl",
+ ],
+ }`)
+
+ aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl")
+ libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
+
+ if !inList("-I"+aidl.Args["outDir"], libfoo.flags.GlobalFlags) {
+ t.Errorf("missing aidl includes in global flags")
+ }
+ })
+
+ t.Run("filegroup", func(t *testing.T) {
+ ctx := testCc(t, `
+ filegroup {
+ name: "fg",
+ srcs: ["b.aidl"],
+ }
+
+ cc_library_shared {
+ name: "libfoo",
+ srcs: [
+ "foo.c",
+ ":fg",
+ ],
+ }`)
+
+ aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl")
+ libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
+
+ if !inList("-I"+aidl.Args["outDir"], libfoo.flags.GlobalFlags) {
+ t.Errorf("missing aidl includes in global flags")
+ }
+ })
+
+}
diff --git a/cc/library.go b/cc/library.go
index 23e4f44c..192496ad 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -317,7 +317,7 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla
return flags
}
-func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
+func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
if len(exportIncludeDirs) > 0 {
f := includeDirsToFlags(exportIncludeDirs)
@@ -325,7 +325,7 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) F
flags.YasmFlags = append(flags.YasmFlags, f)
}
- return library.baseCompiler.compilerFlags(ctx, flags)
+ return library.baseCompiler.compilerFlags(ctx, flags, deps)
}
func extractExportIncludesFromFlags(flags []string) []string {
diff --git a/cc/llndk_library.go b/cc/llndk_library.go
index 154b3f4f..9a29964d 100644
--- a/cc/llndk_library.go
+++ b/cc/llndk_library.go
@@ -70,8 +70,8 @@ type llndkStubDecorator struct {
versionScriptPath android.ModuleGenPath
}
-func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
- flags = stub.baseCompiler.compilerFlags(ctx, flags)
+func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
+ flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
return addStubLibraryCompilerFlags(flags)
}
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 066fb988..c5175236 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -258,8 +258,8 @@ func addStubLibraryCompilerFlags(flags Flags) Flags {
return flags
}
-func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
- flags = stub.baseCompiler.compilerFlags(ctx, flags)
+func (stub *stubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
+ flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
return addStubLibraryCompilerFlags(flags)
}