1// Copyright 2024 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package java 16 17import ( 18 "testing" 19 20 "android/soong/android" 21) 22 23func stringPtr(v string) *string { 24 return &v 25} 26 27func TestSystemSdkFromVendor(t *testing.T) { 28 fixtures := android.GroupFixturePreparers( 29 PrepareForTestWithJavaDefaultModules, 30 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { 31 variables.Platform_sdk_version = intPtr(34) 32 variables.Platform_sdk_codename = stringPtr("VanillaIceCream") 33 variables.Platform_version_active_codenames = []string{"VanillaIceCream"} 34 variables.Platform_systemsdk_versions = []string{"33", "34", "VanillaIceCream"} 35 variables.DeviceSystemSdkVersions = []string{"VanillaIceCream"} 36 }), 37 FixtureWithPrebuiltApis(map[string][]string{ 38 "33": {}, 39 "34": {}, 40 "35": {}, 41 }), 42 ) 43 44 fixtures.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("incompatible sdk version")). 45 RunTestWithBp(t, ` 46 android_app { 47 name: "foo", 48 srcs: ["a.java"], 49 vendor: true, 50 sdk_version: "system_35", 51 }`) 52 53 result := fixtures.RunTestWithBp(t, ` 54 android_app { 55 name: "foo", 56 srcs: ["a.java"], 57 vendor: true, 58 sdk_version: "system_current", 59 }`) 60 fooModule := result.ModuleForTests("foo", "android_common") 61 fooClasspath := fooModule.Rule("javac").Args["classpath"] 62 63 android.AssertStringDoesContain(t, "foo classpath", fooClasspath, "prebuilts/sdk/34/system/android.jar") 64 android.AssertStringDoesNotContain(t, "foo classpath", fooClasspath, "prebuilts/sdk/35/system/android.jar") 65 android.AssertStringDoesNotContain(t, "foo classpath", fooClasspath, "prebuilts/sdk/current/system/android.jar") 66} 67