1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-09-19 16:38:51 +02:00

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
This commit is contained in:
epriestley 2012-03-05 10:02:37 -08:00
parent eae497152c
commit 2f9a422bc6
29 changed files with 264 additions and 61 deletions

View file

@ -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.

View file

@ -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}()'.";

View file

@ -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

View file

@ -23,11 +23,17 @@
*/
final class ArcanistAliasWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**alias**
**alias** __command__
**alias** __command__ __target__ -- [__options__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: cli
Create an alias from __command__ to __target__ (optionally, with
__options__). For example:
@ -46,7 +52,6 @@ final class ArcanistAliasWorkflow extends ArcanistBaseWorkflow {
arc alias fpatch
Without any arguments, 'arc alias' will list aliases.
EOTEXT
);
}

View file

@ -23,9 +23,15 @@
*/
final class ArcanistAmendWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**amend** [--revision __revision_id__] [--show]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git
Amend the working copy after a revision has been accepted, so commits
can be marked 'committed' and pushed upstream.

View file

@ -374,6 +374,10 @@ abstract class ArcanistBaseWorkflow {
return $this->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);
}
}

View file

@ -25,9 +25,15 @@ final class ArcanistBranchWorkflow extends ArcanistBaseWorkflow {
private $branches;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**branch**
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git
A wrapper on 'git branch'. It pulls data from Differential and
displays the revision status next to the branch name.

View file

@ -23,9 +23,15 @@
*/
final class ArcanistCallConduitWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**call-conduit** __method__
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: http, https
Allows you to make a raw Conduit method call:
@ -38,7 +44,6 @@ final class ArcanistCallConduitWorkflow extends ArcanistBaseWorkflow {
$ echo '{}' | arc call-conduit conduit.ping
$ echo '{"phid":"PHID-FILE-xxxx"}' | arc call-conduit file.download
EOTEXT
);
}

View file

@ -25,9 +25,15 @@ final class ArcanistCommitWorkflow extends ArcanistBaseWorkflow {
private $revisionID;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**commit** [--revision __revision_id__] [--show]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: svn
Commit a revision which has been accepted by a reviewer.
EOTEXT

View file

@ -23,9 +23,15 @@
*/
final class ArcanistCoverWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**cover**
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: svn, git
Cover your... professional reputation. Show blame for the lines you
changed in your working copy. This will take a minute because blame

View file

@ -37,10 +37,16 @@ final class ArcanistDiffWorkflow extends ArcanistBaseWorkflow {
private $revisionID;
private $unitWorkflow;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**diff** [__paths__] (svn)
**diff** [__commit__] (git, hg)
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, svn, hg
Generate a Differential diff or revision from local changes.
@ -51,7 +57,6 @@ final class ArcanistDiffWorkflow extends ArcanistBaseWorkflow {
Under svn, you can choose to include only some of the modified files
in the working copy in the diff by specifying their paths. If you
omit paths, all changes are included in the diff.
EOTEXT
);
}

View file

@ -27,14 +27,19 @@ final class ArcanistDownloadWorkflow extends ArcanistBaseWorkflow {
private $saveAs;
private $show;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**download** __file__ [--as __name__] [--show]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: filesystems
Download a file to local disk, e.g.:
$ arc download F33 # Download file 'F33'
EOTEXT
);
}

View file

