mirror of https://github.com/aminya/setup-cpp
fix: support matching assets with partial versions specified
This commit is contained in:
parent
e1217a3287
commit
dcadbb8407
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
|
@ -36,7 +36,10 @@ describe("setup-llvm", () => {
|
||||||
it("Finds valid LLVM URLs", async () => {
|
it("Finds valid LLVM URLs", async () => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
[
|
[
|
||||||
...(process.platform === "darwin" ? [] : ["16.0.2", "16.0.0"]),
|
"18",
|
||||||
|
"17",
|
||||||
|
"16",
|
||||||
|
"15",
|
||||||
"15.0.2",
|
"15.0.2",
|
||||||
// "14.0.1",
|
// "14.0.1",
|
||||||
"14.0.0",
|
"14.0.0",
|
||||||
|
@ -57,7 +60,7 @@ describe("setup-llvm", () => {
|
||||||
"5",
|
"5",
|
||||||
"5.0.0",
|
"5.0.0",
|
||||||
"4",
|
"4",
|
||||||
].map((version) => getLLVMAssetURL(process.platform, process.arch, version)),
|
].map((version) => getLLVMAssetURL("win32", "x64", version)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,69 @@ export function matchAsset(
|
||||||
assets: Assets,
|
assets: Assets,
|
||||||
opts: MatchAssetOpts,
|
opts: MatchAssetOpts,
|
||||||
): { tag: string; name: string } | undefined {
|
): { tag: string; name: string } | undefined {
|
||||||
// match the tag
|
// get the list of versions
|
||||||
const assetVersion = matchAssetVersion(assets, opts)
|
const origTags = Object.keys(assets)
|
||||||
if (assetVersion === undefined) {
|
|
||||||
|
// filter/map the tags
|
||||||
|
const versionMap: Map<string, string> = new Map()
|
||||||
|
if (opts.filterMapTag === undefined) {
|
||||||
|
for (const origTag of origTags) {
|
||||||
|
versionMap.set(origTag, origTag)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const origTag of origTags) {
|
||||||
|
const mappedTag = opts.filterMapTag(origTag)
|
||||||
|
if (mappedTag !== undefined) {
|
||||||
|
versionMap.set(mappedTag, origTag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versionMap.size === 0) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
const { tag, assetNames } = assetVersion
|
|
||||||
|
|
||||||
|
// find the first tag that starts with the version
|
||||||
|
// loop over the versions starting with the latest
|
||||||
|
const candidateTags: string[] = []
|
||||||
|
for (const [version, origTag] of versionMap.entries()) {
|
||||||
|
if (version.startsWith(opts.version)) {
|
||||||
|
candidateTags.push(origTag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (candidateTags.length === 0) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over the candidate tags and return the first one that has assets
|
||||||
|
for (const candidateTag of candidateTags) {
|
||||||
|
// get the list of assets
|
||||||
|
let assetNames = assets[candidateTag]
|
||||||
|
if (assetNames === undefined) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter the assets
|
||||||
|
if (opts.filterName !== undefined) {
|
||||||
|
assetNames = assetNames.filter(opts.filterName)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (assetNames.length === 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if this version contains the keywords and optional keywords in the asset name
|
||||||
|
const match = matchAssetName(candidateTag, assetNames, opts)
|
||||||
|
if (match !== undefined) {
|
||||||
|
return match
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchAssetName(tag: string, assetNames: string[], opts: MatchAssetOpts) {
|
||||||
// if no keywords are given, return the first asset
|
// if no keywords are given, return the first asset
|
||||||
if (
|
if (
|
||||||
(opts.keywords === undefined
|
(opts.keywords === undefined
|
||||||
|
@ -64,7 +120,6 @@ export function matchAsset(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidates.length === 0) {
|
if (candidates.length === 0) {
|
||||||
info(`no asset found for version ${opts.version} and keywords ${opts.keywords}`)
|
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,64 +148,3 @@ export function matchAsset(
|
||||||
// return the first candidate if no optional keywords are given
|
// return the first candidate if no optional keywords are given
|
||||||
return { tag, name: candidates[0] }
|
return { tag, name: candidates[0] }
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchAssetVersion(assets: Assets, opts: MatchAssetOpts) {
|
|
||||||
// get the list of versions
|
|
||||||
const origTags = Object.keys(assets)
|
|
||||||
|
|
||||||
// filter/map the tags
|
|
||||||
const versionMap: Map<string, string> = new Map()
|
|
||||||
if (opts.filterMapTag === undefined) {
|
|
||||||
for (const origTag of origTags) {
|
|
||||||
versionMap.set(origTag, origTag)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const origTag of origTags) {
|
|
||||||
const mappedTag = opts.filterMapTag(origTag)
|
|
||||||
if (mappedTag !== undefined) {
|
|
||||||
versionMap.set(mappedTag, origTag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versionMap.size === 0) {
|
|
||||||
info(`no tag found for version ${opts.version}`)
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
// find the first tag that starts with the version
|
|
||||||
// loop over the versions starting with the latest
|
|
||||||
let foundVersion: string | undefined
|
|
||||||
let foundOrigTag: string | undefined
|
|
||||||
for (const [version, origTag] of versionMap.entries()) {
|
|
||||||
if (version.startsWith(opts.version)) {
|
|
||||||
foundVersion = version
|
|
||||||
foundOrigTag = origTag
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (foundVersion === undefined || foundOrigTag === undefined) {
|
|
||||||
info(`version ${opts.version} is not supported`)
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the list of assets
|
|
||||||
let assetNames = assets[foundOrigTag]
|
|
||||||
if (assetNames === undefined) {
|
|
||||||
info(`no asset found for version ${opts.version}`)
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter the assets
|
|
||||||
if (opts.filterName !== undefined) {
|
|
||||||
assetNames = assetNames.filter(opts.filterName)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (assetNames.length === 0) {
|
|
||||||
info(`no asset found for version ${opts.version}`)
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
return { tag: foundOrigTag, assetNames }
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue