Merge pull request #9 from aminya/fixes

This commit is contained in:
Amin Yahyaabadi 2021-12-07 03:14:03 -06:00 committed by GitHub
commit cda21f972d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 66 additions and 29 deletions

View File

@ -76,6 +76,7 @@ Download the `setup_cpp.js` file form [here](https://github.com/aminya/setup-cpp
On Windows: On Windows:
Open the shell as admin, download via `curl`, then install Open the shell as admin, download via `curl`, then install
```ps1 ```ps1
# open shell as admin # open shell as admin
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.4.0/setup_cpp.js" curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.4.0/setup_cpp.js"

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -36,7 +36,7 @@
"execa": "^5.1.1", "execa": "^5.1.1",
"hasha": "^5.2.2", "hasha": "^5.2.2",
"mri": "^1.2.0", "mri": "^1.2.0",
"msvc-dev-cmd": " https://github.com/aminya/msvc-dev-cmd", "msvc-dev-cmd": "git://github.com/aminya/msvc-dev-cmd#9f672c1",
"semver": "^7.3.5", "semver": "^7.3.5",
"setup-python": "https://github.com/actions/setup-python", "setup-python": "https://github.com/actions/setup-python",
"untildify": "^4.0.0", "untildify": "^4.0.0",

View File

@ -22,7 +22,7 @@ specifiers:
hasha: ^5.2.2 hasha: ^5.2.2
jest: ^27.4.2 jest: ^27.4.2
mri: ^1.2.0 mri: ^1.2.0
msvc-dev-cmd: ' https://github.com/aminya/msvc-dev-cmd' msvc-dev-cmd: git://github.com/aminya/msvc-dev-cmd#9f672c1
npm-run-all2: ^5.0.2 npm-run-all2: ^5.0.2
parcel: ^2.0.1 parcel: ^2.0.1
prettier-config-atomic: ^3.0.1 prettier-config-atomic: ^3.0.1
@ -43,7 +43,7 @@ dependencies:
execa: 5.1.1 execa: 5.1.1
hasha: 5.2.2 hasha: 5.2.2
mri: 1.2.0 mri: 1.2.0
msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1c3d12ea8156d8d0e53543791491291aec msvc-dev-cmd: github.com/aminya/msvc-dev-cmd/9f672c1
semver: 7.3.5 semver: 7.3.5
setup-python: github.com/actions/setup-python/f38219332975fe8f9c04cca981d674bf22aea1d3 setup-python: github.com/actions/setup-python/f38219332975fe8f9c04cca981d674bf22aea1d3
untildify: 4.0.0 untildify: 4.0.0
@ -8619,8 +8619,8 @@ packages:
semver: 7.3.5 semver: 7.3.5
dev: false dev: false
github.com/aminya/msvc-dev-cmd/9f672c1c3d12ea8156d8d0e53543791491291aec: github.com/aminya/msvc-dev-cmd/9f672c1:
resolution: {tarball: https://codeload.github.com/aminya/msvc-dev-cmd/tar.gz/9f672c1c3d12ea8156d8d0e53543791491291aec} resolution: {tarball: https://codeload.github.com/aminya/msvc-dev-cmd/tar.gz/9f672c1}
name: msvc-dev-cmd name: msvc-dev-cmd
version: 1.1.1 version: 1.1.1
dependencies: dependencies:

View File

@ -34,18 +34,34 @@ export async function setupGcc(version: string, _setupDir: string, arch: string)
} }
case "linux": { case "linux": {
if (arch === "x64") { if (arch === "x64") {
binDir = (await setupAptPack("g++", version, "ppa:ubuntu-toolchain-r/test")).binDir binDir = (
await setupAptPack("g++", version, [
"ppa:ubuntu-toolchain-r/test",
"'deb http://dk.archive.ubuntu.com/ubuntu/ xenial mai'",
"'deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe'",
])
).binDir
} else { } else {
info(`Install g++-multilib because gcc for ${arch} was requested`) info(`Install g++-multilib because gcc for ${arch} was requested`)
binDir = (await setupAptPack("g++-multilib", version, "ppa:ubuntu-toolchain-r/test")).binDir binDir = (
await setupAptPack("g++-multilib", version, [
"ppa:ubuntu-toolchain-r/test",
"'deb http://dk.archive.ubuntu.com/ubuntu/ xenial mai'",
"'deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe'",
])
).binDir
} }
break break
} }
// TODO support bare-metal // TODO support bare-metal (need to support passing it as the input)
// TODO support abi // TODO support abi
// case "none": { // case "none": {
// if (arch === "arm" || arch === "arm64") { // if (arch === "arm" || arch === "arm64") {
// return setupAptPack("gcc-arm-none-eabi", version, "ppa:ubuntu-toolchain-r/test") // return setupAptPack("gcc-arm-none-eabi", version, [
// "ppa:ubuntu-toolchain-r/test",
// "'deb http://dk.archive.ubuntu.com/ubuntu/ xenial mai'",
// "'deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe'",
// ])
// } else { // } else {
// throw new Error(`Unsupported platform for ${arch}`) // throw new Error(`Unsupported platform for ${arch}`)
// } // }

