Skip to content

Commit

Permalink
Fix detection of libc++ hardening mode support without git history
Browse files Browse the repository at this point in the 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.
  • Loading branch information
arichardson committed Jan 15, 2025
1 parent e4a50ce commit dc2953d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pycheribuild/projects/cross/libcxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,24 @@ def setup_config_options(cls, **kwargs):
kind=int,
)

def _supported_libcxx_hardening_modes(self) -> "list[str]":
# We may have a partial history, so prefer scanning the CMakeLists.txt
prefix = "set(LIBCXX_SUPPORTED_HARDENING_MODES "
for line in self.read_file(self.source_dir / "../libcxx/CMakeLists.txt").splitlines():
if line.startswith(prefix):
return line[len(prefix) : -1].split()
# Not found in the CMakeLists.txt, assume old version of LLVM
return []

def configure(self, **kwargs) -> None:
if "libcxx" in self.get_enabled_runtimes():
if GitRepository.contains_commit(self, "64d413efdd76f2e6464ae6f578161811b9d12411", src_dir=self.source_dir):
# LLVM 16+ use hardening modes instead of LIBCXX_ENABLE_ASSERTIONS
# Commit 64d413efdd76f2e6464ae6f578161811b9d12411 renamed safe to extensive, which is the one we prefer.
# Commit f0dfe682bca0b39d1fd64845f1576243d00c9d59 removed the old LIBCXX_ENABLE_ASSERTIONS
hardening_modes = self._supported_libcxx_hardening_modes()
if "extensive" in hardening_modes:
self.add_cmake_options(LIBCXX_HARDENING_MODE="extensive")
elif GitRepository.contains_commit(
self, "f0dfe682bca0b39d1fd64845f1576243d00c9d59", src_dir=self.source_dir
):
elif "debug" in hardening_modes:
self.add_cmake_options(LIBCXX_HARDENING_MODE="debug")
else:
self.add_cmake_options(LIBCXX_ENABLE_ASSERTIONS=True)
Expand Down

0 comments on commit dc2953d

Please sign in to comment.