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