Skip to content

Commit 99f8d1a

Browse files
committed
feat: support ubuntu specific versions for llvm
1 parent 3aa347d commit 99f8d1a

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/default_versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function getVersion(name: string, version: string | undefined, osVersion:
2424
// choose the default version for llvm based on ubuntu
2525
if (osVersion !== null) {
2626
if ([20, 18, 16].includes(osVersion[0]) && osVersion[1] === 4) {
27-
return `-13.0.0-x86_64-linux-gnu-ubuntu-${osVersion[0]}.0${osVersion[1]}`
27+
return `${osVersion[0] === 18 ? "13.0.1" : "13.0.0"}-ubuntu-${osVersion[0]}.0${osVersion[1]}`
2828
}
2929
}
3030
}

src/llvm/__tests__/llvm.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setupLLVM, VERSIONS, getUrl, setupClangTools } from "../llvm"
1+
import { setupLLVM, VERSIONS, getUrl, setupClangTools, getLinuxUrl } from "../llvm"
22
import { getSpecificVersionAndUrl } from "../../utils/setup/version"
33
import { isValidUrl } from "../../utils/http/validate_url"
44
import { setupTmpDir, cleanupTmpDir, testBin } from "../../utils/tests/test-helpers"
@@ -25,6 +25,33 @@ describe("setup-llvm", () => {
2525
directory = await setupTmpDir("llvm")
2626
})
2727

28+
it("Finds URL for ubuntu version", async () => {
29+
expect(
30+
await getSpecificVersionAndUrl(VERSIONS, "linux", "13.0.0-ubuntu-16.04", (_plantform, version) =>
31+
getLinuxUrl(version)
32+
)
33+
).toStrictEqual([
34+
"13.0.0-ubuntu-16.04",
35+
"https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz",
36+
])
37+
expect(
38+
await getSpecificVersionAndUrl(VERSIONS, "linux", "13.0.1-ubuntu-18.04", (_plantform, version) =>
39+
getLinuxUrl(version)
40+
)
41+
).toStrictEqual([
42+
"13.0.1-ubuntu-18.04",
43+
"https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04.tar.xz",
44+
])
45+
expect(
46+
await getSpecificVersionAndUrl(VERSIONS, "linux", "13.0.0-ubuntu-20.04", (_plantform, version) =>
47+
getLinuxUrl(version)
48+
)
49+
).toStrictEqual([
50+
"13.0.0-ubuntu-20.04",
51+
"https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz",
52+
])
53+
})
54+
2855
it("Finds valid LLVM URLs", async () => {
2956
await Promise.all(
3057
[

src/llvm/llvm.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import semverMajor from "semver/functions/major"
44
import { isValidUrl } from "../utils/http/validate_url"
55
import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin"
66
import { extractExe, extractTarByExe } from "../utils/setup/extract"
7-
import { getSpecificVersionAndUrl, getVersions, semverCoerceIfInvalid } from "../utils/setup/version"
7+
import {
8+
getSpecificVersionAndUrl,
9+
getSpecificVersions,
10+
getVersions,
11+
semverCoerceIfInvalid,
12+
} from "../utils/setup/version"
813
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
914
import { addBinExtension } from "../utils/extension/extension"
1015
import { addEnv } from "../utils/env/addEnv"
@@ -158,7 +163,10 @@ const UBUNTU_SUFFIX_MAP: { [key: string]: string } = {
158163
"12.0.0": "-ubuntu-20.04",
159164
"12.0.1": "-ubuntu-16.04",
160165
"13.0.0": "-ubuntu-20.04",
166+
"13.0.0-ubuntu-16.04": "-ubuntu-16.04",
167+
"13.0.0-ubuntu-20.04": "-ubuntu-20.04",
161168
"13.0.1": "-ubuntu-18.04",
169+
"13.0.1-ubuntu-18.04": "-ubuntu-18.04",
162170
"14.0.0": "-ubuntu-18.04",
163171
// "14.0.1": "-ubuntu-18.04", // only available for powerpc64le
164172
}
@@ -167,7 +175,7 @@ const UBUNTU_SUFFIX_MAP: { [key: string]: string } = {
167175
const MAX_UBUNTU: string = "14.0.0"
168176

169177
/** Gets an LLVM download URL for the Linux (Ubuntu) platform. */
170-
function getLinuxUrl(versionGiven: string): string {
178+
export function getLinuxUrl(versionGiven: string): string {
171179
let version = versionGiven
172180

173181
const rc = UBUNTU_RC.get(version)
@@ -178,7 +186,12 @@ function getLinuxUrl(versionGiven: string): string {
178186
let ubuntu: string
179187
// ubuntu-version is specified
180188
if (version.includes("ubuntu")) {
181-
ubuntu = version
189+
const givenUbuntuVersion = version.replace(/-ubuntu-.*/, "")
190+
if (!VERSIONS.has(givenUbuntuVersion)) {
191+
throw new Error(`Unsupported Ubuntu version: ${givenUbuntuVersion}`)
192+
}
193+
ubuntu = version.replace(givenUbuntuVersion, "")
194+
version = getSpecificVersions(VERSIONS, givenUbuntuVersion)[0]
182195
} else if (version !== "" && version in UBUNTU_SUFFIX_MAP) {
183196
ubuntu = UBUNTU_SUFFIX_MAP[version]
184197
} else {

src/utils/setup/version.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export async function getSpecificVersionAndUrl(
3838
version: string,
3939
getUrl: (platform: string, version: string) => string | null | Promise<string | null>
4040
): Promise<[string, string]> {
41+
// specific ubuntu version
42+
if (platform === "linux" && version.includes("ubuntu")) {
43+
const url = await getUrl(platform, version)
44+
// eslint-disable-next-line no-await-in-loop
45+
if (url !== null && (await isValidUrl(url))) {
46+
return [version, url]
47+
}
48+
}
49+
4150
if (!versions.has(version)) {
4251
throw new Error(`Unsupported target! (platform='${platform}', version='${version}')`)
4352
}

0 commit comments

Comments
 (0)