Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb0a7234 authored by Artur Satayev's avatar Artur Satayev Committed by Gerrit Code Review
Browse files

Merge changes Ieb9aef29,I6985ebb6

* changes:
  Propagate min and max sdk versions to classpaths.proto configs.
  Introduce max_sdk_version device property.
parents eca59f3d cca4ab76
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -765,6 +765,16 @@ func (c *config) PreviewApiLevels() []ApiLevel {
	return levels
}

func (c *config) LatestPreviewApiLevel() ApiLevel {
	level := NoneApiLevel
	for _, l := range c.PreviewApiLevels() {
		if l.GreaterThan(level) {
			level = l
		}
	}
	return level
}

func (c *config) AllSupportedApiLevels() []ApiLevel {
	var levels []ApiLevel
	levels = append(levels, c.FinalApiLevels()...)
+12 −0
Original line number Diff line number Diff line
@@ -197,6 +197,10 @@ type DeviceProperties struct {
	// Defaults to sdk_version if not set. See sdk_version for possible values.
	Min_sdk_version *string

	// if not blank, set the maximum version of the sdk that the compiled artifacts will run against.
	// Defaults to empty string "". See sdk_version for possible values.
	Max_sdk_version *string

	// if not blank, set the targetSdkVersion in the AndroidManifest.xml.
	// Defaults to sdk_version if not set. See sdk_version for possible values.
	Target_sdk_version *string
@@ -460,6 +464,7 @@ type Module struct {

	sdkVersion    android.SdkSpec
	minSdkVersion android.SdkSpec
	maxSdkVersion android.SdkSpec
}

func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
@@ -617,6 +622,13 @@ func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
	return j.SdkVersion(ctx)
}

func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
	maxSdkVersion := proptools.StringDefault(j.deviceProperties.Max_sdk_version, "")
	// SdkSpecFrom returns SdkSpecPrivate for this, which may be confusing.
	// TODO(b/208456999): ideally MaxSdkVersion should be an ApiLevel and not SdkSpec.
	return android.SdkSpecFrom(ctx, maxSdkVersion)
}

func (j *Module) MinSdkVersionString() string {
	return j.minSdkVersion.Raw
}
+43 −6
Original line number Diff line number Diff line
@@ -87,9 +87,8 @@ func initClasspathFragment(c classpathFragment, classpathType classpathType) {
type classpathJar struct {
	path          string
	classpath     classpathType
	// TODO(satayev): propagate min/max sdk versions for the jars
	minSdkVersion int32
	maxSdkVersion int32
	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())
}

+1 −0
Original line number Diff line number Diff line
@@ -550,6 +550,7 @@ func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	j.sdkVersion = j.SdkVersion(ctx)
	j.minSdkVersion = j.MinSdkVersion(ctx)
	j.maxSdkVersion = j.MaxSdkVersion(ctx)

	apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
	if !apexInfo.IsForPlatform() {
+0 −1
Original line number Diff line number Diff line
@@ -68,7 +68,6 @@ type platformBootclasspathProperties struct {
func platformBootclasspathFactory() android.SingletonModule {
	m := &platformBootclasspathModule{}
	m.AddProperties(&m.properties)
	// TODO(satayev): split apex jars into separate configs.
	initClasspathFragment(m, BOOTCLASSPATH)
	android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
	return m