Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip the launcher when using Windows. #2312

Merged
merged 6 commits into from Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -40,7 +40,8 @@
"symfony/console": "2.7.*",
"symfony/event-dispatcher": "2.7.*",
"symfony/config": "~2.2",
"pear/console_table": "~1.3.0"
"pear/console_table": "~1.3.0",
"webmozart/path-util": "~2"
},
"require-dev": {
"phpunit/phpunit": "4.*",
Expand Down
50 changes: 48 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/install-alternative.md
Expand Up @@ -68,7 +68,7 @@ cd /opt/drush-9.x

Windows
------------
Drush on Windows is not recommended, since Drush's test suite is not running there ([help wanted](https://github.com/drush-ops/drush/issues/1612)).
Drush on Windows is experimental, since Drush's test suite is not running there ([help wanted](https://github.com/drush-ops/drush/issues/1612)).

- [Acquia Dev Desktop](https://www.acquia.com/downloads) is excellent, and includes Drush. See the terminal icon after setting up a web site.
- Or consider running Linux/OSX via Virtualbox. [Drupal VM](http://www.drupalvm.com/) and [Vlad](https://github.com/hashbangcode/vlad) are popular.
Expand Down
10 changes: 0 additions & 10 deletions includes/environment.inc
Expand Up @@ -506,16 +506,6 @@ function drush_build_drush_command($drush_path = NULL, $php = NULL, $os = NULL,
return trim($prefix . ' ' . drush_escapeshellarg($drush_path, $os) . $additional_options);
}

/**
* Check if the operating system is Windows.
* This will return TRUE under DOS, Powershell
* Cygwin and MSYSGIT shells, so test for the
* Windows variant FIRST if you care.
*/
function drush_is_windows($os = NULL) {
return _drush_test_os($os, array("WIN","CYGWIN","CWRSYNC","MINGW"));
}

/**
* Check if the operating system is Winodws
* running some variant of cygwin -- either
Expand Down
34 changes: 0 additions & 34 deletions includes/exec.inc
Expand Up @@ -322,40 +322,6 @@ function drush_wrap_with_quotes($arg) {
* Use raw to get an unquoted version of the escaped arg.
* Notice that you can't add quotes later until you know the platform.
*/
function drush_escapeshellarg($arg, $os = NULL, $raw = FALSE) {
// Short-circuit escaping for simple params (keep stuff readable)
if (preg_match('|^[a-zA-Z0-9.:/_-]*$|', $arg)) {
return $arg;
}
elseif (drush_is_windows($os)) {
return _drush_escapeshellarg_windows($arg, $raw);
}
else {
return _drush_escapeshellarg_linux($arg, $raw);
}
}

/**
* Windows version of escapeshellarg().
*/
function _drush_escapeshellarg_windows($arg, $raw = FALSE) {
// Double up existing backslashes
$arg = preg_replace('/\\\/', '\\\\\\\\', $arg);

// Double up double quotes
$arg = preg_replace('/"/', '""', $arg);

// Double up percents.
$arg = preg_replace('/%/', '%%', $arg);

// Only wrap with quotes when needed.
if(!$raw) {
// Add surrounding quotes.
$arg = '"' . $arg . '"';
}

return $arg;
}

/**
* Stores output for the most recent shell command.
Expand Down
6 changes: 3 additions & 3 deletions includes/filesystem.inc
Expand Up @@ -4,6 +4,7 @@
* @file
* Filesystem utilities.
*/
use Webmozart\PathUtil\Path;

/**
* @defgroup filesystemfunctions Filesystem convenience functions.
Expand Down Expand Up @@ -738,9 +739,8 @@ function drush_file_append_data($file, $data) {
* the other.
*/
function drush_is_nested_directory($base_dir, $test_is_nested) {
// Ensure there is always exactly one '/' at the end of $base_dir
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
return substr($test_is_nested, 0, strlen($base_dir)) == $base_dir;
$common = Path::getLongestCommonBasePath([$test_is_nested, $base_dir]);
return $common == Path::canonicalize($base_dir);
}

/**
Expand Down
64 changes: 56 additions & 8 deletions includes/startup.inc
Expand Up @@ -125,6 +125,26 @@ function find_wrapper_or_launcher_at_location($location) {
return "";
}

/**
* Determine whether current OS is a Windows variant.
*/
function drush_is_windows() {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}

function drush_escapeshellarg($arg, $os = NULL, $raw = FALSE) {
// Short-circuit escaping for simple params (keep stuff readable)
if (preg_match('|^[a-zA-Z0-9.:/_-]*$|', $arg)) {
return $arg;
}
elseif (drush_is_windows($os)) {
return _drush_escapeshellarg_windows($arg, $raw);
}
else {
return _drush_escapeshellarg_linux($arg, $raw);
}
}

/**
* Linux version of escapeshellarg().
*
Expand Down Expand Up @@ -157,6 +177,28 @@ function _drush_escapeshellarg_linux($arg, $raw = FALSE) {
return $arg;
}

/**
* Windows version of escapeshellarg().
*/
function _drush_escapeshellarg_windows($arg, $raw = FALSE) {
// Double up existing backslashes
$arg = preg_replace('/\\\/', '\\\\\\\\', $arg);

// Double up double quotes
$arg = preg_replace('/"/', '""', $arg);

// Double up percents.
$arg = preg_replace('/%/', '%%', $arg);

// Only wrap with quotes when needed.
if(!$raw) {
// Add surrounding quotes.
$arg = '"' . $arg . '"';
}

return $arg;
}

/**
* drush_startup is called once, by the Drush "finder"
* script -- the "drush" script at the Drush root.
Expand Down Expand Up @@ -313,20 +355,26 @@ function drush_startup($argv) {
}
}

// A Phar can't use the Bash niceties of the Launcher so just proceed to drush_main().
if (class_exists('Phar') && Phar::running()) {
// Didn't find any site-local Drush, or @use'd Drush.
// If a Phar finds itself (https://github.com/drush-ops/drush/pull/2246), skip the Bash niceties of the launcher and proceed to drush_main().
if (!empty($found_script) && class_exists('Phar') && $found_script == Phar::running(FALSE)) {
drush_run_main($DEBUG, $sep, "Phar detected. Proceeding to drush_main().");
}

// Didn't find any site-local Drush, or @use'd Drush, or Phar.
// There should be a drush.launcher in same directory as this script.
if (empty($found_script)) {
$found_script = dirname(__DIR__) . "{$sep}drush.launcher";
// Phar clause added due to https://github.com/drush-ops/drush/pull/2246
if (!is_executable($found_script)) {
// Can't execute the found launcher, so proceed with the current drush,
// bypassing the Bash niceties of the launcher.
drush_run_main($DEBUG, $sep, 'No executable launcher found. Proceeding to drush_main()."');
}

if (drush_is_windows()) {
// Sometimes we found launcher in /bin, and sometimes not. Adjust accordingly.
if (strpos($found_script, 'bin')) {
$found_script = dirname($found_script). $sep. 'drush.php.bat';
}
else {
array_unshift($arguments, dirname($found_script). $sep. 'drush.php');
$found_script = 'php';
}
}

Expand Down Expand Up @@ -370,7 +418,7 @@ function drush_startup($argv) {
exit(1);
}
else {
$escaped_args = array_map(function($item) { return _drush_escapeshellarg_linux($item); }, $arguments);
$escaped_args = array_map(function($item) { return drush_escapeshellarg($item); }, $arguments);
$process = proc_open($found_script . ' ' . implode(' ', $escaped_args), array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes);
$proc_status = proc_get_status($process);
$exit_code = proc_close($process);
Expand Down
2 changes: 1 addition & 1 deletion lib/Drush/Boot/DrupalBoot.php
Expand Up @@ -285,7 +285,7 @@ function bootstrap_drupal_root_validate() {
return drush_set_error('DRUSH_DRUPAL_VERSION_UNSUPPORTED', dt('Drush !drush_version does not support Drupal !major_version.', array('!drush_version' => DRUSH_VERSION, '!major_version' => $major_version)));
}

drush_bootstrap_value('drupal_root', realpath($drupal_root));
drush_bootstrap_value('drupal_root', $drupal_root);
define('DRUSH_DRUPAL_SIGNATURE', $signature);

return TRUE;
Expand Down