mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
Allow setting lint cache granularity
Summary: We can add `GRANULARITY_DIRECTORY` and `GRANULARITY_REPOSITORY` later. Repository granularity may use current commit + changes. Directory would need to use hashes of all files in dir which would be quite expensive. Test Plan: $ echo '<?php class A extends B {}' > A.php $ arc lint --cache 1 $ arc lint --cache 1 $ echo '<?php class B {}' > B.php $ arc lint --cache 1 $ arc lint --cache 1 $ rm B.php $ arc lint --cache 1 $ arc lint --cache 1 Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4021
This commit is contained in:
parent
0d1d04e434
commit
e8eacb6ae3
5 changed files with 46 additions and 4 deletions
|
@ -19,6 +19,7 @@ final class ArcanistLintMessage {
|
||||||
protected $appliedToDisk;
|
protected $appliedToDisk;
|
||||||
protected $dependentMessages = array();
|
protected $dependentMessages = array();
|
||||||
protected $obsolete;
|
protected $obsolete;
|
||||||
|
protected $uncacheable;
|
||||||
|
|
||||||
public static function newFromDictionary(array $dict) {
|
public static function newFromDictionary(array $dict) {
|
||||||
$message = new ArcanistLintMessage();
|
$message = new ArcanistLintMessage();
|
||||||
|
@ -179,6 +180,15 @@ final class ArcanistLintMessage {
|
||||||
return $this->appliedToDisk;
|
return $this->appliedToDisk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setUncacheable($bool) {
|
||||||
|
$this->uncacheable = $bool;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isUncacheable() {
|
||||||
|
return $this->uncacheable;
|
||||||
|
}
|
||||||
|
|
||||||
public function setDependentMessages(array $messages) {
|
public function setDependentMessages(array $messages) {
|
||||||
assert_instances_of($messages, 'ArcanistLintMessage');
|
assert_instances_of($messages, 'ArcanistLintMessage');
|
||||||
$this->dependentMessages = $messages;
|
$this->dependentMessages = $messages;
|
||||||
|
|
|
@ -198,6 +198,8 @@ abstract class ArcanistLintEngine {
|
||||||
}
|
}
|
||||||
$paths = $linter->getPaths();
|
$paths = $linter->getPaths();
|
||||||
|
|
||||||
|
$cache_granularity = $linter->getCacheGranularity();
|
||||||
|
|
||||||
foreach ($paths as $key => $path) {
|
foreach ($paths as $key => $path) {
|
||||||
// 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).
|
||||||
|
@ -205,11 +207,12 @@ abstract class ArcanistLintEngine {
|
||||||
if (isset($stopped[$path])) {
|
if (isset($stopped[$path])) {
|
||||||
unset($paths[$key]);
|
unset($paths[$key]);
|
||||||
}
|
}
|
||||||
// TODO: Some linters work with the whole directory.
|
|
||||||
if (isset($this->cachedResults[$path][$this->cacheVersion])) {
|
if (isset($this->cachedResults[$path][$this->cacheVersion])) {
|
||||||
|
if ($cache_granularity == ArcanistLinter::GRANULARITY_FILE) {
|
||||||
unset($paths[$key]);
|
unset($paths[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$paths = array_values($paths);
|
$paths = array_values($paths);
|
||||||
|
|
||||||
if ($paths) {
|
if ($paths) {
|
||||||
|
@ -231,6 +234,9 @@ abstract class ArcanistLintEngine {
|
||||||
if (!$this->isRelevantMessage($message)) {
|
if (!$this->isRelevantMessage($message)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($cache_granularity != ArcanistLinter::GRANULARITY_FILE) {
|
||||||
|
$message->setUncacheable(true);
|
||||||
|
}
|
||||||
$result = $this->getResultForPath($message->getPath());
|
$result = $this->getResultForPath($message->getPath());
|
||||||
$result->addMessage($message);
|
$result->addMessage($message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,11 @@
|
||||||
*/
|
*/
|
||||||
abstract class ArcanistLinter {
|
abstract class ArcanistLinter {
|
||||||
|
|
||||||
|
const GRANULARITY_FILE = 1;
|
||||||
|
const GRANULARITY_DIRECTORY = 2;
|
||||||
|
const GRANULARITY_REPOSITORY = 3;
|
||||||
|
const GRANULARITY_GLOBAL = 4;
|
||||||
|
|
||||||
protected $paths = array();
|
protected $paths = array();
|
||||||
protected $data = array();
|
protected $data = array();
|
||||||
protected $engine;
|
protected $engine;
|
||||||
|
@ -211,4 +216,8 @@ abstract class ArcanistLinter {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCacheGranularity() {
|
||||||
|
return self::GRANULARITY_FILE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,4 +171,9 @@ final class ArcanistPhutilLibraryLinter extends ArcanistLinter {
|
||||||
public function lintPath($path) {
|
public function lintPath($path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCacheGranularity() {
|
||||||
|
return self::GRANULARITY_GLOBAL;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,9 +192,14 @@ EOTEXT
|
||||||
if ($this->getArgument('cache')) {
|
if ($this->getArgument('cache')) {
|
||||||
$cache = $this->readScratchJSONFile('lint-cache.json');
|
$cache = $this->readScratchJSONFile('lint-cache.json');
|
||||||
$cache = idx($cache, $this->getCacheKey(), array());
|
$cache = idx($cache, $this->getCacheKey(), array());
|
||||||
|
$cache = array_intersect_key($cache, array_flip($paths));
|
||||||
$cached = array();
|
$cached = array();
|
||||||
foreach ($cache as $path => $messages) {
|
foreach ($cache as $path => $messages) {
|
||||||
$messages = idx($messages, md5_file($engine->getFilePathOnDisk($path)));
|
$abs_path = $engine->getFilePathOnDisk($path);
|
||||||
|
if (!Filesystem::pathExists($abs_path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$messages = idx($messages, md5_file($abs_path));
|
||||||
if ($messages !== null) {
|
if ($messages !== null) {
|
||||||
$cached[$path] = $messages;
|
$cached[$path] = $messages;
|
||||||
}
|
}
|
||||||
|
@ -400,10 +405,17 @@ EOTEXT
|
||||||
unset($cached[$path]);
|
unset($cached[$path]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$hash = md5_file($engine->getFilePathOnDisk($path));
|
$abs_path = $engine->getFilePathOnDisk($path);
|
||||||
|
if (!Filesystem::pathExists($abs_path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$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()));
|
||||||
foreach ($result->getMessages() as $message) {
|
foreach ($result->getMessages() as $message) {
|
||||||
|
if ($message->isUncacheable()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!$message->isPatchApplied()) {
|
if (!$message->isPatchApplied()) {
|
||||||
$cached[$path][$hash][$version][] = $message->toDictionary();
|
$cached[$path][$hash][$version][] = $message->toDictionary();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue