Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "reflect" |
| 19 | "testing" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | func TestCollectJavaLibraryPropertiesAddLibsDeps(t *testing.T) { |
Spandan Das | 8aac993 | 2024-07-18 23:14:13 +0000 | [diff] [blame] | 25 | 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 Faust | b36d31d | 2024-08-27 16:04:28 -0700 | [diff] [blame] | 35 | dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 36 | |
Spandan Das | 8aac993 | 2024-07-18 23:14:13 +0000 | [diff] [blame] | 37 | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | func TestCollectJavaLibraryPropertiesAddStaticLibsDeps(t *testing.T) { |
Spandan Das | 8aac993 | 2024-07-18 23:14:13 +0000 | [diff] [blame] | 45 | 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 Faust | b36d31d | 2024-08-27 16:04:28 -0700 | [diff] [blame] | 55 | dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 56 | |
Spandan Das | 8aac993 | 2024-07-18 23:14:13 +0000 | [diff] [blame] | 57 | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestCollectJavaLibraryPropertiesAddScrs(t *testing.T) { |
Cole Faust | b36d31d | 2024-08-27 16:04:28 -0700 | [diff] [blame] | 65 | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 74 | |
Cole Faust | b36d31d | 2024-08-27 16:04:28 -0700 | [diff] [blame] | 75 | expected := []string{"Foo.java", "Bar.java"} |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 76 | if !reflect.DeepEqual(dpInfo.Srcs, expected) { |
| 77 | t.Errorf("Library.IDEInfo() Srcs = %v, want %v", dpInfo.Srcs, expected) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func TestCollectJavaLibraryPropertiesAddAidlIncludeDirs(t *testing.T) { |
Cole Faust | b36d31d | 2024-08-27 16:04:28 -0700 | [diff] [blame] | 82 | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 94 | expected := []string{"Foo", "Bar"} |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 95 | 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 Das | b4cd5df | 2024-08-08 21:57:22 +0000 | [diff] [blame] | 100 | func 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 Faust | b36d31d | 2024-08-27 16:04:28 -0700 | [diff] [blame] | 110 | dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) |
Brandon Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 111 | |
Spandan Das | 096b8d6 | 2024-10-08 22:41:26 +0000 | [diff] [blame] | 112 | android.AssertStringEquals(t, "IdeInfo.Srcs of repackaged library should not be empty", "foo.java", dpInfo.Srcs[0]) |
Spandan Das | b4cd5df | 2024-08-08 21:57:22 +0000 | [diff] [blame] | 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 Lee | 5d45c6f | 2018-08-15 15:35:38 -0700 | [diff] [blame] | 116 | } |
| 117 | } |
Spandan Das | 6e8bd1c | 2024-08-09 00:07:03 +0000 | [diff] [blame] | 118 | |
| 119 | func 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 Faust | b36d31d | 2024-08-27 16:04:28 -0700 | [diff] [blame] | 133 | dpInfo, _ := android.OtherModuleProvider(ctx, module, android.IdeInfoProviderKey) |
Spandan Das | 6e8bd1c | 2024-08-09 00:07:03 +0000 | [diff] [blame] | 134 | |
Spandan Das | 6e8bd1c | 2024-08-09 00:07:03 +0000 | [diff] [blame] | 135 | android.AssertStringListContains(t, "IdeInfo.Deps should contain versioned sdk module", dpInfo.Deps, "sdk_public_29_android") |
| 136 | } |
Spandan Das | 4f443e7 | 2024-10-17 00:04:19 +0000 | [diff] [blame^] | 137 | |
| 138 | func TestDoNotAddNoneSystemModulesToDeps(t *testing.T) { |
| 139 | ctx := android.GroupFixturePreparers( |
| 140 | prepareForJavaTest, |
| 141 | android.FixtureMergeEnv( |
| 142 | map[string]string{ |
| 143 | "DISABLE_STUB_VALIDATION": "true", |
| 144 | }, |
| 145 | ), |
| 146 | ).RunTestWithBp(t, |
| 147 | ` |
| 148 | java_library { |
| 149 | name: "javalib", |
| 150 | srcs: ["foo.java"], |
| 151 | sdk_version: "none", |
| 152 | system_modules: "none", |
| 153 | } |
| 154 | |
| 155 | java_api_library { |
| 156 | name: "javalib.stubs", |
| 157 | stubs_type: "everything", |
| 158 | api_contributions: ["javalib-current.txt"], |
| 159 | api_surface: "public", |
| 160 | system_modules: "none", |
| 161 | } |
| 162 | java_api_contribution { |
| 163 | name: "javalib-current.txt", |
| 164 | api_file: "javalib-current.txt", |
| 165 | api_surface: "public", |
| 166 | } |
| 167 | `) |
| 168 | javalib := ctx.ModuleForTests("javalib", "android_common").Module().(*Library) |
| 169 | dpInfo, _ := android.OtherModuleProvider(ctx, javalib, android.IdeInfoProviderKey) |
| 170 | android.AssertStringListDoesNotContain(t, "IdeInfo.Deps should contain not contain `none`", dpInfo.Deps, "none") |
| 171 | |
| 172 | javalib_stubs := ctx.ModuleForTests("javalib.stubs", "android_common").Module().(*ApiLibrary) |
| 173 | dpInfo, _ = android.OtherModuleProvider(ctx, javalib_stubs, android.IdeInfoProviderKey) |
| 174 | android.AssertStringListDoesNotContain(t, "IdeInfo.Deps should contain not contain `none`", dpInfo.Deps, "none") |
| 175 | } |