From 35de4a5d1f45e3d406ba7604385bdb5b96c8f272 Mon Sep 17 00:00:00 2001 From: vrana Date: Wed, 9 Jan 2013 13:00:45 -0800 Subject: [PATCH] Run all willLintPaths() before any lintPath() Summary: FB runs some linters on background and it's a magnificent hack using `ParallelLinter` (two instances), `BackgroundLinter` and `FutureLinter`. I want to simplify this by resolving the futures in engine instead of in some virtual linter. It also seems like a better place to do it. It should also fix caching problems I have with them (because the virtual linters don't know about the cache at all). Test Plan: None yet. Reviewers: epriestley, nh Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4380 --- src/lint/engine/ArcanistLintEngine.php | 65 ++++++++++++++------------ 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/lint/engine/ArcanistLintEngine.php b/src/lint/engine/ArcanistLintEngine.php index 8d4845f2..c46a8922 100644 --- a/src/lint/engine/ArcanistLintEngine.php +++ b/src/lint/engine/ArcanistLintEngine.php @@ -164,7 +164,6 @@ abstract class ArcanistLintEngine { } public function run() { - $stopped = array(); $linters = $this->buildLinters(); if (!$linters) { @@ -189,40 +188,46 @@ abstract class ArcanistLintEngine { } $this->cacheVersion = crc32(implode("\n", $versions)); + $linters_paths = array(); + foreach ($linters as $linter_name => $linter) { + $linter->setEngine($this); + if (!$linter->canRun()) { + continue; + } + $paths = $linter->getPaths(); + + $cache_granularity = $linter->getCacheGranularity(); + + foreach ($paths as $key => $path) { + // Make sure each path has a result generated, even if it is empty + // (i.e., the file has no lint messages). + $result = $this->getResultForPath($path); + if (isset($this->cachedResults[$path][$this->cacheVersion])) { + if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) { + unset($paths[$key]); + } + } + } + $paths = array_values($paths); + $linters_paths[$linter_name] = $paths; + + if ($paths) { + $linter->willLintPaths($paths); + } + } + + $stopped = array(); $exceptions = array(); foreach ($linters as $linter_name => $linter) { try { - $linter->setEngine($this); - if (!$linter->canRun()) { - continue; - } - $paths = $linter->getPaths(); - - $cache_granularity = $linter->getCacheGranularity(); - - foreach ($paths as $key => $path) { - // Make sure each path has a result generated, even if it is empty - // (i.e., the file has no lint messages). - $result = $this->getResultForPath($path); + foreach ($linters_paths[$linter_name] as $path) { if (isset($stopped[$path])) { - unset($paths[$key]); + continue; } - if (isset($this->cachedResults[$path][$this->cacheVersion])) { - if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) { - unset($paths[$key]); - } - } - } - $paths = array_values($paths); - - if ($paths) { - $linter->willLintPaths($paths); - foreach ($paths as $path) { - $linter->willLintPath($path); - $linter->lintPath($path); - if ($linter->didStopAllLinters()) { - $stopped[$path] = true; - } + $linter->willLintPath($path); + $linter->lintPath($path); + if ($linter->didStopAllLinters()) { + $stopped[$path] = true; } }