Skip to content

Commit 1077091

Browse files
committed
fix: print a warning if no tool was installed
1 parent 5add80e commit 1077091

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The package can be used locally or from CI services like GitHub Actions.
3737

3838
# Usage
3939

40-
# From Terminal
40+
## From Terminal
4141

4242
You should download the executable file or the js file (if Nodejs installed), and run it with the available options.
4343

@@ -105,7 +105,7 @@ sudo node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true
105105
source ~/.profile # reload the environment
106106
```
107107

108-
# Inside GitHub Actions
108+
## Inside GitHub Actions
109109

110110
Here is a complete cross-platform example that tests llvm, gcc, and msvc. It also uses cmake, ninja, vcpkg, and cppcheck.
111111

@@ -157,14 +157,16 @@ jobs:
157157
uses: aminya/setup-cpp@v1
158158
with:
159159
compiler: ${{ matrix.compiler }}
160+
vcvarsall: ${{ contains(matrix.os, 'windows') }}
160161
cmake: true
161162
ninja: true
162163
vcpkg: true
163-
cppcheck: true # instead of `true`, which chooses the default version, you can pass a specific version.
164-
# add any tool that you need here...
164+
cppcheck: true
165+
clangtidy: true # instead of `true`, which chooses the default version, you can pass a specific version.
166+
# ...
165167
```
166168

167-
# Inside Docker
169+
## Inside Docker
168170

169171
Here is an example for using setup_cpp to make a builder image that has the Cpp tools you need.
170172

@@ -196,15 +198,15 @@ If you want to build the ones included, then run:
196198
docker build -f ./building/docker/debian.dockerfile -t setup_cpp .
197199
```
198200

199-
Where you should use the path to the docker after `-f`.
201+
Where you should use the path to the dockerfile after `-f`.
200202

201203
After build, run the following to start an interactive shell in your container
202204

203205
```ps1
204206
docker run -it setup_cpp
205207
```
206208

207-
# Inside Docker inside GitHub Actions
209+
## Inside Docker inside GitHub Actions
208210

209211
You can use the docker file discussed in the previous section inside GitHub Actions like the following:
210212

@@ -226,7 +228,7 @@ jobs:
226228
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
227229
```
228230
229-
# GitLab PipeLines
231+
## Inside GitLab pipelines
230232
231233
The following gives an example for setting up a C++ environment inside GitLab pipelines.
232234
@@ -289,6 +291,7 @@ test_linux_gcc:
289291

290292
# Usage Examples
291293

294+
- [cpp-best-practices starter project](https://github.com/cpp-best-practices/cpp_starter_project)
292295
- [libclang](https://github.com/atilaneves/libclang)
293296
- [dpp](https://github.com/atilaneves/dpp)
294297
- [d-tree-sitter](https://github.com/aminya/d-tree-sitter)

dist/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import semverValid from "semver/functions/valid"
2121
import { getVersion } from "./default_versions"
2222
import { setupGcc } from "./gcc/gcc"
2323
import { InstallationInfo } from "./utils/setup/setupBin"
24-
import { error, success } from "./utils/io/io"
24+
import { error, success, warning } from "./utils/io/io"
2525
import { setupVcpkg } from "./vcpkg/vcpkg"
2626
import { join } from "path"
2727
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
@@ -134,11 +134,7 @@ export async function main(args: string[]): Promise<number> {
134134
installationInfo = await setupFunction(getVersion(tool, value), join(setupCppDir, tool), arch)
135135
}
136136
// preparing a report string
137-
if (installationInfo !== undefined) {
138-
successMessages.push(getSuccessMessage(tool, installationInfo))
139-
} else {
140-
successMessages.push(`${tool} was successfully installed`)
141-
}
137+
successMessages.push(getSuccessMessage(tool, installationInfo))
142138
} catch (e) {
143139
// push error message to the logger
144140
error(e as string | Error)
@@ -158,14 +154,20 @@ export async function main(args: string[]): Promise<number> {
158154
case "llvm":
159155
case "clang":
160156
case "clang++": {
161-
await setupLLVM(getVersion("llvm", version) as string, join(setupCppDir, "llvm"), arch)
157+
const installationInfo = await setupLLVM(
158+
getVersion("llvm", version) as string,
159+
join(setupCppDir, "llvm"),
160+
arch
161+
)
162+
successMessages.push(getSuccessMessage("llvm", installationInfo))
162163
break
163164
}
164165
case "gcc":
165166
case "mingw":
166167
case "cygwin":
167168
case "msys": {
168-
await setupGcc(getVersion("gcc", version) as string, join(setupCppDir, "gcc"), arch)
169+
const installationInfo = await setupGcc(getVersion("gcc", version) as string, join(setupCppDir, "gcc"), arch)
170+
successMessages.push(getSuccessMessage("gcc", installationInfo))
169171
break
170172
}
171173
case "cl":
@@ -175,14 +177,20 @@ export async function main(args: string[]): Promise<number> {
175177
case "visualstudio":
176178
case "visualcpp":
177179
case "visualc++": {
178-
await setupMSVC(getVersion("msvc", version) as string, join(setupCppDir, "msvc"), arch)
180+
const installationInfo = await setupMSVC(
181+
getVersion("msvc", version) as string,
182+
join(setupCppDir, "msvc"),
183+
arch
184+
)
185+
successMessages.push(getSuccessMessage("msvc", installationInfo))
179186
break
180187
}
181188
case "appleclang":
182189
case "applellvm": {
183190
core.info("Assuming apple-clang is already installed")
184191
addEnv("CC", "clang")
185192
addEnv("CXX", "clang++")
193+
successMessages.push(getSuccessMessage("apple-clang", undefined))
186194
break
187195
}
188196
default: {
@@ -195,6 +203,11 @@ export async function main(args: string[]): Promise<number> {
195203
errorMessages.push(`Failed to install the ${maybeCompiler}`)
196204
}
197205

206+
if (successMessages.length === 0 && errorMessages.length === 0) {
207+
warning("setup_cpp was called without any arguments. Nothing to do.")
208+
return 0
209+
}
210+
198211
// report the messages in the end
199212
successMessages.forEach((tool) => success(tool))
200213
errorMessages.forEach((tool) => error(tool))
@@ -292,8 +305,11 @@ function maybeGetInput(key: string) {
292305
return undefined // skip installation
293306
}
294307

295-
function getSuccessMessage(tool: string, installationInfo: InstallationInfo) {
308+
function getSuccessMessage(tool: string, installationInfo: InstallationInfo | undefined | void) {
296309
let msg = `${tool} was successfully installed`
310+
if (installationInfo === undefined) {
311+
return msg
312+
}
297313
if ("installDir" in installationInfo) {
298314
msg += `\nThe installation directory is ${installationInfo.installDir}`
299315
}

src/utils/io/io.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ export function error(err: string | Error) {
88
export function success(msg: string) {
99
return isGitHubCI() ? core.info(msg) : console.log(`\x1b[32m${msg}\x1b[0m`)
1010
}
11+
12+
export function warning(msg: string) {
13+
return isGitHubCI() ? core.warning(msg) : console.log(`\x1b[33m${msg}\x1b[0m`)
14+
}

0 commit comments

Comments
 (0)