fix code-signing on macOS (#15592)

* rebase

* move if statement location

* remove whitespace

* spec to self.spec

* switch statements as per review

* fix erronous indent

* add missing cmake arg

* minor placement fix for cmake args

* edit comment

* fix erronous return

* clarify conflicts with messages

* remove duplicate comment

* simplify logic

* macos wasn't a variant, fix that

* remove extra blank line

* address reviewer comments on spaces
This commit is contained in:
Sajid Ali 2020-04-22 09:49:07 -05:00 committed by GitHub
parent 2a5592f419
commit 5f285fdd05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,6 +119,8 @@ class Llvm(CMakePackage, CudaPackage):
default=False, default=False,
description="Build with OpenMP capable thread sanitizer", description="Build with OpenMP capable thread sanitizer",
) )
variant('code_signing', default=False,
description="Enable code-signing on macOS")
variant("python", default=False, description="Install python bindings") variant("python", default=False, description="Install python bindings")
extends("python", when="+python") extends("python", when="+python")
@ -176,6 +178,20 @@ class Llvm(CMakePackage, CudaPackage):
# MLIR exists in > 10.x # MLIR exists in > 10.x
conflicts("+mlir", when="@:9") conflicts("+mlir", when="@:9")
# code signing is only necessary on macOS",
conflicts('+code_signing', when='platform=linux')
conflicts('+code_signing', when='platform=bgq')
conflicts('+code_signing', when='platform=cray')
conflicts(
'+code_signing',
when='~lldb platform=darwin',
msg="code signing is only necessary for building the "
"in-tree debug server on macOS. Turning this variant "
"off enables a build of llvm with lldb that uses the "
"system debug server",
)
# Github issue #4986 # Github issue #4986
patch("llvm_gcc7.patch", when="@4.0.0:4.0.1+lldb %gcc@7.0:") patch("llvm_gcc7.patch", when="@4.0.0:4.0.1+lldb %gcc@7.0:")
# Backport from llvm master + additional fix # Backport from llvm master + additional fix
@ -192,30 +208,30 @@ class Llvm(CMakePackage, CudaPackage):
# https://bugs.llvm.org/show_bug.cgi?id=39696 # https://bugs.llvm.org/show_bug.cgi?id=39696
patch("thread-p9.patch", when="@develop+libcxx") patch("thread-p9.patch", when="@develop+libcxx")
@run_before("cmake") @run_before('cmake')
def check_darwin_lldb_codesign_requirement(self): def codesign_check(self):
if not self.spec.satisfies("+lldb platform=darwin"): if self.spec.satisfies("+code_signing"):
return codesign = which('codesign')
codesign = which("codesign") mkdir('tmp')
mkdir("tmp") llvm_check_file = join_path('tmp', 'llvm_check')
llvm_check_file = join_path("tmp", "llvm_check") copy('/usr/bin/false', llvm_check_file)
copy("/usr/bin/false", llvm_check_file)
try: try:
codesign("-f", "-s", "lldb_codesign", "--dryrun", llvm_check_file) codesign('-f', '-s', 'lldb_codesign', '--dryrun',
llvm_check_file)
except ProcessError: except ProcessError:
# Newer LLVM versions have a simple script that sets up # Newer LLVM versions have a simple script that sets up
# automatically # automatically when run with sudo priviliges
setup = Executable("./lldb/scripts/macos-setup-codesign.sh") setup = Executable("./lldb/scripts/macos-setup-codesign.sh")
try: try:
setup() setup()
except Exception: except Exception:
raise RuntimeError( raise RuntimeError(
'The "lldb_codesign" identity must be available to build ' 'spack was unable to either find or set up'
"LLVM with LLDB. See https://lldb.llvm.org/resources/" 'code-signing on your system. Please refer to'
"build.html#code-signing-on-macos for details on how to " 'https://lldb.llvm.org/resources/build.html#'
"create this identity." 'code-signing-on-macos for details on how to'
'create this identity.'
) )
def setup_build_environment(self, env): def setup_build_environment(self, env):
@ -355,6 +371,9 @@ def cmake_args(self):
): ):
cmake_args.append("-DCMAKE_BUILD_WITH_INSTALL_RPATH=1") cmake_args.append("-DCMAKE_BUILD_WITH_INSTALL_RPATH=1")
if self.spec.satisfies("~code_signing platform=darwin"):
cmake_args.append('-DLLDB_USE_SYSTEM_DEBUGSERVER=ON')
# Semicolon seperated list of projects to enable # Semicolon seperated list of projects to enable
cmake_args.append( cmake_args.append(
"-DLLVM_ENABLE_PROJECTS:STRING={0}".format(";".join(projects)) "-DLLVM_ENABLE_PROJECTS:STRING={0}".format(";".join(projects))