From a898bb85ca707cee1904e95705d238990570b683 Mon Sep 17 00:00:00 2001 From: Neill Kapron Date: Fri, 30 Aug 2024 20:55:22 +0000 Subject: [PATCH] Soong: BPF: add defaults support and local include Add support for defaults clause in the bpf soong module, as well as local_include_dirs property. Test: TH Change-Id: Iaa03e7f1f6dcf0e929d1d5b23bb79ca2a8366bef Signed-off-by: Neill Kapron --- bpf/bpf.go | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/bpf/bpf.go b/bpf/bpf.go index 73c8800d8..86798217f 100644 --- a/bpf/bpf.go +++ b/bpf/bpf.go @@ -56,6 +56,7 @@ var ( ) func registerBpfBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterModuleType("bpf_defaults", defaultsFactory) ctx.RegisterModuleType("bpf", BpfFactory) } @@ -77,10 +78,16 @@ type BpfProperties struct { // the C/C++ module. Cflags []string - // directories (relative to the root of the source tree) that will - // be added to the include paths using -I. + // list of directories relative to the root of the source tree that + // will be added to the include paths using -I. + // If possible, don't use this. If adding paths from the current + // directory, use local_include_dirs. If adding paths from other + // modules, use export_include_dirs in that module. Include_dirs []string + // list of directories relative to the Blueprint file that will be + // added to the include path using -I. + Local_include_dirs []string // optional subdirectory under which this module is installed into. Sub_dir string @@ -94,7 +101,7 @@ type BpfProperties struct { type bpf struct { android.ModuleBase - + android.DefaultableModuleBase properties BpfProperties objs android.Paths @@ -163,6 +170,10 @@ func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) { "-I " + ctx.ModuleDir(), } + for _, dir := range android.PathsForModuleSrc(ctx, bpf.properties.Local_include_dirs) { + cflags = append(cflags, "-I "+dir.String()) + } + for _, dir := range android.PathsForSource(ctx, bpf.properties.Include_dirs) { cflags = append(cflags, "-I "+dir.String()) } @@ -264,6 +275,26 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData { } } +type Defaults struct { + android.ModuleBase + android.DefaultsModuleBase +} + +func defaultsFactory() android.Module { + return DefaultsFactory() +} + +func DefaultsFactory(props ...interface{}) android.Module { + module := &Defaults{} + + module.AddProperties(props...) + module.AddProperties(&BpfProperties{}) + + android.InitDefaultsModule(module) + + return module +} + func (bpf *bpf) SubDir() string { return bpf.properties.Sub_dir } @@ -274,5 +305,7 @@ func BpfFactory() android.Module { module.AddProperties(&module.properties) android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) + android.InitDefaultableModule(module) + return module }