Merge changes Ieb9aef29,I6985ebb6

* changes:
  Propagate min and max sdk versions to classpaths.proto configs.
  Introduce max_sdk_version device property.
This commit is contained in:
Artur Satayev
2021-12-02 14:53:48 +00:00
committed by Gerrit Code Review
5 changed files with 66 additions and 7 deletions

View File

@@ -85,11 +85,10 @@ func initClasspathFragment(c classpathFragment, classpathType classpathType) {
// Matches definition of Jar in packages/modules/SdkExtensions/proto/classpaths.proto
type classpathJar struct {
path string
classpath classpathType
// TODO(satayev): propagate min/max sdk versions for the jars
minSdkVersion int32
maxSdkVersion int32
path string
classpath classpathType
minSdkVersion string
maxSdkVersion string
}
// gatherPossibleApexModuleNamesAndStems returns a set of module and stem names from the
@@ -121,10 +120,32 @@ func configuredJarListToClasspathJars(ctx android.ModuleContext, configuredJars
jars := make([]classpathJar, 0, len(paths)*len(classpaths))
for i := 0; i < len(paths); i++ {
for _, classpathType := range classpaths {
jars = append(jars, classpathJar{
jar := classpathJar{
classpath: classpathType,
path: paths[i],
}
ctx.VisitDirectDepsIf(func(m android.Module) bool {
return m.Name() == configuredJars.Jar(i)
}, func(m android.Module) {
if s, ok := m.(*SdkLibrary); ok {
// TODO(208456999): instead of mapping "current" to latest, min_sdk_version should never be set to "current"
if s.minSdkVersion.Specified() {
if s.minSdkVersion.ApiLevel.IsCurrent() {
jar.minSdkVersion = ctx.Config().LatestPreviewApiLevel().String()
} else {
jar.minSdkVersion = s.minSdkVersion.ApiLevel.String()
}
}
if s.maxSdkVersion.Specified() {
if s.maxSdkVersion.ApiLevel.IsCurrent() {
jar.maxSdkVersion = ctx.Config().LatestPreviewApiLevel().String()
} else {
jar.maxSdkVersion = s.maxSdkVersion.ApiLevel.String()
}
}
}
})
jars = append(jars, jar)
}
}
return jars
@@ -162,6 +183,7 @@ func (c *ClasspathFragmentBase) generateClasspathProtoBuildActions(ctx android.M
func writeClasspathsJson(ctx android.ModuleContext, output android.WritablePath, jars []classpathJar) {
var content strings.Builder
fmt.Fprintf(&content, "{\n")
fmt.Fprintf(&content, "\"jars\": [\n")
for idx, jar := range jars {
@@ -170,6 +192,20 @@ func writeClasspathsJson(ctx android.ModuleContext, output android.WritablePath,
fmt.Fprintf(&content, "\"path\": \"%s\",\n", jar.path)
fmt.Fprintf(&content, "\"classpath\": \"%s\"\n", jar.classpath)
if jar.minSdkVersion != "" {
fmt.Fprintf(&content, ",\n")
fmt.Fprintf(&content, "\"minSdkVersion\": \"%s\"\n", jar.minSdkVersion)
} else {
fmt.Fprintf(&content, "\n")
}
if jar.maxSdkVersion != "" {
fmt.Fprintf(&content, ",\n")
fmt.Fprintf(&content, "\"maxSdkVersion\": \"%s\"\n", jar.maxSdkVersion)
} else {
fmt.Fprintf(&content, "\n")
}
if idx < len(jars)-1 {
fmt.Fprintf(&content, "},\n")
} else {
@@ -178,6 +214,7 @@ func writeClasspathsJson(ctx android.ModuleContext, output android.WritablePath,
}
fmt.Fprintf(&content, "]\n")
fmt.Fprintf(&content, "}\n")
android.WriteFileRule(ctx, output, content.String())
}