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 1
1
# 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)
138
138
139
139
++argv;
140
140
141
- std::filesystem::path configPath = " " ;
142
-
143
141
for (; *argv; ++argv) {
144
142
const char *arg = *argv;
145
143
const char *value;
146
144
147
145
if ((value = startsWith (arg, " --config=" ))) {
148
- configPath = value;
146
+ m_configPath = value;
149
147
continue ;
150
148
}
151
149
@@ -166,16 +164,20 @@ std::string Config::parseArgs(int argc, char **argv)
166
164
if (!error.empty ())
167
165
return error;
168
166
}
169
- if (configPath .empty ())
170
- configPath = findConfig (m_filename);
167
+ if (m_configPath .empty ())
168
+ m_configPath = findConfig (m_filename);
171
169
172
- if (configPath .empty ())
170
+ if (m_configPath .empty ())
173
171
return " Failed to find config file" ;
174
172
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 " " ;
179
181
}
180
182
181
183
// 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 {
10
10
Config ()
11
11
: m_projectFilePath(" " )
12
12
, m_logFilePath(" " )
13
+ , m_configPath(" " )
13
14
, m_loggingEnabled(true )
14
15
, m_cppcheck(" cppcheck" )
15
16
, m_filename(" " )
@@ -35,12 +36,18 @@ class Config {
35
36
return m_logFilePath;
36
37
}
37
38
39
+ const std::filesystem::path configPath () const
40
+ {
41
+ return m_configPath;
42
+ }
43
+
38
44
private:
39
45
static std::filesystem::path findConfig (const std::filesystem::path &input_path);
40
46
static std::string getDefaultLogFilePath (std::filesystem::path &path);
41
47
42
48
std::filesystem::path m_projectFilePath;
43
49
std::filesystem::path m_logFilePath;
50
+ std::filesystem::path m_configPath;
44
51
bool m_loggingEnabled;
45
52
std::string m_cppcheck;
46
53
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) {
76
76
77
77
const std::string cmd = config.command ();
78
78
79
- logfile << " CMD: " << cmd << std::endl;
79
+ logfile << " config path: " << config.configPath () << std::endl;
80
+ logfile << " command: " << cmd << std::endl;
80
81
81
82
std::string output;
82
83
int res = executeCommand (cmd, output);
You can’t perform that action at this time.
0 commit comments