| 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 |  | 
 | 412 | 	t.Run("SOONG_SDK_SNAPSHOT_PREFER=true", func(t *testing.T) { | 
 | 413 | 		result := android.GroupFixturePreparers( | 
 | 414 | 			preparer, | 
 | 415 | 			android.FixtureMergeEnv(map[string]string{ | 
 | 416 | 				"SOONG_SDK_SNAPSHOT_PREFER": "true", | 
 | 417 | 			}), | 
 | 418 | 		).RunTest(t) | 
 | 419 |  | 
 | 420 | 		checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") | 
 | 421 |  | 
 | 422 | 		CheckSnapshot(t, result, "mysdk", "", | 
 | 423 | 			checkAndroidBpContents(` | 
 | 424 | // This is auto-generated. DO NOT EDIT. | 
 | 425 |  | 
 | 426 | java_import { | 
| Paul Duffin | 64fb526 | 2021-05-05 21:36:04 +0100 | [diff] [blame] | 427 |     name: "myjavalib", | 
 | 428 |     prefer: true, | 
 | 429 |     visibility: ["//visibility:public"], | 
 | 430 |     apex_available: ["//apex_available:platform"], | 
 | 431 |     jars: ["java/myjavalib.jar"], | 
 | 432 | } | 
| Paul Duffin | 64fb526 | 2021-05-05 21:36:04 +0100 | [diff] [blame] | 433 | 			`), | 
 | 434 | 		) | 
 | 435 | 	}) | 
