Skip to content

Changes to make runner work with VS code tooling on macOS #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Build options
build --enable_platform_specific_config
build --cxxopt=-std=c++17

# Platform-specific settings
build:linux --copt=-static
build:linux --copt=-static-libgcc
build:linux --copt=-static-libstdc++

# Windows specific settings
build:windows --copt=/MT

# Testing options
test --test_output=errors

# Release build settings
build:release -c opt
build:release --strip=always
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.0.0
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
*.exe
*.out
*.app

build
bazel-*
14 changes: 14 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cc_binary(
name = "run-cppcheck",
srcs = [
"main.cpp",
"config.cpp",
"config.h",
"picojson.h",
],
copts = [
"-std=c++17",
],
visibility = ["//visibility:public"],
)

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 17)

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")

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

Expand Down
6 changes: 6 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module(
name = "run_cppcheck",
version = "1.0.1",
)

bazel_dep(name = "platforms", version = "0.0.8")
160 changes: 160 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ A wrapper for cppcheck to simplify cppcheck integration. This program exists to
to configure how to run cppcheck on a single file, that can be shared between editor plugins.
The log file also provides additional information that plugins may be lacking.

## Building

### CMake
```console
mkdir build && cd build
cmake ..
make
```

### Bazel
```console
bazel build //:run-cppcheck
```

The compiled binary will be located at `bazel-bin/run-cppcheck`.

## Invocation

```console
Expand Down
1 change: 1 addition & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "run_cppcheck")
19 changes: 16 additions & 3 deletions config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,18 @@ std::string Config::command() const

cmd += "\"" + m_cppcheck + "\"";

for (const auto &arg : m_args)
cmd += " \"" + arg + "\"";
for (const auto &arg : m_args) {
// If arg contains double quotes, escape them
std::string escapedArg = arg;
size_t pos = 0;
while ((pos = escapedArg.find("\"", pos)) != std::string::npos) {
escapedArg.replace(pos, 1, "\\\"");
pos += 2;
}
cmd += " \"" + escapedArg + "\"";

}


if (!m_projectFilePath.empty()) {
cmd += " \"--project=" + m_projectFilePath.string() + "\" \"--file-filter=" + m_filename.string() + "\"";
Expand Down Expand Up @@ -166,7 +176,6 @@ std::string Config::matchFilenameFromCompileCommand()
// TODO should we warn if the file is not found?
std::error_code err;
if (std::filesystem::equivalent(file, m_filename, err)) {
m_filename = file;
return "";
}
}
Expand All @@ -191,6 +200,10 @@ std::string Config::parseArgs(int argc, char **argv)
continue;
}

if ((value = startsWith(arg, "--language="))) {
continue;
}

if (arg[0] == '-') {
m_args.push_back(arg);
continue;
Expand Down