From 2f9a422bc6365be026e2cf1cdf7d34705fad4e28 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 5 Mar 2012 10:02:37 -0800 Subject: [PATCH] Improve arc compatibility on Windows Summary: - When altering the include_path(), use PATH_SEPARATOR (";" on Windows, ":" elsewhere) instead of hard-coded ":". - Detect missing php_curl.dll extension. - Use APPDATA instead of HOME for storing .arcrc (the internet implies this is correct?) - Don't try to do chmod() stuff on Windows; it's not critical and I don't want to figure out how it works. Test Plan: Was able to run part of some arc commands on Windows. Reviewers: btrahan, Makinde, Koolvin Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T124 Differential Revision: https://secure.phabricator.com/D1756 --- scripts/__init_script__.php | 7 +++- scripts/arcanist.php | 36 +++++++++++++---- scripts/phutil_analyzer.php | 2 +- src/workflow/alias/ArcanistAliasWorkflow.php | 9 ++++- src/workflow/amend/ArcanistAmendWorkflow.php | 8 +++- src/workflow/base/ArcanistBaseWorkflow.php | 40 +++++++++++++------ .../branch/ArcanistBranchWorkflow.php | 8 +++- .../ArcanistCallConduitWorkflow.php | 9 ++++- .../commit/ArcanistCommitWorkflow.php | 8 +++- src/workflow/cover/ArcanistCoverWorkflow.php | 8 +++- src/workflow/diff/ArcanistDiffWorkflow.php | 9 ++++- .../download/ArcanistDownloadWorkflow.php | 9 ++++- .../export/ArcanistExportWorkflow.php | 8 +++- .../ArcanistGitHookPreReceiveWorkflow.php | 8 +++- src/workflow/help/ArcanistHelpWorkflow.php | 36 +++++++++++++++-- .../ArcanistInstallCertificateWorkflow.php | 8 +++- src/workflow/land/ArcanistLandWorkflow.php | 9 ++++- .../liberate/ArcanistLiberateWorkflow.php | 8 +++- src/workflow/lint/ArcanistLintWorkflow.php | 8 +++- src/workflow/list/ArcanistListWorkflow.php | 8 +++- .../ArcanistMarkCommittedWorkflow.php | 8 +++- src/workflow/merge/ArcanistMergeWorkflow.php | 9 ++++- src/workflow/paste/ArcanistPasteWorkflow.php | 11 +++-- src/workflow/patch/ArcanistPatchWorkflow.php | 8 +++- .../ArcanistShellCompleteWorkflow.php | 8 +++- .../ArcanistSvnHookPreCommitWorkflow.php | 8 +++- src/workflow/unit/ArcanistUnitWorkflow.php | 8 +++- .../upload/ArcanistUploadWorkflow.php | 11 +++-- src/workflow/which/ArcanistWhichWorkflow.php | 8 +++- 29 files changed, 264 insertions(+), 61 deletions(-) diff --git a/scripts/__init_script__.php b/scripts/__init_script__.php index 9ff10fd4..3d67b9fb 100644 --- a/scripts/__init_script__.php +++ b/scripts/__init_script__.php @@ -17,7 +17,10 @@ */ $include_path = ini_get('include_path'); -ini_set('include_path', $include_path.':'.dirname(__FILE__).'/../../'); + +$parent_dir = dirname(dirname(dirname(__FILE__))); + +ini_set('include_path', $include_path.PATH_SEPARATOR.$parent_dir); @include_once 'libphutil/src/__phutil_library_init__.php'; if (!@constant('__LIBPHUTIL__')) { echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to ". @@ -25,7 +28,7 @@ if (!@constant('__LIBPHUTIL__')) { exit(1); } -phutil_load_library(dirname(__FILE__).'/../src/'); +phutil_load_library(dirname(dirname(__FILE__)).'/src/'); // There may be some kind of auto-prepend script configured which starts an // output buffer. Discard any such output buffers. diff --git a/scripts/arcanist.php b/scripts/arcanist.php index 3808137e..59d3665d 100755 --- a/scripts/arcanist.php +++ b/scripts/arcanist.php @@ -331,15 +331,23 @@ function sanity_check_environment() { "'{$min_version}'."); } - $need_functions = array( - 'json_decode' => '--without-json', - ); + // NOTE: We don't have phutil_is_windows() yet here. + + if (DIRECTORY_SEPARATOR != '/') { + $need_functions = array( + 'curl_init' => array('builtin-dll', 'php_curl.dll'), + ); + } else { + $need_functions = array( + 'json_decode' => array('flag', '--without-json'), + ); + } $problems = array(); $config = null; $show_config = false; - foreach ($need_functions as $fname => $flag) { + foreach ($need_functions as $fname => $resolution) { if (function_exists($fname)) { continue; } @@ -355,15 +363,29 @@ function sanity_check_environment() { } } - if (strpos($config, $flag) !== false) { + $generic = true; + list($what, $which) = $resolution; + + if ($what == 'flag' && strpos($config, $which) !== false) { $show_config = true; + $generic = false; $problems[] = - "This build of PHP was compiled with the configure flag '{$flag}', ". + "This build of PHP was compiled with the configure flag '{$which}', ". "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 { + } + + if ($what == 'builtin-dll') { + $generic = false; + $problems[] = + "Your install of PHP does not have the '{$which}' extension enabled. ". + "Edit your php.ini file and uncomment the line which reads ". + "'extension={$which}'."; + } + + if ($generic) { $problems[] = "This build of PHP is missing the required function '{$fname}()'. ". "Rebuild PHP or install the extension which provides '{$fname}()'."; diff --git a/scripts/phutil_analyzer.php b/scripts/phutil_analyzer.php index 5df27104..48c59a32 100755 --- a/scripts/phutil_analyzer.php +++ b/scripts/phutil_analyzer.php @@ -34,7 +34,7 @@ $builtin = array( 'print' => true, 'exit' => true, 'die' => true, - 'phutil_load_library' => true, + 'phutil_is_windows' => true, // HPHP/i defines these functions as 'internal', but they are NOT // builtins and do not exist in vanilla PHP. Make sure we don't mark them diff --git a/src/workflow/alias/ArcanistAliasWorkflow.php b/src/workflow/alias/ArcanistAliasWorkflow.php index 7a1704e5..70cbfda1 100644 --- a/src/workflow/alias/ArcanistAliasWorkflow.php +++ b/src/workflow/alias/ArcanistAliasWorkflow.php @@ -23,11 +23,17 @@ */ final class ArcanistAliasWorkflow extends ArcanistBaseWorkflow { - public function getCommandHelp() { + public function getCommandSynopses() { return phutil_console_format(<<arcanistConfiguration; } + public function getCommandSynopses() { + return get_class($this).": Undocumented"; + } + public function getCommandHelp() { return get_class($this).": Undocumented"; } @@ -921,25 +925,32 @@ abstract class ArcanistBaseWorkflow { } public static function getUserConfigurationFileLocation() { - return getenv('HOME').'/.arcrc'; + if (phutil_is_windows()) { + return getenv('APPDATA').'/.arcrc'; + } else { + return getenv('HOME').'/.arcrc'; + } } public static function readUserConfigurationFile() { $user_config = array(); $user_config_path = self::getUserConfigurationFileLocation(); if (Filesystem::pathExists($user_config_path)) { - $mode = fileperms($user_config_path); - if (!$mode) { - throw new Exception("Unable to get perms of '{$user_config_path}'!"); - } - if ($mode & 0177) { - // Mode should allow only owner access. - $prompt = "File permissions on your ~/.arcrc are too open. ". - "Fix them by chmod'ing to 600?"; - if (!phutil_console_confirm($prompt, $default_no = false)) { - throw new ArcanistUsageException("Set ~/.arcrc to file mode 600."); + + if (!phutil_is_windows()) { + $mode = fileperms($user_config_path); + if (!$mode) { + throw new Exception("Unable to get perms of '{$user_config_path}'!"); + } + if ($mode & 0177) { + // Mode should allow only owner access. + $prompt = "File permissions on your ~/.arcrc are too open. ". + "Fix them by chmod'ing to 600?"; + if (!phutil_console_confirm($prompt, $default_no = false)) { + throw new ArcanistUsageException("Set ~/.arcrc to file mode 600."); + } + execx('chmod 600 %s', $user_config_path); } - execx('chmod 600 %s', $user_config_path); } $user_config_data = Filesystem::readFile($user_config_path); @@ -959,7 +970,10 @@ abstract class ArcanistBaseWorkflow { $path = self::getUserConfigurationFileLocation(); Filesystem::writeFile($path, $json); - execx('chmod 600 %s', $path); + + if (!phutil_is_windows()) { + execx('chmod 600 %s', $path); + } } diff --git a/src/workflow/branch/ArcanistBranchWorkflow.php b/src/workflow/branch/ArcanistBranchWorkflow.php index e46306be..8731f520 100644 --- a/src/workflow/branch/ArcanistBranchWorkflow.php +++ b/src/workflow/branch/ArcanistBranchWorkflow.php @@ -25,9 +25,15 @@ final class ArcanistBranchWorkflow extends ArcanistBaseWorkflow { private $branches; - public function getCommandHelp() { + public function getCommandSynopses() { return phutil_console_format(<< array( + 'help' => 'Print detailed information about each command.', + ), '*' => 'command', ); } @@ -59,6 +69,10 @@ EOTEXT if ($target && $target != $command) { continue; } + if (!$target && !$this->getArgument('full')) { + $cmdref[] = $workflow->getCommandSynopses(); + continue; + } $optref = array(); $arguments = $workflow->getArguments(); @@ -133,7 +147,10 @@ EOTEXT $optref = "\n"; } - $cmdref[] = $workflow->getCommandHelp().$optref; + $cmdref[] = + $workflow->getCommandSynopses()."\n". + $workflow->getCommandHelp(). + $optref; } $cmdref = implode("\n\n", $cmdref); @@ -143,19 +160,30 @@ EOTEXT } $self = 'arc'; + $description = ($this->getArgument('full') ? + "This help file provides a detailed command reference." : + "Run 'arc help --full' to get detailed command reference."); echo phutil_console_format(<<getArgument('full')) { + return; + } + + echo phutil_console_format(<<