build: use Python3 for compiler-rt
authorSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 28 Apr 2020 17:25:23 +0000 (17:25 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 28 Apr 2020 17:29:04 +0000 (17:29 +0000)
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.

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

index fffaabe..8619b6e 100644 (file)
@@ -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
index 699b03a..6c8651d 100644 (file)
@@ -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}
index 60464bc..a0203c0 100644 (file)
@@ -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@")