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