@ -35,12 +35,18 @@ final class ArcanistExportWorkflow extends ArcanistBaseWorkflow {
private $sourceID;
private $format;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**export** [__paths__] __format__ (svn)
**export** [__commit_range__] __format__ (git)
**export** __--revision__ __revision_id__ __format__
**export** __--diff__ __diff_id__ __format__
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, svn
Export the local changeset (or a Differential changeset) to a file,
in some __format__: git diff (__--git__), unified diff

View file

@ -23,9 +23,15 @@
*/
final class ArcanistGitHookPreReceiveWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**git-hook-pre-receive**
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git
You can install this as a git pre-receive hook.
EOTEXT

View file

@ -23,9 +23,16 @@
*/
final class ArcanistHelpWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**help** [__command__]
**help** --full
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: english
Shows this help. With __command__, shows help about a specific
command.
@ -35,6 +42,9 @@ EOTEXT
public function getArguments() {
return array(
'full' => 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(<<<EOTEXT
**NAME**
**{$self}** - arcanist, a code review and revision management utility
**SYNOPSIS**
**{$self}** __command__ [__options__] [__args__]
This help file provides a detailed command reference.
{$description}
**COMMAND REFERENCE**
{$cmdref}
EOTEXT
);
if (!$this->getArgument('full')) {
return;
}
echo phutil_console_format(<<<EOTEXT
**OPTION REFERENCE**
__--trace__

View file

@ -23,9 +23,15 @@
*/
final class ArcanistInstallCertificateWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**install-certificate** [uri]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: http, https
Installs Conduit credentials into your ~/.arcrc for the given install
of Phabricator. You need to do this before you can use 'arc', as it

View file

@ -23,9 +23,15 @@
*/
final class ArcanistLandWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**land** [__options__] __branch__ [--onto __master__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git
Land an accepted change (currently sitting in local feature branch
@ -37,7 +43,6 @@ final class ArcanistLandWorkflow extends ArcanistBaseWorkflow {
immutable repositories (or when --merge is provided), it will perform
a --no-ff merge (the branch will always be merged into __master__ with
a merge commit).
EOTEXT
);
}

View file

@ -29,9 +29,15 @@
*/
final class ArcanistLiberateWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**liberate** [__path__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: libphutil
Create or update a libphutil library, generating required metadata
files like \__init__.php.

View file

@ -36,10 +36,16 @@ class ArcanistLintWorkflow extends ArcanistBaseWorkflow {
return $this;
}
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**lint** [__options__] [__paths__]
**lint** [__options__] --rev [__rev__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, svn, hg
Run static analysis on changes to check for mistakes. If no files
are specified, lint will be run on all files which have been modified.

View file

@ -23,9 +23,15 @@
*/
final class ArcanistListWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**list**
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, svn, hg
List your open Differential revisions.
EOTEXT

View file

@ -23,9 +23,15 @@
*/
final class ArcanistMarkCommittedWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**mark-committed** __revision__
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, svn
Manually mark a revision as committed. You should not normally need
to do this; arc commit (svn), arc amend (git), arc merge (git, hg) or

View file

@ -26,11 +26,16 @@
*/
final class ArcanistMergeWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**merge**
Deprecated.
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Deprecated.
EOTEXT
);
}

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -28,10 +28,16 @@ final class ArcanistPasteWorkflow extends ArcanistBaseWorkflow {
private $title;
private $json;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**paste** [--title __title__] [--lang __language__] [--json]
**paste** __id__ [--json]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: text
Share and grab text using the Paste application. To create a paste,
use stdin to provide the text:
@ -41,7 +47,6 @@ final class ArcanistPasteWorkflow extends ArcanistBaseWorkflow {
To retrieve a paste, specify the paste ID:
$ arc paste P123
EOTEXT
);
}

View file

@ -31,13 +31,19 @@ final class ArcanistPatchWorkflow extends ArcanistBaseWorkflow {
private $source;
private $sourceParam;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**patch** __D12345__
**patch** __--revision__ __revision_id__
**patch** __--diff__ __diff_id__
**patch** __--patch__ __file__
**patch** __--arcbundle__ __bundlefile__
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, svn, hg
Apply the changes in a Differential revision, patchfile, or arc
bundle to the working copy.

View file

@ -23,9 +23,15 @@
*/
final class ArcanistShellCompleteWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**shell-complete** __--current__ __N__ -- [__argv__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: bash, etc.
Implements shell completion. To use shell completion, source the
appropriate script from 'resources/shell/' in your .shellrc.

View file

@ -23,9 +23,15 @@
*/
final class ArcanistSvnHookPreCommitWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**svn-hook-pre-commit** __repository__ __transaction__
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: svn
You can install this as an SVN pre-commit hook. For more information,
see the article "Installing Arcanist SVN Hooks" in the Arcanist

View file

@ -33,10 +33,16 @@ final class ArcanistUnitWorkflow extends ArcanistBaseWorkflow {
private $testResults;
private $engine;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**unit** [__options__] [__paths__]
**unit** [__options__] --rev [__rev__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: git, svn, hg
Run unit tests that cover specified paths. If no paths are specified,
unit tests covering all modified files will be run.

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,12 +26,17 @@ final class ArcanistUploadWorkflow extends ArcanistBaseWorkflow {
private $paths;
private $json;
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**upload** __file__ [__file__ ...] [--json]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: filesystems
Upload a file from local disk.
EOTEXT
);
}

View file

@ -23,10 +23,16 @@
*/
final class ArcanistWhichWorkflow extends ArcanistBaseWorkflow {
public function getCommandHelp() {
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**which** (svn)
**which** [commit] (hg, git)
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: svn, git, hg
Shows which revision is in the working copy (or which revisions, if
more than one matches).