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