summaryrefslogtreecommitdiff
path: root/java/classpath_fragment.go
diff options
context:
space:
mode:
author Artur Satayev <satayev@google.com> 2021-12-02 14:53:48 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2021-12-02 14:53:48 +0000
commitfb0a7234d7b4190911f59bd82a18f6e0b1f8c210 (patch)
tree44764745d2cdea2f4931f6f0eebe400358a11a34 /java/classpath_fragment.go
parenteca59f3deecf7fc14a4c9cbee2b0e14b2e34cb66 (diff)
parentcca4ab762eab320fb9beaad61a51969e16127833 (diff)
Merge changes Ieb9aef29,I6985ebb6
* changes: Propagate min and max sdk versions to classpaths.proto configs. Introduce max_sdk_version device property.
Diffstat (limited to 'java/classpath_fragment.go')
-rw-r--r--java/classpath_fragment.go49
1 files changed, 43 insertions, 6 deletions
diff --git a/java/classpath_fragment.go b/java/classpath_fragment.go
index d1d9e73da..0c792d80b 100644
--- a/java/classpath_fragment.go
+++ b/java/classpath_fragment.go
@@ -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())
}