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

Allow passing configure options without being a real file #235

Merged
merged 2 commits into from
Aug 17, 2021

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Jul 29, 2021

By removing the is_file check we allow installing extensions like this:

bin/pickle install --source \
    --with-configure-options <(echo --with-rdkafka=/opt/homebrew/opt/librdkafka) rdkafka

No more need to create a file with the options first 🎉

By removing the `is_file` check we allow installing extensions like this:

```bash
bin/pickle install --source --with-configure-options <(echo --with-rdkafka=/opt/homebrew/opt/librdkafka) rdkafka
```

No more need to create a file with the options first.
@pierrejoye
Copy link
Member

pierrejoye commented Jul 29, 2021 via email

@ruudk
Copy link
Contributor Author

ruudk commented Jul 29, 2021

@pierrejoye ?

@pierrejoye
Copy link
Member

pierrejoye commented Jul 29, 2021 via email

@ruudk
Copy link
Contributor Author

ruudk commented Jul 29, 2021

I remember something about console arguments and options using this as a norm

In Pickle? AFAIK there is no other way than configuration with --with-configure-options <file>.

So I would suggest to merge this, as it allows for a better UX.

@ruudk
Copy link
Contributor Author

ruudk commented Aug 16, 2021

Can this be merged?

@mlocati
Copy link
Collaborator

mlocati commented Aug 17, 2021

What about replacing

|| !is_file($force_opts)

with

|| !(is_file($force_opts) || is_link($force_opts))

instead of removing that check?

@ruudk
Copy link
Contributor Author

ruudk commented Aug 17, 2021

We can try, but why does this has to be so strict? If it's readable, it's fine, right? Otherwise an error will be thrown for something unexpected.

@mlocati
Copy link
Collaborator

mlocati commented Aug 17, 2021

PS:

$ php -r 'var_dump(is_file($argv[1]) || is_link($argv[1]));' .
bool(false)

$ php -r 'var_dump(is_file($argv[1]) || is_link($argv[1]));' <(echo 'this is a test')
bool(true)

@mlocati
Copy link
Collaborator

mlocati commented Aug 17, 2021

If it's readable, it's fine, right?

Because it may be a directory. Another alternative would be to replace || !is_file($force_opts) with || is_dir($force_opts)

@ruudk
Copy link
Contributor Author

ruudk commented Aug 17, 2021

@mlocati Applied your feedback :) Thanks!

@mlocati mlocati merged commit ea757d2 into FriendsOfPHP:master Aug 17, 2021
@ruudk ruudk deleted the allow-fd branch August 17, 2021 12:10
@ruudk
Copy link
Contributor Author

ruudk commented Aug 17, 2021

Thanks @mlocati 💙

@ruudk
Copy link
Contributor Author

ruudk commented Aug 17, 2021

I tried it out with 0.7.5 but it doesn't work anymore:

php var/pickle.phar install --dry-run --source --with-configure-options <(echo --with-rdkafka=/opt/homebrew/opt/librdkafka) rdkafka

@mlocati
Copy link
Collaborator

mlocati commented Aug 17, 2021

I tried it out with 0.7.5 but it doesn't work anymore:

What's the error? Is something like this one?

PHP Warning:  file_get_contents(/dev/fd/<number>):
failed to open stream: No such file or directory
in phar://.../pickle.phar/src/Base/Abstracts/Console/Command/BuildCommand.php on line 112

If so, the error should be fixed by #237

@mlocati
Copy link
Collaborator

mlocati commented Aug 17, 2021

@ruudk if you confirm the above error, I'd merge #237 and publish a new pickle version

@ruudk
Copy link
Contributor Author

ruudk commented Aug 17, 2021

@mlocati I'll test it now

@ruudk
Copy link
Contributor Author

ruudk commented Aug 17, 2021

Sorry for not posting the error immediately, that was my intention. This is what I get:

php var/pickle.phar install --dry-run --source --with-configure-options <(echo --with-rdkafka=/opt/homebrew/opt/librdkafka) rdkafka -vvv
warning: An error occurred while redirecting file '--with-rdkafka=/opt/homebrew/opt/librdkafka'
open: No such file or directory

@mlocati
Copy link
Collaborator

mlocati commented Aug 17, 2021

