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

With 0.16 getting "The executable for "composer" could not be found" during composer task #671

Closed
jaydiablo opened this issue Sep 9, 2019 · 10 comments

Comments

@jaydiablo
Copy link

Q A
Version 0.16.0
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets

Seems that composer executable can't be found by 0.16 (this worked fine in 0.15), so when executing the composer task in grumphp, an error message is shown.

My configuration

# grumphp.yml
parameters:
    tasks:
        composer:
            strict: true
        composer_require_checker: ~
        phpcsfixer2:
            allow_risky: true
            config: .php_cs
        phpstan:
            level: 7
            configuration: phpstan.neon
        phpunit:
            metadata:
                priority: 100
            always_execute: true

Steps to reproduce:

git clone [email protected]:diablomedia/zf1-acl.git
git checkout dependabot/composer/phpro/grumphp-tw-0.14.0or-tw-0.16.0
composer update

# Your actions
./vendor/bin/grumphp run

Result:

GrumPHP is sniffing your code!
Running task 1/5: Phpunit... ✔
Running task 2/5: Composer... ✘
Running task 3/5: ComposerRequireChecker... ✔
Running task 4/5: PhpCsFixerV2... ✔
Running task 5/5: PhpStan... ✔
             ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
           ▄▄▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
         ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄
        ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
       ▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
  ▄███▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 █▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
 ▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
   ▀█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▌
     ▀▀▓▓▓▓▓▓▓▓▓▓▓▓█▀▀▀▀▀▀▀▀▀▀▀▀▀▀████████████▄
      ▄███████                       ██████████
     ███████▀  ▀▀▀▀▀▄      ▄▀▀▀▀▀     █████ ▀
      ▐████      ▐██        ▐██        ████▌
      ████▌                            ███
       ▌██▌           ▄▄ ▄▄           ▐███
        ███       ▄▄▄▄▄▄▄▄▄▄▄▄       ▐███
         ██▄ ▐███████████████████████████
        █▀███████████▀     ▀▀███████████
          ██████████▄███████▄███████████
         ▐█████████████████████████████
          █████████████████████████████
           ██ █████████████████████▐██▀
            ▀ ▐███████████████████▌ ▐▀
                ████▀████████▀▐███
                 ▀█▌  ▐█████  ██▌
                        ██▀   ▐▀

       ██████████████████████████████████
       █░░░░░░▀█▀░░░░░░▀█░░░░░░▀█▀░░░░░▀█
       █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█
       █░░▐█▌░░█░░░██░░░█░░██░░░█░░░██░░█
       █░░▐█▌░░█░░░██░░░█░░░░░░▄█░░▄▄▄▄▄█
       █░░▐█▌░░█░░░██░░░█░░░░████░░░░░░░█
       █░░░█░░░█▄░░░░░░▄█░░░░████▄░░░░░▄█
       ██████████████████████████████████

The executable for "composer" could not be found.

Downgrading this particular repo to 0.15 doesn't have the issue.

Composer is installed globally on this system in /usr/local/bin/composer.phar and then aliased to composer in .bash_profile file.

@veewee
Copy link
Contributor

veewee commented Sep 9, 2019

Thanks for reporting @jaydiablo,

I am not sure why it worked in previous release.
Can you paste me what the alias looks like?

The \Symfony\Component\Process\ExecutableFinder searches your PATH variable to check if it can find composer.
Since it doesn't contain .phar as a suffix, it can't find it in /usr/local/bin/composer.phar.
Is there any other location in which there is another composer executable?

Feel free to provide me additional information on the issue.

@jyggen
Copy link
Contributor

jyggen commented Sep 9, 2019

Possibly caused by #556?

@jaydiablo
Copy link
Author

This is the alias line in .bash_profile (this is on a macOS system):

alias composer="php /usr/local/bin/composer.phar"

I don't recall why it was installed this way (the official composer instructions seem to suggest naming the file composer when moving the composer.phar file to its location in the PATH. I haven't tried installing composer using the official installer (https://getcomposer.org/installer), at least not in recent memory, but I could try that and see if it does the aliasing.

@jyggen I suspect that could be the case as well. I'm not terribly familiar with the ExecutableFinder, but I suspect that it probably looks in the ./vendor/bin directory for executables, and with composer moved to a dev dependency, it's probably not there anymore.

@veewee
Copy link
Contributor

veewee commented Sep 9, 2019

A yes, that's probably it. That one installed composer in vendor/bin as well. Thanks @jyggen!

I'm thinking of adding the phar suffix to the list of executables. That will fix this particular issue as well and might make sense.

A temporary solution is to link, copy or move the phar to /usr/local/bin. Is there any reason why you are using the alias solution at the moment?

Edit: looks like you already answered most of the questions above ;)

@jaydiablo
Copy link
Author

@veewee I don't recall why composer was installed this way, perhaps that was the recommended way when it was originally installed. I just tried the installer from the link I posted above, and all it does is download the phar file to the directory that it is run from.

I've moved the phar file to just /usr/local/bin/composer and that does fix the issue.

@rjwebdev
Copy link

rjwebdev commented Sep 16, 2019

I'm facing same issues but with phpstan and phpcpd. They are installed in a subfolder of my git dir and this is my config:

parameters:
    git_dir: .
    bin_dir: ./htdocs/vendor/bin/

I also use phpcsfixer 2, which works fine but these don't.

And if I check the bin folder, I see the executables:
image

I downgraded to grumphp version 0.15.2 and error doesn't show up.

@veewee
Copy link
Contributor

veewee commented Sep 16, 2019

Hi @rjwebdev,

Thanks for reporting!

That is actually another case: You are using 2 separate bin dirs.
GrumPHP is able to find the regular vendor/bin executables, but not the other directory.

It indeed worked in previous version, but rather by accident than by design.

Can you give me more information about why those are in a separate folder?
Wouldn't it make sense to add them to composer as well (since they are very likely tools everybody who is working on the project requires)?
If they do need to be in a separate place : Would it be an acceptable solution to add the htdocs/vendor/bin/ to your env PATH variable?

Edit
Actually: when you use the GRUMPHP_BIN_DIR env variable, this should work in the same way as it did with bin_dir. So there are 2 options:

  • Either set GRUMPHP_BIN_DIR
  • Or set PATH (if you want to support even more bin dirs)

https://github.com/phpro/grumphp/blob/master/doc/installation/exotic.md
(The last option could be added in there as well)

@rjwebdev
Copy link

Hello @veewee ,

Thanks for your answers! Our code is in the htdocs folder because this is the way of working at our firm. I'll give it a try by adding the path to my PATH variable and also by setting it as a env variable.

I'll keep you posted about the result!

@rjwebdev
Copy link

Hello @veewee,

Binaries were indeed found by setting the PATH correctly (apparently, the wrong file was used) but then we found out that the wrong path was set in the created git hook files where the commands should be executed. I opened a PR to fix this when the grumphp location name contains the name of the project dir.

@veewee
Copy link
Contributor

veewee commented Sep 17, 2019

I fixed the phar issue and added documentation about the PATH var.
You can test it out and discuss it in the PR above.

Lets continue the invalid path in the git hook inside the PR you opened.

@veewee veewee closed this as completed Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants