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