Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Install rubyinstaller-head version with Devkit #198

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs')
const util = require('util')
const stream = require('stream')
const crypto = require('crypto')
const child_process = require('child_process')
const core = require('@actions/core')
const { performance } = require('perf_hooks')

Expand Down Expand Up @@ -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)
Expand All @@ -168,13 +176,27 @@ export function setupPath(newPathEntries) {
}

// Then add new path entries using core.addPath()
let newPath
let newPath = newPathEntries
if (windows) {
// 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']
newPath = [...newPathEntries, ...msys2]
} else {
newPath = newPathEntries
try {
// Use RubyInstaller mechanisms to set various evenironment variables including the PATH to MSYS2 tools
// Same as "ridk enable" on the command line
const envbuf = child_process.execFileSync(`${newPathEntries[0]}\\ruby`, ['-rruby_installer/runtime', '-e', 'puts RubyInstaller::Runtime.msys2_installation.enable_msys_apps_per_cmd'])
const envvars = envbuf.toString().trim().split(/\r?\n/)

envvars.forEach( (envvar) => {
console.log(`SET ${envvar}`)
const parts = envvar.split("=", 2)
core.exportVariable(parts[0], parts[1])
})
} catch (ex) {
// 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\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin']
newPath = [...newPathEntries, ...msys2]
}
}
console.log(`Entries added to ${envPath} to use selected Ruby:`)
for (const entry of newPath) {
Expand Down
58 changes: 43 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generate-windows-versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[version, entry[:href]]
}.to_h

versions['head'] = 'https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-head-x64.7z'
versions['head'] = 'https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-devkit-head-x64.exe'
versions['mingw'] = 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mingw.7z'
versions['mswin'] = 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mswin.7z'

Expand Down
2 changes: 1 addition & 1 deletion windows-versions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export function getAvailableVersions(platform, engine) {
export async function install(platform, engine, version) {
const url = rubyInstallerVersions[version]

if (!url.endsWith('.7z')) {
throw new Error(`URL should end in .7z: ${url}`)
if (!url.endsWith('.7z') && !url.endsWith('.exe')) {
throw new Error(`URL should end in .7z or .exe: ${url}`)
}
const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length)
const base = url.slice(url.lastIndexOf('/') + 1, url.length).replace(/\.(exe|7z)$/, "")

let rubyPrefix, inToolCache
if (common.shouldUseToolCache(engine, version)) {
Expand All @@ -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
}

Expand All @@ -64,11 +64,17 @@ async function downloadAndExtract(engine, version, url, base, rubyPrefix) {

const downloadPath = await common.measure('Downloading Ruby', async () => {
console.log(url)
return await tc.downloadTool(url)
const fname = url.slice(url.lastIndexOf('/') + 1, url.length)
return await tc.downloadTool(url, fname)
})

await common.measure('Extracting Ruby', async () =>
exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true }))
await common.measure('Extracting Ruby', async () => {
if (url.endsWith('.7z')) {
await exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true })
} else if (url.endsWith('.exe')) {
await exec.exec('cmd', ['/c', `${downloadPath} /verysilent /dir=${parentDir}\\${base} /tasks=noassocfiles,nomodpath,noridkinstall /components=ruby,msys2`])
}
})

if (base !== path.basename(rubyPrefix)) {
await io.mv(path.join(parentDir, base), rubyPrefix)
Expand Down