From 21aa270b1707d797622453131b47fec46db548b4 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 11 Dec 2022 17:44:36 +0100 Subject: [PATCH] fix: don't override `AGENT_TOOLSDIRECTORY` if it's not needed `AGENT_TOOLSDIRECTORY` is always overriden on macOS. This seems to be needed because CPython < 3.11 x64 builds are not relocatable. It means this is not needed for PyPy and also not needed when targetting macOS arm64 runners. --- dist/setup/index.js | 20 +++++++++++--------- src/setup-python.ts | 30 +++++++++++++++++------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 6cf4871db..0b00d1e63 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -66896,21 +66896,23 @@ function resolveVersionInput() { function run() { var _a; return __awaiter(this, void 0, void 0, function* () { - if (utils_1.IS_MAC) { - process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; - } - if ((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim()) { - process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; - } - core.debug(`Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`); try { const version = resolveVersionInput(); - const checkLatest = core.getBooleanInput('check-latest'); if (version) { let pythonVersion; const arch = core.getInput('architecture') || os.arch(); const updateEnvironment = core.getBooleanInput('update-environment'); - if (isPyPyVersion(version)) { + const checkLatest = core.getBooleanInput('check-latest'); + const isPyPy = isPyPyVersion(version); + const forceMacToolsDirectory = utils_1.IS_MAC && !isPyPy && arch === 'x64'; + if (forceMacToolsDirectory) { + process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; + } + if ((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim()) { + process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; + } + core.debug(`Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}`); + if (isPyPy) { const installed = yield finderPyPy.findPyPyVersion(version, arch, updateEnvironment, checkLatest); pythonVersion = `${installed.resolvedPyPyVersion}-${installed.resolvedPythonVersion}`; core.info(`Successfully set up PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`); diff --git a/src/setup-python.ts b/src/setup-python.ts index d6e6bdaf0..1c2792418 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -63,26 +63,30 @@ function resolveVersionInput(): string { } async function run() { - if (IS_MAC) { - process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; - } - - if (process.env.AGENT_TOOLSDIRECTORY?.trim()) { - process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; - } - - core.debug( - `Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}` - ); try { const version = resolveVersionInput(); - const checkLatest = core.getBooleanInput('check-latest'); if (version) { let pythonVersion: string; const arch: string = core.getInput('architecture') || os.arch(); const updateEnvironment = core.getBooleanInput('update-environment'); - if (isPyPyVersion(version)) { + const checkLatest = core.getBooleanInput('check-latest'); + const isPyPy = isPyPyVersion(version); + const forceMacToolsDirectory = IS_MAC && !isPyPy && arch === 'x64'; + + if (forceMacToolsDirectory) { + process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache'; + } + + if (process.env.AGENT_TOOLSDIRECTORY?.trim()) { + process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY']; + } + + core.debug( + `Python is expected to be installed into ${process.env['RUNNER_TOOL_CACHE']}` + ); + + if (isPyPy) { const installed = await finderPyPy.findPyPyVersion( version, arch,