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

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

Merge "Test SdkSpecForm."

parents c01a5cd7 0ee2f913
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ bootstrap_go_package {
        "paths_test.go",
        "prebuilt_test.go",
        "rule_builder_test.go",
        "sdk_version_test.go",
        "sdk_test.go",
        "singleton_module_test.go",
        "soong_config_modules_test.go",
+11 −5
Original line number Diff line number Diff line
@@ -192,8 +192,8 @@ var LastWithoutModuleLibCoreSystemModules = uncheckedFinalApiLevel(31)
// * "30" -> "30"
// * "R" -> "30"
// * "S" -> "S"
func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
	num, ok := getFinalCodenamesMap(ctx.Config())[raw]
func ReplaceFinalizedCodenames(config Config, raw string) string {
	num, ok := getFinalCodenamesMap(config)[raw]
	if !ok {
		return raw
	}
@@ -201,7 +201,7 @@ func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
	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.
//
@@ -216,6 +216,12 @@ func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
// Inputs that are not "current", known previews, or convertible to an integer
// will return an 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 == "" {
		panic("API level string must be non-empty")
	}
@@ -224,13 +230,13 @@ func ApiLevelFromUser(ctx PathContext, raw string) (ApiLevel, error) {
		return FutureApiLevel, nil
	}

	for _, preview := range ctx.Config().PreviewApiLevels() {
	for _, preview := range config.PreviewApiLevels() {
		if raw == preview.String() {
			return preview, nil
		}
	}

	canonical := ReplaceFinalizedCodenames(ctx, raw)
	canonical := ReplaceFinalizedCodenames(config, raw)
	asInt, err := strconv.Atoi(canonical)
	if err != nil {
		return NoneApiLevel, fmt.Errorf("%q could not be parsed as an integer and is not a recognized codename", canonical)
+6 −2
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ func (s SdkSpec) Stable() bool {
	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.
func (s SdkSpec) PrebuiltSdkAvailableForUnbundledBuild() bool {
	// "", "none", and "core_platform" are not available for unbundled build
@@ -212,6 +212,10 @@ var (
)

func SdkSpecFrom(ctx EarlyModuleContext, str string) SdkSpec {
	return SdkSpecFromWithConfig(ctx.Config(), str)
}

func SdkSpecFromWithConfig(config Config, str string) SdkSpec {
	switch str {
	// special cases first
	case "":
@@ -252,7 +256,7 @@ func SdkSpecFrom(ctx EarlyModuleContext, str string) SdkSpec {
			return SdkSpec{SdkInvalid, NoneApiLevel, str}
		}

		apiLevel, err := ApiLevelFromUser(ctx, versionString)
		apiLevel, err := ApiLevelFromUserWithConfig(config, versionString)
		if err != nil {
			return SdkSpec{SdkInvalid, apiLevel, str}
		}
+89 −0
Original line number Diff line number Diff line
// 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)
		}
	}
}