Skip to content

Commit

Permalink
feat: add support for facebook/infer
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 19, 2024
1 parent 118cfec commit 69b2c1b
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 16 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Setting up a **cross-platform** environment for building and testing C++/C proje

`setup-cpp` is **modular** and you can choose to install any of these tools:

| category | tools |
| --------------------- | -------------------------------------------------------------------------------------------------------- |
| compiler and analyzer | llvm, gcc, msvc, apple-clang, vcvarsall, cppcheck, clang-tidy, clang-format, cpplint, flawfinder, lizard |
| build system | cmake, ninja, meson, make, task, bazel, cmakelang, cmake-format, cmake-lint |
| package manager | vcpkg, conan, choco, brew, nala |
| cache | ccache, sccache |
| documentation | doxygen, graphviz |
| coverage | gcovr, opencppcoverage, kcov |
| other | python, powershell, sevenzip |
| category | tools |
| --------------------- | --------------------------------------------------------------------------------------------------------------- |
| compiler and analyzer | llvm, gcc, msvc, apple-clang, vcvarsall, cppcheck, clang-tidy, clang-format, cpplint, flawfinder, lizard, infer |
| build system | cmake, ninja, meson, make, task, bazel, cmakelang, cmake-format, cmake-lint |
| package manager | vcpkg, conan, choco, brew, nala |
| cache | ccache, sccache |
| documentation | doxygen, graphviz |
| coverage | gcovr, opencppcoverage, kcov |
| other | python, powershell, sevenzip |

