Skip to content

Commit 965bfa5

Browse files
committed
获取python路径改为在make.js
1 parent 3ae6d85 commit 965bfa5

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

unity/cli/make.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ function selectVisualStudioGenerator() {
5353
}
5454
}
5555

56+
function tryGetPythonFromPath() {
57+
try {
58+
const out = execFileSync('python', ['-c', 'import sys; print(sys.executable)'], { encoding: 'utf8' }).trim();
59+
if (out && existsSync(out)) return { exe: out, home: dirname(out) };
60+
} catch {}
61+
return null;
62+
}
63+
5664
const platformCompileConfig = {
5765
'android': {
5866
'armv7': {
@@ -420,6 +428,12 @@ async function runPuertsMake(cwd, options) {
420428
if (options.cmake_args) {
421429
CmakeDArgs += ` ${options.cmake_args}`;
422430
}
431+
if (options.backend == 'papi-python' && options.platform == "win") {
432+
const pyInfo = tryGetPythonFromPath();
433+
if (pyInfo && pyInfo.exe) {
434+
CmakeDArgs += ` -DPython3_EXECUTABLE="${pyInfo.exe}"`;
435+
}
436+
}
423437

424438
var outputFile = BuildConfig.hook(
425439
CMAKE_BUILD_PATH,

unity/cli/test.mjs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,6 @@ function getExeSuffix() {
250250
return "";
251251
}
252252

253-
function tryGetPythonFromPath() {
254-
try {
255-
const out = execFileSync('python', ['-c', 'import sys; print(sys.executable)'], { encoding: 'utf8' }).trim();
256-
if (out && existsSync(out)) return { exe: out, home: dirname(out) };
257-
} catch {}
258-
return null;
259-
}
260-
261253
export async function dotnetTest(cwd, backend, filter = '', thread_safe = false) {
262254
// 编译binary
263255
let dlls = await runPuertsMake(join(cwd, '../../native/puerts'), {
@@ -299,14 +291,11 @@ export async function dotnetTest(cwd, backend, filter = '', thread_safe = false)
299291
});
300292
dlls = dlls.concat(nodedlls);
301293

302-
const pyInfo = tryGetPythonFromPath();
303-
304294
const pydlls = await runPuertsMake(join(cwd, '../../native/papi-python'), {
305295
platform: getPlatform(),
306296
config: "Debug",
307297
arch: process.arch,
308-
thread_safe: thread_safe,
309-
cmake_args: (pyInfo && pyInfo.exe) ? `-DPython3_EXECUTABLE="${pyInfo.exe}"` : undefined
298+
thread_safe: thread_safe
310299
});
311300
dlls = dlls.concat(pydlls);
312301

0 commit comments

Comments
 (0)