Skip to content

Commit 42d28c8

Browse files
authored
Fix call to PHPStan phar on Windows
* Add AppVeyor build configuration for testing * Update matrix * Specify PHP version minors for Chocolatey * Test drupal-check analyze * Remove COMPOSER_MEMORY_LIMIT for Windows * Try to fix memory and composer problems with Composer * Ignore ext-gd requirement * Debug to see if we can find path to PHP * Try reqs * On Windows, prefix bin path with `php` * Add realpath for Windows * Fix generated configuration location * Don't use realpath in file_exists * Try wrapping in quotes * Add verbosity for debugging * Add debugging on the path to be analyzed * drupal-finder returns invalid paths * Debug the PHPStan bin path * Fix phpstanBin debug output * Add more debugging * Ensure realpath for config path passed to PHPStan * Invoke phar directly
1 parent 9af16ad commit 42d28c8

File tree

2 files changed

+69
-23
lines changed

2 files changed

+69
-23
lines changed

appveyor.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '{build}'
2+
platform:
3+
- x64
4+
clone_depth: 1
5+
max_jobs: 3
6+
cache:
7+
- '%LOCALAPPDATA%\Composer'
8+
- '%LOCALAPPDATA%\Temp\Chocolatey'
9+
environment:
10+
ANSICON: 121x90 (121x90)
11+
matrix:
12+
# @todo learn how to have Chocolately install latest minor without specifying patch version.
13+
- { PHP_VERSION: '7.2.33' }
14+
- { PHP_VERSION: '7.3.22' }
15+
install:
16+
# Enable Windows Update service, needed to install vcredist2015 (dependency of php)
17+
- ps: Set-Service wuauserv -StartupType Manual
18+
- choco config set cacheLocation %LOCALAPPDATA%\Temp\Chocolatey
19+
- choco install -y php --version %PHP_VERSION%
20+
- choco install -y composer
21+
- refreshenv
22+
- SET | more
23+
- composer install --no-interaction --no-progress --no-suggest --prefer-dist
24+
- set COMPOSER_MEMORY_LIMIT=-1&& composer create-project drupal-composer/drupal-project:8.x-dev %APPVEYOR_BUILD_FOLDER%\..\drupal --no-interaction --prefer-dist --ignore-platform-reqs
25+
build: off
26+
test_script:
27+
- php drupal-check --version
28+
- php drupal-check %APPVEYOR_BUILD_FOLDER%\..\drupal\web\core\install.php -vvv

src/Command/CheckCommand.php

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
5252
$this->memoryLimit = $input->getOption('memory-limit');
5353
$this->excludeDirectory = $input->getOption('exclude-dir');
5454

55+
// Default to deprecations.
56+
if (!$this->isDeprecationsCheck) {
57+
if (!$this->isAnalysisCheck && !$this->isStyleCheck) {
58+
$this->isDeprecationsCheck = true;
59+
} else {
60+
$this->isDeprecationsCheck = false;
61+
}
62+
}
63+
5564
if ($this->memoryLimit) {
5665
$output->writeln("<comment>Memory limit set to $this->memoryLimit", OutputInterface::VERBOSITY_DEBUG);
5766
}
@@ -65,15 +74,6 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
6574
$output->writeln('<comment>Performing code styling checks', OutputInterface::VERBOSITY_DEBUG);
6675
}
6776

68-
// Default to deprecations.
69-
if (!$this->isDeprecationsCheck) {
70-
if (!$this->isAnalysisCheck && !$this->isStyleCheck) {
71-
$this->isDeprecationsCheck = true;
72-
} else {
73-
$this->isDeprecationsCheck = false;
74-
}
75-
}
76-
7777
if ($input->getOption('format') === 'json') {
7878
$input->setOption('format', 'prettyJson');
7979
}
@@ -94,6 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9494
return 1;
9595
}
9696

97+
$output->writeln(sprintf('<comment>Analyzing path: %s</comment>', $realPath), OutputInterface::VERBOSITY_DEBUG);
9798
$paths[] = $realPath;
9899
}
99100

@@ -108,8 +109,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
108109
}
109110

110111
$drupalFinder->locateRoot($drupalRootCandidate);
111-
$this->drupalRoot = $drupalFinder->getDrupalRoot();
112-
$this->vendorRoot = $drupalFinder->getVendorDir();
112+
$this->drupalRoot = realpath($drupalFinder->getDrupalRoot());
113+
$this->vendorRoot = realpath($drupalFinder->getVendorDir());
113114

