mirror of https://github.com/aminya/setup-cpp
Merge pull request #262 from aminya/downloader [skip ci]
This commit is contained in:
commit
42d0df7db6
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -126,7 +126,8 @@
|
||||||
"untildify-user": "workspace:*",
|
"untildify-user": "workspace:*",
|
||||||
"util.types": "^0.0.2",
|
"util.types": "^0.0.2",
|
||||||
"web-streams-polyfill": "^4.0.0",
|
"web-streams-polyfill": "^4.0.0",
|
||||||
"which": "^4.0.0"
|
"which": "^4.0.0",
|
||||||
|
"node-downloader-helper": "2.1.9"
|
||||||
},
|
},
|
||||||
"productionDependencies": [
|
"productionDependencies": [
|
||||||
"@actions/core",
|
"@actions/core",
|
||||||
|
@ -148,6 +149,7 @@
|
||||||
"micro-memoize",
|
"micro-memoize",
|
||||||
"mri",
|
"mri",
|
||||||
"msvc-dev-cmd",
|
"msvc-dev-cmd",
|
||||||
|
"node-downloader-helper",
|
||||||
"numerous",
|
"numerous",
|
||||||
"envosman",
|
"envosman",
|
||||||
"path-exists",
|
"path-exists",
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
"envosman": "workspace:*",
|
"envosman": "workspace:*",
|
||||||
"which": "4.0.0",
|
"which": "4.0.0",
|
||||||
"execa": "^7.2.0",
|
"execa": "^7.2.0",
|
||||||
"escape-string-regexp": "^5.0.0"
|
"escape-string-regexp": "^5.0.0",
|
||||||
|
"node-downloader-helper": "2.1.9"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { tmpdir } from "os"
|
||||||
import { execRoot, execRootSync } from "admina"
|
import { execRoot, execRootSync } from "admina"
|
||||||
import { warning } from "ci-log"
|
import { warning } from "ci-log"
|
||||||
import { execa } from "execa"
|
import { DownloaderHelper } from "node-downloader-helper"
|
||||||
import { pathExists } from "path-exists"
|
import { pathExists } from "path-exists"
|
||||||
import { installAptPack } from "./install.js"
|
import { installAptPack } from "./install.js"
|
||||||
|
|
||||||
|
@ -53,8 +54,14 @@ export async function addAptKeyViaDownload(name: string, url: string) {
|
||||||
const fileName = `/etc/apt/trusted.gpg.d/${name}`
|
const fileName = `/etc/apt/trusted.gpg.d/${name}`
|
||||||
if (!(await pathExists(fileName))) {
|
if (!(await pathExists(fileName))) {
|
||||||
initGpg()
|
initGpg()
|
||||||
await installAptPack([{ name: "curl" }, { name: "ca-certificates" }], undefined)
|
|
||||||
await execa("curl", ["-s", url, "-o", `/tmp/${name}`])
|
await installAptPack([{ name: "ca-certificates" }])
|
||||||
|
const dl = new DownloaderHelper(url, tmpdir(), { fileName: name })
|
||||||
|
dl.on("error", (err) => {
|
||||||
|
throw new Error(`Failed to download ${url}: ${err}`)
|
||||||
|
})
|
||||||
|
await dl.start()
|
||||||
|
|
||||||
execRootSync("gpg", ["--no-default-keyring", "--keyring", `gnupg-ring:${fileName}`, "--import", `/tmp/${name}`])
|
execRootSync("gpg", ["--no-default-keyring", "--keyring", `gnupg-ring:${fileName}`, "--import", `/tmp/${name}`])
|
||||||
execRootSync("chmod", ["644", fileName])
|
execRootSync("chmod", ["644", fileName])
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,6 +140,9 @@ importers:
|
||||||
msvc-dev-cmd:
|
msvc-dev-cmd:
|
||||||
specifier: github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd
|
specifier: github:aminya/msvc-dev-cmd#c01f519bd995460228ed3dec4df51df92dc290fd
|
||||||
version: https://codeload.github.com/aminya/msvc-dev-cmd/tar.gz/c01f519bd995460228ed3dec4df51df92dc290fd
|
version: https://codeload.github.com/aminya/msvc-dev-cmd/tar.gz/c01f519bd995460228ed3dec4df51df92dc290fd
|
||||||
|
node-downloader-helper:
|
||||||
|
specifier: 2.1.9
|
||||||
|
version: 2.1.9
|
||||||
npm-check-updates:
|
npm-check-updates:
|
||||||
specifier: ^17.0.6
|
specifier: ^17.0.6
|
||||||
version: 17.0.6
|
version: 17.0.6
|
||||||
|
@ -306,6 +309,9 @@ importers:
|
||||||
execa:
|
execa:
|
||||||
specifier: ^7.2.0
|
specifier: ^7.2.0
|
||||||
version: 7.2.0
|
version: 7.2.0
|
||||||
|
node-downloader-helper:
|
||||||
|
specifier: 2.1.9
|
||||||
|
version: 2.1.9
|
||||||
path-exists:
|
path-exists:
|
||||||
specifier: ^5.0.0
|
specifier: ^5.0.0
|
||||||
version: 5.0.0
|
version: 5.0.0
|
||||||
|
@ -4176,6 +4182,11 @@ packages:
|
||||||
node-addon-api@7.1.1:
|
node-addon-api@7.1.1:
|
||||||
resolution: {integrity: sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==}
|
resolution: {integrity: sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==}
|
||||||
|
|
||||||
|
node-downloader-helper@2.1.9:
|
||||||
|
resolution: {integrity: sha512-FSvAol2Z8UP191sZtsUZwHIN0eGoGue3uEXGdWIH5228e9KH1YHXT7fN8Oa33UGf+FbqGTQg3sJfrRGzmVCaJA==}
|
||||||
|
engines: {node: '>=14.18'}
|
||||||
|
hasBin: true
|
||||||
|
|
||||||
node-fetch@2.7.0:
|
node-fetch@2.7.0:
|
||||||
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
|
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
|
||||||
engines: {node: 4.x || >=6.0.0}
|
engines: {node: 4.x || >=6.0.0}
|
||||||
|
@ -10343,6 +10354,8 @@ snapshots:
|
||||||
|
|
||||||
node-addon-api@7.1.1: {}
|
node-addon-api@7.1.1: {}
|
||||||
|
|
||||||
|
node-downloader-helper@2.1.9: {}
|
||||||
|
|
||||||
node-fetch@2.7.0(encoding@0.1.13):
|
node-fetch@2.7.0(encoding@0.1.13):
|
||||||
dependencies:
|
dependencies:
|
||||||
whatwg-url: 5.0.0
|
whatwg-url: 5.0.0
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { tmpdir } from "os"
|
import { tmpdir } from "os"
|
||||||
import path, { join } from "path"
|
|
||||||
import { mkdirP } from "@actions/io"
|
|
||||||
import { addPath } from "envosman"
|
import { addPath } from "envosman"
|
||||||
import { execaSync } from "execa"
|
import { execaSync } from "execa"
|
||||||
import { readFile } from "fs/promises"
|
import { DownloaderHelper } from "node-downloader-helper"
|
||||||
import { dirname } from "patha"
|
import { dirname } from "patha"
|
||||||
|
import { installAptPack } from "setup-apt"
|
||||||
import which from "which"
|
import which from "which"
|
||||||
import { rcOptions } from "../cli-options.js"
|
import { rcOptions } from "../cli-options.js"
|
||||||
|
|
||||||
|
@ -13,50 +12,66 @@ let binDir: string | undefined
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
export async function setupBrew(_version: string, _setupDir: string, _arch: string) {
|
export async function setupBrew(_version: string, _setupDir: string, _arch: string) {
|
||||||
|
// brew is only available on darwin and linux
|
||||||
if (!["darwin", "linux"].includes(process.platform)) {
|
if (!["darwin", "linux"].includes(process.platform)) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the function has already been called
|
||||||
if (typeof binDir === "string") {
|
if (typeof binDir === "string") {
|
||||||
return { binDir }
|
return { binDir }
|
||||||
}
|
}
|
||||||
|
|
||||||
const maybeBinDir = which.sync("brew", { nothrow: true })
|
// check if brew is already installed
|
||||||
|
const maybeBinDir = await which("brew", { nothrow: true })
|
||||||
if (maybeBinDir !== null) {
|
if (maybeBinDir !== null) {
|
||||||
binDir = dirname(maybeBinDir)
|
binDir = dirname(maybeBinDir)
|
||||||
return { binDir }
|
return { binDir }
|
||||||
}
|
}
|
||||||
|
|
||||||
// brew is not thread-safe
|
// download the installation script
|
||||||
const brewTempDirectory = path.join(tmpdir(), "setup-cpp", "brew")
|
await installAptPack([{ name: "ca-certificates" }])
|
||||||
await mkdirP(brewTempDirectory)
|
const dl = new DownloaderHelper("https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh", tmpdir(), {
|
||||||
|
fileName: "install-brew.sh",
|
||||||
execaSync("curl", ["-LJO", "https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"], {
|
|
||||||
cwd: brewTempDirectory,
|
|
||||||
})
|
})
|
||||||
const installSh = join(brewTempDirectory, "install.sh")
|
dl.on("error", (err) => {
|
||||||
|
throw new Error(`Failed to download the brew installer script: ${err}`)
|
||||||
|
})
|
||||||
|
await dl.start()
|
||||||
|
|
||||||
if (process.platform === "linux") {
|
// brew installation is not thread-safe
|
||||||
const installShContent = await readFile(installSh, "utf-8")
|
execaSync("/bin/bash", [dl.getDownloadPath()], {
|
||||||
installShContent.replace("#!/bin/bash", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
execaSync("/bin/bash", [installSh], {
|
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
env: {
|
env: {
|
||||||
NONINTERACTIVE: "1",
|
NONINTERACTIVE: "1",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// add the bin directory to the PATH
|
||||||
binDir = getBrewPath()
|
binDir = getBrewPath()
|
||||||
await addPath(binDir, rcOptions)
|
await addPath(binDir, rcOptions)
|
||||||
|
|
||||||
return { binDir }
|
return { binDir }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path where brew is installed
|
||||||
|
* @returns {string} The path where brew is installed
|
||||||
|
*
|
||||||
|
* Based on the installation script from https://brew.sh
|
||||||
|
*/
|
||||||
export function getBrewPath() {
|
export function getBrewPath() {
|
||||||
|
if (process.platform === "darwin") {
|
||||||
|
if (process.arch === "arm64") {
|
||||||
|
return "/opt/homebrew/bin/"
|
||||||
|
} else {
|
||||||
|
return "/usr/local/bin/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (process.platform === "linux") {
|
if (process.platform === "linux") {
|
||||||
return "/home/linuxbrew/.linuxbrew/bin/"
|
return "/home/linuxbrew/.linuxbrew/bin/"
|
||||||
} else {
|
|
||||||
return "/usr/local/bin/"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Error("Unsupported platform for brew")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { info } from "console"
|
import { info } from "console"
|
||||||
|
import { tmpdir } from "os"
|
||||||
|
import { join } from "path"
|
||||||
import { execRoot } from "admina"
|
import { execRoot } from "admina"
|
||||||
import { addPath } from "envosman"
|
import { addPath } from "envosman"
|
||||||
import { execa } from "execa"
|
|
||||||
import { chmod, readFile, writeFile } from "fs/promises"
|
import { chmod, readFile, writeFile } from "fs/promises"
|
||||||
|
import { DownloaderHelper } from "node-downloader-helper"
|
||||||
import { aptTimeout, hasNala, installAptPack, isAptPackRegexInstalled } from "setup-apt"
|
import { aptTimeout, hasNala, installAptPack, isAptPackRegexInstalled } from "setup-apt"
|
||||||
import { rcOptions } from "../cli-options.js"
|
import { rcOptions } from "../cli-options.js"
|
||||||
import { DEFAULT_TIMEOUT } from "../installTool.js"
|
import { DEFAULT_TIMEOUT } from "../installTool.js"
|
||||||
|
@ -21,14 +23,27 @@ export async function setupLLVMApt(
|
||||||
// TODO for older versions, this also includes the minor version
|
// TODO for older versions, this also includes the minor version
|
||||||
const installationFolder = `/usr/lib/llvm-${majorVersion}`
|
const installationFolder = `/usr/lib/llvm-${majorVersion}`
|
||||||
|
|
||||||
await installAptPack([{ name: "curl" }])
|
// download the installation script
|
||||||
await execa("curl", ["-LJO", "https://apt.llvm.org/llvm.sh"], { cwd: "/tmp" })
|
await installAptPack([{ name: "ca-certificates" }])
|
||||||
const neededPackages = await patchAptLLVMScript("/tmp/llvm.sh", "/tmp/llvm-setup-cpp.sh", majorVersion, packages)
|
const dl = new DownloaderHelper("https://apt.llvm.org/llvm.sh", tmpdir(), { fileName: "llvm.sh" })
|
||||||
|
dl.on("error", (err) => {
|
||||||
|
throw new Error(`Failed to download the LLVM installer script: ${err}`)
|
||||||
|
})
|
||||||
|
await dl.start()
|
||||||
|
const installerScript = await readFile(dl.getDownloadPath(), "utf-8")
|
||||||
|
|
||||||
|
const installerPath = join(tmpdir(), "llvm-setup-cpp.sh")
|
||||||
|
const neededPackages = await patchAptLLVMScript(
|
||||||
|
installerScript,
|
||||||
|
installerPath,
|
||||||
|
majorVersion,
|
||||||
|
packages,
|
||||||
|
)
|
||||||
await installAptPack(neededPackages)
|
await installAptPack(neededPackages)
|
||||||
await chmod("/tmp/llvm-setup-cpp.sh", "755")
|
await chmod(installerPath, "755")
|
||||||
await execRoot(
|
await execRoot(
|
||||||
"bash",
|
"bash",
|
||||||
["/tmp/llvm-setup-cpp.sh", `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
|
[installerPath, `${majorVersion}`, ...(packages === LLVMPackages.All ? ["all"] : [])],
|
||||||
{
|
{
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
shell: true,
|
shell: true,
|
||||||
|
@ -45,10 +60,13 @@ export async function setupLLVMApt(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function patchAptLLVMScript(path: string, target_path: string, majorVersion: number, packages: LLVMPackages) {
|
async function patchAptLLVMScript(
|
||||||
let script = await readFile(path, "utf-8")
|
givenScript: string,
|
||||||
|
target_path: string,
|
||||||
script = debugScript(script)
|
majorVersion: number,
|
||||||
|
packages: LLVMPackages,
|
||||||
|
) {
|
||||||
|
let script = debugScript(givenScript)
|
||||||
script = nonInteractiveScript(script)
|
script = nonInteractiveScript(script)
|
||||||
script = choosePackages(packages, script, majorVersion)
|
script = choosePackages(packages, script, majorVersion)
|
||||||
script = await removeConflictingPackages(script)
|
script = await removeConflictingPackages(script)
|
||||||
|
|
Loading…
Reference in New Issue