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