blob: 41c32d1eae504829210bb3b8acbcd8f3e169d6a7 [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 {
Cole Faustf8320212021-11-10 15:05:07 -0800356 desc: "ifeq with soong_config_get",
357 mkname: "product.mk",
358 in: `
359ifeq (true,$(call soong_config_get,art_module,source_build))
360endif
361`,
362 expected: `load("//build/make/core:product_config.rbc", "rblf")
363
364def init(g, handle):
365 cfg = rblf.cfg(handle)
366 if "true" == rblf.soong_config_get(g, "art_module", "source_build"):
367 pass
368`,
369 },
370 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800371 desc: "Check filter result",
372 mkname: "product.mk",
373 in: `
374ifeq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT)))
375endif
376ifneq (,$(filter userdebug,$(TARGET_BUILD_VARIANT))
377endif
378ifneq (,$(filter plaf,$(PLATFORM_LIST)))
379endif
380ifeq ($(TARGET_BUILD_VARIANT), $(filter $(TARGET_BUILD_VARIANT), userdebug eng))
381endif
Sasha Smundak0554d762021-07-08 18:26:12 -0700382ifneq (,$(filter true, $(v1)$(v2)))
383endif
Sasha Smundak5f463be2021-09-15 18:43:36 -0700384ifeq (,$(filter barbet coral%,$(TARGET_PRODUCT)))
385else ifneq (,$(filter barbet%,$(TARGET_PRODUCT)))
386endif
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800387`,
388 expected: `load("//build/make/core:product_config.rbc", "rblf")
389
390def init(g, handle):
391 cfg = rblf.cfg(handle)
Sasha Smundak5f463be2021-09-15 18:43:36 -0700392 if not rblf.filter("userdebug eng", g["TARGET_BUILD_VARIANT"]):
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800393 pass
Sasha Smundak5f463be2021-09-15 18:43:36 -0700394 if rblf.filter("userdebug", g["TARGET_BUILD_VARIANT"]):
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800395 pass
396 if "plaf" in g.get("PLATFORM_LIST", []):
397 pass
398 if g["TARGET_BUILD_VARIANT"] in ["userdebug", "eng"]:
399 pass
Sasha Smundak5f463be2021-09-15 18:43:36 -0700400 if rblf.filter("true", "%s%s" % (_v1, _v2)):
401 pass
402 if not rblf.filter("barbet coral%", g["TARGET_PRODUCT"]):
403 pass
404 elif rblf.filter("barbet%", g["TARGET_PRODUCT"]):
Sasha Smundak0554d762021-07-08 18:26:12 -0700405 pass
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800406`,
407 },
408 {
409 desc: "Get filter result",
410 mkname: "product.mk",
411 in: `
412PRODUCT_LIST2=$(filter-out %/foo.ko,$(wildcard path/*.ko))
413`,
414 expected: `load("//build/make/core:product_config.rbc", "rblf")
415
416def init(g, handle):
417 cfg = rblf.cfg(handle)
418 cfg["PRODUCT_LIST2"] = rblf.filter_out("%/foo.ko", rblf.expand_wildcard("path/*.ko"))
419`,
420 },
421 {
422 desc: "filter $(VAR), values",
423 mkname: "product.mk",
424 in: `
425ifeq (,$(filter $(TARGET_PRODUCT), yukawa_gms yukawa_sei510_gms)
426 ifneq (,$(filter $(TARGET_PRODUCT), yukawa_gms)
427 endif
428endif
429
430`,
431 expected: `load("//build/make/core:product_config.rbc", "rblf")
432
433def init(g, handle):
434 cfg = rblf.cfg(handle)
435 if g["TARGET_PRODUCT"] not in ["yukawa_gms", "yukawa_sei510_gms"]:
Sasha Smundak0554d762021-07-08 18:26:12 -0700436 if g["TARGET_PRODUCT"] == "yukawa_gms":
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800437 pass
438`,
439 },
440 {
Sasha Smundak0554d762021-07-08 18:26:12 -0700441 desc: "filter $(V1), $(V2)",
442 mkname: "product.mk",
443 in: `
444ifneq (, $(filter $(PRODUCT_LIST), $(TARGET_PRODUCT)))
445endif
446`,
447 expected: `load("//build/make/core:product_config.rbc", "rblf")
448
449def init(g, handle):
450 cfg = rblf.cfg(handle)
Sasha Smundak468e11f2021-08-26 09:10:23 -0700451 if rblf.filter(g.get("PRODUCT_LIST", []), g["TARGET_PRODUCT"]):
Sasha Smundak0554d762021-07-08 18:26:12 -0700452 pass
453`,
454 },
455 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800456 desc: "ifeq",
457 mkname: "product.mk",
458 in: `
459ifeq (aosp, $(TARGET_PRODUCT)) # Comment
460else ifneq (, $(TARGET_PRODUCT))
461endif
462`,
463 expected: `load("//build/make/core:product_config.rbc", "rblf")
464
465def init(g, handle):
466 cfg = rblf.cfg(handle)
467 if "aosp" == g["TARGET_PRODUCT"]:
468 # Comment
469 pass
470 elif g["TARGET_PRODUCT"]:
471 pass
472`,
473 },
474 {
475 desc: "Nested if",
476 mkname: "product.mk",
477 in: `
478ifdef PRODUCT_NAME
479 PRODUCT_PACKAGES = pack-if0
480 ifdef PRODUCT_MODEL
481 PRODUCT_PACKAGES = pack-if-if
482 else ifdef PRODUCT_NAME
483 PRODUCT_PACKAGES = pack-if-elif
484 else
485 PRODUCT_PACKAGES = pack-if-else
486 endif
487 PRODUCT_PACKAGES = pack-if
488else ifneq (,$(TARGET_PRODUCT))
489 PRODUCT_PACKAGES = pack-elif
490else
491 PRODUCT_PACKAGES = pack-else
492endif
493`,
494 expected: `load("//build/make/core:product_config.rbc", "rblf")
495
496def init(g, handle):
497 cfg = rblf.cfg(handle)
498 if g.get("PRODUCT_NAME") != None:
499 cfg["PRODUCT_PACKAGES"] = ["pack-if0"]
500 if g.get("PRODUCT_MODEL") != None:
501 cfg["PRODUCT_PACKAGES"] = ["pack-if-if"]
502 elif g.get("PRODUCT_NAME") != None:
503 cfg["PRODUCT_PACKAGES"] = ["pack-if-elif"]
504 else:
505 cfg["PRODUCT_PACKAGES"] = ["pack-if-else"]
506 cfg["PRODUCT_PACKAGES"] = ["pack-if"]
507 elif g["TARGET_PRODUCT"]:
508 cfg["PRODUCT_PACKAGES"] = ["pack-elif"]
509 else:
510 cfg["PRODUCT_PACKAGES"] = ["pack-else"]
511`,
512 },
513 {
514 desc: "Wildcard",
515 mkname: "product.mk",
516 in: `
517ifeq (,$(wildcard foo.mk))
518endif
519ifneq (,$(wildcard foo*.mk))
520endif
521`,
522 expected: `load("//build/make/core:product_config.rbc", "rblf")
523
524def init(g, handle):
525 cfg = rblf.cfg(handle)
526 if not rblf.file_exists("foo.mk"):
527 pass
528 if rblf.file_wildcard_exists("foo*.mk"):
529 pass
530`,
531 },
532 {
Cole Faustf8320212021-11-10 15:05:07 -0800533 desc: "if with interpolation",
534 mkname: "product.mk",
535 in: `
536ifeq ($(VARIABLE1)text$(VARIABLE2),true)
537endif
538`,
539 expected: `load("//build/make/core:product_config.rbc", "rblf")
540
541def init(g, handle):
542 cfg = rblf.cfg(handle)
543 if "%stext%s" % (g.get("VARIABLE1", ""), g.get("VARIABLE2", "")) == "true":
544 pass
545`,
546 },
547 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800548 desc: "ifneq $(X),true",
549 mkname: "product.mk",
550 in: `
551ifneq ($(VARIABLE),true)
552endif
553`,
554 expected: `load("//build/make/core:product_config.rbc", "rblf")
555
556def init(g, handle):
557 cfg = rblf.cfg(handle)
558 if g.get("VARIABLE", "") != "true":
559 pass
560`,
561 },
562 {
563 desc: "Const neq",
564 mkname: "product.mk",
565 in: `
566ifneq (1,0)
567endif
568`,
569 expected: `load("//build/make/core:product_config.rbc", "rblf")
570
571def init(g, handle):
572 cfg = rblf.cfg(handle)
573 if "1" != "0":
574 pass
575`,
576 },
577 {
578 desc: "is-board calls",
579 mkname: "product.mk",
580 in: `
581ifeq ($(call is-board-platform-in-list,msm8998), true)
582else ifneq ($(call is-board-platform,copper),true)
583else ifneq ($(call is-vendor-board-platform,QCOM),true)
584else ifeq ($(call is-product-in-list, $(PLATFORM_LIST)), true)
585endif
586`,
587 expected: `load("//build/make/core:product_config.rbc", "rblf")
588
589def init(g, handle):
590 cfg = rblf.cfg(handle)
591 if g.get("TARGET_BOARD_PLATFORM", "") in ["msm8998"]:
592 pass
593 elif g.get("TARGET_BOARD_PLATFORM", "") != "copper":
594 pass
595 elif g.get("TARGET_BOARD_PLATFORM", "") not in g["QCOM_BOARD_PLATFORMS"]:
596 pass
597 elif g["TARGET_PRODUCT"] in g.get("PLATFORM_LIST", []):
598 pass
599`,
600 },
601 {
Sasha Smundak3a9b8e82021-08-25 14:11:04 -0700602 desc: "new is-board calls",
603 mkname: "product.mk",
604 in: `
605ifneq (,$(call is-board-platform-in-list2,msm8998 $(X))
606else ifeq (,$(call is-board-platform2,copper)
607else ifneq (,$(call is-vendor-board-qcom))
608endif
609`,
610 expected: `load("//build/make/core:product_config.rbc", "rblf")
611
612def init(g, handle):
613 cfg = rblf.cfg(handle)
614 if rblf.board_platform_in(g, "msm8998 %s" % g.get("X", "")):
615 pass
616 elif not rblf.board_platform_is(g, "copper"):
617 pass
Sasha Smundak4f1f1182021-11-04 17:57:39 -0700618 elif g.get("TARGET_BOARD_PLATFORM", "") in g["QCOM_BOARD_PLATFORMS"]:
Sasha Smundak3a9b8e82021-08-25 14:11:04 -0700619 pass
620`,
621 },
622 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800623 desc: "findstring call",
624 mkname: "product.mk",
625 in: `
626ifneq ($(findstring foo,$(PRODUCT_PACKAGES)),)
627endif
628`,
629 expected: `load("//build/make/core:product_config.rbc", "rblf")
630
631def init(g, handle):
632 cfg = rblf.cfg(handle)
633 if (cfg.get("PRODUCT_PACKAGES", [])).find("foo") != -1:
634 pass
635`,
636 },
637 {
638 desc: "rhs call",
639 mkname: "product.mk",
640 in: `
641PRODUCT_COPY_FILES = $(call add-to-product-copy-files-if-exists, path:distpath) \
642 $(call find-copy-subdir-files, *, fromdir, todir) $(wildcard foo.*)
643`,
644 expected: `load("//build/make/core:product_config.rbc", "rblf")
645
646def init(g, handle):
647 cfg = rblf.cfg(handle)
648 cfg["PRODUCT_COPY_FILES"] = (rblf.copy_if_exists("path:distpath") +
649 rblf.find_and_copy("*", "fromdir", "todir") +
650 rblf.expand_wildcard("foo.*"))
651`,
652 },
653 {
654 desc: "inferred type",
655 mkname: "product.mk",
656 in: `
657HIKEY_MODS := $(wildcard foo/*.ko)
658BOARD_VENDOR_KERNEL_MODULES += $(HIKEY_MODS)
659`,
660 expected: `load("//build/make/core:product_config.rbc", "rblf")
661
662def init(g, handle):
663 cfg = rblf.cfg(handle)
664 g["HIKEY_MODS"] = rblf.expand_wildcard("foo/*.ko")
665 g.setdefault("BOARD_VENDOR_KERNEL_MODULES", [])
666 g["BOARD_VENDOR_KERNEL_MODULES"] += g["HIKEY_MODS"]
667`,
668 },
669 {
670 desc: "list with vars",
671 mkname: "product.mk",
672 in: `
673PRODUCT_COPY_FILES += path1:$(TARGET_PRODUCT)/path1 $(PRODUCT_MODEL)/path2:$(TARGET_PRODUCT)/path2
674`,
675 expected: `load("//build/make/core:product_config.rbc", "rblf")
676
677def init(g, handle):
678 cfg = rblf.cfg(handle)
679 rblf.setdefault(handle, "PRODUCT_COPY_FILES")
680 cfg["PRODUCT_COPY_FILES"] += (("path1:%s/path1" % g["TARGET_PRODUCT"]).split() +
681 ("%s/path2:%s/path2" % (cfg.get("PRODUCT_MODEL", ""), g["TARGET_PRODUCT"])).split())
682`,
683 },
684 {
685 desc: "misc calls",
686 mkname: "product.mk",
687 in: `
688$(call enforce-product-packages-exist,)
689$(call enforce-product-packages-exist, foo)
690$(call require-artifacts-in-path, foo, bar)
691$(call require-artifacts-in-path-relaxed, foo, bar)
Sasha Smundakd6797852021-11-15 13:01:53 -0800692$(call dist-for-goals, goal, from:to)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800693`,
694 expected: `load("//build/make/core:product_config.rbc", "rblf")
695
696def init(g, handle):
697 cfg = rblf.cfg(handle)
698 rblf.enforce_product_packages_exist("")
699 rblf.enforce_product_packages_exist("foo")
700 rblf.require_artifacts_in_path("foo", "bar")
701 rblf.require_artifacts_in_path_relaxed("foo", "bar")
Sasha Smundakd6797852021-11-15 13:01:53 -0800702 rblf.mkdist_for_goals(g, "goal", "from:to")
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800703`,
704 },
705 {
706 desc: "list with functions",
707 mkname: "product.mk",
708 in: `
709PRODUCT_COPY_FILES := $(call find-copy-subdir-files,*.kl,from1,to1) \
710 $(call find-copy-subdir-files,*.kc,from2,to2) \
711 foo bar
712`,
713 expected: `load("//build/make/core:product_config.rbc", "rblf")
714
715def init(g, handle):
716 cfg = rblf.cfg(handle)
717 cfg["PRODUCT_COPY_FILES"] = (rblf.find_and_copy("*.kl", "from1", "to1") +
718 rblf.find_and_copy("*.kc", "from2", "to2") +
719 [
720 "foo",
721 "bar",
722 ])
723`,
724 },
725 {
726 desc: "Text functions",
727 mkname: "product.mk",
728 in: `
729PRODUCT_COPY_FILES := $(addprefix pfx-,a b c)
730PRODUCT_COPY_FILES := $(addsuffix .sff, a b c)
731PRODUCT_NAME := $(word 1, $(subst ., ,$(TARGET_BOARD_PLATFORM)))
Sasha Smundak35434ed2021-11-05 16:29:56 -0700732$(info $(patsubst %.pub,$(PRODUCT_NAME)%,$(PRODUCT_ADB_KEYS)))
Sasha Smundak16e07732021-07-23 11:38:23 -0700733$(info $(dir foo/bar))
734$(info $(firstword $(PRODUCT_COPY_FILES)))
735$(info $(lastword $(PRODUCT_COPY_FILES)))
736$(info $(dir $(lastword $(MAKEFILE_LIST))))
737$(info $(dir $(lastword $(PRODUCT_COPY_FILES))))
738$(info $(dir $(lastword $(foobar))))
739$(info $(abspath foo/bar))
740$(info $(notdir foo/bar))
Sasha Smundak3deb9682021-07-26 18:42:25 -0700741$(call add_soong_config_namespace,snsconfig)
742$(call add_soong_config_var_value,snsconfig,imagetype,odm_image)
Sasha Smundak65b547e2021-09-17 15:35:41 -0700743$(call soong_config_set, snsconfig, foo, foo_value)
744$(call soong_config_append, snsconfig, bar, bar_value)
Sasha Smundak3deb9682021-07-26 18:42:25 -0700745PRODUCT_COPY_FILES := $(call copy-files,$(wildcard foo*.mk),etc)
Sasha Smundak04453082021-08-17 18:14:41 -0700746PRODUCT_COPY_FILES := $(call product-copy-files-by-pattern,from/%,to/%,a b c)
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800747`,
748 expected: `load("//build/make/core:product_config.rbc", "rblf")
749
750def init(g, handle):
751 cfg = rblf.cfg(handle)
752 cfg["PRODUCT_COPY_FILES"] = rblf.addprefix("pfx-", "a b c")
753 cfg["PRODUCT_COPY_FILES"] = rblf.addsuffix(".sff", "a b c")
754 cfg["PRODUCT_NAME"] = ((g.get("TARGET_BOARD_PLATFORM", "")).replace(".", " ")).split()[0]
Sasha Smundak35434ed2021-11-05 16:29:56 -0700755 rblf.mkinfo("product.mk", rblf.mkpatsubst("%.pub", "%s%%" % cfg["PRODUCT_NAME"], g.get("PRODUCT_ADB_KEYS", "")))
Sasha Smundak16e07732021-07-23 11:38:23 -0700756 rblf.mkinfo("product.mk", rblf.dir("foo/bar"))
757 rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][0])
758 rblf.mkinfo("product.mk", cfg["PRODUCT_COPY_FILES"][-1])
759 rblf.mkinfo("product.mk", rblf.dir("product.mk"))
760 rblf.mkinfo("product.mk", rblf.dir(cfg["PRODUCT_COPY_FILES"][-1]))
761 rblf.mkinfo("product.mk", rblf.dir((_foobar).split()[-1]))
762 rblf.mkinfo("product.mk", rblf.abspath("foo/bar"))
763 rblf.mkinfo("product.mk", rblf.notdir("foo/bar"))
Sasha Smundak65b547e2021-09-17 15:35:41 -0700764 rblf.soong_config_namespace(g, "snsconfig")
765 rblf.soong_config_set(g, "snsconfig", "imagetype", "odm_image")
766 rblf.soong_config_set(g, "snsconfig", "foo", "foo_value")
767 rblf.soong_config_append(g, "snsconfig", "bar", "bar_value")
Sasha Smundak3deb9682021-07-26 18:42:25 -0700768 cfg["PRODUCT_COPY_FILES"] = rblf.copy_files(rblf.expand_wildcard("foo*.mk"), "etc")
Sasha Smundak04453082021-08-17 18:14:41 -0700769 cfg["PRODUCT_COPY_FILES"] = rblf.product_copy_files_by_pattern("from/%", "to/%", "a b c")
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800770`,
771 },
772 {
Sasha Smundak9d011ab2021-07-09 16:00:57 -0700773 desc: "subst in list",
774 mkname: "product.mk",
775 in: `
776files = $(call find-copy-subdir-files,*,from,to)
777PRODUCT_COPY_FILES += $(subst foo,bar,$(files))
778`,
779 expected: `load("//build/make/core:product_config.rbc", "rblf")
780
781def init(g, handle):
782 cfg = rblf.cfg(handle)
783 _files = rblf.find_and_copy("*", "from", "to")
784 rblf.setdefault(handle, "PRODUCT_COPY_FILES")
785 cfg["PRODUCT_COPY_FILES"] += rblf.mksubst("foo", "bar", _files)
786`,
787 },
788 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800789 desc: "assignment flavors",
790 mkname: "product.mk",
791 in: `
792PRODUCT_LIST1 := a
793PRODUCT_LIST2 += a
794PRODUCT_LIST1 += b
795PRODUCT_LIST2 += b
796PRODUCT_LIST3 ?= a
797PRODUCT_LIST1 = c
798PLATFORM_LIST += x
799PRODUCT_PACKAGES := $(PLATFORM_LIST)
800`,
801 expected: `load("//build/make/core:product_config.rbc", "rblf")
802
803def init(g, handle):
804 cfg = rblf.cfg(handle)
805 cfg["PRODUCT_LIST1"] = ["a"]
806 rblf.setdefault(handle, "PRODUCT_LIST2")
807 cfg["PRODUCT_LIST2"] += ["a"]
808 cfg["PRODUCT_LIST1"] += ["b"]
809 cfg["PRODUCT_LIST2"] += ["b"]
810 if cfg.get("PRODUCT_LIST3") == None:
811 cfg["PRODUCT_LIST3"] = ["a"]
812 cfg["PRODUCT_LIST1"] = ["c"]
813 g.setdefault("PLATFORM_LIST", [])
814 g["PLATFORM_LIST"] += ["x"]
815 cfg["PRODUCT_PACKAGES"] = g["PLATFORM_LIST"][:]
816`,
817 },
818 {
819 desc: "assigment flavors2",
820 mkname: "product.mk",
821 in: `
822PRODUCT_LIST1 = a
823ifeq (0,1)
824 PRODUCT_LIST1 += b
825 PRODUCT_LIST2 += b
826endif
827PRODUCT_LIST1 += c
828PRODUCT_LIST2 += c
829`,
830 expected: `load("//build/make/core:product_config.rbc", "rblf")
831
832def init(g, handle):
833 cfg = rblf.cfg(handle)
834 cfg["PRODUCT_LIST1"] = ["a"]
835 if "0" == "1":
836 cfg["PRODUCT_LIST1"] += ["b"]
837 rblf.setdefault(handle, "PRODUCT_LIST2")
838 cfg["PRODUCT_LIST2"] += ["b"]
839 cfg["PRODUCT_LIST1"] += ["c"]
840 rblf.setdefault(handle, "PRODUCT_LIST2")
841 cfg["PRODUCT_LIST2"] += ["c"]
842`,
843 },
844 {
Sasha Smundak3deb9682021-07-26 18:42:25 -0700845 desc: "soong namespace assignments",
846 mkname: "product.mk",
847 in: `
848SOONG_CONFIG_NAMESPACES += cvd
849SOONG_CONFIG_cvd += launch_configs
Sasha Smundak65b547e2021-09-17 15:35:41 -0700850SOONG_CONFIG_cvd_launch_configs = cvd_config_auto.json
Sasha Smundak3deb9682021-07-26 18:42:25 -0700851SOONG_CONFIG_cvd += grub_config
852SOONG_CONFIG_cvd_grub_config += grub.cfg
Sasha Smundak65b547e2021-09-17 15:35:41 -0700853x := $(SOONG_CONFIG_cvd_grub_config)
Sasha Smundak3deb9682021-07-26 18:42:25 -0700854`,
855 expected: `load("//build/make/core:product_config.rbc", "rblf")
856
857def init(g, handle):
858 cfg = rblf.cfg(handle)
Sasha Smundak65b547e2021-09-17 15:35:41 -0700859 rblf.soong_config_namespace(g, "cvd")
860 rblf.soong_config_set(g, "cvd", "launch_configs", "cvd_config_auto.json")
861 rblf.soong_config_append(g, "cvd", "grub_config", "grub.cfg")
Cole Faustc00184e2021-11-08 12:08:57 -0800862 # 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 -0700863 # x := $(SOONG_CONFIG_cvd_grub_config)
864 rblf.warning("product.mk", "partially successful conversion")
Sasha Smundak3deb9682021-07-26 18:42:25 -0700865`,
Cole Faustc00184e2021-11-08 12:08:57 -0800866 }, {
867 desc: "soong namespace accesses",
868 mkname: "product.mk",
869 in: `
870SOONG_CONFIG_NAMESPACES += cvd
871SOONG_CONFIG_cvd += launch_configs
872SOONG_CONFIG_cvd_launch_configs = cvd_config_auto.json
873SOONG_CONFIG_cvd += grub_config
874SOONG_CONFIG_cvd_grub_config += grub.cfg
875x := $(call soong_config_get,cvd,grub_config)
876`,
877 expected: `load("//build/make/core:product_config.rbc", "rblf")
878
879def init(g, handle):
880 cfg = rblf.cfg(handle)
881 rblf.soong_config_namespace(g, "cvd")
882 rblf.soong_config_set(g, "cvd", "launch_configs", "cvd_config_auto.json")
883 rblf.soong_config_append(g, "cvd", "grub_config", "grub.cfg")
884 _x = rblf.soong_config_get(g, "cvd", "grub_config")
885`,
Sasha Smundak3deb9682021-07-26 18:42:25 -0700886 },
887 {
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800888 desc: "string split",
889 mkname: "product.mk",
890 in: `
891PRODUCT_LIST1 = a
892local = b
893local += c
894FOO = d
895FOO += e
896PRODUCT_LIST1 += $(local)
897PRODUCT_LIST1 += $(FOO)
898`,
899 expected: `load("//build/make/core:product_config.rbc", "rblf")
900
901def init(g, handle):
902 cfg = rblf.cfg(handle)
903 cfg["PRODUCT_LIST1"] = ["a"]
904 _local = "b"
905 _local += " " + "c"
906 g["FOO"] = "d"
907 g["FOO"] += " " + "e"
908 cfg["PRODUCT_LIST1"] += (_local).split()
909 cfg["PRODUCT_LIST1"] += (g["FOO"]).split()
910`,
911 },
912 {
913 desc: "apex_jars",
914 mkname: "product.mk",
915 in: `
916PRODUCT_BOOT_JARS := $(ART_APEX_JARS) framework-minus-apex
917`,
918 expected: `load("//build/make/core:product_config.rbc", "rblf")
919
920def init(g, handle):
921 cfg = rblf.cfg(handle)
922 cfg["PRODUCT_BOOT_JARS"] = (g.get("ART_APEX_JARS", []) +
923 ["framework-minus-apex"])
924`,
925 },
926 {
927 desc: "strip function",
928 mkname: "product.mk",
929 in: `
930ifeq ($(filter hwaddress,$(PRODUCT_PACKAGES)),)
931 PRODUCT_PACKAGES := $(strip $(PRODUCT_PACKAGES) hwaddress)
932endif
933`,
934 expected: `load("//build/make/core:product_config.rbc", "rblf")
935
936def init(g, handle):
937 cfg = rblf.cfg(handle)
938 if "hwaddress" not in cfg.get("PRODUCT_PACKAGES", []):
939 cfg["PRODUCT_PACKAGES"] = (rblf.mkstrip("%s hwaddress" % " ".join(cfg.get("PRODUCT_PACKAGES", [])))).split()
940`,
941 },
942 {
943 desc: "strip func in condition",
944 mkname: "product.mk",
945 in: `
946ifneq ($(strip $(TARGET_VENDOR)),)
947endif
948`,
949 expected: `load("//build/make/core:product_config.rbc", "rblf")
950
951def init(g, handle):
952 cfg = rblf.cfg(handle)
Sasha Smundak0554d762021-07-08 18:26:12 -0700953 if rblf.mkstrip(g.get("TARGET_VENDOR", "")):
Sasha Smundakb051c4e2020-11-05 20:45:07 -0800954 pass
955`,
956 },
957 {
958 desc: "ref after set",
959 mkname: "product.mk",
960 in: `
961PRODUCT_ADB_KEYS:=value
962FOO := $(PRODUCT_ADB_KEYS)
963ifneq (,$(PRODUCT_ADB_KEYS))
964endif
965`,
966 expected: `load("//build/make/core:product_config.rbc", "rblf")
967
968def init(g, handle):
969 cfg = rblf.cfg(handle)
970 g["PRODUCT_ADB_KEYS"] = "value"
971 g["FOO"] = g["PRODUCT_ADB_KEYS"]
972 if g["PRODUCT_ADB_KEYS"]:
973 pass
974`,
975 },
976 {
977 desc: "ref before set",
978 mkname: "product.mk",
979 in: `
980V1 := $(PRODUCT_ADB_KEYS)
981ifeq (,$(PRODUCT_ADB_KEYS))
982 V2 := $(PRODUCT_ADB_KEYS)
983 PRODUCT_ADB_KEYS:=foo
984 V3 := $(PRODUCT_ADB_KEYS)
985endif`,
986 expected: `load("//build/make/core:product_config.rbc", "rblf")
987
988def init(g, handle):
989 cfg = rblf.cfg(handle)
990 g["V1"] = g.get("PRODUCT_ADB_KEYS", "")
991 if not g.get("PRODUCT_ADB_KEYS", ""):
992 g["V2"] = g.get("PRODUCT_ADB_KEYS", "")
993 g["PRODUCT_ADB_KEYS"] = "foo"
994 g["V3"] = g["PRODUCT_ADB_KEYS"]
995`,
996 },
Sasha Smundak6609ba72021-07-22 18:32:56 -0700997 {
998 desc: "Dynamic inherit path",
999 mkname: "product.mk",
1000 in: `
Sasha Smundak6d852dd2021-09-27 20:34:39 -07001001MY_PATH:=foo
Sasha Smundak6609ba72021-07-22 18:32:56 -07001002$(call inherit-product,vendor/$(MY_PATH)/cfg.mk)
1003`,
1004 expected: `load("//build/make/core:product_config.rbc", "rblf")
1005load("//vendor/foo1:cfg.star|init", _cfg_init = "init")
1006load("//vendor/bar/baz:cfg.star|init", _cfg1_init = "init")
1007
1008def init(g, handle):
1009 cfg = rblf.cfg(handle)
1010 g["MY_PATH"] = "foo"
1011 _entry = {
1012 "vendor/foo1/cfg.mk": ("_cfg", _cfg_init),
1013 "vendor/bar/baz/cfg.mk": ("_cfg1", _cfg1_init),
1014 }.get("vendor/%s/cfg.mk" % g["MY_PATH"])
1015 (_varmod, _varmod_init) = _entry if _entry else (None, None)
1016 if not _varmod_init:
1017 rblf.mkerror("cannot")
1018 rblf.inherit(handle, _varmod, _varmod_init)
1019`,
1020 },
Sasha Smundak6d852dd2021-09-27 20:34:39 -07001021 {
1022 desc: "Dynamic inherit with hint",
1023 mkname: "product.mk",
1024 in: `
1025MY_PATH:=foo
1026#RBC# include_top vendor/foo1
1027$(call inherit-product,$(MY_PATH)/cfg.mk)
1028`,
1029 expected: `load("//build/make/core:product_config.rbc", "rblf")
1030load("//vendor/foo1:cfg.star|init", _cfg_init = "init")
1031
1032def init(g, handle):
1033 cfg = rblf.cfg(handle)
1034 g["MY_PATH"] = "foo"
1035 #RBC# include_top vendor/foo1
1036 _entry = {
1037 "vendor/foo1/cfg.mk": ("_cfg", _cfg_init),
1038 }.get("%s/cfg.mk" % g["MY_PATH"])
1039 (_varmod, _varmod_init) = _entry if _entry else (None, None)
1040 if not _varmod_init:
1041 rblf.mkerror("cannot")
1042 rblf.inherit(handle, _varmod, _varmod_init)
1043`,
1044 },
Sasha Smundak2afb9d72021-10-24 15:16:59 -07001045 {
1046 desc: "Ignore make rules",
1047 mkname: "product.mk",
1048 in: `
1049foo: foo.c
1050 gcc -o $@ $*`,
1051 expected: `# MK2RBC TRANSLATION ERROR: unsupported line rule: foo: foo.c
1052#gcc -o $@ $*
1053# rule: foo: foo.c
1054# gcc -o $@ $*
1055load("//build/make/core:product_config.rbc", "rblf")
1056
1057def init(g, handle):
1058 cfg = rblf.cfg(handle)
1059 rblf.warning("product.mk", "partially successful conversion")
1060`,
1061 },
Sasha Smundakea3bc3a2021-11-10 13:06:42 -08001062 {
1063 desc: "Flag override",
1064 mkname: "product.mk",
1065 in: `
1066override FOO:=`,
1067 expected: `# MK2RBC TRANSLATION ERROR: cannot handle override directive
1068# override FOO :=
1069load("//build/make/core:product_config.rbc", "rblf")
1070
1071def init(g, handle):
1072 cfg = rblf.cfg(handle)
1073 g["override FOO"] = ""
1074 rblf.warning("product.mk", "partially successful conversion")
1075`,
1076 },
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001077}
1078
1079var known_variables = []struct {
1080 name string
1081 class varClass
1082 starlarkType
1083}{
1084 {"PRODUCT_NAME", VarClassConfig, starlarkTypeString},
1085 {"PRODUCT_MODEL", VarClassConfig, starlarkTypeString},
1086 {"PRODUCT_PACKAGES", VarClassConfig, starlarkTypeList},
1087 {"PRODUCT_BOOT_JARS", VarClassConfig, starlarkTypeList},
1088 {"PRODUCT_COPY_FILES", VarClassConfig, starlarkTypeList},
1089 {"PRODUCT_IS_64BIT", VarClassConfig, starlarkTypeString},
1090 {"PRODUCT_LIST1", VarClassConfig, starlarkTypeList},
1091 {"PRODUCT_LIST2", VarClassConfig, starlarkTypeList},
1092 {"PRODUCT_LIST3", VarClassConfig, starlarkTypeList},
1093 {"TARGET_PRODUCT", VarClassSoong, starlarkTypeString},
1094 {"TARGET_BUILD_VARIANT", VarClassSoong, starlarkTypeString},
1095 {"TARGET_BOARD_PLATFORM", VarClassSoong, starlarkTypeString},
1096 {"QCOM_BOARD_PLATFORMS", VarClassSoong, starlarkTypeString},
1097 {"PLATFORM_LIST", VarClassSoong, starlarkTypeList}, // TODO(asmundak): make it local instead of soong
1098}
1099
Sasha Smundak6609ba72021-07-22 18:32:56 -07001100type testMakefileFinder struct {
1101 fs fs.FS
1102 root string
1103 files []string
1104}
1105
1106func (t *testMakefileFinder) Find(root string) []string {
1107 if t.files != nil || root == t.root {
1108 return t.files
1109 }
1110 t.files = make([]string, 0)
1111 fs.WalkDir(t.fs, root, func(path string, d fs.DirEntry, err error) error {
1112 if err != nil {
1113 return err
1114 }
1115 if d.IsDir() {
1116 base := filepath.Base(path)
1117 if base[0] == '.' && len(base) > 1 {
1118 return fs.SkipDir
1119 }
1120 return nil
1121 }
1122 if strings.HasSuffix(path, ".mk") {
1123 t.files = append(t.files, path)
1124 }
1125 return nil
1126 })
1127 return t.files
1128}
1129
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001130func TestGood(t *testing.T) {
1131 for _, v := range known_variables {
1132 KnownVariables.NewVariable(v.name, v.class, v.starlarkType)
1133 }
Sasha Smundak6609ba72021-07-22 18:32:56 -07001134 fs := NewFindMockFS([]string{
1135 "vendor/foo1/cfg.mk",
1136 "vendor/bar/baz/cfg.mk",
1137 "part.mk",
1138 "foo/font.mk",
1139 "bar/font.mk",
1140 })
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001141 for _, test := range testCases {
1142 t.Run(test.desc,
1143 func(t *testing.T) {
1144 ss, err := Convert(Request{
1145 MkFile: test.mkname,
1146 Reader: bytes.NewBufferString(test.in),
1147 RootDir: ".",
1148 OutputSuffix: ".star",
1149 WarnPartialSuccess: true,
Sasha Smundak6609ba72021-07-22 18:32:56 -07001150 SourceFS: fs,
1151 MakefileFinder: &testMakefileFinder{fs: fs},
Sasha Smundakb051c4e2020-11-05 20:45:07 -08001152 })
1153 if err != nil {
1154 t.Error(err)
1155 return
1156 }
1157 got := ss.String()
1158 if got != test.expected {
1159 t.Errorf("%q failed\nExpected:\n%s\nActual:\n%s\n", test.desc,
1160 strings.ReplaceAll(test.expected, "\n", "␤\n"),
1161 strings.ReplaceAll(got, "\n", "␤\n"))
1162 }
1163 })
1164 }
1165}