diff --git a/commands/simpletest/simpletest.drush.inc b/commands/simpletest/simpletest.drush.inc index 807533f..1d6f5a0 100644 --- a/commands/simpletest/simpletest.drush.inc +++ b/commands/simpletest/simpletest.drush.inc @@ -61,7 +61,7 @@ function drush_test_mail($recipients) { return drush_set_error('DRUSH_SIMPLETEST_RUNTESTS_SH', dt('You must copy or symlink run-tests.sh into your /scripts directory beneath Drupal root.')); } - $php = drush_find_php(); + $php = drush_simpletest_find_php(); $extra = drush_get_option('extra'); $url = escapeshellarg(url('', array('absolute' => TRUE))); $exec = $php . " $run_tests --php '" . $php . '\' --url ' . $url . " $extra"; @@ -71,6 +71,26 @@ function drush_test_mail($recipients) { mail($recipients, $subject, $output); } +// Copied from run-tests.sh +function drush_simpletest_find_php() { + // Determine location of php command automatically, unless a comamnd line argument is supplied. + if (!$php = drush_get_option('php')) { + if (!empty($_ENV['_'])) { + // '_' is an environment variable set by the shell. It contains the command that was executed. + $php = $_ENV['_']; + } + elseif (!empty($_ENV['SUDO_COMMAND'])) { + // 'SUDO_COMMAND' is an environment variable set by the sudo program. + // Extract only the PHP interpreter, not the rest of the command. + list($php, ) = explode(' ', $_ENV['SUDO_COMMAND'], 2); + } + else { + drush_set_error('DRUSH_SIMPLETEST_PHP_PATH_NOT_FOUND', dt('Unable to automatically determine the path to the PHP interpreter. Please supply the --php argument.')); + } + } + return $php; +} + // Based on pifr_review_format_results(). Not working yet. Help wanted. function drush_simpletest_format_results($output) { if (preg_match_all('/^(.*?) (\d+) (?:pass|passes), (\d+) fails?, and (\d+) exceptions?$/m', $output, $matches, PREG_SET_ORDER)) { diff --git a/drush.php b/drush.php index 360477d..782985b 100755 --- a/drush.php +++ b/drush.php @@ -1,3 +1,4 @@ +#!/usr/bin/env php ./drush.php + * _SERVER["_"] => /home/anarcat/dist/drush/./drush.php + * + * Calling php ./drush.php yeilds the following: + * + * _SERVER["argv"][0] => ./drush.php + * _SERVER["_"] => /usr/bin/php + * + * Therefore, we assume that if $_ finishes with $argv[0], we can call + * it directly again. Otherwise, we assume that $_ is the php binary + * and $argv[0] is the path to drush.php. We will use __FILE__, + * however, since we do not want to rely on (potentially) relative + * paths. + */ +if (substr($_SERVER['_'], -strlen($_SERVER['argv'][0])) == $_SERVER['argv'][0]) { + // $GLOBALS['_'] and $GLOBALS['argv'][0] both finish with the same, + // which means we were called directly + define('DRUSH_COMMAND', $_SERVER['_']); +} +else { + // not called directly, we were called as an argument to PHP, which + // should be in $GLOBALS['_'] + define('DRUSH_COMMAND', $_SERVER['_'] . ' ' . __FILE__); +} define('DRUSH_REQUEST_TIME', microtime(TRUE)); require_once DRUSH_BASE_PATH . '/includes/environment.inc'; diff --git a/includes/backend.inc b/includes/backend.inc index fa864fe..e9d4e18 100644 --- a/includes/backend.inc +++ b/includes/backend.inc @@ -326,8 +326,7 @@ function _drush_backend_generate_command($command, &$data, $method = 'GET', $dru $command .= ' ' . escapeshellarg($arg); } // @TODO: Implement proper multi platform / multi server support. - $php = drush_find_php(); - $cmd = $php . sprintf(escapeshellcmd(" %s %s %s --backend"), escapeshellcmd($drush_path), $option_str, $command); + $cmd = sprintf(escapeshellcmd("%s %s %s --backend"), escapeshellcmd($drush_path), $option_str, $command); if (!is_null($hostname)) { $username = (!is_null($username)) ? $username : get_current_user(); diff --git a/includes/drush.inc b/includes/drush.inc index a0425c0..af84afb 100644 --- a/includes/drush.inc +++ b/includes/drush.inc @@ -298,7 +298,6 @@ function drush_get_option_help() { $options['-u, --user'] = dt("Specify a user to login with. May be a name or a number."); $options['-b, --backend'] = dt("Hide all output and return structured data (internal use only)."); $options['-p, --pipe'] = dt("Emit a compact representation of the command for scripting."); - $options['--php'] = dt("The absolute path to your PHP intepreter."); return $options; } diff --git a/includes/environment.inc b/includes/environment.inc index dede0c7..797b97e 100644 --- a/includes/environment.inc +++ b/includes/environment.inc @@ -830,26 +830,6 @@ function drush_valid_db_credentials() { } } -// Copied from run-tests.sh -function drush_find_php() { - // Determine location of php command automatically, unless a command line argument is supplied. - if (!$php = drush_get_option('php')) { - if (!empty($_ENV['_'])) { - // '_' is an environment variable set by the shell. It contains the command that was executed. - $php = $_ENV['_']; - } - elseif (!empty($_ENV['SUDO_COMMAND'])) { - // 'SUDO_COMMAND' is an environment variable set by the sudo program. - // Extract only the PHP interpreter, not the rest of the command. - list($php, ) = explode(' ', $_ENV['SUDO_COMMAND'], 2); - } - else { - drush_set_error('DRUSH_PHP_PATH_NOT_FOUND', dt('Unable to automatically determine the path to the PHP interpreter. Please supply the --php argument.')); - } - } - return $php; -} - /** * Get module information for all installed modules. Wrapper for _drush_get_modules(). *