114115
if (!$this->drupalRoot) {
115116
$output->writeln(sprintf('<error>Unable to locate the Drupal root in %s</error>', $drupalRootCandidate));
@@ -178,36 +179,48 @@ protected function execute(InputInterface $input, OutputInterface $output): int
178179
$pharPath = \Phar::running();
179180
if ($pharPath !== '') {
180181
// Running in packaged Phar archive.
181-
$phpstanBin = 'vendor/phpstan/phpstan/phpstan';
182-
$configuration_data['parameters']['bootstrapFiles'] = [$pharPath . '/error-bootstrap.php'];
182+
$phpstanBin = \realpath('vendor/phpstan/phpstan/phpstan.phar');
183+
$configuration_data['parameters']['bootstrapFiles'] = [\realpath($pharPath . '/error-bootstrap.php')];
183184
$configuration_data['includes'] = [
184-
$pharPath . '/vendor/phpstan/phpstan-deprecation-rules/rules.neon',
185-
$pharPath . '/vendor/mglaman/phpstan-drupal/extension.neon',
185+
\realpath($pharPath . '/vendor/phpstan/phpstan-deprecation-rules/rules.neon'),
186+
\realpath($pharPath . '/vendor/mglaman/phpstan-drupal/extension.neon'),
186187
];
187188
} elseif (file_exists(__DIR__ . '/../../vendor/autoload.php')) {
188189
// Running as a project dependency.
189-
$phpstanBin = __DIR__ . '/../../vendor/phpstan/phpstan/phpstan';
190-
$configuration_data['parameters']['bootstrapFiles'] = [__DIR__ . '/../../error-bootstrap.php'];
190+
$phpstanBin = \realpath(__DIR__ . '/../../vendor/phpstan/phpstan/phpstan.phar');
191+
$configuration_data['parameters']['bootstrapFiles'] = [\realpath(__DIR__ . '/../../error-bootstrap.php')];
191192
$configuration_data['includes'] = [
192-
__DIR__ . '/../../vendor/phpstan/phpstan-deprecation-rules/rules.neon',
193-
__DIR__ . '/../../vendor/mglaman/phpstan-drupal/extension.neon',
193+
\realpath(__DIR__ . '/../../vendor/phpstan/phpstan-deprecation-rules/rules.neon'),
194+
\realpath(__DIR__ . '/../../vendor/mglaman/phpstan-drupal/extension.neon'),
194195
];
195196
} elseif (file_exists(__DIR__ . '/../../../../autoload.php')) {
196197
// Running as a global dependency.
197-
$phpstanBin = __DIR__ . '/../../../../phpstan/phpstan/phpstan';
198-
$configuration_data['parameters']['bootstrapFiles'] = [__DIR__ . '/../../error-bootstrap.php'];
198+
$phpstanBin = \realpath(__DIR__ . '/../../../../phpstan/phpstan/phpstan.phar');
199+
$configuration_data['parameters']['bootstrapFiles'] = [\realpath(__DIR__ . '/../../error-bootstrap.php')];
199200
// The phpstan/extension-installer doesn't seem to register.
200201
$configuration_data['includes'] = [
201-
__DIR__ . '/../../../../phpstan/phpstan-deprecation-rules/rules.neon',
202-
__DIR__ . '/../../../../mglaman/phpstan-drupal/extension.neon',
202+
\realpath(__DIR__ . '/../../../../phpstan/phpstan-deprecation-rules/rules.neon'),
203+
\realpath(__DIR__ . '/../../../../mglaman/phpstan-drupal/extension.neon'),
203204
];
204205
} else {
205206
throw new ShouldNotHappenException('Could not determine if local or global installation');
206207
}
207208

209+
if (!file_exists($phpstanBin)) {
210+
$output->writeln('Could not find PHPStan at ' . $phpstanBin);
211+
return 1;
212+
}
213+
214+
if (substr(PHP_OS, 0, 3) == 'WIN') {
215+
$phpstanBin = "php $phpstanBin";
216+
}
217+
218+
$output->writeln(sprintf('<comment>PHPStan path: %s</comment>', $phpstanBin), OutputInterface::VERBOSITY_DEBUG);
208219
$configuration_encoded = Neon::encode($configuration_data, Neon::BLOCK);
209220
$configuration = sys_get_temp_dir() . '/drupal_check_phpstan_' . time() . '.neon';
210221
file_put_contents($configuration, $configuration_encoded);
222+
$configuration = realpath($configuration);
223+
$output->writeln(sprintf('<comment>PHPStan configuration path: %s</comment>', $configuration), OutputInterface::VERBOSITY_DEBUG);
211224

212225
$output->writeln('<comment>PHPStan configuration:</comment>', OutputInterface::VERBOSITY_DEBUG);
213226
$output->writeln($configuration_encoded, OutputInterface::VERBOSITY_DEBUG);
@@ -238,15 +251,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
238251

239252
$process = new Process($command);
240253
$process->setTimeout(null);
254+
255+
$output->writeln('<comment>Executing PHPStan</comment>', OutputInterface::VERBOSITY_DEBUG);
241256
$process->run(static function ($type, $buffer) use ($output) {
242257
if (Process::ERR === $type) {
243258
$output->getErrorOutput()->write($buffer, false, OutputInterface::OUTPUT_RAW);
244259
} else {
245260
$output->write($buffer, false, OutputInterface::OUTPUT_RAW);
246261
}
247262
});
263+
$output->writeln('<comment>Finished executing PHPStan</comment>', OutputInterface::VERBOSITY_DEBUG);
264+
$output->writeln('<comment>Unlinking PHPStan configuration</comment>', OutputInterface::VERBOSITY_DEBUG);
248265
unlink($configuration);
249266

267+
$output->writeln('<comment>Return PHPStan exit code</comment>', OutputInterface::VERBOSITY_DEBUG);
250268
return $process->getExitCode();
251269
}
252270
}

0 commit comments

Comments
 (0)