mk2rbc_test.go 44 KB

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