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