Skip to content

Commit

Permalink
Add architecture input check for PyPy for Windows platform (#520)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Vladimir Safonkin authored Oct 18, 2022
1 parent 13ae5bb commit 8bcd256
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
23 changes: 15 additions & 8 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -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,
Expand All @@ -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;
}


/***/ }),
Expand Down
25 changes: 16 additions & 9 deletions src/install-pypy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import fs from 'fs';

import {
IS_WINDOWS,
WINDOWS_ARCHS,
WINDOWS_PLATFORMS,
IPyPyManifestRelease,
createSymlinkInFolder,
Expand Down Expand Up @@ -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;
});
Expand All @@ -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 {
Expand All @@ -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
);
}

Expand All @@ -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
);
}

Expand All @@ -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;
}

0 comments on commit 8bcd256

Please sign in to comment.