blob: d282f1976df0f724c862f8096b70d477549f97bf [file] [log] [blame]
Brandon Lee5d45c6f2018-08-15 15:35:38 -07001// Copyright 2018 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 "reflect"
19 "testing"
20
21 "android/soong/android"
22)
23
24func TestCollectJavaLibraryPropertiesAddLibsDeps(t *testing.T) {
Spandan Das8aac9932024-07-18 23:14:13 +000025 ctx, _ := testJava(t,
26 `
27 java_library {name: "Foo"}
28 java_library {name: "Bar"}
29 java_library {
30 name: "javalib",
31 libs: ["Foo", "Bar"],
32 }
33 `)
34 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
Cole Faustb36d31d2024-08-27 16:04:28 -070035 dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
Brandon Lee5d45c6f2018-08-15 15:35:38 -070036
Spandan Das8aac9932024-07-18 23:14:13 +000037 for _, expected := range []string{"Foo", "Bar"} {
38 if !android.InList(expected, dpInfo.Deps) {
39 t.Errorf("Library.IDEInfo() Deps = %v, %v not found", dpInfo.Deps, expected)
40 }
Brandon Lee5d45c6f2018-08-15 15:35:38 -070041 }
42}
43
44func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) {
Spandan Das8aac9932024-07-18 23:14:13 +000045 ctx, _ := testJava(t,
46 `
47 java_library {name: "Foo"}
48 java_library {name: "Bar"}
49 java_library {
50 name: "javalib",
51 static_libs: ["Foo", "Bar"],
52 }
53 `)
54 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
Cole Faustb36d31d2024-08-27 16:04:28 -070055 dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
Brandon Lee5d45c6f2018-08-15 15:35:38 -070056
Spandan Das8aac9932024-07-18 23:14:13 +000057 for _, expected := range []string{"Foo", "Bar"} {
58 if !android.InList(expected, dpInfo.Deps) {
59 t.Errorf("Library.IDEInfo() Deps = %v, %v not found", dpInfo.Deps, expected)
60 }
Brandon Lee5d45c6f2018-08-15 15:35:38 -070061 }
62}
63
64func TestCollectJavaLibraryPropertiesAddScrs(t *testing.T) {
Cole Faustb36d31d2024-08-27 16:04:28 -070065 ctx, _ := testJava(t,
66 `
67 java_library {
68 name: "javalib",
69 srcs: ["Foo.java", "Bar.java"],
70 }
71 `)
72 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
73 dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
Brandon Lee5d45c6f2018-08-15 15:35:38 -070074
Cole Faustb36d31d2024-08-27 16:04:28 -070075 expected := []string{"Foo.java", "Bar.java"}
Brandon Lee5d45c6f2018-08-15 15:35:38 -070076 if !reflect.DeepEqual(dpInfo.Srcs, expected) {
77 t.Errorf("Library.IDEInfo() Srcs = %v, want %v", dpInfo.Srcs, expected)
78 }
79}
80
81func TestCollectJavaLibraryPropertiesAddAidlIncludeDirs(t *testing.T) {
Cole Faustb36d31d2024-08-27 16:04:28 -070082 ctx, _ := testJava(t,
83 `
84 java_library {
85 name: "javalib",
86 aidl: {
87 include_dirs: ["Foo", "Bar"],
88 },
89 }
90 `)
91 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
92 dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
93
Brandon Lee5d45c6f2018-08-15 15:35:38 -070094 expected := []string{"Foo", "Bar"}
Brandon Lee5d45c6f2018-08-15 15:35:38 -070095 if !reflect.DeepEqual(dpInfo.Aidl_include_dirs, expected) {
96 t.Errorf("Library.IDEInfo() Aidl_include_dirs = %v, want %v", dpInfo.Aidl_include_dirs, expected)
97 }
98}
99
Spandan Dasb4cd5df2024-08-08 21:57:22 +0000100func TestCollectJavaLibraryWithJarJarRules(t *testing.T) {
101 ctx, _ := testJava(t,
102 `
103 java_library {
104 name: "javalib",
105 srcs: ["foo.java"],
106 jarjar_rules: "jarjar_rules.txt",
107 }
108 `)
109 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
Cole Faustb36d31d2024-08-27 16:04:28 -0700110 dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700111
Spandan Dasb4cd5df2024-08-08 21:57:22 +0000112 android.AssertBoolEquals(t, "IdeInfo.Srcs of repackaged library should be empty", true, len(dpInfo.Srcs) == 0)
113 android.AssertStringEquals(t, "IdeInfo.Jar_rules of repackaged library should not be empty", "jarjar_rules.txt", dpInfo.Jarjar_rules[0])
114 if !android.SubstringInList(dpInfo.Jars, "soong/.intermediates/javalib/android_common/jarjar/turbine/javalib.jar") {
115 t.Errorf("IdeInfo.Jars of repackaged library should contain the output of jarjar-ing. All outputs: %v\n", dpInfo.Jars)
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700116 }
117}
Spandan Das6e8bd1c2024-08-09 00:07:03 +0000118
119func TestCollectJavaLibraryLinkingAgainstVersionedSdk(t *testing.T) {
120 ctx := android.GroupFixturePreparers(
121 prepareForJavaTest,
122 FixtureWithPrebuiltApis(map[string][]string{
123 "29": {},
124 })).RunTestWithBp(t,
125 `
126 java_library {
127 name: "javalib",
128 srcs: ["foo.java"],
129 sdk_version: "29",
130 }
131 `)
132 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
Cole Faustb36d31d2024-08-27 16:04:28 -0700133 dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey)
Spandan Das6e8bd1c2024-08-09 00:07:03 +0000134
Spandan Das6e8bd1c2024-08-09 00:07:03 +0000135 android.AssertStringListContains(t, "IdeInfo.Deps should contain versioned sdk module", dpInfo.Deps, "sdk_public_29_android")
136}