0004-add-false-option-for-tests.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. From ebeb780df4ca5a8e5a43da1b38492964d8817455 Mon Sep 17 00:00:00 2001
  2. From: Adam Duskett <Adamduskett@outlook.com>
  3. Date: Mon, 1 Jan 2018 08:01:01 -0500
  4. Subject: [PATCH] add false option for tests
  5. Currently there is no way to not build tests. This introduces two problems:
  6. 1) It adds a extra 381 files to compile.
  7. 2) One of these tests explicitly requires libgcrypt to be built even if systemd
  8. is not using it.
  9. This patch adds the option "false" to tests, adds a check around the
  10. foreach loop that compiles the tests to see if tests is set to false,
  11. and adds a check around finding g++ as it's only used for tests and
  12. is not needed.
  13. Signed-off-by: Adam Duskett <Adamduskett@outlook.com>
  14. ---
  15. meson.build | 91 +++++++++++++++++++++++++++++--------------------------
  16. meson_options.txt | 2 +-
  17. 2 files changed, 49 insertions(+), 44 deletions(-)
  18. diff --git a/meson.build b/meson.build
  19. index ddc061c..4dcdd41 100644
  20. --- a/meson.build
  21. +++ b/meson.build
  22. @@ -260,10 +260,12 @@ cc = meson.get_compiler('c')
  23. pkgconfig = import('pkgconfig')
  24. check_compilation_sh = find_program('tools/meson-check-compilation.sh')
  25. -cxx = find_program('c++', required : false)
  26. -if cxx.found()
  27. - # Used only for tests
  28. - add_languages('cpp')
  29. +if get_option('tests') != 'false'
  30. + cxx = find_program('c++', required : false)
  31. + if cxx.found()
  32. + # Used only for tests
  33. + add_languages('cpp')
  34. + endif
  35. endif
  36. foreach arg : ['-Wextra',
  37. @@ -2388,48 +2390,51 @@ executable('systemd-sulogin-shell',
  38. install_dir : rootlibexecdir)
  39. ############################################################
  40. +if want_tests == 'false'
  41. + message('Not compiling because tests is set to false')
  42. +else
  43. + foreach tuple : tests
  44. + sources = tuple[0]
  45. + link_with = tuple[1].length() > 0 ? tuple[1] : [libshared]
  46. + dependencies = tuple[2]
  47. + condition = tuple.length() >= 4 ? tuple[3] : ''
  48. + type = tuple.length() >= 5 ? tuple[4] : ''
  49. + defs = tuple.length() >= 6 ? tuple[5] : []
  50. + incs = tuple.length() >= 7 ? tuple[6] : includes
  51. + timeout = 30
  52. +
  53. + name = sources[0].split('/')[-1].split('.')[0]
  54. + if type.startswith('timeout=')
  55. + timeout = type.split('=')[1].to_int()
  56. + type = ''
  57. + endif
  58. -foreach tuple : tests
  59. - sources = tuple[0]
  60. - link_with = tuple[1].length() > 0 ? tuple[1] : [libshared]
  61. - dependencies = tuple[2]
  62. - condition = tuple.length() >= 4 ? tuple[3] : ''
  63. - type = tuple.length() >= 5 ? tuple[4] : ''
  64. - defs = tuple.length() >= 6 ? tuple[5] : []
  65. - incs = tuple.length() >= 7 ? tuple[6] : includes
  66. - timeout = 30
  67. -
  68. - name = sources[0].split('/')[-1].split('.')[0]
  69. - if type.startswith('timeout=')
  70. - timeout = type.split('=')[1].to_int()
  71. - type = ''
  72. - endif
  73. -
  74. - if condition == '' or conf.get(condition) == 1
  75. - exe = executable(
  76. - name,
  77. - sources,
  78. - include_directories : incs,
  79. - link_with : link_with,
  80. - dependencies : dependencies,
  81. - c_args : defs,
  82. - install_rpath : rootlibexecdir,
  83. - install : install_tests,
  84. - install_dir : join_paths(testsdir, type))
  85. -
  86. - if type == 'manual'
  87. - message('@0@ is a manual test'.format(name))
  88. - elif type == 'unsafe' and want_tests != 'unsafe'
  89. - message('@0@ is an unsafe test'.format(name))
  90. + if condition == '' or conf.get(condition) == 1
  91. + exe = executable(
  92. + name,
  93. + sources,
  94. + include_directories : incs,
  95. + link_with : link_with,
  96. + dependencies : dependencies,
  97. + c_args : defs,
  98. + install_rpath : rootlibexecdir,
  99. + install : install_tests,
  100. + install_dir : join_paths(testsdir, type))
  101. +
  102. + if type == 'manual'
  103. + message('@0@ is a manual test'.format(name))
  104. + elif type == 'unsafe' and want_tests != 'unsafe'
  105. + message('@0@ is an unsafe test'.format(name))
  106. + else
  107. + test(name, exe,
  108. + env : test_env,
  109. + timeout : timeout)
  110. + endif
  111. else
  112. - test(name, exe,
  113. - env : test_env,
  114. - timeout : timeout)
  115. + message('Not compiling @0@ because @1@ is not true'.format(name, condition))
  116. endif
  117. - else
  118. - message('Not compiling @0@ because @1@ is not true'.format(name, condition))
  119. - endif
  120. -endforeach
  121. + endforeach
  122. +endif
  123. test_libsystemd_sym = executable(
  124. 'test-libsystemd-sym',
  125. diff --git a/meson_options.txt b/meson_options.txt
  126. index f0c0506..0caba0c 100644
  127. --- a/meson_options.txt
  128. +++ b/meson_options.txt
  129. @@ -284,7 +284,7 @@ option('bashcompletiondir', type : 'string',
  130. option('zshcompletiondir', type : 'string',
  131. description : 'directory for zsh completion scripts ["no" disables]')
  132. -option('tests', type : 'combo', choices : ['true', 'unsafe'],
  133. +option('tests', type : 'combo', choices : ['true', 'unsafe', 'false'],
  134. description : 'enable extra tests with =unsafe')
  135. option('slow-tests', type : 'boolean', value : 'false',
  136. description : 'run the slow tests by default')
  137. --
  138. 2.14.3