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