Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 1 | // Copyright 2020 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 ( |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 18 | "fmt" |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 19 | "path/filepath" |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 20 | "testing" |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 21 | |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 22 | "android/soong/android" |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 24 | ) |
| 25 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 26 | func fixtureSetBootJarsProductVariable(bootJars ...string) android.FixturePreparer { |
| 27 | return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 28 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 29 | }) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 32 | func fixtureSetPrebuiltHiddenApiDirProductVariable(prebuiltHiddenApiDir *string) android.FixturePreparer { |
| 33 | return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 34 | variables.PrebuiltHiddenApiDir = prebuiltHiddenApiDir |
| 35 | }) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 38 | var hiddenApiFixtureFactory = android.GroupFixturePreparers( |
| 39 | prepareForJavaTest, PrepareForTestWithHiddenApiBuildComponents) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 40 | |
| 41 | func TestHiddenAPISingleton(t *testing.T) { |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 42 | result := android.GroupFixturePreparers( |
| 43 | hiddenApiFixtureFactory, |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 44 | fixtureSetBootJarsProductVariable("platform:foo"), |
| 45 | ).RunTestWithBp(t, ` |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 46 | java_library { |
| 47 | name: "foo", |
| 48 | srcs: ["a.java"], |
| 49 | compile_dex: true, |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 50 | } |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 51 | `) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 52 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 53 | hiddenAPI := result.SingletonForTests("hiddenapi") |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 54 | hiddenapiRule := hiddenAPI.Rule("hiddenapi") |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 55 | want := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 56 | android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, want) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 59 | func TestHiddenAPIIndexSingleton(t *testing.T) { |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 60 | result := android.GroupFixturePreparers( |
| 61 | hiddenApiFixtureFactory, |
Paul Duffin | dc92abb | 2021-03-13 08:28:35 +0000 | [diff] [blame] | 62 | PrepareForTestWithJavaSdkLibraryFiles, |
| 63 | FixtureWithLastReleaseApis("bar"), |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 64 | fixtureSetBootJarsProductVariable("platform:foo", "platform:bar"), |
| 65 | ).RunTestWithBp(t, ` |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 66 | java_library { |
| 67 | name: "foo", |
| 68 | srcs: ["a.java"], |
| 69 | compile_dex: true, |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 70 | |
| 71 | hiddenapi_additional_annotations: [ |
| 72 | "foo-hiddenapi-annotations", |
| 73 | ], |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Paul Duffin | e7975ff | 2021-02-11 15:33:37 +0000 | [diff] [blame] | 76 | java_library { |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 77 | name: "foo-hiddenapi-annotations", |
| 78 | srcs: ["a.java"], |
| 79 | compile_dex: true, |
| 80 | } |
| 81 | |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 82 | java_import { |
| 83 | name: "foo", |
| 84 | jars: ["a.jar"], |
| 85 | compile_dex: true, |
| 86 | prefer: false, |
| 87 | } |
| 88 | |
| 89 | java_sdk_library { |
| 90 | name: "bar", |
| 91 | srcs: ["a.java"], |
| 92 | compile_dex: true, |
| 93 | } |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 94 | `) |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 95 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 96 | hiddenAPIIndex := result.SingletonForTests("hiddenapi_index") |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 97 | indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 98 | CheckHiddenAPIRuleInputs(t, ` |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 99 | .intermediates/bar/android_common/hiddenapi/index.csv |
| 100 | .intermediates/foo/android_common/hiddenapi/index.csv |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 101 | `, |
| 102 | indexRule) |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 103 | |
| 104 | // Make sure that the foo-hiddenapi-annotations.jar is included in the inputs to the rules that |
| 105 | // creates the index.csv file. |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 106 | foo := result.ModuleForTests("foo", "android_common") |
Paul Duffin | 031d869 | 2021-02-12 11:46:42 +0000 | [diff] [blame] | 107 | indexParams := foo.Output("hiddenapi/index.csv") |
| 108 | CheckHiddenAPIRuleInputs(t, ` |
| 109 | .intermediates/foo-hiddenapi-annotations/android_common/javac/foo-hiddenapi-annotations.jar |
| 110 | .intermediates/foo/android_common/javac/foo.jar |
| 111 | `, indexParams) |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Paul Duffin | ec0fe17 | 2021-02-25 15:34:13 +0000 | [diff] [blame] | 114 | func TestHiddenAPISingletonWithSourceAndPrebuiltPreferredButNoDex(t *testing.T) { |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 115 | expectedErrorMessage := |
| 116 | "hiddenapi has determined that the source module \"foo\" should be ignored as it has been" + |
| 117 | " replaced by the prebuilt module \"prebuilt_foo\" but unfortunately it does not provide a" + |
| 118 | " suitable boot dex jar" |
| 119 | |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 120 | android.GroupFixturePreparers( |
| 121 | hiddenApiFixtureFactory, |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 122 | fixtureSetBootJarsProductVariable("platform:foo"), |
| 123 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(expectedErrorMessage)). |
| 124 | RunTestWithBp(t, ` |
Paul Duffin | ec0fe17 | 2021-02-25 15:34:13 +0000 | [diff] [blame] | 125 | java_library { |
| 126 | name: "foo", |
| 127 | srcs: ["a.java"], |
| 128 | compile_dex: true, |
| 129 | } |
| 130 | |
| 131 | java_import { |
| 132 | name: "foo", |
| 133 | jars: ["a.jar"], |
| 134 | prefer: true, |
| 135 | } |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 136 | `) |
Paul Duffin | ec0fe17 | 2021-02-25 15:34:13 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 139 | func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 140 | result := android.GroupFixturePreparers( |
| 141 | hiddenApiFixtureFactory, |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 142 | fixtureSetBootJarsProductVariable("platform:foo"), |
| 143 | ).RunTestWithBp(t, ` |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 144 | java_import { |
| 145 | name: "foo", |
| 146 | jars: ["a.jar"], |
| 147 | compile_dex: true, |
| 148 | } |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 149 | `) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 150 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 151 | hiddenAPI := result.SingletonForTests("hiddenapi") |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 152 | hiddenapiRule := hiddenAPI.Rule("hiddenapi") |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 153 | want := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 154 | android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, want) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) { |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 158 | result := android.GroupFixturePreparers( |
| 159 | hiddenApiFixtureFactory, |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 160 | fixtureSetBootJarsProductVariable("platform:foo"), |
| 161 | ).RunTestWithBp(t, ` |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 162 | java_library { |
| 163 | name: "foo", |
| 164 | srcs: ["a.java"], |
| 165 | compile_dex: true, |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 166 | } |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 167 | |
| 168 | java_import { |
| 169 | name: "foo", |
| 170 | jars: ["a.jar"], |
| 171 | compile_dex: true, |
| 172 | prefer: false, |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 173 | } |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 174 | `) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 175 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 176 | hiddenAPI := result.SingletonForTests("hiddenapi") |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 177 | hiddenapiRule := hiddenAPI.Rule("hiddenapi") |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 178 | fromSourceJarArg := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 179 | android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, fromSourceJarArg) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 180 | |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 181 | prebuiltJarArg := "--boot-dex=out/soong/.intermediates/foo/android_common/dex/foo.jar" |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 182 | android.AssertStringDoesNotContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, prebuiltJarArg) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) { |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 186 | result := android.GroupFixturePreparers( |
| 187 | hiddenApiFixtureFactory, |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 188 | fixtureSetBootJarsProductVariable("platform:foo"), |
| 189 | ).RunTestWithBp(t, ` |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 190 | java_library { |
| 191 | name: "foo", |
| 192 | srcs: ["a.java"], |
| 193 | compile_dex: true, |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 194 | } |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 195 | |
| 196 | java_import { |
| 197 | name: "foo", |
| 198 | jars: ["a.jar"], |
| 199 | compile_dex: true, |
| 200 | prefer: true, |
Paul Duffin | 01289a2 | 2021-02-04 17:49:33 +0000 | [diff] [blame] | 201 | } |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 202 | `) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 203 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 204 | hiddenAPI := result.SingletonForTests("hiddenapi") |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 205 | hiddenapiRule := hiddenAPI.Rule("hiddenapi") |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 206 | prebuiltJarArg := "--boot-dex=out/soong/.intermediates/prebuilt_foo/android_common/dex/foo.jar" |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 207 | android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, prebuiltJarArg) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 208 | |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 209 | fromSourceJarArg := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 210 | android.AssertStringDoesNotContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, fromSourceJarArg) |
Liz Kammer | 5ca3a62 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 211 | } |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 212 | |
| 213 | func TestHiddenAPISingletonSdks(t *testing.T) { |
| 214 | testCases := []struct { |
| 215 | name string |
| 216 | unbundledBuild bool |
| 217 | publicStub string |
| 218 | systemStub string |
| 219 | testStub string |
| 220 | corePlatformStub string |
Paul Duffin | dc92abb | 2021-03-13 08:28:35 +0000 | [diff] [blame] | 221 | |
| 222 | // Additional test preparer |
| 223 | preparer android.FixturePreparer |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 224 | }{ |
| 225 | { |
| 226 | name: "testBundled", |
| 227 | unbundledBuild: false, |
| 228 | publicStub: "android_stubs_current", |
| 229 | systemStub: "android_system_stubs_current", |
| 230 | testStub: "android_test_stubs_current", |
| 231 | corePlatformStub: "legacy.core.platform.api.stubs", |
Paul Duffin | dc92abb | 2021-03-13 08:28:35 +0000 | [diff] [blame] | 232 | preparer: android.GroupFixturePreparers(), |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 233 | }, { |
| 234 | name: "testUnbundled", |
| 235 | unbundledBuild: true, |
| 236 | publicStub: "sdk_public_current_android", |
| 237 | systemStub: "sdk_system_current_android", |
| 238 | testStub: "sdk_test_current_android", |
| 239 | corePlatformStub: "legacy.core.platform.api.stubs", |
Paul Duffin | dc92abb | 2021-03-13 08:28:35 +0000 | [diff] [blame] | 240 | preparer: PrepareForTestWithPrebuiltsOfCurrentApi, |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 241 | }, |
| 242 | } |
| 243 | for _, tc := range testCases { |
| 244 | t.Run(tc.name, func(t *testing.T) { |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 245 | result := android.GroupFixturePreparers( |
| 246 | hiddenApiFixtureFactory, |
Paul Duffin | dc92abb | 2021-03-13 08:28:35 +0000 | [diff] [blame] | 247 | tc.preparer, |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 248 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 249 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(tc.unbundledBuild) |
| 250 | }), |
| 251 | ).RunTest(t) |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 252 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 253 | hiddenAPI := result.SingletonForTests("hiddenapi") |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 254 | hiddenapiRule := hiddenAPI.Rule("hiddenapi") |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 255 | wantPublicStubs := "--public-stub-classpath=" + generateSdkDexPath(tc.publicStub, tc.unbundledBuild) |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 256 | android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, wantPublicStubs) |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 257 | |
| 258 | wantSystemStubs := "--system-stub-classpath=" + generateSdkDexPath(tc.systemStub, tc.unbundledBuild) |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 259 | android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, wantSystemStubs) |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 260 | |
| 261 | wantTestStubs := "--test-stub-classpath=" + generateSdkDexPath(tc.testStub, tc.unbundledBuild) |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 262 | android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, wantTestStubs) |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 263 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 264 | wantCorePlatformStubs := "--core-platform-stub-classpath=" + generateDexPath(defaultJavaDir, tc.corePlatformStub) |
| 265 | android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, wantCorePlatformStubs) |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 266 | }) |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | func generateDexedPath(subDir, dex, module string) string { |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 271 | return fmt.Sprintf("out/soong/.intermediates/%s/android_common/%s/%s.jar", subDir, dex, module) |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 274 | func generateDexPath(moduleDir string, module string) string { |
| 275 | return generateDexedPath(filepath.Join(moduleDir, module), "dex", module) |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | func generateSdkDexPath(module string, unbundled bool) string { |
| 279 | if unbundled { |
| 280 | return generateDexedPath("prebuilts/sdk/"+module, "dex", module) |
| 281 | } |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 282 | return generateDexPath(defaultJavaDir, module) |
Anton Hansson | a2adc37 | 2020-07-03 15:31:32 +0100 | [diff] [blame] | 283 | } |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 284 | |
| 285 | func TestHiddenAPISingletonWithPrebuiltCsvFile(t *testing.T) { |
| 286 | |
| 287 | // The idea behind this test is to ensure that when the build is |
| 288 | // confugured with a PrebuiltHiddenApiDir that the rules for the |
| 289 | // hiddenapi singleton copy the prebuilts to the typical output |
| 290 | // location, and then use that output location for the hiddenapi encode |
| 291 | // dex step. |
| 292 | |
| 293 | // Where to find the prebuilt hiddenapi files: |
| 294 | prebuiltHiddenApiDir := "path/to/prebuilt/hiddenapi" |
| 295 | |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 296 | result := android.GroupFixturePreparers( |
| 297 | hiddenApiFixtureFactory, |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 298 | fixtureSetBootJarsProductVariable("platform:foo"), |
| 299 | fixtureSetPrebuiltHiddenApiDirProductVariable(&prebuiltHiddenApiDir), |
| 300 | ).RunTestWithBp(t, ` |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 301 | java_import { |
| 302 | name: "foo", |
| 303 | jars: ["a.jar"], |
| 304 | compile_dex: true, |
| 305 | } |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 306 | `) |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 307 | |
| 308 | expectedCpInput := prebuiltHiddenApiDir + "/hiddenapi-flags.csv" |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 309 | expectedCpOutput := "out/soong/hiddenapi/hiddenapi-flags.csv" |
| 310 | expectedFlagsCsv := "out/soong/hiddenapi/hiddenapi-flags.csv" |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 311 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 312 | foo := result.ModuleForTests("foo", "android_common") |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 313 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 314 | hiddenAPI := result.SingletonForTests("hiddenapi") |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 315 | cpRule := hiddenAPI.Rule("Cp") |
| 316 | actualCpInput := cpRule.BuildParams.Input |
| 317 | actualCpOutput := cpRule.BuildParams.Output |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 318 | encodeDexRule := foo.Rule("hiddenAPIEncodeDex") |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 319 | actualFlagsCsv := encodeDexRule.BuildParams.Args["flagsCsv"] |
| 320 | |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 321 | android.AssertPathRelativeToTopEquals(t, "hiddenapi cp rule input", expectedCpInput, actualCpInput) |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 322 | |
Paul Duffin | 2f9e71e | 2021-03-22 16:24:49 +0000 | [diff] [blame] | 323 | android.AssertPathRelativeToTopEquals(t, "hiddenapi cp rule output", expectedCpOutput, actualCpOutput) |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 324 | |
Paul Duffin | 175947f | 2021-03-12 21:44:02 +0000 | [diff] [blame] | 325 | android.AssertStringEquals(t, "hiddenapi encode dex rule flags csv", expectedFlagsCsv, actualFlagsCsv) |
Bill Peckham | bae4749 | 2021-01-08 09:34:44 -0800 | [diff] [blame] | 326 | } |