mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-14 02:28:03 +08:00
[scripts] More isolation for VFAP(PYTHON3) (#41874)
This commit is contained in:
parent
f71a7bb13d
commit
7812310b2b
@ -26,13 +26,14 @@ if(CMAKE_HOST_WIN32)
|
||||
set(download_sha512 15542080E0CC25C574391218107FE843006E8C5A7161D1CD48CF14A3C47155C0244587273D9C747F35B15EA17676869ECCE079214824214C1A62ABFC86AD9F9B)
|
||||
endif()
|
||||
|
||||
# Remove this after the next update
|
||||
string(APPEND tool_subdirectory "-1")
|
||||
|
||||
set(paths_to_search "${DOWNLOADS}/tools/python/${tool_subdirectory}")
|
||||
|
||||
# We want to be able to import stuff from outside of this embeddable package.
|
||||
# https://docs.python.org/3/library/sys_path_init.html#pth-files
|
||||
string(REGEX MATCH "^3\\.[0-9]+" _python_version_plain "${program_version}")
|
||||
string(REPLACE "." "" _python_version_plain "${_python_version_plain}")
|
||||
vcpkg_list(SET post_install_command "${CMAKE_COMMAND}" -E rm "python${_python_version_plain}._pth")
|
||||
vcpkg_list(SET post_install_command
|
||||
"${CMAKE_COMMAND}" "-DPYTHON_DIR=${paths_to_search}" "-DPYTHON_VERSION=${program_version}" -P "${CMAKE_CURRENT_LIST_DIR}/z_vcpkg_make_python_less_embedded.cmake"
|
||||
)
|
||||
else()
|
||||
set(program_name python3)
|
||||
set(brew_package_name "python")
|
||||
|
20
scripts/cmake/z_vcpkg_make_python_less_embedded.cmake
Normal file
20
scripts/cmake/z_vcpkg_make_python_less_embedded.cmake
Normal file
@ -0,0 +1,20 @@
|
||||
if(NOT DEFINED PYTHON_VERSION)
|
||||
message(FATAL_ERROR "PYTHON_VERSION should be defined.")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED PYTHON_DIR)
|
||||
message(FATAL_ERROR "PYTHON_DIR should be defined.")
|
||||
endif()
|
||||
|
||||
# We want to be able to import stuff from outside of this embeddable package.
|
||||
# https://docs.python.org/3/library/sys_path_init.html#pth-files
|
||||
string(REGEX MATCH "^3\\.[0-9]+" _python_version_plain "${PYTHON_VERSION}")
|
||||
string(REPLACE "." "" _python_version_plain "${_python_version_plain}")
|
||||
file(REMOVE "${PYTHON_DIR}/python${_python_version_plain}._pth")
|
||||
|
||||
# Since this embeddable package is not isolated anymore, we should make sure
|
||||
# it doesn't accidentally pick up stuff from windows registry.
|
||||
file(WRITE "${PYTHON_DIR}/sitecustomize.py" [[import os
|
||||
import sys
|
||||
sys.path.insert(1, os.path.dirname(os.path.realpath(__file__)))
|
||||
]])
|
Loading…
x
Reference in New Issue
Block a user