diff --git a/common.js b/common.js index 9153130c1..4d33d35a0 100644 --- a/common.js +++ b/common.js @@ -1,6 +1,7 @@ const os = require('os') const path = require('path') const fs = require('fs') +const cp = require('child_process') const util = require('util') const stream = require('stream') const crypto = require('crypto') @@ -149,6 +150,13 @@ export function win2nix(path) { return path.replace(/\\/g, '/').replace(/ /g, '\\ ') } +// JRuby is installed after setupPath is called, so folder doesn't exist +function rubyIsUCRT(path) { + return !!(fs.existsSync(path) && + fs.readdirSync(path, { withFileTypes: true }).find(dirent => + dirent.isFile() && dirent.name.match(/^x64-ucrt-ruby\d{3}\.dll$/))) +} + export function setupPath(newPathEntries) { const envPath = windows ? 'Path' : 'PATH' const originalPath = process.env[envPath].split(path.delimiter) @@ -170,8 +178,11 @@ export function setupPath(newPathEntries) { // Then add new path entries using core.addPath() let newPath if (windows) { + // main Ruby dll determines whether mingw or ucrt build + let build_sys = rubyIsUCRT(newPathEntries[0]) ? 'ucrt64' : 'mingw64' + // add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain - const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin'] + const msys2 = [`C:\\msys64\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] newPath = [...newPathEntries, ...msys2] } else { newPath = newPathEntries diff --git a/dist/index.js b/dist/index.js index 9cc41f932..89eb3162b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -242,6 +242,7 @@ __nccwpck_require__.r(__webpack_exports__); const os = __nccwpck_require__(2087) const path = __nccwpck_require__(5622) const fs = __nccwpck_require__(5747) +const cp = __nccwpck_require__(3129) const util = __nccwpck_require__(1669) const stream = __nccwpck_require__(2413) const crypto = __nccwpck_require__(6417) @@ -390,6 +391,13 @@ function win2nix(path) { return path.replace(/\\/g, '/').replace(/ /g, '\\ ') } +// JRuby is installed after setupPath is called, so folder doesn't exist +function rubyIsUCRT(path) { + return !!(fs.existsSync(path) && + fs.readdirSync(path, { withFileTypes: true }).find(dirent => + dirent.isFile() && dirent.name.match(/^x64-ucrt-ruby\d{3}\.dll$/))) +} + function setupPath(newPathEntries) { const envPath = windows ? 'Path' : 'PATH' const originalPath = process.env[envPath].split(path.delimiter) @@ -411,8 +419,11 @@ function setupPath(newPathEntries) { // Then add new path entries using core.addPath() let newPath if (windows) { + // main Ruby dll determines whether mingw or ucrt build + let build_sys = rubyIsUCRT(newPathEntries[0]) ? 'ucrt64' : 'mingw64' + // add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain - const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin'] + const msys2 = [`C:\\msys64\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] newPath = [...newPathEntries, ...msys2] } else { newPath = newPathEntries @@ -59003,12 +59014,12 @@ async function install(platform, engine, version) { let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version) - common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) - if (!inToolCache) { await downloadAndExtract(engine, version, url, base, rubyPrefix); } + common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) + return rubyPrefix } diff --git a/windows.js b/windows.js index e88411fd5..d9e978849 100644 --- a/windows.js +++ b/windows.js @@ -50,12 +50,12 @@ export async function install(platform, engine, version) { let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version) - common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) - if (!inToolCache) { await downloadAndExtract(engine, version, url, base, rubyPrefix); } + common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) + return rubyPrefix }