Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1 | // Copyright 2021 Google LLC |
| 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 mk2rbc |
| 16 | |
| 17 | import ( |
| 18 | "bytes" |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 19 | "io/fs" |
| 20 | "path/filepath" |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 21 | "strings" |
| 22 | "testing" |
| 23 | ) |
| 24 | |
| 25 | var testCases = []struct { |
| 26 | desc string |
| 27 | mkname string |
| 28 | in string |
| 29 | expected string |
| 30 | }{ |
| 31 | { |
| 32 | desc: "Comment", |
| 33 | mkname: "product.mk", |
| 34 | in: ` |
| 35 | # Comment |
| 36 | # FOO= a\ |
| 37 | b |
| 38 | `, |
| 39 | expected: `# Comment |
| 40 | # FOO= a |
| 41 | # b |
| 42 | load("//build/make/core:product_config.rbc", "rblf") |
| 43 | |
| 44 | def init(g, handle): |
| 45 | cfg = rblf.cfg(handle) |
| 46 | `, |
| 47 | }, |
| 48 | { |
| 49 | desc: "Name conversion", |
| 50 | mkname: "path/bar-baz.mk", |
| 51 | in: ` |
| 52 | # Comment |
| 53 | `, |
| 54 | expected: `# Comment |
| 55 | load("//build/make/core:product_config.rbc", "rblf") |
| 56 | |
| 57 | def init(g, handle): |
| 58 | cfg = rblf.cfg(handle) |
| 59 | `, |
| 60 | }, |
| 61 | { |
| 62 | desc: "Item variable", |
| 63 | mkname: "pixel3.mk", |
| 64 | in: ` |
| 65 | PRODUCT_NAME := Pixel 3 |
| 66 | PRODUCT_MODEL := |
| 67 | local_var = foo |
| 68 | `, |
| 69 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 70 | |
| 71 | def init(g, handle): |
| 72 | cfg = rblf.cfg(handle) |
| 73 | cfg["PRODUCT_NAME"] = "Pixel 3" |
| 74 | cfg["PRODUCT_MODEL"] = "" |
| 75 | _local_var = "foo" |
| 76 | `, |
| 77 | }, |
| 78 | { |
| 79 | desc: "List variable", |
| 80 | mkname: "pixel4.mk", |
| 81 | in: ` |
| 82 | PRODUCT_PACKAGES = package1 package2 |
| 83 | PRODUCT_COPY_FILES += file2:target |
| 84 | PRODUCT_PACKAGES += package3 |
| 85 | PRODUCT_COPY_FILES = |
| 86 | `, |
| 87 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 88 | |
| 89 | def init(g, handle): |
| 90 | cfg = rblf.cfg(handle) |
| 91 | cfg["PRODUCT_PACKAGES"] = [ |
| 92 | "package1", |
| 93 | "package2", |
| 94 | ] |
| 95 | rblf.setdefault(handle, "PRODUCT_COPY_FILES") |
| 96 | cfg["PRODUCT_COPY_FILES"] += ["file2:target"] |
| 97 | cfg["PRODUCT_PACKAGES"] += ["package3"] |
| 98 | cfg["PRODUCT_COPY_FILES"] = [] |
| 99 | `, |
| 100 | }, |
| 101 | { |
| 102 | desc: "Unknown function", |
| 103 | mkname: "product.mk", |
| 104 | in: ` |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 105 | PRODUCT_NAME := $(call foo1, bar) |
| 106 | PRODUCT_NAME := $(call foo0) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 107 | `, |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 108 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 109 | |
| 110 | def init(g, handle): |
| 111 | cfg = rblf.cfg(handle) |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 112 | rblf.mk2rbc_error("product.mk:2", "cannot handle invoking foo1") |
| 113 | rblf.mk2rbc_error("product.mk:3", "cannot handle invoking foo0") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 114 | `, |
| 115 | }, |
| 116 | { |
| 117 | desc: "Inherit configuration always", |
| 118 | mkname: "product.mk", |
| 119 | in: ` |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 120 | $(call inherit-product, part.mk) |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 121 | ifdef PRODUCT_NAME |
| 122 | $(call inherit-product, part1.mk) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 123 | else # Comment |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 124 | $(call inherit-product, $(LOCAL_PATH)/part1.mk) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 125 | endif |
| 126 | `, |
| 127 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 128 | load(":part.star", _part_init = "init") |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 129 | load(":part1.star|init", _part1_init = "init") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 130 | |
| 131 | def init(g, handle): |
| 132 | cfg = rblf.cfg(handle) |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 133 | rblf.inherit(handle, "part", _part_init) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 134 | if g.get("PRODUCT_NAME") != None: |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 135 | rblf.inherit(handle, "part1", _part1_init) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 136 | else: |
| 137 | # Comment |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 138 | rblf.inherit(handle, "part1", _part1_init) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 139 | `, |
| 140 | }, |
| 141 | { |
| 142 | desc: "Inherit configuration if it exists", |
| 143 | mkname: "product.mk", |
| 144 | in: ` |
| 145 | $(call inherit-product-if-exists, part.mk) |
| 146 | `, |
| 147 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 148 | load(":part.star|init", _part_init = "init") |
| 149 | |
| 150 | def init(g, handle): |
| 151 | cfg = rblf.cfg(handle) |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 152 | if _part_init: |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 153 | rblf.inherit(handle, "part", _part_init) |
| 154 | `, |
| 155 | }, |
| 156 | |
| 157 | { |
| 158 | desc: "Include configuration", |
| 159 | mkname: "product.mk", |
| 160 | in: ` |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 161 | include part.mk |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 162 | ifdef PRODUCT_NAME |
| 163 | include part1.mk |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 164 | else |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 165 | -include $(LOCAL_PATH)/part1.mk) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 166 | endif |
| 167 | `, |
| 168 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 169 | load(":part.star", _part_init = "init") |
| 170 | load(":part1.star|init", _part1_init = "init") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 171 | |
| 172 | def init(g, handle): |
| 173 | cfg = rblf.cfg(handle) |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 174 | _part_init(g, handle) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 175 | if g.get("PRODUCT_NAME") != None: |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 176 | _part1_init(g, handle) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 177 | else: |
Sasha Smundak | 868c5e3 | 2021-09-23 16:20:58 -0700 | [diff] [blame] | 178 | if _part1_init != None: |
| 179 | _part1_init(g, handle) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 180 | `, |
| 181 | }, |
| 182 | |
| 183 | { |
| 184 | desc: "Synonymous inherited configurations", |
| 185 | mkname: "path/product.mk", |
| 186 | in: ` |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 187 | $(call inherit-product, */font.mk) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 188 | `, |
| 189 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 190 | load("//foo:font.star", _font_init = "init") |
| 191 | load("//bar:font.star", _font1_init = "init") |
| 192 | |
| 193 | def init(g, handle): |
| 194 | cfg = rblf.cfg(handle) |
| 195 | rblf.inherit(handle, "foo/font", _font_init) |
| 196 | rblf.inherit(handle, "bar/font", _font1_init) |
| 197 | `, |
| 198 | }, |
| 199 | { |
| 200 | desc: "Directive define", |
| 201 | mkname: "product.mk", |
| 202 | in: ` |
| 203 | define some-macro |
| 204 | $(info foo) |
| 205 | endef |
| 206 | `, |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 207 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 208 | |
| 209 | def init(g, handle): |
| 210 | cfg = rblf.cfg(handle) |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 211 | rblf.mk2rbc_error("product.mk:2", "define is not supported: some-macro") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 212 | `, |
| 213 | }, |
| 214 | { |
| 215 | desc: "Ifdef", |
| 216 | mkname: "product.mk", |
| 217 | in: ` |
| 218 | ifdef PRODUCT_NAME |
| 219 | PRODUCT_NAME = gizmo |
| 220 | else |
| 221 | endif |
Sasha Smundak | c4fa93e | 2021-11-05 14:38:46 -0700 | [diff] [blame] | 222 | local_var := |
| 223 | ifdef local_var |
| 224 | endif |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 225 | `, |
| 226 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 227 | |
| 228 | def init(g, handle): |
| 229 | cfg = rblf.cfg(handle) |
| 230 | if g.get("PRODUCT_NAME") != None: |
| 231 | cfg["PRODUCT_NAME"] = "gizmo" |
| 232 | else: |
| 233 | pass |
Sasha Smundak | c4fa93e | 2021-11-05 14:38:46 -0700 | [diff] [blame] | 234 | _local_var = "" |
| 235 | if _local_var: |
| 236 | pass |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 237 | `, |
| 238 | }, |
| 239 | { |
| 240 | desc: "Simple functions", |
| 241 | mkname: "product.mk", |
| 242 | in: ` |
| 243 | $(warning this is the warning) |
| 244 | $(warning) |
| 245 | $(info this is the info) |
| 246 | $(error this is the error) |
| 247 | PRODUCT_NAME:=$(shell echo *) |
| 248 | `, |
| 249 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 250 | |
| 251 | def init(g, handle): |
| 252 | cfg = rblf.cfg(handle) |
| 253 | rblf.mkwarning("product.mk", "this is the warning") |
| 254 | rblf.mkwarning("product.mk", "") |
| 255 | rblf.mkinfo("product.mk", "this is the info") |
| 256 | rblf.mkerror("product.mk", "this is the error") |
| 257 | cfg["PRODUCT_NAME"] = rblf.shell("echo *") |
| 258 | `, |
| 259 | }, |
| 260 | { |
| 261 | desc: "Empty if", |
| 262 | mkname: "product.mk", |
| 263 | in: ` |
| 264 | ifdef PRODUCT_NAME |
| 265 | # Comment |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 266 | else |
Sasha Smundak | 02183cf | 2021-08-16 13:36:11 -0700 | [diff] [blame] | 267 | TARGET_COPY_OUT_RECOVERY := foo |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 268 | endif |
| 269 | `, |
| 270 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 271 | |
| 272 | def init(g, handle): |
| 273 | cfg = rblf.cfg(handle) |
| 274 | if g.get("PRODUCT_NAME") != None: |
| 275 | # Comment |
| 276 | pass |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 277 | else: |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 278 | rblf.mk2rbc_error("product.mk:5", "cannot set predefined variable TARGET_COPY_OUT_RECOVERY to \"foo\", its value should be \"recovery\"") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 279 | `, |
| 280 | }, |
| 281 | { |
| 282 | desc: "if/else/endif", |
| 283 | mkname: "product.mk", |
| 284 | in: ` |
| 285 | ifndef PRODUCT_NAME |
| 286 | PRODUCT_NAME=gizmo1 |
| 287 | else |
| 288 | PRODUCT_NAME=gizmo2 |
| 289 | endif |
| 290 | `, |
| 291 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 292 | |
| 293 | def init(g, handle): |
| 294 | cfg = rblf.cfg(handle) |
| 295 | if not g.get("PRODUCT_NAME") != None: |
| 296 | cfg["PRODUCT_NAME"] = "gizmo1" |
| 297 | else: |
| 298 | cfg["PRODUCT_NAME"] = "gizmo2" |
| 299 | `, |
| 300 | }, |
| 301 | { |
| 302 | desc: "else if", |
| 303 | mkname: "product.mk", |
| 304 | in: ` |
| 305 | ifdef PRODUCT_NAME |
| 306 | PRODUCT_NAME = gizmo |
| 307 | else ifndef PRODUCT_PACKAGES # Comment |
| 308 | endif |
| 309 | `, |
| 310 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 311 | |
| 312 | def init(g, handle): |
| 313 | cfg = rblf.cfg(handle) |
| 314 | if g.get("PRODUCT_NAME") != None: |
| 315 | cfg["PRODUCT_NAME"] = "gizmo" |
| 316 | elif not g.get("PRODUCT_PACKAGES") != None: |
| 317 | # Comment |
| 318 | pass |
| 319 | `, |
| 320 | }, |
| 321 | { |
| 322 | desc: "ifeq / ifneq", |
| 323 | mkname: "product.mk", |
| 324 | in: ` |
| 325 | ifeq (aosp_arm, $(TARGET_PRODUCT)) |
| 326 | PRODUCT_MODEL = pix2 |
| 327 | else |
| 328 | PRODUCT_MODEL = pix21 |
| 329 | endif |
| 330 | ifneq (aosp_x86, $(TARGET_PRODUCT)) |
| 331 | PRODUCT_MODEL = pix3 |
| 332 | endif |
| 333 | `, |
| 334 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 335 | |
| 336 | def init(g, handle): |
| 337 | cfg = rblf.cfg(handle) |
| 338 | if "aosp_arm" == g["TARGET_PRODUCT"]: |
| 339 | cfg["PRODUCT_MODEL"] = "pix2" |
| 340 | else: |
| 341 | cfg["PRODUCT_MODEL"] = "pix21" |
| 342 | if "aosp_x86" != g["TARGET_PRODUCT"]: |
| 343 | cfg["PRODUCT_MODEL"] = "pix3" |
| 344 | `, |
| 345 | }, |
| 346 | { |
Cole Faust | f832021 | 2021-11-10 15:05:07 -0800 | [diff] [blame] | 347 | desc: "ifeq with soong_config_get", |
| 348 | mkname: "product.mk", |
| 349 | in: ` |
| 350 | ifeq (true,$(call soong_config_get,art_module,source_build)) |
| 351 | endif |
| 352 | `, |
| 353 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 354 | |
| 355 | def init(g, handle): |
| 356 | cfg = rblf.cfg(handle) |
| 357 | if "true" == rblf.soong_config_get(g, "art_module", "source_build"): |
| 358 | pass |
| 359 | `, |
| 360 | }, |
| 361 | { |
Cole Faust | f1f44d3 | 2021-11-16 14:52:12 -0800 | [diff] [blame] | 362 | desc: "ifeq with $(NATIVE_COVERAGE)", |
| 363 | mkname: "product.mk", |
| 364 | in: ` |
| 365 | ifeq ($(NATIVE_COVERAGE),true) |
| 366 | endif |
| 367 | `, |
| 368 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 369 | |
| 370 | def init(g, handle): |
| 371 | cfg = rblf.cfg(handle) |
| 372 | if g.get("NATIVE_COVERAGE", False): |
| 373 | pass |
| 374 | `, |
| 375 | }, |
| 376 | { |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 377 | desc: "Check filter result", |
| 378 | mkname: "product.mk", |
| 379 | in: ` |
| 380 | ifeq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) |
| 381 | endif |
| 382 | ifneq (,$(filter userdebug,$(TARGET_BUILD_VARIANT)) |
| 383 | endif |
| 384 | ifneq (,$(filter plaf,$(PLATFORM_LIST))) |
| 385 | endif |
| 386 | ifeq ($(TARGET_BUILD_VARIANT), $(filter $(TARGET_BUILD_VARIANT), userdebug eng)) |
| 387 | endif |
Sasha Smundak | 0554d76 | 2021-07-08 18:26:12 -0700 | [diff] [blame] | 388 | ifneq (,$(filter true, $(v1)$(v2))) |
| 389 | endif |
Sasha Smundak | 5f463be | 2021-09-15 18:43:36 -0700 | [diff] [blame] | 390 | ifeq (,$(filter barbet coral%,$(TARGET_PRODUCT))) |
| 391 | else ifneq (,$(filter barbet%,$(TARGET_PRODUCT))) |
| 392 | endif |
Cole Faust | eec0d81 | 2021-12-06 16:23:51 -0800 | [diff] [blame] | 393 | ifeq (,$(filter-out sunfish_kasan, $(TARGET_PRODUCT))) |
| 394 | endif |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 395 | `, |
| 396 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 397 | |
| 398 | def init(g, handle): |
| 399 | cfg = rblf.cfg(handle) |
Sasha Smundak | 5f463be | 2021-09-15 18:43:36 -0700 | [diff] [blame] | 400 | if not rblf.filter("userdebug eng", g["TARGET_BUILD_VARIANT"]): |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 401 | pass |
Sasha Smundak | 5f463be | 2021-09-15 18:43:36 -0700 | [diff] [blame] | 402 | if rblf.filter("userdebug", g["TARGET_BUILD_VARIANT"]): |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 403 | pass |
| 404 | if "plaf" in g.get("PLATFORM_LIST", []): |
| 405 | pass |
| 406 | if g["TARGET_BUILD_VARIANT"] in ["userdebug", "eng"]: |
| 407 | pass |
Sasha Smundak | 5f463be | 2021-09-15 18:43:36 -0700 | [diff] [blame] | 408 | if rblf.filter("true", "%s%s" % (_v1, _v2)): |
| 409 | pass |
| 410 | if not rblf.filter("barbet coral%", g["TARGET_PRODUCT"]): |
| 411 | pass |
| 412 | elif rblf.filter("barbet%", g["TARGET_PRODUCT"]): |
Sasha Smundak | 0554d76 | 2021-07-08 18:26:12 -0700 | [diff] [blame] | 413 | pass |
Cole Faust | eec0d81 | 2021-12-06 16:23:51 -0800 | [diff] [blame] | 414 | if not rblf.filter_out("sunfish_kasan", g["TARGET_PRODUCT"]): |
| 415 | pass |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 416 | `, |
| 417 | }, |
| 418 | { |
| 419 | desc: "Get filter result", |
| 420 | mkname: "product.mk", |
| 421 | in: ` |
| 422 | PRODUCT_LIST2=$(filter-out %/foo.ko,$(wildcard path/*.ko)) |
| 423 | `, |
| 424 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 425 | |
| 426 | def init(g, handle): |
| 427 | cfg = rblf.cfg(handle) |
| 428 | cfg["PRODUCT_LIST2"] = rblf.filter_out("%/foo.ko", rblf.expand_wildcard("path/*.ko")) |
| 429 | `, |
| 430 | }, |
| 431 | { |
| 432 | desc: "filter $(VAR), values", |
| 433 | mkname: "product.mk", |
| 434 | in: ` |
| 435 | ifeq (,$(filter $(TARGET_PRODUCT), yukawa_gms yukawa_sei510_gms) |
| 436 | ifneq (,$(filter $(TARGET_PRODUCT), yukawa_gms) |
| 437 | endif |
| 438 | endif |
| 439 | |
| 440 | `, |
| 441 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 442 | |
| 443 | def init(g, handle): |
| 444 | cfg = rblf.cfg(handle) |
| 445 | if g["TARGET_PRODUCT"] not in ["yukawa_gms", "yukawa_sei510_gms"]: |
Sasha Smundak | 0554d76 | 2021-07-08 18:26:12 -0700 | [diff] [blame] | 446 | if g["TARGET_PRODUCT"] == "yukawa_gms": |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 447 | pass |
| 448 | `, |
| 449 | }, |
| 450 | { |
Sasha Smundak | 0554d76 | 2021-07-08 18:26:12 -0700 | [diff] [blame] | 451 | desc: "filter $(V1), $(V2)", |
| 452 | mkname: "product.mk", |
| 453 | in: ` |
| 454 | ifneq (, $(filter $(PRODUCT_LIST), $(TARGET_PRODUCT))) |
| 455 | endif |
| 456 | `, |
| 457 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 458 | |
| 459 | def init(g, handle): |
| 460 | cfg = rblf.cfg(handle) |
Sasha Smundak | 468e11f | 2021-08-26 09:10:23 -0700 | [diff] [blame] | 461 | if rblf.filter(g.get("PRODUCT_LIST", []), g["TARGET_PRODUCT"]): |
Sasha Smundak | 0554d76 | 2021-07-08 18:26:12 -0700 | [diff] [blame] | 462 | pass |
| 463 | `, |
| 464 | }, |
| 465 | { |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 466 | desc: "ifeq", |
| 467 | mkname: "product.mk", |
| 468 | in: ` |
| 469 | ifeq (aosp, $(TARGET_PRODUCT)) # Comment |
| 470 | else ifneq (, $(TARGET_PRODUCT)) |
| 471 | endif |
| 472 | `, |
| 473 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 474 | |
| 475 | def init(g, handle): |
| 476 | cfg = rblf.cfg(handle) |
| 477 | if "aosp" == g["TARGET_PRODUCT"]: |
| 478 | # Comment |
| 479 | pass |
| 480 | elif g["TARGET_PRODUCT"]: |
| 481 | pass |
| 482 | `, |
| 483 | }, |
| 484 | { |
| 485 | desc: "Nested if", |
| 486 | mkname: "product.mk", |
| 487 | in: ` |
| 488 | ifdef PRODUCT_NAME |
| 489 | PRODUCT_PACKAGES = pack-if0 |
| 490 | ifdef PRODUCT_MODEL |
| 491 | PRODUCT_PACKAGES = pack-if-if |
| 492 | else ifdef PRODUCT_NAME |
| 493 | PRODUCT_PACKAGES = pack-if-elif |
| 494 | else |
| 495 | PRODUCT_PACKAGES = pack-if-else |
| 496 | endif |
| 497 | PRODUCT_PACKAGES = pack-if |
| 498 | else ifneq (,$(TARGET_PRODUCT)) |
| 499 | PRODUCT_PACKAGES = pack-elif |
| 500 | else |
| 501 | PRODUCT_PACKAGES = pack-else |
| 502 | endif |
| 503 | `, |
| 504 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 505 | |
| 506 | def init(g, handle): |
| 507 | cfg = rblf.cfg(handle) |
| 508 | if g.get("PRODUCT_NAME") != None: |
| 509 | cfg["PRODUCT_PACKAGES"] = ["pack-if0"] |
| 510 | if g.get("PRODUCT_MODEL") != None: |
| 511 | cfg["PRODUCT_PACKAGES"] = ["pack-if-if"] |
| 512 | elif g.get("PRODUCT_NAME") != None: |
| 513 | cfg["PRODUCT_PACKAGES"] = ["pack-if-elif"] |
| 514 | else: |
| 515 | cfg["PRODUCT_PACKAGES"] = ["pack-if-else"] |
| 516 | cfg["PRODUCT_PACKAGES"] = ["pack-if"] |
| 517 | elif g["TARGET_PRODUCT"]: |
| 518 | cfg["PRODUCT_PACKAGES"] = ["pack-elif"] |
| 519 | else: |
| 520 | cfg["PRODUCT_PACKAGES"] = ["pack-else"] |
| 521 | `, |
| 522 | }, |
| 523 | { |
| 524 | desc: "Wildcard", |
| 525 | mkname: "product.mk", |
| 526 | in: ` |
| 527 | ifeq (,$(wildcard foo.mk)) |
| 528 | endif |
| 529 | ifneq (,$(wildcard foo*.mk)) |
| 530 | endif |
| 531 | `, |
| 532 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 533 | |
| 534 | def init(g, handle): |
| 535 | cfg = rblf.cfg(handle) |
| 536 | if not rblf.file_exists("foo.mk"): |
| 537 | pass |
| 538 | if rblf.file_wildcard_exists("foo*.mk"): |
| 539 | pass |
| 540 | `, |
| 541 | }, |
| 542 | { |
Cole Faust | f832021 | 2021-11-10 15:05:07 -0800 | [diff] [blame] | 543 | desc: "if with interpolation", |
| 544 | mkname: "product.mk", |
| 545 | in: ` |
| 546 | ifeq ($(VARIABLE1)text$(VARIABLE2),true) |
| 547 | endif |
| 548 | `, |
| 549 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 550 | |
| 551 | def init(g, handle): |
| 552 | cfg = rblf.cfg(handle) |
| 553 | if "%stext%s" % (g.get("VARIABLE1", ""), g.get("VARIABLE2", "")) == "true": |
| 554 | pass |
| 555 | `, |
| 556 | }, |
| 557 | { |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 558 | desc: "ifneq $(X),true", |
| 559 | mkname: "product.mk", |
| 560 | in: ` |
| 561 | ifneq ($(VARIABLE),true) |
| 562 | endif |
| 563 | `, |
| 564 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 565 | |
| 566 | def init(g, handle): |
| 567 | cfg = rblf.cfg(handle) |
| 568 | if g.get("VARIABLE", "") != "true": |
| 569 | pass |
| 570 | `, |
| 571 | }, |
| 572 | { |
| 573 | desc: "Const neq", |
| 574 | mkname: "product.mk", |
| 575 | in: ` |
| 576 | ifneq (1,0) |
| 577 | endif |
| 578 | `, |
| 579 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 580 | |
| 581 | def init(g, handle): |
| 582 | cfg = rblf.cfg(handle) |
| 583 | if "1" != "0": |
| 584 | pass |
| 585 | `, |
| 586 | }, |
| 587 | { |
| 588 | desc: "is-board calls", |
| 589 | mkname: "product.mk", |
| 590 | in: ` |
| 591 | ifeq ($(call is-board-platform-in-list,msm8998), true) |
| 592 | else ifneq ($(call is-board-platform,copper),true) |
| 593 | else ifneq ($(call is-vendor-board-platform,QCOM),true) |
| 594 | else ifeq ($(call is-product-in-list, $(PLATFORM_LIST)), true) |
| 595 | endif |
| 596 | `, |
| 597 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 598 | |
| 599 | def init(g, handle): |
| 600 | cfg = rblf.cfg(handle) |
| 601 | if g.get("TARGET_BOARD_PLATFORM", "") in ["msm8998"]: |
| 602 | pass |
| 603 | elif g.get("TARGET_BOARD_PLATFORM", "") != "copper": |
| 604 | pass |
| 605 | elif g.get("TARGET_BOARD_PLATFORM", "") not in g["QCOM_BOARD_PLATFORMS"]: |
| 606 | pass |
| 607 | elif g["TARGET_PRODUCT"] in g.get("PLATFORM_LIST", []): |
| 608 | pass |
| 609 | `, |
| 610 | }, |
| 611 | { |
Sasha Smundak | 3a9b8e8 | 2021-08-25 14:11:04 -0700 | [diff] [blame] | 612 | desc: "new is-board calls", |
| 613 | mkname: "product.mk", |
| 614 | in: ` |
| 615 | ifneq (,$(call is-board-platform-in-list2,msm8998 $(X)) |
| 616 | else ifeq (,$(call is-board-platform2,copper) |
| 617 | else ifneq (,$(call is-vendor-board-qcom)) |
| 618 | endif |
| 619 | `, |
| 620 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 621 | |
| 622 | def init(g, handle): |
| 623 | cfg = rblf.cfg(handle) |
| 624 | if rblf.board_platform_in(g, "msm8998 %s" % g.get("X", "")): |
| 625 | pass |
| 626 | elif not rblf.board_platform_is(g, "copper"): |
| 627 | pass |
Sasha Smundak | 4f1f118 | 2021-11-04 17:57:39 -0700 | [diff] [blame] | 628 | elif g.get("TARGET_BOARD_PLATFORM", "") in g["QCOM_BOARD_PLATFORMS"]: |
Sasha Smundak | 3a9b8e8 | 2021-08-25 14:11:04 -0700 | [diff] [blame] | 629 | pass |
| 630 | `, |
| 631 | }, |
| 632 | { |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 633 | desc: "findstring call", |
| 634 | mkname: "product.mk", |
| 635 | in: ` |
| 636 | ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),) |
| 637 | endif |
| 638 | `, |
| 639 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 640 | |
| 641 | def init(g, handle): |
| 642 | cfg = rblf.cfg(handle) |
| 643 | if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1: |
| 644 | pass |
| 645 | `, |
| 646 | }, |
| 647 | { |
| 648 | desc: "rhs call", |
| 649 | mkname: "product.mk", |
| 650 | in: ` |
| 651 | PRODUCT_COPY_FILES = $(call add-to-product-copy-files-if-exists, path:distpath) \ |
| 652 | $(call find-copy-subdir-files, *, fromdir, todir) $(wildcard foo.*) |
| 653 | `, |
| 654 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 655 | |
| 656 | def init(g, handle): |
| 657 | cfg = rblf.cfg(handle) |
| 658 | cfg["PRODUCT_COPY_FILES"] = (rblf.copy_if_exists("path:distpath") + |
| 659 | rblf.find_and_copy("*", "fromdir", "todir") + |
| 660 | rblf.expand_wildcard("foo.*")) |
| 661 | `, |
| 662 | }, |
| 663 | { |
| 664 | desc: "inferred type", |
| 665 | mkname: "product.mk", |
| 666 | in: ` |
| 667 | HIKEY_MODS := $(wildcard foo/*.ko) |
| 668 | BOARD_VENDOR_KERNEL_MODULES += $(HIKEY_MODS) |
| 669 | `, |
| 670 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 671 | |
| 672 | def init(g, handle): |
| 673 | cfg = rblf.cfg(handle) |
| 674 | g["HIKEY_MODS"] = rblf.expand_wildcard("foo/*.ko") |
| 675 | g.setdefault("BOARD_VENDOR_KERNEL_MODULES", []) |
| 676 | g["BOARD_VENDOR_KERNEL_MODULES"] += g["HIKEY_MODS"] |
| 677 | `, |
| 678 | }, |
| 679 | { |
| 680 | desc: "list with vars", |
| 681 | mkname: "product.mk", |
| 682 | in: ` |
| 683 | PRODUCT_COPY_FILES += path1:$(TARGET_PRODUCT)/path1 $(PRODUCT_MODEL)/path2:$(TARGET_PRODUCT)/path2 |
| 684 | `, |
| 685 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 686 | |
| 687 | def init(g, handle): |
| 688 | cfg = rblf.cfg(handle) |
| 689 | rblf.setdefault(handle, "PRODUCT_COPY_FILES") |
| 690 | cfg["PRODUCT_COPY_FILES"] += (("path1:%s/path1" % g["TARGET_PRODUCT"]).split() + |
| 691 | ("%s/path2:%s/path2" % (cfg.get("PRODUCT_MODEL", ""), g["TARGET_PRODUCT"])).split()) |
| 692 | `, |
| 693 | }, |
| 694 | { |
| 695 | desc: "misc calls", |
| 696 | mkname: "product.mk", |
| 697 | in: ` |
| 698 | $(call enforce-product-packages-exist,) |
| 699 | $(call enforce-product-packages-exist, foo) |
| 700 | $(call require-artifacts-in-path, foo, bar) |
| 701 | $(call require-artifacts-in-path-relaxed, foo, bar) |
Sasha Smundak | d679785 | 2021-11-15 13:01:53 -0800 | [diff] [blame] | 702 | $(call dist-for-goals, goal, from:to) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 703 | `, |
| 704 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 705 | |
| 706 | def init(g, handle): |
| 707 | cfg = rblf.cfg(handle) |
| 708 | rblf.enforce_product_packages_exist("") |
| 709 | rblf.enforce_product_packages_exist("foo") |
| 710 | rblf.require_artifacts_in_path("foo", "bar") |
| 711 | rblf.require_artifacts_in_path_relaxed("foo", "bar") |
Sasha Smundak | d679785 | 2021-11-15 13:01:53 -0800 | [diff] [blame] | 712 | rblf.mkdist_for_goals(g, "goal", "from:to") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 713 | `, |
| 714 | }, |
| 715 | { |
| 716 | desc: "list with functions", |
| 717 | mkname: "product.mk", |
| 718 | in: ` |
| 719 | PRODUCT_COPY_FILES := $(call find-copy-subdir-files,*.kl,from1,to1) \ |
| 720 | $(call find-copy-subdir-files,*.kc,from2,to2) \ |
| 721 | foo bar |
| 722 | `, |
| 723 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 724 | |
| 725 | def init(g, handle): |
| 726 | cfg = rblf.cfg(handle) |
| 727 | cfg["PRODUCT_COPY_FILES"] = (rblf.find_and_copy("*.kl", "from1", "to1") + |
| 728 | rblf.find_and_copy("*.kc", "from2", "to2") + |
| 729 | [ |
| 730 | "foo", |
| 731 | "bar", |
| 732 | ]) |
| 733 | `, |
| 734 | }, |
| 735 | { |
| 736 | desc: "Text functions", |
| 737 | mkname: "product.mk", |
| 738 | in: ` |
| 739 | PRODUCT_COPY_FILES := $(addprefix pfx-,a b c) |
| 740 | PRODUCT_COPY_FILES := $(addsuffix .sff, a b c) |
| 741 | PRODUCT_NAME := $(word 1, $(subst ., ,$(TARGET_BOARD_PLATFORM))) |
Sasha Smundak | 35434ed | 2021-11-05 16:29:56 -0700 | [diff] [blame] | 742 | $(info $(patsubst %.pub,$(PRODUCT_NAME)%,$(PRODUCT_ADB_KEYS))) |
Sasha Smundak | 16e0773 | 2021-07-23 11:38:23 -0700 | [diff] [blame] | 743 | $(info $(dir foo/bar)) |
| 744 | $(info $(firstword $(PRODUCT_COPY_FILES))) |
| 745 | $(info $(lastword $(PRODUCT_COPY_FILES))) |
| 746 | $(info $(dir $(lastword $(MAKEFILE_LIST)))) |
| 747 | $(info $(dir $(lastword $(PRODUCT_COPY_FILES)))) |
| 748 | $(info $(dir $(lastword $(foobar)))) |
| 749 | $(info $(abspath foo/bar)) |
| 750 | $(info $(notdir foo/bar)) |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 751 | $(call add_soong_config_namespace,snsconfig) |
| 752 | $(call add_soong_config_var_value,snsconfig,imagetype,odm_image) |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 753 | $(call soong_config_set, snsconfig, foo, foo_value) |
| 754 | $(call soong_config_append, snsconfig, bar, bar_value) |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 755 | PRODUCT_COPY_FILES := $(call copy-files,$(wildcard foo*.mk),etc) |
Sasha Smundak | 0445308 | 2021-08-17 18:14:41 -0700 | [diff] [blame] | 756 | PRODUCT_COPY_FILES := $(call product-copy-files-by-pattern,from/%,to/%,a b c) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 757 | `, |
| 758 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 759 | |
| 760 | def init(g, handle): |
| 761 | cfg = rblf.cfg(handle) |
| 762 | cfg["PRODUCT_COPY_FILES"] = rblf.addprefix("pfx-", "a b c") |
| 763 | cfg["PRODUCT_COPY_FILES"] = rblf.addsuffix(".sff", "a b c") |
| 764 | cfg["PRODUCT_NAME"] = ((g.get("TARGET_BOARD_PLATFORM", "")).replace(".", " ")).split()[0] |
Sasha Smundak | 35434ed | 2021-11-05 16:29:56 -0700 | [diff] [blame] | 765 | rblf.mkinfo("product.mk", rblf.mkpatsubst("%.pub", "%s%%" % cfg["PRODUCT_NAME"], g.get("PRODUCT_ADB_KEYS", ""))) |
Sasha Smundak | 16e0773 | 2021-07-23 11:38:23 -0700 | [diff] [blame] | 766 | rblf.mkinfo("product.mk", rblf.dir("foo/bar")) |
| 767 | rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][0]) |
| 768 | rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][-1]) |
| 769 | rblf.mkinfo("product.mk", rblf.dir("product.mk")) |
| 770 | rblf.mkinfo("product.mk", rblf.dir(cfg["PRODUCT_COPY_FILES"][-1])) |
| 771 | rblf.mkinfo("product.mk", rblf.dir((_foobar).split()[-1])) |
| 772 | rblf.mkinfo("product.mk", rblf.abspath("foo/bar")) |
| 773 | rblf.mkinfo("product.mk", rblf.notdir("foo/bar")) |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 774 | rblf.soong_config_namespace(g, "snsconfig") |
| 775 | rblf.soong_config_set(g, "snsconfig", "imagetype", "odm_image") |
| 776 | rblf.soong_config_set(g, "snsconfig", "foo", "foo_value") |
| 777 | rblf.soong_config_append(g, "snsconfig", "bar", "bar_value") |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 778 | cfg["PRODUCT_COPY_FILES"] = rblf.copy_files(rblf.expand_wildcard("foo*.mk"), "etc") |
Sasha Smundak | 0445308 | 2021-08-17 18:14:41 -0700 | [diff] [blame] | 779 | cfg["PRODUCT_COPY_FILES"] = rblf.product_copy_files_by_pattern("from/%", "to/%", "a b c") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 780 | `, |
| 781 | }, |
| 782 | { |
Sasha Smundak | 9d011ab | 2021-07-09 16:00:57 -0700 | [diff] [blame] | 783 | desc: "subst in list", |
| 784 | mkname: "product.mk", |
| 785 | in: ` |
| 786 | files = $(call find-copy-subdir-files,*,from,to) |
| 787 | PRODUCT_COPY_FILES += $(subst foo,bar,$(files)) |
| 788 | `, |
| 789 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 790 | |
| 791 | def init(g, handle): |
| 792 | cfg = rblf.cfg(handle) |
| 793 | _files = rblf.find_and_copy("*", "from", "to") |
| 794 | rblf.setdefault(handle, "PRODUCT_COPY_FILES") |
| 795 | cfg["PRODUCT_COPY_FILES"] += rblf.mksubst("foo", "bar", _files) |
| 796 | `, |
| 797 | }, |
| 798 | { |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 799 | desc: "assignment flavors", |
| 800 | mkname: "product.mk", |
| 801 | in: ` |
| 802 | PRODUCT_LIST1 := a |
| 803 | PRODUCT_LIST2 += a |
| 804 | PRODUCT_LIST1 += b |
| 805 | PRODUCT_LIST2 += b |
| 806 | PRODUCT_LIST3 ?= a |
| 807 | PRODUCT_LIST1 = c |
| 808 | PLATFORM_LIST += x |
| 809 | PRODUCT_PACKAGES := $(PLATFORM_LIST) |
| 810 | `, |
| 811 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 812 | |
| 813 | def init(g, handle): |
| 814 | cfg = rblf.cfg(handle) |
| 815 | cfg["PRODUCT_LIST1"] = ["a"] |
| 816 | rblf.setdefault(handle, "PRODUCT_LIST2") |
| 817 | cfg["PRODUCT_LIST2"] += ["a"] |
| 818 | cfg["PRODUCT_LIST1"] += ["b"] |
| 819 | cfg["PRODUCT_LIST2"] += ["b"] |
| 820 | if cfg.get("PRODUCT_LIST3") == None: |
| 821 | cfg["PRODUCT_LIST3"] = ["a"] |
| 822 | cfg["PRODUCT_LIST1"] = ["c"] |
| 823 | g.setdefault("PLATFORM_LIST", []) |
| 824 | g["PLATFORM_LIST"] += ["x"] |
| 825 | cfg["PRODUCT_PACKAGES"] = g["PLATFORM_LIST"][:] |
| 826 | `, |
| 827 | }, |
| 828 | { |
| 829 | desc: "assigment flavors2", |
| 830 | mkname: "product.mk", |
| 831 | in: ` |
| 832 | PRODUCT_LIST1 = a |
| 833 | ifeq (0,1) |
| 834 | PRODUCT_LIST1 += b |
| 835 | PRODUCT_LIST2 += b |
| 836 | endif |
| 837 | PRODUCT_LIST1 += c |
| 838 | PRODUCT_LIST2 += c |
| 839 | `, |
| 840 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 841 | |
| 842 | def init(g, handle): |
| 843 | cfg = rblf.cfg(handle) |
| 844 | cfg["PRODUCT_LIST1"] = ["a"] |
| 845 | if "0" == "1": |
| 846 | cfg["PRODUCT_LIST1"] += ["b"] |
| 847 | rblf.setdefault(handle, "PRODUCT_LIST2") |
| 848 | cfg["PRODUCT_LIST2"] += ["b"] |
| 849 | cfg["PRODUCT_LIST1"] += ["c"] |
| 850 | rblf.setdefault(handle, "PRODUCT_LIST2") |
| 851 | cfg["PRODUCT_LIST2"] += ["c"] |
| 852 | `, |
| 853 | }, |
| 854 | { |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 855 | desc: "soong namespace assignments", |
| 856 | mkname: "product.mk", |
| 857 | in: ` |
| 858 | SOONG_CONFIG_NAMESPACES += cvd |
| 859 | SOONG_CONFIG_cvd += launch_configs |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 860 | SOONG_CONFIG_cvd_launch_configs = cvd_config_auto.json |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 861 | SOONG_CONFIG_cvd += grub_config |
| 862 | SOONG_CONFIG_cvd_grub_config += grub.cfg |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 863 | x := $(SOONG_CONFIG_cvd_grub_config) |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 864 | `, |
| 865 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 866 | |
| 867 | def init(g, handle): |
| 868 | cfg = rblf.cfg(handle) |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 869 | rblf.soong_config_namespace(g, "cvd") |
| 870 | rblf.soong_config_set(g, "cvd", "launch_configs", "cvd_config_auto.json") |
| 871 | rblf.soong_config_append(g, "cvd", "grub_config", "grub.cfg") |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 872 | rblf.mk2rbc_error("product.mk:7", "SOONG_CONFIG_ variables cannot be referenced, use soong_config_get instead: SOONG_CONFIG_cvd_grub_config") |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 873 | `, |
Cole Faust | c00184e | 2021-11-08 12:08:57 -0800 | [diff] [blame] | 874 | }, { |
| 875 | desc: "soong namespace accesses", |
| 876 | mkname: "product.mk", |
| 877 | in: ` |
| 878 | SOONG_CONFIG_NAMESPACES += cvd |
| 879 | SOONG_CONFIG_cvd += launch_configs |
| 880 | SOONG_CONFIG_cvd_launch_configs = cvd_config_auto.json |
| 881 | SOONG_CONFIG_cvd += grub_config |
| 882 | SOONG_CONFIG_cvd_grub_config += grub.cfg |
| 883 | x := $(call soong_config_get,cvd,grub_config) |
| 884 | `, |
| 885 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 886 | |
| 887 | def init(g, handle): |
| 888 | cfg = rblf.cfg(handle) |
| 889 | rblf.soong_config_namespace(g, "cvd") |
| 890 | rblf.soong_config_set(g, "cvd", "launch_configs", "cvd_config_auto.json") |
| 891 | rblf.soong_config_append(g, "cvd", "grub_config", "grub.cfg") |
| 892 | _x = rblf.soong_config_get(g, "cvd", "grub_config") |
| 893 | `, |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 894 | }, |
| 895 | { |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 896 | desc: "string split", |
| 897 | mkname: "product.mk", |
| 898 | in: ` |
| 899 | PRODUCT_LIST1 = a |
| 900 | local = b |
| 901 | local += c |
| 902 | FOO = d |
| 903 | FOO += e |
| 904 | PRODUCT_LIST1 += $(local) |
| 905 | PRODUCT_LIST1 += $(FOO) |
| 906 | `, |
| 907 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 908 | |
| 909 | def init(g, handle): |
| 910 | cfg = rblf.cfg(handle) |
| 911 | cfg["PRODUCT_LIST1"] = ["a"] |
| 912 | _local = "b" |
| 913 | _local += " " + "c" |
| 914 | g["FOO"] = "d" |
| 915 | g["FOO"] += " " + "e" |
| 916 | cfg["PRODUCT_LIST1"] += (_local).split() |
| 917 | cfg["PRODUCT_LIST1"] += (g["FOO"]).split() |
| 918 | `, |
| 919 | }, |
| 920 | { |
| 921 | desc: "apex_jars", |
| 922 | mkname: "product.mk", |
| 923 | in: ` |
| 924 | PRODUCT_BOOT_JARS := $(ART_APEX_JARS) framework-minus-apex |
| 925 | `, |
| 926 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 927 | |
| 928 | def init(g, handle): |
| 929 | cfg = rblf.cfg(handle) |
| 930 | cfg["PRODUCT_BOOT_JARS"] = (g.get("ART_APEX_JARS", []) + |
| 931 | ["framework-minus-apex"]) |
| 932 | `, |
| 933 | }, |
| 934 | { |
| 935 | desc: "strip function", |
| 936 | mkname: "product.mk", |
| 937 | in: ` |
| 938 | ifeq ($(filter hwaddress,$(PRODUCT_PACKAGES)),) |
| 939 | PRODUCT_PACKAGES := $(strip $(PRODUCT_PACKAGES) hwaddress) |
| 940 | endif |
| 941 | `, |
| 942 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 943 | |
| 944 | def init(g, handle): |
| 945 | cfg = rblf.cfg(handle) |
| 946 | if "hwaddress" not in cfg.get("PRODUCT_PACKAGES", []): |
| 947 | cfg["PRODUCT_PACKAGES"] = (rblf.mkstrip("%s hwaddress" % " ".join(cfg.get("PRODUCT_PACKAGES", [])))).split() |
| 948 | `, |
| 949 | }, |
| 950 | { |
| 951 | desc: "strip func in condition", |
| 952 | mkname: "product.mk", |
| 953 | in: ` |
| 954 | ifneq ($(strip $(TARGET_VENDOR)),) |
| 955 | endif |
| 956 | `, |
| 957 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 958 | |
| 959 | def init(g, handle): |
| 960 | cfg = rblf.cfg(handle) |
Sasha Smundak | 0554d76 | 2021-07-08 18:26:12 -0700 | [diff] [blame] | 961 | if rblf.mkstrip(g.get("TARGET_VENDOR", "")): |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 962 | pass |
| 963 | `, |
| 964 | }, |
| 965 | { |
| 966 | desc: "ref after set", |
| 967 | mkname: "product.mk", |
| 968 | in: ` |
| 969 | PRODUCT_ADB_KEYS:=value |
| 970 | FOO := $(PRODUCT_ADB_KEYS) |
| 971 | ifneq (,$(PRODUCT_ADB_KEYS)) |
| 972 | endif |
| 973 | `, |
| 974 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 975 | |
| 976 | def init(g, handle): |
| 977 | cfg = rblf.cfg(handle) |
| 978 | g["PRODUCT_ADB_KEYS"] = "value" |
| 979 | g["FOO"] = g["PRODUCT_ADB_KEYS"] |
| 980 | if g["PRODUCT_ADB_KEYS"]: |
| 981 | pass |
| 982 | `, |
| 983 | }, |
| 984 | { |
| 985 | desc: "ref before set", |
| 986 | mkname: "product.mk", |
| 987 | in: ` |
| 988 | V1 := $(PRODUCT_ADB_KEYS) |
| 989 | ifeq (,$(PRODUCT_ADB_KEYS)) |
| 990 | V2 := $(PRODUCT_ADB_KEYS) |
| 991 | PRODUCT_ADB_KEYS:=foo |
| 992 | V3 := $(PRODUCT_ADB_KEYS) |
| 993 | endif`, |
| 994 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 995 | |
| 996 | def init(g, handle): |
| 997 | cfg = rblf.cfg(handle) |
| 998 | g["V1"] = g.get("PRODUCT_ADB_KEYS", "") |
| 999 | if not g.get("PRODUCT_ADB_KEYS", ""): |
| 1000 | g["V2"] = g.get("PRODUCT_ADB_KEYS", "") |
| 1001 | g["PRODUCT_ADB_KEYS"] = "foo" |
| 1002 | g["V3"] = g["PRODUCT_ADB_KEYS"] |
| 1003 | `, |
| 1004 | }, |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1005 | { |
| 1006 | desc: "Dynamic inherit path", |
| 1007 | mkname: "product.mk", |
| 1008 | in: ` |
Sasha Smundak | 6d852dd | 2021-09-27 20:34:39 -0700 | [diff] [blame] | 1009 | MY_PATH:=foo |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1010 | $(call inherit-product,vendor/$(MY_PATH)/cfg.mk) |
| 1011 | `, |
| 1012 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1013 | load("//vendor/foo1:cfg.star|init", _cfg_init = "init") |
| 1014 | load("//vendor/bar/baz:cfg.star|init", _cfg1_init = "init") |
| 1015 | |
| 1016 | def init(g, handle): |
| 1017 | cfg = rblf.cfg(handle) |
| 1018 | g["MY_PATH"] = "foo" |
| 1019 | _entry = { |
| 1020 | "vendor/foo1/cfg.mk": ("_cfg", _cfg_init), |
| 1021 | "vendor/bar/baz/cfg.mk": ("_cfg1", _cfg1_init), |
| 1022 | }.get("vendor/%s/cfg.mk" % g["MY_PATH"]) |
| 1023 | (_varmod, _varmod_init) = _entry if _entry else (None, None) |
| 1024 | if not _varmod_init: |
| 1025 | rblf.mkerror("cannot") |
| 1026 | rblf.inherit(handle, _varmod, _varmod_init) |
| 1027 | `, |
| 1028 | }, |
Sasha Smundak | 6d852dd | 2021-09-27 20:34:39 -0700 | [diff] [blame] | 1029 | { |
| 1030 | desc: "Dynamic inherit with hint", |
| 1031 | mkname: "product.mk", |
| 1032 | in: ` |
| 1033 | MY_PATH:=foo |
| 1034 | #RBC# include_top vendor/foo1 |
| 1035 | $(call inherit-product,$(MY_PATH)/cfg.mk) |
| 1036 | `, |
| 1037 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1038 | load("//vendor/foo1:cfg.star|init", _cfg_init = "init") |
| 1039 | |
| 1040 | def init(g, handle): |
| 1041 | cfg = rblf.cfg(handle) |
| 1042 | g["MY_PATH"] = "foo" |
| 1043 | #RBC# include_top vendor/foo1 |
| 1044 | _entry = { |
| 1045 | "vendor/foo1/cfg.mk": ("_cfg", _cfg_init), |
| 1046 | }.get("%s/cfg.mk" % g["MY_PATH"]) |
| 1047 | (_varmod, _varmod_init) = _entry if _entry else (None, None) |
| 1048 | if not _varmod_init: |
| 1049 | rblf.mkerror("cannot") |
| 1050 | rblf.inherit(handle, _varmod, _varmod_init) |
| 1051 | `, |
| 1052 | }, |
Sasha Smundak | 2afb9d7 | 2021-10-24 15:16:59 -0700 | [diff] [blame] | 1053 | { |
| 1054 | desc: "Ignore make rules", |
| 1055 | mkname: "product.mk", |
| 1056 | in: ` |
| 1057 | foo: foo.c |
| 1058 | gcc -o $@ $*`, |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1059 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
Sasha Smundak | 2afb9d7 | 2021-10-24 15:16:59 -0700 | [diff] [blame] | 1060 | |
| 1061 | def init(g, handle): |
| 1062 | cfg = rblf.cfg(handle) |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1063 | rblf.mk2rbc_error("product.mk:2", "unsupported line rule: foo: foo.c\n#gcc -o $@ $*") |
Sasha Smundak | 2afb9d7 | 2021-10-24 15:16:59 -0700 | [diff] [blame] | 1064 | `, |
| 1065 | }, |
Sasha Smundak | ea3bc3a | 2021-11-10 13:06:42 -0800 | [diff] [blame] | 1066 | { |
| 1067 | desc: "Flag override", |
| 1068 | mkname: "product.mk", |
| 1069 | in: ` |
| 1070 | override FOO:=`, |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1071 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
Sasha Smundak | ea3bc3a | 2021-11-10 13:06:42 -0800 | [diff] [blame] | 1072 | |
| 1073 | def init(g, handle): |
| 1074 | cfg = rblf.cfg(handle) |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1075 | rblf.mk2rbc_error("product.mk:2", "cannot handle override directive") |
Sasha Smundak | ea3bc3a | 2021-11-10 13:06:42 -0800 | [diff] [blame] | 1076 | g["override FOO"] = "" |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1077 | `, |
| 1078 | }, |
| 1079 | { |
| 1080 | desc: "Bad expression", |
| 1081 | mkname: "build/product.mk", |
| 1082 | in: ` |
| 1083 | ifeq (,$(call foobar)) |
| 1084 | endif |
| 1085 | `, |
| 1086 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1087 | |
| 1088 | def init(g, handle): |
| 1089 | cfg = rblf.cfg(handle) |
| 1090 | if rblf.mk2rbc_error("build/product.mk:2", "cannot handle invoking foobar"): |
| 1091 | pass |
Sasha Smundak | ea3bc3a | 2021-11-10 13:06:42 -0800 | [diff] [blame] | 1092 | `, |
| 1093 | }, |
Cole Faust | 4eadba7 | 2021-12-07 11:54:52 -0800 | [diff] [blame] | 1094 | { |
| 1095 | desc: "if expression", |
| 1096 | mkname: "product.mk", |
| 1097 | in: ` |
| 1098 | TEST_VAR := foo |
| 1099 | TEST_VAR_LIST := foo |
| 1100 | TEST_VAR_LIST += bar |
| 1101 | TEST_VAR_2 := $(if $(TEST_VAR),bar) |
| 1102 | TEST_VAR_3 := $(if $(TEST_VAR),bar,baz) |
| 1103 | TEST_VAR_3 := $(if $(TEST_VAR),$(TEST_VAR_LIST)) |
| 1104 | `, |
| 1105 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1106 | |
| 1107 | def init(g, handle): |
| 1108 | cfg = rblf.cfg(handle) |
| 1109 | g["TEST_VAR"] = "foo" |
| 1110 | g["TEST_VAR_LIST"] = ["foo"] |
| 1111 | g["TEST_VAR_LIST"] += ["bar"] |
| 1112 | g["TEST_VAR_2"] = ("bar" if g["TEST_VAR"] else "") |
| 1113 | g["TEST_VAR_3"] = ("bar" if g["TEST_VAR"] else "baz") |
| 1114 | g["TEST_VAR_3"] = (g["TEST_VAR_LIST"] if g["TEST_VAR"] else []) |
| 1115 | `, |
| 1116 | }, |
Cole Faust | c36c962 | 2021-12-07 15:20:45 -0800 | [diff] [blame] | 1117 | { |
| 1118 | desc: "substitution references", |
| 1119 | mkname: "product.mk", |
| 1120 | in: ` |
| 1121 | SOURCES := foo.c bar.c |
| 1122 | OBJECTS := $(SOURCES:.c=.o) |
| 1123 | OBJECTS2 := $(SOURCES:%.c=%.o) |
| 1124 | `, |
| 1125 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1126 | |
| 1127 | def init(g, handle): |
| 1128 | cfg = rblf.cfg(handle) |
| 1129 | g["SOURCES"] = "foo.c bar.c" |
| 1130 | g["OBJECTS"] = rblf.mkpatsubst("%.c", "%.o", g["SOURCES"]) |
| 1131 | g["OBJECTS2"] = rblf.mkpatsubst("%.c", "%.o", g["SOURCES"]) |
| 1132 | `, |
| 1133 | }, |
Cole Faust | b0d32ab | 2021-12-09 14:00:59 -0800 | [diff] [blame^] | 1134 | { |
| 1135 | desc: "foreach expressions", |
| 1136 | mkname: "product.mk", |
| 1137 | in: ` |
| 1138 | BOOT_KERNEL_MODULES := foo.ko bar.ko |
| 1139 | BOOT_KERNEL_MODULES_FILTER := $(foreach m,$(BOOT_KERNEL_MODULES),%/$(m)) |
| 1140 | BOOT_KERNEL_MODULES_LIST := foo.ko |
| 1141 | BOOT_KERNEL_MODULES_LIST += bar.ko |
| 1142 | BOOT_KERNEL_MODULES_FILTER_2 := $(foreach m,$(BOOT_KERNEL_MODULES_LIST),%/$(m)) |
| 1143 | |
| 1144 | `, |
| 1145 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1146 | |
| 1147 | def init(g, handle): |
| 1148 | cfg = rblf.cfg(handle) |
| 1149 | g["BOOT_KERNEL_MODULES"] = "foo.ko bar.ko" |
| 1150 | g["BOOT_KERNEL_MODULES_FILTER"] = ["%%/%s" % m for m in rblf.words(g["BOOT_KERNEL_MODULES"])] |
| 1151 | g["BOOT_KERNEL_MODULES_LIST"] = ["foo.ko"] |
| 1152 | g["BOOT_KERNEL_MODULES_LIST"] += ["bar.ko"] |
| 1153 | g["BOOT_KERNEL_MODULES_FILTER_2"] = ["%%/%s" % m for m in g["BOOT_KERNEL_MODULES_LIST"]] |
| 1154 | `, |
| 1155 | }, |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | var known_variables = []struct { |
| 1159 | name string |
| 1160 | class varClass |
| 1161 | starlarkType |
| 1162 | }{ |
Cole Faust | f1f44d3 | 2021-11-16 14:52:12 -0800 | [diff] [blame] | 1163 | {"NATIVE_COVERAGE", VarClassSoong, starlarkTypeBool}, |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1164 | {"PRODUCT_NAME", VarClassConfig, starlarkTypeString}, |
| 1165 | {"PRODUCT_MODEL", VarClassConfig, starlarkTypeString}, |
| 1166 | {"PRODUCT_PACKAGES", VarClassConfig, starlarkTypeList}, |
| 1167 | {"PRODUCT_BOOT_JARS", VarClassConfig, starlarkTypeList}, |
| 1168 | {"PRODUCT_COPY_FILES", VarClassConfig, starlarkTypeList}, |
| 1169 | {"PRODUCT_IS_64BIT", VarClassConfig, starlarkTypeString}, |
| 1170 | {"PRODUCT_LIST1", VarClassConfig, starlarkTypeList}, |
| 1171 | {"PRODUCT_LIST2", VarClassConfig, starlarkTypeList}, |
| 1172 | {"PRODUCT_LIST3", VarClassConfig, starlarkTypeList}, |
| 1173 | {"TARGET_PRODUCT", VarClassSoong, starlarkTypeString}, |
| 1174 | {"TARGET_BUILD_VARIANT", VarClassSoong, starlarkTypeString}, |
| 1175 | {"TARGET_BOARD_PLATFORM", VarClassSoong, starlarkTypeString}, |
| 1176 | {"QCOM_BOARD_PLATFORMS", VarClassSoong, starlarkTypeString}, |
| 1177 | {"PLATFORM_LIST", VarClassSoong, starlarkTypeList}, // TODO(asmundak): make it local instead of soong |
| 1178 | } |
| 1179 | |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1180 | type testMakefileFinder struct { |
| 1181 | fs fs.FS |
| 1182 | root string |
| 1183 | files []string |
| 1184 | } |
| 1185 | |
| 1186 | func (t *testMakefileFinder) Find(root string) []string { |
| 1187 | if t.files != nil || root == t.root { |
| 1188 | return t.files |
| 1189 | } |
| 1190 | t.files = make([]string, 0) |
| 1191 | fs.WalkDir(t.fs, root, func(path string, d fs.DirEntry, err error) error { |
| 1192 | if err != nil { |
| 1193 | return err |
| 1194 | } |
| 1195 | if d.IsDir() { |
| 1196 | base := filepath.Base(path) |
| 1197 | if base[0] == '.' && len(base) > 1 { |
| 1198 | return fs.SkipDir |
| 1199 | } |
| 1200 | return nil |
| 1201 | } |
| 1202 | if strings.HasSuffix(path, ".mk") { |
| 1203 | t.files = append(t.files, path) |
| 1204 | } |
| 1205 | return nil |
| 1206 | }) |
| 1207 | return t.files |
| 1208 | } |
| 1209 | |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1210 | func TestGood(t *testing.T) { |
| 1211 | for _, v := range known_variables { |
| 1212 | KnownVariables.NewVariable(v.name, v.class, v.starlarkType) |
| 1213 | } |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1214 | fs := NewFindMockFS([]string{ |
| 1215 | "vendor/foo1/cfg.mk", |
| 1216 | "vendor/bar/baz/cfg.mk", |
| 1217 | "part.mk", |
| 1218 | "foo/font.mk", |
| 1219 | "bar/font.mk", |
| 1220 | }) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1221 | for _, test := range testCases { |
| 1222 | t.Run(test.desc, |
| 1223 | func(t *testing.T) { |
| 1224 | ss, err := Convert(Request{ |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1225 | MkFile: test.mkname, |
| 1226 | Reader: bytes.NewBufferString(test.in), |
| 1227 | RootDir: ".", |
| 1228 | OutputSuffix: ".star", |
| 1229 | SourceFS: fs, |
| 1230 | MakefileFinder: &testMakefileFinder{fs: fs}, |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1231 | }) |
| 1232 | if err != nil { |
| 1233 | t.Error(err) |
| 1234 | return |
| 1235 | } |
| 1236 | got := ss.String() |
| 1237 | if got != test.expected { |
| 1238 | t.Errorf("%q failed\nExpected:\n%s\nActual:\n%s\n", test.desc, |
| 1239 | strings.ReplaceAll(test.expected, "\n", "\n"), |
| 1240 | strings.ReplaceAll(got, "\n", "\n")) |
| 1241 | } |
| 1242 | }) |
| 1243 | } |
| 1244 | } |