blob: ff54da92a58e73e91c8f8f110eb21f4abb73557f [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)
Brandon Lee5d45c6f2018-08-15 15:35:38 -070035 dpInfo := &android.IdeInfo{}
36
37 module.IDEInfo(dpInfo)
38
Spandan Das8aac9932024-07-18 23:14:13 +000039 for _, expected := range []string{"Foo", "Bar"} {
40 if !android.InList(expected, dpInfo.Deps) {
41 t.Errorf("Library.IDEInfo() Deps = %v, %v not found", dpInfo.Deps, expected)
42 }
Brandon Lee5d45c6f2018-08-15 15:35:38 -070043 }
44}
45
46func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) {
Spandan Das8aac9932024-07-18 23:14:13 +000047 ctx, _ := testJava(t,
48 `
49 java_library {name: "Foo"}
50 java_library {name: "Bar"}
51 java_library {
52 name: "javalib",
53 static_libs: ["Foo", "Bar"],
54 }
55 `)
56 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
Brandon Lee5d45c6f2018-08-15 15:35:38 -070057 dpInfo := &android.IdeInfo{}
58
59 module.IDEInfo(dpInfo)
60
Spandan Das8aac9932024-07-18 23:14:13 +000061 for _, expected := range []string{"Foo", "Bar"} {
62 if !android.InList(expected, dpInfo.Deps) {
63 t.Errorf("Library.IDEInfo() Deps = %v, %v not found", dpInfo.Deps, expected)
64 }
Brandon Lee5d45c6f2018-08-15 15:35:38 -070065 }
66}
67
68func TestCollectJavaLibraryPropertiesAddScrs(t *testing.T) {
69 expected := []string{"Foo", "Bar"}
70 module := LibraryFactory().(*Library)
71 module.expandIDEInfoCompiledSrcs = append(module.expandIDEInfoCompiledSrcs, expected...)
72 dpInfo := &android.IdeInfo{}
73
74 module.IDEInfo(dpInfo)
75
76 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) {
82 expected := []string{"Foo", "Bar"}
83 module := LibraryFactory().(*Library)
84 module.deviceProperties.Aidl.Include_dirs = append(module.deviceProperties.Aidl.Include_dirs, expected...)
85 dpInfo := &android.IdeInfo{}
86
87 module.IDEInfo(dpInfo)
88
89 if !reflect.DeepEqual(dpInfo.Aidl_include_dirs, expected) {
90 t.Errorf("Library.IDEInfo() Aidl_include_dirs = %v, want %v", dpInfo.Aidl_include_dirs, expected)
91 }
92}
93
Spandan Dasb4cd5df2024-08-08 21:57:22 +000094func TestCollectJavaLibraryWithJarJarRules(t *testing.T) {
95 ctx, _ := testJava(t,
96 `
97 java_library {
98 name: "javalib",
99 srcs: ["foo.java"],
100 jarjar_rules: "jarjar_rules.txt",
101 }
102 `)
103 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
Brandon Lee5d45c6f2018-08-15 15:35:38 -0700104 dpInfo := &android.IdeInfo{}
105
106 module.IDEInfo(dpInfo)
Spandan Dasb4cd5df2024-08-08 21:57:22 +0000107 android.AssertBoolEquals(t, "IdeInfo.Srcs of repackaged library should be empty", true, len(dpInfo.Srcs) == 0)
108 android.AssertStringEquals(t, "IdeInfo.Jar_rules of repackaged library should not be empty", "jarjar_rules.txt", dpInfo.Jarjar_rules[0])
109 if !android.SubstringInList(dpInfo.Jars, "soong/.intermediates/javalib/android_common/jarjar/turbine/javalib.jar") {
110 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 -0700111 }
112}
Spandan Das6e8bd1c2024-08-09 00:07:03 +0000113
114func TestCollectJavaLibraryLinkingAgainstVersionedSdk(t *testing.T) {
115 ctx := android.GroupFixturePreparers(
116 prepareForJavaTest,
117 FixtureWithPrebuiltApis(map[string][]string{
118 "29": {},
119 })).RunTestWithBp(t,
120 `
121 java_library {
122 name: "javalib",
123 srcs: ["foo.java"],
124 sdk_version: "29",
125 }
126 `)
127 module := ctx.ModuleForTests("javalib", "android_common").Module().(*Library)
128 dpInfo := &android.IdeInfo{}
129
130 module.IDEInfo(dpInfo)
131 android.AssertStringListContains(t, "IdeInfo.Deps should contain versioned sdk module", dpInfo.Deps, "sdk_public_29_android")
132}