Merge "Fix ProcessBazelQueryResponse of filegroup" am: 845c4c1646
am: 643bfe39e9
am: 735e92803c
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2186437 Change-Id: Iaf6b8130950398fc385c094429b513f9f0160b12 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package android
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"android/soong/bazel"
|
||||
@@ -164,12 +165,17 @@ func (fg *fileGroup) IsMixedBuildSupported(ctx BaseModuleContext) bool {
|
||||
}
|
||||
|
||||
func (fg *fileGroup) ProcessBazelQueryResponse(ctx ModuleContext) {
|
||||
fg.srcs = PathsForModuleSrcExcludes(ctx, fg.properties.Srcs, fg.properties.Exclude_srcs)
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
// This is a short-term solution because we rely on info from Android.bp to handle
|
||||
// a converted module. This will block when we want to remove Android.bp for all
|
||||
// converted modules at some point.
|
||||
// TODO(b/242847534): Implement a long-term solution in which we don't need to rely
|
||||
// on info form Android.bp for modules that are already converted to Bazel
|
||||
relativeRoot := ctx.ModuleDir()
|
||||
if fg.properties.Path != nil {
|
||||
fg.srcs = PathsWithModuleSrcSubDir(ctx, fg.srcs, String(fg.properties.Path))
|
||||
relativeRoot = filepath.Join(relativeRoot, *fg.properties.Path)
|
||||
}
|
||||
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
filePaths, err := bazelCtx.GetOutputFiles(fg.GetBazelLabel(ctx, fg), configKey{Common.String(), CommonOS})
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf(err.Error())
|
||||
@@ -178,8 +184,7 @@ func (fg *fileGroup) ProcessBazelQueryResponse(ctx ModuleContext) {
|
||||
|
||||
bazelOuts := make(Paths, 0, len(filePaths))
|
||||
for _, p := range filePaths {
|
||||
bazelOuts = append(bazelOuts, PathForBazelOutRelative(ctx, ctx.ModuleDir(), p))
|
||||
bazelOuts = append(bazelOuts, PathForBazelOutRelative(ctx, relativeRoot, p))
|
||||
}
|
||||
|
||||
fg.srcs = bazelOuts
|
||||
}
|
||||
|
58
android/filegroup_test.go
Normal file
58
android/filegroup_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
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())
|
||||
}
|
||||
}
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user