-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathsetup-cpp.ts
More file actions
144 lines (125 loc) · 4.3 KB
/
Copy pathsetup-cpp.ts
File metadata and controls
144 lines (125 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env node
/* eslint-disable node/shebang */
import mri from "mri"
import updateNotifier from "simple-update-notifier"
import packageJson from "../package-version.json"
import { maybeGetInput } from "./actions-input.js"
import { GITHUB_ACTIONS, type Inputs, error, info, inputs, setupCpp, success, warning } from "./lib.ts"
import type { Opts } from "./options.js"
/** The main entry function */
async function main(args: string[]): Promise<number> {
const checkUpdatePromise = GITHUB_ACTIONS ? Promise.resolve() : checkUpdates()
// parse options using mri or github actions
const opts = parseArgs(args)
// print help
if (opts.help) {
printHelp()
return 0
}
// print version
if (opts.version) {
info(`${packageJson.version}`)
return 0
}
const { successMessages, errorMessages } = await setupCpp(opts)
// report the messages in the end
for (const tool of successMessages) {
success(tool)
}
for (const tool of errorMessages) {
error(tool)
}
if (successMessages.length !== 0 || errorMessages.length !== 0) {
info("setup-cpp finished")
if (!GITHUB_ACTIONS) {
switch (process.platform) {
case "win32": {
warning("Run `RefreshEnv.cmd` or restart your shell to update the environment.")
break
}
case "linux":
case "darwin": {
warning("Run `source ~/.cpprc` or restart your shell to update the environment.")
break
}
default: {
// nothing
}
}
}
}
await checkUpdatePromise
return errorMessages.length === 0 ? 0 : 1
}
// auto self update notifier
async function checkUpdates() {
try {
await updateNotifier({ pkg: packageJson })
} catch (err) {
warning(`Failed to check for updates: ${err instanceof Error ? err.message + err.stack : err}`)
}
}
/**
* The options for the setup-cpp function
*/
type CliOpts = Opts & {
help: boolean
version: boolean
}
export function parseArgs(args: string[]): CliOpts {
const defaults = Object.fromEntries(inputs.map((inp) => [inp, maybeGetInput(inp)]))
return mri<Record<Inputs, string | undefined> & { help: boolean; version: boolean; "setup-cpp": boolean }>(args, {
string: [...inputs, "timeout", "node-package-manager"],
default: defaults,
alias: { h: "help", v: "version" },
boolean: ["help", "version", "setup-cpp"],
})
}
export function printHelp() {
info(`
setup-cpp [options]
setup-cpp --compiler llvm --cmake true --ninja true --ccache true --vcpkg true
Install all the tools required for building and testing C++/C projects.
--architecture\t the cpu architecture to install the tools for. By default it uses the current CPU architecture.
--timeout\t the timeout for the installation of each tool in minutes. By default it is 10 minutes.
--compiler\t the <compiler> to install.
\t You can specify the version instead of specifying just the name e.g: --compiler 'llvm-13.0.0'
--tool_name\t pass "true" or pass the <version> you would like to install for this tool. e.g. --conan true or --conan "1.42.1"
--nodePackageManager\t the node package manager to use (npm/yarn/pnpm) when installing setup-cpp globally
--help\t show this help message
--version\t show the version of setup-cpp
All the available tools:
`)
console.table(
{
"compiler and analyzer": {
tools: "--llvm, --gcc, --msvc, --apple-clang, --vcvarsall",
},
"build system": {
tools: "--cmake, --ninja, --meson, --make, --autoreconf, --task, --bazel",
},
"package manager": { tools: "--vcpkg, --conan, --choco, --brew, --apt-fast, --nala, --git, --setup-cpp" },
"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" },
other: { tools: "--python, --powershell, --sevenzip, --tar" },
},
["tools"],
)
}
// Run main
if (process.env.SETUP_CPP_SKIP_MAIN !== "true") {
main(process.argv)
.then((ret) => {
process.exitCode = ret
})
.catch((err) => {
error("main() panicked!")
error(err as string | Error)
process.exitCode = 1
})
}