[libclc] 1c1a810 - libclc: Use find_package to find Python 3 and require it

Aaron Puchert via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 13:32:30 PDT 2020


Author: Aaron Puchert
Date: 2020-10-01T22:31:33+02:00
New Revision: 1c1a8105580784c96212db1afc097a844740bc69

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

LOG: libclc: Use find_package to find Python 3 and require it

The script's shebang wants Python 3, so we use FindPython3. The
original code didn't work when an unversioned python was not available.
This is explicitly allowed in PEP 394. ("Distributors may choose to set
the behavior of the python command as follows: python2, python3, not
provide python command, allow python to be configurable by an end user
or a system administrator.")

Also I think it's actually required, so let the configuration fail if we
can't find it.

Lastly remove the shebang, since the script is only run via interpreter
and doesn't have the executable bit set anyway.

Reviewed By: jvesely

Differential Revision: https://reviews.llvm.org/D88366

Added: 
    

Modified: 
    libclc/CMakeLists.txt
    libclc/generic/lib/gen_convert.py

Removed: 
    


################################################################################
diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 1a77a378e192..b8b5ceff086c 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -184,11 +184,11 @@ if( ENABLE_RUNTIME_SUBNORMAL )
 		DESTINATION ${CMAKE_INSTALL_DATADIR}/clc )
 endif()
 
-find_program( PYTHON python )
+find_package( Python3 REQUIRED COMPONENTS Interpreter )
 file( TO_CMAKE_PATH ${CMAKE_SOURCE_DIR}/generic/lib/gen_convert.py script_loc )
 add_custom_command(
 	OUTPUT convert.cl
-	COMMAND ${PYTHON} ${script_loc} > convert.cl
+	COMMAND ${Python3_EXECUTABLE} ${script_loc} > convert.cl
 	DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 

diff  --git a/libclc/generic/lib/gen_convert.py b/libclc/generic/lib/gen_convert.py
index 5c87fcbe1aba..7e649faa7dfc 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python3
-
 # OpenCL built-in library: type conversion functions
 #
 # Copyright (c) 2013 Victor Oliveira <victormatheus at gmail.com>


        


More information about the cfe-commits mailing list