Skip to content

Commit 1d1491e

Browse files
authored
Changes to make runner work with VS code tooling on macOS (#13)
1 parent 04a8147 commit 1d1491e

10 files changed

+236
-4
lines changed

.bazelrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Build options
2+
build --enable_platform_specific_config
3+
build --cxxopt=-std=c++17
4+
5+
# Platform-specific settings
6+
build:linux --copt=-static
7+
build:linux --copt=-static-libgcc
8+
build:linux --copt=-static-libstdc++
9+
10+
# Windows specific settings
11+
build:windows --copt=/MT
12+
13+
# Testing options
14+
test --test_output=errors
15+
16+
# Release build settings
17+
build:release -c opt
18+
build:release --strip=always

.bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.0.0

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
build
35+
bazel-*

BUILD.bazel

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cc_binary(
2+
name = "run-cppcheck",
3+
srcs = [
4+
"main.cpp",
5+
"config.cpp",
6+
"config.h",
7+
"picojson.h",
8+
],
9+
copts = [
10+
"-std=c++17",
11+
],
12+
visibility = ["//visibility:public"],
13+
)
14+

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 17)
66

77
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
88

9-
if (UNIX)
9+
if (UNIX AND NOT APPLE)
1010
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libgcc -static-libstdc++")
1111
endif ()
1212

MODULE.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module(
2+
name = "run_cppcheck",
3+
version = "1.0.1",
4+
)
5+
6+
bazel_dep(name = "platforms", version = "0.0.8")

MODULE.bazel.lock

+160
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ A wrapper for cppcheck to simplify cppcheck integration. This program exists to
44
to configure how to run cppcheck on a single file, that can be shared between editor plugins.
55
The log file also provides additional information that plugins may be lacking.
66

7+
## Building
8+
9+
### CMake
10+
```console
11+
mkdir build && cd build
12+
cmake ..
13+
make
14+
```
15+
16+
### Bazel
17+
```console
18+
bazel build //:run-cppcheck
19+
```
20+
21+
The compiled binary will be located at `bazel-bin/run-cppcheck`.
22+
723
## Invocation
824

925
```console

WORKSPACE.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workspace(name = "run_cppcheck")

config.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,18 @@ std::string Config::command() const
9595

9696
cmd += "\"" + m_cppcheck + "\"";
9797

98-
for (const auto &arg : m_args)
99-
cmd += " \"" + arg + "\"";
98+
for (const auto &arg : m_args) {
99+
// If arg contains double quotes, escape them
100+
std::string escapedArg = arg;
101+
size_t pos = 0;
102+
while ((pos = escapedArg.find("\"", pos)) != std::string::npos) {
103+
escapedArg.replace(pos, 1, "\\\"");
104+
pos += 2;
105+
}
106+
cmd += " \"" + escapedArg + "\"";
107+
108+
}
109+
100110

101111
if (!m_projectFilePath.empty()) {
102112
cmd += " \"--project=" + m_projectFilePath.string() + "\" \"--file-filter=" + m_filename.string() + "\"";
@@ -166,7 +176,6 @@ std::string Config::matchFilenameFromCompileCommand()
166176
// TODO should we warn if the file is not found?
167177
std::error_code err;
168178
if (std::filesystem::equivalent(file, m_filename, err)) {
169-
m_filename = file;
170179
return "";
171180
}
172181
}
@@ -191,6 +200,10 @@ std::string Config::parseArgs(int argc, char **argv)
191200
continue;
192201
}
193202

203+
if ((value = startsWith(arg, "--language="))) {
204+
continue;
205+
}
206+
194207
if (arg[0] == '-') {
195208
m_args.push_back(arg);
196209
continue;

0 commit comments

Comments
 (0)