Merge changes from topic "ctx_in_ideinfo" into main am: 9cbbafe300

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3246818

Change-Id: Ia2b721e9967c0772acd7dd261ec18315f6c26b5e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2024-08-28 00:53:10 +00:00
committed by Automerger Merge Worker
14 changed files with 79 additions and 68 deletions

View File

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

View File

@@ -287,7 +287,7 @@ func neverallowMutator(ctx BottomUpMutatorContext) {
continue
}
if !n.appliesToProperties(properties) {
if !n.appliesToProperties(ctx, properties) {
continue
}
@@ -604,9 +604,9 @@ func (r *rule) appliesToModuleType(moduleType string) bool {
return (len(r.moduleTypes) == 0 || InList(moduleType, r.moduleTypes)) && !InList(moduleType, r.unlessModuleTypes)
}
func (r *rule) appliesToProperties(properties []interface{}) bool {
includeProps := hasAllProperties(properties, r.props)
excludeProps := hasAnyProperty(properties, r.unlessProps)
func (r *rule) appliesToProperties(ctx BottomUpMutatorContext, properties []interface{}) bool {
includeProps := hasAllProperties(ctx, properties, r.props)
excludeProps := hasAnyProperty(ctx, properties, r.unlessProps)
return includeProps && !excludeProps
}
@@ -644,25 +644,25 @@ func fieldNamesForProperties(propertyNames string) []string {
return names
}
func hasAnyProperty(properties []interface{}, props []ruleProperty) bool {
func hasAnyProperty(ctx BottomUpMutatorContext, properties []interface{}, props []ruleProperty) bool {
for _, v := range props {
if hasProperty(properties, v) {
if hasProperty(ctx, properties, v) {
return true
}
}
return false
}
func hasAllProperties(properties []interface{}, props []ruleProperty) bool {
func hasAllProperties(ctx BottomUpMutatorContext, properties []interface{}, props []ruleProperty) bool {
for _, v := range props {
if !hasProperty(properties, v) {
if !hasProperty(ctx, properties, v) {
return false
}
}
return true
}
func hasProperty(properties []interface{}, prop ruleProperty) bool {
func hasProperty(ctx BottomUpMutatorContext, properties []interface{}, prop ruleProperty) bool {
for _, propertyStruct := range properties {
propertiesValue := reflect.ValueOf(propertyStruct).Elem()
for _, v := range prop.fields {
@@ -679,14 +679,14 @@ func hasProperty(properties []interface{}, prop ruleProperty) bool {
return prop.matcher.Test(value)
}
if matchValue(propertiesValue, check) {
if matchValue(ctx, propertiesValue, check) {
return true
}
}
return false
}
func matchValue(value reflect.Value, check func(string) bool) bool {
func matchValue(ctx BottomUpMutatorContext, value reflect.Value, check func(string) bool) bool {
if !value.IsValid() {
return false
}
@@ -698,19 +698,26 @@ func matchValue(value reflect.Value, check func(string) bool) bool {
value = value.Elem()
}
switch value.Kind() {
case reflect.String:
return check(value.String())
case reflect.Bool:
return check(strconv.FormatBool(value.Bool()))
case reflect.Int:
return check(strconv.FormatInt(value.Int(), 10))
case reflect.Slice:
slice, ok := value.Interface().([]string)
if !ok {
panic("Can only handle slice of string")
switch v := value.Interface().(type) {
case string:
return check(v)
case bool:
return check(strconv.FormatBool(v))
case int:
return check(strconv.FormatInt((int64)(v), 10))
case []string:
for _, v := range v {
if check(v) {
return true
}
}
for _, v := range slice {
return false
case proptools.Configurable[string]:
return check(v.GetOrDefault(ctx, ""))
case proptools.Configurable[bool]:
return check(strconv.FormatBool(v.GetOrDefault(ctx, false)))
case proptools.Configurable[[]string]:
for _, v := range v.GetOrDefault(ctx, nil) {
if check(v) {
return true
}

View File

@@ -2873,7 +2873,7 @@ func isStaticExecutableAllowed(apex string, exec string) bool {
}
// 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.Bootclasspath_fragments...)
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.
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()...)
for _, src := range g.properties.ResolvedSrcs {
if strings.HasPrefix(src, ":") {

View File

@@ -914,12 +914,12 @@ func (a *AndroidLibrary) setOutputFiles(ctx android.ModuleContext) {
setOutputFiles(ctx, a.Library.Module)
}
func (a *AndroidLibrary) IDEInfo(dpInfo *android.IdeInfo) {
a.Library.IDEInfo(dpInfo)
a.aapt.IDEInfo(dpInfo)
func (a *AndroidLibrary) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
a.Library.IDEInfo(ctx, 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 {
dpInfo.Jars = append(dpInfo.Jars, a.rJar.String())
}
@@ -1451,6 +1451,6 @@ func AARImportFactory() android.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())
}

View File

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

View File

@@ -2044,7 +2044,7 @@ func (j *Module) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {
}
// 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
// repackaged jar instead of the input sources.
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.
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...)
}

View File

@@ -192,7 +192,7 @@ func (d *DeviceHostConverter) AndroidMk() android.AndroidMkData {
// implement the following interface for IDE completion.
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.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
}
func (al *ApiLibrary) IDEInfo(i *android.IdeInfo) {
i.Deps = append(i.Deps, al.ideDeps()...)
func (al *ApiLibrary) IDEInfo(ctx android.BaseModuleContext, i *android.IdeInfo) {
i.Deps = append(i.Deps, al.ideDeps(ctx)...)
i.Libs = append(i.Libs, al.properties.Libs...)
i.Static_libs = append(i.Static_libs, al.properties.Static_libs...)
i.SrcJars = append(i.SrcJars, al.stubsSrcJar.String())
}
// 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 = append(ret, al.properties.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.
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())
}

View File

@@ -32,9 +32,7 @@ func TestCollectJavaLibraryPropertiesAddLibsDeps(t *testing.T) {
}
`)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo := &android.IdeInfo{}
module.IDEInfo(dpInfo)
dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
for _, expected := range []string{"Foo", "Bar"} {
if !android.InList(expected, dpInfo.Deps) {
@@ -54,9 +52,7 @@ func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) {
}
`)
module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
dpInfo := &android.IdeInfo{}
module.IDEInfo(dpInfo)
dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
for _, expected := range []string{"Foo", "Bar"} {
if !android.InList(expected, dpInfo.Deps) {
@@ -66,26 +62,36 @@ func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) {
}
func TestCollectJavaLibraryPropertiesAddScrs(t *testing.T) {
expected := []string{"Foo", "Bar"}
module := LibraryFactory().(*Library)
module.expandIDEInfoCompiledSrcs = append(module.expandIDEInfoCompiledSrcs, expected...)
dpInfo := &android.IdeInfo{}
module.IDEInfo(dpInfo)
ctx, _ := testJava(t,
`
java_library {
name: "javalib",
srcs: ["Foo.java", "Bar.java"],
}
`)
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) {
t.Errorf("Library.IDEInfo() Srcs = %v, want %v", dpInfo.Srcs, expected)
}
}
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"}
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) {
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)
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.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") {
@@ -125,8 +130,7 @@ func TestCollectJavaLibraryLinkingAgainstVersionedSdk(t *testing.T) {
}
`)
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")
}

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.
func (s *SdkLibrary) IDEInfo(dpInfo *android.IdeInfo) {
s.Library.IDEInfo(dpInfo)
func (s *SdkLibrary) IDEInfo(ctx android.BaseModuleContext, dpInfo *android.IdeInfo) {
s.Library.IDEInfo(ctx, dpInfo)
if s.implLibraryModule != nil {
dpInfo.Deps = append(dpInfo.Deps, s.implLibraryModule.Name())
} else {

View File

@@ -307,7 +307,7 @@ func (p *systemModulesInfoProperties) AddToPropertySet(ctx android.SdkMemberCont
// implement the following interface for IDE completion.
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.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.
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.Standalone_contents...)
}