platform_build_soong/android/filegroup_test.go
Vinh Tran 16fe8e1cf1 Fix ProcessBazelQueryResponse of filegroup
In mixed builds currently, filegroup doesn't use path prop when creating the paths to the srcs. It defaults to ModuleDir.

Hence, when java.genAidlIncludeFlags [1] calls srcFile.Rel() to eventually create the AIDL include dir for AIDL flags, srcFile.Rel() returns the filepath relative to the module directory instead. This CL appends path prop to module dir when creating relativeRoot.

This fixes the bridge between converted filegroup that set path prop (e.g. libbinder_aidl) to unconverted module (for example, droidstubs). The fix is needed for the child CL aosp/2186599 to convert libbinder_aidl to Bazel. Without this fix, module-lib-api-stubs-docs-non-updatable (unconverted module that depends on libbinder_aidl) can't be built in mixed builds.

[1]: https://cs.android.com/android/platform/superproject/+/master:build/soong/java/gen.go;l=123?q=java%2Fgen.go

Test: go test
Bug: 243010121
Change-Id: Ic2dd2ab9199c62010303a5b8c611d722f4a4118d
2022-08-18 13:59:06 -04:00

58 lines
1.2 KiB
Go

package android
import (
"path/filepath"
"testing"
)
func TestFileGroupWithPathProp(t *testing.T) {
outBaseDir := "outputbase"
pathPrefix := outBaseDir + "/execroot/__main__"
expectedOutputfile := filepath.Join(pathPrefix, "a/b/c/d/test.aidl")
testCases := []struct {
bp string
rel string
}{
{
bp: `
filegroup {
name: "baz",
srcs: ["a/b/c/d/test.aidl"],
path: "a/b",
bazel_module: { label: "//:baz" },
}
`,
rel: "c/d/test.aidl",
},
{
bp: `
filegroup {
name: "baz",
srcs: ["a/b/c/d/test.aidl"],
bazel_module: { label: "//:baz" },
}
`,
rel: "a/b/c/d/test.aidl",
},
}
for _, testCase := range testCases {
outBaseDir := "outputbase"
result := GroupFixturePreparers(
PrepareForTestWithFilegroup,
FixtureModifyConfig(func(config Config) {
config.BazelContext = MockBazelContext{
OutputBaseDir: outBaseDir,
LabelToOutputFiles: map[string][]string{
"//:baz": []string{"a/b/c/d/test.aidl"},
},
}
}),
).RunTestWithBp(t, testCase.bp)
fg := result.Module("baz", "").(*fileGroup)
AssertStringEquals(t, "src relativeRoot", testCase.rel, fg.srcs[0].Rel())
AssertStringEquals(t, "src full path", expectedOutputfile, fg.srcs[0].String())
}
}