blob: 03d55f70aeeddd310f8f215fc6855c620853b858 [file] [log] [blame]
Jiyong Park7416d672024-01-04 23:20:42 +00001// 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) {
Colin Cross844cb6a2025-01-29 15:53:21 -080028 t.Parallel()
Jiyong Park7416d672024-01-04 23:20:42 +000029 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 }`)
Colin Cross90607e92025-02-11 14:58:07 -080061 fooModule := result.ModuleForTests(t, "foo", "android_common")
Jiyong Park7416d672024-01-04 23:20:42 +000062 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}