| 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"` | 
| Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 224 | Public_Keep   string `sdk:"keep"` | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 225 | S_Common      string | 
|  | 226 | S_Different   string `android:"arch_variant"` | 
|  | 227 | A_Common      []string | 
|  | 228 | A_Different   []string `android:"arch_variant"` | 
|  | 229 | F_Common      *bool | 
|  | 230 | F_Different   *bool `android:"arch_variant"` | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 231 | EmbeddedPropertiesStruct | 
|  | 232 | } | 
|  | 233 |  | 
| Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 234 | func (p *testPropertiesStruct) optimizableProperties() interface{} { | 
|  | 235 | return p | 
|  | 236 | } | 
|  | 237 |  | 
| Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 238 | func (p *testPropertiesStruct) String() string { | 
|  | 239 | return p.name | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | var _ propertiesContainer = (*testPropertiesStruct)(nil) | 
|  | 243 |  | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 244 | func TestCommonValueOptimization(t *testing.T) { | 
| Paul Duffin | 4b8b793 | 2020-05-06 12:35:38 +0100 | [diff] [blame] | 245 | common := &testPropertiesStruct{name: "common"} | 
| Paul Duffin | f34f6d8 | 2020-04-30 15:48:31 +0100 | [diff] [blame] | 246 | structs := []propertiesContainer{ | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 247 | &testPropertiesStruct{ | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 248 | name:          "struct-0", | 
|  | 249 | private:       "common", | 
|  | 250 | Public_Ignore: "common", | 
| Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 251 | Public_Keep:   "keep", | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 252 | S_Common:      "common", | 
|  | 253 | S_Different:   "upper", | 
|  | 254 | A_Common:      []string{"first", "second"}, | 
|  | 255 | A_Different:   []string{"alpha", "beta"}, | 
|  | 256 | F_Common:      proptools.BoolPtr(false), | 
|  | 257 | F_Different:   proptools.BoolPtr(false), | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 258 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ | 
|  | 259 | S_Embedded_Common:    "embedded_common", | 
|  | 260 | S_Embedded_Different: "embedded_upper", | 
|  | 261 | }, | 
|  | 262 | }, | 
|  | 263 | &testPropertiesStruct{ | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 264 | name:          "struct-1", | 
|  | 265 | private:       "common", | 
|  | 266 | Public_Ignore: "common", | 
| Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 267 | Public_Keep:   "keep", | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 268 | S_Common:      "common", | 
|  | 269 | S_Different:   "lower", | 
|  | 270 | A_Common:      []string{"first", "second"}, | 
|  | 271 | A_Different:   []string{"alpha", "delta"}, | 
|  | 272 | F_Common:      proptools.BoolPtr(false), | 
|  | 273 | F_Different:   proptools.BoolPtr(true), | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 274 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ | 
|  | 275 | S_Embedded_Common:    "embedded_common", | 
|  | 276 | S_Embedded_Different: "embedded_lower", | 
|  | 277 | }, | 
|  | 278 | }, | 
|  | 279 | } | 
|  | 280 |  | 
|  | 281 | extractor := newCommonValueExtractor(common) | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 282 |  | 
| Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 283 | err := extractor.extractCommonProperties(common, structs) | 
| Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 284 | android.AssertDeepEquals(t, "unexpected error", nil, err) | 
| Paul Duffin | c459f89 | 2020-04-30 18:08:29 +0100 | [diff] [blame] | 285 |  | 
| Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 286 | android.AssertDeepEquals(t, "common properties not correct", | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 287 | &testPropertiesStruct{ | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 288 | name:          "common", | 
|  | 289 | private:       "", | 
|  | 290 | Public_Ignore: "", | 
| Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 291 | Public_Keep:   "keep", | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 292 | S_Common:      "common", | 
|  | 293 | S_Different:   "", | 
|  | 294 | A_Common:      []string{"first", "second"}, | 
|  | 295 | A_Different:   []string(nil), | 
|  | 296 | F_Common:      proptools.BoolPtr(false), | 
|  | 297 | F_Different:   nil, | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 298 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ | 
|  | 299 | S_Embedded_Common:    "embedded_common", | 
|  | 300 | S_Embedded_Different: "", | 
|  | 301 | }, | 
| Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 302 | }, | 
|  | 303 | common) | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 304 |  | 
| Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 305 | android.AssertDeepEquals(t, "updated properties[0] not correct", | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 306 | &testPropertiesStruct{ | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 307 | name:          "struct-0", | 
|  | 308 | private:       "common", | 
|  | 309 | Public_Ignore: "common", | 
| Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 310 | Public_Keep:   "keep", | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 311 | S_Common:      "", | 
|  | 312 | S_Different:   "upper", | 
|  | 313 | A_Common:      nil, | 
|  | 314 | A_Different:   []string{"alpha", "beta"}, | 
|  | 315 | F_Common:      nil, | 
|  | 316 | F_Different:   proptools.BoolPtr(false), | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 317 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ | 
|  | 318 | S_Embedded_Common:    "", | 
|  | 319 | S_Embedded_Different: "embedded_upper", | 
|  | 320 | }, | 
| Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 321 | }, | 
|  | 322 | structs[0]) | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 323 |  | 
| Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 324 | android.AssertDeepEquals(t, "updated properties[1] not correct", | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 325 | &testPropertiesStruct{ | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 326 | name:          "struct-1", | 
|  | 327 | private:       "common", | 
|  | 328 | Public_Ignore: "common", | 
| Paul Duffin | bfdca96 | 2022-09-22 16:21:54 +0100 | [diff] [blame] | 329 | Public_Keep:   "keep", | 
| Paul Duffin | 02e25c8 | 2022-09-22 15:30:58 +0100 | [diff] [blame] | 330 | S_Common:      "", | 
|  | 331 | S_Different:   "lower", | 
|  | 332 | A_Common:      nil, | 
|  | 333 | A_Different:   []string{"alpha", "delta"}, | 
|  | 334 | F_Common:      nil, | 
|  | 335 | F_Different:   proptools.BoolPtr(true), | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 336 | EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{ | 
|  | 337 | S_Embedded_Common:    "", | 
|  | 338 | S_Embedded_Different: "embedded_lower", | 
|  | 339 | }, | 
| Paul Duffin | 1d6c0df | 2020-05-06 12:50:19 +0100 | [diff] [blame] | 340 | }, | 
|  | 341 | structs[1]) | 
| Paul Duffin | b07fa51 | 2020-03-10 22:17:04 +0000 | [diff] [blame] | 342 | } | 
| Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 343 |  | 
|  | 344 | func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) { | 
|  | 345 | common := &testPropertiesStruct{name: "common"} | 
|  | 346 | structs := []propertiesContainer{ | 
|  | 347 | &testPropertiesStruct{ | 
|  | 348 | name:     "struct-0", | 
|  | 349 | S_Common: "should-be-but-is-not-common0", | 
|  | 350 | }, | 
|  | 351 | &testPropertiesStruct{ | 
|  | 352 | name:     "struct-1", | 
|  | 353 | S_Common: "should-be-but-is-not-common1", | 
|  | 354 | }, | 
|  | 355 | } | 
|  | 356 |  | 
|  | 357 | extractor := newCommonValueExtractor(common) | 
|  | 358 |  | 
| Paul Duffin | 864e1b4 | 2020-05-06 10:23:19 +0100 | [diff] [blame] | 359 | err := extractor.extractCommonProperties(common, structs) | 
| Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 360 | 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] | 361 | "struct-0" has value "should-be-but-is-not-common0" | 
|  | 362 | "struct-1" has value "should-be-but-is-not-common1"`, err) | 
|  | 363 | } | 
| Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 364 |  | 
|  | 365 | // Ensure that sdk snapshot related environment variables work correctly. | 
|  | 366 | func TestSnapshot_EnvConfiguration(t *testing.T) { | 
|  | 367 | bp := ` | 
|  | 368 | sdk { | 
|  | 369 | name: "mysdk", | 
|  | 370 | java_header_libs: ["myjavalib"], | 
|  | 371 | } | 
|  | 372 |  | 
|  | 373 | java_library { | 
|  | 374 | name: "myjavalib", | 
|  | 375 | srcs: ["Test.java"], | 
|  | 376 | system_modules: "none", | 
|  | 377 | sdk_version: "none", | 
|  | 378 | compile_dex: true, | 
|  | 379 | host_supported: true, | 
|  | 380 | } | 
|  | 381 | ` | 
|  | 382 | preparer := android.GroupFixturePreparers( | 
|  | 383 | prepareForSdkTestWithJava, | 
|  | 384 | android.FixtureWithRootAndroidBp(bp), | 
|  | 385 | ) | 
|  | 386 |  | 
|  | 387 | checkZipFile := func(t *testing.T, result *android.TestResult, expected string) { | 
|  | 388 | zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles") | 
|  | 389 | android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String()) | 
|  | 390 | } | 
|  | 391 |  | 
|  | 392 | t.Run("no env variables", func(t *testing.T) { | 
|  | 393 | result := preparer.RunTest(t) | 
|  | 394 |  | 
|  | 395 | checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") | 
|  | 396 |  | 
|  | 397 | CheckSnapshot(t, result, "mysdk", "", | 
|  | 398 | checkAndroidBpContents(` | 
|  | 399 | // This is auto-generated. DO NOT EDIT. | 
|  | 400 |  | 
|  | 401 | java_import { | 
| Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 402 | name: "myjavalib", | 
|  | 403 | prefer: false, | 
|  | 404 | visibility: ["//visibility:public"], | 
|  | 405 | apex_available: ["//apex_available:platform"], | 
|  | 406 | jars: ["java/myjavalib.jar"], | 
|  | 407 | } | 
| Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 408 | `), | 
|  | 409 | ) | 
|  | 410 | }) | 
| Paul Duffin | 64fb526 | 2021-05-05 21:36:04 +0100 | [diff] [blame] | 411 |  | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 412 | t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) { | 
|  | 413 | result := android.GroupFixturePreparers( | 
|  | 414 | prepareForSdkTestWithJava, | 
|  | 415 | java.PrepareForTestWithJavaDefaultModules, | 
|  | 416 | java.PrepareForTestWithJavaSdkLibraryFiles, | 
|  | 417 | java.FixtureWithLastReleaseApis("mysdklibrary"), | 
|  | 418 | android.FixtureWithRootAndroidBp(` | 
|  | 419 | sdk { | 
|  | 420 | name: "mysdk", | 
|  | 421 | bootclasspath_fragments: ["mybootclasspathfragment"], | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | bootclasspath_fragment { | 
|  | 425 | name: "mybootclasspathfragment", | 
|  | 426 | apex_available: ["myapex"], | 
|  | 427 | contents: ["mysdklibrary"], | 
| Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 428 | hidden_api: { | 
|  | 429 | split_packages: ["*"], | 
|  | 430 | }, | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 431 | } | 
|  | 432 |  | 
|  | 433 | java_sdk_library { | 
|  | 434 | name: "mysdklibrary", | 
|  | 435 | srcs: ["Test.java"], | 
|  | 436 | compile_dex: true, | 
| Paul Duffin | 1938dba | 2022-07-26 23:53:00 +0000 | [diff] [blame] | 437 | sdk_version: "S", | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 438 | public: {enabled: true}, | 
|  | 439 | permitted_packages: ["mysdklibrary"], | 
|  | 440 | } | 
|  | 441 | `), | 
|  | 442 | android.FixtureMergeEnv(map[string]string{ | 
|  | 443 | "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S", | 
|  | 444 | }), | 
|  | 445 | ).RunTest(t) | 
|  | 446 |  | 
|  | 447 | CheckSnapshot(t, result, "mysdk", "", | 
| Paul Duffin | b01ac4b | 2022-05-24 20:10:05 +0000 | [diff] [blame] | 448 | checkAndroidBpContents(` | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 449 | // This is auto-generated. DO NOT EDIT. | 
|  | 450 |  | 
|  | 451 | prebuilt_bootclasspath_fragment { | 
|  | 452 | name: "mybootclasspathfragment", | 
|  | 453 | prefer: false, | 
|  | 454 | visibility: ["//visibility:public"], | 
|  | 455 | apex_available: ["myapex"], | 
|  | 456 | contents: ["mysdklibrary"], | 
|  | 457 | hidden_api: { | 
|  | 458 | annotation_flags: "hiddenapi/annotation-flags.csv", | 
|  | 459 | metadata: "hiddenapi/metadata.csv", | 
|  | 460 | index: "hiddenapi/index.csv", | 
| Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 461 | stub_flags: "hiddenapi/stub-flags.csv", | 
|  | 462 | all_flags: "hiddenapi/all-flags.csv", | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 463 | }, | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | java_sdk_library_import { | 
|  | 467 | name: "mysdklibrary", | 
|  | 468 | prefer: false, | 
|  | 469 | visibility: ["//visibility:public"], | 
|  | 470 | apex_available: ["//apex_available:platform"], | 
|  | 471 | shared_library: true, | 
|  | 472 | compile_dex: true, | 
|  | 473 | permitted_packages: ["mysdklibrary"], | 
|  | 474 | public: { | 
|  | 475 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], | 
|  | 476 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], | 
|  | 477 | current_api: "sdk_library/public/mysdklibrary.txt", | 
|  | 478 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", | 
|  | 479 | sdk_version: "current", | 
|  | 480 | }, | 
|  | 481 | } | 
|  | 482 | `), | 
|  | 483 |  | 
|  | 484 | checkAllCopyRules(` | 
|  | 485 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv | 
|  | 486 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv | 
|  | 487 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv | 
| Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 488 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv | 
|  | 489 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv | 
| Jihoon Kang | 1147b31 | 2023-06-08 23:25:57 +0000 | [diff] [blame] | 490 | .intermediates/mysdklibrary.stubs/android_common/combined/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 491 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt | 
|  | 492 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt | 
|  | 493 | `), | 
|  | 494 | ) | 
|  | 495 | }) | 
|  | 496 |  | 
| Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 497 | } |