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

Commit cd05792d authored by Spandan Das's avatar Spandan Das Committed by Gerrit Code Review
Browse files

Merge changes from topic "revert-2457063-EKFSKANQWZ"

* changes:
  Revert "Create two sentinel api levels"
  Revert "Create EffectiveVersion* functions for ApiLevel"
  Revert "Prework for migrating min_sdk_version from (kind+level) ..."
  Revert "Always include host variants in the sdk snapshot"
  Revert "Update min_sdk_version from SdkSpec to ApiLevel"
parents 52cb409e ac96191f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -845,7 +845,7 @@ type WalkPayloadDepsFunc func(ctx ModuleContext, do PayloadDepsCallback)
// ModuleWithMinSdkVersionCheck represents a module that implements min_sdk_version checks
type ModuleWithMinSdkVersionCheck interface {
	Module
	MinSdkVersion(ctx EarlyModuleContext) ApiLevel
	MinSdkVersion(ctx EarlyModuleContext) SdkSpec
	CheckMinSdkVersion(ctx ModuleContext)
}

+0 −103
Original line number Diff line number Diff line
@@ -55,9 +55,6 @@ type ApiLevel struct {
}

func (this ApiLevel) FinalInt() int {
	if this.IsInvalid() {
		panic(fmt.Errorf("%v is not a recognized api_level\n", this))
	}
	if this.IsPreview() {
		panic("Requested a final int from a non-final ApiLevel")
	} else {
@@ -66,9 +63,6 @@ func (this ApiLevel) FinalInt() int {
}

func (this ApiLevel) FinalOrFutureInt() int {
	if this.IsInvalid() {
		panic(fmt.Errorf("%v is not a recognized api_level\n", this))
	}
	if this.IsPreview() {
		return FutureApiLevelInt
	} else {
@@ -82,9 +76,6 @@ func (this ApiLevel) FinalOrFutureInt() int {
// - preview codenames -> preview base (9000) + index
// - otherwise -> cast to int
func (this ApiLevel) FinalOrPreviewInt() int {
	if this.IsInvalid() {
		panic(fmt.Errorf("%v is not a recognized api_level\n", this))
	}
	if this.IsCurrent() {
		return this.number
	}
@@ -106,11 +97,6 @@ func (this ApiLevel) IsPreview() bool {
	return this.isPreview
}

// Returns true if the raw api level string is invalid
func (this ApiLevel) IsInvalid() bool {
	return this.EqualTo(InvalidApiLevel)
}

// Returns true if this is the unfinalized "current" API level. This means
// different things across Java and native. Java APIs do not use explicit
// codenames, so all non-final codenames are grouped into "current". For native
@@ -127,72 +113,6 @@ func (this ApiLevel) IsNone() bool {
	return this.number == -1
}

// Returns true if an app is compiling against private apis.
// e.g. if sdk_version = "" in Android.bp, then the ApiLevel of that "sdk" is at PrivateApiLevel.
func (this ApiLevel) IsPrivate() bool {
	return this.number == PrivateApiLevel.number
}

// EffectiveVersion converts an ApiLevel into the concrete ApiLevel that the module should use. For
// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns
// FutureApiLevel(10000).
func (l ApiLevel) EffectiveVersion(ctx EarlyModuleContext) (ApiLevel, error) {
	if l.EqualTo(InvalidApiLevel) {
		return l, fmt.Errorf("invalid version in sdk_version %q", l.value)
	}
	if !l.IsPreview() {
		return l, nil
	}
	ret := ctx.Config().DefaultAppTargetSdk(ctx)
	if ret.IsPreview() {
		return FutureApiLevel, nil
	}
	return ret, nil
}

// EffectiveVersionString converts an SdkSpec into the concrete version string that the module
// should use. For modules targeting an unreleased SDK (meaning it does not yet have a number)
// it returns the codename (P, Q, R, etc.)
func (l ApiLevel) EffectiveVersionString(ctx EarlyModuleContext) (string, error) {
	if l.EqualTo(InvalidApiLevel) {
		return l.value, fmt.Errorf("invalid version in sdk_version %q", l.value)
	}
	if !l.IsPreview() {
		return l.String(), nil
	}
	// Determine the default sdk
	ret := ctx.Config().DefaultAppTargetSdk(ctx)
	if !ret.IsPreview() {
		// If the default sdk has been finalized, return that
		return ret.String(), nil
	}
	// There can be more than one active in-development sdks
	// If an app is targeting an active sdk, but not the default one, return the requested active sdk.
	// e.g.
	// SETUP
	// In-development: UpsideDownCake, VanillaIceCream
	// Default: VanillaIceCream
	// Android.bp
	// min_sdk_version: `UpsideDownCake`
	// RETURN
	// UpsideDownCake and not VanillaIceCream
	for _, preview := range ctx.Config().PreviewApiLevels() {
		if l.String() == preview.String() {
			return preview.String(), nil
		}
	}
	// Otherwise return the default one
	return ret.String(), nil
}

// Specified returns true if the module is targeting a recognzized api_level.
// It returns false if either
// 1. min_sdk_version is not an int or a recognized codename
// 2. both min_sdk_version and sdk_version are empty. In this case, MinSdkVersion() defaults to SdkSpecPrivate.ApiLevel
func (this ApiLevel) Specified() bool {
	return !this.IsInvalid() && !this.IsPrivate()
}

// Returns -1 if the current API level is less than the argument, 0 if they
// are equal, and 1 if it is greater than the argument.
func (this ApiLevel) CompareTo(other ApiLevel) int {
@@ -246,19 +166,6 @@ var NoneApiLevel = ApiLevel{
	isPreview: true,
}

// Sentinel ApiLevel to validate that an apiLevel is either an int or a recognized codename.
var InvalidApiLevel = NewInvalidApiLevel("invalid")

// Returns an apiLevel object at the same level as InvalidApiLevel.
// The object contains the raw string provied in bp file, and can be used for error handling.
func NewInvalidApiLevel(raw string) ApiLevel {
	return ApiLevel{
		value:     raw,
		number:    -2, // One less than NoneApiLevel
		isPreview: true,
	}
}

// The first version that introduced 64-bit ABIs.
var FirstLp64Version = uncheckedFinalApiLevel(21)

@@ -297,16 +204,6 @@ func ReplaceFinalizedCodenames(config Config, raw string) string {
	return strconv.Itoa(num)
}

// ApiLevelFrom converts the given string `raw` to an ApiLevel.
// If `raw` is invalid (empty string, unrecognized codename etc.) it returns an invalid ApiLevel
func ApiLevelFrom(ctx PathContext, raw string) ApiLevel {
	ret, err := ApiLevelFromUser(ctx, raw)
	if err != nil {
		return NewInvalidApiLevel(raw)
	}
	return ret
}

// ApiLevelFromUser converts the given string `raw` to an ApiLevel, possibly returning an error.
//
// `raw` must be non-empty. Passing an empty string results in a panic.
+0 −9
Original line number Diff line number Diff line
@@ -52,15 +52,6 @@ var StringDefault = proptools.StringDefault
// FutureApiLevelInt is a placeholder constant for unreleased API levels.
const FutureApiLevelInt = 10000

// PrivateApiLevel represents the api level of SdkSpecPrivate (sdk_version: "")
// This api_level exists to differentiate user-provided "" from "current" sdk_version
// The differentiation is necessary to enable different validation rules for these two possible values.
var PrivateApiLevel = ApiLevel{
	value:     "current",             // The value is current since aidl expects `current` as the default (TestAidlFlagsWithMinSdkVersion)
	number:    FutureApiLevelInt + 1, // This is used to differentiate it from FutureApiLevel
	isPreview: true,
}

// FutureApiLevel represents unreleased API levels.
var FutureApiLevel = ApiLevel{
	value:     "current",
+2 −2
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import (

// minApiLevelForSdkSnapshot provides access to the min_sdk_version for MinApiLevelForSdkSnapshot
type minApiLevelForSdkSnapshot interface {
	MinSdkVersion(ctx EarlyModuleContext) ApiLevel
	MinSdkVersion(ctx EarlyModuleContext) SdkSpec
}

// MinApiLevelForSdkSnapshot returns the ApiLevel of the min_sdk_version of the supplied module.
@@ -34,7 +34,7 @@ type minApiLevelForSdkSnapshot interface {
func MinApiLevelForSdkSnapshot(ctx EarlyModuleContext, module Module) ApiLevel {
	minApiLevel := NoneApiLevel
	if m, ok := module.(minApiLevelForSdkSnapshot); ok {
		minApiLevel = m.MinSdkVersion(ctx)
		minApiLevel = m.MinSdkVersion(ctx).ApiLevel
	}
	if minApiLevel == NoneApiLevel {
		// The default min API level is 1.
+39 −7
Original line number Diff line number Diff line
@@ -25,9 +25,9 @@ type SdkContext interface {
	SdkVersion(ctx EarlyModuleContext) SdkSpec
	// SystemModules returns the system_modules property of the current module, or an empty string if it is not set.
	SystemModules() string
	// MinSdkVersion returns ApiLevel that corresponds to the min_sdk_version property of the current module,
	// MinSdkVersion returns SdkSpec that corresponds to the min_sdk_version property of the current module,
	// or from sdk_version if it is not set.
	MinSdkVersion(ctx EarlyModuleContext) ApiLevel
	MinSdkVersion(ctx EarlyModuleContext) SdkSpec
	// ReplaceMaxSdkVersionPlaceholder returns SdkSpec to replace the maxSdkVersion property of permission and
	// uses-permission tags if it is set.
	ReplaceMaxSdkVersionPlaceholder(ctx EarlyModuleContext) SdkSpec
@@ -187,7 +187,14 @@ func (s SdkSpec) EffectiveVersion(ctx EarlyModuleContext) (ApiLevel, error) {
	if ctx.DeviceSpecific() || ctx.SocSpecific() {
		s = s.ForVendorPartition(ctx)
	}
	return s.ApiLevel.EffectiveVersion(ctx)
	if !s.ApiLevel.IsPreview() {
		return s.ApiLevel, nil
	}
	ret := ctx.Config().DefaultAppTargetSdk(ctx)
	if ret.IsPreview() {
		return FutureApiLevel, nil
	}
	return ret, nil
}

// EffectiveVersionString converts an SdkSpec into the concrete version string that the module
@@ -201,12 +208,37 @@ func (s SdkSpec) EffectiveVersionString(ctx EarlyModuleContext) (string, error)
	if ctx.DeviceSpecific() || ctx.SocSpecific() {
		s = s.ForVendorPartition(ctx)
	}
	return s.ApiLevel.EffectiveVersionString(ctx)
	if !s.ApiLevel.IsPreview() {
		return s.ApiLevel.String(), nil
	}
	// Determine the default sdk
	ret := ctx.Config().DefaultAppTargetSdk(ctx)
	if !ret.IsPreview() {
		// If the default sdk has been finalized, return that
		return ret.String(), nil
	}
	// There can be more than one active in-development sdks
	// If an app is targeting an active sdk, but not the default one, return the requested active sdk.
	// e.g.
	// SETUP
	// In-development: UpsideDownCake, VanillaIceCream
	// Default: VanillaIceCream
	// Android.bp
	// min_sdk_version: `UpsideDownCake`
	// RETURN
	// UpsideDownCake and not VanillaIceCream
	for _, preview := range ctx.Config().PreviewApiLevels() {
		if s.ApiLevel.String() == preview.String() {
			return preview.String(), nil
		}
	}
	// Otherwise return the default one
	return ret.String(), nil
}

var (
	SdkSpecNone         = SdkSpec{SdkNone, NoneApiLevel, "(no version)"}
	SdkSpecPrivate      = SdkSpec{SdkPrivate, PrivateApiLevel, ""}
	SdkSpecPrivate      = SdkSpec{SdkPrivate, FutureApiLevel, ""}
	SdkSpecCorePlatform = SdkSpec{SdkCorePlatform, FutureApiLevel, "core_platform"}
)

@@ -229,7 +261,7 @@ func SdkSpecFromWithConfig(config Config, str string) SdkSpec {

		var kindString string
		if sep == 0 {
			return SdkSpec{SdkInvalid, NewInvalidApiLevel(str), str}
			return SdkSpec{SdkInvalid, NoneApiLevel, str}
		} else if sep == -1 {
			kindString = ""
		} else {
@@ -257,7 +289,7 @@ func SdkSpecFromWithConfig(config Config, str string) SdkSpec {

		apiLevel, err := ApiLevelFromUserWithConfig(config, versionString)
		if err != nil {
			return SdkSpec{SdkInvalid, NewInvalidApiLevel(versionString), str}
			return SdkSpec{SdkInvalid, apiLevel, str}
		}
		return SdkSpec{kind, apiLevel, str}
	}
Loading