-
Notifications
You must be signed in to change notification settings - Fork 476
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
Cross platform shebangs by special-casing #!/usr/bin/env
on Windows
#1549
Comments
@cspotcode something like this following should take care of things. 😉 shebang := if os() == 'windows' {
'python'
} else {
'/usr/bin/env python3'
}
recipe:
#!{{shebang}}
# Script code goes here |
I did that, but it's still error-prone. If the variable includes the |
Note that the |
Do we think the |
@cspotcode There are a few ways to interpret what you said as I'm not sure if you're referring to how Just manages shebangs at all on Windows or that having a shebang start with |
The idea is that common devtools are often available on PATH but at a path that may vary or be onerous to add to a shebang. For example, on my Linux box:
The practical solution here, acknowledging that it's not part of an original UNIX spec, is We can add logic to When This means that users writing a well-known and well-understood shebang of the form |
I always thought having to specify the exact path to the "interpreter" was lame in the shebang spec. It being an option was completely reasonable but required is just problematic. I believe I've already proposed to @casey to have how shebang is handled on Windows also work for other operating systems. I forget where he landed on that exactly at the moment. But I'd prefer that to Just ignoring |
When users rely on cygpath to convert |
Hm, |
That's my thinking as well. -S allows passing args, so I see that one used in the wild a fair bit. I was playing around with writing a PR for this. It's predicated on the assumption that Windows users never actually care that they're invoking cygwin's |
Thanks for opening this issue, and sorry for not responding here! I definitely agree that there's a problem here, but I think I'm on balance against special-casing
|
Taken from here: casey/just#1549 (comment)
Just ran into this myself and took a lot of searching to find the solution given here (#1549 (comment)). While it's inelegant, it does work. I would strongly recommend listing it somewhere in the Docs until a "proper" solution is added to just. I think enough people write cross platform recipes to warrant its inclusion in the docs. |
I thought an example like mine was in the docs for some time. Maybe it was removed due to some redundancy in the docs at the time. @casey do you know anything about that example? I think you wrote the one that ended up in the docs, no? |
I can't figure out how to write a cross-platform
python
ornode
shebang recipe.#!python
works on Windows, and#!/usr/bin/env python
works on Linux. But what works on both?On Linux we can write a reliable shebang using:
#!/usr/bin/env bash
or#!/usr/bin/env python3
It is expected that
/usr/bin/env
will always exist at that path, and it will look up the positional argument on your$PATH
and call it.I'm proposing that just can safely special-case this
/usr/bin/env
prefix on Windows to behave the same: look up the positional argument on your $PATH and execute it. Essentially, on Windows,#!/usr/bin/env whatever
will be handled the way it handles#!whatever
today.I can't think of a situation where it is desirable for
/usr/bin/env
to either do something else on Windows, or to fail with an error. So I don't think special-casing will break anyone's use-case.The text was updated successfully, but these errors were encountered: