Merge "Test SdkSpecForm." am: a71eabb705
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1907852 Change-Id: Ie33a2c35cf7939494a5efecb5139bed3213c92fb
This commit is contained in:
@@ -113,6 +113,7 @@ bootstrap_go_package {
|
|||||||
"paths_test.go",
|
"paths_test.go",
|
||||||
"prebuilt_test.go",
|
"prebuilt_test.go",
|
||||||
"rule_builder_test.go",
|
"rule_builder_test.go",
|
||||||
|
"sdk_version_test.go",
|
||||||
"sdk_test.go",
|
"sdk_test.go",
|
||||||
"singleton_module_test.go",
|
"singleton_module_test.go",
|
||||||
"soong_config_modules_test.go",
|
"soong_config_modules_test.go",
|
||||||
|
@@ -192,8 +192,8 @@ var LastWithoutModuleLibCoreSystemModules = uncheckedFinalApiLevel(31)
|
|||||||
// * "30" -> "30"
|
// * "30" -> "30"
|
||||||
// * "R" -> "30"
|
// * "R" -> "30"
|
||||||
// * "S" -> "S"
|
// * "S" -> "S"
|
||||||
func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
|
func ReplaceFinalizedCodenames(config Config, raw string) string {
|
||||||
num, ok := getFinalCodenamesMap(ctx.Config())[raw]
|
num, ok := getFinalCodenamesMap(config)[raw]
|
||||||
if !ok {
|
if !ok {
|
||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
|
|||||||
return strconv.Itoa(num)
|
return strconv.Itoa(num)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts the given string `raw` to an ApiLevel, possibly returning an error.
|
// 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.
|
// `raw` must be non-empty. Passing an empty string results in a panic.
|
||||||
//
|
//
|
||||||
@@ -216,6 +216,12 @@ func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
|
|||||||
// Inputs that are not "current", known previews, or convertible to an integer
|
// Inputs that are not "current", known previews, or convertible to an integer
|
||||||
// will return an error.
|
// will return an error.
|
||||||
func ApiLevelFromUser(ctx PathContext, raw string) (ApiLevel, error) {
|
func ApiLevelFromUser(ctx PathContext, raw string) (ApiLevel, error) {
|
||||||
|
return ApiLevelFromUserWithConfig(ctx.Config(), raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApiLevelFromUserWithConfig implements ApiLevelFromUser, see comments for
|
||||||
|
// ApiLevelFromUser for more details.
|
||||||
|
func ApiLevelFromUserWithConfig(config Config, raw string) (ApiLevel, error) {
|
||||||
if raw == "" {
|
if raw == "" {
|
||||||
panic("API level string must be non-empty")
|
panic("API level string must be non-empty")
|
||||||
}
|
}
|
||||||
@@ -224,13 +230,13 @@ func ApiLevelFromUser(ctx PathContext, raw string) (ApiLevel, error) {
|
|||||||
return FutureApiLevel, nil
|
return FutureApiLevel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, preview := range ctx.Config().PreviewApiLevels() {
|
for _, preview := range config.PreviewApiLevels() {
|
||||||
if raw == preview.String() {
|
if raw == preview.String() {
|
||||||
return preview, nil
|
return preview, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
canonical := ReplaceFinalizedCodenames(ctx, raw)
|
canonical := ReplaceFinalizedCodenames(config, raw)
|
||||||
asInt, err := strconv.Atoi(canonical)
|
asInt, err := strconv.Atoi(canonical)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NoneApiLevel, fmt.Errorf("%q could not be parsed as an integer and is not a recognized codename", canonical)
|
return NoneApiLevel, fmt.Errorf("%q could not be parsed as an integer and is not a recognized codename", canonical)
|
||||||
|
@@ -117,7 +117,7 @@ func (s SdkSpec) Stable() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrebuiltSdkAvailableForUnbundledBuilt tells whether this SdkSpec can have a prebuilt SDK
|
// PrebuiltSdkAvailableForUnbundledBuild tells whether this SdkSpec can have a prebuilt SDK
|
||||||
// that can be used for unbundled builds.
|
// that can be used for unbundled builds.
|
||||||
func (s SdkSpec) PrebuiltSdkAvailableForUnbundledBuild() bool {
|
func (s SdkSpec) PrebuiltSdkAvailableForUnbundledBuild() bool {
|
||||||
// "", "none", and "core_platform" are not available for unbundled build
|
// "", "none", and "core_platform" are not available for unbundled build
|
||||||
@@ -212,6 +212,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func SdkSpecFrom(ctx EarlyModuleContext, str string) SdkSpec {
|
func SdkSpecFrom(ctx EarlyModuleContext, str string) SdkSpec {
|
||||||
|
return SdkSpecFromWithConfig(ctx.Config(), str)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SdkSpecFromWithConfig(config Config, str string) SdkSpec {
|
||||||
switch str {
|
switch str {
|
||||||
// special cases first
|
// special cases first
|
||||||
case "":
|
case "":
|
||||||
@@ -252,7 +256,7 @@ func SdkSpecFrom(ctx EarlyModuleContext, str string) SdkSpec {
|
|||||||
return SdkSpec{SdkInvalid, NoneApiLevel, str}
|
return SdkSpec{SdkInvalid, NoneApiLevel, str}
|
||||||
}
|
}
|
||||||
|
|
||||||
apiLevel, err := ApiLevelFromUser(ctx, versionString)
|
apiLevel, err := ApiLevelFromUserWithConfig(config, versionString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SdkSpec{SdkInvalid, apiLevel, str}
|
return SdkSpec{SdkInvalid, apiLevel, str}
|
||||||
}
|
}
|
||||||
|
89
android/sdk_version_test.go
Normal file
89
android/sdk_version_test.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
// Copyright 2015 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package android
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSdkSpecFrom(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
input string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: "",
|
||||||
|
expected: "private_current",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "none",
|
||||||
|
expected: "none_(no version)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "core_platform",
|
||||||
|
expected: "core_platform_current",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "_",
|
||||||
|
expected: "invalid_(no version)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "_31",
|
||||||
|
expected: "invalid_(no version)",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "system_R",
|
||||||
|
expected: "system_30",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "test_31",
|
||||||
|
expected: "test_31",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "module_current",
|
||||||
|
expected: "module-lib_current",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "31",
|
||||||
|
expected: "public_31",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "S",
|
||||||
|
expected: "public_31",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "current",
|
||||||
|
expected: "public_current",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "Tiramisu",
|
||||||
|
expected: "public_Tiramisu",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
config := NullConfig("", "")
|
||||||
|
|
||||||
|
config.productVariables = productVariables{
|
||||||
|
Platform_sdk_version: intPtr(31),
|
||||||
|
Platform_sdk_codename: stringPtr("Tiramisu"),
|
||||||
|
Platform_version_active_codenames: []string{"Tiramisu"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
if got := SdkSpecFromWithConfig(config, tc.input).String(); tc.expected != got {
|
||||||
|
t.Errorf("Expected %v, got %v", tc.expected, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user