run-tests.sh relies on $_ENV['_'] being defined. But "_" is not defined on all systems, particularly in Windows and others that don't run from a shell variant. In this case, we have to set --php when executing the run-tests.sh script. There however is built in a constant from PHP >= 5.4 that contains the path to the php executable that was called. PHP_BINARY. Lets use this in addition to the $_ENV['_'] check for php 5.3...

Comments

generalredneck created an issue. See original summary.

generalredneck’s picture

Status: Active » Needs review
StatusFileSize
new522 bytes

Here is a quick patch. Works on my Windows 10 machine running from CMD as well as from bash on Windows 10. This is using PHP 5.5. I will need someone to test linux/mac to make sure it still works (though I seriously doubt I broke anything, and for older versions of php like 5.3 and 5.2 which are officially supported.

cilefen’s picture

Issue summary: View changes
Status: Needs review » Postponed
Parent issue: » #2748883: Use the PHP_BINARY constant in addition to --php in run-tests.sh

Hi @generalredneck:

It doesn't break anything on a Mac, or the Linux testbots. This seems fine to me. But there is a backport policy so we don't miss useful enhancements on newer versions. These sections of the policy are relevant to this issue:

Where an issue filed against 8.x also applies to 7.x, a separate issue should be opened against 7.x, related to 8.x via the 'Parent issue' field (this can be done using the "Add child issue" link on the 8.x issue).
... By default, 7.x issues should be marked postponed until the 8.x issue is fixed to avoid duplicate work.

There already is an issue open in D8, #2748883: Use the PHP_BINARY constant in addition to --php in run-tests.sh. I am marking this postponed on that one.

mustanggb’s picture

Status: Postponed » Reviewed & tested by the community

D8 is set to use Symphony's PhpExecutableFinder, no chance of duplicate work, so we're unblocked.

mustanggb’s picture

Issue tags: +Drupal 7.69 target
mustanggb’s picture

Issue tags: -Drupal 7.69 target +Drupal 7.70 target
mustanggb’s picture

mcdruid’s picture

#2748883: Use the PHP_BINARY constant in addition to --php in run-tests.sh is still open for D8 (likely not getting much attention as I'm not sure the run-tests.sh script is used much now in newer branches), but as noted by @MustangGB the suggested approach there is to use Symfony's

https://github.com/symfony/process/blob/3.4/PhpExecutableFinder.php

#2 looks okay to me, but if we're primarily concerned with fixing run-tests.sh for Windows (as it works okay on *nix hosts which set the shell environment up in a reasonably consistent way), couldn't we put the new logic in later as a fallback? - e.g. something like:

  // Determine location of php command automatically, unless a command line argument is supplied.
  if (!empty($args['php'])) {                                                      
    $php = $args['php'];                                                           
  }                                                                                
  elseif ($php_env = getenv('_')) {                                                
    // '_' is an environment variable set by the shell. It contains the command that was executed.
    $php = $php_env;                                                               
  }
  elseif (defined('PHP_BINARY') && $php_env = PHP_BINARY) {
    $php = $php_env;
  }                                                                         
  elseif ($sudo = getenv('SUDO_COMMAND')) {

Perhaps that's a very minor point, but in the interests of "if it ain't broke, don't fix it" ...

mcdruid’s picture

StatusFileSize
new824 bytes
new727 bytes

This is hardly any different to #2 but will use the shell's _ env variable first if that's available.

mcdruid’s picture

Issue tags: +Drupal 7 bugfix target
fabianx’s picture

RTBM, +1 from me for merge

  • mcdruid committed 804aaac on 7.x
    Issue #2798377 by mcdruid, generalredneck, MustangGB, cilefen: Use...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Drupal 7.76 target, -Drupal 7 bugfix target

Thanks everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.