xtest: Allow to specify the python interpreter

Explicitly use the interpreter when invoking python scripts
(i.e. scripts/file_to_c.py and scripts/rsp_to_gcm.py).
Previously, the default interpreter was used when the scripts
were called. Now, the interpreter is explicitly specified which
would hence override the default interpreter being used.

For android and makefile builds, $(PYTHON3) would be used.
On the other hand, for CMAKE based builds, the path to the
python interpreter is populated in the "Python_EXECUTABLE" variable
via the python package.

How it is helpful:
More explicit control over the version of python interpreters
that needs to be used.

Signed-off-by: Sadiq Hussain <sadiq.muchumarri@intel.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/Android.mk b/Android.mk
index d608598..831f821 100644
--- a/Android.mk
+++ b/Android.mk
@@ -16,6 +16,7 @@
 TA_DEV_KIT_DIR ?= ../invalid_include_path
 
 -include $(TA_DEV_KIT_DIR)/host_include/conf.mk
+include scripts/common.mk
 
 ################################################################################
 # Build xtest                                                                  #
@@ -74,7 +75,7 @@
 define my-embed-file
 $(TARGET_OUT_HEADERS)/$(1).h: $(LOCAL_PATH)/$(2)
 	@echo '  GEN     $$@'
-	@$(LOCAL_PATH)/scripts/file_to_c.py --inf $$< --out $$@ --name $(1)
+	@$(PYTHON3) $(LOCAL_PATH)/scripts/file_to_c.py --inf $$< --out $$@ --name $(1)
 
 LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT_HEADERS)/$(1).h
 
diff --git a/host/xtest/CMakeLists.txt b/host/xtest/CMakeLists.txt
index 7442425..4c7737e 100644
--- a/host/xtest/CMakeLists.txt
+++ b/host/xtest/CMakeLists.txt
@@ -16,12 +16,17 @@
 	set (OPENSSL_PRIVATE_LINK OpenSSL::Crypto)
 endif()
 
+find_package(Python COMPONENTS Interpreter Development)
+if(NOT Python_Interpreter_FOUND)
+	message(FATAL_ERROR "Python interpreter not found")
+endif()
+
 include(GNUInstallDirs)
 
 macro(EMBED_8100FILE prefix infile)
 	add_custom_command(
 		OUTPUT  regression_8100_${prefix}.h
-		COMMAND ${OPTEE_TEST_ROOT_DIR}/scripts/file_to_c.py --inf ${infile}
+		COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/file_to_c.py --inf ${infile}
 	--out ${CMAKE_CURRENT_BINARY_DIR}/regression_8100_${prefix}.h
 	--name regression_8100_${prefix}
 		DEPENDS ${OPTEE_TEST_ROOT_DIR}/scripts/file_to_c.py ${infile}
diff --git a/host/xtest/Makefile b/host/xtest/Makefile
index ae6e21c..0040914 100644
--- a/host/xtest/Makefile
+++ b/host/xtest/Makefile
@@ -193,7 +193,7 @@
 
 $(out-dir)/xtest/$(1).h: $(out-dir)/$(1).rsp
 	@echo '  GEN     $$@'
-	$(q)../../scripts/rsp_to_gcm_test.py --inf $$< --outf $$@ --mode=$(2) \
+	$(q)$(PYTHON3) ../../scripts/rsp_to_gcm_test.py --inf $$< --outf $$@ --mode=$(2) \
 		$(if $(filter y,$(CFG_GCM_NIST_VECTORS_LIMITED)),--limited)
 
 $(CURDIR)/regression_4000.c: $(out-dir)/xtest/$(1).h
@@ -210,7 +210,7 @@
 
 $(out-dir)/xtest/$(1).h: $(2)
 	@echo '  GEN     $$@'
-	$(q)../../scripts/file_to_c.py --inf $$< --out $$@ --name $(1)
+	$(q)$(PYTHON3) ../../scripts/file_to_c.py --inf $$< --out $$@ --name $(1)
 
 $(CURDIR)/regression_8100.c: $(out-dir)/xtest/$(1).h
 endef
diff --git a/scripts/common.mk b/scripts/common.mk
index 103a415..fb5eb3e 100644
--- a/scripts/common.mk
+++ b/scripts/common.mk
@@ -7,3 +7,5 @@
 $(eval _o := $(patsubst %/,%,$(patsubst %/.,%,$(1))))$(if \
 	$(filter-out $(1),$(_o)),$(call strip-trailing-slashes-and-dots,$(_o)),$(_o))
 endef
+
+PYTHON3 ?= python3