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