setup-cpp/src/doxygen/doxygen.ts

69 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-09-18 10:17:21 +08:00
import { addPath } from "../utils/path/addPath"
2021-09-16 16:47:47 +08:00
import { setupAptPack } from "../utils/setup/setupAptPack"
import { PackageInfo, setupBin } from "../utils/setup/setupBin"
2021-09-16 16:47:47 +08:00
import { setupBrewPack } from "../utils/setup/setupBrewPack"
import { setupChocoPack } from "../utils/setup/setupChocoPack"
import { addBinExtension } from "../utils/extension/extension"
import { extractTarByExe } from "../utils/setup/extract"
import { warning } from "../utils/io/io"
2021-09-16 16:47:47 +08:00
/** Get the platform data for cmake */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getDoxygenPackageInfo(version: string, platform: NodeJS.Platform, _arch: string): PackageInfo {
switch (platform) {
case "linux": {
const folderName = `doxygen-${version}`
return {
binRelativeDir: "bin/",
binFileName: addBinExtension("doxygen"),
extractedFolderName: folderName,
extractFunction: (file: string, dest: string) => {
return extractTarByExe(file, dest, ["--strip-components=1"])
},
url: `https://www.doxygen.nl/files/${folderName}.linux.bin.tar.gz`,
}
}
default:
throw new Error(`Unsupported platform '${platform}'`)
}
}
export async function setupDoxygen(version: string, setupDir: string, arch: string) {
2021-09-16 16:47:47 +08:00
switch (process.platform) {
case "win32": {
await setupChocoPack("doxygen.install", version)
try {
await setupChocoPack("graphviz", undefined)
} catch (err) {
warning(`${err}`)
}
2021-09-20 20:31:40 +08:00
const binDir = activateWinDoxygen()
2021-09-17 02:49:24 +08:00
return { binDir }
2021-09-16 16:47:47 +08:00
}
case "darwin": {
setupBrewPack("doxygen", undefined)
return setupBrewPack("graphviz", undefined)
2021-09-16 16:47:47 +08:00
}
case "linux": {
try {
// doxygen on stable Ubuntu repositories is very old. So, we use get the binary from the website itself
await setupBin("doxygen", version, getDoxygenPackageInfo, setupDir, arch)
} catch (err) {
warning(`Failed to download doxygen binary. ${err}. Falling back to apt-get.`)
await setupAptPack("doxygen", undefined)
}
return setupAptPack("graphviz", undefined)
2021-09-16 16:47:47 +08:00
}
default: {
throw new Error(`Unsupported platform`)
}
}
}
2021-09-20 20:31:40 +08:00
function activateWinDoxygen() {
addPath("C:/Program Files/Graphviz/bin")
const binDir = "C:/Program Files/doxygen/bin"
addPath(binDir)
return binDir
}