]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Cache stopped paths in lint
authorvrana <jakubv@fb.com>
Tue, 15 Jan 2013 21:47:11 +0000 (13:47 -0800)
committervrana <jakubv@fb.com>
Wed, 16 Jan 2013 01:58:32 +0000 (17:58 -0800)
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

src/lint/engine/ArcanistLintEngine.php
src/workflow/ArcanistLintWorkflow.php

index fd5816eba6227ddffbea7015d5ec6d4f289da12a..358ba281559e4bc93629a35190250d203d0c9733 100644 (file)
@@ -53,6 +53,7 @@ abstract class ArcanistLintEngine {
   private $cachedResults;
   private $cacheVersion;
   private $results = array();
+  private $stopped = array();
   private $minimumSeverity = ArcanistLintSeverity::SEVERITY_DISABLED;
 
   private $changedLines = array();
@@ -188,9 +189,12 @@ abstract class ArcanistLintEngine {
     }
     $this->cacheVersion = crc32(implode("\n", $versions));
 
-    $stopped = array();
+    $this->stopped = array();
     $exceptions = array();
     foreach ($linters as $linter_name => $linter) {
+      if (!is_string($linter_name)) {
+        $linter_name = get_class($linter);
+      }
       try {
         $linter->setEngine($this);
         if (!$linter->canRun()) {
@@ -204,12 +208,19 @@ abstract class ArcanistLintEngine {
           // 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($stopped[$path])) {
+          if (isset($this->stopped[$path])) {
             unset($paths[$key]);
           }
           if (isset($this->cachedResults[$path][$this->cacheVersion])) {
             if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
               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->lintPath($path);
             if ($linter->didStopAllLinters()) {
-              $stopped[$path] = true;
+              $this->stopped[$path] = $linter_name;
             }
           }
         }
 
       } catch (Exception $ex) {
-        if (!is_string($linter_name)) {
-          $linter_name = get_class($linter);
-        }
         $exceptions[$linter_name] = $ex;
       }
     }
@@ -255,7 +263,9 @@ abstract class ArcanistLintEngine {
 
     if ($this->cachedResults) {
       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(
             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
    */
   public function setCachedResults(array $results) {
@@ -303,6 +313,10 @@ abstract class ArcanistLintEngine {
     return $this->results;
   }
 
+  public function getStoppedPaths() {
+    return $this->stopped;
+  }
+
   abstract protected function buildLinters();
 
   protected function didRunLinters(array $linters) {
@@ -401,7 +415,7 @@ abstract class ArcanistLintEngine {
   }
 
   protected function getCacheVersion() {
-    return 0;
+    return 1;
   }
 
   protected function getPEP8WithTextOptions() {
index 22b2983134c3e1eee25ed422d48f713018679b33..faf32b61ede50ce2e1236cc9b308ad0a1733969a 100644 (file)
@@ -504,6 +504,7 @@ EOTEXT
     $cache = $this->readScratchJSONFile('lint-cache.json');
     $cached = idx($cache, $this->getCacheKey(), array());
     if ($cached || $use_cache) {
+      $stopped = $engine->getStoppedPaths();
       foreach ($results as $result) {
         $path = $result->getPath();
         if (!$use_cache) {
@@ -517,6 +518,9 @@ EOTEXT
         $hash = md5_file($abs_path);
         $version = $result->getCacheVersion();
         $cached[$path] = array($hash => array($version => array()));
+        if (isset($stopped[$path])) {
+          $cached[$path][$hash][$version]['stopped'] = $stopped[$path];
+        }
         foreach ($result->getMessages() as $message) {
           if ($message->isUncacheable()) {
             continue;