Skip to content

Commit

Permalink
fix: print a warning if no tool was installed
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 29, 2022
1 parent 5add80e commit 1077091
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The package can be used locally or from CI services like GitHub Actions.

# 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.

Expand Down Expand Up @@ -105,7 +105,7 @@ sudo node ./setup_cpp.js --compiler llvm --cmake true --ninja true --ccache true
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.

Expand Down Expand Up @@ -157,14 +157,16 @@ jobs:
uses: aminya/setup-cpp@v1
with:
compiler: ${{ matrix.compiler }}
vcvarsall: ${{ contains(matrix.os, 'windows') }}
cmake: true
ninja: true
vcpkg: true
cppcheck: true # instead of `true`, which chooses the default version, you can pass a specific version.
# add any tool that you need here...
cppcheck: true
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.

Expand Down Expand Up @@ -196,15 +198,15 @@ If you want to build the ones included, then run:
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

```ps1
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:

Expand All @@ -226,7 +228,7 @@ jobs:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
```
# GitLab PipeLines
## Inside GitLab pipelines
The following gives an example for setting up a C++ environment inside GitLab pipelines.
Expand Down Expand Up @@ -289,6 +291,7 @@ test_linux_gcc:

# Usage Examples

- [cpp-best-practices starter project](https://github.com/cpp-best-practices/cpp_starter_project)
- [libclang](https://github.com/atilaneves/libclang)
- [dpp](https://github.com/atilaneves/dpp)
- [d-tree-sitter](https://github.com/aminya/d-tree-sitter)
Expand Down
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

36 changes: 26 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import semverValid from "semver/functions/valid"
import { getVersion } from "./default_versions"
import { setupGcc } from "./gcc/gcc"
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 { join } from "path"
import { setupVCVarsall } from "./vcvarsall/vcvarsall"
Expand Down Expand Up @@ -134,11 +134,7 @@ export async function main(args: string[]): Promise<number> {
installationInfo = await setupFunction(getVersion(tool, value), join(setupCppDir, tool), arch)
}
// preparing a report string
if (installationInfo !== undefined) {
successMessages.push(getSuccessMessage(tool, installationInfo))
} else {
successMessages.push(`${tool} was successfully installed`)
}
successMessages.push(getSuccessMessage(tool, installationInfo))
} catch (e) {
// push error message to the logger
error(e as string | Error)
Expand All @@ -158,14 +154,20 @@ export async function main(args: string[]): Promise<number> {
case "llvm":
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
}
case "gcc":
case "mingw":
case "cygwin":
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
}
case "cl":
Expand All @@ -175,14 +177,20 @@ export async function main(args: string[]): Promise<number> {
case "visualstudio":
case "visualcpp":
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
}
case "appleclang":
case "applellvm": {
core.info("Assuming apple-clang is already installed")
addEnv("CC", "clang")
addEnv("CXX", "clang++")
successMessages.push(getSuccessMessage("apple-clang", undefined))
break
}
default: {
Expand All @@ -195,6 +203,11 @@ export async function main(args: string[]): Promise<number> {
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
successMessages.forEach((tool) => success(tool))
errorMessages.forEach((tool) => error(tool))
Expand Down Expand Up @@ -292,8 +305,11 @@ function maybeGetInput(key: string) {
return undefined // skip installation
}

function getSuccessMessage(tool: string, installationInfo: InstallationInfo) {
function getSuccessMessage(tool: string, installationInfo: InstallationInfo | undefined | void) {
let msg = `${tool} was successfully installed`
if (installationInfo === undefined) {
return msg
}
if ("installDir" in installationInfo) {
msg += `\nThe installation directory is ${installationInfo.installDir}`
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/io/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export function error(err: string | Error) {
export function success(msg: string) {
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`)
}

0 comments on commit 1077091

Please sign in to comment.