Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15381721
D14298.id34513.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D14298.id34513.diff
View Options
diff --git a/src/lint/linter/ArcanistExternalLinter.php b/src/lint/linter/ArcanistExternalLinter.php
--- a/src/lint/linter/ArcanistExternalLinter.php
+++ b/src/lint/linter/ArcanistExternalLinter.php
@@ -13,6 +13,7 @@
private $bin;
private $interpreter;
private $flags;
+ private $versionRequirement;
/* -( Interpreters, Binaries and Flags )----------------------------------- */
@@ -103,6 +104,18 @@
}
/**
+ * Set the binary's version requirement.
+ *
+ * @param string Version requirement.
+ * @return this
+ * @task bin
+ */
+ final public function setVersionRequirement($version) {
+ $this->versionRequirement = trim($version);
+ return $this;
+ }
+
+ /**
* Return the binary or script to execute. This method synthesizes defaults
* and configuration. You can override the binary with @{method:setBinary}.
*
@@ -259,6 +272,59 @@
}
/**
+ * If a binary version requirement has been specified, compare the version
+ * of the configured binary to the required version, and if the binary's
+ * version is not supported, throw an exception.
+ *
+ * @param string Version string to check.
+ * @return void
+ */
+ final protected function checkBinaryVersion($version) {
+ if (!$this->versionRequirement) {
+ return;
+ }
+
+ if (!$version) {
+ throw new ArcanistMissingLinterException(
+ sprintf(
+ "%s\n%s",
+ pht(
+ 'Linter %s requires %s version %s. Unable to determine the '.
+ 'version that you have installed.',
+ get_class($this),
+ $this->getBinary(),
+ $this->versionRequirement),
+ pht(
+ 'TO INSTALL: %s',
+ $this->getInstallInstructions())));
+ }
+
+ $operator = '==';
+ $compare_to = $this->versionRequirement;
+
+ $matches = null;
+ if (preg_match('/^([<>]=?|==)\s*(.*)$/', $compare_to, $matches)) {
+ $operator = $matches[1];
+ $compare_to = $matches[2];
+ }
+
+ if (!version_compare($version, $compare_to, $operator)) {
+ throw new ArcanistMissingLinterException(
+ sprintf(
+ "%s\n%s",
+ pht(
+ 'Linter %s requires %s version %s. You have version %s.',
+ get_class($this),
+ $this->getBinary(),
+ $this->versionRequirement,
+ $version),
+ pht(
+ 'TO INSTALL: %s',
+ $this->getInstallInstructions())));
+ }
+ }
+
+ /**
* Get the composed executable command, including the interpreter and binary
* but without flags or paths. This can be used to execute `--version`
* commands.
@@ -308,6 +374,7 @@
$version = $this->getVersion();
if ($version) {
+ $this->checkBinaryVersion($version);
return $version.'-'.json_encode($this->getCommandFlags());
} else {
// Either we failed to parse the version number or the `getVersion`
@@ -395,6 +462,13 @@
'Provide a list of additional flags to pass to the linter on the '.
'command line.'),
),
+ 'version' => array(
+ 'type' => 'optional string',
+ 'help' => pht(
+ 'Specify a version requirement for the binary. The version number '.
+ 'may be prefixed with <, <=, >, >=, or == to specify the version '.
+ 'comparison operator (default: ==).'),
+ ),
);
if ($this->shouldUseInterpreter()) {
@@ -456,6 +530,9 @@
case 'flags':
$this->setFlags($value);
return;
+ case 'version':
+ $this->setVersionRequirement($value);
+ return;
}
return parent::setLinterConfigurationValue($key, $value);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 15, 9:04 AM (3 d, 22 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7688368
Default Alt Text
D14298.id34513.diff (3 KB)
Attached To
Mode
D14298: External linters can now specify a version requirement.
Attached
Detach File
Event Timeline
Log In to Comment