Add ctx argument to IDEInfo()

The IDEInfo() methods read properties. To make those properties
configurable, we need a context to evaluate them with.

Bug: 362579941
Test: m nothing --no-skip-soong-tests
Change-Id: I26d4b7084439b3006e50b02277298f74a929e1aa
This commit is contained in:
Cole Faust
2024-08-27 16:04:28 -07:00
parent 5b35cb9aef
commit b36d31d870
13 changed files with 49 additions and 45 deletions

View File

@@ -1959,7 +1959,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
if x, ok := m.module.(IDEInfo); ok { if x, ok := m.module.(IDEInfo); ok {
var result IdeInfo var result IdeInfo
x.IDEInfo(&result) x.IDEInfo(ctx, &result)
result.BaseModuleName = x.BaseModuleName() result.BaseModuleName = x.BaseModuleName()
SetProvider(ctx, IdeInfoProviderKey, result) SetProvider(ctx, IdeInfoProviderKey, result)
} }
@@ -2748,7 +2748,7 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
// Collect information for opening IDE project files in java/jdeps.go. // Collect information for opening IDE project files in java/jdeps.go.
type IDEInfo interface { type IDEInfo interface {
IDEInfo(ideInfo *IdeInfo) IDEInfo(ctx BaseModuleContext, ideInfo *IdeInfo)
BaseModuleName() string BaseModuleName() string
} }

View File

@@ -2865,7 +2865,7 @@ func isStaticExecutableAllowed(apex string, exec string) bool {
} }
// Collect information for opening IDE project files in java/jdeps.go. // Collect information for opening IDE project files in java/jdeps.go.
func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) { func (a *apexBundle) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...) dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...)
dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...) dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...)
dpInfo.Deps = append(dpInfo.Deps, a.properties.ResolvedSystemserverclasspathFragments...) dpInfo.Deps = append(dpInfo.Deps, a.properties.ResolvedSystemserverclasspathFragments...)

View File

