mirror of https://github.com/aminya/setup-cpp.git
feat: add git as an installable tool
This commit is contained in:
parent
627988e604
commit
43327b967b
|
|
@ -31,7 +31,7 @@ Setting up a **cross-platform** environment for building and testing C++/C proje
|
|||
| --------------- | ----------------------------------------------------------------------------------------------------------- |
|
||||
| compiler | llvm, gcc, msvc, apple-clang, vcvarsall |
|
||||
| build system | cmake, ninja, meson, make, task, bazel |
|
||||
| package manager | vcpkg, conan, choco, brew, nala, setup-cpp |
|
||||
| package manager | vcpkg, conan, choco, brew, nala, git, setup-cpp |
|
||||
| analyzer/linter | clang-tidy, clang-format, cppcheck, cpplint, flawfinder, lizard, infer, cmakelang, cmake-format, cmake-lint |
|
||||
| cache | ccache, sccache |
|
||||
| documentation | doxygen, graphviz |
|
||||
|
|
|
|||
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
|
|
@ -42,7 +42,7 @@ All the available tools:
|
|||
"build system": {
|
||||
tools: "--cmake, --ninja, --meson, --make, --task, --bazel",
|
||||
},
|
||||
"package manager": { tools: "--vcpkg, --conan, --choco, --brew, --nala, --setup-cpp" },
|
||||
"package manager": { tools: "--vcpkg, --conan, --choco, --brew, --nala, --git, --setup-cpp" },
|
||||
"analyzer/linter": {
|
||||
tools:
|
||||
"--clang-tidy, --clang-format, --cppcheck, --cpplint, --flawfinder, --lizard, --infer, , --cmakelang, --cmake-lint, --cmake-format",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
import type { InstallationInfo } from "../../utils/setup/setupBin.js"
|
||||
import { testBin } from "../../utils/tests/test-helpers.js"
|
||||
import { setupGit } from "../git.js"
|
||||
|
||||
jest.setTimeout(300000)
|
||||
describe("setup-git", () => {
|
||||
it("should setup git", async () => {
|
||||
const installInfo = await setupGit("", "", process.arch)
|
||||
|
||||
await testBin("git", ["--version"], (installInfo as InstallationInfo | undefined)?.binDir)
|
||||
})
|
||||
})
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import { installAptPack } from "setup-apt"
|
||||
import { installBrewPack } from "setup-brew"
|
||||
import { hasDnf } from "../utils/env/hasDnf.js"
|
||||
import { isArch } from "../utils/env/isArch.js"
|
||||
import { isUbuntu } from "../utils/env/isUbuntu.js"
|
||||
import { setupChocoPack } from "../utils/setup/setupChocoPack.js"
|
||||
import { setupDnfPack } from "../utils/setup/setupDnfPack.js"
|
||||
import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function setupGit(version: string, _setupDir: string, _arch: string) {
|
||||
switch (process.platform) {
|
||||
case "win32": {
|
||||
return setupChocoPack("git", version)
|
||||
}
|
||||
case "darwin": {
|
||||
return installBrewPack("git", version)
|
||||
}
|
||||
case "linux": {
|
||||
if (isArch()) {
|
||||
return setupPacmanPack("git", version)
|
||||
} else if (hasDnf()) {
|
||||
return setupDnfPack([{ name: "git", version }])
|
||||
} else if (isUbuntu()) {
|
||||
return installAptPack([{ name: "git", version }])
|
||||
}
|
||||
throw new Error("Unsupported linux distribution")
|
||||
}
|
||||
default: {
|
||||
throw new Error("Unsupported platform")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import { setupFlawfinder } from "./flawfinder/flawfinder.js"
|
|||
import { setupGcc } from "./gcc/gcc.js"
|
||||
import { setupMingw } from "./gcc/mingw.js"
|
||||
import { setupGcovr } from "./gcovr/gcovr.js"
|
||||
import { setupGit } from "./git/git.js"
|
||||
import { setupGraphviz } from "./graphviz/graphviz.js"
|
||||
import { setupInfer } from "./infer/infer.js"
|
||||
import { setupKcov } from "./kcov/kcov.js"
|
||||
|
|
@ -60,6 +61,7 @@ export const llvmTools = ["llvm", "clang", "clang++", "clang-tidy", "clang-forma
|
|||
|
||||
/** The setup functions */
|
||||
export const setups = {
|
||||
git: setupGit,
|
||||
nala: setupNala,
|
||||
brew: setupBrew,
|
||||
choco: setupChocolatey,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { addShExt, addShRelativePrefix } from "patha"
|
|||
import { installAptPack } from "setup-apt"
|
||||
import which from "which"
|
||||
import { rcOptions } from "../cli-options.js"
|
||||
import { setupGit } from "../git/git.js"
|
||||
import { arm64 } from "../utils/env/arch.js"
|
||||
import { hasDnf } from "../utils/env/hasDnf.js"
|
||||
import { isArch } from "../utils/env/isArch.js"
|
||||
|
|
@ -19,74 +20,77 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
|
|||
let hasVCPKG = false
|
||||
|
||||
export async function setupVcpkg(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
|
||||
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
|
||||
if (process.platform === "linux") {
|
||||
// vcpkg download and extraction dependencies
|
||||
if (isArch()) {
|
||||
await Promise.all([
|
||||
setupPacmanPack("curl"),
|
||||
setupPacmanPack("zip"),
|
||||
setupPacmanPack("unzip"),
|
||||
setupPacmanPack("tar"),
|
||||
setupPacmanPack("git"),
|
||||
setupPacmanPack("pkg-config"),
|
||||
])
|
||||
} else if (hasDnf()) {
|
||||
await setupDnfPack([
|
||||
{ name: "curl" },
|
||||
{ name: "zip" },
|
||||
{ name: "unzip" },
|
||||
{ name: "tar" },
|
||||
{ name: "git" },
|
||||
{ name: "pkg-config" },
|
||||
])
|
||||
} else if (isUbuntu()) {
|
||||
await installAptPack([
|
||||
{ name: "curl" },
|
||||
{ name: "zip" },
|
||||
{ name: "unzip" },
|
||||
{ name: "tar" },
|
||||
{ name: "git" },
|
||||
{ name: "pkg-config" },
|
||||
])
|
||||
}
|
||||
}
|
||||
const vcpkg = await which("vcpkg", { nothrow: true })
|
||||
|
||||
// clone if not already exists
|
||||
if (!(await pathExists(join(setupDir, addShExt("bootstrap-vcpkg", ".bat"))))) {
|
||||
execaSync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir), stdio: "inherit" })
|
||||
} else {
|
||||
notice(`Vcpkg folder already exists at ${setupDir}. Skipping the clone`)
|
||||
}
|
||||
|
||||
// if version specified, checkout the version
|
||||
if (version !== "" && version !== "true") {
|
||||
info(`Checking out vcpkg version ${version}`)
|
||||
execaSync("git", ["checkout", version], {
|
||||
cwd: setupDir,
|
||||
stdio: "inherit",
|
||||
})
|
||||
}
|
||||
|
||||
// Add VCPKG_FORCE_SYSTEM_BINARIES=1 for Linux arm64
|
||||
if (process.platform === "linux" && arch in arm64) {
|
||||
await addEnv("VCPKG_FORCE_SYSTEM_BINARIES", "1")
|
||||
}
|
||||
|
||||
// bootstrap vcpkg
|
||||
execaSync(addShExt(addShRelativePrefix("bootstrap-vcpkg"), ".bat"), {
|
||||
cwd: setupDir,
|
||||
shell: true,
|
||||
stdio: "inherit",
|
||||
})
|
||||
|
||||
await grantUserWriteAccess(setupDir)
|
||||
|
||||
await addPath(setupDir, rcOptions)
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
hasVCPKG = true
|
||||
return { binDir: setupDir }
|
||||
if (hasVCPKG && vcpkg !== null) {
|
||||
return { binDir: dirname(vcpkg) }
|
||||
}
|
||||
|
||||
return { binDir: dirname(which.sync("vcpkg")) }
|
||||
// vcpkg dependencies
|
||||
await setupGit("", setupDir, arch)
|
||||
|
||||
if (process.platform === "linux") {
|
||||
if (isArch()) {
|
||||
await Promise.all([
|
||||
setupPacmanPack("curl"),
|
||||
setupPacmanPack("zip"),
|
||||
setupPacmanPack("unzip"),
|
||||
setupPacmanPack("tar"),
|
||||
setupPacmanPack("pkg-config"),
|
||||
])
|
||||
} else if (hasDnf()) {
|
||||
await setupDnfPack([
|
||||
{ name: "curl" },
|
||||
{ name: "zip" },
|
||||
{ name: "unzip" },
|
||||
{ name: "tar" },
|
||||
{ name: "pkg-config" },
|
||||
])
|
||||
} else if (isUbuntu()) {
|
||||
await installAptPack([
|
||||
{ name: "curl" },
|
||||
{ name: "zip" },
|
||||
{ name: "unzip" },
|
||||
{ name: "tar" },
|
||||
{ name: "pkg-config" },
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
// clone if not already exists
|
||||
if (!(await pathExists(join(setupDir, addShExt("bootstrap-vcpkg", ".bat"))))) {
|
||||
execaSync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir), stdio: "inherit" })
|
||||
} else {
|
||||
notice(`Vcpkg folder already exists at ${setupDir}. Skipping the clone`)
|
||||
}
|
||||
|
||||
// if version specified, checkout the version
|
||||
if (version !== "" && version !== "true") {
|
||||
info(`Checking out vcpkg version ${version}`)
|
||||
execaSync("git", ["checkout", version], {
|
||||
cwd: setupDir,
|
||||
stdio: "inherit",
|
||||
})
|
||||
}
|
||||
|
||||
// Add VCPKG_FORCE_SYSTEM_BINARIES=1 for Linux arm64
|
||||
if (process.platform === "linux" && arch in arm64) {
|
||||
await addEnv("VCPKG_FORCE_SYSTEM_BINARIES", "1")
|
||||
}
|
||||
|
||||
// bootstrap vcpkg
|
||||
execaSync(addShExt(addShRelativePrefix("bootstrap-vcpkg"), ".bat"), {
|
||||
cwd: setupDir,
|
||||
shell: true,
|
||||
stdio: "inherit",
|
||||
})
|
||||
|
||||
await grantUserWriteAccess(setupDir)
|
||||
|
||||
await addPath(setupDir, rcOptions)
|
||||
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
hasVCPKG = true
|
||||
|
||||
return { binDir: setupDir }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue