[compiler-rt] a5d79e5 - build: use Python3 for compiler-rt

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 28 10:29:57 PDT 2020


Author: Saleem Abdulrasool
Date: 2020-04-28T17:29:04Z
New Revision: a5d79e5fa14f8c9aea9d731637e37f57598847ab

URL: https://github.com/llvm/llvm-project/commit/a5d79e5fa14f8c9aea9d731637e37f57598847ab
DIFF: https://github.com/llvm/llvm-project/commit/a5d79e5fa14f8c9aea9d731637e37f57598847ab.diff

LOG: build: use Python3 for compiler-rt

compiler-rt is built in a unified configuration on some of the builders
which requires that this is updated to follow the same pattern as LLVM.

Added: 
    

Modified: 
    compiler-rt/CMakeLists.txt
    compiler-rt/cmake/Modules/SanitizerUtils.cmake
    compiler-rt/test/lit.common.configured.in

Removed: 
    


################################################################################
diff  --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index fffaabe97ef0..8619b6e6280c 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -81,12 +81,34 @@ if (COMPILER_RT_STANDALONE_BUILD)
     set_target_properties(intrinsics_gen PROPERTIES FOLDER "Compiler-RT Misc")
   endif()
 
-  # Find Python interpreter.
-  include(FindPythonInterp)
-  if(NOT PYTHONINTERP_FOUND)
-    message(FATAL_ERROR "
-      Unable to find Python interpreter required testing. Please install Python
-      or specify the PYTHON_EXECUTABLE CMake variable.")
+  if(CMAKE_VERSION VERSION_LESS 3.12)
+    # Find Python interpreter.
+    include(FindPythonInterp)
+    if(NOT PYTHONINTERP_FOUND)
+      message(FATAL_ERROR "
+        Unable to find Python interpreter required testing. Please install Python
+        or specify the PYTHON_EXECUTABLE CMake variable.")
+    endif()
+
+    add_executable(Python3::Interpreter IMPORTED)
+    set_target_properties(Python3::Interpreter PROPERTIES
+      IMPORTED_LOCATION ${PYTHON_EXECUTABLE})
+    set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
+  else()
+    find_package(Python3 COMPONENTS Interpreter)
+    if(NOT Python3_Interpreter_FOUND)
+      message(WARNING "Python3 not found, using python2 as a fallback")
+      find_package(Python2 COMPONENTS Interpreter REQUIRED)
+      if(Python2_VERSION VERSION_LESS 2.7)
+        message(SEND_ERROR "Python 2.7 or newer is required")
+      endif()
+
+      # Treat python2 as python3
+      add_executable(Python3::Interpreter IMPORTED)
+      set_target_properties(Python3::Interpreter PROPERTIES
+        IMPORTED_LOCATION ${Python2_EXECUTABLE})
+      set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
+    endif()
   endif()
 
   # Ensure that fat libraries are built correctly on Darwin

diff  --git a/compiler-rt/cmake/Modules/SanitizerUtils.cmake b/compiler-rt/cmake/Modules/SanitizerUtils.cmake
index 699b03ae6a11..6c8651df3b3c 100644
--- a/compiler-rt/cmake/Modules/SanitizerUtils.cmake
+++ b/compiler-rt/cmake/Modules/SanitizerUtils.cmake
@@ -34,7 +34,7 @@ macro(add_sanitizer_rt_symbols name)
       list(APPEND extra_args "--extra" ${arg})
     endforeach()
     add_custom_command(OUTPUT ${stamp}
-      COMMAND ${PYTHON_EXECUTABLE}
+      COMMAND ${Python3_EXECUTABLE}
         ${SANITIZER_GEN_DYNAMIC_LIST} ${extra_args} $<TARGET_FILE:${target_name}>
         --nm-executable "${SANITIZER_NM}" -o $<TARGET_FILE:${target_name}>.syms
       COMMAND ${CMAKE_COMMAND} -E touch ${stamp}
@@ -84,7 +84,7 @@ macro(add_sanitizer_rt_version_list name)
     list(APPEND args "$<TARGET_FILE:${arg}>")
   endforeach()
   add_custom_command(OUTPUT ${vers}
-    COMMAND ${PYTHON_EXECUTABLE}
+    COMMAND ${Python3_EXECUTABLE}
       ${SANITIZER_GEN_DYNAMIC_LIST} --version-list ${args}
       --nm-executable "${SANITIZER_NM}" -o ${vers}
     DEPENDS ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA} ${ARG_LIBS}
@@ -100,7 +100,7 @@ endmacro()
 if(CMAKE_HOST_UNIX AND NOT OS_NAME MATCHES "OpenBSD")
   add_custom_target(SanitizerLintCheck
     COMMAND env LLVM_CHECKOUT=${LLVM_MAIN_SRC_DIR} SILENT=1 TMPDIR=
-      PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
+      PYTHON_EXECUTABLE=${Python3_EXECUTABLE}
       COMPILER_RT=${COMPILER_RT_SOURCE_DIR}
       ${SANITIZER_LINT_SCRIPT}
     DEPENDS ${SANITIZER_LINT_SCRIPT}

diff  --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in
index 60464bcdaa87..a0203c085565 100644
--- a/compiler-rt/test/lit.common.configured.in
+++ b/compiler-rt/test/lit.common.configured.in
@@ -22,7 +22,7 @@ set_default("llvm_shlib_dir", "@LLVM_LIBRARY_OUTPUT_INTDIR@")
 set_default("gold_executable", "@GOLD_EXECUTABLE@")
 set_default("clang", "@COMPILER_RT_RESOLVED_TEST_COMPILER@")
 set_default("compiler_id", "@COMPILER_RT_TEST_COMPILER_ID@")
-set_default("python_executable", "@PYTHON_EXECUTABLE@")
+set_default("python_executable", "@Python3_EXECUTABLE@")
 set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@)
 set_default("compiler_rt_intercept_libdispatch", @COMPILER_RT_INTERCEPT_LIBDISPATCH_PYBOOL@)
 set_default("compiler_rt_libdir", "@COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR@")


        


More information about the llvm-commits mailing list