fix: print a warning if no tool was installed

This commit is contained in:
Amin Yahyaabadi 2022-01-29 15:13:52 -08:00
parent 5add80e442
commit 10770915e5
5 changed files with 43 additions and 20 deletions

View File

@ -37,7 +37,7 @@ The package can be used locally or from CI services like GitHub Actions.
# Usage # Usage
# From Terminal ## From Terminal
You should download the executable file or the js file (if Nodejs installed), and run it with the available options. You should download the executable file or the js file (if Nodejs installed), and run it with the available options.
@ -105,7 +105,7 @@ sudo node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true
source ~/.profile # reload the environment source ~/.profile # reload the environment
``` ```
# Inside GitHub Actions ## Inside GitHub Actions
Here is a complete cross-platform example that tests llvm, gcc, and msvc. It also uses cmake, ninja, vcpkg, and cppcheck. Here is a complete cross-platform example that tests llvm, gcc, and msvc. It also uses cmake, ninja, vcpkg, and cppcheck.
@ -157,14 +157,16 @@ jobs:
uses: aminya/setup-cpp@v1 uses: aminya/setup-cpp@v1
with: with:
compiler: ${{ matrix.compiler }} compiler: ${{ matrix.compiler }}
vcvarsall: ${{ contains(matrix.os, 'windows') }}
cmake: true cmake: true
ninja: true ninja: true
vcpkg: true vcpkg: true
cppcheck: true # instead of `true`, which chooses the default version, you can pass a specific version. cppcheck: true
# add any tool that you need here... clangtidy: true # instead of `true`, which chooses the default version, you can pass a specific version.
# ...
``` ```
# Inside Docker ## Inside Docker
Here is an example for using setup_cpp to make a builder image that has the Cpp tools you need. Here is an example for using setup_cpp to make a builder image that has the Cpp tools you need.
@ -196,7 +198,7 @@ If you want to build the ones included, then run:
docker build -f ./building/docker/debian.dockerfile -t setup_cpp . docker build -f ./building/docker/debian.dockerfile -t setup_cpp .
``` ```
Where you should use the path to the docker after `-f`. Where you should use the path to the dockerfile after `-f`.
After build, run the following to start an interactive shell in your container After build, run the following to start an interactive shell in your container
@ -204,7 +206,7 @@ After build, run the following to start an interactive shell in your container
docker run -it setup_cpp docker run -it setup_cpp
``` ```
# Inside Docker inside GitHub Actions ## Inside Docker inside GitHub Actions
You can use the docker file discussed in the previous section inside GitHub Actions like the following: You can use the docker file discussed in the previous section inside GitHub Actions like the following:
@ -226,7 +228,7 @@ jobs:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true ACTIONS_ALLOW_UNSECURE_COMMANDS: true
``` ```
# GitLab PipeLines ## Inside GitLab pipelines
The following gives an example for setting up a C++ environment inside GitLab pipelines. The following gives an example for setting up a C++ environment inside GitLab pipelines.
@ -289,6 +291,7 @@ test_linux_gcc:
# Usage Examples # Usage Examples
- [cpp-best-practices starter project](https://github.com/cpp-best-practices/cpp_starter_project)
- [libclang](https://github.com/atilaneves/libclang) - [libclang](https://github.com/atilaneves/libclang)
- [dpp](https://github.com/atilaneves/dpp) - [dpp](https://github.com/atilaneves/dpp)
- [d-tree-sitter](https://github.com/aminya/d-tree-sitter) - [d-tree-sitter](https://github.com/aminya/d-tree-sitter)

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -21,7 +21,7 @@ import semverValid from "semver/functions/valid"
import { getVersion } from "./default_versions" import { getVersion } from "./default_versions"
import { setupGcc } from "./gcc/gcc" import { setupGcc } from "./gcc/gcc"
import { InstallationInfo } from "./utils/setup/setupBin" import { InstallationInfo } from "./utils/setup/setupBin"
import { error, success } from "./utils/io/io" import { error, success, warning } from "./utils/io/io"
import { setupVcpkg } from "./vcpkg/vcpkg" import { setupVcpkg } from "./vcpkg/vcpkg"
import { join } from "path" import { join } from "path"
import { setupVCVarsall } from "./vcvarsall/vcvarsall" import { setupVCVarsall } from "./vcvarsall/vcvarsall"
@ -134,11 +134,7 @@ export async function main(args: string[]): Promise<number> {
installationInfo = await setupFunction(getVersion(tool, value), join(setupCppDir, tool), arch) installationInfo = await setupFunction(getVersion(tool, value), join(setupCppDir, tool), arch)
} }
// preparing a report string // preparing a report string
if (installationInfo !== undefined) {
successMessages.push(getSuccessMessage(tool, installationInfo)) successMessages.push(getSuccessMessage(tool, installationInfo))
} else {
successMessages.push(`${tool} was successfully installed`)
}
} catch (e) { } catch (e) {
// push error message to the logger // push error message to the logger
error(e as string | Error) error(e as string | Error)
@ -158,14 +154,20 @@ export async function main(args: string[]): Promise<number> {
case "llvm": case "llvm":
case "clang": case "clang":
case "clang++": { case "clang++": {
await setupLLVM(getVersion("llvm", version) as string, join(setupCppDir, "llvm"), arch) const installationInfo = await setupLLVM(
getVersion("llvm", version) as string,
join(setupCppDir, "llvm"),
arch
)
successMessages.push(getSuccessMessage("llvm", installationInfo))
break break
} }
case "gcc": case "gcc":
case "mingw": case "mingw":
case "cygwin": case "cygwin":
case "msys": { case "msys": {
await setupGcc(getVersion("gcc", version) as string, join(setupCppDir, "gcc"), arch) const installationInfo = await setupGcc(getVersion("gcc", version) as string, join(setupCppDir, "gcc"), arch)
successMessages.push(getSuccessMessage("gcc", installationInfo))
break break
} }
case "cl": case "cl":
@ -175,7 +177,12 @@ export async function main(args: string[]): Promise<number> {
case "visualstudio": case "visualstudio":
case "visualcpp": case "visualcpp":
case "visualc++": { case "visualc++": {
await setupMSVC(getVersion("msvc", version) as string, join(setupCppDir, "msvc"), arch) const installationInfo = await setupMSVC(
getVersion("msvc", version) as string,
join(setupCppDir, "msvc"),
arch
)
successMessages.push(getSuccessMessage("msvc", installationInfo))
break break
} }
case "appleclang": case "appleclang":
@ -183,6 +190,7 @@ export async function main(args: string[]): Promise<number> {
core.info("Assuming apple-clang is already installed") core.info("Assuming apple-clang is already installed")
addEnv("CC", "clang") addEnv("CC", "clang")
addEnv("CXX", "clang++") addEnv("CXX", "clang++")
successMessages.push(getSuccessMessage("apple-clang", undefined))
break break
} }
default: { default: {
@ -195,6 +203,11 @@ export async function main(args: string[]): Promise<number> {
errorMessages.push(`Failed to install the ${maybeCompiler}`) errorMessages.push(`Failed to install the ${maybeCompiler}`)
} }
if (successMessages.length === 0 && errorMessages.length === 0) {
warning("setup_cpp was called without any arguments. Nothing to do.")
return 0
}
// report the messages in the end // report the messages in the end
successMessages.forEach((tool) => success(tool)) successMessages.forEach((tool) => success(tool))
errorMessages.forEach((tool) => error(tool)) errorMessages.forEach((tool) => error(tool))
@ -292,8 +305,11 @@ function maybeGetInput(key: string) {
return undefined // skip installation return undefined // skip installation
} }
function getSuccessMessage(tool: string, installationInfo: InstallationInfo) { function getSuccessMessage(tool: string, installationInfo: InstallationInfo | undefined | void) {
let msg = `${tool} was successfully installed` let msg = `${tool} was successfully installed`
if (installationInfo === undefined) {
return msg
}
if ("installDir" in installationInfo) { if ("installDir" in installationInfo) {
msg += `\nThe installation directory is ${installationInfo.installDir}` msg += `\nThe installation directory is ${installationInfo.installDir}`
} }

View File

@ -8,3 +8,7 @@ export function error(err: string | Error) {
export function success(msg: string) { export function success(msg: string) {
return isGitHubCI() ? core.info(msg) : console.log(`\x1b[32m${msg}\x1b[0m`) return isGitHubCI() ? core.info(msg) : console.log(`\x1b[32m${msg}\x1b[0m`)
} }
export function warning(msg: string) {
return isGitHubCI() ? core.warning(msg) : console.log(`\x1b[33m${msg}\x1b[0m`)
}