From 16fe8e1cf108c95ee48776121c4e2d45d9e3fd50 Mon Sep 17 00:00:00 2001 From: Vinh Tran Date: Tue, 16 Aug 2022 16:45:44 -0400 Subject: 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 --- java/java_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'java/java_test.go') diff --git a/java/java_test.go b/java/java_test.go index 9e5cf0cf2..bfd97eb0d 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1287,6 +1287,41 @@ func TestAidlExportIncludeDirsFromImports(t *testing.T) { } } +func TestAidlIncludeDirFromConvertedFileGroupWithPathPropInMixedBuilds(t *testing.T) { + bp := ` + filegroup { + name: "foo_aidl", + srcs: ["aidl/foo/IFoo.aidl"], + path: "aidl/foo", + bazel_module: { label: "//:foo_aidl" }, + } + java_library { + name: "foo", + srcs: [":foo_aidl"], + } +` + + outBaseDir := "out/bazel/output" + result := android.GroupFixturePreparers( + prepareForJavaTest, + android.PrepareForTestWithFilegroup, + android.FixtureModifyConfig(func(config android.Config) { + config.BazelContext = android.MockBazelContext{ + OutputBaseDir: outBaseDir, + LabelToOutputFiles: map[string][]string{ + "//:foo_aidl": []string{"aidl/foo/IFoo.aidl"}, + }, + } + }), + ).RunTestWithBp(t, bp) + + aidlCommand := result.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command + expectedAidlFlag := "-I" + outBaseDir + "/execroot/__main__/aidl/foo" + if !strings.Contains(aidlCommand, expectedAidlFlag) { + t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) + } +} + func TestAidlFlagsArePassedToTheAidlCompiler(t *testing.T) { ctx, _ := testJava(t, ` java_library { -- cgit v1.2.3-59-g8ed1b