diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -335,6 +335,7 @@ 'PhutilUtilsTestCase' => 'utils/__tests__/PhutilUtilsTestCase.php', 'PhutilWordPressAuthAdapter' => 'auth/PhutilWordPressAuthAdapter.php', 'PhutilWordPressFuture' => 'future/wordpress/PhutilWordPressFuture.php', + 'PhutilXHPASTBinary' => 'parser/xhpast/bin/PhutilXHPASTBinary.php', 'PhutilXHPASTSyntaxHighlighter' => 'markup/syntax/highlighter/PhutilXHPASTSyntaxHighlighter.php', 'PhutilXHPASTSyntaxHighlighterFuture' => 'markup/syntax/highlighter/xhpast/PhutilXHPASTSyntaxHighlighterFuture.php', 'PhutilXHPASTSyntaxHighlighterTestCase' => 'markup/syntax/highlighter/__tests__/PhutilXHPASTSyntaxHighlighterTestCase.php', diff --git a/src/parser/xhpast/bin/PhutilXHPASTBinary.php b/src/parser/xhpast/bin/PhutilXHPASTBinary.php new file mode 100644 --- /dev/null +++ b/src/parser/xhpast/bin/PhutilXHPASTBinary.php @@ -0,0 +1,123 @@ +write($data); + + return $future; + } + + /** + * Returns the path to the XHPAST binary. + * + * @return string + */ + public static function getPath() { + if (phutil_is_windows()) { + return dirname(__FILE__).'\\xhpast.exe'; + } + return dirname(__FILE__).'/xhpast'; + } + + /** + * Returns the XHPAST version. + * + * @return string + */ + public static function getVersion() { + if (self::$version === null) { + $bin = self::getPath(); + + if (Filesystem::pathExists($bin)) { + list($err, $stdout) = exec_manual('%s --version', $bin); + if (!$err) { + self::$version = trim($stdout); + } + } + } + + return self::$version; + } + + /** + * Checks if XHPAST is built and up-to-date. + * + * @return bool + */ + public static function isAvailable() { + return self::getVersion() == self::VERSION; + } + +} diff --git a/src/parser/xhpast/bin/xhpast_parse.php b/src/parser/xhpast/bin/xhpast_parse.php --- a/src/parser/xhpast/bin/xhpast_parse.php +++ b/src/parser/xhpast/bin/xhpast_parse.php @@ -1,101 +1,25 @@ write($data); - - return $future; + return PhutilXHPASTBinary::getParserFuture($data); } -/** - * Checks if XHPAST is built and up-to-date. - * - * @return bool - */ function xhpast_is_available() { - static $available; - - if ($available === null) { - $available = xhpast_version() == 'xhpast version 5.5.8/1g'; - } - - return $available; + return PhutilXHPASTBinary::isAvailable(); } -/** - * Returns the XHPAST version. - * - * @return string - */ function xhpast_version() { - static $version; - - if ($version === null) { - $bin = xhpast_get_binary_path(); - if (Filesystem::pathExists($bin)) { - list($err, $stdout) = exec_manual('%s --version', $bin); - if (!$err) { - $version = trim($stdout); - } - } - } - - return $version; + return PhutilXHPASTBinary::getVersion(); }