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 t.Parallel() 29 fixtures := android.GroupFixturePreparers( 30 PrepareForTestWithJavaDefaultModules, 31 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { 32 variables.Platform_sdk_version = intPtr(34) 33 variables.Platform_sdk_codename = stringPtr("VanillaIceCream") 34 variables.Platform_version_active_codenames = []string{"VanillaIceCream"} 35 variables.Platform_systemsdk_versions = []string{"33", "34", "VanillaIceCream"} 36 variables.DeviceSystemSdkVersions = []string{"VanillaIceCream"} 37 }), 38 FixtureWithPrebuiltApis(map[string][]string{ 39 "33": {}, 40 "34": {}, 41 "35": {}, 42 }), 43 ) 44 45 fixtures.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern("incompatible sdk version")). 46 RunTestWithBp(t, ` 47 android_app { 48 name: "foo", 49 srcs: ["a.java"], 50 vendor: true, 51 sdk_version: "system_35", 52 }`) 53 54 result := fixtures.RunTestWithBp(t, ` 55 android_app { 56 name: "foo", 57 srcs: ["a.java"], 58 vendor: true, 59 sdk_version: "system_current", 60 }`) 61 fooModule := result.ModuleForTests(t, "foo", "android_common") 62 fooClasspath := fooModule.Rule("javac").Args["classpath"] 63 64 android.AssertStringDoesContain(t, "foo classpath", fooClasspath, "prebuilts/sdk/34/system/android.jar") 65 android.AssertStringDoesNotContain(t, "foo classpath", fooClasspath, "prebuilts/sdk/35/system/android.jar") 66 android.AssertStringDoesNotContain(t, "foo classpath", fooClasspath, "prebuilts/sdk/current/system/android.jar") 67} 68