Skip to content
Bitcoin Roots

v31.1-roots.1 · Commit 14: [PATCH 14/17] fix(build): retain implicit Homebrew system header flags

ci/test/test_homebrew_boost_headers.py

Before: ci/test/test_homebrew_boost_headers.py · After: ci/test/test_homebrew_boost_headers.py

File metadata
index ca865a7a27303ae437d6ff07be70ea814cf69e5e..d312f1aa984ef7adcf7f8f17b8baaee0a24680f7 100644

Download original patch · Release notes

Diff rows 1–90 of 90. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

ci/test/test_homebrew_boost_headers.py CHANGED
@@ -4,6 +4,7 @@
4
4
  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
 
6
6
  from pathlib import Path
7
+ import json
7
8
  import os
8
9
  import shlex
9
10
  import shutil
@@ -18,7 +19,7 @@ CLANG = shutil.which('clang++')
18
19
 
19
20
  @unittest.skipUnless(CLANG and shutil.which('cmake'), 'CMake and Clang are required')
20
21
  class HomebrewBoostHeadersTest(unittest.TestCase):
21
- def build(self, *, apple=True, matching=True, project_warning=False):
22
+ def build(self, *, apple=True, matching=True, project_warning=False, implicit_alias=False):
22
23
  with tempfile.TemporaryDirectory(prefix='roots-homebrew-boost-') as directory:
23
24
  work = Path(directory)
24
25
  cellar = work / 'Cellar/boost/1.92.0'
@@ -28,7 +29,7 @@ class HomebrewBoostHeadersTest(unittest.TestCase):
28
29
  'template<class T> struct Derived: Base { void lock() {} };\n')
29
30
  (headers / 'signal.hpp').write_text(header)
30
31
  (headers / 'config.hpp').write_text('')
31
- prefix = work / 'homebrew'
32
+ prefix = work / 'homebrew prefix'
32
33
  (prefix / 'include').mkdir(parents=True)
33
34
  if matching:
34
35
  (prefix / 'include/boost').symlink_to(headers, target_is_directory=True)
@@ -58,10 +59,13 @@ class HomebrewBoostHeadersTest(unittest.TestCase):
58
59
  (source / 'main.cpp').write_text(
59
60
  '#include <boost/signal.hpp>\nDerived<int> item;\n'
60
61
  + ('struct Own: Base { void lock() {} };\nOwn own;\n' if project_warning else ''))
62
+ implicit_include = (f'list(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "{prefix / "include"}")\n'
63
+ if implicit_alias else '')
61
64
  (source / 'CMakeLists.txt').write_text(
62
65
  'cmake_minimum_required(VERSION 3.22)\n'
63
66
  'project(HomebrewBoostHeaders LANGUAGES CXX)\n'
64
67
  f'set(CMAKE_HOST_APPLE {"TRUE" if apple else "FALSE"})\n'
68
+ f'{implicit_include}'
65
69
  f'include("{ROOT / "cmake/module/AddBoostIfNeeded.cmake"}")\n'
66
70
  'add_boost_if_needed()\n'
67
71
  'add_library(probe OBJECT main.cpp)\n'
@@ -72,11 +76,25 @@ class HomebrewBoostHeadersTest(unittest.TestCase):
72
76
  environment = {**os.environ, 'PATH': f'{tools}:{os.environ["PATH"]}',
73
77
  'CPATH': str(prefix / 'include')}
74
78
  build = work / 'build'
79
+ configure_environment = environment.copy()
80
+ if implicit_alias:
81
+ # CMake exempts configure-time CPATH entries from implicit-dir
82
+ # filtering. Model the filtered path without that exemption;
83
+ # the build still selects the linked headers through CPATH.
84
+ configure_environment.pop('CPATH')
75
85
  configure = subprocess.run(
76
86
  ['cmake', '-S', str(source), '-B', str(build),
77
- f'-DCMAKE_CXX_COMPILER={CLANG}', f'-DBoost_DIR={config}'],
78
- capture_output=True, text=True, env=environment)
87
+ f'-DCMAKE_CXX_COMPILER={CLANG}', f'-DBoost_DIR={config}',
88
+ '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON'],
89
+ capture_output=True, text=True, env=configure_environment)
79
90
  self.assertEqual(configure.returncode, 0, configure.stdout + configure.stderr)
91
+ command = json.loads((build / 'compile_commands.json').read_text())[0]['command']
92
+ arguments = shlex.split(command)
93
+ system_dirs = [arguments[i + 1] for i, argument in enumerate(arguments[:-1])
94
+ if argument == '-isystem']
95
+ self.assertEqual(str(prefix / 'include') in system_dirs, apple and matching, command)
96
+ self.assertIn('-Werror', arguments)
97
+ self.assertIn('-Wsuggest-override', arguments)
80
98
  return subprocess.run(['cmake', '--build', str(build), '--parallel', '2'],
81
99
  capture_output=True, text=True, env=environment)
82
100
 
@@ -90,15 +108,25 @@ class HomebrewBoostHeadersTest(unittest.TestCase):
90
108
  self.assertIn('main.cpp:', result.stderr)
91
109
  self.assertIn('[-Werror,-Wsuggest-override]', result.stderr)
92
110
 
111
+ def test_implicit_alias_retains_generated_system_flag(self):
112
+ result = self.build(implicit_alias=True)
113
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
114
+
115
+ def test_implicit_alias_keeps_project_warnings_strict(self):
116
+ result = self.build(implicit_alias=True, project_warning=True)
117
+ self.assertNotEqual(result.returncode, 0)
118
+ self.assertIn('main.cpp:', result.stderr)
119
+ self.assertIn('[-Werror,-Wsuggest-override]', result.stderr)
120
+
93
121
  def test_different_boost_installation_is_not_hidden(self):
94
122
  result = self.build(matching=False)
95
123
  self.assertNotEqual(result.returncode, 0)
96
- self.assertIn('homebrew/include/boost/signal.hpp:', result.stderr)
124
+ self.assertIn('homebrew prefix/include/boost/signal.hpp:', result.stderr)
97
125
 
98
126
  def test_other_hosts_do_not_classify_homebrew_alias(self):
99
127
  result = self.build(apple=False)
100
128
  self.assertNotEqual(result.returncode, 0)
101
- self.assertIn('homebrew/include/boost/signal.hpp:', result.stderr)
129
+ self.assertIn('homebrew prefix/include/boost/signal.hpp:', result.stderr)
102
130
 
103
131
 
104
132
  if __name__ == '__main__':