test_lib_mk.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. import pytest
  2. import checkpackagelib.test_util as util
  3. import checkpackagelib.lib_mk as m
  4. Ifdef = [
  5. ('ignore commented line',
  6. 'any',
  7. '# ifdef\n',
  8. []),
  9. ('simple',
  10. 'any',
  11. '\n'
  12. 'ifdef BR2_PACKAGE_FWTS_EFI_RUNTIME_MODULE\n'
  13. 'endif\n',
  14. [['any:2: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL',
  15. 'ifdef BR2_PACKAGE_FWTS_EFI_RUNTIME_MODULE\n']]),
  16. ('ignore indentation',
  17. 'any',
  18. ' ifdef FOO\n'
  19. ' endif\n'
  20. '\tifdef BAR\n'
  21. 'endif\n',
  22. [['any:1: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL',
  23. ' ifdef FOO\n'],
  24. ['any:3: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL',
  25. '\tifdef BAR\n']]),
  26. ('typo',
  27. 'any',
  28. '\n'
  29. 'ifndef ($(BR2_ENABLE_LOCALE),y)\n'
  30. 'endif\n',
  31. [['any:2: use ifneq ($(SYMBOL),y) instead of ifndef SYMBOL',
  32. 'ifndef ($(BR2_ENABLE_LOCALE),y)\n']]),
  33. ('else ifdef',
  34. 'any',
  35. 'else ifdef SYMBOL # comment\n',
  36. [['any:1: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL',
  37. 'else ifdef SYMBOL # comment\n']]),
  38. ('else ifndef',
  39. 'any',
  40. '\t else ifndef\t($(SYMBOL),y) # comment\n',
  41. [['any:1: use ifneq ($(SYMBOL),y) instead of ifndef SYMBOL',
  42. '\t else ifndef\t($(SYMBOL),y) # comment\n']]),
  43. ]
  44. @pytest.mark.parametrize('testname,filename,string,expected', Ifdef)
  45. def test_Ifdef(testname, filename, string, expected):
  46. warnings = util.check_file(m.Ifdef, filename, string)
  47. assert warnings == expected
  48. Indent = [
  49. ('ignore comment at beginning of line',
  50. 'any',
  51. '# very useful comment\n',
  52. []),
  53. ('ignore comment at end of line',
  54. 'any',
  55. ' # very useful comment\n',
  56. []),
  57. ('do not indent on conditional (good)',
  58. 'any',
  59. 'ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)\n'
  60. 'FOO_CONF_OPTS += something\n'
  61. 'endef\n',
  62. []),
  63. ('do not indent on conditional (bad)',
  64. 'any',
  65. 'ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)\n'
  66. '\tFOO_CONF_OPTS += something\n'
  67. 'endef\n',
  68. [['any:2: unexpected indent with tabs',
  69. '\tFOO_CONF_OPTS += something\n']]),
  70. ('indent after line that ends in backslash (good)',
  71. 'any',
  72. 'FOO_CONF_OPTS += \\\n'
  73. '\tsomething\n',
  74. []),
  75. ('indent after line that ends in backslash (bad)',
  76. 'any',
  77. 'FOO_CONF_OPTS += \\\n'
  78. 'something\n',
  79. [['any:2: expected indent with tabs',
  80. 'something\n']]),
  81. ('indent after 2 lines that ends in backslash (good)',
  82. 'any',
  83. 'FOO_CONF_OPTS += \\\n'
  84. '\tsomething \\\n'
  85. '\tsomething_else\n',
  86. []),
  87. ('indent after 2 lines that ends in backslash (bad)',
  88. 'any',
  89. 'FOO_CONF_OPTS += \\\n'
  90. '\tsomething \\\n'
  91. '\tsomething_else \\\n'
  92. 'FOO_CONF_OPTS += another_thing\n',
  93. [['any:4: expected indent with tabs',
  94. 'FOO_CONF_OPTS += another_thing\n']]),
  95. ('indent inside define (good)',
  96. 'any',
  97. 'define FOO_SOMETHING\n'
  98. '\tcommand\n'
  99. '\tcommand \\\n'
  100. '\t\targuments\n'
  101. 'endef\n'
  102. 'FOO_POST_PATCH_HOOKS += FOO_SOMETHING\n',
  103. []),
  104. ('indent inside define (bad, no indent)',
  105. 'any',
  106. 'define FOO_SOMETHING\n'
  107. 'command\n'
  108. 'endef\n',
  109. [['any:2: expected indent with tabs',
  110. 'command\n']]),
  111. ('indent inside define (bad, spaces)',
  112. 'any',
  113. 'define FOO_SOMETHING\n'
  114. ' command\n'
  115. 'endef\n',
  116. [['any:2: expected indent with tabs',
  117. ' command\n']]),
  118. ('indent make target (good)',
  119. 'any',
  120. 'make_target:\n'
  121. '\tcommand\n'
  122. '\n',
  123. []),
  124. ('indent make target (bad)',
  125. 'any',
  126. 'make_target:\n'
  127. ' command\n'
  128. '\n',
  129. [['any:2: expected indent with tabs',
  130. ' command\n']]),
  131. ]
  132. @pytest.mark.parametrize('testname,filename,string,expected', Indent)
  133. def test_Indent(testname, filename, string, expected):
  134. warnings = util.check_file(m.Indent, filename, string)
  135. assert warnings == expected
  136. OverriddenVariable = [
  137. ('simple assignment',
  138. 'any.mk',
  139. 'VAR_1 = VALUE1\n',
  140. []),
  141. ('unconditional override (variable without underscore)',
  142. 'any.mk',
  143. 'VAR1 = VALUE1\n'
  144. 'VAR1 = VALUE1\n',
  145. [['any.mk:2: unconditional override of variable VAR1',
  146. 'VAR1 = VALUE1\n']]),
  147. ('unconditional override (variable with underscore, same value)',
  148. 'any.mk',
  149. 'VAR_1 = VALUE1\n'
  150. 'VAR_1 = VALUE1\n',
  151. [['any.mk:2: unconditional override of variable VAR_1',
  152. 'VAR_1 = VALUE1\n']]),
  153. ('unconditional override (variable with underscore, different value)',
  154. 'any.mk',
  155. 'VAR_1 = VALUE1\n'
  156. 'VAR_1 = VALUE2\n',
  157. [['any.mk:2: unconditional override of variable VAR_1',
  158. 'VAR_1 = VALUE2\n']]),
  159. ('warn for unconditional override even with wrong number of spaces',
  160. 'any.mk',
  161. 'VAR_1= VALUE1\n'
  162. 'VAR_1 =VALUE2\n',
  163. [['any.mk:2: unconditional override of variable VAR_1',
  164. 'VAR_1 =VALUE2\n']]),
  165. ('warn for := override',
  166. 'any.mk',
  167. 'VAR_1 = VALUE1\n'
  168. 'VAR_1 := VALUE2\n',
  169. [['any.mk:2: unconditional override of variable VAR_1',
  170. 'VAR_1 := VALUE2\n']]),
  171. ('append values outside conditional (good)',
  172. 'any.mk',
  173. 'VAR_1 = VALUE1\n'
  174. 'VAR_1 += VALUE2\n',
  175. []),
  176. ('append values outside conditional (bad)',
  177. 'any.mk',
  178. 'VAR_1 = VALUE1\n'
  179. 'VAR_1 := $(VAR_1), VALUE2\n',
  180. [['any.mk:2: unconditional override of variable VAR_1',
  181. 'VAR_1 := $(VAR_1), VALUE2\n']]),
  182. ('immediate assignment inside conditional',
  183. 'any.mk',
  184. 'VAR_1 = VALUE1\n'
  185. 'ifeq (condition)\n'
  186. 'VAR_1 := $(VAR_1), VALUE2\n',
  187. [['any.mk:3: immediate assignment to append to variable VAR_1',
  188. 'VAR_1 := $(VAR_1), VALUE2\n']]),
  189. ('immediate assignment inside conditional and unconditional override outside',
  190. 'any.mk',
  191. 'VAR_1 = VALUE1\n'
  192. 'ifeq (condition)\n'
  193. 'VAR_1 := $(VAR_1), VALUE2\n'
  194. 'endif\n'
  195. 'VAR_1 := $(VAR_1), VALUE2\n',
  196. [['any.mk:3: immediate assignment to append to variable VAR_1',
  197. 'VAR_1 := $(VAR_1), VALUE2\n'],
  198. ['any.mk:5: unconditional override of variable VAR_1',
  199. 'VAR_1 := $(VAR_1), VALUE2\n']]),
  200. ]
  201. @pytest.mark.parametrize('testname,filename,string,expected', OverriddenVariable)
  202. def test_OverriddenVariable(testname, filename, string, expected):
  203. warnings = util.check_file(m.OverriddenVariable, filename, string)
  204. assert warnings == expected
  205. PackageHeader = [
  206. ('first line (good)',
  207. 'any',
  208. 80 * '#' + '\n',
  209. []),
  210. ('first line (bad)',
  211. 'any',
  212. '# very useful comment\n',
  213. [['any:1: should be 80 hashes (url#writing-rules-mk)',
  214. '# very useful comment\n',
  215. 80 * '#']]),
  216. ('second line (bad)',
  217. 'any',
  218. 80 * '#' + '\n'
  219. '# package\n',
  220. [['any:2: should be 1 hash (url#writing-rules-mk)',
  221. '# package\n']]),
  222. ('full header (good)',
  223. 'any',
  224. 80 * '#' + '\n'
  225. '#\n'
  226. '# package\n'
  227. '#\n' +
  228. 80 * '#' + '\n'
  229. '\n',
  230. []),
  231. ('blank line after header (good)',
  232. 'any',
  233. 80 * '#' + '\n'
  234. '#\n'
  235. '# package\n'
  236. '#\n' +
  237. 80 * '#' + '\n'
  238. '\n'
  239. 'FOO_VERSION = 1\n',
  240. []),
  241. ('blank line after header (bad)',
  242. 'any',
  243. 80 * '#' + '\n'
  244. '#\n'
  245. '# package\n'
  246. '#\n' +
  247. 80 * '#' + '\n'
  248. 'FOO_VERSION = 1\n',
  249. [['any:6: should be a blank line (url#writing-rules-mk)',
  250. 'FOO_VERSION = 1\n']]),
  251. ('wrong number of hashes',
  252. 'any',
  253. 79 * '#' + '\n'
  254. '#\n'
  255. '# package\n'
  256. '#\n' +
  257. 81 * '#' + '\n'
  258. '\n',
  259. [['any:1: should be 80 hashes (url#writing-rules-mk)',
  260. 79 * '#' + '\n',
  261. 80 * '#'],
  262. ['any:5: should be 80 hashes (url#writing-rules-mk)',
  263. 81 * '#' + '\n',
  264. 80 * '#']]),
  265. ('allow include without header',
  266. 'any',
  267. 'include $(sort $(wildcard package/foo/*/*.mk))\n',
  268. []),
  269. ]
  270. @pytest.mark.parametrize('testname,filename,string,expected', PackageHeader)
  271. def test_PackageHeader(testname, filename, string, expected):
  272. warnings = util.check_file(m.PackageHeader, filename, string)
  273. assert warnings == expected
  274. RemoveDefaultPackageSourceVariable = [
  275. ('bad',
  276. 'any.mk',
  277. 'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n',
  278. [['any.mk:1: remove default value of _SOURCE variable (url#generic-package-reference)',
  279. 'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n']]),
  280. ('bad with path',
  281. './any.mk',
  282. 'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n',
  283. [['./any.mk:1: remove default value of _SOURCE variable (url#generic-package-reference)',
  284. 'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n']]),
  285. ('warn for correct line',
  286. './any.mk',
  287. '\n'
  288. '\n'
  289. '\n'
  290. 'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n',
  291. [['./any.mk:4: remove default value of _SOURCE variable (url#generic-package-reference)',
  292. 'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n']]),
  293. ('warn ignoring missing spaces',
  294. './any.mk',
  295. 'ANY_SOURCE=any-$(ANY_VERSION).tar.gz\n',
  296. [['./any.mk:1: remove default value of _SOURCE variable (url#generic-package-reference)',
  297. 'ANY_SOURCE=any-$(ANY_VERSION).tar.gz\n']]),
  298. ('good',
  299. './any.mk',
  300. 'ANY_SOURCE = aNy-$(ANY_VERSION).tar.gz\n',
  301. []),
  302. ('gcc exception',
  303. 'gcc.mk',
  304. 'GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz\n',
  305. []),
  306. ('binutils exception',
  307. './binutils.mk',
  308. 'BINUTILS_SOURCE = binutils-$(BINUTILS_VERSION).tar.gz\n',
  309. []),
  310. ('gdb exception',
  311. 'gdb/gdb.mk',
  312. 'GDB_SOURCE = gdb-$(GDB_VERSION).tar.gz\n',
  313. []),
  314. ('package name with dash',
  315. 'python-subprocess32.mk',
  316. 'PYTHON_SUBPROCESS32_SOURCE = python-subprocess32-$(PYTHON_SUBPROCESS32_VERSION).tar.gz\n',
  317. [['python-subprocess32.mk:1: remove default value of _SOURCE variable (url#generic-package-reference)',
  318. 'PYTHON_SUBPROCESS32_SOURCE = python-subprocess32-$(PYTHON_SUBPROCESS32_VERSION).tar.gz\n']]),
  319. ]
  320. @pytest.mark.parametrize('testname,filename,string,expected', RemoveDefaultPackageSourceVariable)
  321. def test_RemoveDefaultPackageSourceVariable(testname, filename, string, expected):
  322. warnings = util.check_file(m.RemoveDefaultPackageSourceVariable, filename, string)
  323. assert warnings == expected
  324. SpaceBeforeBackslash = [
  325. ('no backslash',
  326. 'any.mk',
  327. '\n',
  328. []),
  329. ('ignore missing indent',
  330. 'any.mk',
  331. 'define ANY_SOME_FIXUP\n'
  332. 'for i in $$(find $(STAGING_DIR)/usr/lib* -name "any*.la"); do \\\n',
  333. []),
  334. ('ignore missing space',
  335. 'any.mk',
  336. 'ANY_CONF_ENV= \\\n'
  337. '\tap_cv_void_ptr_lt_long=no \\\n',
  338. []),
  339. ('variable',
  340. 'any.mk',
  341. '\n'
  342. 'ANY = \\\n',
  343. []),
  344. ('2 spaces',
  345. 'any.mk',
  346. 'ANY = \\\n',
  347. [['any.mk:1: use only one space before backslash',
  348. 'ANY = \\\n']]),
  349. ('warn about correct line',
  350. 'any.mk',
  351. '\n'
  352. 'ANY = \\\n',
  353. [['any.mk:2: use only one space before backslash',
  354. 'ANY = \\\n']]),
  355. ('tab',
  356. 'any.mk',
  357. 'ANY =\t\\\n',
  358. [['any.mk:1: use only one space before backslash',
  359. 'ANY =\t\\\n']]),
  360. ('tabs',
  361. 'any.mk',
  362. 'ANY =\t\t\\\n',
  363. [['any.mk:1: use only one space before backslash',
  364. 'ANY =\t\t\\\n']]),
  365. ('spaces and tabs',
  366. 'any.mk',
  367. 'ANY = \t\t\\\n',
  368. [['any.mk:1: use only one space before backslash',
  369. 'ANY = \t\t\\\n']]),
  370. ('mixed spaces and tabs 1',
  371. 'any.mk',
  372. 'ANY = \t \t\\\n',
  373. [['any.mk:1: use only one space before backslash',
  374. 'ANY = \t \t\\\n']]),
  375. ('mixed spaces and tabs 2',
  376. 'any.mk',
  377. 'ANY = \t \\\n',
  378. [['any.mk:1: use only one space before backslash',
  379. 'ANY = \t \\\n']]),
  380. ]
  381. @pytest.mark.parametrize('testname,filename,string,expected', SpaceBeforeBackslash)
  382. def test_SpaceBeforeBackslash(testname, filename, string, expected):
  383. warnings = util.check_file(m.SpaceBeforeBackslash, filename, string)
  384. assert warnings == expected
  385. TrailingBackslash = [
  386. ('no backslash',
  387. 'any.mk',
  388. 'ANY = \n',
  389. []),
  390. ('one line',
  391. 'any.mk',
  392. 'ANY = \\\n',
  393. []),
  394. ('2 lines',
  395. 'any.mk',
  396. 'ANY = \\\n'
  397. '\\\n',
  398. []),
  399. ('empty line after',
  400. 'any.mk',
  401. 'ANY = \\\n'
  402. '\n',
  403. [['any.mk:1: remove trailing backslash',
  404. 'ANY = \\\n']]),
  405. ('line with spaces after',
  406. 'any.mk',
  407. 'ANY = \\\n'
  408. ' \n',
  409. [['any.mk:1: remove trailing backslash',
  410. 'ANY = \\\n']]),
  411. ('line with tabs after',
  412. 'any.mk',
  413. 'ANY = \\\n'
  414. '\t\n',
  415. [['any.mk:1: remove trailing backslash',
  416. 'ANY = \\\n']]),
  417. ('ignore if commented',
  418. 'any.mk',
  419. '# ANY = \\\n'
  420. '\n',
  421. []),
  422. ('real example',
  423. 'any.mk',
  424. 'ANY_CONF_ENV= \t\\\n'
  425. '\tap_cv_void_ptr_lt_long=no \\\n'
  426. '\n',
  427. [['any.mk:2: remove trailing backslash',
  428. '\tap_cv_void_ptr_lt_long=no \\\n']]),
  429. ('ignore whitespace 1',
  430. 'any.mk',
  431. 'ANY = \t\t\\\n',
  432. []),
  433. ('ignore whitespace 2',
  434. 'any.mk',
  435. 'ANY = \t \t\\\n',
  436. []),
  437. ('ignore whitespace 3',
  438. 'any.mk',
  439. 'ANY = \t \\\n',
  440. []),
  441. ]
  442. @pytest.mark.parametrize('testname,filename,string,expected', TrailingBackslash)
  443. def test_TrailingBackslash(testname, filename, string, expected):
  444. warnings = util.check_file(m.TrailingBackslash, filename, string)
  445. assert warnings == expected
  446. TypoInPackageVariable = [
  447. ('good',
  448. 'any.mk',
  449. 'ANY_VAR = \n',
  450. []),
  451. ('good with path 1',
  452. './any.mk',
  453. 'ANY_VAR += \n',
  454. []),
  455. ('good with path 2',
  456. 'any/any.mk',
  457. 'ANY_VAR = \n',
  458. []),
  459. ('bad =',
  460. 'any.mk',
  461. 'OTHER_VAR = \n',
  462. [['any.mk:1: possible typo: OTHER_VAR -> *ANY*',
  463. 'OTHER_VAR = \n']]),
  464. ('bad +=',
  465. 'any.mk',
  466. 'OTHER_VAR += \n',
  467. [['any.mk:1: possible typo: OTHER_VAR -> *ANY*',
  468. 'OTHER_VAR += \n']]),
  469. ('ignore missing space',
  470. 'any.mk',
  471. 'OTHER_VAR= \n',
  472. [['any.mk:1: possible typo: OTHER_VAR -> *ANY*',
  473. 'OTHER_VAR= \n']]),
  474. ('use path in the warning',
  475. './any.mk',
  476. 'OTHER_VAR = \n',
  477. [['./any.mk:1: possible typo: OTHER_VAR -> *ANY*',
  478. 'OTHER_VAR = \n']]),
  479. ('another name',
  480. 'other.mk',
  481. 'ANY_VAR = \n',
  482. [['other.mk:1: possible typo: ANY_VAR -> *OTHER*',
  483. 'ANY_VAR = \n']]),
  484. ('libc exception',
  485. './any.mk',
  486. 'BR_LIBC = \n',
  487. []),
  488. ('rootfs exception',
  489. 'any.mk',
  490. 'ROOTFS_ANY_VAR += \n',
  491. []),
  492. ('host (good)',
  493. 'any.mk',
  494. 'HOST_ANY_VAR += \n',
  495. []),
  496. ('host (bad)',
  497. 'any.mk',
  498. 'HOST_OTHER_VAR = \n',
  499. [['any.mk:1: possible typo: HOST_OTHER_VAR -> *ANY*',
  500. 'HOST_OTHER_VAR = \n']]),
  501. ('provides',
  502. 'any.mk',
  503. 'ANY_PROVIDES = other thing\n'
  504. 'OTHER_VAR = \n',
  505. []),
  506. ('ignore space',
  507. 'any.mk',
  508. 'ANY_PROVIDES = thing other \n'
  509. 'OTHER_VAR = \n',
  510. []),
  511. ('wrong provides',
  512. 'any.mk',
  513. 'ANY_PROVIDES = other\n'
  514. 'OTHERS_VAR = \n',
  515. [['any.mk:2: possible typo: OTHERS_VAR -> *ANY*',
  516. 'OTHERS_VAR = \n']]),
  517. ]
  518. @pytest.mark.parametrize('testname,filename,string,expected', TypoInPackageVariable)
  519. def test_TypoInPackageVariable(testname, filename, string, expected):
  520. warnings = util.check_file(m.TypoInPackageVariable, filename, string)
  521. assert warnings == expected
  522. UselessFlag = [
  523. ('autoreconf no',
  524. 'any.mk',
  525. 'ANY_AUTORECONF=NO\n',
  526. [['any.mk:1: useless default value (url#_infrastructure_for_autotools_based_packages)',
  527. 'ANY_AUTORECONF=NO\n']]),
  528. ('host autoreconf no',
  529. 'any.mk',
  530. 'HOST_ANY_AUTORECONF\n',
  531. []),
  532. ('autoreconf yes',
  533. 'any.mk',
  534. 'ANY_AUTORECONF=YES\n',
  535. []),
  536. ('libtool_patch yes',
  537. 'any.mk',
  538. 'ANY_LIBTOOL_PATCH\t= YES\n',
  539. [['any.mk:1: useless default value (url#_infrastructure_for_autotools_based_packages)',
  540. 'ANY_LIBTOOL_PATCH\t= YES\n']]),
  541. ('libtool_patch no',
  542. 'any.mk',
  543. 'ANY_LIBTOOL_PATCH= \t NO\n',
  544. []),
  545. ('generic',
  546. 'any.mk',
  547. 'ANY_INSTALL_IMAGES = NO\n'
  548. 'ANY_INSTALL_REDISTRIBUTE = YES\n'
  549. 'ANY_INSTALL_STAGING = NO\n'
  550. 'ANY_INSTALL_TARGET = YES\n',
  551. [['any.mk:1: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
  552. 'ANY_INSTALL_IMAGES = NO\n'],
  553. ['any.mk:2: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
  554. 'ANY_INSTALL_REDISTRIBUTE = YES\n'],
  555. ['any.mk:3: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
  556. 'ANY_INSTALL_STAGING = NO\n'],
  557. ['any.mk:4: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
  558. 'ANY_INSTALL_TARGET = YES\n']]),
  559. ('conditional',
  560. 'any.mk',
  561. 'ifneq (condition)\n'
  562. 'ANY_INSTALL_IMAGES = NO\n'
  563. 'endif\n'
  564. 'ANY_INSTALL_REDISTRIBUTE = YES\n',
  565. [['any.mk:4: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
  566. 'ANY_INSTALL_REDISTRIBUTE = YES\n']]),
  567. ]
  568. @pytest.mark.parametrize('testname,filename,string,expected', UselessFlag)
  569. def test_UselessFlag(testname, filename, string, expected):
  570. warnings = util.check_file(m.UselessFlag, filename, string)
  571. assert warnings == expected
  572. VariableWithBraces = [
  573. ('good',
  574. 'xmlstarlet.mk',
  575. 'XMLSTARLET_CONF_OPTS += \\\n'
  576. '\t--with-libxml-prefix=$(STAGING_DIR)/usr \\\n',
  577. []),
  578. ('bad',
  579. 'xmlstarlet.mk',
  580. 'XMLSTARLET_CONF_OPTS += \\\n'
  581. '\t--with-libxml-prefix=${STAGING_DIR}/usr \\\n',
  582. [['xmlstarlet.mk:2: use $() to delimit variables, not ${}',
  583. '\t--with-libxml-prefix=${STAGING_DIR}/usr \\\n']]),
  584. ('expanded by the shell',
  585. 'sg3_utils.mk',
  586. '\tfor prog in xcopy zone; do \\\n'
  587. '\t\t$(RM) $(TARGET_DIR)/usr/bin/sg_$${prog} ; \\\n'
  588. '\tdone\n',
  589. []),
  590. ('comments',
  591. 'any.mk',
  592. '#\t--with-libxml-prefix=${STAGING_DIR}/usr \\\n',
  593. []),
  594. ]
  595. @pytest.mark.parametrize('testname,filename,string,expected', VariableWithBraces)
  596. def test_VariableWithBraces(testname, filename, string, expected):
  597. warnings = util.check_file(m.VariableWithBraces, filename, string)
  598. assert warnings == expected