Repository navigation
Open
Description
cabal list-bin returns the path of a executable in the current project matching a specified target. E.g.
λ cabal list-bin cabal
/home/andrea/code/cabal/master/dist-newstyle/build/x86_64-linux/ghc-9.6.4/cabal-install-3.11.0.0/x/cabal/build/cabal/cabal
The command accepts one and only one target:
λ cabal list-bin
Error: cabal: One target is required, none provided
λ cabal list-bin cabal unit-tests
Error: cabal: One target is required, given multiple
The funny thing is that all is effectively one target, so cabal list-bin all almost works ...
λ cabal list-bin all
Error: cabal: The list-bin command is for finding a single binary at once. The
target 'all' refers to all the packages in the project which includes the
executable 'cabal', the executable 'test-runtime-deps', the executable
'setup', the executable 'cabal-tests', the executable 'hackage-benchmark', the
test suite 'unit-tests', the test suite 'rpmvercmp', the test suite
'parser-tests', the test suite 'no-thunks-test', the test suite
'hackage-tests', the test suite 'custom-setup-tests', the test suite
'check-tests', the test suite 'cabal-benchmarks', the test suite 'unit-tests',
the test suite 'mem-use-tests', the test suite 'long-tests', the test suite
'integration-tests2', the test suite 'unit-tests' and the test suite
'unit-tests'.
Combinations like all:tests and all:exes give a similar result:
λ cabal list-bin all:tests
Error: cabal: The list-bin command is for finding a single binary at once. The
target 'all:tests' refers to all the test suites in the project which includes
the test suite 'unit-tests', the test suite 'rpmvercmp', the test suite
'parser-tests', the test suite 'no-thunks-test', the test suite
'hackage-tests', the test suite 'custom-setup-tests', the test suite
'check-tests', the test suite 'cabal-benchmarks', the test suite 'unit-tests',
the test suite 'mem-use-tests', the test suite 'long-tests', the test suite
'integration-tests2', the test suite 'unit-tests' and the test suite
'unit-tests'.
λ cabal list-bin all:exes
Error: cabal: The list-bin command is for finding a single binary at once. The
target 'all:exes' refers to all the executables in the project which includes
the executable 'cabal', the executable 'test-runtime-deps', the executable
'setup', the executable 'cabal-tests' and the executable 'hackage-benchmark'.
The error lists all the matching targets so we must have a way to iterate over them!
Reacted by fendor and Mouse
Activity
mpickering commentedon Feb 22, 2024
Isn't the point that
list-bingives either zero or one answers, because if it gives multiple answers then$(cabal list-bin ...)fails?Are you proposing that
list-binshould be allowed to return multiple results?philderbeast commentedon Feb 22, 2024
Stack has a similar command that returns multiple exes;
andreabedini commentedon Feb 23, 2024
This is a good point.
Perhaps under a different command? Perhaps
list-binslikecabal-plan?ulysses4ever commentedon Feb 23, 2024
Some discussion about this in
Not sure it's all that good of an idea judging by how often people ask for an ability to get a list out of it, and I'm yet to see people excited by this idea outside the old cabal team. I'd rather there was a flag that people would apply in scripting scenarios (e.g.
$(cabal list-bin --force-unique ...)) if they want today's strict behavior. A separate command altogether is also possible, perhaps, but feels a little like an overkill: it'd mostly duplicate the existinglist-bin; also it will take time to teach people to use it (the old subcommand should participate in that by issuing a suggesting to use the new one if there're multiple results).So, I'd prefer augmenting
list-bin. If we make this change, I don't think many things will fail because the scripting use cases that work today will probably work under the new version: after all, we're making it more lenient rather than more strict (which would break more).gbaz commentedon Feb 23, 2024
"I'm yet to see people excited by this idea outside the old cabal team" <- nobody's excited by this or asking for it because it already works, and was widely demanded, which is why the feature was implemented.
I think we can add an
--allflag tolist-binto get the new behavior, and put that in the error message as a suggestion. But the behavior should be opt-in rather than opt-out to not disrupt any existing uses.(Remember, existing uses always may be widespread but silent, and the only people who speak up are the ones who have new complaints -- the folks happy with how it works don't hang out on the tracker looking for tickets that might change thins for them!)
ulysses4ever commentedon Feb 23, 2024
My point is very simple: people who are happy with the current behavior will be just as happy with the new behavior because they probably rely on the happy parth rather than on the exceptional path.
But the opt-in strategy with a suggestion sounds fine too.
alt-romes commentedon Feb 26, 2024
Yes, let's please do opt-in.
--allsounds nice to me.philderbeast commentedon Feb 26, 2024
I find the command name confusing, a list command that returns one thing, the full path to an executable. What is the history there? Is it named after the
lsshell command (a command that takes [FILE] and has a default)?Could we please add a
cabal targetscommand before we change thecabal list-binbehaviour?philderbeast commentedon Feb 26, 2024
That's the
all:exes all:tests all:benchestarget form, isn't it?andreasabel commentedon Aug 1, 2024
I would also like
list-binto make it easier to discover targets forcabal run.Here is a record of my difficult conversation with
cabal: :-DThis conversation is definitely improvable.
cabal list-bincould already list the executables rather than slamming the door in my face with Cabal-7024cabal list-bin allshould print the targets in a form suitable forcabal run, and ideally as a bullet list rather than prosecabal testdoes not work butcabal run test:stmdoes remains mysterious to the end-user, but maybe this is orthogonal to the present issue here...Mikolaj commentedon Aug 1, 2024
@andreasabel: I'm confused: the https://hackage.haskell.org/package/stm-2.5.3.1/stm.cabal file only mentions a library. not exes nor tests. How come? Are you working in a larger project stm is a member package of?
Kleidukos commentedon Aug 1, 2024
I get the following non-helpful output from the maximal verbosity level:
andreasabel commentedon Aug 1, 2024
@Mikolaj wrote:
I was working on master which has a
testsuiteproject: https://github.com/haskell/stm/blob/cb861ea10065f229bbc5b6a1e2b9bde998f18184/testsuite/testsuite.cabalOh, this testsuite itself is named
stm, which explains part of my confusion.Seems like:
cabal runcan run any target referenced fromcabal.project.cabal testonly checks for testsuites in the root projectstm.cabal.fgaz commentedon Aug 1, 2024
This is because
cabal testdefaults to., notall. In your case.is thestmpackage. From https://cabal.readthedocs.io/en/stable/cabal-commands.html#cabal-test:In the biweekly call we agreed that
allwould be a less surprising default.ulysses4ever commentedon Aug 3, 2024
Is this PR doing anything helpful: #9744?
fix haskell#9714: list-bin with no targets finds all executables