`setup-cpp` automatically handles the dependencies of the selected tool (e.g., `python` is required for `conan`).

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ inputs:
lizard:
description: "Wether to install lizard (true/false) or the specific version to install."
required: false
infer:
description: "Wether to install facebook/infer (true/false) or the specific version to install."
required: false
clang-tidy:
description: "Wether to install clang-tidy (true/false) or the specific version to install."
required: false
Expand Down
1 change: 1 addition & 0 deletions dist/legacy/github_facebook_infer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v1.2.0":["infer-osx-x86_64-v1.2.0.tar.xz","infer-osx-arm64-v1.2.0.tar.xz","infer-linux-x86_64-v1.2.0.tar.xz"],"v1.1.0":["infer-linux64-v1.1.0.tar.xz"],"v1.0.0":["infer-osx-v1.0.0.tar.xz","infer-linux64-v1.0.0.tar.xz"],"v0.17.0":["infer-osx-v0.17.0.tar.xz","infer-linux64-v0.17.0.tar.xz"],"v0.16.0":["infer-osx-v0.16.0.tar.xz","infer-linux64-v0.16.0.tar.xz"],"v0.15.0":["infer-osx-v0.15.0.tar.xz","infer-linux64-v0.15.0.tar.xz"],"v0.14.0":["infer-osx-v0.14.0.tar.xz","infer-linux64-v0.14.0.tar.xz"],"v0.13.1":["infer-osx-v0.13.1.tar.xz","infer-linux64-v0.13.1.tar.xz"],"v0.13.0":["infer-osx-v0.13.0.tar.xz","infer-linux64-v0.13.0.tar.xz"],"v0.12.1":["infer-osx-v0.12.1.tar.xz","infer-linux64-v0.12.1.tar.xz"],"v0.12.0":["infer-osx-v0.12.0.tar.xz","infer-linux64-v0.12.0.tar.xz"],"v0.11.0":["infer-osx-v0.11.0.tar.xz","infer-linux64-v0.11.0.tar.xz"],"v0.10.0":["infer-osx-v0.10.0.tar.xz","infer-linux64-v0.10.0.tar.xz"],"v0.9.5":["infer-osx-v0.9.5.tar.xz","infer-linux64-v0.9.5.tar.xz"],"v0.9.4.1":["infer-osx-v0.9.4.1.tar.xz","infer-linux64-v0.9.4.1.tar.xz"],"v0.9.4":["infer-osx-v0.9.4.tar.xz","infer-linux64-v0.9.4.tar.xz"],"v0.9.3":["infer-osx-v0.9.3.tar.xz","infer-linux64-v0.9.3.tar.xz"],"v0.9.2":["infer-osx-v0.9.2.tar.xz","infer-linux64-v0.9.2.tar.xz"],"v0.9.1":["infer-osx-v0.9.1.tar.xz","infer-linux64-v0.9.1.tar.xz"],"v0.9.0":["infer-osx-v0.9.0.tar.xz","infer-linux64-v0.9.0.tar.xz"],"v0.8.1":["infer-osx-v0.8.1.tar.xz","infer-linux64-v0.8.1.tar.xz"],"v0.8.0":["infer-osx-v0.8.0.tar.xz","infer-linux64-v0.8.0.tar.xz"],"v0.7.0":["infer-osx-v0.7.0.tar.xz","infer-linux64-v0.7.0.tar.xz"],"v0.6.0":["infer-osx-v0.6.0.tar.xz","infer-linux64-v0.6.0.tar.xz"],"v0.5.0":["infer-osx-v0.5.0.tar.xz","infer-linux64-v0.5.0.tar.xz"],"v0.4.0":["infer-osx-v0.4.0.tar.xz","infer-linux64-v0.4.0.tar.xz"],"v0.3.0":["infer-osx-v0.3.0.tar.xz","infer-linux64-v0.3.0.tar.xz"]}
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/modern/github_facebook_infer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v1.2.0":["infer-osx-x86_64-v1.2.0.tar.xz","infer-osx-arm64-v1.2.0.tar.xz","infer-linux-x86_64-v1.2.0.tar.xz"],"v1.1.0":["infer-linux64-v1.1.0.tar.xz"],"v1.0.0":["infer-osx-v1.0.0.tar.xz","infer-linux64-v1.0.0.tar.xz"],"v0.17.0":["infer-osx-v0.17.0.tar.xz","infer-linux64-v0.17.0.tar.xz"],"v0.16.0":["infer-osx-v0.16.0.tar.xz","infer-linux64-v0.16.0.tar.xz"],"v0.15.0":["infer-osx-v0.15.0.tar.xz","infer-linux64-v0.15.0.tar.xz"],"v0.14.0":["infer-osx-v0.14.0.tar.xz","infer-linux64-v0.14.0.tar.xz"],"v0.13.1":["infer-osx-v0.13.1.tar.xz","infer-linux64-v0.13.1.tar.xz"],"v0.13.0":["infer-osx-v0.13.0.tar.xz","infer-linux64-v0.13.0.tar.xz"],"v0.12.1":["infer-osx-v0.12.1.tar.xz","infer-linux64-v0.12.1.tar.xz"],"v0.12.0":["infer-osx-v0.12.0.tar.xz","infer-linux64-v0.12.0.tar.xz"],"v0.11.0":["infer-osx-v0.11.0.tar.xz","infer-linux64-v0.11.0.tar.xz"],"v0.10.0":["infer-osx-v0.10.0.tar.xz","infer-linux64-v0.10.0.tar.xz"],"v0.9.5":["infer-osx-v0.9.5.tar.xz","infer-linux64-v0.9.5.tar.xz"],"v0.9.4.1":["infer-osx-v0.9.4.1.tar.xz","infer-linux64-v0.9.4.1.tar.xz"],"v0.9.4":["infer-osx-v0.9.4.tar.xz","infer-linux64-v0.9.4.tar.xz"],"v0.9.3":["infer-osx-v0.9.3.tar.xz","infer-linux64-v0.9.3.tar.xz"],"v0.9.2":["infer-osx-v0.9.2.tar.xz","infer-linux64-v0.9.2.tar.xz"],"v0.9.1":["infer-osx-v0.9.1.tar.xz","infer-linux64-v0.9.1.tar.xz"],"v0.9.0":["infer-osx-v0.9.0.tar.xz","infer-linux64-v0.9.0.tar.xz"],"v0.8.1":["infer-osx-v0.8.1.tar.xz","infer-linux64-v0.8.1.tar.xz"],"v0.8.0":["infer-osx-v0.8.0.tar.xz","infer-linux64-v0.8.0.tar.xz"],"v0.7.0":["infer-osx-v0.7.0.tar.xz","infer-linux64-v0.7.0.tar.xz"],"v0.6.0":["infer-osx-v0.6.0.tar.xz","infer-linux64-v0.6.0.tar.xz"],"v0.5.0":["infer-osx-v0.5.0.tar.xz","infer-linux64-v0.5.0.tar.xz"],"v0.4.0":["infer-osx-v0.4.0.tar.xz","infer-linux64-v0.4.0.tar.xz"],"v0.3.0":["infer-osx-v0.3.0.tar.xz","infer-linux64-v0.3.0.tar.xz"]}
2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"clean": "shx rm -rf ./dist ./packages/*/dist ./exe ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/modern ./dist/modern ",
"dev.vite": "cross-env NODE_ENV=development vite build --watch",
"dev.packages": "turbo dev",
"dev": "run-p dev.packages dev.vite",
"dev": "run-p build.json dev.packages dev.vite",
"docs": "shx rm -rf packages/*/README.md && pnpm -r exec readme --path ../../dev/readme/template.md -y && pnpm -r exec ts-readme",
"format": "run-s lint.dprint",
"lint": "turbo lint && run-p --aggregate-output --continue-on-error lint.**",
Expand Down
2 changes: 1 addition & 1 deletion src/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ All the available tools:
{
"compiler and analyzer": {
tools:
"--llvm, --gcc, --msvc, --apple-clang, --vcvarsall, --cppcheck, --clang-tidy, --clang-format, --cpplint, --flawfinder, --lizard",
"--llvm, --gcc, --msvc, --apple-clang, --vcvarsall, --cppcheck, --clang-tidy, --clang-format, --cpplint, --flawfinder, --lizard, --infer",
},
"build system": {
tools: "--cmake, --ninja, --meson, --make, --task, --bazel, --cmakelang, --cmake-lint, --cmake-format",
Expand Down
26 changes: 26 additions & 0 deletions src/infer/__tests__/infer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { cleanupTmpDir, setupTmpDir, testBin } from "../../utils/tests/test-helpers.js"
import { getVersion } from "../../versions/versions.js"
import { setupInfer } from "../infer.js"

jest.setTimeout(300000)

describe("setup-infer", () => {
if (process.platform === "win32") {
return
}

let directory: string
beforeAll(async () => {
directory = await setupTmpDir("infer")
process.env.CACHE_TOOLS = "true"
})

it("should setup infer", async () => {
const { binDir } = await setupInfer(getVersion("infer", "true"), directory, process.arch)
await testBin("infer", ["--version"], binDir)
})

afterAll(async () => {
await cleanupTmpDir("infer")
}, 100000)
})
18 changes: 18 additions & 0 deletions src/infer/assets-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { saveGitHubAssetList } from "../utils/asset/fetch-github-assets.ts"

/**
* Generate the list of all releases of a GitHub repository and save it to a json file
*/
async function main() {
// https://github.com/facebook/infer/releases
await saveGitHubAssetList(
"facebook",
"infer",
"./src/infer/github_facebook_infer.json",
)
}

main().catch((err) => {
console.error(err)
process.exit(1)
})
110 changes: 110 additions & 0 deletions src/infer/github_facebook_infer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"v1.2.0": [
"infer-osx-x86_64-v1.2.0.tar.xz",
"infer-osx-arm64-v1.2.0.tar.xz",
"infer-linux-x86_64-v1.2.0.tar.xz"
],
"v1.1.0": [
"infer-linux64-v1.1.0.tar.xz"
],
"v1.0.0": [
"infer-osx-v1.0.0.tar.xz",
"infer-linux64-v1.0.0.tar.xz"
],
"v0.17.0": [
"infer-osx-v0.17.0.tar.xz",
"infer-linux64-v0.17.0.tar.xz"
],
"v0.16.0": [
"infer-osx-v0.16.0.tar.xz",
"infer-linux64-v0.16.0.tar.xz"
],
"v0.15.0": [
"infer-osx-v0.15.0.tar.xz",
"infer-linux64-v0.15.0.tar.xz"
],
"v0.14.0": [
"infer-osx-v0.14.0.tar.xz",
"infer-linux64-v0.14.0.tar.xz"
],
"v0.13.1": [
"infer-osx-v0.13.1.tar.xz",
"infer-linux64-v0.13.1.tar.xz"
],
"v0.13.0": [
"infer-osx-v0.13.0.tar.xz",
"infer-linux64-v0.13.0.tar.xz"
],
"v0.12.1": [
"infer-osx-v0.12.1.tar.xz",
"infer-linux64-v0.12.1.tar.xz"
],
"v0.12.0": [
"infer-osx-v0.12.0.tar.xz",
"infer-linux64-v0.12.0.tar.xz"
],
"v0.11.0": [
"infer-osx-v0.11.0.tar.xz",
"infer-linux64-v0.11.0.tar.xz"
],
"v0.10.0": [
"infer-osx-v0.10.0.tar.xz",
"infer-linux64-v0.10.0.tar.xz"
],
"v0.9.5": [
"infer-osx-v0.9.5.tar.xz",
"infer-linux64-v0.9.5.tar.xz"
],
"v0.9.4.1": [
"infer-osx-v0.9.4.1.tar.xz",
"infer-linux64-v0.9.4.1.tar.xz"
],
"v0.9.4": [
"infer-osx-v0.9.4.tar.xz",
"infer-linux64-v0.9.4.tar.xz"
],
"v0.9.3": [
"infer-osx-v0.9.3.tar.xz",
"infer-linux64-v0.9.3.tar.xz"
],
"v0.9.2": [
"infer-osx-v0.9.2.tar.xz",
"infer-linux64-v0.9.2.tar.xz"
],
"v0.9.1": [
"infer-osx-v0.9.1.tar.xz",
"infer-linux64-v0.9.1.tar.xz"
],
"v0.9.0": [
"infer-osx-v0.9.0.tar.xz",
"infer-linux64-v0.9.0.tar.xz"
],
"v0.8.1": [
"infer-osx-v0.8.1.tar.xz",
"infer-linux64-v0.8.1.tar.xz"
],
"v0.8.0": [
"infer-osx-v0.8.0.tar.xz",
"infer-linux64-v0.8.0.tar.xz"
],
"v0.7.0": [
"infer-osx-v0.7.0.tar.xz",
"infer-linux64-v0.7.0.tar.xz"
],
"v0.6.0": [
"infer-osx-v0.6.0.tar.xz",
"infer-linux64-v0.6.0.tar.xz"
],
"v0.5.0": [
"infer-osx-v0.5.0.tar.xz",
"infer-linux64-v0.5.0.tar.xz"
],
"v0.4.0": [
"infer-osx-v0.4.0.tar.xz",
"infer-linux64-v0.4.0.tar.xz"
],
"v0.3.0": [
"infer-osx-v0.3.0.tar.xz",
"infer-linux64-v0.3.0.tar.xz"
]
}
85 changes: 85 additions & 0 deletions src/infer/infer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import path, { basename, join } from "path"
import { fileURLToPath } from "url"
import { info } from "ci-log"
import { addExeExt } from "patha"
import { loadAssetList, matchAsset } from "../utils/asset/load-assets.js"
import { arm64, x86_64 } from "../utils/env/arch.js"
import { type InstallationInfo, type PackageInfo, setupBin } from "../utils/setup/setupBin.js"

const dirname = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url))

