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