fix: support llvm 8 and 7 for windows

This commit is contained in:
Amin Yahyaabadi 2021-09-14 07:34:14 -05:00
parent f4939bc8e2
commit 46cc30329b
3 changed files with 58 additions and 27 deletions

View File

@ -1,31 +1,37 @@
import { getSpecificVersionAndUrl } from "../llvm" import { getSpecificVersionAndUrl } from "../llvm"
import * as https from "https" import { isValidUrl } from "../../utils/http/validate_url"
jest.setTimeout(100000) jest.setTimeout(100000)
function testUrl(version: string) { async function testUrl(version: string) {
const [specificVersion, url] = getSpecificVersionAndUrl(process.platform, version) const [specificVersion, url] = await getSpecificVersionAndUrl(process.platform, version)
const input = `Version: ${version} => ${specificVersion} \n URL: ${url}` if (!(await isValidUrl(url))) {
throw new Error(`Failed to install Version: ${version} => ${specificVersion} \n URL: ${url}`)
return new Promise<string>((resolve, reject) => {
https.get(url, (res) => {
const report = `${input}\nStatus: ${res.statusCode}\nContent-Length: ${res.headers["content-length"]}`
if (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode <= 399) {
resolve(report)
} else {
reject(new Error(`Failed to download LLVM and Clang binaries.\n${input}\n${report}`))
} }
})
})
} }
describe("setup-llvm", () => { describe("setup-llvm", () => {
it("Finds valid LLVM URLs", async () => { it("Finds valid LLVM URLs", async () => {
await Promise.all( await Promise.all(
["12.0.0", "12", "11", "11.0.0", "10", "10.0.0", "9.0.0", "8.0.0", "7.0.0", "6", "6.0.0", "5", "5.0.0", "4"].map( [
(version) => testUrl(version) "12.0.0",
) "12",
"11",
"11.0.0",
"10",
"10.0.0",
"9.0.0",
"8",
"8.0.0",
"7.0.0",
"7",
"6",
"6.0.0",
"5",
"5.0.0",
"4",
].map((version) => testUrl(version))
) )
}) })
}) })

View File

@ -5,6 +5,7 @@ import * as tc from "@actions/tool-cache"
import * as path from "path" import * as path from "path"
import semverLte from "semver/functions/lte" import semverLte from "semver/functions/lte"
import semverLt from "semver/functions/lt" import semverLt from "semver/functions/lt"
import { isValidUrl } from "../utils/http/validate_url"
//================================================ //================================================
// Version // Version
@ -200,22 +201,32 @@ function getLinuxUrl(versionGiven: string): string {
const WIN32_MISSING: Set<string> = new Set(["10.0.1"]) const WIN32_MISSING: Set<string> = new Set(["10.0.1"])
/** Gets an LLVM download URL for the Windows platform. */ /** Gets an LLVM download URL for the Windows platform. */
function getWin32Url(version: string): string | null { async function getWin32Url(version: string): Promise<string | null> {
if (WIN32_MISSING.has(version)) { if (WIN32_MISSING.has(version)) {
return null return null
} }
const prefix = "LLVM-" const prefix = "LLVM-"
const suffix = semverLte(version, "3.7.0") ? "-win32.exe" : "-win64.exe" const suffix = semverLte(version, "3.7.0") ? "-win32.exe" : "-win64.exe"
if (semverLte(version, "9.0.1")) {
return getReleaseUrl(version, prefix, suffix) const olderThan9_1 = semverLte(version, "9.0.1")
} else { let url: string
return getGitHubUrl(version, prefix, suffix) let fallback = false
if (olderThan9_1) {
url = getReleaseUrl(version, prefix, suffix)
if (!(await isValidUrl(url))) {
fallback = true // fallback to github
} }
}
if (fallback || !olderThan9_1) {
url = getGitHubUrl(version, prefix, suffix)
}
return url!
} }
/** Gets an LLVM download URL. */ /** Gets an LLVM download URL. */
function getUrl(platform: string, version: string): string | null { function getUrl(platform: string, version: string): string | null | Promise<string | null> {
switch (platform) { switch (platform) {
case "darwin": case "darwin":
return getDarwinUrl(version) return getDarwinUrl(version)
@ -229,13 +240,14 @@ function getUrl(platform: string, version: string): string | null {
} }
/** Gets the most recent specific LLVM version for which there is a valid download URL. */ /** Gets the most recent specific LLVM version for which there is a valid download URL. */
export function getSpecificVersionAndUrl(platform: string, version: string): [string, string] { export async function getSpecificVersionAndUrl(platform: string, version: string): Promise<[string, string]> {
if (!VERSIONS.has(version)) { if (!VERSIONS.has(version)) {
throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`) throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`)
} }
for (const specificVersion of getSpecificVersions(version)) { for (const specificVersion of getSpecificVersions(version)) {
const url = getUrl(platform, specificVersion) // eslint-disable-next-line no-await-in-loop
const url = await getUrl(platform, specificVersion)
if (url !== null) { if (url !== null) {
return [specificVersion, url] return [specificVersion, url]
} }
@ -253,7 +265,7 @@ const DEFAULT_WIN32_DIRECTORY = "C:/Program Files/LLVM"
async function install(version: string, directory: string): Promise<void> { async function install(version: string, directory: string): Promise<void> {
const platform = process.platform const platform = process.platform
const [specificVersion, url] = getSpecificVersionAndUrl(platform, version) const [specificVersion, url] = await getSpecificVersionAndUrl(platform, version)
core.setOutput("version", specificVersion) core.setOutput("version", specificVersion)
core.info(`Installing LLVM and Clang ${version} (${specificVersion})...`) core.info(`Installing LLVM and Clang ${version} (${specificVersion})...`)

View File

@ -0,0 +1,13 @@
import * as https from "https"
export function isValidUrl(url: string) {
return new Promise<boolean>((resolve) => {
https.get(url, (res) => {
if (res.statusCode !== undefined && res.statusCode >= 200 && res.statusCode <= 399) {
resolve(true)
} else {
resolve(false)
}
})
})
}