test_lib_mk.py 19 KB

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