Add cc_genrule
cc_genrule is the same as a normal genrule, but can depend on other cc modules (like cc_object). Test: mmma external/minijail Change-Id: I8df87665c7bdc76ce89c92755c054f967a818e57
This commit is contained in:
parent
0c16293821
commit
3e5bdf29ba
|
@ -150,6 +150,8 @@ bootstrap_go_package {
|
||||||
"cc/llndk_library.go",
|
"cc/llndk_library.go",
|
||||||
|
|
||||||
"cc/kernel_headers.go",
|
"cc/kernel_headers.go",
|
||||||
|
|
||||||
|
"cc/genrule.go",
|
||||||
],
|
],
|
||||||
testSrcs: [
|
testSrcs: [
|
||||||
"cc/cc_test.go",
|
"cc/cc_test.go",
|
||||||
|
|
|
@ -89,7 +89,7 @@ func (c *Module) AndroidMk() android.AndroidMkData {
|
||||||
}
|
}
|
||||||
c.subAndroidMk(&ret, c.installer)
|
c.subAndroidMk(&ret, c.installer)
|
||||||
|
|
||||||
if c.vndk() && Bool(c.Properties.Vendor_available) {
|
if c.vndk() && Bool(c.VendorProperties.Vendor_available) {
|
||||||
// .vendor suffix is added only when we will have two variants: core and vendor.
|
// .vendor suffix is added only when we will have two variants: core and vendor.
|
||||||
// The suffix is not added for vendor-only module.
|
// The suffix is not added for vendor-only module.
|
||||||
ret.SubName += vendorSuffix
|
ret.SubName += vendorSuffix
|
||||||
|
|
51
cc/cc.go
51
cc/cc.go
|
@ -154,6 +154,14 @@ type BaseProperties struct {
|
||||||
// cppflags, conlyflags, ldflags, or include_dirs
|
// cppflags, conlyflags, ldflags, or include_dirs
|
||||||
No_default_compiler_flags *bool
|
No_default_compiler_flags *bool
|
||||||
|
|
||||||
|
AndroidMkSharedLibs []string `blueprint:"mutated"`
|
||||||
|
HideFromMake bool `blueprint:"mutated"`
|
||||||
|
PreventInstall bool `blueprint:"mutated"`
|
||||||
|
|
||||||
|
UseVndk bool `blueprint:"mutated"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type VendorProperties struct {
|
||||||
// whether this module should be allowed to install onto /vendor as
|
// whether this module should be allowed to install onto /vendor as
|
||||||
// well as /system. The two variants will be built separately, one
|
// well as /system. The two variants will be built separately, one
|
||||||
// like normal, and the other limited to the set of libraries and
|
// like normal, and the other limited to the set of libraries and
|
||||||
|
@ -166,12 +174,6 @@ type BaseProperties struct {
|
||||||
//
|
//
|
||||||
// Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
|
// Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
|
||||||
Vendor_available *bool
|
Vendor_available *bool
|
||||||
|
|
||||||
AndroidMkSharedLibs []string `blueprint:"mutated"`
|
|
||||||
HideFromMake bool `blueprint:"mutated"`
|
|
||||||
PreventInstall bool `blueprint:"mutated"`
|
|
||||||
|
|
||||||
UseVndk bool `blueprint:"mutated"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UnusedProperties struct {
|
type UnusedProperties struct {
|
||||||
|
@ -281,8 +283,9 @@ type Module struct {
|
||||||
android.ModuleBase
|
android.ModuleBase
|
||||||
android.DefaultableModuleBase
|
android.DefaultableModuleBase
|
||||||
|
|
||||||
Properties BaseProperties
|
Properties BaseProperties
|
||||||
unused UnusedProperties
|
VendorProperties VendorProperties
|
||||||
|
unused UnusedProperties
|
||||||
|
|
||||||
// initialize before calling Init
|
// initialize before calling Init
|
||||||
hod android.HostOrDeviceSupported
|
hod android.HostOrDeviceSupported
|
||||||
|
@ -313,7 +316,7 @@ type Module struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Module) Init() android.Module {
|
func (c *Module) Init() android.Module {
|
||||||
c.AddProperties(&c.Properties, &c.unused)
|
c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
|
||||||
if c.compiler != nil {
|
if c.compiler != nil {
|
||||||
c.AddProperties(c.compiler.compilerProps()...)
|
c.AddProperties(c.compiler.compilerProps()...)
|
||||||
}
|
}
|
||||||
|
@ -1127,7 +1130,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||||
libName := strings.TrimSuffix(name, llndkLibrarySuffix)
|
libName := strings.TrimSuffix(name, llndkLibrarySuffix)
|
||||||
libName = strings.TrimPrefix(libName, "prebuilt_")
|
libName = strings.TrimPrefix(libName, "prebuilt_")
|
||||||
isLLndk := inList(libName, llndkLibraries)
|
isLLndk := inList(libName, llndkLibraries)
|
||||||
if c.vndk() && (Bool(cc.Properties.Vendor_available) || isLLndk) {
|
if c.vndk() && (Bool(cc.VendorProperties.Vendor_available) || isLLndk) {
|
||||||
libName += vendorSuffix
|
libName += vendorSuffix
|
||||||
}
|
}
|
||||||
// Note: the order of libs in this list is not important because
|
// Note: the order of libs in this list is not important because
|
||||||
|
@ -1178,6 +1181,13 @@ func (c *Module) IntermPathForModuleOut() android.OptionalPath {
|
||||||
return c.outputFile
|
return c.outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Module) Srcs() android.Paths {
|
||||||
|
if c.outputFile.Valid() {
|
||||||
|
return android.Paths{c.outputFile.Path()}
|
||||||
|
}
|
||||||
|
return android.Paths{}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Defaults
|
// Defaults
|
||||||
//
|
//
|
||||||
|
@ -1202,6 +1212,7 @@ func DefaultsFactory(props ...interface{}) android.Module {
|
||||||
module.AddProperties(props...)
|
module.AddProperties(props...)
|
||||||
module.AddProperties(
|
module.AddProperties(
|
||||||
&BaseProperties{},
|
&BaseProperties{},
|
||||||
|
&VendorProperties{},
|
||||||
&BaseCompilerProperties{},
|
&BaseCompilerProperties{},
|
||||||
&BaseLinkerProperties{},
|
&BaseLinkerProperties{},
|
||||||
&LibraryProperties{},
|
&LibraryProperties{},
|
||||||
|
@ -1241,19 +1252,33 @@ func vendorMutator(mctx android.BottomUpMutatorContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if genrule, ok := mctx.Module().(*genrule.Module); ok {
|
||||||
|
if props, ok := genrule.Extra.(*VendorProperties); ok {
|
||||||
|
if !mctx.DeviceConfig().CompileVndk() {
|
||||||
|
mctx.CreateVariations(coreMode)
|
||||||
|
} else if Bool(props.Vendor_available) {
|
||||||
|
mctx.CreateVariations(coreMode, vendorMode)
|
||||||
|
} else if mctx.Vendor() {
|
||||||
|
mctx.CreateVariations(vendorMode)
|
||||||
|
} else {
|
||||||
|
mctx.CreateVariations(coreMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m, ok := mctx.Module().(*Module)
|
m, ok := mctx.Module().(*Module)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
|
if Bool(m.VendorProperties.Vendor_available) && mctx.Vendor() {
|
||||||
mctx.PropertyErrorf("vendor_available",
|
mctx.PropertyErrorf("vendor_available",
|
||||||
"doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
|
"doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if vndk := m.vndkdep; vndk != nil {
|
if vndk := m.vndkdep; vndk != nil {
|
||||||
if vndk.isVndk() && !Bool(m.Properties.Vendor_available) {
|
if vndk.isVndk() && !Bool(m.VendorProperties.Vendor_available) {
|
||||||
mctx.PropertyErrorf("vndk",
|
mctx.PropertyErrorf("vndk",
|
||||||
"has to define `vendor_available: true` to enable vndk")
|
"has to define `vendor_available: true` to enable vndk")
|
||||||
return
|
return
|
||||||
|
@ -1273,7 +1298,7 @@ func vendorMutator(mctx android.BottomUpMutatorContext) {
|
||||||
// LL-NDK stubs only exist in the vendor variant, since the
|
// LL-NDK stubs only exist in the vendor variant, since the
|
||||||
// real libraries will be used in the core variant.
|
// real libraries will be used in the core variant.
|
||||||
mctx.CreateVariations(vendorMode)
|
mctx.CreateVariations(vendorMode)
|
||||||
} else if Bool(m.Properties.Vendor_available) {
|
} else if Bool(m.VendorProperties.Vendor_available) {
|
||||||
// This will be available in both /system and /vendor
|
// This will be available in both /system and /vendor
|
||||||
// or a /system directory that is available to vendor.
|
// or a /system directory that is available to vendor.
|
||||||
mod := mctx.CreateVariations(coreMode, vendorMode)
|
mod := mctx.CreateVariations(coreMode, vendorMode)
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
// 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 (
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/genrule"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
android.RegisterModuleType("cc_genrule", genRuleFactory)
|
||||||
|
}
|
||||||
|
|
||||||
|
// cc_genrule is a genrule that can depend on other cc_* objects.
|
||||||
|
// The cmd may be run multiple times, once for each of the different arch/etc
|
||||||
|
// variations.
|
||||||
|
func genRuleFactory() android.Module {
|
||||||
|
module := genrule.NewGenRule()
|
||||||
|
|
||||||
|
module.Extra = &VendorProperties{}
|
||||||
|
module.AddProperties(module.Extra)
|
||||||
|
|
||||||
|
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth)
|
||||||
|
|
||||||
|
return module
|
||||||
|
}
|
|
@ -28,8 +28,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
android.RegisterModuleType("gensrcs", GenSrcsFactory)
|
android.RegisterModuleType("gensrcs", genSrcsFactory)
|
||||||
android.RegisterModuleType("genrule", GenRuleFactory)
|
android.RegisterModuleType("genrule", genRuleFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -90,9 +90,13 @@ type generatorProperties struct {
|
||||||
Srcs []string
|
Srcs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type generator struct {
|
type Module struct {
|
||||||
android.ModuleBase
|
android.ModuleBase
|
||||||
|
|
||||||
|
// For other packages to make their own genrules with extra
|
||||||
|
// properties
|
||||||
|
Extra interface{}
|
||||||
|
|
||||||
properties generatorProperties
|
properties generatorProperties
|
||||||
|
|
||||||
tasks taskFunc
|
tasks taskFunc
|
||||||
|
@ -112,21 +116,21 @@ type generateTask struct {
|
||||||
out android.WritablePaths
|
out android.WritablePaths
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *generator) GeneratedSourceFiles() android.Paths {
|
func (g *Module) GeneratedSourceFiles() android.Paths {
|
||||||
return g.outputFiles
|
return g.outputFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *generator) Srcs() android.Paths {
|
func (g *Module) Srcs() android.Paths {
|
||||||
return g.outputFiles
|
return g.outputFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *generator) GeneratedHeaderDirs() android.Paths {
|
func (g *Module) GeneratedHeaderDirs() android.Paths {
|
||||||
return g.exportedIncludeDirs
|
return g.exportedIncludeDirs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *generator) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (g *Module) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
android.ExtractSourcesDeps(ctx, g.properties.Srcs)
|
android.ExtractSourcesDeps(ctx, g.properties.Srcs)
|
||||||
if g, ok := ctx.Module().(*generator); ok {
|
if g, ok := ctx.Module().(*Module); ok {
|
||||||
if len(g.properties.Tools) > 0 {
|
if len(g.properties.Tools) > 0 {
|
||||||
ctx.AddFarVariationDependencies([]blueprint.Variation{
|
ctx.AddFarVariationDependencies([]blueprint.Variation{
|
||||||
{"arch", ctx.AConfig().BuildOsVariant},
|
{"arch", ctx.AConfig().BuildOsVariant},
|
||||||
|
@ -135,7 +139,7 @@ func (g *generator) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *generator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (g *Module) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
if len(g.properties.Tools) == 0 && len(g.properties.Tool_files) == 0 {
|
if len(g.properties.Tools) == 0 && len(g.properties.Tool_files) == 0 {
|
||||||
ctx.ModuleErrorf("at least one `tools` or `tool_files` is required")
|
ctx.ModuleErrorf("at least one `tools` or `tool_files` is required")
|
||||||
return
|
return
|
||||||
|
@ -275,7 +279,7 @@ func (g *generator) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *generator) generateSourceFile(ctx android.ModuleContext, task generateTask) {
|
func (g *Module) generateSourceFile(ctx android.ModuleContext, task generateTask) {
|
||||||
desc := "generate"
|
desc := "generate"
|
||||||
if len(task.out) == 1 {
|
if len(task.out) == 1 {
|
||||||
desc += " " + task.out[0].Base()
|
desc += " " + task.out[0].Base()
|
||||||
|
@ -299,20 +303,18 @@ func (g *generator) generateSourceFile(ctx android.ModuleContext, task generateT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generatorFactory(tasks taskFunc, props ...interface{}) android.Module {
|
func generatorFactory(tasks taskFunc, props ...interface{}) *Module {
|
||||||
module := &generator{
|
module := &Module{
|
||||||
tasks: tasks,
|
tasks: tasks,
|
||||||
}
|
}
|
||||||
|
|
||||||
module.AddProperties(props...)
|
module.AddProperties(props...)
|
||||||
module.AddProperties(&module.properties)
|
module.AddProperties(&module.properties)
|
||||||
|
|
||||||
android.InitAndroidModule(module)
|
|
||||||
|
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenSrcsFactory() android.Module {
|
func NewGenSrcs() *Module {
|
||||||
properties := &genSrcsProperties{}
|
properties := &genSrcsProperties{}
|
||||||
|
|
||||||
tasks := func(ctx android.ModuleContext, srcFiles android.Paths) []generateTask {
|
tasks := func(ctx android.ModuleContext, srcFiles android.Paths) []generateTask {
|
||||||
|
@ -329,12 +331,18 @@ func GenSrcsFactory() android.Module {
|
||||||
return generatorFactory(tasks, properties)
|
return generatorFactory(tasks, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func genSrcsFactory() android.Module {
|
||||||
|
m := NewGenSrcs()
|
||||||
|
android.InitAndroidModule(m)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
type genSrcsProperties struct {
|
type genSrcsProperties struct {
|
||||||
// extension that will be substituted for each output file
|
// extension that will be substituted for each output file
|
||||||
Output_extension string
|
Output_extension string
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenRuleFactory() android.Module {
|
func NewGenRule() *Module {
|
||||||
properties := &genRuleProperties{}
|
properties := &genRuleProperties{}
|
||||||
|
|
||||||
tasks := func(ctx android.ModuleContext, srcFiles android.Paths) []generateTask {
|
tasks := func(ctx android.ModuleContext, srcFiles android.Paths) []generateTask {
|
||||||
|
@ -353,6 +361,12 @@ func GenRuleFactory() android.Module {
|
||||||
return generatorFactory(tasks, properties)
|
return generatorFactory(tasks, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func genRuleFactory() android.Module {
|
||||||
|
m := NewGenRule()
|
||||||
|
android.InitAndroidModule(m)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
type genRuleProperties struct {
|
type genRuleProperties struct {
|
||||||
// names of the output files that will be generated
|
// names of the output files that will be generated
|
||||||
Out []string
|
Out []string
|
||||||
|
|
Loading…
Reference in New Issue