Skip to content

Commit 22bfbec

Browse files
committed
fix: match assets via keywords
1 parent d0c5d22 commit 22bfbec

File tree

8 files changed

+33
-24
lines changed

8 files changed

+33
-24
lines changed

dist/legacy/setup-cpp.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

+1-1
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

+1-1
Large diffs are not rendered by default.

src/gcc/gcc.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { addUpdateAlternativesToRc, installAptPack } from "setup-apt"
1313
import { installBrewPack } from "setup-brew"
1414
import { rcOptions } from "../cli-options.js"
1515
import { setupMacOSSDK } from "../macos-sdk/macos-sdk.js"
16-
import { loadGitHubAssetList, matchAsset } from "../utils/asset/load-assets.js"
16+
import { loadAssetList, matchAsset } from "../utils/asset/load-assets.js"
1717
import { hasDnf } from "../utils/env/hasDnf.js"
1818
import { isArch } from "../utils/env/isArch.js"
1919
import { isUbuntu } from "../utils/env/isUbuntu.js"
@@ -29,18 +29,22 @@ const dirname = typeof __dirname === "string" ? __dirname : path.dirname(fileURL
2929
async function getGccPackageInfo(version: string, platform: NodeJS.Platform, arch: string): Promise<PackageInfo> {
3030
switch (platform) {
3131
case "win32": {
32-
const mingwAssets = await loadGitHubAssetList(
32+
const mingwAssets = await loadAssetList(
3333
join(dirname, "github_brechtsanders_winlibs_mingw.json"),
3434
)
35+
36+
const mingwArchMap = {
37+
x64: "x86_64",
38+
ia32: "i386",
39+
} as Record<string, string | undefined>
40+
3541
const asset = matchAsset(
3642
mingwAssets,
3743
{
3844
version,
39-
arch: arch === "x64"
40-
? "x86_64"
41-
: arch === "ia32"
42-
? "i386"
43-
: arch,
45+
keywords: [
46+
mingwArchMap[arch] ?? arch,
47+
],
4448
},
4549
)
4650

src/llvm/llvm_org_releases.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,4 @@
595595
"polly-3.5.1.src.tar.xz",
596596
"test-suite-3.5.1.src.tar.xz"
597597
]
598-
}
598+
}

src/utils/asset/fetch-html-assets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function fetchIndexFile(version: string, url: string, htmlDownloadDir: str
6969
retry: {
7070
delay: 100,
7171
maxRetries: 3,
72-
}
72+
},
7373
},
7474
)
7575
dl.on("start", () => {

src/utils/asset/load-assets.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
import { readFile } from "fs/promises"
22

33
/**
4-
* The list of assets of a GitHub release
4+
* The list of assets
55
* @key tag The tag of the release
66
* @value assets The names of the assets of the release
77
*/
88
export type Assets = Record<string, string[]>
99

10-
export async function loadGitHubAssetList(path: string): Promise<Assets> {
10+
/**
11+
* Load the list of assets from a json file
12+
*/
13+
export async function loadAssetList(path: string): Promise<Assets> {
1114
const data = await readFile(path, "utf-8")
1215
return JSON.parse(data)
1316
}
1417

1518
type MatchAssetOpts = {
1619
version: string
17-
arch?: string
20+
keywords?: string[]
1821
filterTag?: (version: string) => boolean
1922
filterName?: (asset: string) => boolean
2023
}
2124

2225
/**
23-
* Match the asset that matches the version and arch
26+
* Match the asset that matches the version and given keywords
2427
*/
2528
export function matchAsset(
2629
assets: Assets,
@@ -60,21 +63,23 @@ export function matchAsset(
6063
}
6164

6265
if (matchedNames.length === 0) {
63-
throw new Error(`no asset found for version ${opts.version} and arch ${opts.arch}`)
66+
throw new Error(`no asset found for version ${opts.version}`)
6467
}
6568

66-
// use the first asset if the arch is not specified
67-
if (opts.arch === undefined) {
69+
if (opts.keywords?.length === 0) {
6870
return { tag, name: matchedNames[0] }
6971
}
7072

71-
// find the asset that matches the arch
73+
// find the first asset that matches the keywords
7274
for (const name of matchedNames) {
73-
// search each asset name for the arch
74-
if (name.includes(opts.arch)) {
75+
if (opts.keywords!.every((keyword) => name.includes(keyword))) {
7576
return { tag, name }
7677
}
7778
}
7879

79-
throw new Error(`arch ${opts.arch} could not be found among ${JSON.stringify(matchedNames)}`)
80+
throw new Error(
81+
`Could not find a matching asset for version ${opts.version} and keywords ${JSON.stringify(opts.keywords)} among ${
82+
JSON.stringify(matchedNames)
83+
}`,
84+
)
8085
}

0 commit comments

Comments
 (0)