8000 On Windows, we don't rely on the OS to find executables · composer/composer@e1caf42 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1caf42

Browse files
On Windows, we don't rely on the OS to find executables
1 parent 186d78c commit e1caf42

34 files changed

+341
-251
lines changed

src/Composer/Command/DiagnoseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ private function checkGit(): string
302302
return '<comment>proc_open is not available, git cannot be used</comment>';
303303
}
304304

305-
$this->process->execute('git config color.ui', $output);
305+
$this->process->execute(['git', 'config', 'color.ui'], $output);
306306
if (strtolower(trim($output)) === 'always') {
307307
return '<comment>Your git color.ui setting is set to always, this is known to create issues. Use "git config --global color.ui true" to set it correctly.</comment>';
308308
}

src/Composer/Command/HomeCommand.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,20 @@ private function handlePackage(CompletePackageInterface $package, bool $showHome
122122
*/
123123
private function openBrowser(string $url): void
124124
{
125-
$url = ProcessExecutor::escape($url);
126-
127125
$process = new ProcessExecutor($this->getIO());
128126
if (Platform::isWindows()) {
129-
$process->execute('start "web" explorer ' . $url, $output);
127+
$process->execute(['start', '"web"', 'explorer', $url], $output);
130128

131129
return;
132130
}
133131

134-
$linux = $process->execute('which xdg-open', $output);
135-
$osx = $process->execute('which open', $output);
132+
$linux = $process->execute(['which', 'xdg-open'], $output);
133+
$osx = $process->execute(['which', 'open'], $output);
136134

137135
if (0 === $linux) {
138-
$process->execute('xdg-open ' . $url, $output);
136+
$process->execute(['xdg-open', $url], $output);
139137
} elseif (0 === $osx) {
140-
$process->execute('open ' . $url, $output);
138+
$process->execute(['open', $url], $output);
141139
} else {
142140
$this->getIO()->writeError('No suitable browser opening command found, open yourself: ' . $url);
143141
}

src/Composer/Command/InitCommand.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Component\Console\Input\ArrayInput;
2828
use Symfony\Component\Console\Input\InputInterface;
2929
use Composer\Console\Input\InputOption;
30+
use Composer\Util\ProcessExecutor;
3031
use Symfony\Component\Console\Output\OutputInterface;
3132
use Symfony\Component\Process\ExecutableFinder;
3233
use Symfony\Component\Process\Process;
@@ -535,15 +536,11 @@ protected function getGitConfig(): array
535536
return $this->gitConfig;
536537
}
537538

538-
$finder = new ExecutableFinder();
539-
$gitBin = $finder->find('git');
539+
$process = new ProcessExecutor($this->getIO());
540540

541-
$cmd = new Process([$gitBin, 'config', '-l']);
542-
$cmd->run();
543-
544-
if ($cmd->isSuccessful()) {
541+
if (0 === $process->execute(['git', 'config', '-l'], $output)) {
545542
$this->gitConfig = [];
546-
Preg::matchAllStrictGroups('{^([^=]+)=(.*)$}m', $cmd->getOutput(), $matches);
543+
Preg::matchAllStrictGroups('{^([^=]+)=(.*)$}m', $output, $matches);
547544
foreach ($matches[1] as $key => $match) {
548545
$this->gitConfig[$match] = $matches[2][$key];
549546
}

src/Composer/Compiler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Composer\Json\JsonFile;
1616
use Composer\CaBundle\CaBundle;
1717
use Composer\Pcre\Preg;
18+
use Composer\Util\ProcessExecutor;
1819
use Symfony\Component\Finder\Finder;
1920
use Symfony\Component\Process\Process;
2021
use Seld\PharUtils\Timestamps;
@@ -48,23 +49,22 @@ public function compile(string $pharFile = 'composer.phar'): void
4849
unlink($pharFile);
4950
}
5051

51-
$process = new Process(['git', 'log', '--pretty=%H', '-n1', 'HEAD'], __DIR__);
52-
if ($process->run() !== 0) {
52+
$process = new ProcessExecutor();
53+
54+
if (0 !== $process->execute(['git', 'log', '--pretty=%H', '-n1', 'HEAD'], $output, __DIR__)) {
5355
throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.');
5456
}
55-
$this->version = trim($process->getOutput());
57+
$this->version = trim($output);
5658

57-
$process = new Process(['git', 'log', '-n1', '--pretty=%ci', 'HEAD'], __DIR__);
58-
if ($process->run() !== 0) {
59+
if (0 !== $process->execute(['git', 'log', '-n1', '--pretty=%ci', 'HEAD'], $output, __DIR__)) {
5960
throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.');
6061
}
6162

62-
$this->versionDate = new \DateTime(trim($process->getOutput()));
63+
$this->versionDate = new \DateTime(trim($output));
6364
$this->versionDate->setTimezone(new \DateTimeZone('UTC'));
6465

65-
$process = new Process(['git', 'describe', '--tags', '--exact-match', 'HEAD'], __DIR__);
66-
if ($process->run() === 0) {
67-
$this->version = trim($process->getOutput());
66+
if (0 !== $process->execute(['git', 'describe', '--tags', '--exact-match', 'HEAD'], $output, __DIR__)) {
67+
$this->version = trim($output);
6868
} else {
6969
// get branch-alias defined in composer.json for dev-main (if any)
7070
$localConfig = __DIR__.'/../../composer.json';

src/Composer/Downloader/FossilDownloader.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,19 @@ protected function doInstall(PackageInterface $package, string $path, string $ur
3838
// Ensure we are allowed to use this URL by config
3939
$this->config->prohibitUrlByConfig($url, $this->io);
4040

41-
$url = ProcessExecutor::escape($url);
42-
$ref = ProcessExecutor::escape($package->getSourceReference());
4341
$repoFile = $path . '.fossil';
4442
$this->io->writeError("Cloning ".$package->getSourceReference());
45-
$command = sprintf('fossil clone -- %s %s', $url, ProcessExecutor::escape($repoFile));
43+
$command = ['fossil', 'clone', '--', $url, $repoFile];
4644
if (0 !== $this->process->execute($command, $ignoredOutput)) {
47-
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
45+
throw new \RuntimeException('Failed to execute ' . implode(' ', $command) . "\n\n" . $this->process->getErrorOutput());
4846
}
49-
$command = sprintf('fossil open --nested -- %s', ProcessExecutor::escape($repoFile));
47+
$command = ['fossil', 'open', '--nested', '--', $repoFile];
5048
if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) {
51-
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
49+
throw new \RuntimeException('Failed to execute ' . implode(' ', $command) . "\n\n" . $this->process->getErrorOutput());
5250
}
53-
$command = sprintf('fossil update -- %s', $ref);
51+
$command = ['fossil', 'update', '--', $package->getSourceReference()];
5452
if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) {
55-
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
53+
throw new \RuntimeException('Failed to execute ' . implode(' ', $command) . "\n\n" . $this->process->getErrorOutput());
5654
}
5755

5856
return \React\Promise\resolve(null);
@@ -66,16 +64,18 @@ protected function doUpdate(PackageInterface $initial, PackageInterface $target,
6664
// Ensure we are allowed to use this URL by config
6765
$this->config->prohibitUrlByConfig($url, $this->io);
6866

69-
$ref = ProcessExecutor::escape($target->getSourceReference());
7067
$this->io->writeError(" Updating to ".$target->getSourceReference());
7168

7269
if (!$this->hasMetadataRepository($path)) {
7370
throw new \RuntimeException('The .fslckout file is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
7471
}
7572

76-
$command = sprintf('fossil pull && fossil up %s', $ref);
77-
if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) {
78-
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
73+
if (0 !== $this->process->execute(['fossil', 'pull'], $ignoredOutput, realpath($path))) {
74+
throw new \RuntimeException("Failed to execute fossil pull\n\n" . $this->process->getErrorOutput());
75+
}
76+
77+
if (0 !== $this->process->execute(['fossil', 'up', $target->getSourceReference()], $ignoredOutput, realpath($path))) {
78+
throw new \RuntimeException("Failed to execute fossil up\n\n" . $this->process->getErrorOutput());
7979
}
8080

8181
return \React\Promise\resolve(null);
@@ -90,7 +90,7 @@ public function getLocalChanges(PackageInterface $package, string $path): ?strin
9090
return null;
9191
}
9292

93-
$this->process->execute('fossil changes', $output, realpath($path));
93+
$this->process->execute(['fossil', 'changes'], $output, realpath($path));
9494

9595
$output = trim($output);
9696

@@ -102,10 +102,10 @@ public function getLocalChanges(PackageInterface $package, string $path): ?strin
102102
*/
103103
protected function getCommitLogs(string $fromReference, string $toReference, string $path): string
104104
{
105-
$command = sprintf('fossil timeline -t ci -W 0 -n 0 before %s', ProcessExecutor::escape($toReference));
105+
$command = ['fossil', 'timeline', '-t', 'ci', '-W', '0', '-n', '0', 'before', $toReference];
106106

107107
if (0 !== $this->process->execute($command, $output, realpath($path))) {
108-
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
108+
throw new \RuntimeException('Failed to execute ' . implode(' ', $command) . "\n\n" . $this->process->getErrorOutput());
109109
}
110110

111111
$log = '';

0 commit comments

Comments
 (0)
0