]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/arcanist_util/cpp_linter/ArcanistCpplintLinter.php
4 * Uses google's cpplint.py to check code. RocksDB team forked this file from
5 * phabricator's /src/lint/linter/ArcanistCpplintLinter.php, and customized it
9 * http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py
12 final class ArcanistCpplintLinter
extends ArcanistLinter
{
14 public function willLintPaths(array $paths) {
18 public function getLinterName() {
22 public function getLintPath() {
24 // Search under current dir
25 list($err) = exec_manual('which %s/%s', $this->linterDir(), $bin);
27 return $this->linterDir().'/'.$bin;
30 // Look for globally installed cpplint.py
31 list($err) = exec_manual('which %s', $bin);
33 throw new ArcanistUsageException(
34 "cpplint.py does not appear to be installed on this system. Install ".
35 "it (e.g., with 'wget \"http://google-styleguide.googlecode.com/".
36 "svn/trunk/cpplint/cpplint.py\"') ".
37 "in your .arcconfig to point to the directory where it resides. ".
38 "Also don't forget to chmod a+x cpplint.py!");
44 public function lintPath($path) {
45 $bin = $this->getLintPath();
46 $path = $this->rocksdbDir().'/'.$path;
48 $f = new ExecFuture("%C $path", $bin);
50 list($err, $stdout, $stderr) = $f->resolve();
53 throw new Exception("cpplint failed to run correctly:\n".$stderr);
56 $lines = explode("\n", $stderr);
58 foreach ($lines as $line) {
61 $regex = '/^[^:]+:(\d+):\s*(.*)\s*\[(.*)\] \[(\d+)\]$/';
62 if (!preg_match($regex, $line, $matches)) {
65 foreach ($matches as $key => $match) {
66 $matches[$key] = trim($match);
68 $message = new ArcanistLintMessage();
69 $message->setPath($path);
70 $message->setLine($matches[1]);
71 $message->setCode($matches[3]);
72 $message->setName($matches[3]);
73 $message->setDescription($matches[2]);
74 $message->setSeverity(ArcanistLintSeverity
::SEVERITY_WARNING
);
75 $this->addLintMessage($message);
79 // The path of this linter
80 private function linterDir() {
81 return dirname(__FILE__
);
84 // TODO(kaili) a quick and dirty way to figure out rocksdb's root dir.
85 private function rocksdbDir() {
86 return $this->linterDir()."/../..";