summaryrefslogtreecommitdiff
path: root/bpf/bpf.go
diff options
context:
space:
mode:
Diffstat (limited to 'bpf/bpf.go')
-rw-r--r--bpf/bpf.go114
1 files changed, 26 insertions, 88 deletions
diff --git a/bpf/bpf.go b/bpf/bpf.go
index 45009c1e7..09262e507 100644
--- a/bpf/bpf.go
+++ b/bpf/bpf.go
@@ -22,8 +22,6 @@ import (
"strings"
"android/soong/android"
- "android/soong/bazel"
- "android/soong/bazel/cquery"
"android/soong/cc"
"github.com/google/blueprint"
@@ -67,8 +65,6 @@ var PrepareForTestWithBpf = android.FixtureRegisterWithContext(registerBpfBuildC
type BpfModule interface {
android.Module
- OutputFiles(tag string) (android.Paths, error)
-
// Returns the sub install directory if the bpf module is included by apex.
SubDir() string
}
@@ -98,7 +94,6 @@ type BpfProperties struct {
type bpf struct {
android.ModuleBase
- android.BazelModuleBase
properties BpfProperties
@@ -109,6 +104,14 @@ var _ android.ImageInterface = (*bpf)(nil)
func (bpf *bpf) ImageMutatorBegin(ctx android.BaseModuleContext) {}
+func (bpf *bpf) VendorVariantNeeded(ctx android.BaseModuleContext) bool {
+ return proptools.Bool(bpf.properties.Vendor)
+}
+
+func (bpf *bpf) ProductVariantNeeded(ctx android.BaseModuleContext) bool {
+ return false
+}
+
func (bpf *bpf) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
return !proptools.Bool(bpf.properties.Vendor)
}
@@ -130,13 +133,10 @@ func (bpf *bpf) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
}
func (bpf *bpf) ExtraImageVariations(ctx android.BaseModuleContext) []string {
- if proptools.Bool(bpf.properties.Vendor) {
- return []string{"vendor"}
- }
return nil
}
-func (bpf *bpf) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
+func (bpf *bpf) SetImageVariation(ctx android.BaseModuleContext, variation string) {
bpf.properties.VendorInternal = variation == "vendor"
}
@@ -153,7 +153,7 @@ func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// The architecture doesn't matter here, but asm/types.h is included by linux/types.h.
"-isystem bionic/libc/kernel/uapi/asm-arm64",
"-isystem bionic/libc/kernel/android/uapi",
- "-I frameworks/libs/net/common/native/bpf_headers/include/bpf",
+ "-I packages/modules/Connectivity/staticlibs/native/bpf_headers/include/bpf",
// TODO(b/149785767): only give access to specific file with AID_* constants
"-I system/core/libcutils/include",
"-I " + ctx.ModuleDir(),
@@ -206,6 +206,18 @@ func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) {
}
}
+
+ installDir := android.PathForModuleInstall(ctx, "etc", "bpf")
+ if len(bpf.properties.Sub_dir) > 0 {
+ installDir = installDir.Join(ctx, bpf.properties.Sub_dir)
+ }
+ for _, obj := range bpf.objs {
+ ctx.PackageFile(installDir, obj.Base(), obj)
+ }
+
+ android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: srcs.Strings()})
+
+ ctx.SetOutputFiles(bpf.objs, "")
}
func (bpf *bpf) AndroidMk() android.AndroidMkData {
@@ -229,108 +241,34 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData {
names = append(names, objName)
fmt.Fprintln(w, "include $(CLEAR_VARS)", " # bpf.bpf.obj")
fmt.Fprintln(w, "LOCAL_MODULE := ", objName)
- data.Entries.WriteLicenseVariables(w)
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", obj.String())
fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", obj.Base())
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC")
fmt.Fprintln(w, localModulePath)
+ // AconfigUpdateAndroidMkData may have added elements to Extra. Process them here.
+ for _, extra := range data.Extra {
+ extra(w, nil)
+ }
fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
fmt.Fprintln(w)
}
fmt.Fprintln(w, "include $(CLEAR_VARS)", " # bpf.bpf")
fmt.Fprintln(w, "LOCAL_MODULE := ", name)
- data.Entries.WriteLicenseVariables(w)
android.AndroidMkEmitAssignList(w, "LOCAL_REQUIRED_MODULES", names)
fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)")
},
}
}
-var _ android.MixedBuildBuildable = (*bpf)(nil)
-
-func (bpf *bpf) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
- return true
-}
-
-func (bpf *bpf) QueueBazelCall(ctx android.BaseModuleContext) {
- bazelCtx := ctx.Config().BazelContext
- bazelCtx.QueueBazelRequest(
- bpf.GetBazelLabel(ctx, bpf),
- cquery.GetOutputFiles,
- android.GetConfigKey(ctx))
-}
-
-func (bpf *bpf) ProcessBazelQueryResponse(ctx android.ModuleContext) {
- bazelCtx := ctx.Config().BazelContext
- objPaths, err := bazelCtx.GetOutputFiles(bpf.GetBazelLabel(ctx, bpf), android.GetConfigKey(ctx))
- if err != nil {
- ctx.ModuleErrorf(err.Error())
- return
- }
-
- bazelOuts := android.Paths{}
- for _, p := range objPaths {
- bazelOuts = append(bazelOuts, android.PathForBazelOut(ctx, p))
- }
- bpf.objs = bazelOuts
-}
-
-// Implements OutputFileFileProducer interface so that the obj output can be used in the data property
-// of other modules.
-func (bpf *bpf) OutputFiles(tag string) (android.Paths, error) {
- switch tag {
- case "":
- return bpf.objs, nil
- default:
- return nil, fmt.Errorf("unsupported module reference tag %q", tag)
- }
-}
-
func (bpf *bpf) SubDir() string {
return bpf.properties.Sub_dir
}
-var _ android.OutputFileProducer = (*bpf)(nil)
-
func BpfFactory() android.Module {
module := &bpf{}
module.AddProperties(&module.properties)
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
- android.InitBazelModule(module)
return module
}
-
-type bazelBpfAttributes struct {
- Srcs bazel.LabelListAttribute
- Copts bazel.StringListAttribute
- Absolute_includes bazel.StringListAttribute
- Btf *bool
- // TODO(b/249528391): Add support for sub_dir
-}
-
-// bpf bp2build converter
-func (b *bpf) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
- if ctx.ModuleType() != "bpf" {
- return
- }
-
- srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, b.properties.Srcs))
- copts := bazel.MakeStringListAttribute(b.properties.Cflags)
- absolute_includes := bazel.MakeStringListAttribute(b.properties.Include_dirs)
- btf := b.properties.Btf
-
- attrs := bazelBpfAttributes{
- Srcs: srcs,
- Copts: copts,
- Absolute_includes: absolute_includes,
- Btf: btf,
- }
- props := bazel.BazelTargetModuleProperties{
- Rule_class: "bpf",
- Bzl_load_location: "//build/bazel/rules/bpf:bpf.bzl",
- }
-
- ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: b.Name()}, &attrs)
-}