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

[BUGFIX] Keep PhpStorm from indexing the tool PHARs #968

Merged
merged 2 commits into from
Apr 9, 2021
Merged

Conversation

oliverklee
Copy link
Contributor

PHPUnit is the only tool for which we would like PhpStorm to index
the PHAR (so that it knows the PHPUnit classes exist). For all other
tools, indexing the PHARs would only slow PhpStorm down (and possibly
create warnings about classing existing multiple times).

@oliverklee oliverklee added the bug label Apr 6, 2021
@oliverklee oliverklee added this to the 6.0.0 milestone Apr 6, 2021
@oliverklee oliverklee requested a review from JakeQZ April 6, 2021 17:14
@oliverklee oliverklee self-assigned this Apr 6, 2021
Copy link
Contributor

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break the development environment on Windows, which depends on file extensions to know what program to use to run an executable.

I can't immediately think of a workaround or alternative solution...

@JakeQZ
Copy link
Contributor

JakeQZ commented Apr 6, 2021

I'll checkout the branch and look into it later. I know that PHIVE also generates batch files for Windows - maybe Windows will prefer those to the file without an extension...

@JakeQZ
Copy link
Contributor

JakeQZ commented Apr 6, 2021

I know that PHIVE also generates batch files for Windows - maybe Windows will prefer those to the file without an extension...

Yes, Windows will run a batch file if one exists with a .bat extension and the same base name as the requested extension-less file. I don't know if it's possible to get PHIVE to generate these when run on non-Windows, but if not, they can be manually created.

The same content will do for all of them:

@echo off
php "%~dpn0" %*

It does not matter if the line endings are Windows or UNIX, or if the last line has one. There'll need to be one for each tool without a file extension, i.e. psalm.bat, phpmd.bat, etc.

The exact content generated by PHIVE is tool-specific, e.g. for Psalm

@echo off
php "%~dp0psalm" %*

%~...0 expands based on the command part of the command line as described here, so dp = drive and path and dpn = drive, path and filename without extension.

Without such batch files, the tools without a file extension do indeed fail to run:

> "./tools/phpmd" src text config/phpmd.xml
'".\tools\phpmd"' is not recognized as an internal or external command,
operable program or batch file.
Script "./tools/phpmd" src text config/phpmd.xml handling the ci:php:md event returned with error code 1

@oliverklee oliverklee changed the title [BUGFIX] Keep PhpStan from indexing the tool PHARs [BUGFIX] Keep PhpStorm from indexing the tool PHARs Apr 7, 2021
@oliverklee
Copy link
Contributor Author

@JakeQZ Does work in Windows for you if we changed every tool-related Composer command to use the @php prefix, e.g., like this:

"ci:php:sniff": "@php \"./tools/phpcs\" config src tests",

@JakeQZ
Copy link
Contributor

JakeQZ commented Apr 7, 2021

"ci:php:sniff": "@php \"./tools/phpcs\" config src tests",

That would indeed work :)

While here, I wonder if were are using PHIVE in the right/recommended way. I.e. should we be storing the .phars under version control at all? We don't put the contents of the vendor directory from Composer under version control. And isn't the phive.xml at least partly analogous to the composer.lock file - though part of it is analogous to composer.json and would be needed under version control, with the only other way I can think of handling it being a script with a series of PHIVE commands specifying the required versions to install.

Feedback from phar-io/phive#296 suggests we have an "interesting use case". However feedback from phar-io/phive#295 indicates PHIVE currently does not support installing a version necessarily compatible with the calling environment.

Possibly a separate issue to come back to when it becomes more clear what the 'best practice' is...

@oliverklee
Copy link
Contributor Author

Let's see what the rest of the PHP developer crowd thinks. :-)

I have created a Twitter poll for this: https://twitter.com/oliklee/status/1380082284200595457

PHPUnit is the only tool for which we would like PhpStorm to index
the PHAR (so that it knows the PHPUnit classes exist). For all other
tools, indexing the PHARs would only slow PhpStorm down (and possibly
create warnings about classing existing multiple times).
@oliverklee oliverklee force-pushed the task/phar branch 2 times, most recently from bce9045 to 211a38f Compare April 9, 2021 11:30
This allows running the PHARs without the `.phar` suffix even
on Windows.
"ci:tests:sof": "@php \"./tools/phpunit.phar\" --stop-on-failure",
"ci:tests:unit": "@php \"./tools/phpunit.phar\"",
"composer:normalize": "@php \"./tools/composer-normalize\"",
"phive:update:phpunit": "echo y | \"./tools/phive\" --no-progress update phpunit",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only needed for the CI build server, so it's OK.

@JakeQZ JakeQZ merged commit d79c1ad into main Apr 9, 2021
@JakeQZ JakeQZ deleted the task/phar branch April 9, 2021 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants