File tree Expand file tree Collapse file tree 4 files changed +42
-12
lines changed Expand file tree Collapse file tree 4 files changed +42
-12
lines changed Original file line number Diff line number Diff line change 11# run-cppcheck
2- cppcheck wrapper to simplify cppcheck integration
2+
3+ A wrapper for cppcheck to simplify cppcheck integration. This program exists to provide a way
4+ to configure how to run cppcheck on a single file, that can be shared between editor plugins.
5+ The log file also provides additional information that plugins may be lacking.
6+
7+ ## Invocation
8+
9+ ``` console
10+ run-cppcheck <file>
11+ ```
12+
13+ ## Configuration options
14+ The configuration file is written in json, as ** run-cppcheck-config.json** . It is searched for recursively in parent directories of the analyzed file.
15+
16+ - ** project_file** : a path to a project file accepted by the cppcheck option ** --project=...** . If the path is relative,
17+ it's interpreted as relative to the configuration file.
18+ - ** cppcheck** : cppcheck command.
19+ - ** log_file** : Path to log file. The default log file location is ` $XDG_STATE_HOME/run-cppcheck ` or ` $HOME/.local/state/run-cppcheck ` on Linux,
20+ and ` %LOCALAPPDATA%\run-cppcheck ` on Windows. The log file may provide more information than the editor plugin if analysis fails.
21+ - ** enable_logging** : Default is ` true ` .
22+ - ** args** : Extra arguments to pass to cppcheck. Example: ` ["--enable=style"] ` .
Original file line number Diff line number Diff line change @@ -138,14 +138,12 @@ std::string Config::parseArgs(int argc, char **argv)
138138
139139 ++argv;
140140
141- std::filesystem::path configPath = " " ;
142-
143141 for (; *argv; ++argv) {
144142 const char *arg = *argv;
145143 const char *value;
146144
147145 if ((value = startsWith (arg, " --config=" ))) {
148- configPath = value;
146+ m_configPath = value;
149147 continue ;
150148 }
151149
@@ -166,16 +164,20 @@ std::string Config::parseArgs(int argc, char **argv)
166164 if (!error.empty ())
167165 return error;
168166 }
169- if (configPath .empty ())
170- configPath = findConfig (m_filename);
167+ if (m_configPath .empty ())
168+ m_configPath = findConfig (m_filename);
171169
172- if (configPath .empty ())
170+ if (m_configPath .empty ())
173171 return " Failed to find config file" ;
174172
175- const std::string err = load (configPath);
176- if (err.empty ())
177- return " " ;
178- return " Failed to load '" + configPath.string () + " ': " + err;
173+ const std::string err = load (m_configPath);
174+ if (!err.empty ())
175+ return " Failed to load '" + m_configPath.string () + " ': " + err;
176+
177+ if (!m_projectFilePath.empty () && m_projectFilePath.is_relative ())
178+ m_projectFilePath = m_configPath.parent_path () / m_projectFilePath;
179+
180+ return " " ;
179181}
180182
181183// Find config file by recursively searching parent directories of input file
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class Config {
1010 Config ()
1111 : m_projectFilePath(" " )
1212 , m_logFilePath(" " )
13+ , m_configPath(" " )
1314 , m_loggingEnabled(true )
1415 , m_cppcheck(" cppcheck" )
1516 , m_filename(" " )
@@ -35,12 +36,18 @@ class Config {
3536 return m_logFilePath;
3637 }
3738
39+ const std::filesystem::path configPath () const
40+ {
41+ return m_configPath;
42+ }
43+
3844private:
3945 static std::filesystem::path findConfig (const std::filesystem::path &input_path);
4046 static std::string getDefaultLogFilePath (std::filesystem::path &path);
4147
4248 std::filesystem::path m_projectFilePath;
4349 std::filesystem::path m_logFilePath;
50+ std::filesystem::path m_configPath;
4451 bool m_loggingEnabled;
4552 std::string m_cppcheck;
4653 std::filesystem::path m_filename;
Original file line number Diff line number Diff line change @@ -76,7 +76,8 @@ int main(int argc, char** argv) {
7676
7777 const std::string cmd = config.command ();
7878
79- logfile << " CMD: " << cmd << std::endl;
79+ logfile << " config path: " << config.configPath () << std::endl;
80+ logfile << " command: " << cmd << std::endl;
8081
8182 std::string output;
8283 int res = executeCommand (cmd, output);
You can’t perform that action at this time.
0 commit comments