From 360f35ba0b34837b7adfa88fb61355298c435adf Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Tue, 28 Apr 2020 16:41:22 -0700 Subject: [PATCH] Temporarily revert "build: use `find_package(Python3)` if available" as it seems to be causing multiple people problems with running tests and building. This reverts commit c4c3883b00d3a6aa657a5e3e515c90c9ea1f81c6. --- CMakeLists.txt | 40 ++++++++------------------------- cmake/config-ix.cmake | 2 +- cmake/modules/AddLLVM.cmake | 9 ++++---- test/lit.site.cfg.py.in | 2 +- tools/llvm-shlib/CMakeLists.txt | 2 +- 5 files changed, 17 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc86e5ac385..8bc5a9f052f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -671,38 +671,16 @@ option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default include(HandleLLVMOptions) -if(CMAKE_VERSION VERSION_LESS 3.12) - include(FindPythonInterp) - if( NOT PYTHONINTERP_FOUND ) - message(FATAL_ERROR - "Unable to find Python interpreter, required for builds and testing. +include(FindPythonInterp) +if( NOT PYTHONINTERP_FOUND ) + message(FATAL_ERROR +"Unable to find Python interpreter, required for builds and testing. - Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") - endif() +Please install Python or specify the PYTHON_EXECUTABLE CMake variable.") +endif() - if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) - message(FATAL_ERROR "Python 2.7 or newer is required") - 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() +if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 ) + message(FATAL_ERROR "Python 2.7 or newer is required") endif() ###### @@ -738,7 +716,7 @@ endif (LLVM_USE_PERF) message(STATUS "Constructing LLVMBuild project information") execute_process( - COMMAND "${Python3_EXECUTABLE}" -B ${LLVMBUILDTOOL} + COMMAND ${PYTHON_EXECUTABLE} -B ${LLVMBUILDTOOL} --native-target "${LLVM_NATIVE_ARCH}" --enable-targets "${LLVM_TARGETS_TO_BUILD}" --enable-optional-components "${LLVMOPTIONALCOMPONENTS}" diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index 777cfd628a8..d9624c42da6 100644 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -639,7 +639,7 @@ function(find_python_module module) return() endif() - execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import ${module}" + execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import ${module}" RESULT_VARIABLE status ERROR_QUIET) diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index cc1c122dce3..b77b59240eb 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -117,7 +117,7 @@ function(add_llvm_symbol_exports target_name export_file) set(native_export_file "${target_name}.def") add_custom_command(OUTPUT ${native_export_file} - COMMAND "${Python3_EXECUTABLE}" -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))" + COMMAND ${PYTHON_EXECUTABLE} -c "import sys;print(''.join(['EXPORTS\\n']+sys.stdin.readlines(),))" < ${export_file} > ${native_export_file} DEPENDS ${export_file} VERBATIM @@ -1052,7 +1052,7 @@ function(export_executable_symbols target) set(mangling itanium) endif() add_custom_command(OUTPUT ${exported_symbol_file} - COMMAND "${Python3_EXECUTABLE}" ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py --mangling=${mangling} ${static_libs} -o ${exported_symbol_file} + COMMAND ${PYTHON_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py --mangling=${mangling} ${static_libs} -o ${exported_symbol_file} WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR} DEPENDS ${LLVM_MAIN_SRC_DIR}/utils/extract_symbols.py ${static_libs} VERBATIM @@ -1453,7 +1453,7 @@ function(make_paths_relative out_pathlist basedir pathlist) # empty list entries. So escape the ;s in the list and do the splitting # ourselves. cmake has no relpath function, so use Python for that. string(REPLACE ";" "\\;" pathlist_escaped "${pathlist}") - execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "\n + execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "\n import os, sys\n base = sys.argv[1] def haslink(p):\n @@ -1528,6 +1528,7 @@ function(configure_lit_site_cfg site_in site_out) # SHLIBDIR points the build tree. string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" SHLIBDIR "${LLVM_SHLIB_OUTPUT_INTDIR}") + set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}) # FIXME: "ENABLE_SHARED" doesn't make sense, since it is used just for # plugins. We may rename it. if(LLVM_ENABLE_PLUGINS) @@ -1685,7 +1686,7 @@ function(add_lit_target target comment) ALLOW_EXTERNAL ) - set(LIT_COMMAND "${Python3_EXECUTABLE};${lit_base_dir}/${lit_file_name}") + set(LIT_COMMAND "${PYTHON_EXECUTABLE};${lit_base_dir}/${lit_file_name}") list(APPEND LIT_COMMAND ${LIT_ARGS}) foreach(param ${ARG_PARAMS}) list(APPEND LIT_COMMAND --param ${param}) diff --git a/test/lit.site.cfg.py.in b/test/lit.site.cfg.py.in index 3797830862f..ee9e5941a39 100644 --- a/test/lit.site.cfg.py.in +++ b/test/lit.site.cfg.py.in @@ -12,7 +12,7 @@ config.llvm_shlib_dir = path(r"@SHLIBDIR@") config.llvm_shlib_ext = "@SHLIBEXT@" config.llvm_exe_ext = "@EXEEXT@" config.lit_tools_dir = path(r"@LLVM_LIT_TOOLS_DIR@") -config.python_executable = "@Python3_EXECUTABLE@" +config.python_executable = "@PYTHON_EXECUTABLE@" config.gold_executable = "@GOLD_EXECUTABLE@" config.ld64_executable = "@LD64_EXECUTABLE@" config.ocamlfind_executable = "@OCAMLFIND@" diff --git a/tools/llvm-shlib/CMakeLists.txt b/tools/llvm-shlib/CMakeLists.txt index 563e4a100dc..eb42abfc1d4 100644 --- a/tools/llvm-shlib/CMakeLists.txt +++ b/tools/llvm-shlib/CMakeLists.txt @@ -164,7 +164,7 @@ if(LLVM_BUILD_LLVM_C_DYLIB AND MSVC) endif() add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE} - COMMAND "${Python3_EXECUTABLE}" ${GEN_SCRIPT} --libsfile ${LIBSFILE} ${GEN_UNDERSCORE} --nm "${llvm_nm}" -o ${LLVM_EXPORTED_SYMBOL_FILE} + COMMAND ${PYTHON_EXECUTABLE} ${GEN_SCRIPT} --libsfile ${LIBSFILE} ${GEN_UNDERSCORE} --nm "${llvm_nm}" -o ${LLVM_EXPORTED_SYMBOL_FILE} DEPENDS ${LIB_NAMES} ${llvm_nm_target} COMMENT "Generating export list for LLVM-C" VERBATIM )