1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-26 08:42:40 +01:00

Cache stopped paths in lint

Summary:
If linter with file cache granularity stops linting then we don't run it on the same path next time.
But we still run linters with non-file cache granularity causing that they run even on the paths that would be stopped otherwise.

Test Plan:
Put global granularity linter after Generated linter.
Caused an error from this linter but in ignored path.
Verified that 'stopped' is saved in `lint-cache.json`.
Linted the same files second time, verified that the path is still skipped (wasn't before).

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4446
This commit is contained in:
vrana 2013-01-15 13:47:11 -08:00
parent d4359a838a
commit f25c01606b
2 changed files with 27 additions and 9 deletions

View file

@ -53,6 +53,7 @@ abstract class ArcanistLintEngine {
private $cachedResults; private $cachedResults;
private $cacheVersion; private $cacheVersion;
private $results = array(); private $results = array();
private $stopped = array();
private $minimumSeverity = ArcanistLintSeverity::SEVERITY_DISABLED; private $minimumSeverity = ArcanistLintSeverity::SEVERITY_DISABLED;
private $changedLines = array(); private $changedLines = array();
@ -188,9 +189,12 @@ abstract class ArcanistLintEngine {
} }
$this->cacheVersion = crc32(implode("\n", $versions)); $this->cacheVersion = crc32(implode("\n", $versions));
$stopped = array(); $this->stopped = array();
$exceptions = array(); $exceptions = array();
foreach ($linters as $linter_name => $linter) { foreach ($linters as $linter_name => $linter) {
if (!is_string($linter_name)) {
$linter_name = get_class($linter);
}
try { try {
$linter->setEngine($this); $linter->setEngine($this);
if (!$linter->canRun()) { if (!$linter->canRun()) {
@ -204,12 +208,19 @@ abstract class ArcanistLintEngine {
// Make sure each path has a result generated, even if it is empty // Make sure each path has a result generated, even if it is empty
// (i.e., the file has no lint messages). // (i.e., the file has no lint messages).
$result = $this->getResultForPath($path); $result = $this->getResultForPath($path);
if (isset($stopped[$path])) { if (isset($this->stopped[$path])) {
unset($paths[$key]); unset($paths[$key]);
} }
if (isset($this->cachedResults[$path][$this->cacheVersion])) { if (isset($this->cachedResults[$path][$this->cacheVersion])) {
if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) { if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
unset($paths[$key]); unset($paths[$key]);
$cached_stopped = idx(
$this->cachedResults[$path][$this->cacheVersion],
'stopped');
if ($cached_stopped == $linter_name) {
$this->stopped[$path] = $linter_name;
}
} }
} }
} }
@ -221,15 +232,12 @@ abstract class ArcanistLintEngine {
$linter->willLintPath($path); $linter->willLintPath($path);
$linter->lintPath($path); $linter->lintPath($path);
if ($linter->didStopAllLinters()) { if ($linter->didStopAllLinters()) {
$stopped[$path] = true; $this->stopped[$path] = $linter_name;
} }
} }
} }
} catch (Exception $ex) { } catch (Exception $ex) {
if (!is_string($linter_name)) {
$linter_name = get_class($linter);
}
$exceptions[$linter_name] = $ex; $exceptions[$linter_name] = $ex;
} }
} }
@ -255,7 +263,9 @@ abstract class ArcanistLintEngine {
if ($this->cachedResults) { if ($this->cachedResults) {
foreach ($this->cachedResults as $path => $messages) { foreach ($this->cachedResults as $path => $messages) {
foreach (idx($messages, $this->cacheVersion, array()) as $message) { $messages = idx($messages, $this->cacheVersion, array());
unset($messages['stopped']);
foreach ($messages as $message) {
$this->getResultForPath($path)->addMessage( $this->getResultForPath($path)->addMessage(
ArcanistLintMessage::newFromDictionary($message)); ArcanistLintMessage::newFromDictionary($message));
} }
@ -291,7 +301,7 @@ abstract class ArcanistLintEngine {
} }
/** /**
* @param dict<string path, dict<int version, list<dict message>>> * @param dict<string path, dict<string version, list<dict message>>>
* @return this * @return this
*/ */
public function setCachedResults(array $results) { public function setCachedResults(array $results) {
@ -303,6 +313,10 @@ abstract class ArcanistLintEngine {
return $this->results; return $this->results;
} }
public function getStoppedPaths() {
return $this->stopped;
}
abstract protected function buildLinters(); abstract protected function buildLinters();
protected function didRunLinters(array $linters) { protected function didRunLinters(array $linters) {
@ -401,7 +415,7 @@ abstract class ArcanistLintEngine {
} }
protected function getCacheVersion() { protected function getCacheVersion() {
return 0; return 1;
} }
protected function getPEP8WithTextOptions() { protected function getPEP8WithTextOptions() {

View file

@ -504,6 +504,7 @@ EOTEXT
$cache = $this->readScratchJSONFile('lint-cache.json'); $cache = $this->readScratchJSONFile('lint-cache.json');
$cached = idx($cache, $this->getCacheKey(), array()); $cached = idx($cache, $this->getCacheKey(), array());
if ($cached || $use_cache) { if ($cached || $use_cache) {
$stopped = $engine->getStoppedPaths();
foreach ($results as $result) { foreach ($results as $result) {
$path = $result->getPath(); $path = $result->getPath();
if (!$use_cache) { if (!$use_cache) {
@ -517,6 +518,9 @@ EOTEXT
$hash = md5_file($abs_path); $hash = md5_file($abs_path);
$version = $result->getCacheVersion(); $version = $result->getCacheVersion();
$cached[$path] = array($hash => array($version => array())); $cached[$path] = array($hash => array($version => array()));
if (isset($stopped[$path])) {
$cached[$path][$hash][$version]['stopped'] = $stopped[$path];
}
foreach ($result->getMessages() as $message) { foreach ($result->getMessages() as $message) {
if ($message->isUncacheable()) { if ($message->isUncacheable()) {
continue; continue;