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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
ci/test/test_homebrew_boost_headers.py
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
|
| 6 |
from pathlib import Path
|
|
|
|
| 7 |
import os
|
| 8 |
import shlex
|
| 9 |
import shutil
|
|
@@ -18,7 +19,7 @@ CLANG = shutil.which('clang++')
|
|
| 18 |
|
| 19 |
@unittest.skipUnless(CLANG and shutil.which('cmake'), 'CMake and Clang are required')
|
| 20 |
class HomebrewBoostHeadersTest(unittest.TestCase):
|
| 21 |
-
def build(self, *, apple=True, matching=True, project_warning=False):
|
| 22 |
with tempfile.TemporaryDirectory(prefix='roots-homebrew-boost-') as directory:
|
| 23 |
work = Path(directory)
|
| 24 |
cellar = work / 'Cellar/boost/1.92.0'
|
|
@@ -28,7 +29,7 @@ class HomebrewBoostHeadersTest(unittest.TestCase):
|
|
| 28 |
'template<class T> struct Derived: Base { void lock() {} };\n')
|
| 29 |
(headers / 'signal.hpp').write_text(header)
|
| 30 |
(headers / 'config.hpp').write_text('')
|
| 31 |
-
prefix = work / 'homebrew'
|
| 32 |
(prefix / 'include').mkdir(parents=True)
|
| 33 |
if matching:
|
| 34 |
(prefix / 'include/boost').symlink_to(headers, target_is_directory=True)
|
|
@@ -58,10 +59,13 @@ class HomebrewBoostHeadersTest(unittest.TestCase):
|
|
| 58 |
(source / 'main.cpp').write_text(
|
| 59 |
'#include <boost/signal.hpp>\nDerived<int> item;\n'
|
| 60 |
+ ('struct Own: Base { void lock() {} };\nOwn own;\n' if project_warning else ''))
|
|
|
|
|
|
|
| 61 |
(source / 'CMakeLists.txt').write_text(
|
| 62 |
'cmake_minimum_required(VERSION 3.22)\n'
|
| 63 |
'project(HomebrewBoostHeaders LANGUAGES CXX)\n'
|
| 64 |
f'set(CMAKE_HOST_APPLE {"TRUE" if apple else "FALSE"})\n'
|
|
|
|
| 65 |
f'include("{ROOT / "cmake/module/AddBoostIfNeeded.cmake"}")\n'
|
| 66 |
'add_boost_if_needed()\n'
|
| 67 |
'add_library(probe OBJECT main.cpp)\n'
|
|
@@ -72,11 +76,25 @@ class HomebrewBoostHeadersTest(unittest.TestCase):
|
|
| 72 |
environment = {**os.environ, 'PATH': f'{tools}:{os.environ["PATH"]}',
|
| 73 |
'CPATH': str(prefix / 'include')}
|
| 74 |
build = work / 'build'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
configure = subprocess.run(
|
| 76 |
['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)
|
|
|
|
| 79 |
self.assertEqual(configure.returncode, 0, configure.stdout + configure.stderr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
return subprocess.run(['cmake', '--build', str(build), '--parallel', '2'],
|
| 81 |
capture_output=True, text=True, env=environment)
|
| 82 |
|
|
@@ -90,15 +108,25 @@ class HomebrewBoostHeadersTest(unittest.TestCase):
|
|
| 90 |
self.assertIn('main.cpp:', result.stderr)
|
| 91 |
self.assertIn('[-Werror,-Wsuggest-override]', result.stderr)
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
def test_different_boost_installation_is_not_hidden(self):
|
| 94 |
result = self.build(matching=False)
|
| 95 |
self.assertNotEqual(result.returncode, 0)
|
| 96 |
-
self.assertIn('homebrew/include/boost/signal.hpp:', result.stderr)
|
| 97 |
|
| 98 |
def test_other_hosts_do_not_classify_homebrew_alias(self):
|
| 99 |
result = self.build(apple=False)
|
| 100 |
self.assertNotEqual(result.returncode, 0)
|
| 101 |
-
self.assertIn('homebrew/include/boost/signal.hpp:', result.stderr)
|
| 102 |
|
| 103 |
|
| 104 |
if __name__ == '__main__':
|
|
|
|
| 4 |
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
| 5 |
|
| 6 |
from pathlib import Path
|
| 7 |
+
import json
|
| 8 |
import os
|
| 9 |
import shlex
|
| 10 |
import shutil
|
|
|
|
| 19 |
|
| 20 |
@unittest.skipUnless(CLANG and shutil.which('cmake'), 'CMake and Clang are required')
|
| 21 |
class HomebrewBoostHeadersTest(unittest.TestCase):
|
| 22 |
+
def build(self, *, apple=True, matching=True, project_warning=False, implicit_alias=False):
|
| 23 |
with tempfile.TemporaryDirectory(prefix='roots-homebrew-boost-') as directory:
|
| 24 |
work = Path(directory)
|
| 25 |
cellar = work / 'Cellar/boost/1.92.0'
|
|
|
|
| 29 |
'template<class T> struct Derived: Base { void lock() {} };\n')
|
| 30 |
(headers / 'signal.hpp').write_text(header)
|
| 31 |
(headers / 'config.hpp').write_text('')
|
| 32 |
+
prefix = work / 'homebrew prefix'
|
| 33 |
(prefix / 'include').mkdir(parents=True)
|
| 34 |
if matching:
|
| 35 |
(prefix / 'include/boost').symlink_to(headers, target_is_directory=True)
|
|
|
|
| 59 |
(source / 'main.cpp').write_text(
|
| 60 |
'#include <boost/signal.hpp>\nDerived<int> item;\n'
|
| 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 '')
|
| 64 |
(source / 'CMakeLists.txt').write_text(
|
| 65 |
'cmake_minimum_required(VERSION 3.22)\n'
|
| 66 |
'project(HomebrewBoostHeaders LANGUAGES CXX)\n'
|
| 67 |
f'set(CMAKE_HOST_APPLE {"TRUE" if apple else "FALSE"})\n'
|
| 68 |
+
f'{implicit_include}'
|
| 69 |
f'include("{ROOT / "cmake/module/AddBoostIfNeeded.cmake"}")\n'
|
| 70 |
'add_boost_if_needed()\n'
|
| 71 |
'add_library(probe OBJECT main.cpp)\n'
|
|
|
|
| 76 |
environment = {**os.environ, 'PATH': f'{tools}:{os.environ["PATH"]}',
|
| 77 |
'CPATH': str(prefix / 'include')}
|
| 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')
|
| 85 |
configure = subprocess.run(
|
| 86 |
['cmake', '-S', str(source), '-B', str(build),
|
| 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)
|
| 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)
|
| 98 |
return subprocess.run(['cmake', '--build', str(build), '--parallel', '2'],
|
| 99 |
capture_output=True, text=True, env=environment)
|
| 100 |
|
|
|
|
| 108 |
self.assertIn('main.cpp:', result.stderr)
|
| 109 |
self.assertIn('[-Werror,-Wsuggest-override]', result.stderr)
|
| 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 |
+
|
| 121 |
def test_different_boost_installation_is_not_hidden(self):
|
| 122 |
result = self.build(matching=False)
|
| 123 |
self.assertNotEqual(result.returncode, 0)
|
| 124 |
+
self.assertIn('homebrew prefix/include/boost/signal.hpp:', result.stderr)
|
| 125 |
|
| 126 |
def test_other_hosts_do_not_classify_homebrew_alias(self):
|
| 127 |
result = self.build(apple=False)
|
| 128 |
self.assertNotEqual(result.returncode, 0)
|
| 129 |
+
self.assertIn('homebrew prefix/include/boost/signal.hpp:', result.stderr)
|
| 130 |
|
| 131 |
|
| 132 |
if __name__ == '__main__':
|