]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/arcanist_util/cpp_linter/FbcodeCppLinter.php
2 // Copyright 2004-present Facebook. All rights reserved.
4 class FbcodeCppLinter
extends ArcanistLinter
{
5 const FLINT
= "/home/engshare/tools/flint";
7 const LINT_WARNING
= 2;
9 const C_FLAG
= "--c_mode=true";
11 private $rawLintOutput = array();
13 public function willLintPaths(array $paths) {
14 if (!file_exists(self
::FLINT
)) {
18 foreach ($paths as $p) {
19 $lpath = $this->getEngine()->getFilePathOnDisk($p);
20 $lpath_file = file($lpath);
21 if (preg_match('/\.(c)$/', $lpath) ||
22 preg_match('/-\*-.*Mode: C[; ].*-\*-/', $lpath_file[0]) ||
23 preg_match('/vim(:.*)*:\s*(set\s+)?filetype=c\s*:/', $lpath_file[0])
25 $futures[$p] = new ExecFuture("%s %s %s 2>&1",
26 self
::FLINT
, self
::C_FLAG
,
27 $this->getEngine()->getFilePathOnDisk($p));
29 $futures[$p] = new ExecFuture("%s %s 2>&1",
30 self
::FLINT
, $this->getEngine()->getFilePathOnDisk($p));
34 foreach (Futures($futures)->limit(8) as $p => $f) {
35 $this->rawLintOutput
[$p] = $f->resolvex();
41 public function getLinterName() {
45 public function lintPath($path) {
46 $this->runCppLint($path);
49 private function runCppLint($path) {
50 $msgs = $this->getCppLintOutput($path);
51 foreach ($msgs as $m) {
52 $this->raiseLintAtLine($m['line'], 0, $m['severity'], $m['msg']);
56 private function adviseOnEachPattern(
60 $lint_type = self
::LINT_ADVICE
,
62 $file_data = $this->getData($path);
64 if (!preg_match_all($regex, $file_data, $matches, PREG_OFFSET_CAPTURE
)) {
68 foreach ($matches[$match_idx] as $match) {
69 list($match_str, $offset) = $match;
70 $this->raiseLintAtOffset($offset, $lint_type, $message, $match_str);
74 public function getLintSeverityMap() {
76 self
::LINT_WARNING
=> ArcanistLintSeverity
::SEVERITY_WARNING
,
77 self
::LINT_ADVICE
=> ArcanistLintSeverity
::SEVERITY_ADVICE
,
78 self
::LINT_ERROR
=> ArcanistLintSeverity
::SEVERITY_ERROR
82 public function getLintNameMap() {
84 self
::LINT_ADVICE
=> "CppLint Advice",
85 self
::LINT_WARNING
=> "CppLint Warning",
86 self
::LINT_ERROR
=> "CppLint Error"
90 private function getCppLintOutput($path) {
91 if (!array_key_exists($path, $this->rawLintOutput
)) {
94 list($output) = $this->rawLintOutput
[$path];
99 foreach (explode("\n", $output) as $line) {
100 if (preg_match('/.*?:(\d+):(.*)/', $line, $matches)) {
106 if (preg_match('/.*Warning.*/', $text)) {
107 $sev = self
::LINT_WARNING
;
108 } else if (preg_match('/.*Advice.*/', $text)) {
109 $sev = self
::LINT_ADVICE
;
111 $sev = self
::LINT_ERROR
;
113 $current = array('line' => $line,
116 } else if ($current) {
117 $current['msg'] .= ' ' . $line;