Merge pull request #297 from aminya/cpplint [skip ci]

This commit is contained in:
Amin Yahyaabadi 2024-09-19 14:34:45 -07:00 committed by GitHub
commit 5d12f41e90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 350 additions and 17 deletions

View File

@ -14,15 +14,16 @@ 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 |
| 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 | llvm, gcc, msvc, apple-clang, vcvarsall |
| build system | cmake, ninja, meson, make, task, bazel |
| package manager | vcpkg, conan, choco, brew, nala |
| analyzer/linter | clang-tidy, clang-format, cppcheck, cpplint, flawfinder, lizard, infer, cmakelang, cmake-format, cmake-lint |
| 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`).

View File

@ -55,6 +55,18 @@ inputs:
cppcheck:
description: "Wether to install cppcheck (true/false) or the specific version to install."
required: false
cpplint:
description: "Wether to install cpplint (true/false) or the specific version to install."
required: false
flawfinder:
description: "Wether to install flawfinder (true/false) or the specific version to install."
required: false
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

View File

@ -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"]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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"]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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.**",

View File

@ -33,12 +33,16 @@ All the available tools:
console.table(
{
"compiler and analyzer": {
tools: "--llvm, --gcc, --msvc, --apple-clang, --vcvarsall, --cppcheck, --clang-tidy, --clang-format",
tools: "--llvm, --gcc, --msvc, --apple-clang, --vcvarsall",
},
"build system": {
tools: "--cmake, --ninja, --meson, --make, --task, --bazel, --cmakelang, --cmake-lint, --cmake-format",
tools: "--cmake, --ninja, --meson, --make, --task, --bazel",
},
"package manager": { tools: "--vcpkg, --conan, --choco, --brew, --nala" },
"analyzer/linter": {
tools:
"--clang-tidy, --clang-format, --cppcheck, --cpplint, --flawfinder, --lizard, --infer, , --cmakelang, --cmake-lint, --cmake-format",
},
cache: { tools: "--ccache, --sccache" },
documentation: { tools: "--doxygen, --graphviz" },
coverage: { tools: "--gcovr, --opencppcoverage, --kcov" },

View File

@ -0,0 +1,12 @@
import { ubuntuVersion } from "../../utils/env/ubuntu_version.js"
import { testBin } from "../../utils/tests/test-helpers.js"
import { getVersion } from "../../versions/versions.js"
import { setupCpplint } from "../cpplint.js"
jest.setTimeout(300000)
describe("setup-cpplint", () => {
it("should setup cpplint", async () => {
const installInfo = await setupCpplint(getVersion("cpplint", "true", await ubuntuVersion()), "", process.arch)
await testBin("cpplint", ["--version"], installInfo.binDir)
})
})

6
src/cpplint/cpplint.ts Normal file
View File

@ -0,0 +1,6 @@
import { setupPipPack } from "../utils/setup/setupPipPack.js"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupCpplint(version: string | undefined, _setupDir: string, _arch: string) {
return setupPipPack("cpplint", version)
}

View File

@ -0,0 +1,12 @@
import { ubuntuVersion } from "../../utils/env/ubuntu_version.js"
import { testBin } from "../../utils/tests/test-helpers.js"
import { getVersion } from "../../versions/versions.js"
import { setupFlawfinder } from "../flawfinder.js"
jest.setTimeout(300000)
describe("setup-flawfinder", () => {
it("should setup flawfinder", async () => {
const installInfo = await setupFlawfinder(getVersion("flawfinder", "true", await ubuntuVersion()), "", process.arch)
await testBin("flawfinder", ["--version"], installInfo.binDir)
})
})

View File

@ -0,0 +1,6 @@
import { setupPipPack } from "../utils/setup/setupPipPack.js"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupFlawfinder(version: string | undefined, _setupDir: string, _arch: string) {
return setupPipPack("flawfinder", version)
}

View File

@ -0,0 +1,38 @@
import { info } from "ci-log"
import { isUbuntu } from "../../utils/env/isUbuntu.js"
import { ubuntuVersion } from "../../utils/env/ubuntu_version.js"
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") {
it("should skip infer tests on windows", () => {
expect(true).toBe(true)
})
return
}
let directory: string
beforeAll(async () => {
directory = await setupTmpDir("infer")
process.env.CACHE_TOOLS = "true"
})
it("should setup infer", async () => {
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
if (isUbuntu() && (await ubuntuVersion())?.[0]! <= 20) {
info("Skipping infer test on ubuntu 20 and below")
return
}
const { binDir } = await setupInfer(getVersion("infer", "true"), directory, process.arch)
await testBin("infer", ["--version"], binDir)
})
afterAll(async () => {
await cleanupTmpDir("infer")
}, 100000)
})

18
src/infer/assets-list.ts Normal file
View File

@ -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)
})

View File

@ -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
src/infer/infer.ts Normal file
View File

@ -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 }
}

View File

@ -0,0 +1,12 @@
import { ubuntuVersion } from "../../utils/env/ubuntu_version.js"
import { testBin } from "../../utils/tests/test-helpers.js"
import { getVersion } from "../../versions/versions.js"
import { setupLizard } from "../lizard.js"
jest.setTimeout(300000)
describe("setup-lizard", () => {
it("should setup lizard", async () => {
const installInfo = await setupLizard(getVersion("lizard", "true", await ubuntuVersion()), "", process.arch)
await testBin("lizard", ["--version"], installInfo.binDir)
})
})

6
src/lizard/lizard.ts Normal file
View File

@ -0,0 +1,6 @@
import { setupPipPack } from "../utils/setup/setupPipPack.js"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setupLizard(version: string | undefined, _setupDir: string, _arch: string) {
return setupPipPack("lizard", version)
}

View File

@ -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 }

View File

@ -6,11 +6,15 @@ import { setupCmake } from "./cmake/cmake.js"
import { setupCmakelang } from "./cmakelang/cmakelang.js"
import { setupConan } from "./conan/conan.js"
import { setupCppcheck } from "./cppcheck/cppcheck.js"
import { setupCpplint } from "./cpplint/cpplint.js"
import { setupDoxygen } from "./doxygen/doxygen.js"
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"
import { setupClangFormat, setupClangTools, setupLLVM } from "./llvm/llvm.js"
import { setupMake } from "./make/make.js"
@ -81,6 +85,10 @@ export const setups = {
doxygen: setupDoxygen,
graphviz: setupGraphviz,
cppcheck: setupCppcheck,
cpplint: setupCpplint,
flawfinder: setupFlawfinder,
lizard: setupLizard,
infer: setupInfer,
"clang-tidy": setupClangTools,
clangtidy: setupClangTools,
"clang-format": setupClangFormat,

View File

@ -21,6 +21,7 @@ const viteConfig = defineConfig({
: "es",
},
},
emptyOutDir: process.env.NODE_ENV === "production",
},
resolve: {
alias: {