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: ` |
Cole Faust | 0e9418c | 2021-12-13 16:33:25 -0800 | [diff] [blame] | 636 | result := $(findstring a,a b c) |
| 637 | result := $(findstring b,x y z) |
| 638 | `, |
| 639 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 640 | |
| 641 | def init(g, handle): |
| 642 | cfg = rblf.cfg(handle) |
| 643 | _result = rblf.findstring("a", "a b c") |
| 644 | _result = rblf.findstring("b", "x y z") |
| 645 | `, |
| 646 | }, |
| 647 | { |
| 648 | desc: "findstring in if statement", |
| 649 | mkname: "product.mk", |
| 650 | in: ` |
| 651 | ifeq ($(findstring foo,$(PRODUCT_PACKAGES)),) |
| 652 | endif |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 653 | ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),) |
| 654 | endif |
Cole Faust | 0e9418c | 2021-12-13 16:33:25 -0800 | [diff] [blame] | 655 | ifeq ($(findstring foo,$(PRODUCT_PACKAGES)),foo) |
| 656 | endif |
| 657 | ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),foo) |
| 658 | endif |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 659 | `, |
| 660 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 661 | |
| 662 | def init(g, handle): |
| 663 | cfg = rblf.cfg(handle) |
Cole Faust | 0e9418c | 2021-12-13 16:33:25 -0800 | [diff] [blame] | 664 | if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") == -1: |
| 665 | pass |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 666 | if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1: |
| 667 | pass |
Cole Faust | 0e9418c | 2021-12-13 16:33:25 -0800 | [diff] [blame] | 668 | if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1: |
| 669 | pass |
| 670 | if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") == -1: |
| 671 | pass |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 672 | `, |
| 673 | }, |
| 674 | { |
| 675 | desc: "rhs call", |
| 676 | mkname: "product.mk", |
| 677 | in: ` |
| 678 | PRODUCT_COPY_FILES = $(call add-to-product-copy-files-if-exists, path:distpath) \ |
| 679 | $(call find-copy-subdir-files, *, fromdir, todir) $(wildcard foo.*) |
| 680 | `, |
| 681 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 682 | |
| 683 | def init(g, handle): |
| 684 | cfg = rblf.cfg(handle) |
| 685 | cfg["PRODUCT_COPY_FILES"] = (rblf.copy_if_exists("path:distpath") + |
| 686 | rblf.find_and_copy("*", "fromdir", "todir") + |
| 687 | rblf.expand_wildcard("foo.*")) |
| 688 | `, |
| 689 | }, |
| 690 | { |
| 691 | desc: "inferred type", |
| 692 | mkname: "product.mk", |
| 693 | in: ` |
| 694 | HIKEY_MODS := $(wildcard foo/*.ko) |
| 695 | BOARD_VENDOR_KERNEL_MODULES += $(HIKEY_MODS) |
| 696 | `, |
| 697 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 698 | |
| 699 | def init(g, handle): |
| 700 | cfg = rblf.cfg(handle) |
| 701 | g["HIKEY_MODS"] = rblf.expand_wildcard("foo/*.ko") |
| 702 | g.setdefault("BOARD_VENDOR_KERNEL_MODULES", []) |
| 703 | g["BOARD_VENDOR_KERNEL_MODULES"] += g["HIKEY_MODS"] |
| 704 | `, |
| 705 | }, |
| 706 | { |
| 707 | desc: "list with vars", |
| 708 | mkname: "product.mk", |
| 709 | in: ` |
| 710 | PRODUCT_COPY_FILES += path1:$(TARGET_PRODUCT)/path1 $(PRODUCT_MODEL)/path2:$(TARGET_PRODUCT)/path2 |
| 711 | `, |
| 712 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 713 | |
| 714 | def init(g, handle): |
| 715 | cfg = rblf.cfg(handle) |
| 716 | rblf.setdefault(handle, "PRODUCT_COPY_FILES") |
| 717 | cfg["PRODUCT_COPY_FILES"] += (("path1:%s/path1" % g["TARGET_PRODUCT"]).split() + |
| 718 | ("%s/path2:%s/path2" % (cfg.get("PRODUCT_MODEL", ""), g["TARGET_PRODUCT"])).split()) |
| 719 | `, |
| 720 | }, |
| 721 | { |
| 722 | desc: "misc calls", |
| 723 | mkname: "product.mk", |
| 724 | in: ` |
| 725 | $(call enforce-product-packages-exist,) |
| 726 | $(call enforce-product-packages-exist, foo) |
| 727 | $(call require-artifacts-in-path, foo, bar) |
| 728 | $(call require-artifacts-in-path-relaxed, foo, bar) |
Sasha Smundak | d679785 | 2021-11-15 13:01:53 -0800 | [diff] [blame] | 729 | $(call dist-for-goals, goal, from:to) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 730 | `, |
| 731 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 732 | |
| 733 | def init(g, handle): |
| 734 | cfg = rblf.cfg(handle) |
| 735 | rblf.enforce_product_packages_exist("") |
| 736 | rblf.enforce_product_packages_exist("foo") |
| 737 | rblf.require_artifacts_in_path("foo", "bar") |
| 738 | rblf.require_artifacts_in_path_relaxed("foo", "bar") |
Sasha Smundak | d679785 | 2021-11-15 13:01:53 -0800 | [diff] [blame] | 739 | rblf.mkdist_for_goals(g, "goal", "from:to") |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 740 | `, |
| 741 | }, |
| 742 | { |
| 743 | desc: "list with functions", |
| 744 | mkname: "product.mk", |
| 745 | in: ` |
| 746 | PRODUCT_COPY_FILES := $(call find-copy-subdir-files,*.kl,from1,to1) \ |
| 747 | $(call find-copy-subdir-files,*.kc,from2,to2) \ |
| 748 | foo bar |
| 749 | `, |
| 750 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 751 | |
| 752 | def init(g, handle): |
| 753 | cfg = rblf.cfg(handle) |
| 754 | cfg["PRODUCT_COPY_FILES"] = (rblf.find_and_copy("*.kl", "from1", "to1") + |
| 755 | rblf.find_and_copy("*.kc", "from2", "to2") + |
| 756 | [ |
| 757 | "foo", |
| 758 | "bar", |
| 759 | ]) |
| 760 | `, |
| 761 | }, |
| 762 | { |
| 763 | desc: "Text functions", |
| 764 | mkname: "product.mk", |
| 765 | in: ` |
| 766 | PRODUCT_COPY_FILES := $(addprefix pfx-,a b c) |
| 767 | PRODUCT_COPY_FILES := $(addsuffix .sff, a b c) |
| 768 | PRODUCT_NAME := $(word 1, $(subst ., ,$(TARGET_BOARD_PLATFORM))) |
Sasha Smundak | 35434ed | 2021-11-05 16:29:56 -0700 | [diff] [blame] | 769 | $(info $(patsubst %.pub,$(PRODUCT_NAME)%,$(PRODUCT_ADB_KEYS))) |
Sasha Smundak | 16e0773 | 2021-07-23 11:38:23 -0700 | [diff] [blame] | 770 | $(info $(dir foo/bar)) |
| 771 | $(info $(firstword $(PRODUCT_COPY_FILES))) |
| 772 | $(info $(lastword $(PRODUCT_COPY_FILES))) |
| 773 | $(info $(dir $(lastword $(MAKEFILE_LIST)))) |
| 774 | $(info $(dir $(lastword $(PRODUCT_COPY_FILES)))) |
| 775 | $(info $(dir $(lastword $(foobar)))) |
| 776 | $(info $(abspath foo/bar)) |
| 777 | $(info $(notdir foo/bar)) |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 778 | $(call add_soong_config_namespace,snsconfig) |
| 779 | $(call add_soong_config_var_value,snsconfig,imagetype,odm_image) |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 780 | $(call soong_config_set, snsconfig, foo, foo_value) |
| 781 | $(call soong_config_append, snsconfig, bar, bar_value) |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 782 | PRODUCT_COPY_FILES := $(call copy-files,$(wildcard foo*.mk),etc) |
Sasha Smundak | 0445308 | 2021-08-17 18:14:41 -0700 | [diff] [blame] | 783 | 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] | 784 | `, |
| 785 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 786 | |
| 787 | def init(g, handle): |
| 788 | cfg = rblf.cfg(handle) |
| 789 | cfg["PRODUCT_COPY_FILES"] = rblf.addprefix("pfx-", "a b c") |
| 790 | cfg["PRODUCT_COPY_FILES"] = rblf.addsuffix(".sff", "a b c") |
| 791 | cfg["PRODUCT_NAME"] = ((g.get("TARGET_BOARD_PLATFORM", "")).replace(".", " ")).split()[0] |
Sasha Smundak | 35434ed | 2021-11-05 16:29:56 -0700 | [diff] [blame] | 792 | 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] | 793 | rblf.mkinfo("product.mk", rblf.dir("foo/bar")) |
| 794 | rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][0]) |
| 795 | rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][-1]) |
| 796 | rblf.mkinfo("product.mk", rblf.dir("product.mk")) |
| 797 | rblf.mkinfo("product.mk", rblf.dir(cfg["PRODUCT_COPY_FILES"][-1])) |
| 798 | rblf.mkinfo("product.mk", rblf.dir((_foobar).split()[-1])) |
| 799 | rblf.mkinfo("product.mk", rblf.abspath("foo/bar")) |
| 800 | rblf.mkinfo("product.mk", rblf.notdir("foo/bar")) |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 801 | rblf.soong_config_namespace(g, "snsconfig") |
| 802 | rblf.soong_config_set(g, "snsconfig", "imagetype", "odm_image") |
| 803 | rblf.soong_config_set(g, "snsconfig", "foo", "foo_value") |
| 804 | rblf.soong_config_append(g, "snsconfig", "bar", "bar_value") |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 805 | 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] | 806 | 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] | 807 | `, |
| 808 | }, |
| 809 | { |
Sasha Smundak | 9d011ab | 2021-07-09 16:00:57 -0700 | [diff] [blame] | 810 | desc: "subst in list", |
| 811 | mkname: "product.mk", |
| 812 | in: ` |
| 813 | files = $(call find-copy-subdir-files,*,from,to) |
| 814 | PRODUCT_COPY_FILES += $(subst foo,bar,$(files)) |
| 815 | `, |
| 816 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 817 | |
| 818 | def init(g, handle): |
| 819 | cfg = rblf.cfg(handle) |
| 820 | _files = rblf.find_and_copy("*", "from", "to") |
| 821 | rblf.setdefault(handle, "PRODUCT_COPY_FILES") |
| 822 | cfg["PRODUCT_COPY_FILES"] += rblf.mksubst("foo", "bar", _files) |
| 823 | `, |
| 824 | }, |
| 825 | { |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 826 | desc: "assignment flavors", |
| 827 | mkname: "product.mk", |
| 828 | in: ` |
| 829 | PRODUCT_LIST1 := a |
| 830 | PRODUCT_LIST2 += a |
| 831 | PRODUCT_LIST1 += b |
| 832 | PRODUCT_LIST2 += b |
| 833 | PRODUCT_LIST3 ?= a |
| 834 | PRODUCT_LIST1 = c |
| 835 | PLATFORM_LIST += x |
| 836 | PRODUCT_PACKAGES := $(PLATFORM_LIST) |
| 837 | `, |
| 838 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 839 | |
| 840 | def init(g, handle): |
| 841 | cfg = rblf.cfg(handle) |
| 842 | cfg["PRODUCT_LIST1"] = ["a"] |
| 843 | rblf.setdefault(handle, "PRODUCT_LIST2") |
| 844 | cfg["PRODUCT_LIST2"] += ["a"] |
| 845 | cfg["PRODUCT_LIST1"] += ["b"] |
| 846 | cfg["PRODUCT_LIST2"] += ["b"] |
| 847 | if cfg.get("PRODUCT_LIST3") == None: |
| 848 | cfg["PRODUCT_LIST3"] = ["a"] |
| 849 | cfg["PRODUCT_LIST1"] = ["c"] |
| 850 | g.setdefault("PLATFORM_LIST", []) |
| 851 | g["PLATFORM_LIST"] += ["x"] |
| 852 | cfg["PRODUCT_PACKAGES"] = g["PLATFORM_LIST"][:] |
| 853 | `, |
| 854 | }, |
| 855 | { |
| 856 | desc: "assigment flavors2", |
| 857 | mkname: "product.mk", |
| 858 | in: ` |
| 859 | PRODUCT_LIST1 = a |
| 860 | ifeq (0,1) |
| 861 | PRODUCT_LIST1 += b |
| 862 | PRODUCT_LIST2 += b |
| 863 | endif |
| 864 | PRODUCT_LIST1 += c |
| 865 | PRODUCT_LIST2 += c |
| 866 | `, |
| 867 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 868 | |
| 869 | def init(g, handle): |
| 870 | cfg = rblf.cfg(handle) |
| 871 | cfg["PRODUCT_LIST1"] = ["a"] |
| 872 | if "0" == "1": |
| 873 | cfg["PRODUCT_LIST1"] += ["b"] |
| 874 | rblf.setdefault(handle, "PRODUCT_LIST2") |
| 875 | cfg["PRODUCT_LIST2"] += ["b"] |
| 876 | cfg["PRODUCT_LIST1"] += ["c"] |
| 877 | rblf.setdefault(handle, "PRODUCT_LIST2") |
| 878 | cfg["PRODUCT_LIST2"] += ["c"] |
| 879 | `, |
| 880 | }, |
| 881 | { |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 882 | desc: "soong namespace assignments", |
| 883 | mkname: "product.mk", |
| 884 | in: ` |
| 885 | SOONG_CONFIG_NAMESPACES += cvd |
| 886 | SOONG_CONFIG_cvd += launch_configs |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 887 | SOONG_CONFIG_cvd_launch_configs = cvd_config_auto.json |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 888 | SOONG_CONFIG_cvd += grub_config |
| 889 | SOONG_CONFIG_cvd_grub_config += grub.cfg |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 890 | x := $(SOONG_CONFIG_cvd_grub_config) |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 891 | `, |
| 892 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 893 | |
| 894 | def init(g, handle): |
| 895 | cfg = rblf.cfg(handle) |
Sasha Smundak | 65b547e | 2021-09-17 15:35:41 -0700 | [diff] [blame] | 896 | rblf.soong_config_namespace(g, "cvd") |
| 897 | rblf.soong_config_set(g, "cvd", "launch_configs", "cvd_config_auto.json") |
| 898 | rblf.soong_config_append(g, "cvd", "grub_config", "grub.cfg") |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 899 | 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] | 900 | `, |
Cole Faust | c00184e | 2021-11-08 12:08:57 -0800 | [diff] [blame] | 901 | }, { |
| 902 | desc: "soong namespace accesses", |
| 903 | mkname: "product.mk", |
| 904 | in: ` |
| 905 | SOONG_CONFIG_NAMESPACES += cvd |
| 906 | SOONG_CONFIG_cvd += launch_configs |
| 907 | SOONG_CONFIG_cvd_launch_configs = cvd_config_auto.json |
| 908 | SOONG_CONFIG_cvd += grub_config |
| 909 | SOONG_CONFIG_cvd_grub_config += grub.cfg |
| 910 | x := $(call soong_config_get,cvd,grub_config) |
| 911 | `, |
| 912 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 913 | |
| 914 | def init(g, handle): |
| 915 | cfg = rblf.cfg(handle) |
| 916 | rblf.soong_config_namespace(g, "cvd") |
| 917 | rblf.soong_config_set(g, "cvd", "launch_configs", "cvd_config_auto.json") |
| 918 | rblf.soong_config_append(g, "cvd", "grub_config", "grub.cfg") |
| 919 | _x = rblf.soong_config_get(g, "cvd", "grub_config") |
| 920 | `, |
Sasha Smundak | 3deb968 | 2021-07-26 18:42:25 -0700 | [diff] [blame] | 921 | }, |
| 922 | { |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 923 | desc: "string split", |
| 924 | mkname: "product.mk", |
| 925 | in: ` |
| 926 | PRODUCT_LIST1 = a |
| 927 | local = b |
| 928 | local += c |
| 929 | FOO = d |
| 930 | FOO += e |
| 931 | PRODUCT_LIST1 += $(local) |
| 932 | PRODUCT_LIST1 += $(FOO) |
| 933 | `, |
| 934 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 935 | |
| 936 | def init(g, handle): |
| 937 | cfg = rblf.cfg(handle) |
| 938 | cfg["PRODUCT_LIST1"] = ["a"] |
| 939 | _local = "b" |
| 940 | _local += " " + "c" |
| 941 | g["FOO"] = "d" |
| 942 | g["FOO"] += " " + "e" |
| 943 | cfg["PRODUCT_LIST1"] += (_local).split() |
| 944 | cfg["PRODUCT_LIST1"] += (g["FOO"]).split() |
| 945 | `, |
| 946 | }, |
| 947 | { |
| 948 | desc: "apex_jars", |
| 949 | mkname: "product.mk", |
| 950 | in: ` |
| 951 | PRODUCT_BOOT_JARS := $(ART_APEX_JARS) framework-minus-apex |
| 952 | `, |
| 953 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 954 | |
| 955 | def init(g, handle): |
| 956 | cfg = rblf.cfg(handle) |
| 957 | cfg["PRODUCT_BOOT_JARS"] = (g.get("ART_APEX_JARS", []) + |
| 958 | ["framework-minus-apex"]) |
| 959 | `, |
| 960 | }, |
| 961 | { |
| 962 | desc: "strip function", |
| 963 | mkname: "product.mk", |
| 964 | in: ` |
| 965 | ifeq ($(filter hwaddress,$(PRODUCT_PACKAGES)),) |
| 966 | PRODUCT_PACKAGES := $(strip $(PRODUCT_PACKAGES) hwaddress) |
| 967 | endif |
| 968 | `, |
| 969 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 970 | |
| 971 | def init(g, handle): |
| 972 | cfg = rblf.cfg(handle) |
| 973 | if "hwaddress" not in cfg.get("PRODUCT_PACKAGES", []): |
| 974 | cfg["PRODUCT_PACKAGES"] = (rblf.mkstrip("%s hwaddress" % " ".join(cfg.get("PRODUCT_PACKAGES", [])))).split() |
| 975 | `, |
| 976 | }, |
| 977 | { |
| 978 | desc: "strip func in condition", |
| 979 | mkname: "product.mk", |
| 980 | in: ` |
| 981 | ifneq ($(strip $(TARGET_VENDOR)),) |
| 982 | endif |
| 983 | `, |
| 984 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 985 | |
| 986 | def init(g, handle): |
| 987 | cfg = rblf.cfg(handle) |
Sasha Smundak | 0554d76 | 2021-07-08 18:26:12 -0700 | [diff] [blame] | 988 | if rblf.mkstrip(g.get("TARGET_VENDOR", "")): |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 989 | pass |
| 990 | `, |
| 991 | }, |
| 992 | { |
| 993 | desc: "ref after set", |
| 994 | mkname: "product.mk", |
| 995 | in: ` |
| 996 | PRODUCT_ADB_KEYS:=value |
| 997 | FOO := $(PRODUCT_ADB_KEYS) |
| 998 | ifneq (,$(PRODUCT_ADB_KEYS)) |
| 999 | endif |
| 1000 | `, |
| 1001 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1002 | |
| 1003 | def init(g, handle): |
| 1004 | cfg = rblf.cfg(handle) |
| 1005 | g["PRODUCT_ADB_KEYS"] = "value" |
| 1006 | g["FOO"] = g["PRODUCT_ADB_KEYS"] |
| 1007 | if g["PRODUCT_ADB_KEYS"]: |
| 1008 | pass |
| 1009 | `, |
| 1010 | }, |
| 1011 | { |
| 1012 | desc: "ref before set", |
| 1013 | mkname: "product.mk", |
| 1014 | in: ` |
| 1015 | V1 := $(PRODUCT_ADB_KEYS) |
| 1016 | ifeq (,$(PRODUCT_ADB_KEYS)) |
| 1017 | V2 := $(PRODUCT_ADB_KEYS) |
| 1018 | PRODUCT_ADB_KEYS:=foo |
| 1019 | V3 := $(PRODUCT_ADB_KEYS) |
| 1020 | endif`, |
| 1021 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1022 | |
| 1023 | def init(g, handle): |
| 1024 | cfg = rblf.cfg(handle) |
| 1025 | g["V1"] = g.get("PRODUCT_ADB_KEYS", "") |
| 1026 | if not g.get("PRODUCT_ADB_KEYS", ""): |
| 1027 | g["V2"] = g.get("PRODUCT_ADB_KEYS", "") |
| 1028 | g["PRODUCT_ADB_KEYS"] = "foo" |
| 1029 | g["V3"] = g["PRODUCT_ADB_KEYS"] |
| 1030 | `, |
| 1031 | }, |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1032 | { |
| 1033 | desc: "Dynamic inherit path", |
| 1034 | mkname: "product.mk", |
| 1035 | in: ` |
Sasha Smundak | 6d852dd | 2021-09-27 20:34:39 -0700 | [diff] [blame] | 1036 | MY_PATH:=foo |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1037 | $(call inherit-product,vendor/$(MY_PATH)/cfg.mk) |
| 1038 | `, |
| 1039 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1040 | load("//vendor/foo1:cfg.star|init", _cfg_init = "init") |
| 1041 | load("//vendor/bar/baz:cfg.star|init", _cfg1_init = "init") |
| 1042 | |
| 1043 | def init(g, handle): |
| 1044 | cfg = rblf.cfg(handle) |
| 1045 | g["MY_PATH"] = "foo" |
| 1046 | _entry = { |
| 1047 | "vendor/foo1/cfg.mk": ("_cfg", _cfg_init), |
| 1048 | "vendor/bar/baz/cfg.mk": ("_cfg1", _cfg1_init), |
| 1049 | }.get("vendor/%s/cfg.mk" % g["MY_PATH"]) |
| 1050 | (_varmod, _varmod_init) = _entry if _entry else (None, None) |
| 1051 | if not _varmod_init: |
Cole Faust | 7321b09 | 2021-12-21 16:11:16 -0800 | [diff] [blame^] | 1052 | rblf.mkerror("product.mk", "Cannot find %s" % ("vendor/%s/cfg.mk" % g["MY_PATH"])) |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1053 | rblf.inherit(handle, _varmod, _varmod_init) |
| 1054 | `, |
| 1055 | }, |
Sasha Smundak | 6d852dd | 2021-09-27 20:34:39 -0700 | [diff] [blame] | 1056 | { |
| 1057 | desc: "Dynamic inherit with hint", |
| 1058 | mkname: "product.mk", |
| 1059 | in: ` |
| 1060 | MY_PATH:=foo |
| 1061 | #RBC# include_top vendor/foo1 |
| 1062 | $(call inherit-product,$(MY_PATH)/cfg.mk) |
| 1063 | `, |
| 1064 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1065 | load("//vendor/foo1:cfg.star|init", _cfg_init = "init") |
| 1066 | |
| 1067 | def init(g, handle): |
| 1068 | cfg = rblf.cfg(handle) |
| 1069 | g["MY_PATH"] = "foo" |
| 1070 | #RBC# include_top vendor/foo1 |
| 1071 | _entry = { |
| 1072 | "vendor/foo1/cfg.mk": ("_cfg", _cfg_init), |
| 1073 | }.get("%s/cfg.mk" % g["MY_PATH"]) |
| 1074 | (_varmod, _varmod_init) = _entry if _entry else (None, None) |
| 1075 | if not _varmod_init: |
Cole Faust | 7321b09 | 2021-12-21 16:11:16 -0800 | [diff] [blame^] | 1076 | rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"])) |
Sasha Smundak | 6d852dd | 2021-09-27 20:34:39 -0700 | [diff] [blame] | 1077 | rblf.inherit(handle, _varmod, _varmod_init) |
| 1078 | `, |
| 1079 | }, |
Sasha Smundak | 2afb9d7 | 2021-10-24 15:16:59 -0700 | [diff] [blame] | 1080 | { |
Cole Faust | f7ed534 | 2021-12-21 14:15:12 -0800 | [diff] [blame] | 1081 | desc: "Dynamic inherit with duplicated hint", |
| 1082 | mkname: "product.mk", |
| 1083 | in: ` |
| 1084 | MY_PATH:=foo |
| 1085 | #RBC# include_top vendor/foo1 |
| 1086 | $(call inherit-product,$(MY_PATH)/cfg.mk) |
| 1087 | #RBC# include_top vendor/foo1 |
| 1088 | $(call inherit-product,$(MY_PATH)/cfg.mk) |
| 1089 | `, |
| 1090 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1091 | load("//vendor/foo1:cfg.star|init", _cfg_init = "init") |
| 1092 | |
| 1093 | def init(g, handle): |
| 1094 | cfg = rblf.cfg(handle) |
| 1095 | g["MY_PATH"] = "foo" |
| 1096 | #RBC# include_top vendor/foo1 |
| 1097 | _entry = { |
| 1098 | "vendor/foo1/cfg.mk": ("_cfg", _cfg_init), |
| 1099 | }.get("%s/cfg.mk" % g["MY_PATH"]) |
| 1100 | (_varmod, _varmod_init) = _entry if _entry else (None, None) |
| 1101 | if not _varmod_init: |
Cole Faust | 7321b09 | 2021-12-21 16:11:16 -0800 | [diff] [blame^] | 1102 | rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"])) |
Cole Faust | f7ed534 | 2021-12-21 14:15:12 -0800 | [diff] [blame] | 1103 | rblf.inherit(handle, _varmod, _varmod_init) |
| 1104 | #RBC# include_top vendor/foo1 |
| 1105 | _entry = { |
| 1106 | "vendor/foo1/cfg.mk": ("_cfg", _cfg_init), |
| 1107 | }.get("%s/cfg.mk" % g["MY_PATH"]) |
| 1108 | (_varmod, _varmod_init) = _entry if _entry else (None, None) |
| 1109 | if not _varmod_init: |
Cole Faust | 7321b09 | 2021-12-21 16:11:16 -0800 | [diff] [blame^] | 1110 | rblf.mkerror("product.mk", "Cannot find %s" % ("%s/cfg.mk" % g["MY_PATH"])) |
Cole Faust | f7ed534 | 2021-12-21 14:15:12 -0800 | [diff] [blame] | 1111 | rblf.inherit(handle, _varmod, _varmod_init) |
| 1112 | `, |
| 1113 | }, |
| 1114 | { |
Sasha Smundak | 2afb9d7 | 2021-10-24 15:16:59 -0700 | [diff] [blame] | 1115 | desc: "Ignore make rules", |
| 1116 | mkname: "product.mk", |
| 1117 | in: ` |
| 1118 | foo: foo.c |
| 1119 | gcc -o $@ $*`, |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1120 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
Sasha Smundak | 2afb9d7 | 2021-10-24 15:16:59 -0700 | [diff] [blame] | 1121 | |
| 1122 | def init(g, handle): |
| 1123 | cfg = rblf.cfg(handle) |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1124 | 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] | 1125 | `, |
| 1126 | }, |
Sasha Smundak | ea3bc3a | 2021-11-10 13:06:42 -0800 | [diff] [blame] | 1127 | { |
| 1128 | desc: "Flag override", |
| 1129 | mkname: "product.mk", |
| 1130 | in: ` |
| 1131 | override FOO:=`, |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1132 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
Sasha Smundak | ea3bc3a | 2021-11-10 13:06:42 -0800 | [diff] [blame] | 1133 | |
| 1134 | def init(g, handle): |
| 1135 | cfg = rblf.cfg(handle) |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1136 | rblf.mk2rbc_error("product.mk:2", "cannot handle override directive") |
Sasha Smundak | ea3bc3a | 2021-11-10 13:06:42 -0800 | [diff] [blame] | 1137 | g["override FOO"] = "" |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1138 | `, |
| 1139 | }, |
| 1140 | { |
| 1141 | desc: "Bad expression", |
| 1142 | mkname: "build/product.mk", |
| 1143 | in: ` |
| 1144 | ifeq (,$(call foobar)) |
| 1145 | endif |
| 1146 | `, |
| 1147 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1148 | |
| 1149 | def init(g, handle): |
| 1150 | cfg = rblf.cfg(handle) |
| 1151 | if rblf.mk2rbc_error("build/product.mk:2", "cannot handle invoking foobar"): |
| 1152 | pass |
Sasha Smundak | ea3bc3a | 2021-11-10 13:06:42 -0800 | [diff] [blame] | 1153 | `, |
| 1154 | }, |
Cole Faust | 4eadba7 | 2021-12-07 11:54:52 -0800 | [diff] [blame] | 1155 | { |
| 1156 | desc: "if expression", |
| 1157 | mkname: "product.mk", |
| 1158 | in: ` |
| 1159 | TEST_VAR := foo |
| 1160 | TEST_VAR_LIST := foo |
| 1161 | TEST_VAR_LIST += bar |
| 1162 | TEST_VAR_2 := $(if $(TEST_VAR),bar) |
| 1163 | TEST_VAR_3 := $(if $(TEST_VAR),bar,baz) |
| 1164 | TEST_VAR_3 := $(if $(TEST_VAR),$(TEST_VAR_LIST)) |
| 1165 | `, |
| 1166 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1167 | |
| 1168 | def init(g, handle): |
| 1169 | cfg = rblf.cfg(handle) |
| 1170 | g["TEST_VAR"] = "foo" |
| 1171 | g["TEST_VAR_LIST"] = ["foo"] |
| 1172 | g["TEST_VAR_LIST"] += ["bar"] |
| 1173 | g["TEST_VAR_2"] = ("bar" if g["TEST_VAR"] else "") |
| 1174 | g["TEST_VAR_3"] = ("bar" if g["TEST_VAR"] else "baz") |
| 1175 | g["TEST_VAR_3"] = (g["TEST_VAR_LIST"] if g["TEST_VAR"] else []) |
| 1176 | `, |
| 1177 | }, |
Cole Faust | c36c962 | 2021-12-07 15:20:45 -0800 | [diff] [blame] | 1178 | { |
| 1179 | desc: "substitution references", |
| 1180 | mkname: "product.mk", |
| 1181 | in: ` |
| 1182 | SOURCES := foo.c bar.c |
| 1183 | OBJECTS := $(SOURCES:.c=.o) |
| 1184 | OBJECTS2 := $(SOURCES:%.c=%.o) |
| 1185 | `, |
| 1186 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1187 | |
| 1188 | def init(g, handle): |
| 1189 | cfg = rblf.cfg(handle) |
| 1190 | g["SOURCES"] = "foo.c bar.c" |
| 1191 | g["OBJECTS"] = rblf.mkpatsubst("%.c", "%.o", g["SOURCES"]) |
| 1192 | g["OBJECTS2"] = rblf.mkpatsubst("%.c", "%.o", g["SOURCES"]) |
| 1193 | `, |
| 1194 | }, |
Cole Faust | b0d32ab | 2021-12-09 14:00:59 -0800 | [diff] [blame] | 1195 | { |
| 1196 | desc: "foreach expressions", |
| 1197 | mkname: "product.mk", |
| 1198 | in: ` |
| 1199 | BOOT_KERNEL_MODULES := foo.ko bar.ko |
| 1200 | BOOT_KERNEL_MODULES_FILTER := $(foreach m,$(BOOT_KERNEL_MODULES),%/$(m)) |
| 1201 | BOOT_KERNEL_MODULES_LIST := foo.ko |
| 1202 | BOOT_KERNEL_MODULES_LIST += bar.ko |
| 1203 | BOOT_KERNEL_MODULES_FILTER_2 := $(foreach m,$(BOOT_KERNEL_MODULES_LIST),%/$(m)) |
| 1204 | |
| 1205 | `, |
| 1206 | expected: `load("//build/make/core:product_config.rbc", "rblf") |
| 1207 | |
| 1208 | def init(g, handle): |
| 1209 | cfg = rblf.cfg(handle) |
| 1210 | g["BOOT_KERNEL_MODULES"] = "foo.ko bar.ko" |
| 1211 | g["BOOT_KERNEL_MODULES_FILTER"] = ["%%/%s" % m for m in rblf.words(g["BOOT_KERNEL_MODULES"])] |
| 1212 | g["BOOT_KERNEL_MODULES_LIST"] = ["foo.ko"] |
| 1213 | g["BOOT_KERNEL_MODULES_LIST"] += ["bar.ko"] |
| 1214 | g["BOOT_KERNEL_MODULES_FILTER_2"] = ["%%/%s" % m for m in g["BOOT_KERNEL_MODULES_LIST"]] |
| 1215 | `, |
| 1216 | }, |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | var known_variables = []struct { |
| 1220 | name string |
| 1221 | class varClass |
| 1222 | starlarkType |
| 1223 | }{ |
Cole Faust | f1f44d3 | 2021-11-16 14:52:12 -0800 | [diff] [blame] | 1224 | {"NATIVE_COVERAGE", VarClassSoong, starlarkTypeBool}, |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1225 | {"PRODUCT_NAME", VarClassConfig, starlarkTypeString}, |
| 1226 | {"PRODUCT_MODEL", VarClassConfig, starlarkTypeString}, |
| 1227 | {"PRODUCT_PACKAGES", VarClassConfig, starlarkTypeList}, |
| 1228 | {"PRODUCT_BOOT_JARS", VarClassConfig, starlarkTypeList}, |
| 1229 | {"PRODUCT_COPY_FILES", VarClassConfig, starlarkTypeList}, |
| 1230 | {"PRODUCT_IS_64BIT", VarClassConfig, starlarkTypeString}, |
| 1231 | {"PRODUCT_LIST1", VarClassConfig, starlarkTypeList}, |
| 1232 | {"PRODUCT_LIST2", VarClassConfig, starlarkTypeList}, |
| 1233 | {"PRODUCT_LIST3", VarClassConfig, starlarkTypeList}, |
| 1234 | {"TARGET_PRODUCT", VarClassSoong, starlarkTypeString}, |
| 1235 | {"TARGET_BUILD_VARIANT", VarClassSoong, starlarkTypeString}, |
| 1236 | {"TARGET_BOARD_PLATFORM", VarClassSoong, starlarkTypeString}, |
| 1237 | {"QCOM_BOARD_PLATFORMS", VarClassSoong, starlarkTypeString}, |
| 1238 | {"PLATFORM_LIST", VarClassSoong, starlarkTypeList}, // TODO(asmundak): make it local instead of soong |
| 1239 | } |
| 1240 | |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1241 | type testMakefileFinder struct { |
| 1242 | fs fs.FS |
| 1243 | root string |
| 1244 | files []string |
| 1245 | } |
| 1246 | |
| 1247 | func (t *testMakefileFinder) Find(root string) []string { |
| 1248 | if t.files != nil || root == t.root { |
| 1249 | return t.files |
| 1250 | } |
| 1251 | t.files = make([]string, 0) |
| 1252 | fs.WalkDir(t.fs, root, func(path string, d fs.DirEntry, err error) error { |
| 1253 | if err != nil { |
| 1254 | return err |
| 1255 | } |
| 1256 | if d.IsDir() { |
| 1257 | base := filepath.Base(path) |
| 1258 | if base[0] == '.' && len(base) > 1 { |
| 1259 | return fs.SkipDir |
| 1260 | } |
| 1261 | return nil |
| 1262 | } |
| 1263 | if strings.HasSuffix(path, ".mk") { |
| 1264 | t.files = append(t.files, path) |
| 1265 | } |
| 1266 | return nil |
| 1267 | }) |
| 1268 | return t.files |
| 1269 | } |
| 1270 | |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1271 | func TestGood(t *testing.T) { |
| 1272 | for _, v := range known_variables { |
| 1273 | KnownVariables.NewVariable(v.name, v.class, v.starlarkType) |
| 1274 | } |
Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 1275 | fs := NewFindMockFS([]string{ |
| 1276 | "vendor/foo1/cfg.mk", |
| 1277 | "vendor/bar/baz/cfg.mk", |
| 1278 | "part.mk", |
| 1279 | "foo/font.mk", |
| 1280 | "bar/font.mk", |
| 1281 | }) |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1282 | for _, test := range testCases { |
| 1283 | t.Run(test.desc, |
| 1284 | func(t *testing.T) { |
| 1285 | ss, err := Convert(Request{ |
Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 1286 | MkFile: test.mkname, |
| 1287 | Reader: bytes.NewBufferString(test.in), |
| 1288 | RootDir: ".", |
| 1289 | OutputSuffix: ".star", |
| 1290 | SourceFS: fs, |
| 1291 | MakefileFinder: &testMakefileFinder{fs: fs}, |
Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1292 | }) |
| 1293 | if err != nil { |
| 1294 | t.Error(err) |
| 1295 | return |
| 1296 | } |
| 1297 | got := ss.String() |
| 1298 | if got != test.expected { |
| 1299 | t.Errorf("%q failed\nExpected:\n%s\nActual:\n%s\n", test.desc, |
| 1300 | strings.ReplaceAll(test.expected, "\n", "\n"), |
| 1301 | strings.ReplaceAll(got, "\n", "\n")) |
| 1302 | } |
| 1303 | }) |
| 1304 | } |
| 1305 | } |