@@ -625,7 +625,7 @@ func (g *Module) setOutputFiles(ctx android.ModuleContext) {
} }
// Collect information for opening IDE project files in java/jdeps.go. // Collect information for opening IDE project files in java/jdeps.go.
func (g *Module) IDEInfo(dpInfo *android.IdeInfo) { func (g *Module) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
dpInfo.Srcs = append(dpInfo.Srcs, g.Srcs().Strings()...) dpInfo.Srcs = append(dpInfo.Srcs, g.Srcs().Strings()...)
for _, src := range g.properties.ResolvedSrcs { for _, src := range g.properties.ResolvedSrcs {
if strings.HasPrefix(src, ":") { if strings.HasPrefix(src, ":") {

View File

@@ -914,12 +914,12 @@ func (a *AndroidLibrary) setOutputFiles(ctx android.ModuleContext) {
setOutputFiles(ctx, a.Library.Module) setOutputFiles(ctx, a.Library.Module)
} }
func (a *AndroidLibrary) IDEInfo(dpInfo *android.IdeInfo) { func (a *AndroidLibrary) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
a.Library.IDEInfo(dpInfo) a.Library.IDEInfo(ctx, dpInfo)
a.aapt.IDEInfo(dpInfo) a.aapt.IDEInfo(ctx, dpInfo)
} }
func (a *aapt) IDEInfo(dpInfo *android.IdeInfo) { func (a *aapt) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
if a.rJar != nil { if a.rJar != nil {
dpInfo.Jars = append(dpInfo.Jars, a.rJar.String()) dpInfo.Jars = append(dpInfo.Jars, a.rJar.String())
} }
@@ -1451,6 +1451,6 @@ func AARImportFactory() android.Module {
return module return module
} }
func (a *AARImport) IDEInfo(dpInfo *android.IdeInfo) { func (a *AARImport) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
dpInfo.Jars = append(dpInfo.Jars, a.headerJarFile.String(), a.rJar.String()) dpInfo.Jars = append(dpInfo.Jars, a.headerJarFile.String(), a.rJar.String())
} }

View File

@@ -1243,9 +1243,9 @@ func (a *AndroidApp) EnableCoverageIfNeeded() {}
var _ cc.Coverage = (*AndroidApp)(nil) var _ cc.Coverage = (*AndroidApp)(nil)
func (a *AndroidApp) IDEInfo(dpInfo *android.IdeInfo) { func (a *AndroidApp) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
a.Library.IDEInfo(dpInfo) a.Library.IDEInfo(ctx, dpInfo)
a.aapt.IDEInfo(dpInfo) a.aapt.IDEInfo(ctx, dpInfo)
} }
func (a *AndroidApp) productCharacteristicsRROPackageName() string { func (a *AndroidApp) productCharacteristicsRROPackageName() string {

View File

@@ -2049,7 +2049,7 @@ func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
} }
// Collect information for opening IDE project files in java/jdeps.go. // Collect information for opening IDE project files in java/jdeps.go.
func (j *Module) IDEInfo(dpInfo *android.IdeInfo) { func (j *Module) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
// jarjar rules will repackage the sources. To prevent misleading results, IdeInfo should contain the // jarjar rules will repackage the sources. To prevent misleading results, IdeInfo should contain the
// repackaged jar instead of the input sources. // repackaged jar instead of the input sources.
if j.expandJarjarRules != nil { if j.expandJarjarRules != nil {

View File

@@ -836,7 +836,7 @@ func (b *BootclasspathFragmentModule) getProfilePath() android.Path {
} }
// Collect information for opening IDE project files in java/jdeps.go. // Collect information for opening IDE project files in java/jdeps.go.
func (b *BootclasspathFragmentModule) IDEInfo(dpInfo *android.IdeInfo) { func (b *BootclasspathFragmentModule) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, b.properties.Contents...) dpInfo.Deps = append(dpInfo.Deps, b.properties.Contents...)
} }

View File

@@ -192,7 +192,7 @@ func (d *DeviceHostConverter) AndroidMk() android.AndroidMkData {
// implement the following interface for IDE completion. // implement the following interface for IDE completion.
var _ android.IDEInfo = (*DeviceHostConverter)(nil) var _ android.IDEInfo = (*DeviceHostConverter)(nil)
func (d *DeviceHostConverter) IDEInfo(ideInfo *android.IdeInfo) { func (d *DeviceHostConverter) IDEInfo(ctx android.BaseModuleContext, ideInfo *android.IdeInfo) {
ideInfo.Deps = append(ideInfo.Deps, d.properties.Libs...) ideInfo.Deps = append(ideInfo.Deps, d.properties.Libs...)
ideInfo.Libs = append(ideInfo.Libs, d.properties.Libs...) ideInfo.Libs = append(ideInfo.Libs, d.properties.Libs...)
} }

View File

@@ -2404,15 +2404,15 @@ func (al *ApiLibrary) TargetSdkVersion(ctx android.EarlyModuleContext) android.A
return al.SdkVersion(ctx).ApiLevel return al.SdkVersion(ctx).ApiLevel
} }
func (al *ApiLibrary) IDEInfo(i *android.IdeInfo) { func (al *ApiLibrary) IDEInfo(ctx android.BaseModuleContext, i *android.IdeInfo) {
i.Deps = append(i.Deps, al.ideDeps()...) i.Deps = append(i.Deps, al.ideDeps(ctx)...)
i.Libs = append(i.Libs, al.properties.Libs...) i.Libs = append(i.Libs, al.properties.Libs...)
i.Static_libs = append(i.Static_libs, al.properties.Static_libs...) i.Static_libs = append(i.Static_libs, al.properties.Static_libs...)
i.SrcJars = append(i.SrcJars, al.stubsSrcJar.String()) i.SrcJars = append(i.SrcJars, al.stubsSrcJar.String())
} }
// deps of java_api_library for module_bp_java_deps.json // deps of java_api_library for module_bp_java_deps.json
func (al *ApiLibrary) ideDeps() []string { func (al *ApiLibrary) ideDeps(ctx android.BaseModuleContext) []string {
ret := []string{} ret := []string{}
ret = append(ret, al.properties.Libs...) ret = append(ret, al.properties.Libs...)
ret = append(ret, al.properties.Static_libs...) ret = append(ret, al.properties.Static_libs...)
@@ -2933,7 +2933,7 @@ var _ android.IDECustomizedModuleName = (*Import)(nil)
// Collect information for opening IDE project files in java/jdeps.go. // Collect information for opening IDE project files in java/jdeps.go.
func (j *Import) IDEInfo(dpInfo *android.IdeInfo) { func (j *Import) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
dpInfo.Jars = append(dpInfo.Jars, j.combinedHeaderFile.String()) dpInfo.Jars = append(dpInfo.Jars, j.combinedHeaderFile.String())
} }

View File

@@ -32,9 +32,7 @@ func TestCollectJavaLibraryPropertiesAddLibsDeps(t *testing.T) {
} }
`) `)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo := &android.IdeInfo{} dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
module.IDEInfo(dpInfo)
for _, expected := range []string{"Foo", "Bar"} { for _, expected := range []string{"Foo", "Bar"} {
if !android.InList(expected, dpInfo.Deps) { if !android.InList(expected, dpInfo.Deps) {
@@ -54,9 +52,7 @@ func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) {
} }
`) `)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo := &android.IdeInfo{} dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
module.IDEInfo(dpInfo)
for _, expected := range []string{"Foo", "Bar"} { for _, expected := range []string{"Foo", "Bar"} {
if !android.InList(expected, dpInfo.Deps) { if !android.InList(expected, dpInfo.Deps) {
@@ -66,26 +62,36 @@ func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) {
} }
func TestCollectJavaLibraryPropertiesAddScrs(t *testing.T) { func TestCollectJavaLibraryPropertiesAddScrs(t *testing.T) {
expected := []string{"Foo", "Bar"} ctx, _ := testJava(t,
module := LibraryFactory().(*Library) `
module.expandIDEInfoCompiledSrcs = append(module.expandIDEInfoCompiledSrcs, expected...) java_library {
dpInfo := &android.IdeInfo{} name: "javalib",
srcs: ["Foo.java", "Bar.java"],
module.IDEInfo(dpInfo) }
`)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
expected := []string{"Foo.java", "Bar.java"}
if !reflect.DeepEqual(dpInfo.Srcs, expected) { if !reflect.DeepEqual(dpInfo.Srcs, expected) {
t.Errorf("Library.IDEInfo() Srcs = %v, want %v", dpInfo.Srcs, expected) t.Errorf("Library.IDEInfo() Srcs = %v, want %v", dpInfo.Srcs, expected)
} }
} }
func TestCollectJavaLibraryPropertiesAddAidlIncludeDirs(t *testing.T) { func TestCollectJavaLibraryPropertiesAddAidlIncludeDirs(t *testing.T) {
ctx, _ := testJava(t,
`
java_library {
name: "javalib",
aidl: {
include_dirs: ["Foo", "Bar"],
},
}
`)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
expected := []string{"Foo", "Bar"} expected := []string{"Foo", "Bar"}
module := LibraryFactory().(*Library)
module.deviceProperties.Aidl.Include_dirs = append(module.deviceProperties.Aidl.Include_dirs, expected...)
dpInfo := &android.IdeInfo{}
module.IDEInfo(dpInfo)
if !reflect.DeepEqual(dpInfo.Aidl_include_dirs, expected) { if !reflect.DeepEqual(dpInfo.Aidl_include_dirs, expected) {
t.Errorf("Library.IDEInfo() Aidl_include_dirs = %v, want %v", dpInfo.Aidl_include_dirs, expected) t.Errorf("Library.IDEInfo() Aidl_include_dirs = %v, want %v", dpInfo.Aidl_include_dirs, expected)
} }
@@ -101,9 +107,8 @@ func TestCollectJavaLibraryWithJarJarRules(t *testing.T) {
} }
`) `)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo := &android.IdeInfo{} dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
module.IDEInfo(dpInfo)
android.AssertBoolEquals(t, "IdeInfo.Srcs of repackaged library should be empty", true, len(dpInfo.Srcs) == 0) android.AssertBoolEquals(t, "IdeInfo.Srcs of repackaged library should be empty", true, len(dpInfo.Srcs) == 0)
android.AssertStringEquals(t, "IdeInfo.Jar_rules of repackaged library should not be empty", "jarjar_rules.txt", dpInfo.Jarjar_rules[0]) android.AssertStringEquals(t, "IdeInfo.Jar_rules of repackaged library should not be empty", "jarjar_rules.txt", dpInfo.Jarjar_rules[0])
if !android.SubstringInList(dpInfo.Jars, "soong/.intermediates/javalib/android_common/jarjar/turbine/javalib.jar") { if !android.SubstringInList(dpInfo.Jars, "soong/.intermediates/javalib/android_common/jarjar/turbine/javalib.jar") {
@@ -125,8 +130,7 @@ func TestCollectJavaLibraryLinkingAgainstVersionedSdk(t *testing.T) {
} }
`) `)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo := &android.IdeInfo{} dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
module.IDEInfo(dpInfo)
android.AssertStringListContains(t, "IdeInfo.Deps should contain versioned sdk module", dpInfo.Deps, "sdk_public_29_android") android.AssertStringListContains(t, "IdeInfo.Deps should contain versioned sdk module", dpInfo.Deps, "sdk_public_29_android")
} }

View File

@@ -3599,8 +3599,8 @@ func (s *sdkLibrarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberCo
} }
// TODO(b/358613520): This can be removed when modules are no longer allowed to depend on the top-level library. // TODO(b/358613520): This can be removed when modules are no longer allowed to depend on the top-level library.
func (s *SdkLibrary) IDEInfo(dpInfo *android.IdeInfo) { func (s *SdkLibrary) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
s.Library.IDEInfo(dpInfo) s.Library.IDEInfo(ctx, dpInfo)
if s.implLibraryModule != nil { if s.implLibraryModule != nil {
dpInfo.Deps = append(dpInfo.Deps, s.implLibraryModule.Name()) dpInfo.Deps = append(dpInfo.Deps, s.implLibraryModule.Name())
} else { } else {

View File

@@ -307,7 +307,7 @@ func (p *systemModulesInfoProperties) AddToPropertySet(ctx android.SdkMemberCont
// implement the following interface for IDE completion. // implement the following interface for IDE completion.
var _ android.IDEInfo = (*SystemModules)(nil) var _ android.IDEInfo = (*SystemModules)(nil)
func (s *SystemModules) IDEInfo(ideInfo *android.IdeInfo) { func (s *SystemModules) IDEInfo(ctx android.BaseModuleContext, ideInfo *android.IdeInfo) {
ideInfo.Deps = append(ideInfo.Deps, s.properties.Libs...) ideInfo.Deps = append(ideInfo.Deps, s.properties.Libs...)
ideInfo.Libs = append(ideInfo.Libs, s.properties.Libs...) ideInfo.Libs = append(ideInfo.Libs, s.properties.Libs...)
} }

View File

@@ -239,7 +239,7 @@ func (s *SystemServerClasspathModule) ComponentDepsMutator(ctx android.BottomUpM
} }
// Collect information for opening IDE project files in java/jdeps.go. // Collect information for opening IDE project files in java/jdeps.go.
func (s *SystemServerClasspathModule) IDEInfo(dpInfo *android.IdeInfo) { func (s *SystemServerClasspathModule) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...) dpInfo.Deps = append(dpInfo.Deps, s.properties.Contents...)
dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...) dpInfo.Deps = append(dpInfo.Deps, s.properties.Standalone_contents...)
} }