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 | |
Spandan Das | a5e26d3 | 2024-03-06 14:04:36 +0000 | [diff] [blame] | 121 | apex_contributions_defaults { |
| 122 | name: "mysdk.contributions", |
| 123 | contents: [ |
| 124 | "prebuilt_myjavalib", |
| 125 | "prebuilt_mypublicjavalib", |
| 126 | "prebuilt_mydefaultedjavalib", |
| 127 | "prebuilt_myprivatejavalib", |
| 128 | ], |
| 129 | } |
| 130 | |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 131 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 132 | name: "myjavalib", |
| 133 | prefer: false, |
Spandan Das | 2c20726 | 2024-08-30 18:56:39 +0000 | [diff] [blame^] | 134 | visibility: ["//visibility:public"], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 135 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 136 | jars: ["java/myjavalib.jar"], |
| 137 | } |
| 138 | |
| 139 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 140 | name: "mypublicjavalib", |
| 141 | prefer: false, |
| 142 | visibility: ["//visibility:public"], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 143 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 144 | jars: ["java/mypublicjavalib.jar"], |
| 145 | } |
| 146 | |
| 147 | java_import { |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 148 | name: "mydefaultedjavalib", |
| 149 | prefer: false, |
Spandan Das | 2c20726 | 2024-08-30 18:56:39 +0000 | [diff] [blame^] | 150 | visibility: ["//visibility:public"], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 151 | apex_available: ["//apex_available:platform"], |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 152 | jars: ["java/mydefaultedjavalib.jar"], |
| 153 | } |
| 154 | |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 155 | java_import { |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 156 | name: "myprivatejavalib", |
| 157 | prefer: false, |
Spandan Das | 2c20726 | 2024-08-30 18:56:39 +0000 | [diff] [blame^] | 158 | visibility: ["//visibility:public"], |
Martin Stjernholm | 1e04109 | 2020-11-03 00:11:09 +0000 | [diff] [blame] | 159 | apex_available: ["//apex_available:platform"], |
Martin Stjernholm | 64aeaad | 2020-05-13 22:11:40 +0100 | [diff] [blame] | 160 | jars: ["java/myprivatejavalib.jar"], |
| 161 | } |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 162 | `)) |
| 163 | } |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 164 | |
Paul Duffin | 157f40f | 2020-09-29 16:01:08 +0100 | [diff] [blame] | 165 | func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) { |
| 166 | testSdkError(t, `prebuilt_visibility: cannot mix "//visibility:private" with any other visibility rules`, ` |
| 167 | sdk { |
| 168 | name: "mysdk", |
| 169 | prebuilt_visibility: [ |
| 170 | "//foo", |
| 171 | "//visibility:private", |
| 172 | ], |
| 173 | } |
| 174 | `) |
| 175 | } |
| 176 | |
Paul Duffin | 8edc99c | 2021-03-09 23:02:20 +0000 | [diff] [blame] | 177 | func TestSdkInstall(t *testing.T) { |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 178 | sdk := ` |
| 179 | sdk { |
| 180 | name: "mysdk", |
| 181 | } |
| 182 | ` |
Paul Duffin | 8edc99c | 2021-03-09 23:02:20 +0000 | [diff] [blame] | 183 | result := testSdkWithFs(t, sdk, nil) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 184 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 185 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | c6ba182 | 2022-05-06 09:38:02 +0000 | [diff] [blame] | 186 | checkAllOtherCopyRules(` |
| 187 | .intermediates/mysdk/common_os/mysdk-current.info -> mysdk-current.info |
| 188 | .intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip |
| 189 | `)) |
Nicolas Geoffray | 1228e9c | 2020-02-27 13:45:35 +0000 | [diff] [blame] | 190 | } |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 191 | |
| 192 | type EmbeddedPropertiesStruct struct { |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 193 | S_Embedded_Common string `android:"arch_variant"` |
| 194 | S_Embedded_Different string `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | type testPropertiesStruct struct { |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 198 | name string |
| 199 | private string |
| 200 | Public_Ignore string `sdk:"ignore"` |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 201 | Public_Keep string `sdk:"keep"` |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 202 | S_Common string |
| 203 | S_Different string `android:"arch_variant"` |
| 204 | A_Common []string |
| 205 | A_Different []string `android:"arch_variant"` |
| 206 | F_Common *bool |
| 207 | F_Different *bool `android:"arch_variant"` |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 208 | EmbeddedPropertiesStruct |
| 209 | } |
| 210 | |
Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 211 | func (p *testPropertiesStruct) optimizableProperties() interface{} { |
| 212 | return p |
| 213 | } |
| 214 | |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 215 | func (p *testPropertiesStruct) String() string { |
| 216 | return p.name |
| 217 | } |
| 218 | |
| 219 | var _ propertiesContainer = (*testPropertiesStruct)(nil) |
| 220 | |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 221 | func TestCommonValueOptimization(t *testing.T) { |
Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 222 | common := &testPropertiesStruct{name: "common"} |
Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 223 | structs := []propertiesContainer{ |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 224 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 225 | name: "struct-0", |
| 226 | private: "common", |
| 227 | Public_Ignore: "common", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 228 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 229 | S_Common: "common", |
| 230 | S_Different: "upper", |
| 231 | A_Common: []string{"first", "second"}, |
| 232 | A_Different: []string{"alpha", "beta"}, |
| 233 | F_Common: proptools.BoolPtr(false), |
| 234 | F_Different: proptools.BoolPtr(false), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 235 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 236 | S_Embedded_Common: "embedded_common", |
| 237 | S_Embedded_Different: "embedded_upper", |
| 238 | }, |
| 239 | }, |
| 240 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 241 | name: "struct-1", |
| 242 | private: "common", |
| 243 | Public_Ignore: "common", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 244 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 245 | S_Common: "common", |
| 246 | S_Different: "lower", |
| 247 | A_Common: []string{"first", "second"}, |
| 248 | A_Different: []string{"alpha", "delta"}, |
| 249 | F_Common: proptools.BoolPtr(false), |
| 250 | F_Different: proptools.BoolPtr(true), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 251 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 252 | S_Embedded_Common: "embedded_common", |
| 253 | S_Embedded_Different: "embedded_lower", |
| 254 | }, |
| 255 | }, |
| 256 | } |
| 257 | |
| 258 | extractor := newCommonValueExtractor(common) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 259 | |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 260 | err := extractor.extractCommonProperties(common, structs) |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 261 | android.AssertDeepEquals(t, "unexpected error", nil, err) |
Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 262 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 263 | android.AssertDeepEquals(t, "common properties not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 264 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 265 | name: "common", |
| 266 | private: "", |
| 267 | Public_Ignore: "", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 268 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 269 | S_Common: "common", |
| 270 | S_Different: "", |
| 271 | A_Common: []string{"first", "second"}, |
| 272 | A_Different: []string(nil), |
| 273 | F_Common: proptools.BoolPtr(false), |
| 274 | F_Different: nil, |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 275 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 276 | S_Embedded_Common: "embedded_common", |
| 277 | S_Embedded_Different: "", |
| 278 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 279 | }, |
| 280 | common) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 281 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 282 | android.AssertDeepEquals(t, "updated properties[0] not correct", |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 283 | &testPropertiesStruct{ |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 284 | name: "struct-0", |
| 285 | private: "common", |
| 286 | Public_Ignore: "common", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 287 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 288 | S_Common: "", |
| 289 | S_Different: "upper", |
| 290 | A_Common: nil, |
| 291 | A_Different: []string{"alpha", "beta"}, |
| 292 | F_Common: nil, |
| 293 | F_Different: proptools.BoolPtr(false), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 294 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 295 | S_Embedded_Common: "", |
| 296 | S_Embedded_Different: "embedded_upper", |
| 297 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 298 | }, |
| 299 | structs[0]) |
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[1] 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-1", |
| 304 | private: "common", |
| 305 | Public_Ignore: "common", |
Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 306 | Public_Keep: "keep", |
Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 307 | S_Common: "", |
| 308 | S_Different: "lower", |
| 309 | A_Common: nil, |
| 310 | A_Different: []string{"alpha", "delta"}, |
| 311 | F_Common: nil, |
| 312 | F_Different: proptools.BoolPtr(true), |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 313 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ |
| 314 | S_Embedded_Common: "", |
| 315 | S_Embedded_Different: "embedded_lower", |
| 316 | }, |
Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 317 | }, |
| 318 | structs[1]) |
Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 319 | } |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 320 | |
| 321 | func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) { |
| 322 | common := &testPropertiesStruct{name: "common"} |
| 323 | structs := []propertiesContainer{ |
| 324 | &testPropertiesStruct{ |
| 325 | name: "struct-0", |
| 326 | S_Common: "should-be-but-is-not-common0", |
| 327 | }, |
| 328 | &testPropertiesStruct{ |
| 329 | name: "struct-1", |
| 330 | S_Common: "should-be-but-is-not-common1", |
| 331 | }, |
| 332 | } |
| 333 | |
| 334 | extractor := newCommonValueExtractor(common) |
| 335 | |
Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 336 | err := extractor.extractCommonProperties(common, structs) |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 337 | 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] | 338 | "struct-0" has value "should-be-but-is-not-common0" |
| 339 | "struct-1" has value "should-be-but-is-not-common1"`, err) |
| 340 | } |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 341 | |
| 342 | // Ensure that sdk snapshot related environment variables work correctly. |
| 343 | func TestSnapshot_EnvConfiguration(t *testing.T) { |
| 344 | bp := ` |
| 345 | sdk { |
| 346 | name: "mysdk", |
| 347 | java_header_libs: ["myjavalib"], |
| 348 | } |
| 349 | |
| 350 | java_library { |
| 351 | name: "myjavalib", |
| 352 | srcs: ["Test.java"], |
| 353 | system_modules: "none", |
| 354 | sdk_version: "none", |
| 355 | compile_dex: true, |
| 356 | host_supported: true, |
| 357 | } |
| 358 | ` |
| 359 | preparer := android.GroupFixturePreparers( |
| 360 | prepareForSdkTestWithJava, |
| 361 | android.FixtureWithRootAndroidBp(bp), |
| 362 | ) |
| 363 | |
| 364 | checkZipFile := func(t *testing.T, result *android.TestResult, expected string) { |
| 365 | zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles") |
| 366 | android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String()) |
| 367 | } |
| 368 | |
| 369 | t.Run("no env variables", func(t *testing.T) { |
| 370 | result := preparer.RunTest(t) |
| 371 | |
| 372 | checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") |
| 373 | |
| 374 | CheckSnapshot(t, result, "mysdk", "", |
| 375 | checkAndroidBpContents(` |
| 376 | // This is auto-generated. DO NOT EDIT. |
| 377 | |
Spandan Das | a5e26d3 | 2024-03-06 14:04:36 +0000 | [diff] [blame] | 378 | apex_contributions_defaults { |
| 379 | name: "mysdk.contributions", |
| 380 | contents: ["prebuilt_myjavalib"], |
| 381 | } |
| 382 | |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 383 | java_import { |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 384 | name: "myjavalib", |
| 385 | prefer: false, |
| 386 | visibility: ["//visibility:public"], |
| 387 | apex_available: ["//apex_available:platform"], |
| 388 | jars: ["java/myjavalib.jar"], |
| 389 | } |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 390 | `), |
| 391 | ) |
| 392 | }) |
Paul Duffin | 64fb526 | 2021-05-05 21:36:04 +0100 | [diff] [blame] | 393 | |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 394 | t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) { |
| 395 | result := android.GroupFixturePreparers( |
| 396 | prepareForSdkTestWithJava, |
| 397 | java.PrepareForTestWithJavaDefaultModules, |
| 398 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 399 | java.FixtureWithLastReleaseApis("mysdklibrary"), |
| 400 | android.FixtureWithRootAndroidBp(` |
| 401 | sdk { |
| 402 | name: "mysdk", |
| 403 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 404 | } |
| 405 | |
| 406 | bootclasspath_fragment { |
| 407 | name: "mybootclasspathfragment", |
| 408 | apex_available: ["myapex"], |
| 409 | contents: ["mysdklibrary"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 410 | hidden_api: { |
| 411 | split_packages: ["*"], |
| 412 | }, |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | java_sdk_library { |
| 416 | name: "mysdklibrary", |
| 417 | srcs: ["Test.java"], |
| 418 | compile_dex: true, |
Paul Duffin | 1938dba | 2022-07-26 23:53:00 +0000 | [diff] [blame] | 419 | sdk_version: "S", |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 420 | public: {enabled: true}, |
| 421 | permitted_packages: ["mysdklibrary"], |
| 422 | } |
| 423 | `), |
| 424 | android.FixtureMergeEnv(map[string]string{ |
| 425 | "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S", |
| 426 | }), |
Colin Cross | a66b463 | 2024-08-08 15:50:47 -0700 | [diff] [blame] | 427 | android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 428 | ).RunTest(t) |
| 429 | |
| 430 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | b01ac4b | 2022-05-24 20:10:05 +0000 | [diff] [blame] | 431 | checkAndroidBpContents(` |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 432 | // This is auto-generated. DO NOT EDIT. |
| 433 | |
Spandan Das | a5e26d3 | 2024-03-06 14:04:36 +0000 | [diff] [blame] | 434 | apex_contributions_defaults { |
| 435 | name: "mysdk.contributions", |
| 436 | contents: ["prebuilt_mysdklibrary"], |
| 437 | } |
| 438 | |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 439 | prebuilt_bootclasspath_fragment { |
| 440 | name: "mybootclasspathfragment", |
| 441 | prefer: false, |
| 442 | visibility: ["//visibility:public"], |
| 443 | apex_available: ["myapex"], |
| 444 | contents: ["mysdklibrary"], |
| 445 | hidden_api: { |
| 446 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 447 | metadata: "hiddenapi/metadata.csv", |
| 448 | index: "hiddenapi/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 449 | stub_flags: "hiddenapi/stub-flags.csv", |
| 450 | all_flags: "hiddenapi/all-flags.csv", |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 451 | }, |
| 452 | } |
| 453 | |
| 454 | java_sdk_library_import { |
| 455 | name: "mysdklibrary", |
| 456 | prefer: false, |
| 457 | visibility: ["//visibility:public"], |
| 458 | apex_available: ["//apex_available:platform"], |
| 459 | shared_library: true, |
| 460 | compile_dex: true, |
| 461 | permitted_packages: ["mysdklibrary"], |
| 462 | public: { |
| 463 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 464 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 465 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 466 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 467 | sdk_version: "current", |
| 468 | }, |
| 469 | } |
| 470 | `), |
| 471 | |
| 472 | checkAllCopyRules(` |
| 473 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 474 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv |
| 475 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 476 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv |
| 477 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv |
Jihoon Kang | f55a5f7 | 2024-01-08 08:56:20 +0000 | [diff] [blame] | 478 | .intermediates/mysdklibrary.stubs.exportable/android_common/combined/mysdklibrary.stubs.exportable.jar -> sdk_library/public/mysdklibrary-stubs.jar |
| 479 | .intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt |
| 480 | .intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt |
Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 481 | `), |
| 482 | ) |
| 483 | }) |
| 484 | |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 485 | t.Run("test replacing exportable module", func(t *testing.T) { |
| 486 | result := android.GroupFixturePreparers( |
| 487 | prepareForSdkTestWithJava, |
| 488 | java.PrepareForTestWithJavaDefaultModules, |
| 489 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 490 | java.FixtureWithLastReleaseApis("mysdklibrary", "anothersdklibrary"), |
| 491 | android.FixtureWithRootAndroidBp(` |
| 492 | sdk { |
| 493 | name: "mysdk", |
| 494 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 495 | } |
| 496 | |
| 497 | bootclasspath_fragment { |
| 498 | name: "mybootclasspathfragment", |
| 499 | apex_available: ["myapex"], |
| 500 | contents: ["mysdklibrary"], |
| 501 | hidden_api: { |
| 502 | split_packages: ["*"], |
| 503 | }, |
| 504 | core_platform_api: { |
| 505 | stub_libs: [ |
| 506 | "anothersdklibrary.stubs.exportable", |
| 507 | ], |
| 508 | }, |
| 509 | api: { |
| 510 | stub_libs: [ |
| 511 | "anothersdklibrary", |
| 512 | ], |
| 513 | }, |
| 514 | } |
| 515 | |
| 516 | java_sdk_library { |
| 517 | name: "mysdklibrary", |
| 518 | srcs: ["Test.java"], |
| 519 | compile_dex: true, |
| 520 | min_sdk_version: "S", |
| 521 | public: {enabled: true}, |
| 522 | permitted_packages: ["mysdklibrary"], |
| 523 | } |
| 524 | |
| 525 | java_sdk_library { |
| 526 | name: "anothersdklibrary", |
| 527 | srcs: ["Test.java"], |
| 528 | compile_dex: true, |
| 529 | min_sdk_version: "S", |
| 530 | public: {enabled: true}, |
| 531 | system: {enabled: true}, |
| 532 | module_lib: {enabled: true}, |
| 533 | } |
| 534 | `), |
| 535 | android.FixtureMergeEnv(map[string]string{ |
| 536 | "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S", |
| 537 | }), |
| 538 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 539 | variables.Platform_version_active_codenames = []string{"UpsideDownCake", "Tiramisu", "S-V2"} |
| 540 | }), |
Colin Cross | a66b463 | 2024-08-08 15:50:47 -0700 | [diff] [blame] | 541 | android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), |
Jihoon Kang | 98aa8fa | 2024-06-07 11:06:57 +0000 | [diff] [blame] | 542 | ).RunTest(t) |
| 543 | |
| 544 | CheckSnapshot(t, result, "mysdk", "", |
| 545 | checkAndroidBpContents(` |
| 546 | // This is auto-generated. DO NOT EDIT. |
| 547 | |
| 548 | prebuilt_bootclasspath_fragment { |
| 549 | name: "mybootclasspathfragment", |
| 550 | prefer: false, |
| 551 | visibility: ["//visibility:public"], |
| 552 | apex_available: ["myapex"], |
| 553 | contents: ["mysdklibrary"], |
| 554 | api: { |
| 555 | stub_libs: ["anothersdklibrary"], |
| 556 | }, |
| 557 | core_platform_api: { |
| 558 | stub_libs: ["anothersdklibrary.stubs"], |
| 559 | }, |
| 560 | hidden_api: { |
| 561 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 562 | metadata: "hiddenapi/metadata.csv", |
| 563 | index: "hiddenapi/index.csv", |
| 564 | stub_flags: "hiddenapi/stub-flags.csv", |
| 565 | all_flags: "hiddenapi/all-flags.csv", |
| 566 | }, |
| 567 | } |
| 568 | |
| 569 | java_sdk_library_import { |
| 570 | name: "mysdklibrary", |
| 571 | prefer: false, |
| 572 | visibility: ["//visibility:public"], |
| 573 | apex_available: ["//apex_available:platform"], |
| 574 | shared_library: true, |
| 575 | compile_dex: true, |
| 576 | permitted_packages: ["mysdklibrary"], |
| 577 | public: { |
| 578 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 579 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 580 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 581 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 582 | sdk_version: "current", |
| 583 | }, |
| 584 | } |
| 585 | |
| 586 | java_sdk_library_import { |
| 587 | name: "anothersdklibrary", |
| 588 | prefer: false, |
| 589 | visibility: ["//visibility:public"], |
| 590 | apex_available: ["//apex_available:platform"], |
| 591 | shared_library: true, |
| 592 | compile_dex: true, |
| 593 | public: { |
| 594 | jars: ["sdk_library/public/anothersdklibrary-stubs.jar"], |
| 595 | stub_srcs: ["sdk_library/public/anothersdklibrary_stub_sources"], |
| 596 | current_api: "sdk_library/public/anothersdklibrary.txt", |
| 597 | removed_api: "sdk_library/public/anothersdklibrary-removed.txt", |
| 598 | sdk_version: "current", |
| 599 | }, |
| 600 | system: { |
| 601 | jars: ["sdk_library/system/anothersdklibrary-stubs.jar"], |
| 602 | stub_srcs: ["sdk_library/system/anothersdklibrary_stub_sources"], |
| 603 | current_api: "sdk_library/system/anothersdklibrary.txt", |
| 604 | removed_api: "sdk_library/system/anothersdklibrary-removed.txt", |
| 605 | sdk_version: "system_current", |
| 606 | }, |
| 607 | module_lib: { |
| 608 | jars: ["sdk_library/module-lib/anothersdklibrary-stubs.jar"], |
| 609 | stub_srcs: ["sdk_library/module-lib/anothersdklibrary_stub_sources"], |
| 610 | current_api: "sdk_library/module-lib/anothersdklibrary.txt", |
| 611 | removed_api: "sdk_library/module-lib/anothersdklibrary-removed.txt", |
| 612 | sdk_version: "module_current", |
| 613 | }, |
| 614 | } |
| 615 | `), |
| 616 | ) |
| 617 | }) |
| 618 | |
Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 619 | } |