Skip to content

Commit dc2953d

Browse files
committed
Fix detection of libc++ hardening mode support without git history
In Jenkins we only have a partial history, so instead of checking for ancestor commits, just read the CMakeLists.txt directly. This is fine since it must exist by the time this code is called.
1 parent e4a50ce commit dc2953d

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pycheribuild/projects/cross/libcxx.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,24 @@ def setup_config_options(cls, **kwargs):
611611
kind=int,
612612
)
613613

614+
def _supported_libcxx_hardening_modes(self) -> "list[str]":
615+
# We may have a partial history, so prefer scanning the CMakeLists.txt
616+
prefix = "set(LIBCXX_SUPPORTED_HARDENING_MODES "
617+
for line in self.read_file(self.source_dir / "../libcxx/CMakeLists.txt").splitlines():
618+
if line.startswith(prefix):
619+
return line[len(prefix) : -1].split()
620+
# Not found in the CMakeLists.txt, assume old version of LLVM
621+
return []
622+
614623
def configure(self, **kwargs) -> None:
615624
if "libcxx" in self.get_enabled_runtimes():
616-
if GitRepository.contains_commit(self, "64d413efdd76f2e6464ae6f578161811b9d12411", src_dir=self.source_dir):
625+
# LLVM 16+ use hardening modes instead of LIBCXX_ENABLE_ASSERTIONS
626+
# Commit 64d413efdd76f2e6464ae6f578161811b9d12411 renamed safe to extensive, which is the one we prefer.
627+
# Commit f0dfe682bca0b39d1fd64845f1576243d00c9d59 removed the old LIBCXX_ENABLE_ASSERTIONS
628+
hardening_modes = self._supported_libcxx_hardening_modes()
629+
if "extensive" in hardening_modes:
617630
self.add_cmake_options(LIBCXX_HARDENING_MODE="extensive")
618-
elif GitRepository.contains_commit(
619-
self, "f0dfe682bca0b39d1fd64845f1576243d00c9d59", src_dir=self.source_dir
620-
):
631+
elif "debug" in hardening_modes:
621632
self.add_cmake_options(LIBCXX_HARDENING_MODE="debug")
622633
else:
623634
self.add_cmake_options(LIBCXX_ENABLE_ASSERTIONS=True)

0 commit comments

Comments
 (0)