View File

@ -5,7 +5,7 @@ import semverMajor from "semver/functions/major"
import { isValidUrl } from "../utils/http/validate_url" import { isValidUrl } from "../utils/http/validate_url"
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin" import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
import { extractExe, extractTarByExe } from "../utils/setup/extract" import { extractExe, extractTarByExe } from "../utils/setup/extract"
import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version" import { getSpecificVersionAndUrl, getVersions, semverCoerceIfInvalid } from "../utils/setup/version"
import { setupMacOSSDK } from "../macos-sdk/macos-sdk" import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
import { addBinExtension } from "../utils/extension/extension" import { addBinExtension } from "../utils/extension/extension"
@ -244,7 +244,9 @@ export async function setupLLVM(
return installationInfo return installationInfo
} }
export async function activateLLVM(directory: string, version: string) { export async function activateLLVM(directory: string, versionGiven: string) {
const version = semverCoerceIfInvalid(versionGiven)
const lib = path.join(directory, "lib") const lib = path.join(directory, "lib")
const ld = process.env.LD_LIBRARY_PATH ?? "" const ld = process.env.LD_LIBRARY_PATH ?? ""

View File

@ -18,7 +18,6 @@ import untildify from "untildify"
import { isCI } from "./utils/env/isci" import { isCI } from "./utils/env/isci"
import semverValid from "semver/functions/valid" import semverValid from "semver/functions/valid"
// import semverCoerce from "semver/functions/coerce"
import { getVersion } from "./default_versions" import { getVersion } from "./default_versions"
import { setupGcc } from "./gcc/gcc" import { setupGcc } from "./gcc/gcc"
import { InstallationInfo } from "./utils/setup/setupBin" import { InstallationInfo } from "./utils/setup/setupBin"
@ -172,6 +171,13 @@ export async function main(args: string[]): Promise<number> {
await setupMSVC(getVersion("msvc", version) as string, join(setupCppDir, "msvc"), arch) await setupMSVC(getVersion("msvc", version) as string, join(setupCppDir, "msvc"), arch)
break break
} }
case "appleclang":
case "applellvm": {
core.warning("Assuming apple-clang is already installed")
core.exportVariable("CC", "clang")
core.exportVariable("CXX", "clang++")
break
}
default: { default: {
errorMessages.push(`Unsupported compiler ${compiler}`) errorMessages.push(`Unsupported compiler ${compiler}`)
} }
@ -227,16 +233,6 @@ export function getCompilerInfo(maybeCompiler: string) {
if (semverValid(maybeVersion) !== null) { if (semverValid(maybeVersion) !== null) {
return { compiler, version: maybeVersion } return { compiler, version: maybeVersion }
} else { } else {
// version coercion
// try {
// // find the semver version of an integer
// const coercedVersion = semverCoerce(maybeVersion)
// if (coercedVersion !== null) {
// return { compiler, version: coercedVersion.version }
// }
// } catch (err) {
// // handled in the end
// }
warning(`Invalid semver version ${maybeVersion} used for the compiler.`) warning(`Invalid semver version ${maybeVersion} used for the compiler.`)
return { compiler, version: maybeVersion } return { compiler, version: maybeVersion }
} }

View File

@ -8,15 +8,18 @@ let didUpdate: boolean = false
export async function setupAptPack( export async function setupAptPack(
name: string, name: string,
version?: string, version?: string,
repository: boolean | string = true repositories: boolean | string[] = true
): Promise<InstallationInfo> { ): Promise<InstallationInfo> {
const apt = "apt-get" const apt = "apt-get"
if (typeof repository === "string") { if (Array.isArray(repositories)) {
await execaSudo("add-apt-repository", ["--update", "-y", repository]) for (const repo of repositories) {
// eslint-disable-next-line no-await-in-loop
await execaSudo("add-apt-repository", ["--update", "-y", repo])
}
} }
if (!didUpdate || repository === true) { if (!didUpdate || repositories === true) {
await execaSudo(apt, ["update", "-y"]) await execaSudo(apt, ["update", "-y"])
didUpdate = true didUpdate = true
} }

View File

@ -1,5 +1,7 @@
import { isValidUrl } from "../http/validate_url" import { isValidUrl } from "../http/validate_url"
import semverCompare from "semver/functions/compare" import semverCompare from "semver/functions/compare"
import semverCoerce from "semver/functions/coerce"
import semverValid from "semver/functions/valid"
import { getExecOutput } from "@actions/exec" import { getExecOutput } from "@actions/exec"
/** /**
@ -84,3 +86,20 @@ export async function isBinUptoDate(
return false return false
} }
} }
/** Coerce the given version if it is invalid */
export function semverCoerceIfInvalid(version: string) {
if (semverValid(version) === null) {
// version coercion
try {
// find the semver version of an integer
const coercedVersion = semverCoerce(version)
if (coercedVersion !== null) {
return coercedVersion.version
}
} catch (err) {
// handled below
}
}
return version
}