| Paul Duffin | 43f7bf0 | 2021-05-05 22:00:51 +0100 | [diff] [blame] | 436 |  | 
| Paul Duffin | fb9a7f9 | 2021-07-06 17:18:42 +0100 | [diff] [blame] | 437 | 	t.Run("SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR=module:build_from_source", func(t *testing.T) { | 
 | 438 | 		result := android.GroupFixturePreparers( | 
 | 439 | 			preparer, | 
 | 440 | 			android.FixtureMergeEnv(map[string]string{ | 
 | 441 | 				"SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR": "module:build_from_source", | 
 | 442 | 			}), | 
 | 443 | 		).RunTest(t) | 
 | 444 |  | 
 | 445 | 		checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip") | 
 | 446 |  | 
 | 447 | 		CheckSnapshot(t, result, "mysdk", "", | 
 | 448 | 			checkAndroidBpContents(` | 
 | 449 | // This is auto-generated. DO NOT EDIT. | 
 | 450 |  | 
 | 451 | java_import { | 
| Paul Duffin | fb9a7f9 | 2021-07-06 17:18:42 +0100 | [diff] [blame] | 452 |     name: "myjavalib", | 
 | 453 |     prefer: false, | 
 | 454 |     use_source_config_var: { | 
 | 455 |         config_namespace: "module", | 
 | 456 |         var_name: "build_from_source", | 
 | 457 |     }, | 
 | 458 |     visibility: ["//visibility:public"], | 
 | 459 |     apex_available: ["//apex_available:platform"], | 
 | 460 |     jars: ["java/myjavalib.jar"], | 
 | 461 | } | 
| Paul Duffin | fb9a7f9 | 2021-07-06 17:18:42 +0100 | [diff] [blame] | 462 | 			`), | 
 | 463 | 		) | 
 | 464 | 	}) | 
 | 465 |  | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 466 | 	t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) { | 
 | 467 | 		result := android.GroupFixturePreparers( | 
 | 468 | 			prepareForSdkTestWithJava, | 
 | 469 | 			java.PrepareForTestWithJavaDefaultModules, | 
 | 470 | 			java.PrepareForTestWithJavaSdkLibraryFiles, | 
 | 471 | 			java.FixtureWithLastReleaseApis("mysdklibrary"), | 
 | 472 | 			android.FixtureWithRootAndroidBp(` | 
 | 473 | 			sdk { | 
 | 474 | 				name: "mysdk", | 
 | 475 | 				bootclasspath_fragments: ["mybootclasspathfragment"], | 
 | 476 | 			} | 
 | 477 |  | 
 | 478 | 			bootclasspath_fragment { | 
 | 479 | 				name: "mybootclasspathfragment", | 
 | 480 | 				apex_available: ["myapex"], | 
 | 481 | 				contents: ["mysdklibrary"], | 
| Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 482 | 				hidden_api: { | 
 | 483 | 					split_packages: ["*"], | 
 | 484 | 				}, | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 485 | 			} | 
 | 486 |  | 
 | 487 | 			java_sdk_library { | 
 | 488 | 				name: "mysdklibrary", | 
 | 489 | 				srcs: ["Test.java"], | 
 | 490 | 				compile_dex: true, | 
| Paul Duffin | 1938dba | 2022-07-26 23:53:00 +0000 | [diff] [blame] | 491 | 				sdk_version: "S", | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 492 | 				public: {enabled: true}, | 
 | 493 | 				permitted_packages: ["mysdklibrary"], | 
 | 494 | 			} | 
 | 495 | 		`), | 
 | 496 | 			android.FixtureMergeEnv(map[string]string{ | 
 | 497 | 				"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S", | 
 | 498 | 			}), | 
 | 499 | 		).RunTest(t) | 
 | 500 |  | 
 | 501 | 		CheckSnapshot(t, result, "mysdk", "", | 
| Paul Duffin | b01ac4b | 2022-05-24 20:10:05 +0000 | [diff] [blame] | 502 | 			checkAndroidBpContents(` | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 503 | // This is auto-generated. DO NOT EDIT. | 
 | 504 |  | 
 | 505 | prebuilt_bootclasspath_fragment { | 
 | 506 |     name: "mybootclasspathfragment", | 
 | 507 |     prefer: false, | 
 | 508 |     visibility: ["//visibility:public"], | 
 | 509 |     apex_available: ["myapex"], | 
 | 510 |     contents: ["mysdklibrary"], | 
 | 511 |     hidden_api: { | 
 | 512 |         annotation_flags: "hiddenapi/annotation-flags.csv", | 
 | 513 |         metadata: "hiddenapi/metadata.csv", | 
 | 514 |         index: "hiddenapi/index.csv", | 
| Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 515 |         stub_flags: "hiddenapi/stub-flags.csv", | 
 | 516 |         all_flags: "hiddenapi/all-flags.csv", | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 517 |     }, | 
 | 518 | } | 
 | 519 |  | 
 | 520 | java_sdk_library_import { | 
 | 521 |     name: "mysdklibrary", | 
 | 522 |     prefer: false, | 
 | 523 |     visibility: ["//visibility:public"], | 
 | 524 |     apex_available: ["//apex_available:platform"], | 
 | 525 |     shared_library: true, | 
 | 526 |     compile_dex: true, | 
 | 527 |     permitted_packages: ["mysdklibrary"], | 
 | 528 |     public: { | 
 | 529 |         jars: ["sdk_library/public/mysdklibrary-stubs.jar"], | 
 | 530 |         stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], | 
 | 531 |         current_api: "sdk_library/public/mysdklibrary.txt", | 
 | 532 |         removed_api: "sdk_library/public/mysdklibrary-removed.txt", | 
 | 533 |         sdk_version: "current", | 
 | 534 |     }, | 
 | 535 | } | 
 | 536 | `), | 
 | 537 |  | 
 | 538 | 			checkAllCopyRules(` | 
 | 539 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv | 
 | 540 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv | 
 | 541 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv | 
| Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 542 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv | 
 | 543 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv | 
| Paul Duffin | 39abf8f | 2021-09-24 14:58:27 +0100 | [diff] [blame] | 544 | .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar | 
 | 545 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt | 
 | 546 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt | 
 | 547 | `), | 
 | 548 | 		) | 
 | 549 | 	}) | 
 | 550 |  | 
| Paul Duffin | 62035b5 | 2021-05-05 21:35:49 +0100 | [diff] [blame] | 551 | } |