1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 14:52:40 +01:00

Add some version/env sanity checks to 'arc'

Summary:
A user filed an issue on GitHub about not having 'json_decode()':

  https://github.com/facebook/arcanist/issues/10

Detect this issue and raise a detailed error message.

Test Plan:
  - Set minimum version to 6.0.0, arc told me to upgrade.
  - Changed function/flag configuration and hit the flag and no-flag error
pathways.

Reviewers: btrahan, jungejason, rm

Reviewed By: rm

CC: aran, rm, epriestley

Differential Revision: https://secure.phabricator.com/D1267
This commit is contained in:
epriestley 2011-12-22 10:23:29 -08:00
parent 736b0deaac
commit ecc8fb13a8

View file

@ -17,6 +17,8 @@
* limitations under the License. * limitations under the License.
*/ */
sanity_check_environment();
require_once dirname(__FILE__).'/__init_script__.php'; require_once dirname(__FILE__).'/__init_script__.php';
phutil_require_module('phutil', 'conduit/client'); phutil_require_module('phutil', 'conduit/client');
@ -287,3 +289,73 @@ try {
exit(1); exit(1);
} }
/**
* Perform some sanity checks against the possible diversity of PHP builds in
* the wild, like very old versions and builds that were compiled with flags
* that exclude core functionality.
*/
function sanity_check_environment() {
$min_version = '5.2.0';
$cur_version = phpversion();
if (version_compare($cur_version, $min_version, '<')) {
die_with_bad_php(
"You are running PHP version '{$cur_version}', which is older than ".
"the minimum version, '{$min_version}'. Update to at least ".
"'{$min_version}'.");
}
$need_functions = array(
'json_decode' => '--without-json',
);
$problems = array();
$config = null;
$show_config = false;
foreach ($need_functions as $fname => $flag) {
if (function_exists($fname)) {
continue;
}
static $info;
if ($info === null) {
ob_start();
phpinfo(INFO_GENERAL);
$info = ob_get_clean();
$matches = null;
if (preg_match('/^Configure Command =>\s*(.*?)$/m', $info, $matches)) {
$config = $matches[1];
}
}
if (strpos($config, $flag) !== false) {
$show_config = true;
$problems[] =
"This build of PHP was compiled with the configure flag '{$flag}', ".
"which means it does not have the function '{$fname}()'. This ".
"function is required for arc to run. Rebuild PHP without this flag. ".
"You may also be able to build or install the relevant extension ".
"separately.";
} else {
$problems[] =
"This build of PHP is missing the required function '{$fname}()'. ".
"Rebuild PHP or install the extension which provides '{$fname}()'.";
}
}
if ($problems) {
if ($show_config) {
$problems[] = "PHP was built with this configure command:\n\n{$config}";
}
die_with_bad_php(implode("\n\n", $problems));
}
}
function die_with_bad_php($message) {
echo "\nPHP CONFIGURATION ERRORS\n\n";
echo $message;
echo "\n\n";
exit(1);
}