Add aconfig flags and a generic generated library plugin module for cc
The generated module lets us keep the aconfig code in its own pacakge and not infect all of the cc package with aconfig. It's also closer to what bazel is going to do Bug: 283479529 Test: m aconfig_hello_world_cc && adb push $TOP/out/target/product/panther/system/bin/aconfig_hello_world_cc /system/bin && adb shell aconfig_hello_world_cc Change-Id: I2fb9e419939c7ca77b111da9c376af077e2348a9
This commit is contained in:
@@ -20,6 +20,7 @@ bootstrap_go_package {
|
|||||||
"aconfig_values.go",
|
"aconfig_values.go",
|
||||||
"aconfig_value_set.go",
|
"aconfig_value_set.go",
|
||||||
"all_aconfig_declarations.go",
|
"all_aconfig_declarations.go",
|
||||||
|
"cc_aconfig_library.go",
|
||||||
"init.go",
|
"init.go",
|
||||||
"java_aconfig_library.go",
|
"java_aconfig_library.go",
|
||||||
"testing.go",
|
"testing.go",
|
||||||
|
128
aconfig/cc_aconfig_library.go
Normal file
128
aconfig/cc_aconfig_library.go
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
// Copyright 2023 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 aconfig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/cc"
|
||||||
|
"github.com/google/blueprint"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ccDeclarationsTagType struct {
|
||||||
|
blueprint.BaseDependencyTag
|
||||||
|
}
|
||||||
|
|
||||||
|
var ccDeclarationsTag = ccDeclarationsTagType{}
|
||||||
|
|
||||||
|
type CcAconfigLibraryProperties struct {
|
||||||
|
// name of the aconfig_declarations module to generate a library for
|
||||||
|
Aconfig_declarations string
|
||||||
|
}
|
||||||
|
|
||||||
|
type CcAconfigLibraryCallbacks struct {
|
||||||
|
properties *CcAconfigLibraryProperties
|
||||||
|
|
||||||
|
generatedDir android.WritablePath
|
||||||
|
headerDir android.WritablePath
|
||||||
|
generatedCpp android.WritablePath
|
||||||
|
generatedH android.WritablePath
|
||||||
|
}
|
||||||
|
|
||||||
|
func CcAconfigLibraryFactory() android.Module {
|
||||||
|
callbacks := &CcAconfigLibraryCallbacks{
|
||||||
|
properties: &CcAconfigLibraryProperties{},
|
||||||
|
}
|
||||||
|
return cc.GeneratedCcLibraryModuleFactory("cc_aconfig_library", callbacks)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CcAconfigLibraryCallbacks) GeneratorInit(ctx cc.BaseModuleContext) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CcAconfigLibraryCallbacks) GeneratorProps() []interface{} {
|
||||||
|
return []interface{}{this.properties}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CcAconfigLibraryCallbacks) GeneratorDeps(ctx cc.DepsContext, deps cc.Deps) cc.Deps {
|
||||||
|
// Add a dependency for the declarations module
|
||||||
|
declarations := this.properties.Aconfig_declarations
|
||||||
|
if len(declarations) == 0 {
|
||||||
|
ctx.PropertyErrorf("aconfig_declarations", "aconfig_declarations property required")
|
||||||
|
} else {
|
||||||
|
ctx.AddDependency(ctx.Module(), ccDeclarationsTag, declarations)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a dependency for the aconfig flags base library
|
||||||
|
deps.SharedLibs = append(deps.SharedLibs, "server_configurable_flags")
|
||||||
|
// TODO: It'd be really nice if we could reexport this library and not make everyone do it.
|
||||||
|
|
||||||
|
return deps
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CcAconfigLibraryCallbacks) GeneratorSources(ctx cc.ModuleContext) cc.GeneratedSource {
|
||||||
|
result := cc.GeneratedSource{}
|
||||||
|
|
||||||
|
// Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
|
||||||
|
declarationsModules := ctx.GetDirectDepsWithTag(ccDeclarationsTag)
|
||||||
|
if len(declarationsModules) != 1 {
|
||||||
|
panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
|
||||||
|
}
|
||||||
|
declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
|
||||||
|
|
||||||
|
// Figure out the generated file paths. This has to match aconfig's codegen_cpp.rs.
|
||||||
|
this.generatedDir = android.PathForModuleGen(ctx)
|
||||||
|
|
||||||
|
this.headerDir = android.PathForModuleGen(ctx, "include")
|
||||||
|
result.IncludeDirs = []android.Path{this.headerDir}
|
||||||
|
result.ReexportedDirs = []android.Path{this.headerDir}
|
||||||
|
|
||||||
|
basename := strings.ReplaceAll(declarations.Package, ".", "_")
|
||||||
|
|
||||||
|
this.generatedCpp = android.PathForModuleGen(ctx, basename+".cc")
|
||||||
|
result.Sources = []android.Path{this.generatedCpp}
|
||||||
|
|
||||||
|
this.generatedH = android.PathForModuleGen(ctx, "include", basename+".h")
|
||||||
|
result.Headers = []android.Path{this.generatedH}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CcAconfigLibraryCallbacks) GeneratorFlags(ctx cc.ModuleContext, flags cc.Flags, deps cc.PathDeps) cc.Flags {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CcAconfigLibraryCallbacks) GeneratorBuildActions(ctx cc.ModuleContext, flags cc.Flags, deps cc.PathDeps) {
|
||||||
|
// Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
|
||||||
|
declarationsModules := ctx.GetDirectDepsWithTag(ccDeclarationsTag)
|
||||||
|
if len(declarationsModules) != 1 {
|
||||||
|
panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
|
||||||
|
}
|
||||||
|
declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
|
||||||
|
|
||||||
|
ctx.Build(pctx, android.BuildParams{
|
||||||
|
Rule: cppRule,
|
||||||
|
Input: declarations.IntermediatePath,
|
||||||
|
Outputs: []android.WritablePath{
|
||||||
|
this.generatedCpp,
|
||||||
|
this.generatedH,
|
||||||
|
},
|
||||||
|
Description: "cc_aconfig_library",
|
||||||
|
Args: map[string]string{
|
||||||
|
"gendir": this.generatedDir.String(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@@ -39,7 +39,7 @@ var (
|
|||||||
}, "release_version", "package", "declarations", "values")
|
}, "release_version", "package", "declarations", "values")
|
||||||
|
|
||||||
// For java_aconfig_library: Generate java file
|
// For java_aconfig_library: Generate java file
|
||||||
srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar",
|
javaRule = pctx.AndroidStaticRule("java_aconfig_library",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf ${out}.tmp` +
|
Command: `rm -rf ${out}.tmp` +
|
||||||
` && mkdir -p ${out}.tmp` +
|
` && mkdir -p ${out}.tmp` +
|
||||||
@@ -55,6 +55,20 @@ var (
|
|||||||
Restat: true,
|
Restat: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// For java_aconfig_library: Generate java file
|
||||||
|
cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
|
||||||
|
blueprint.RuleParams{
|
||||||
|
Command: `rm -rf ${gendir}` +
|
||||||
|
` && mkdir -p ${gendir}` +
|
||||||
|
` && ${aconfig} create-cpp-lib` +
|
||||||
|
` --cache ${in}` +
|
||||||
|
` --out ${gendir}`,
|
||||||
|
CommandDeps: []string{
|
||||||
|
"$aconfig",
|
||||||
|
"$soong_zip",
|
||||||
|
},
|
||||||
|
}, "gendir")
|
||||||
|
|
||||||
// For all_aconfig_declarations
|
// For all_aconfig_declarations
|
||||||
allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
|
allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
@@ -75,6 +89,7 @@ func registerBuildComponents(ctx android.RegistrationContext) {
|
|||||||
ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
|
ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
|
||||||
ctx.RegisterModuleType("aconfig_values", ValuesFactory)
|
ctx.RegisterModuleType("aconfig_values", ValuesFactory)
|
||||||
ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
|
ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
|
||||||
|
ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
|
||||||
ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
|
ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
|
||||||
ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
|
ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,7 @@ func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuild
|
|||||||
|
|
||||||
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
|
srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: srcJarRule,
|
Rule: javaRule,
|
||||||
Input: declarations.IntermediatePath,
|
Input: declarations.IntermediatePath,
|
||||||
Output: srcJarPath,
|
Output: srcJarPath,
|
||||||
Description: "aconfig.srcjar",
|
Description: "aconfig.srcjar",
|
||||||
|
@@ -32,6 +32,7 @@ bootstrap_go_package {
|
|||||||
"check.go",
|
"check.go",
|
||||||
"coverage.go",
|
"coverage.go",
|
||||||
"gen.go",
|
"gen.go",
|
||||||
|
"generated_cc_library.go",
|
||||||
"image.go",
|
"image.go",
|
||||||
"linkable.go",
|
"linkable.go",
|
||||||
"lto.go",
|
"lto.go",
|
||||||
|
54
cc/cc.go
54
cc/cc.go
@@ -569,6 +569,24 @@ type feature interface {
|
|||||||
props() []interface{}
|
props() []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Information returned from Generator about the source code it's generating
|
||||||
|
type GeneratedSource struct {
|
||||||
|
IncludeDirs android.Paths
|
||||||
|
Sources android.Paths
|
||||||
|
Headers android.Paths
|
||||||
|
ReexportedDirs android.Paths
|
||||||
|
}
|
||||||
|
|
||||||
|
// generator allows injection of generated code
|
||||||
|
type Generator interface {
|
||||||
|
GeneratorProps() []interface{}
|
||||||
|
GeneratorInit(ctx BaseModuleContext)
|
||||||
|
GeneratorDeps(ctx DepsContext, deps Deps) Deps
|
||||||
|
GeneratorFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
|
||||||
|
GeneratorSources(ctx ModuleContext) GeneratedSource
|
||||||
|
GeneratorBuildActions(ctx ModuleContext, flags Flags, deps PathDeps)
|
||||||
|
}
|
||||||
|
|
||||||
// compiler is the interface for a compiler helper object. Different module decorators may implement
|
// compiler is the interface for a compiler helper object. Different module decorators may implement
|
||||||
// this helper differently.
|
// this helper differently.
|
||||||
type compiler interface {
|
type compiler interface {
|
||||||
@@ -851,6 +869,7 @@ type Module struct {
|
|||||||
// type-specific logic. These members may reference different objects or the same object.
|
// type-specific logic. These members may reference different objects or the same object.
|
||||||
// Functions of these decorators will be invoked to initialize and register type-specific
|
// Functions of these decorators will be invoked to initialize and register type-specific
|
||||||
// build statements.
|
// build statements.
|
||||||
|
generators []Generator
|
||||||
compiler compiler
|
compiler compiler
|
||||||
linker linker
|
linker linker
|
||||||
installer installer
|
installer installer
|
||||||
@@ -1201,6 +1220,9 @@ func (c *Module) VndkVersion() string {
|
|||||||
|
|
||||||
func (c *Module) Init() android.Module {
|
func (c *Module) Init() android.Module {
|
||||||
c.AddProperties(&c.Properties, &c.VendorProperties)
|
c.AddProperties(&c.Properties, &c.VendorProperties)
|
||||||
|
for _, generator := range c.generators {
|
||||||
|
c.AddProperties(generator.GeneratorProps()...)
|
||||||
|
}
|
||||||
if c.compiler != nil {
|
if c.compiler != nil {
|
||||||
c.AddProperties(c.compiler.compilerProps()...)
|
c.AddProperties(c.compiler.compilerProps()...)
|
||||||
}
|
}
|
||||||
@@ -2149,6 +2171,25 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, generator := range c.generators {
|
||||||
|
gen := generator.GeneratorSources(ctx)
|
||||||
|
deps.IncludeDirs = append(deps.IncludeDirs, gen.IncludeDirs...)
|
||||||
|
deps.ReexportedDirs = append(deps.ReexportedDirs, gen.ReexportedDirs...)
|
||||||
|
deps.GeneratedDeps = append(deps.GeneratedDeps, gen.Headers...)
|
||||||
|
deps.ReexportedGeneratedHeaders = append(deps.ReexportedGeneratedHeaders, gen.Headers...)
|
||||||
|
deps.ReexportedDeps = append(deps.ReexportedDeps, gen.Headers...)
|
||||||
|
if len(deps.Objs.objFiles) == 0 {
|
||||||
|
// If we are reusuing object files (which happens when we're a shared library and we're
|
||||||
|
// reusing our static variant's object files), then skip adding the actual source files,
|
||||||
|
// because we already have the object for it.
|
||||||
|
deps.GeneratedSources = append(deps.GeneratedSources, gen.Sources...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.Failed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if c.stubLibraryMultipleApexViolation(actx) {
|
if c.stubLibraryMultipleApexViolation(actx) {
|
||||||
actx.PropertyErrorf("apex_available",
|
actx.PropertyErrorf("apex_available",
|
||||||
"Stub libraries should have a single apex_available (test apexes excluded). Got %v", c.ApexAvailable())
|
"Stub libraries should have a single apex_available (test apexes excluded). Got %v", c.ApexAvailable())
|
||||||
@@ -2163,6 +2204,9 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
Toolchain: c.toolchain(ctx),
|
Toolchain: c.toolchain(ctx),
|
||||||
EmitXrefs: ctx.Config().EmitXrefRules(),
|
EmitXrefs: ctx.Config().EmitXrefRules(),
|
||||||
}
|
}
|
||||||
|
for _, generator := range c.generators {
|
||||||
|
flags = generator.GeneratorFlags(ctx, flags, deps)
|
||||||
|
}
|
||||||
if c.compiler != nil {
|
if c.compiler != nil {
|
||||||
flags = c.compiler.compilerFlags(ctx, flags, deps)
|
flags = c.compiler.compilerFlags(ctx, flags, deps)
|
||||||
}
|
}
|
||||||
@@ -2220,6 +2264,10 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
|
|
||||||
flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
|
flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
|
||||||
|
|
||||||
|
for _, generator := range c.generators {
|
||||||
|
generator.GeneratorBuildActions(ctx, flags, deps)
|
||||||
|
}
|
||||||
|
|
||||||
var objs Objects
|
var objs Objects
|
||||||
if c.compiler != nil {
|
if c.compiler != nil {
|
||||||
objs = c.compiler.compile(ctx, flags, deps)
|
objs = c.compiler.compile(ctx, flags, deps)
|
||||||
@@ -2307,6 +2355,9 @@ func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Module) begin(ctx BaseModuleContext) {
|
func (c *Module) begin(ctx BaseModuleContext) {
|
||||||
|
for _, generator := range c.generators {
|
||||||
|
generator.GeneratorInit(ctx)
|
||||||
|
}
|
||||||
if c.compiler != nil {
|
if c.compiler != nil {
|
||||||
c.compiler.compilerInit(ctx)
|
c.compiler.compilerInit(ctx)
|
||||||
}
|
}
|
||||||
@@ -2342,6 +2393,9 @@ func (c *Module) begin(ctx BaseModuleContext) {
|
|||||||
func (c *Module) deps(ctx DepsContext) Deps {
|
func (c *Module) deps(ctx DepsContext) Deps {
|
||||||
deps := Deps{}
|
deps := Deps{}
|
||||||
|
|
||||||
|
for _, generator := range c.generators {
|
||||||
|
deps = generator.GeneratorDeps(ctx, deps)
|
||||||
|
}
|
||||||
if c.compiler != nil {
|
if c.compiler != nil {
|
||||||
deps = c.compiler.compilerDeps(ctx, deps)
|
deps = c.compiler.compilerDeps(ctx, deps)
|
||||||
}
|
}
|
||||||
|
38
cc/generated_cc_library.go
Normal file
38
cc/generated_cc_library.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2023 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GeneratedCcLibraryModuleFactory(moduleName string, callbacks Generator) android.Module {
|
||||||
|
module, _ := NewLibrary(android.HostAndDeviceSupported)
|
||||||
|
|
||||||
|
// Can be used as both a static and a shared library.
|
||||||
|
module.sdkMemberTypes = []android.SdkMemberType{
|
||||||
|
sharedLibrarySdkMemberType,
|
||||||
|
staticLibrarySdkMemberType,
|
||||||
|
staticAndSharedLibrarySdkMemberType,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Need to be bazelable
|
||||||
|
// module.bazelable = true
|
||||||
|
// module.bazelHandler = &ccLibraryBazelHandler{module: module}
|
||||||
|
|
||||||
|
module.generators = append(module.generators, callbacks)
|
||||||
|
|
||||||
|
return module.Init()
|
||||||
|
}
|
Reference in New Issue
Block a user