/** Get the platform data for infer */
async function getInferPackageInfo(version: string, platform: NodeJS.Platform, arch: string): Promise<PackageInfo> {
const { keywords, optionalKeywords } = getAssetKeywords(platform, arch)

// first check the github releases
const inferGitHubAssets = await loadAssetList(
join(dirname, "github_facebook_infer.json"),
)
const ghAsset = matchAsset(
inferGitHubAssets,
{
version,
keywords,
optionalKeywords,
filterMapTag(tag) {
return tag.replace(/^v/, "")
},
},
)

if (ghAsset !== undefined) {
return {
url: `https://github.com/facebook/infer/releases/download/${ghAsset.tag}/${ghAsset.name}`,
extractedFolderName: `${basename(ghAsset.name, ".tar.xz")}`,
binRelativeDir: "bin",
binFileName: addExeExt("infer"),
}
}

throw new Error(`No asset found for version ${version} matching ${keywords} and ${optionalKeywords}`)
}

/** Setup infer */
export function setupInfer(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
return setupBin("infer", version, getInferPackageInfo, setupDir, arch)
}

function getAssetKeywords(platform: string, arch: string) {
const keywords: string[] = []
const optionalKeywords: string[] = []

switch (platform) {
case "linux": {
keywords.push("linux")

if (x86_64.includes(arch)) {
optionalKeywords.push("64")
optionalKeywords.push("x86_64")
} else {
info(`Using arch ${arch} for infer`)
keywords.push(arch)
}
break
}
case "darwin": {
keywords.push("osx")

if (x86_64.includes(arch)) {
optionalKeywords.push("x86_64")
} else if (arm64.includes(arch)) {
// allow falling back to x86_64 if arm64 is not available
optionalKeywords.push("arm64")
} else {
info(`Using arch ${arch} for infer`)
keywords.push(arch)
}
break
}
default:
info(`Using ${platform} ${arch} for infer`)
keywords.push(platform, arch)
break
}
return { keywords, optionalKeywords }
}
2 changes: 1 addition & 1 deletion src/llvm/llvm_url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async function getAssetKeywords(platform: string, arch: string) {
}
default:
info(`Using ${platform} ${arch} for LLVM`)
optionalKeywords.push(platform, arch)
keywords.push(platform, arch)
break
}
return { keywords, optionalKeywords }
Expand Down
2 changes: 2 additions & 0 deletions src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { setupFlawfinder } from "./flawfinder/flawfinder.js"
import { setupGcc, setupMingw } from "./gcc/gcc.js"
import { setupGcovr } from "./gcovr/gcovr.js"
import { setupGraphviz } from "./graphviz/graphviz.js"
import { setupInfer } from "./infer/infer.js"
import { setupKcov } from "./kcov/kcov.js"
import { setupLizard } from "./lizard/lizard.js"
import { setupAppleClang } from "./llvm/apple-clang.js"
Expand Down Expand Up @@ -87,6 +88,7 @@ export const setups = {
cpplint: setupCpplint,
flawfinder: setupFlawfinder,
lizard: setupLizard,
infer: setupInfer,
"clang-tidy": setupClangTools,
clangtidy: setupClangTools,
"clang-format": setupClangFormat,
Expand Down
1 change: 1 addition & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const viteConfig = defineConfig({
: "es",
},
},
emptyOutDir: process.env.NODE_ENV === "production",
},
resolve: {
alias: {
Expand Down

0 comments on commit 69b2c1b

Please sign in to comment.