1
0
Fork 0
mirror of https://github.com/actions/setup-python.git synced 2024-11-25 09:58:36 +00:00

Add architecture input check for PyPy for Windows platform (#520)

* Revert cache index.js

* build cache index file

* Refactor

* Debug

* Debug

* Debug

* Debug

* Debug

* Debug

* Debug

* Debug

* Format code

* Rebuild dist

* Minor refactor

* Format code

* Minor fixes

* Check platform firstly
This commit is contained in:
Vladimir Safonkin 2022-10-18 11:01:15 +02:00 committed by GitHub
parent 13ae5bb136
commit 8bcd2560e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 17 deletions

23
dist/setup/index.js vendored
View file

@ -66577,7 +66577,7 @@ function findRelease(releases, pythonVersion, pypyVersion, architecture) {
semver.satisfies(pypyVersionToSemantic(item.pypy_version), pypyVersion);
const isArchPresent = item.files &&
(utils_1.IS_WINDOWS
? isArchPresentForWindows(item)
? isArchPresentForWindows(item, architecture)
: isArchPresentForMacOrLinux(item, architecture, process.platform));
return isPythonVersionSatisfied && isPyPyVersionSatisfied && isArchPresent;
});
@ -66590,7 +66590,7 @@ function findRelease(releases, pythonVersion, pypyVersion, architecture) {
});
const foundRelease = sortedReleases[0];
const foundAsset = utils_1.IS_WINDOWS
? findAssetForWindows(foundRelease)
? findAssetForWindows(foundRelease, architecture)
: findAssetForMacOrLinux(foundRelease, architecture, process.platform);
return {
foundAsset,
@ -66613,24 +66613,31 @@ function pypyVersionToSemantic(versionSpec) {
return versionSpec.replace(prereleaseVersion, '$1-$2.$3');
}
exports.pypyVersionToSemantic = pypyVersionToSemantic;
function isArchPresentForWindows(item) {
return item.files.some((file) => utils_1.WINDOWS_ARCHS.includes(file.arch) &&
utils_1.WINDOWS_PLATFORMS.includes(file.platform));
function isArchPresentForWindows(item, architecture) {
architecture = replaceX32toX86(architecture);
return item.files.some((file) => utils_1.WINDOWS_PLATFORMS.includes(file.platform) && file.arch === architecture);
}
exports.isArchPresentForWindows = isArchPresentForWindows;
function isArchPresentForMacOrLinux(item, architecture, platform) {
return item.files.some((file) => file.arch === architecture && file.platform === platform);
}
exports.isArchPresentForMacOrLinux = isArchPresentForMacOrLinux;
function findAssetForWindows(releases) {
return releases.files.find((item) => utils_1.WINDOWS_ARCHS.includes(item.arch) &&
utils_1.WINDOWS_PLATFORMS.includes(item.platform));
function findAssetForWindows(releases, architecture) {
architecture = replaceX32toX86(architecture);
return releases.files.find((item) => utils_1.WINDOWS_PLATFORMS.includes(item.platform) && item.arch === architecture);
}
exports.findAssetForWindows = findAssetForWindows;
function findAssetForMacOrLinux(releases, architecture, platform) {
return releases.files.find((item) => item.arch === architecture && item.platform === platform);
}
exports.findAssetForMacOrLinux = findAssetForMacOrLinux;
function replaceX32toX86(architecture) {
// convert x32 to x86 because os.arch() returns x32 for 32-bit systems but PyPy releases json has x86 arch value.
if (architecture === 'x32') {
architecture = 'x86';
}
return architecture;
}
/***/ }),

View file

@ -8,7 +8,6 @@ import fs from 'fs';
import {
IS_WINDOWS,
WINDOWS_ARCHS,
WINDOWS_PLATFORMS,
IPyPyManifestRelease,
createSymlinkInFolder,
@ -157,7 +156,7 @@ export function findRelease(
const isArchPresent =
item.files &&
(IS_WINDOWS
? isArchPresentForWindows(item)
? isArchPresentForWindows(item, architecture)
: isArchPresentForMacOrLinux(item, architecture, process.platform));
return isPythonVersionSatisfied && isPyPyVersionSatisfied && isArchPresent;
});
@ -181,7 +180,7 @@ export function findRelease(
const foundRelease = sortedReleases[0];
const foundAsset = IS_WINDOWS
? findAssetForWindows(foundRelease)
? findAssetForWindows(foundRelease, architecture)
: findAssetForMacOrLinux(foundRelease, architecture, process.platform);
return {
@ -205,11 +204,11 @@ export function pypyVersionToSemantic(versionSpec: string) {
return versionSpec.replace(prereleaseVersion, '$1-$2.$3');
}
export function isArchPresentForWindows(item: any) {
export function isArchPresentForWindows(item: any, architecture: string) {
architecture = replaceX32toX86(architecture);
return item.files.some(
(file: any) =>
WINDOWS_ARCHS.includes(file.arch) &&
WINDOWS_PLATFORMS.includes(file.platform)
WINDOWS_PLATFORMS.includes(file.platform) && file.arch === architecture
);
}
@ -223,11 +222,11 @@ export function isArchPresentForMacOrLinux(
);
}
export function findAssetForWindows(releases: any) {
export function findAssetForWindows(releases: any, architecture: string) {
architecture = replaceX32toX86(architecture);
return releases.files.find(
(item: any) =>
WINDOWS_ARCHS.includes(item.arch) &&
WINDOWS_PLATFORMS.includes(item.platform)
WINDOWS_PLATFORMS.includes(item.platform) && item.arch === architecture
);
}
@ -240,3 +239,11 @@ export function findAssetForMacOrLinux(
(item: any) => item.arch === architecture && item.platform === platform
);
}
function replaceX32toX86(architecture: string): string {
// convert x32 to x86 because os.arch() returns x32 for 32-bit systems but PyPy releases json has x86 arch value.
if (architecture === 'x32') {
architecture = 'x86';
}
return architecture;
}