Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1 | // Copyright 2019 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 sdk |
| 16 | |
| 17 | import ( |
Martin Stjernholm | 3ff2e66 | 2020-07-15 14:38:15 +0100 | [diff] [blame] | 18 | "log" |
| 19 | "os" |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 20 | "runtime" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 21 | "testing" |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 22 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 23 | "android/soong/android" |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 24 | "android/soong/java" |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 25 | |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 27 | ) |
| 28 | |
Paul Duffin | 82d9043 | 2019-11-30 09:24:33 +0000 | [diff] [blame] | 29 | // Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE. |
| 30 | func TestMain(m *testing.M) { |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 31 | if runtime.GOOS != "linux" { |
Martin Stjernholm | 3ff2e66 | 2020-07-15 14:38:15 +0100 | [diff] [blame] | 32 | // b/145598135 - Generating host snapshots for anything other than linux is not supported. |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 33 | log.Printf("Skipping as sdk snapshot generation is only supported on linux not %s", runtime.GOOS) |
Martin Stjernholm | 3ff2e66 | 2020-07-15 14:38:15 +0100 | [diff] [blame] | 34 | os.Exit(0) |
| 35 | } |
| 36 | |
Paul Duffin | abbf63d | 2021-03-18 01:47:31 +0000 | [diff] [blame] | 37 | os.Exit(m.Run()) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 38 | } |
| 39 | |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 40 | // Ensure that prebuilt modules have the same effective visibility as the source |
| 41 | // modules. |
| 42 | func TestSnapshotVisibility(t *testing.T) { |
| 43 | packageBp := ` |
| 44 | package { |
| 45 | default_visibility: ["//other/foo"], |
| 46 | } |
| 47 | |
| 48 | sdk { |
| 49 | name: "mysdk", |
| 50 | visibility: [ |
| 51 | "//other/foo", |
| 52 | // This short form will be replaced with //package:__subpackages__ in the |
| 53 | // generated sdk_snapshot. |
| 54 | ":__subpackages__", |
| 55 | ], |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 56 | prebuilt_visibility: [ |
| 57 | "//prebuilts/mysdk", |
| 58 | ], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 59 | java_header_libs: [ |
| 60 | "myjavalib", |
| 61 | "mypublicjavalib", |
| 62 | "mydefaultedjavalib", |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 63 | "myprivatejavalib", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 64 | ], |
| 65 | } |
| 66 | |
| 67 | java_library { |
| 68 | name: "myjavalib", |
| 69 | // Uses package default visibility |
| 70 | srcs: ["Test.java"], |
| 71 | system_modules: "none", |
| 72 | sdk_version: "none", |
| 73 | } |
| 74 | |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 75 | java_defaults { |
| 76 | name: "java-defaults", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 77 | visibility: ["//other/bar"], |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 80 | java_library { |
| 81 | name: "mypublicjavalib", |
Paul Duffin | 44885e2 | 2020-02-19 16:10:09 +0000 | [diff] [blame] | 82 | defaults: ["java-defaults"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 83 | visibility: ["//visibility:public"], |
| 84 | srcs: ["Test.java"], |
| 85 | system_modules: "none", |
| 86 | sdk_version: "none", |
| 87 | } |
| 88 | |
| 89 | java_defaults { |
| 90 | name: "myjavadefaults", |
| 91 | visibility: ["//other/bar"], |
| 92 | } |
| 93 | |
| 94 | java_library { |
| 95 | name: "mydefaultedjavalib", |
| 96 | defaults: ["myjavadefaults"], |
| 97 | srcs: ["Test.java"], |
| 98 | system_modules: "none", |
| 99 | sdk_version: "none", |
| 100 | } |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 101 | |
| 102 | java_library { |
| 103 | name: "myprivatejavalib", |
| 104 | srcs: ["Test.java"], |
| 105 | visibility: ["//visibility:private"], |
| 106 | system_modules: "none", |
| 107 | sdk_version: "none", |
| 108 | } |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 109 | ` |
| 110 | |
| 111 | result := testSdkWithFs(t, ``, |
| 112 | map[string][]byte{ |
| 113 | "package/Test.java": nil, |
| 114 | "package/Android.bp": []byte(packageBp), |
| 115 | }) |
| 116 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 117 | CheckSnapshot(t, result, "mysdk", "package", |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 118 | checkAndroidBpContents(` |
| 119 | // This is auto-generated. DO NOT EDIT. |
| 120 | |
| 121 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 122 | name: "myjavalib", |
| 123 | prefer: false, |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 124 | visibility: [ |
| 125 | "//other/foo", |
| 126 | "//package", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 127 | "//prebuilts/mysdk", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 128 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 129 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 130 | jars: ["java/myjavalib.jar"], |
| 131 | } |
| 132 | |
| 133 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 134 | name: "mypublicjavalib", |
| 135 | prefer: false, |
| 136 | visibility: ["//visibility:public"], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 137 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 138 | jars: ["java/mypublicjavalib.jar"], |
| 139 | } |
| 140 | |
| 141 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 142 | name: "mydefaultedjavalib", |
| 143 | prefer: false, |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 144 | visibility: [ |
| 145 | "//other/bar", |
| 146 | "//package", |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 147 | "//prebuilts/mysdk", |
Martin Stjernholm | 0641d18 | 2020-05-13 02:20:06 +0100 | [diff] [blame] | 148 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 149 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 150 | jars: ["java/mydefaultedjavalib.jar"], |
| 151 | } |
| 152 | |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 153 | java_import { |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 154 | name: "myprivatejavalib", |
| 155 | prefer: false, |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 156 | visibility: [ |
| 157 | "//package", |
| 158 | "//prebuilts/mysdk", |
| 159 | ], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 160 | apex_available: ["//apex_available:platform"], |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 161 | jars: ["java/myprivatejavalib.jar"], |
| 162 | } |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 163 | `)) |
| 164 | } |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 165 | |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 166 | func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) { |
| 167 | testSdkError(t, `prebuilt_visibility: cannot mix "//visibility:private" with any other visibility rules`, ` |
| 168 | sdk { |
| 169 | name: "mysdk", |
| 170 | prebuilt_visibility: [ |
| 171 | "//foo", |
| 172 | "//visibility:private", |
| 173 | ], |
| 174 | } |
| 175 | `) |
| 176 | } |
| 177 | |
| 178 | func TestPrebuiltVisibilityProperty_AddPrivate(t *testing.T) { |
| 179 | testSdkError(t, `prebuilt_visibility: "//visibility:private" does not widen the visibility`, ` |
| 180 | sdk { |
| 181 | name: "mysdk", |
| 182 | prebuilt_visibility: [ |
| 183 | "//visibility:private", |
| 184 | ], |
| 185 | java_header_libs: [ |
| 186 | "myjavalib", |
| 187 | ], |
| 188 | } |
| 189 | |
| 190 | java_library { |
| 191 | name: "myjavalib", |
| 192 | // Uses package default visibility |
| 193 | srcs: ["Test.java"], |
| 194 | system_modules: "none", |
| 195 | sdk_version: "none", |
| 196 | } |
| 197 | `) |
| 198 | } |
| 199 | |
Paul Duffin | 8edc99c | 2021-03-09 23:02:20 +0000 | [diff] [blame] | 200 | func TestSdkInstall(t *testing.T) { |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 201 | sdk := ` |
| 202 | sdk { |
| 203 | name: "mysdk", |
| 204 | } |
| 205 | ` |
Paul Duffin | 8edc99c | 2021-03-09 23:02:20 +0000 | [diff] [blame] | 206 | result := testSdkWithFs(t, sdk, nil) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 207 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 208 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | c6ba182 | 2022-05-06 09:38:02 +0000 | [diff] [blame] | 209 | checkAllOtherCopyRules(` |
| 210 | .intermediates/mysdk/common_os/mysdk-current.info -> mysdk-current.info |
| 211 | .intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip |
| 212 | `)) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 213 | } |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 214 | |
| 215 | type EmbeddedPropertiesStruct struct { |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 216 | S_Embedded_Common string `android:"arch_variant"` |
| 217 | S_Embedded_Different string `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | type testPropertiesStruct struct { |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame^] | 221 | name string |
| 222 | private string |
| 223 | Public_Ignore string `sdk:"ignore"` |
| 224 | S_Common string |
| 225 | S_Different string `android:"arch_variant"` |
| 226 | A_Common []string |
| 227 | A_Different []string `android:"arch_variant"` |
| 228 | F_Common *bool |
| 229 | F_Different *bool `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 230 | EmbeddedPropertiesStruct |
| 231 | } |
| 232 | |
Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 233 | func (p *testPropertiesStruct) optimizableProperties() interface{} { |
| 234 | return p |
| 235 | } |
| 236 | |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 237 | func (p *testPropertiesStruct) String() string { |
| 238 | return p.name |
| 239 | } |
| 240 | |
| 241 | var _ propertiesContainer = (*testPropertiesStruct)(nil) |
| 242 | |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 243 | func TestCommonValueOptimization(t *testing.T) { |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 244 | common := &testPropertiesStruct{name: "common"} |
Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 245 | structs := []propertiesContainer{ |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 246 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame^] | 247 | name: "struct-0", |
| 248 | private: "common", |
| 249 | Public_Ignore: "common", |
| 250 | S_Common: "common", |
| 251 | S_Different: "upper", |
| 252 | A_Common: []string{"first", "second"}, |
| 253 | A_Different: []string{"alpha", "beta"}, |
| 254 | F_Common: proptools.BoolPtr(false), |
| 255 | F_Different: proptools.BoolPtr(false), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 256 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 257 | S_Embedded_Common: "embedded_common", |
| 258 | S_Embedded_Different: "embedded_upper", |
| 259 | }, |
| 260 | }, |
| 261 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame^] | 262 | name: "struct-1", |
| 263 | private: "common", |
| 264 | Public_Ignore: "common", |
| 265 | S_Common: "common", |
| 266 | S_Different: "lower", |
| 267 | A_Common: []string{"first", "second"}, |
| 268 | A_Different: []string{"alpha", "delta"}, |
| 269 | F_Common: proptools.BoolPtr(false), |
| 270 | F_Different: proptools.BoolPtr(true), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 271 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 272 | S_Embedded_Common: "embedded_common", |
| 273 | S_Embedded_Different: "embedded_lower", |
| 274 | }, |
| 275 | }, |
| 276 | } |
| 277 | |
| 278 | extractor := newCommonValueExtractor(common) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 279 | |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 280 | err := extractor.extractCommonProperties(common, structs) |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 281 | android.AssertDeepEquals(t, "unexpected error", nil, err) |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 282 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 283 | android.AssertDeepEquals(t, "common properties not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 284 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame^] | 285 | name: "common", |
| 286 | private: "", |
| 287 | Public_Ignore: "", |
| 288 | S_Common: "common", |
| 289 | S_Different: "", |
| 290 | A_Common: []string{"first", "second"}, |
| 291 | A_Different: []string(nil), |
| 292 | F_Common: proptools.BoolPtr(false), |
| 293 | F_Different: nil, |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 294 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 295 | S_Embedded_Common: "embedded_common", |
| 296 | S_Embedded_Different: "", |
| 297 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 298 | }, |
| 299 | common) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 300 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 301 | android.AssertDeepEquals(t, "updated properties[0] not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 302 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame^] | 303 | name: "struct-0", |
| 304 | private: "common", |
| 305 | Public_Ignore: "common", |
| 306 | S_Common: "", |
| 307 | S_Different: "upper", |
| 308 | A_Common: nil, |
| 309 | A_Different: []string{"alpha", "beta"}, |
| 310 | F_Common: nil, |
| 311 | F_Different: proptools.BoolPtr(false), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 312 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 313 | S_Embedded_Common: "", |
| 314 | S_Embedded_Different: "embedded_upper", |
| 315 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 316 | }, |
| 317 | structs[0]) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 318 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 319 | android.AssertDeepEquals(t, "updated properties[1] not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 320 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame^] | 321 | name: "struct-1", |
| 322 | private: "common", |
| 323 | Public_Ignore: "common", |
| 324 | S_Common: "", |
| 325 | S_Different: "lower", |
| 326 | A_Common: nil, |
| 327 | A_Different: []string{"alpha", "delta"}, |
| 328 | F_Common: nil, |
| 329 | F_Different: proptools.BoolPtr(true), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 330 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 331 | S_Embedded_Common: "", |
| 332 | S_Embedded_Different: "embedded_lower", |
| 333 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 334 | }, |
| 335 | structs[1]) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 336 | } |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 337 | |
| 338 | func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) { |
| 339 | common := &testPropertiesStruct{name: "common"} |
| 340 | structs := []propertiesContainer{ |
| 341 | &testPropertiesStruct{ |
| 342 | name: "struct-0", |
| 343 | S_Common: "should-be-but-is-not-common0", |
| 344 | }, |
| 345 | &testPropertiesStruct{ |
| 346 | name: "struct-1", |
| 347 | S_Common: "should-be-but-is-not-common1", |
| 348 | }, |
| 349 | } |
| 350 | |
| 351 | extractor := newCommonValueExtractor(common) |
| 352 | |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 353 | err := extractor.extractCommonProperties(common, structs) |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 354 | android.AssertErrorMessageEquals(t, "unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties: |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 355 | "struct-0" has value "should-be-but-is-not-common0" |
| 356 | "struct-1" has value "should-be-but-is-not-common1"`, err) |
| 357 | } |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 358 | |
| 359 | // Ensure that sdk snapshot related environment variables work correctly. |
| 360 | func TestSnapshot_EnvConfiguration(t *testing.T) { |
| 361 | bp := ` |
| 362 | sdk { |
| 363 | name: "mysdk", |
| 364 | java_header_libs: ["myjavalib"], |
| 365 | } |
| 366 | |
| 367 | java_library { |
| 368 | name: "myjavalib", |
| 369 | srcs: ["Test.java"], |
| 370 | system_modules: "none", |
| 371 | sdk_version: "none", |
| 372 | compile_dex: true, |
| 373 | host_supported: true, |
| 374 | } |
| 375 | ` |
| 376 | preparer := android.GroupFixturePreparers( |
| 377 | prepareForSdkTestWithJava, |
| 378 | android.FixtureWithRootAndroidBp(bp), |
| 379 | ) |
| 380 | |
| 381 | checkZipFile := func(t *testing.T, result *android.TestResult, expected string) { |
| 382 | zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles") |
| 383 | android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String()) |
| 384 | } |
| 385 | |
| 386 | t.Run("no env variables", func(t *testing.T) { |
| 387 | result := preparer.RunTest(t) |
| 388 | |
| 389 | checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") |
| 390 | |
| 391 | CheckSnapshot(t, result, "mysdk", "", |
| 392 | checkAndroidBpContents(` |
| 393 | // This is auto-generated. DO NOT EDIT. |
| 394 | |
| 395 | java_import { |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 396 | name: "myjavalib", |
| 397 | prefer: false, |
| 398 | visibility: ["//visibility:public"], |
| 399 | apex_available: ["//apex_available:platform"], |
| 400 | jars: ["java/myjavalib.jar"], |
| 401 | } |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 402 | `), |
| 403 | ) |
| 404 | }) |
Paul Duffin | 64fb526 | 2021-05-05 21:36:04 +0100 | [diff] [blame] | 405 | |
| 406 | t.Run("SOONG_SDK_SNAPSHOT_PREFER=true", func(t *testing.T) { |
| 407 | result := android.GroupFixturePreparers( |
| 408 | preparer, |
| 409 | android.FixtureMergeEnv(map[string]string{ |
| 410 | "SOONG_SDK_SNAPSHOT_PREFER": "true", |
| 411 | }), |
| 412 | ).RunTest(t) |
| 413 | |
| 414 | checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") |
| 415 | |
| 416 | CheckSnapshot(t, result, "mysdk", "", |
| 417 | checkAndroidBpContents(` |
| 418 | // This is auto-generated. DO NOT EDIT. |
| 419 | |
| 420 | java_import { |
Paul Duffin | 64fb526 | 2021-05-05 21:36:04 +0100 | [diff] [blame] | 421 | name: "myjavalib", |
| 422 | prefer: true, |
| 423 | visibility: ["//visibility:public"], |
| 424 | apex_available: ["//apex_available:platform"], |
| 425 | jars: ["java/myjavalib.jar"], |
| 426 | } |
Paul Duffin | 64fb526 | 2021-05-05 21:36:04 +0100 | [diff] [blame] | 427 | `), |
| 428 | ) |
| 429 | }) |
Paul Duffin | 43f7bf0 | 2021-05-05 22:00:51 +0100 | [diff] [blame] | 430 | |
Paul Duffin | fb9a7f9 | 2021-07-06 17:18:42 +0100 | [diff] [blame] | 431 | t.Run("SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR=module:build_from_source", func(t *testing.T) { |
| 432 | result := android.GroupFixturePreparers( |
| 433 | preparer, |
| 434 | android.FixtureMergeEnv(map[string]string{ |
| 435 | "SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR": "module:build_from_source", |
| 436 | }), |
| 437 | ).RunTest(t) |
| 438 | |
| 439 | checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") |
| 440 | |
| 441 | CheckSnapshot(t, result, "mysdk", "", |
| 442 | checkAndroidBpContents(` |
| 443 | // This is auto-generated. DO NOT EDIT. |
| 444 | |
| 445 | java_import { |
Paul Duffin | fb9a7f9 | 2021-07-06 17:18:42 +0100 | [diff] [blame] | 446 | name: "myjavalib", |
| 447 | prefer: false, |
| 448 | use_source_config_var: { |
| 449 | config_namespace: "module", |
| 450 | var_name: "build_from_source", |
| 451 | }, |
| 452 | visibility: ["//visibility:public"], |
| 453 | apex_available: ["//apex_available:platform"], |
| 454 | jars: ["java/myjavalib.jar"], |
| 455 | } |
Paul Duffin | fb9a7f9 | 2021-07-06 17:18:42 +0100 | [diff] [blame] | 456 | `), |
| 457 | ) |
| 458 | }) |
| 459 | |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 460 | t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) { |
| 461 | result := android.GroupFixturePreparers( |
| 462 | prepareForSdkTestWithJava, |
| 463 | java.PrepareForTestWithJavaDefaultModules, |
| 464 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 465 | java.FixtureWithLastReleaseApis("mysdklibrary"), |
| 466 | android.FixtureWithRootAndroidBp(` |
| 467 | sdk { |
| 468 | name: "mysdk", |
| 469 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 470 | } |
| 471 | |
| 472 | bootclasspath_fragment { |
| 473 | name: "mybootclasspathfragment", |
| 474 | apex_available: ["myapex"], |
| 475 | contents: ["mysdklibrary"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 476 | hidden_api: { |
| 477 | split_packages: ["*"], |
| 478 | }, |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | java_sdk_library { |
| 482 | name: "mysdklibrary", |
| 483 | srcs: ["Test.java"], |
| 484 | compile_dex: true, |
Paul Duffin | 1938dba | 2022-07-26 23:53:00 +0000 | [diff] [blame] | 485 | sdk_version: "S", |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 486 | public: {enabled: true}, |
| 487 | permitted_packages: ["mysdklibrary"], |
| 488 | } |
| 489 | `), |
| 490 | android.FixtureMergeEnv(map[string]string{ |
| 491 | "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S", |
| 492 | }), |
| 493 | ).RunTest(t) |
| 494 | |
| 495 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | b01ac4b | 2022-05-24 20:10:05 +0000 | [diff] [blame] | 496 | checkAndroidBpContents(` |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 497 | // This is auto-generated. DO NOT EDIT. |
| 498 | |
| 499 | prebuilt_bootclasspath_fragment { |
| 500 | name: "mybootclasspathfragment", |
| 501 | prefer: false, |
| 502 | visibility: ["//visibility:public"], |
| 503 | apex_available: ["myapex"], |
| 504 | contents: ["mysdklibrary"], |
| 505 | hidden_api: { |
| 506 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 507 | metadata: "hiddenapi/metadata.csv", |
| 508 | index: "hiddenapi/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 509 | stub_flags: "hiddenapi/stub-flags.csv", |
| 510 | all_flags: "hiddenapi/all-flags.csv", |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 511 | }, |
| 512 | } |
| 513 | |
| 514 | java_sdk_library_import { |
| 515 | name: "mysdklibrary", |
| 516 | prefer: false, |
| 517 | visibility: ["//visibility:public"], |
| 518 | apex_available: ["//apex_available:platform"], |
| 519 | shared_library: true, |
| 520 | compile_dex: true, |
| 521 | permitted_packages: ["mysdklibrary"], |
| 522 | public: { |
| 523 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 524 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 525 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 526 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 527 | sdk_version: "current", |
| 528 | }, |
| 529 | } |
| 530 | `), |
| 531 | |
| 532 | checkAllCopyRules(` |
| 533 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 534 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv |
| 535 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 536 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv |
| 537 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 538 | .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar |
| 539 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt |
| 540 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt |
| 541 | `), |
| 542 | ) |
| 543 | }) |
| 544 | |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 545 | } |