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
This commit is contained in:
parent
ad59e75a56
commit
f18e11074d
|
@ -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",
|
||||
],
|
||||
|
|
13
cc/cc.go
13
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.
|
||||
|
|
|
@ -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"})
|
||||
|
|
|
@ -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...)
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue