Merge "Include bpf program in APEXes" am: 66a0ae60f8

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1418308

Change-Id: I86983c1012615e95d1d9aac875a52e92248a17b8
This commit is contained in:
Mark Chien 2020-09-04 09:11:22 +00:00 committed by Automerger Merge Worker
commit 288f40ba51
5 changed files with 43 additions and 3 deletions

View File

@ -5,6 +5,7 @@ bootstrap_go_package {
"blueprint", "blueprint",
"soong", "soong",
"soong-android", "soong-android",
"soong-bpf",
"soong-cc", "soong-cc",
"soong-java", "soong-java",
"soong-python", "soong-python",

View File

@ -26,6 +26,7 @@ import (
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
"android/soong/android" "android/soong/android"
"android/soong/bpf"
"android/soong/cc" "android/soong/cc"
prebuilt_etc "android/soong/etc" prebuilt_etc "android/soong/etc"
"android/soong/java" "android/soong/java"
@ -66,6 +67,7 @@ var (
usesTag = dependencyTag{name: "uses"} usesTag = dependencyTag{name: "uses"}
androidAppTag = dependencyTag{name: "androidApp", payload: true} androidAppTag = dependencyTag{name: "androidApp", payload: true}
rroTag = dependencyTag{name: "rro", payload: true} rroTag = dependencyTag{name: "rro", payload: true}
bpfTag = dependencyTag{name: "bpf", payload: true}
apexAvailBaseline = makeApexAvailableBaseline() apexAvailBaseline = makeApexAvailableBaseline()
@ -1063,6 +1065,9 @@ type apexBundleProperties struct {
// List of prebuilt files that are embedded inside this APEX bundle // List of prebuilt files that are embedded inside this APEX bundle
Prebuilts []string Prebuilts []string
// List of BPF programs inside APEX
Bpfs []string
// Name of the apex_key module that provides the private key to sign APEX // Name of the apex_key module that provides the private key to sign APEX
Key *string Key *string
@ -1579,6 +1584,9 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
javaLibTag, a.properties.Java_libs...) javaLibTag, a.properties.Java_libs...)
ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
bpfTag, a.properties.Bpfs...)
// With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library. // With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") { if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
@ -1899,6 +1907,11 @@ func apexFileForRuntimeResourceOverlay(ctx android.BaseModuleContext, rro java.R
return af return af
} }
func apexFileForBpfProgram(ctx android.BaseModuleContext, builtFile android.Path, bpfProgram bpf.BpfModule) apexFile {
dirInApex := filepath.Join("etc", "bpf")
return newApexFile(ctx, builtFile, builtFile.Base(), dirInApex, etc, bpfProgram)
}
// Context "decorator", overriding the InstallBypassMake method to always reply `true`. // Context "decorator", overriding the InstallBypassMake method to always reply `true`.
type flattenedApexContext struct { type flattenedApexContext struct {
android.ModuleContext android.ModuleContext
@ -2227,6 +2240,15 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
} else { } else {
ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName) ctx.PropertyErrorf("rros", "%q is not an runtime_resource_overlay module", depName)
} }
case bpfTag:
if bpfProgram, ok := child.(bpf.BpfModule); ok {
filesToCopy, _ := bpfProgram.OutputFiles("")
for _, bpfFile := range filesToCopy {
filesInfo = append(filesInfo, apexFileForBpfProgram(ctx, bpfFile, bpfProgram))
}
} else {
ctx.PropertyErrorf("bpfs", "%q is not a bpf module", depName)
}
case prebuiltTag: case prebuiltTag:
if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok { if prebuilt, ok := child.(prebuilt_etc.PrebuiltEtcModule); ok {
filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName)) filesInfo = append(filesInfo, apexFileForPrebuiltEtc(ctx, prebuilt, depName))

View File

@ -27,6 +27,7 @@ import (
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
"android/soong/android" "android/soong/android"
"android/soong/bpf"
"android/soong/cc" "android/soong/cc"
"android/soong/dexpreopt" "android/soong/dexpreopt"
prebuilt_etc "android/soong/etc" prebuilt_etc "android/soong/etc"
@ -257,6 +258,7 @@ func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*andr
java.RegisterAppBuildComponents(ctx) java.RegisterAppBuildComponents(ctx)
java.RegisterSdkLibraryBuildComponents(ctx) java.RegisterSdkLibraryBuildComponents(ctx)
ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory) ctx.RegisterSingletonType("apex_keys_text", apexKeysTextFactory)
ctx.RegisterModuleType("bpf", bpf.BpfFactory)
ctx.PreDepsMutators(RegisterPreDepsMutators) ctx.PreDepsMutators(RegisterPreDepsMutators)
ctx.PostDepsMutators(RegisterPostDepsMutators) ctx.PostDepsMutators(RegisterPostDepsMutators)
@ -606,6 +608,7 @@ func TestDefaults(t *testing.T) {
java_libs: ["myjar"], java_libs: ["myjar"],
apps: ["AppFoo"], apps: ["AppFoo"],
rros: ["rro"], rros: ["rro"],
bpfs: ["bpf"],
} }
prebuilt_etc { prebuilt_etc {
@ -652,6 +655,11 @@ func TestDefaults(t *testing.T) {
theme: "blue", theme: "blue",
} }
bpf {
name: "bpf",
srcs: ["bpf.c", "bpf2.c"],
}
`) `)
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
"etc/myetc", "etc/myetc",
@ -659,6 +667,8 @@ func TestDefaults(t *testing.T) {
"lib64/mylib.so", "lib64/mylib.so",
"app/AppFoo/AppFoo.apk", "app/AppFoo/AppFoo.apk",
"overlay/blue/rro.apk", "overlay/blue/rro.apk",
"etc/bpf/bpf.o",
"etc/bpf/bpf2.o",
}) })
} }

View File

@ -26,7 +26,7 @@ import (
) )
func init() { func init() {
android.RegisterModuleType("bpf", bpfFactory) android.RegisterModuleType("bpf", BpfFactory)
pctx.Import("android/soong/cc/config") pctx.Import("android/soong/cc/config")
} }
@ -43,6 +43,13 @@ var (
"ccCmd", "cFlags") "ccCmd", "cFlags")
) )
// BpfModule interface is used by the apex package to gather information from a bpf module.
type BpfModule interface {
android.Module
OutputFiles(tag string) (android.Paths, error)
}
type BpfProperties struct { type BpfProperties struct {
Srcs []string `android:"path"` Srcs []string `android:"path"`
Cflags []string Cflags []string
@ -141,7 +148,7 @@ func (bpf *bpf) OutputFiles(tag string) (android.Paths, error) {
var _ android.OutputFileProducer = (*bpf)(nil) var _ android.OutputFileProducer = (*bpf)(nil)
func bpfFactory() android.Module { func BpfFactory() android.Module {
module := &bpf{} module := &bpf{}
module.AddProperties(&module.properties) module.AddProperties(&module.properties)

View File

@ -59,7 +59,7 @@ func testConfig(buildDir string, env map[string]string, bp string) android.Confi
func testContext(config android.Config) *android.TestContext { func testContext(config android.Config) *android.TestContext {
ctx := cc.CreateTestContext() ctx := cc.CreateTestContext()
ctx.RegisterModuleType("bpf", bpfFactory) ctx.RegisterModuleType("bpf", BpfFactory)
ctx.Register(config) ctx.Register(config)
return ctx return ctx