-
Notifications
You must be signed in to change notification settings - Fork 698
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
Unnecessarily difficult to run executables from outside of project #7940
Comments
Hi, it would not invalidate the issue for other use cases (several modules?) but could not you take ride of the .cabal file and use only |
Could you try with #7749 applied? That's a known bug |
|
Me too. I am experiencing the hardship of the OP when migrating a tool from cabal v1 (which has a fixed location for the produced executable) to v2 (which makes it difficult to locate the produced executable and thus suggests I support the proposal for a |
Why isn't --project-file enough? |
Because there might not be a project file. |
I've implemented option one in PR #8454 Please feel free to discuss/bikeshed in the PR. |
Could I ask for help reviewing the PR fixing this issue (#8454)? Even a cursory look and a comment whether this might fix your use case (bonus points for checking out and confirming) would be very much appreciated. |
A new proposal dropped at #8454. Could you kindly voice your opinion? |
#8454 does not seem to implement So then let us considered this issue resolved in 3.12. |
Describe the bug
One thing that I have noticed holding me back from using Haskell in script-like applications is the difficulty of using Cabal-packaged executables from a working directory outside of the project where they live.
For instance, consider that I have a simple single-file Haskell executable,
Frobble.hs
with no dependencies. I can run this program using withrunghc /path/to/frobble/Frobble.hs
from any directory that I please. If I want I can even justchmod +x
the source file and add an appropriate hash-bang. All is well with the world.Then one day I want to add a dependency to a Hackage package. Being a good
cabal-install
user, I create afrobble.cabal
with anexecutable frobble
stanza. However, I have now lost any ability to conveniently run my program from outside of the directory containing the.cabal
file. As far as I know, my only options are:$(cd /path/to/frobble; cabal build frobble >&/dev/null; cabal list-bin frobble)
cabal run
's hash-bang support, requiring that I duplicate mybuild-depends
in my.cabal
file as well asFrobble.hs
There are also a few non-solutions that I have encountered:
--cabal-file=/path/to/frobble/frobble.cabal
flag, which seems not to work at all from outside the project directory--project-file=/path/to/frobble/cabal.project
flag, which also does not workSurely we can do better than this.
Proposed feature
One can think of many possible designs to address this UX shortcoming but these seem the most plausible:
cabal run
to accept a--directory=...
flag, tellingcabal
to pretend it was run from the given directory. This would address the above use-case withcabal run --directory=/path/to/frobble run
#!/usr/bin/env cabal
hash-bang in a source file without providing a{- cabal run: ... -}
comment. In this case cabal would look for a.cabal
file in the current directory and use theexecutable
stanza with amain-is:
matching the name of the invoked source file{- cabal run: ... -}
block to allow the user to specify the name of the executable stanza to use (as well as, possibly, the relative path of the cabal file?)The text was updated successfully, but these errors were encountered: