@@ -2,8 +2,9 @@ import { cp, exec, mkdir, rm } from "@puerts/shell-util";
22import assert from "assert" ;
33import { existsSync , readFileSync , writeFileSync } from "fs" ;
44import glob from "glob" ;
5- import { basename , extname , join , relative } from "path" ;
5+ import { basename , extname , join , relative , dirname } from "path" ;
66import runPuertsMake from "./make.mjs" ;
7+ import { execFileSync , spawnSync } from "child_process" ;
78
89////////////// dotnet-test
910function collectCSFilesAndMakeCompileConfig ( dir , workdir , excludeGenerator ) {
@@ -209,6 +210,14 @@ function getExeSuffix() {
209210 return "" ;
210211}
211212
213+ function tryGetPythonFromPath ( ) {
214+ try {
215+ const out = execFileSync ( 'python' , [ '-c' , 'import sys; print(sys.executable)' ] , { encoding : 'utf8' } ) . trim ( ) ;
216+ if ( out && existsSync ( out ) ) return { exe : out , home : dirname ( out ) } ;
217+ } catch { }
218+ return null ;
219+ }
220+
212221export async function dotnetTest ( cwd , backend , filter = '' , thread_safe = false ) {
213222 // 编译binary
214223 let dlls = await runPuertsMake ( join ( cwd , '../../native/puerts' ) , {
@@ -250,11 +259,14 @@ export async function dotnetTest(cwd, backend, filter = '', thread_safe = false)
250259 } ) ;
251260 dlls = dlls . concat ( nodedlls ) ;
252261
262+ const pyInfo = tryGetPythonFromPath ( ) ;
263+
253264 const pydlls = await runPuertsMake ( join ( cwd , '../../native/papi-python' ) , {
254265 platform : getPlatform ( ) ,
255266 config : "Debug" ,
256267 arch : process . arch ,
257- thread_safe : thread_safe
268+ thread_safe : thread_safe ,
269+ cmake_args : ( pyInfo && pyInfo . exe ) ? `-DPython3_EXECUTABLE="${ pyInfo . exe } "` : undefined
258270 } ) ;
259271 dlls = dlls . concat ( pydlls ) ;
260272
0 commit comments