Incorporate bpf into mixed builds
Bug: 240163393 Test: TestBpfWithBazel in bpf_test.go Change-Id: I1d24a9c0d1d6911987c730bf1b5b7e02d6e73a5e
This commit is contained in:
parent
f1e6126cb0
commit
aa981edcf0
2 changed files with 53 additions and 0 deletions
30
bpf/bpf.go
30
bpf/bpf.go
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/bazel/cquery"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
@ -239,6 +240,35 @@ func (bpf *bpf) AndroidMk() android.AndroidMkData {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -71,3 +71,26 @@ func TestBpfSourceName(t *testing.T) {
|
|||
`\QAndroid.bp:2:3: module "bpf_invalid_name.o" variant "android_common": invalid character '_' in source name\E`)).
|
||||
RunTestWithBp(t, bp)
|
||||
}
|
||||
|
||||
func TestBpfWithBazel(t *testing.T) {
|
||||
bp := `
|
||||
bpf {
|
||||
name: "bpf.o",
|
||||
srcs: ["bpf.c"],
|
||||
bazel_module: { label: "//bpf" },
|
||||
}
|
||||
`
|
||||
|
||||
result := android.GroupFixturePreparers(
|
||||
prepareForBpfTest, android.FixtureModifyConfig(func(config android.Config) {
|
||||
config.BazelContext = android.MockBazelContext{
|
||||
OutputBaseDir: "outputbase",
|
||||
LabelToOutputFiles: map[string][]string{
|
||||
"//bpf": []string{"bpf.o"}}}
|
||||
})).RunTestWithBp(t, bp)
|
||||
|
||||
output := result.Module("bpf.o", "android_common").(*bpf)
|
||||
|
||||
expectedOutputFiles := []string{"outputbase/execroot/__main__/bpf.o"}
|
||||
android.AssertDeepEquals(t, "output files", expectedOutputFiles, output.objs.Strings())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue