blob: 1e79552cdcedac0447346a3365fa35b64ab2e20a [file] [log] [blame]
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001// 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
15package mk2rbc
16
17import (
18 "bytes"
Sasha Smundak6609ba72021-07-22 18:32:56 -070019 "io/fs"
20 "path/filepath"
Sasha Smundakb051c4e2020-11-05 20:45:07 -080021 "strings"
22 "testing"
23)
24
25var 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
42load("//build/make/core:product_config.rbc", "rblf")
43
44def 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
55load("//build/make/core:product_config.rbc", "rblf")
56
57def init(g, handle):
58 cfg = rblf.cfg(handle)
59`,
60 },
61 {
62 desc: "Item variable",
63 mkname: "pixel3.mk",
64 in: `
65PRODUCT_NAME := Pixel 3
66PRODUCT_MODEL :=
67local_var = foo
68`,
69 expected: `load("//build/make/core:product_config.rbc", "rblf")
70
71def init(g, handle):
72 cfg = rblf.cfg(handle)
73 cfg["PRODUCT_NAME"] = "Pixel 3"
74 cfg["PRODUCT_MODEL"] = ""
75 _local_var = "foo"
76`,
77 },
78 {
79 desc: "List variable",
80 mkname: "pixel4.mk",
81 in: `
82PRODUCT_PACKAGES = package1 package2
83PRODUCT_COPY_FILES += file2:target
84PRODUCT_PACKAGES += package3
85PRODUCT_COPY_FILES =
86`,
87 expected: `load("//build/make/core:product_config.rbc", "rblf")
88
89def init(g, handle):
90 cfg = rblf.cfg(handle)
91 cfg["PRODUCT_PACKAGES"] = [
92 "package1",
93 "package2",
94 ]
95 rblf.setdefault(handle, "PRODUCT_COPY_FILES")
96 cfg["PRODUCT_COPY_FILES"] += ["file2:target"]
97 cfg["PRODUCT_PACKAGES"] += ["package3"]
98 cfg["PRODUCT_COPY_FILES"] = []
99`,
100 },
101 {
102 desc: "Unknown function",
103 mkname: "product.mk",
104 in: `
Sasha Smundak6609ba72021-07-22 18:32:56 -0700105PRODUCT_NAME := $(call foo1, bar)
106PRODUCT_NAME := $(call foo0)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800107`,
Sasha Smundak6609ba72021-07-22 18:32:56 -0700108 expected: `# MK2RBC TRANSLATION ERROR: cannot handle invoking foo1
109# PRODUCT_NAME := $(call foo1, bar)
110# MK2RBC TRANSLATION ERROR: cannot handle invoking foo0
111# PRODUCT_NAME := $(call foo0)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800112load("//build/make/core:product_config.rbc", "rblf")
113
114def init(g, handle):
115 cfg = rblf.cfg(handle)
116 rblf.warning("product.mk", "partially successful conversion")
117`,
118 },
119 {
120 desc: "Inherit configuration always",
121 mkname: "product.mk",
122 in: `
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800123$(call inherit-product, part.mk)
Sasha Smundak868c5e32021-09-23 16:20:58 -0700124ifdef PRODUCT_NAME
125$(call inherit-product, part1.mk)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800126else # Comment
Sasha Smundak868c5e32021-09-23 16:20:58 -0700127$(call inherit-product, $(LOCAL_PATH)/part1.mk)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800128endif
129`,
130 expected: `load("//build/make/core:product_config.rbc", "rblf")
131load(":part.star", _part_init = "init")
Sasha Smundak868c5e32021-09-23 16:20:58 -0700132load(":part1.star|init", _part1_init = "init")
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800133
134def init(g, handle):
135 cfg = rblf.cfg(handle)
Sasha Smundak868c5e32021-09-23 16:20:58 -0700136 rblf.inherit(handle, "part", _part_init)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800137 if g.get("PRODUCT_NAME") != None:
Sasha Smundak868c5e32021-09-23 16:20:58 -0700138 rblf.inherit(handle, "part1", _part1_init)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800139 else:
140 # Comment
Sasha Smundak868c5e32021-09-23 16:20:58 -0700141 rblf.inherit(handle, "part1", _part1_init)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800142`,
143 },
144 {
145 desc: "Inherit configuration if it exists",
146 mkname: "product.mk",
147 in: `
148$(call inherit-product-if-exists, part.mk)
149`,
150 expected: `load("//build/make/core:product_config.rbc", "rblf")
151load(":part.star|init", _part_init = "init")
152
153def init(g, handle):
154 cfg = rblf.cfg(handle)
Sasha Smundak6609ba72021-07-22 18:32:56 -0700155 if _part_init:
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800156 rblf.inherit(handle, "part", _part_init)
157`,
158 },
159
160 {
161 desc: "Include configuration",
162 mkname: "product.mk",
163 in: `
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800164include part.mk
Sasha Smundak868c5e32021-09-23 16:20:58 -0700165ifdef PRODUCT_NAME
166include part1.mk
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800167else
Sasha Smundak868c5e32021-09-23 16:20:58 -0700168-include $(LOCAL_PATH)/part1.mk)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800169endif
170`,
171 expected: `load("//build/make/core:product_config.rbc", "rblf")
Sasha Smundak868c5e32021-09-23 16:20:58 -0700172load(":part.star", _part_init = "init")
173load(":part1.star|init", _part1_init = "init")
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800174
175def init(g, handle):
176 cfg = rblf.cfg(handle)
Sasha Smundak868c5e32021-09-23 16:20:58 -0700177 _part_init(g, handle)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800178 if g.get("PRODUCT_NAME") != None:
Sasha Smundak868c5e32021-09-23 16:20:58 -0700179 _part1_init(g, handle)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800180 else:
Sasha Smundak868c5e32021-09-23 16:20:58 -0700181 if _part1_init != None:
182 _part1_init(g, handle)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800183`,
184 },
185
186 {
187 desc: "Synonymous inherited configurations",
188 mkname: "path/product.mk",
189 in: `
Sasha Smundak6609ba72021-07-22 18:32:56 -0700190$(call inherit-product, */font.mk)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800191`,
192 expected: `load("//build/make/core:product_config.rbc", "rblf")
193load("//foo:font.star", _font_init = "init")
194load("//bar:font.star", _font1_init = "init")
195
196def init(g, handle):
197 cfg = rblf.cfg(handle)
198 rblf.inherit(handle, "foo/font", _font_init)
199 rblf.inherit(handle, "bar/font", _font1_init)
200`,
201 },
202 {
203 desc: "Directive define",
204 mkname: "product.mk",
205 in: `
206define some-macro
207 $(info foo)
208endef
209`,
210 expected: `# MK2RBC TRANSLATION ERROR: define is not supported: some-macro
211# define some-macro
212# $(info foo)
213# endef
214load("//build/make/core:product_config.rbc", "rblf")
215
216def init(g, handle):
217 cfg = rblf.cfg(handle)
218 rblf.warning("product.mk", "partially successful conversion")
219`,
220 },
221 {
222 desc: "Ifdef",
223 mkname: "product.mk",
224 in: `
225ifdef PRODUCT_NAME
226 PRODUCT_NAME = gizmo
227else
228endif
Sasha Smundakc4fa93e2021-11-05 14:38:46 -0700229local_var :=
230ifdef local_var
231endif
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800232`,
233 expected: `load("//build/make/core:product_config.rbc", "rblf")
234
235def init(g, handle):
236 cfg = rblf.cfg(handle)
237 if g.get("PRODUCT_NAME") != None:
238 cfg["PRODUCT_NAME"] = "gizmo"
239 else:
240 pass
Sasha Smundakc4fa93e2021-11-05 14:38:46 -0700241 _local_var = ""
242 if _local_var:
243 pass
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800244`,
245 },
246 {
247 desc: "Simple functions",
248 mkname: "product.mk",
249 in: `
250$(warning this is the warning)
251$(warning)
252$(info this is the info)
253$(error this is the error)
254PRODUCT_NAME:=$(shell echo *)
255`,
256 expected: `load("//build/make/core:product_config.rbc", "rblf")
257
258def init(g, handle):
259 cfg = rblf.cfg(handle)
260 rblf.mkwarning("product.mk", "this is the warning")
261 rblf.mkwarning("product.mk", "")
262 rblf.mkinfo("product.mk", "this is the info")
263 rblf.mkerror("product.mk", "this is the error")
264 cfg["PRODUCT_NAME"] = rblf.shell("echo *")
265`,
266 },
267 {
268 desc: "Empty if",
269 mkname: "product.mk",
270 in: `
271ifdef PRODUCT_NAME
272# Comment
Sasha Smundak6609ba72021-07-22 18:32:56 -0700273else
Sasha Smundak02183cf2021-08-16 13:36:11 -0700274 TARGET_COPY_OUT_RECOVERY := foo
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800275endif
276`,
277 expected: `load("//build/make/core:product_config.rbc", "rblf")
278
279def init(g, handle):
280 cfg = rblf.cfg(handle)
281 if g.get("PRODUCT_NAME") != None:
282 # Comment
283 pass
Sasha Smundak6609ba72021-07-22 18:32:56 -0700284 else:
Sasha Smundak02183cf2021-08-16 13:36:11 -0700285 # MK2RBC TRANSLATION ERROR: cannot set predefined variable TARGET_COPY_OUT_RECOVERY to "foo", its value should be "recovery"
Sasha Smundak6609ba72021-07-22 18:32:56 -0700286 pass
287 rblf.warning("product.mk", "partially successful conversion")
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800288`,
289 },
290 {
291 desc: "if/else/endif",
292 mkname: "product.mk",
293 in: `
294ifndef PRODUCT_NAME
295 PRODUCT_NAME=gizmo1
296else
297 PRODUCT_NAME=gizmo2
298endif
299`,
300 expected: `load("//build/make/core:product_config.rbc", "rblf")
301
302def init(g, handle):
303 cfg = rblf.cfg(handle)
304 if not g.get("PRODUCT_NAME") != None:
305 cfg["PRODUCT_NAME"] = "gizmo1"
306 else:
307 cfg["PRODUCT_NAME"] = "gizmo2"
308`,
309 },
310 {
311 desc: "else if",
312 mkname: "product.mk",
313 in: `
314ifdef PRODUCT_NAME
315 PRODUCT_NAME = gizmo
316else ifndef PRODUCT_PACKAGES # Comment
317endif
318 `,
319 expected: `load("//build/make/core:product_config.rbc", "rblf")
320
321def init(g, handle):
322 cfg = rblf.cfg(handle)
323 if g.get("PRODUCT_NAME") != None:
324 cfg["PRODUCT_NAME"] = "gizmo"
325 elif not g.get("PRODUCT_PACKAGES") != None:
326 # Comment
327 pass
328`,
329 },
330 {
331 desc: "ifeq / ifneq",
332 mkname: "product.mk",
333 in: `
334ifeq (aosp_arm, $(TARGET_PRODUCT))
335 PRODUCT_MODEL = pix2
336else
337 PRODUCT_MODEL = pix21
338endif
339ifneq (aosp_x86, $(TARGET_PRODUCT))
340 PRODUCT_MODEL = pix3
341endif
342`,
343 expected: `load("//build/make/core:product_config.rbc", "rblf")
344
345def init(g, handle):
346 cfg = rblf.cfg(handle)
347 if "aosp_arm" == g["TARGET_PRODUCT"]:
348 cfg["PRODUCT_MODEL"] = "pix2"
349 else:
350 cfg["PRODUCT_MODEL"] = "pix21"
351 if "aosp_x86" != g["TARGET_PRODUCT"]:
352 cfg["PRODUCT_MODEL"] = "pix3"
353`,
354 },
355 {
356 desc: "Check filter result",
357 mkname: "product.mk",
358 in: `
359ifeq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT)))
360endif
361ifneq (,$(filter userdebug,$(TARGET_BUILD_VARIANT))
362endif
363ifneq (,$(filter plaf,$(PLATFORM_LIST)))
364endif
365ifeq ($(TARGET_BUILD_VARIANT), $(filter $(TARGET_BUILD_VARIANT), userdebug eng))
366endif
Sasha Smundak0554d762021-07-08 18:26:12 -0700367ifneq (,$(filter true, $(v1)$(v2)))
368endif
Sasha Smundak5f463be2021-09-15 18:43:36 -0700369ifeq (,$(filter barbet coral%,$(TARGET_PRODUCT)))
370else ifneq (,$(filter barbet%,$(TARGET_PRODUCT)))
371endif
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800372`,
373 expected: `load("//build/make/core:product_config.rbc", "rblf")
374
375def init(g, handle):
376 cfg = rblf.cfg(handle)
Sasha Smundak5f463be2021-09-15 18:43:36 -0700377 if not rblf.filter("userdebug eng", g["TARGET_BUILD_VARIANT"]):
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800378 pass
Sasha Smundak5f463be2021-09-15 18:43:36 -0700379 if rblf.filter("userdebug", g["TARGET_BUILD_VARIANT"]):
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800380 pass
381 if "plaf" in g.get("PLATFORM_LIST", []):
382 pass
383 if g["TARGET_BUILD_VARIANT"] in ["userdebug", "eng"]:
384 pass
Sasha Smundak5f463be2021-09-15 18:43:36 -0700385 if rblf.filter("true", "%s%s" % (_v1, _v2)):
386 pass
387 if not rblf.filter("barbet coral%", g["TARGET_PRODUCT"]):
388 pass
389 elif rblf.filter("barbet%", g["TARGET_PRODUCT"]):
Sasha Smundak0554d762021-07-08 18:26:12 -0700390 pass
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800391`,
392 },
393 {
394 desc: "Get filter result",
395 mkname: "product.mk",
396 in: `
397PRODUCT_LIST2=$(filter-out %/foo.ko,$(wildcard path/*.ko))
398`,
399 expected: `load("//build/make/core:product_config.rbc", "rblf")
400
401def init(g, handle):
402 cfg = rblf.cfg(handle)
403 cfg["PRODUCT_LIST2"] = rblf.filter_out("%/foo.ko", rblf.expand_wildcard("path/*.ko"))
404`,
405 },
406 {
407 desc: "filter $(VAR), values",
408 mkname: "product.mk",
409 in: `
410ifeq (,$(filter $(TARGET_PRODUCT), yukawa_gms yukawa_sei510_gms)
411 ifneq (,$(filter $(TARGET_PRODUCT), yukawa_gms)
412 endif
413endif
414
415`,
416 expected: `load("//build/make/core:product_config.rbc", "rblf")
417
418def init(g, handle):
419 cfg = rblf.cfg(handle)
420 if g["TARGET_PRODUCT"] not in ["yukawa_gms", "yukawa_sei510_gms"]:
Sasha Smundak0554d762021-07-08 18:26:12 -0700421 if g["TARGET_PRODUCT"] == "yukawa_gms":
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800422 pass
423`,
424 },
425 {
Sasha Smundak0554d762021-07-08 18:26:12 -0700426 desc: "filter $(V1), $(V2)",
427 mkname: "product.mk",
428 in: `
429ifneq (, $(filter $(PRODUCT_LIST), $(TARGET_PRODUCT)))
430endif
431`,
432 expected: `load("//build/make/core:product_config.rbc", "rblf")
433
434def init(g, handle):
435 cfg = rblf.cfg(handle)
Sasha Smundak468e11f2021-08-26 09:10:23 -0700436 if rblf.filter(g.get("PRODUCT_LIST", []), g["TARGET_PRODUCT"]):
Sasha Smundak0554d762021-07-08 18:26:12 -0700437 pass
438`,
439 },
440 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800441 desc: "ifeq",
442 mkname: "product.mk",
443 in: `
444ifeq (aosp, $(TARGET_PRODUCT)) # Comment
445else ifneq (, $(TARGET_PRODUCT))
446endif
447`,
448 expected: `load("//build/make/core:product_config.rbc", "rblf")
449
450def init(g, handle):
451 cfg = rblf.cfg(handle)
452 if "aosp" == g["TARGET_PRODUCT"]:
453 # Comment
454 pass
455 elif g["TARGET_PRODUCT"]:
456 pass
457`,
458 },
459 {
460 desc: "Nested if",
461 mkname: "product.mk",
462 in: `
463ifdef PRODUCT_NAME
464 PRODUCT_PACKAGES = pack-if0
465 ifdef PRODUCT_MODEL
466 PRODUCT_PACKAGES = pack-if-if
467 else ifdef PRODUCT_NAME
468 PRODUCT_PACKAGES = pack-if-elif
469 else
470 PRODUCT_PACKAGES = pack-if-else
471 endif
472 PRODUCT_PACKAGES = pack-if
473else ifneq (,$(TARGET_PRODUCT))
474 PRODUCT_PACKAGES = pack-elif
475else
476 PRODUCT_PACKAGES = pack-else
477endif
478`,
479 expected: `load("//build/make/core:product_config.rbc", "rblf")
480
481def init(g, handle):
482 cfg = rblf.cfg(handle)
483 if g.get("PRODUCT_NAME") != None:
484 cfg["PRODUCT_PACKAGES"] = ["pack-if0"]
485 if g.get("PRODUCT_MODEL") != None:
486 cfg["PRODUCT_PACKAGES"] = ["pack-if-if"]
487 elif g.get("PRODUCT_NAME") != None:
488 cfg["PRODUCT_PACKAGES"] = ["pack-if-elif"]
489 else:
490 cfg["PRODUCT_PACKAGES"] = ["pack-if-else"]
491 cfg["PRODUCT_PACKAGES"] = ["pack-if"]
492 elif g["TARGET_PRODUCT"]:
493 cfg["PRODUCT_PACKAGES"] = ["pack-elif"]
494 else:
495 cfg["PRODUCT_PACKAGES"] = ["pack-else"]
496`,
497 },
498 {
499 desc: "Wildcard",
500 mkname: "product.mk",
501 in: `
502ifeq (,$(wildcard foo.mk))
503endif
504ifneq (,$(wildcard foo*.mk))
505endif
506`,
507 expected: `load("//build/make/core:product_config.rbc", "rblf")
508
509def init(g, handle):
510 cfg = rblf.cfg(handle)
511 if not rblf.file_exists("foo.mk"):
512 pass
513 if rblf.file_wildcard_exists("foo*.mk"):
514 pass
515`,
516 },
517 {
518 desc: "ifneq $(X),true",
519 mkname: "product.mk",
520 in: `
521ifneq ($(VARIABLE),true)
522endif
523`,
524 expected: `load("//build/make/core:product_config.rbc", "rblf")
525
526def init(g, handle):
527 cfg = rblf.cfg(handle)
528 if g.get("VARIABLE", "") != "true":
529 pass
530`,
531 },
532 {
533 desc: "Const neq",
534 mkname: "product.mk",
535 in: `
536ifneq (1,0)
537endif
538`,
539 expected: `load("//build/make/core:product_config.rbc", "rblf")
540
541def init(g, handle):
542 cfg = rblf.cfg(handle)
543 if "1" != "0":
544 pass
545`,
546 },
547 {
548 desc: "is-board calls",
549 mkname: "product.mk",
550 in: `
551ifeq ($(call is-board-platform-in-list,msm8998), true)
552else ifneq ($(call is-board-platform,copper),true)
553else ifneq ($(call is-vendor-board-platform,QCOM),true)
554else ifeq ($(call is-product-in-list, $(PLATFORM_LIST)), true)
555endif
556`,
557 expected: `load("//build/make/core:product_config.rbc", "rblf")
558
559def init(g, handle):
560 cfg = rblf.cfg(handle)
561 if g.get("TARGET_BOARD_PLATFORM", "") in ["msm8998"]:
562 pass
563 elif g.get("TARGET_BOARD_PLATFORM", "") != "copper":
564 pass
565 elif g.get("TARGET_BOARD_PLATFORM", "") not in g["QCOM_BOARD_PLATFORMS"]:
566 pass
567 elif g["TARGET_PRODUCT"] in g.get("PLATFORM_LIST", []):
568 pass
569`,
570 },
571 {
Sasha Smundak3a9b8e82021-08-25 14:11:04 -0700572 desc: "new is-board calls",
573 mkname: "product.mk",
574 in: `
575ifneq (,$(call is-board-platform-in-list2,msm8998 $(X))
576else ifeq (,$(call is-board-platform2,copper)
577else ifneq (,$(call is-vendor-board-qcom))
578endif
579`,
580 expected: `load("//build/make/core:product_config.rbc", "rblf")
581
582def init(g, handle):
583 cfg = rblf.cfg(handle)
584 if rblf.board_platform_in(g, "msm8998 %s" % g.get("X", "")):
585 pass
586 elif not rblf.board_platform_is(g, "copper"):
587 pass
Sasha Smundak4f1f1182021-11-04 17:57:39 -0700588 elif g.get("TARGET_BOARD_PLATFORM", "") in g["QCOM_BOARD_PLATFORMS"]:
Sasha Smundak3a9b8e82021-08-25 14:11:04 -0700589 pass
590`,
591 },
592 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800593 desc: "findstring call",
594 mkname: "product.mk",
595 in: `
596ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),)
597endif
598`,
599 expected: `load("//build/make/core:product_config.rbc", "rblf")
600
601def init(g, handle):
602 cfg = rblf.cfg(handle)
603 if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1:
604 pass
605`,
606 },
607 {
608 desc: "rhs call",
609 mkname: "product.mk",
610 in: `
611PRODUCT_COPY_FILES = $(call add-to-product-copy-files-if-exists, path:distpath) \
612 $(call find-copy-subdir-files, *, fromdir, todir) $(wildcard foo.*)
613`,
614 expected: `load("//build/make/core:product_config.rbc", "rblf")
615
616def init(g, handle):
617 cfg = rblf.cfg(handle)
618 cfg["PRODUCT_COPY_FILES"] = (rblf.copy_if_exists("path:distpath") +
619 rblf.find_and_copy("*", "fromdir", "todir") +
620 rblf.expand_wildcard("foo.*"))
621`,
622 },
623 {
624 desc: "inferred type",
625 mkname: "product.mk",
626 in: `
627HIKEY_MODS := $(wildcard foo/*.ko)
628BOARD_VENDOR_KERNEL_MODULES += $(HIKEY_MODS)
629`,
630 expected: `load("//build/make/core:product_config.rbc", "rblf")
631
632def init(g, handle):
633 cfg = rblf.cfg(handle)
634 g["HIKEY_MODS"] = rblf.expand_wildcard("foo/*.ko")
635 g.setdefault("BOARD_VENDOR_KERNEL_MODULES", [])
636 g["BOARD_VENDOR_KERNEL_MODULES"] += g["HIKEY_MODS"]
637`,
638 },
639 {
640 desc: "list with vars",
641 mkname: "product.mk",
642 in: `
643PRODUCT_COPY_FILES += path1:$(TARGET_PRODUCT)/path1 $(PRODUCT_MODEL)/path2:$(TARGET_PRODUCT)/path2
644`,
645 expected: `load("//build/make/core:product_config.rbc", "rblf")
646
647def init(g, handle):
648 cfg = rblf.cfg(handle)
649 rblf.setdefault(handle, "PRODUCT_COPY_FILES")
650 cfg["PRODUCT_COPY_FILES"] += (("path1:%s/path1" % g["TARGET_PRODUCT"]).split() +
651 ("%s/path2:%s/path2" % (cfg.get("PRODUCT_MODEL", ""), g["TARGET_PRODUCT"])).split())
652`,
653 },
654 {
655 desc: "misc calls",
656 mkname: "product.mk",
657 in: `
658$(call enforce-product-packages-exist,)
659$(call enforce-product-packages-exist, foo)
660$(call require-artifacts-in-path, foo, bar)
661$(call require-artifacts-in-path-relaxed, foo, bar)
662`,
663 expected: `load("//build/make/core:product_config.rbc", "rblf")
664
665def init(g, handle):
666 cfg = rblf.cfg(handle)
667 rblf.enforce_product_packages_exist("")
668 rblf.enforce_product_packages_exist("foo")
669 rblf.require_artifacts_in_path("foo", "bar")
670 rblf.require_artifacts_in_path_relaxed("foo", "bar")
671`,
672 },
673 {
674 desc: "list with functions",
675 mkname: "product.mk",
676 in: `
677PRODUCT_COPY_FILES := $(call find-copy-subdir-files,*.kl,from1,to1) \
678 $(call find-copy-subdir-files,*.kc,from2,to2) \
679 foo bar
680`,
681 expected: `load("//build/make/core:product_config.rbc", "rblf")
682
683def init(g, handle):
684 cfg = rblf.cfg(handle)
685 cfg["PRODUCT_COPY_FILES"] = (rblf.find_and_copy("*.kl", "from1", "to1") +
686 rblf.find_and_copy("*.kc", "from2", "to2") +
687 [
688 "foo",
689 "bar",
690 ])
691`,
692 },
693 {
694 desc: "Text functions",
695 mkname: "product.mk",
696 in: `
697PRODUCT_COPY_FILES := $(addprefix pfx-,a b c)
698PRODUCT_COPY_FILES := $(addsuffix .sff, a b c)
699PRODUCT_NAME := $(word 1, $(subst ., ,$(TARGET_BOARD_PLATFORM)))
Sasha Smundak35434ed2021-11-05 16:29:56 -0700700$(info $(patsubst %.pub,$(PRODUCT_NAME)%,$(PRODUCT_ADB_KEYS)))
Sasha Smundak16e07732021-07-23 11:38:23 -0700701$(info $(dir foo/bar))
702$(info $(firstword $(PRODUCT_COPY_FILES)))
703$(info $(lastword $(PRODUCT_COPY_FILES)))
704$(info $(dir $(lastword $(MAKEFILE_LIST))))
705$(info $(dir $(lastword $(PRODUCT_COPY_FILES))))
706$(info $(dir $(lastword $(foobar))))
707$(info $(abspath foo/bar))
708$(info $(notdir foo/bar))
Sasha Smundak3deb9682021-07-26 18:42:25 -0700709$(call add_soong_config_namespace,snsconfig)
710$(call add_soong_config_var_value,snsconfig,imagetype,odm_image)
Sasha Smundak65b547e2021-09-17 15:35:41 -0700711$(call soong_config_set, snsconfig, foo, foo_value)
712$(call soong_config_append, snsconfig, bar, bar_value)
Sasha Smundak3deb9682021-07-26 18:42:25 -0700713PRODUCT_COPY_FILES := $(call copy-files,$(wildcard foo*.mk),etc)
Sasha Smundak04453082021-08-17 18:14:41 -0700714PRODUCT_COPY_FILES := $(call product-copy-files-by-pattern,from/%,to/%,a b c)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800715`,
716 expected: `load("//build/make/core:product_config.rbc", "rblf")
717
718def init(g, handle):
719 cfg = rblf.cfg(handle)
720 cfg["PRODUCT_COPY_FILES"] = rblf.addprefix("pfx-", "a b c")
721 cfg["PRODUCT_COPY_FILES"] = rblf.addsuffix(".sff", "a b c")
722 cfg["PRODUCT_NAME"] = ((g.get("TARGET_BOARD_PLATFORM", "")).replace(".", " ")).split()[0]
Sasha Smundak35434ed2021-11-05 16:29:56 -0700723 rblf.mkinfo("product.mk", rblf.mkpatsubst("%.pub", "%s%%" % cfg["PRODUCT_NAME"], g.get("PRODUCT_ADB_KEYS", "")))
Sasha Smundak16e07732021-07-23 11:38:23 -0700724 rblf.mkinfo("product.mk", rblf.dir("foo/bar"))
725 rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][0])
726 rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][-1])
727 rblf.mkinfo("product.mk", rblf.dir("product.mk"))
728 rblf.mkinfo("product.mk", rblf.dir(cfg["PRODUCT_COPY_FILES"][-1]))
729 rblf.mkinfo("product.mk", rblf.dir((_foobar).split()[-1]))
730 rblf.mkinfo("product.mk", rblf.abspath("foo/bar"))
731 rblf.mkinfo("product.mk", rblf.notdir("foo/bar"))
Sasha Smundak65b547e2021-09-17 15:35:41 -0700732 rblf.soong_config_namespace(g, "snsconfig")
733 rblf.soong_config_set(g, "snsconfig", "imagetype", "odm_image")
734 rblf.soong_config_set(g, "snsconfig", "foo", "foo_value")
735 rblf.soong_config_append(g, "snsconfig", "bar", "bar_value")
Sasha Smundak3deb9682021-07-26 18:42:25 -0700736 cfg["PRODUCT_COPY_FILES"] = rblf.copy_files(rblf.expand_wildcard("foo*.mk"), "etc")
Sasha Smundak04453082021-08-17 18:14:41 -0700737 cfg["PRODUCT_COPY_FILES"] = rblf.product_copy_files_by_pattern("from/%", "to/%", "a b c")
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800738`,
739 },
740 {
Sasha Smundak9d011ab2021-07-09 16:00:57 -0700741 desc: "subst in list",
742 mkname: "product.mk",
743 in: `
744files = $(call find-copy-subdir-files,*,from,to)
745PRODUCT_COPY_FILES += $(subst foo,bar,$(files))
746`,
747 expected: `load("//build/make/core:product_config.rbc", "rblf")
748
749def init(g, handle):
750 cfg = rblf.cfg(handle)
751 _files = rblf.find_and_copy("*", "from", "to")
752 rblf.setdefault(handle, "PRODUCT_COPY_FILES")
753 cfg["PRODUCT_COPY_FILES"] += rblf.mksubst("foo", "bar", _files)
754`,
755 },
756 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800757 desc: "assignment flavors",
758 mkname: "product.mk",
759 in: `
760PRODUCT_LIST1 := a
761PRODUCT_LIST2 += a
762PRODUCT_LIST1 += b
763PRODUCT_LIST2 += b
764PRODUCT_LIST3 ?= a
765PRODUCT_LIST1 = c
766PLATFORM_LIST += x
767PRODUCT_PACKAGES := $(PLATFORM_LIST)
768`,
769 expected: `load("//build/make/core:product_config.rbc", "rblf")
770
771def init(g, handle):
772 cfg = rblf.cfg(handle)
773 cfg["PRODUCT_LIST1"] = ["a"]
774 rblf.setdefault(handle, "PRODUCT_LIST2")
775 cfg["PRODUCT_LIST2"] += ["a"]
776 cfg["PRODUCT_LIST1"] += ["b"]
777 cfg["PRODUCT_LIST2"] += ["b"]
778 if cfg.get("PRODUCT_LIST3") == None:
779 cfg["PRODUCT_LIST3"] = ["a"]
780 cfg["PRODUCT_LIST1"] = ["c"]
781 g.setdefault("PLATFORM_LIST", [])
782 g["PLATFORM_LIST"] += ["x"]
783 cfg["PRODUCT_PACKAGES"] = g["PLATFORM_LIST"][:]
784`,
785 },
786 {
787 desc: "assigment flavors2",
788 mkname: "product.mk",
789 in: `
790PRODUCT_LIST1 = a
791ifeq (0,1)
792 PRODUCT_LIST1 += b
793 PRODUCT_LIST2 += b
794endif
795PRODUCT_LIST1 += c
796PRODUCT_LIST2 += c
797`,
798 expected: `load("//build/make/core:product_config.rbc", "rblf")
799
800def init(g, handle):
801 cfg = rblf.cfg(handle)
802 cfg["PRODUCT_LIST1"] = ["a"]
803 if "0" == "1":
804 cfg["PRODUCT_LIST1"] += ["b"]
805 rblf.setdefault(handle, "PRODUCT_LIST2")
806 cfg["PRODUCT_LIST2"] += ["b"]
807 cfg["PRODUCT_LIST1"] += ["c"]
808 rblf.setdefault(handle, "PRODUCT_LIST2")
809 cfg["PRODUCT_LIST2"] += ["c"]
810`,
811 },
812 {
Sasha Smundak3deb9682021-07-26 18:42:25 -0700813 desc: "soong namespace assignments",
814 mkname: "product.mk",
815 in: `
816SOONG_CONFIG_NAMESPACES += cvd
817SOONG_CONFIG_cvd += launch_configs
Sasha Smundak65b547e2021-09-17 15:35:41 -0700818SOONG_CONFIG_cvd_launch_configs = cvd_config_auto.json
Sasha Smundak3deb9682021-07-26 18:42:25 -0700819SOONG_CONFIG_cvd += grub_config
820SOONG_CONFIG_cvd_grub_config += grub.cfg
Sasha Smundak65b547e2021-09-17 15:35:41 -0700821x := $(SOONG_CONFIG_cvd_grub_config)
Sasha Smundak3deb9682021-07-26 18:42:25 -0700822`,
823 expected: `load("//build/make/core:product_config.rbc", "rblf")
824
825def init(g, handle):
826 cfg = rblf.cfg(handle)
Sasha Smundak65b547e2021-09-17 15:35:41 -0700827 rblf.soong_config_namespace(g, "cvd")
828 rblf.soong_config_set(g, "cvd", "launch_configs", "cvd_config_auto.json")
829 rblf.soong_config_append(g, "cvd", "grub_config", "grub.cfg")
Cole Faustc00184e2021-11-08 12:08:57 -0800830 # MK2RBC TRANSLATION ERROR: SOONG_CONFIG_ variables cannot be referenced, use soong_config_get instead: SOONG_CONFIG_cvd_grub_config
Sasha Smundak65b547e2021-09-17 15:35:41 -0700831 # x := $(SOONG_CONFIG_cvd_grub_config)
832 rblf.warning("product.mk", "partially successful conversion")
Sasha Smundak3deb9682021-07-26 18:42:25 -0700833`,
Cole Faustc00184e2021-11-08 12:08:57 -0800834 }, {
835 desc: "soong namespace accesses",
836 mkname: "product.mk",
837 in: `
838SOONG_CONFIG_NAMESPACES += cvd
839SOONG_CONFIG_cvd += launch_configs
840SOONG_CONFIG_cvd_launch_configs = cvd_config_auto.json
841SOONG_CONFIG_cvd += grub_config
842SOONG_CONFIG_cvd_grub_config += grub.cfg
843x := $(call soong_config_get,cvd,grub_config)
844`,
845 expected: `load("//build/make/core:product_config.rbc", "rblf")
846
847def init(g, handle):
848 cfg = rblf.cfg(handle)
849 rblf.soong_config_namespace(g, "cvd")
850 rblf.soong_config_set(g, "cvd", "launch_configs", "cvd_config_auto.json")
851 rblf.soong_config_append(g, "cvd", "grub_config", "grub.cfg")
852 _x = rblf.soong_config_get(g, "cvd", "grub_config")
853`,
Sasha Smundak3deb9682021-07-26 18:42:25 -0700854 },
855 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800856 desc: "string split",
857 mkname: "product.mk",
858 in: `
859PRODUCT_LIST1 = a
860local = b
861local += c
862FOO = d
863FOO += e
864PRODUCT_LIST1 += $(local)
865PRODUCT_LIST1 += $(FOO)
866`,
867 expected: `load("//build/make/core:product_config.rbc", "rblf")
868
869def init(g, handle):
870 cfg = rblf.cfg(handle)
871 cfg["PRODUCT_LIST1"] = ["a"]
872 _local = "b"
873 _local += " " + "c"
874 g["FOO"] = "d"
875 g["FOO"] += " " + "e"
876 cfg["PRODUCT_LIST1"] += (_local).split()
877 cfg["PRODUCT_LIST1"] += (g["FOO"]).split()
878`,
879 },
880 {
881 desc: "apex_jars",
882 mkname: "product.mk",
883 in: `
884PRODUCT_BOOT_JARS := $(ART_APEX_JARS) framework-minus-apex
885`,
886 expected: `load("//build/make/core:product_config.rbc", "rblf")
887
888def init(g, handle):
889 cfg = rblf.cfg(handle)
890 cfg["PRODUCT_BOOT_JARS"] = (g.get("ART_APEX_JARS", []) +
891 ["framework-minus-apex"])
892`,
893 },
894 {
895 desc: "strip function",
896 mkname: "product.mk",
897 in: `
898ifeq ($(filter hwaddress,$(PRODUCT_PACKAGES)),)
899 PRODUCT_PACKAGES := $(strip $(PRODUCT_PACKAGES) hwaddress)
900endif
901`,
902 expected: `load("//build/make/core:product_config.rbc", "rblf")
903
904def init(g, handle):
905 cfg = rblf.cfg(handle)
906 if "hwaddress" not in cfg.get("PRODUCT_PACKAGES", []):
907 cfg["PRODUCT_PACKAGES"] = (rblf.mkstrip("%s hwaddress" % " ".join(cfg.get("PRODUCT_PACKAGES", [])))).split()
908`,
909 },
910 {
911 desc: "strip func in condition",
912 mkname: "product.mk",
913 in: `
914ifneq ($(strip $(TARGET_VENDOR)),)
915endif
916`,
917 expected: `load("//build/make/core:product_config.rbc", "rblf")
918
919def init(g, handle):
920 cfg = rblf.cfg(handle)
Sasha Smundak0554d762021-07-08 18:26:12 -0700921 if rblf.mkstrip(g.get("TARGET_VENDOR", "")):
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800922 pass
923`,
924 },
925 {
926 desc: "ref after set",
927 mkname: "product.mk",
928 in: `
929PRODUCT_ADB_KEYS:=value
930FOO := $(PRODUCT_ADB_KEYS)
931ifneq (,$(PRODUCT_ADB_KEYS))
932endif
933`,
934 expected: `load("//build/make/core:product_config.rbc", "rblf")
935
936def init(g, handle):
937 cfg = rblf.cfg(handle)
938 g["PRODUCT_ADB_KEYS"] = "value"
939 g["FOO"] = g["PRODUCT_ADB_KEYS"]
940 if g["PRODUCT_ADB_KEYS"]:
941 pass
942`,
943 },
944 {
945 desc: "ref before set",
946 mkname: "product.mk",
947 in: `
948V1 := $(PRODUCT_ADB_KEYS)
949ifeq (,$(PRODUCT_ADB_KEYS))
950 V2 := $(PRODUCT_ADB_KEYS)
951 PRODUCT_ADB_KEYS:=foo
952 V3 := $(PRODUCT_ADB_KEYS)
953endif`,
954 expected: `load("//build/make/core:product_config.rbc", "rblf")
955
956def init(g, handle):
957 cfg = rblf.cfg(handle)
958 g["V1"] = g.get("PRODUCT_ADB_KEYS", "")
959 if not g.get("PRODUCT_ADB_KEYS", ""):
960 g["V2"] = g.get("PRODUCT_ADB_KEYS", "")
961 g["PRODUCT_ADB_KEYS"] = "foo"
962 g["V3"] = g["PRODUCT_ADB_KEYS"]
963`,
964 },
Sasha Smundak6609ba72021-07-22 18:32:56 -0700965 {
966 desc: "Dynamic inherit path",
967 mkname: "product.mk",
968 in: `
Sasha Smundak6d852dd2021-09-27 20:34:39 -0700969MY_PATH:=foo
Sasha Smundak6609ba72021-07-22 18:32:56 -0700970$(call inherit-product,vendor/$(MY_PATH)/cfg.mk)
971`,
972 expected: `load("//build/make/core:product_config.rbc", "rblf")
973load("//vendor/foo1:cfg.star|init", _cfg_init = "init")
974load("//vendor/bar/baz:cfg.star|init", _cfg1_init = "init")
975
976def init(g, handle):
977 cfg = rblf.cfg(handle)
978 g["MY_PATH"] = "foo"
979 _entry = {
980 "vendor/foo1/cfg.mk": ("_cfg", _cfg_init),
981 "vendor/bar/baz/cfg.mk": ("_cfg1", _cfg1_init),
982 }.get("vendor/%s/cfg.mk" % g["MY_PATH"])
983 (_varmod, _varmod_init) = _entry if _entry else (None, None)
984 if not _varmod_init:
985 rblf.mkerror("cannot")
986 rblf.inherit(handle, _varmod, _varmod_init)
987`,
988 },
Sasha Smundak6d852dd2021-09-27 20:34:39 -0700989 {
990 desc: "Dynamic inherit with hint",
991 mkname: "product.mk",
992 in: `
993MY_PATH:=foo
994#RBC# include_top vendor/foo1
995$(call inherit-product,$(MY_PATH)/cfg.mk)
996`,
997 expected: `load("//build/make/core:product_config.rbc", "rblf")
998load("//vendor/foo1:cfg.star|init", _cfg_init = "init")
999
1000def init(g, handle):
1001 cfg = rblf.cfg(handle)
1002 g["MY_PATH"] = "foo"
1003 #RBC# include_top vendor/foo1
1004 _entry = {
1005 "vendor/foo1/cfg.mk": ("_cfg", _cfg_init),
1006 }.get("%s/cfg.mk" % g["MY_PATH"])
1007 (_varmod, _varmod_init) = _entry if _entry else (None, None)
1008 if not _varmod_init:
1009 rblf.mkerror("cannot")
1010 rblf.inherit(handle, _varmod, _varmod_init)
1011`,
1012 },
Sasha Smundak2afb9d72021-10-24 15:16:59 -07001013 {
1014 desc: "Ignore make rules",
1015 mkname: "product.mk",
1016 in: `
1017foo: foo.c
1018 gcc -o $@ $*`,
1019 expected: `# MK2RBC TRANSLATION ERROR: unsupported line rule: foo: foo.c
1020#gcc -o $@ $*
1021# rule: foo: foo.c
1022# gcc -o $@ $*
1023load("//build/make/core:product_config.rbc", "rblf")
1024
1025def init(g, handle):
1026 cfg = rblf.cfg(handle)
1027 rblf.warning("product.mk", "partially successful conversion")
1028`,
1029 },
Sasha Smundakea3bc3a2021-11-10 13:06:42 -08001030 {
1031 desc: "Flag override",
1032 mkname: "product.mk",
1033 in: `
1034override FOO:=`,
1035 expected: `# MK2RBC TRANSLATION ERROR: cannot handle override directive
1036# override FOO :=
1037load("//build/make/core:product_config.rbc", "rblf")
1038
1039def init(g, handle):
1040 cfg = rblf.cfg(handle)
1041 g["override FOO"] = ""
1042 rblf.warning("product.mk", "partially successful conversion")
1043`,
1044 },
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001045}
1046
1047var known_variables = []struct {
1048 name string
1049 class varClass
1050 starlarkType
1051}{
1052 {"PRODUCT_NAME", VarClassConfig, starlarkTypeString},
1053 {"PRODUCT_MODEL", VarClassConfig, starlarkTypeString},
1054 {"PRODUCT_PACKAGES", VarClassConfig, starlarkTypeList},
1055 {"PRODUCT_BOOT_JARS", VarClassConfig, starlarkTypeList},
1056 {"PRODUCT_COPY_FILES", VarClassConfig, starlarkTypeList},
1057 {"PRODUCT_IS_64BIT", VarClassConfig, starlarkTypeString},
1058 {"PRODUCT_LIST1", VarClassConfig, starlarkTypeList},
1059 {"PRODUCT_LIST2", VarClassConfig, starlarkTypeList},
1060 {"PRODUCT_LIST3", VarClassConfig, starlarkTypeList},
1061 {"TARGET_PRODUCT", VarClassSoong, starlarkTypeString},
1062 {"TARGET_BUILD_VARIANT", VarClassSoong, starlarkTypeString},
1063 {"TARGET_BOARD_PLATFORM", VarClassSoong, starlarkTypeString},
1064 {"QCOM_BOARD_PLATFORMS", VarClassSoong, starlarkTypeString},
1065 {"PLATFORM_LIST", VarClassSoong, starlarkTypeList}, // TODO(asmundak): make it local instead of soong
1066}
1067
Sasha Smundak6609ba72021-07-22 18:32:56 -07001068type testMakefileFinder struct {
1069 fs fs.FS
1070 root string
1071 files []string
1072}
1073
1074func (t *testMakefileFinder) Find(root string) []string {
1075 if t.files != nil || root == t.root {
1076 return t.files
1077 }
1078 t.files = make([]string, 0)
1079 fs.WalkDir(t.fs, root, func(path string, d fs.DirEntry, err error) error {
1080 if err != nil {
1081 return err
1082 }
1083 if d.IsDir() {
1084 base := filepath.Base(path)
1085 if base[0] == '.' && len(base) > 1 {
1086 return fs.SkipDir
1087 }
1088 return nil
1089 }
1090 if strings.HasSuffix(path, ".mk") {
1091 t.files = append(t.files, path)
1092 }
1093 return nil
1094 })
1095 return t.files
1096}
1097
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001098func TestGood(t *testing.T) {
1099 for _, v := range known_variables {
1100 KnownVariables.NewVariable(v.name, v.class, v.starlarkType)
1101 }
Sasha Smundak6609ba72021-07-22 18:32:56 -07001102 fs := NewFindMockFS([]string{
1103 "vendor/foo1/cfg.mk",
1104 "vendor/bar/baz/cfg.mk",
1105 "part.mk",
1106 "foo/font.mk",
1107 "bar/font.mk",
1108 })
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001109 for _, test := range testCases {
1110 t.Run(test.desc,
1111 func(t *testing.T) {
1112 ss, err := Convert(Request{
1113 MkFile: test.mkname,
1114 Reader: bytes.NewBufferString(test.in),
1115 RootDir: ".",
1116 OutputSuffix: ".star",
1117 WarnPartialSuccess: true,
Sasha Smundak6609ba72021-07-22 18:32:56 -07001118 SourceFS: fs,
1119 MakefileFinder: &testMakefileFinder{fs: fs},
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001120 })
1121 if err != nil {
1122 t.Error(err)
1123 return
1124 }
1125 got := ss.String()
1126 if got != test.expected {
1127 t.Errorf("%q failed\nExpected:\n%s\nActual:\n%s\n", test.desc,
1128 strings.ReplaceAll(test.expected, "\n", "␤\n"),
1129 strings.ReplaceAll(got, "\n", "␤\n"))
1130 }
1131 })
1132 }
1133}