That's really strange... Here's what I have in an Ubuntu 20.04 with PHP 7.4:

$ curl -sSLf -o /tmp/pickle.phar https://github.com/FriendsOfPHP/pickle/releases/download/v0.7.5/pickle.phar
$ php /tmp/pickle.phar install --dry-run --source --with-configure-options <(echo --with-rdkafka=/opt/homebrew/opt/librdkafka) rdkafka -vvv
+-----------------------------------+---------+
| Package name                      | rdkafka |
| Package version (current release) | 5.0.0   |
| Package status                    | stable  |
+-----------------------------------+---------+
PHP Warning:  file_get_contents(/dev/fd/63): failed to open stream: No such file or directory in phar:///tmp/pickle/src/Base/Abstracts/Console/Command/BuildCommand.php on line 108

Warning: file_get_contents(/dev/fd/63): failed to open stream: No such file or directory in phar:///tmp/pickle/src/Base/Abstracts/Console/Command/BuildCommand.php on line 108

(and that error is fixed by #237)

What's your environment?

@ruudk
Copy link
Contributor Author

ruudk commented Aug 17, 2021

macOS Big Sur PHP 8.0

@mlocati
Copy link
Collaborator

mlocati commented Aug 17, 2021

@ruudk What do you have if you run this command in a terminal window?

php -r 'var_dump($argv);' <(echo ciao)

@ruudk
Copy link
Contributor Author

ruudk commented Aug 18, 2021

$ php -v
PHP 8.0.9 (cli) (built: Jul 29 2021 17:21:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies

$ php -r 'var_dump($argv);' <(echo ciao)
warning: An error occurred while redirecting file 'ciao'
open: No such file or directory

@mlocati
Copy link
Collaborator

mlocati commented Aug 18, 2021

$ php -r 'var_dump($argv);' <(echo ciao)
warning: An error occurred while redirecting file 'ciao'
open: No such file or directory

So, this is a problem of the mac, not of pickle...

@ruudk
Copy link
Contributor Author

ruudk commented Aug 18, 2021

I don't know how this suddenly happened because when I proposed the PR I obviously tested this and it worked.

@ruudk
Copy link
Contributor Author

ruudk commented Aug 18, 2021

Oke, the problem is with Fish Shell. It works properly in Bash:

bash-3.2$ php -r 'var_dump($argv);' <(echo ciao)
array(2) {
  [0]=>
  string(19) "Standard input code"
  [1]=>
  string(10) "/dev/fd/63"
}

@ruudk
Copy link
Contributor Author

ruudk commented Aug 18, 2021

When I try 0.7.5 in Bash I get:

$ pickle install --dry-run --source --with-configure-options <(echo --with-rdkafka=/opt/homebrew/opt/librdkafka) rdkafka
  - Installing rdkafka (latest-stable): Downloading (100%)
+-----------------------------------+---------+
| Package name                      | rdkafka |
| Package version (current release) | 5.0.0   |
| Package status                    | stable  |
+-----------------------------------+---------+

In BuildCommand.php line 105:

  File '/dev/fd/63' is unusable


@mlocati
Copy link
Collaborator

mlocati commented Aug 18, 2021

File '/dev/fd/63' is unusable

I have a different error:

file_get_contents(/dev/fd/65): failed to open stream: No such file or directory

Could you check if this works for you?

php -r 'var_dump(file_get_contents(str_replace("/dev/", "php://", $argv[1])));' <(echo ciao)

@ruudk
Copy link
Contributor Author

ruudk commented Aug 18, 2021

Yes!

bash-3.2$ php -r 'var_dump(file_get_contents(str_replace("/dev/", "php://", $argv[1])));' <(echo ciao)
string(5) "ciao
"
bash-3.2$

Also in Fish:

$ php -r 'var_dump(file_get_contents(str_replace("/dev/", "php://", $argv[1])));' (echo ciao | psub)
string(5) "ciao
"

@mlocati
Copy link
Collaborator

mlocati commented Aug 18, 2021

Great, thanks for confirming! So, #237 should fix the issue

@ruudk
Copy link
Contributor Author

ruudk commented Aug 18, 2021

Thanks for being so persistent in solving this 👏

@mlocati
Copy link
Collaborator

mlocati commented Aug 18, 2021

I've just published version 0.7.6 with the related patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants