You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cabal run/list-bin does not default to exe component for package targets #7403
Describe the bug
When a package test2 is vendored, cabal run test2 or cabal list-bin test2 will not default to exe components.
$ cabal run test2
cabal: The run command is for running a single executable at once. The target
'test2' refers to the package test2-0.1.0.0 which includes the executable
'test2' and the test suite 'test2-test'.
With cabal test test2 cabal will default to the correct component, however.
Expected behavior
cabal should pick exe components for run or list-bin, test components for test, etc. This already happens for non-vendored packages (see related #7335 )
System information
Reproduceable with cabal-install 3.2.0.0 and 3.4.0.0
changed the title [-]cabal-install does not default to the correct component for vendored packages[/-][+]`cabal run/list-bin` does not default to exe component for package targets[/+]on May 21, 2021
I think the behaviour (and the code AFAICT) of test, run and list-bin is the same in this case. It so happens, though, that the name of the executable section in your .cabal file matches the name of the package, while the name of the test section doesn't. I think package name shadows the executable name and hence the message. Do you think this a wrong behaviour?
First, the diagnostic is not particularly helpful:
[nix-shell:~/wobcom/projects/cabal-repro]$ cabal run test2
Resolving dependencies...
cabal: The run command is for running a single executable at once. The target
'test2' refers to the package test2-0.1.0.0 which includes the executable
'test2' and the test suite 'test2-test'.
The user is not informed what the problem is, or how to resolve it. Is this an ambiguity between the executable test2 and the test suite test2-test? It says "is for running [...] [an] executable", and then it says it even found one. To me it begs the question "You found a single executable. What's the problem?".
Vendoring packages
Next, it is not un-common to have a repository structure like this
Where cabal.project just vendors these three sub packages (maybe with a glob or explicitly)
This is particularly useful, if some of these packages depend on each other so you don't have to maintain a cabal.project for each sub-package to vendor the rest. So to build pkgA, you'd sit at repo/ and then issue commands like repo/ $ cabal run pkgA. But now you are forced to use cabal run pkgA:exe:that-component, if you have multiple vendored packages with single executables, this is quite an annoyance. We experience this annoyance every day on one of our internal projects.
What the user expects
I expect run and list-bin to pick an executable component whenever they can, and test a test-suite whenever it can.
Cabal even documents run to be intended for "single executables" and test for "test suites". Why not default to executable and test-suite components of the matching package target?
Proposed changes
run <target> - If cabal-install matches <target> to be a package name, see if contains it a single executable component, and then just run that. If multiple candidates exist, issue an ambiguity error and ask the user to resolve by specifying <target>:exe:<component_name>. If no executable component exists, complain about that.
test - Similar to run except with test-suite components.
list-bin- Similar to run
And all of these should work on whether it's another package, vendored or not.
Reacted by Francesco Gazzetta, Mikolaj Konarski, Dennis Gosnell and Emil Walser
I provided a simple implementation in #7408. Judging from the implementation, cabal test <package> will always build and run all enabled test suites, so that one needs no further attention.
If this is acceptable, I will change the documentation and then this can be merged.
One more thing I noticed. cabal list-bin without a target is not allowed, I think we should make it behave like cabal run, picking the package from the current directory as its target implicitly. Since this was not specified above, opinions? @Mikolaj@fgaz
I suspect that specific choice might have been deliberate, especially since list-bin is useful in scripts (=> it has to be robust => have the user be more explicit). @phadej may know more, as the author of the command
That argument makes sense, to warrant the user being explicit here.
On the other hand, it'd be nice if cabal list-bin <whatever-goes-here>
produced the path of the binary corresponding to cabal run <whatever-goes-here>
But that wishful thinking wouldn't work with cabal build <whatever-goes-here>
or cabal test <whatever-goes-here>
Because these support multiple targets.
So strange to have this discussion split in two streams.
How about we resume the discussion of whether to make list-bin accept an implicit package target in this issue here, while the PR discussion stays about just what's already submitted?
Here's my line of argumentation why I think list-bin should operate on an implicit package like run:
All three commands run, test and list-bin work on a single executable. Your target specifier must somehow be resolvable to a single exact executable that you probably meant.
So what component does a cabal list-bin user usually want? list-bin is a plumbing command with the primary purpose of being able to extract a build artifact, using something like cp $(cabal -v0 list-bin some-exe) destination, most likely in a build script/CI job. It seems obvious that the large portion of users wants to extract executable artifacts (as extracting test/benchmark artifacts seems less interesting to the average user).
Now, there is the following scenarios to consider:
The users cwd is inside a project pepper and wants to extract the single executable artifact mill. cabal list-bin would achieve the goal. Raised an error before, would select pepper:exe:mill now.
The users cwd is outside a project and contains multiple cabal packages pepper and salt. cabal list-bin would not match a component. Raised an error before, and would raise it again.
The users cwd is inside a project pepper and wants to extract the artifact from salt:exe:mill. cabal list-bin would do the unexpected thing. Raised an error before, would select pepper:exe:mill now (but not the intended salt:exe:mill)
The change would not affect any existing CI jobs, since we don't introduce additional error paths, but we lift some. Any user who tried to use cabal list-bin would have changed to specify an explicit target. These we do not need to worry about. What about future users? Here only 3) is of concern, as 1) is desirable, and 2) does not change the behavior.
Why is this the change in 3) unproblematic? For one, if your cwd is in a different package, cabal install and cabal test wouldn't have worked either, so the user would have already specified:
It's very unlikely any user would be specifying an exe/test component first, but be silent about what is passed to list-bin. And even if the user does, they would get rapid feedback that the wrong component was extracted.
This is offset by the benefit of increased coherence between the commands. This leads to less mental overhead for the users, when they have to re-study the target selection algorithm for each command they want to use, or get confused why cabal build works, cabal run works, cabal test works, but cabal list-bin does not. I'm saying this as a user who struggled for nearly 2 years with why cabal <cmd> <target> would break and have differing behavior depending on the choice of <cmd>.
@dminuoso's argument is convincing, but it's about backward compatibility, and while we definitely have to consider that too, my specific concern was a bit different.
I had in mind something like this:
the user writes in a script cabal list-bin p where p is a package with an exe a, so p refers to p:exe:a
(not possible currently)
the user adds a package q with an exe p and forgets to update the script
now the script points to q:exe:p!
BUT this is a contrived example, and
the reason why this happens would be immediately apparent
run behaves the same anyway and is probably also used in scripts and such
Activity
dminuoso commentedon May 21, 2021
I just realized, that this probably applies not just to vendored packages, but rather when the
targetis a package in general.cabal build test2also works and defaults to the exe component.[-]cabal-install does not default to the correct component for vendored packages[/-][+]`cabal run/list-bin` does not default to exe component for package targets[/+]dminuoso commentedon May 21, 2021
Related #7326
Mikolaj commentedon May 21, 2021
I think the behaviour (and the code AFAICT) of
test,runandlist-binis the same in this case. It so happens, though, that the name of the executable section in your .cabal file matches the name of the package, while the name of the test section doesn't. I think package name shadows the executable name and hence the message. Do you think this a wrong behaviour?dminuoso commentedon May 25, 2021
The diagnostic
First, the diagnostic is not particularly helpful:
The user is not informed what the problem is, or how to resolve it. Is this an ambiguity between the executable
test2and the test suitetest2-test? It says "is for running [...] [an] executable", and then it says it even found one. To me it begs the question "You found a single executable. What's the problem?".Vendoring packages
Next, it is not un-common to have a repository structure like this
Where cabal.project just vendors these three sub packages (maybe with a glob or explicitly)
This is particularly useful, if some of these packages depend on each other so you don't have to maintain a cabal.project for each sub-package to vendor the rest. So to build pkgA, you'd sit at
repo/and then issue commands likerepo/ $ cabal run pkgA. But now you are forced to usecabal run pkgA:exe:that-component, if you have multiple vendored packages with single executables, this is quite an annoyance. We experience this annoyance every day on one of our internal projects.What the user expects
I expect
runandlist-binto pick an executable component whenever they can, andtesta test-suite whenever it can.Cabal even documents
runto be intended for "single executables" andtestfor "test suites". Why not default to executable and test-suite components of the matching package target?Proposed changes
run <target>- If cabal-install matches<target>to be a package name, see if contains it a single executable component, and then just run that. If multiple candidates exist, issue an ambiguity error and ask the user to resolve by specifying<target>:exe:<component_name>. If no executable component exists, complain about that.test- Similar torunexcept with test-suite components.list-bin- Similar torunAnd all of these should work on whether it's another package, vendored or not.
Mikolaj commentedon May 25, 2021
Fine analysis. We'd need one more voice to finalize the specification but, in principle, the work could start already. @emilypi, @fgaz, others?
Set exe as default component for `cabal run` and `cabal list-bin`
Set exe as default component run and list-bin
dminuoso commentedon May 25, 2021
I provided a simple implementation in #7408. Judging from the implementation,
cabal test <package>will always build and run all enabled test suites, so that one needs no further attention.If this is acceptable, I will change the documentation and then this can be merged.
Mikolaj commentedon May 26, 2021
Amazing. Let's move the discussion to the PR.
fgaz commentedon May 26, 2021
The specification looks fine to me! Running
cabal run some-testwould still work as this is only for package targets, right?dminuoso commentedon May 27, 2021
@fgaz Yes. The modification applies only when the target refers to a package.
dminuoso commentedon May 27, 2021
One more thing I noticed.
cabal list-binwithout a target is not allowed, I think we should make it behave likecabal run, picking the package from the current directory as its target implicitly. Since this was not specified above, opinions? @Mikolaj @fgazfgaz commentedon May 27, 2021
I suspect that specific choice might have been deliberate, especially since list-bin is useful in scripts (=> it has to be robust => have the user be more explicit). @phadej may know more, as the author of the command
dminuoso commentedon May 28, 2021
That argument makes sense, to warrant the user being explicit here.
On the other hand, it'd be nice if
cabal list-bin <whatever-goes-here>produced the path of the binary corresponding to
cabal run <whatever-goes-here>But that wishful thinking wouldn't work with
cabal build <whatever-goes-here>or
cabal test <whatever-goes-here>Because these support multiple targets.
Mikolaj commentedon Jun 1, 2021
@phadej, could you weigh in? :)
Mikolaj commentedon Jun 8, 2021
Please see the PR for a continuation (conclusion?) of the discussion.
Edit: Let's not, let's stick here as @dminuoso proposes.
dminuoso commentedon Jun 8, 2021
So strange to have this discussion split in two streams.
How about we resume the discussion of whether to make
list-binaccept an implicit package target in this issue here, while the PR discussion stays about just what's already submitted?Here's my line of argumentation why I think
list-binshould operate on an implicit package like run:All three commands
run,testandlist-binwork on a single executable. Your target specifier must somehow be resolvable to a single exact executable that you probably meant.So what component does a
cabal list-binuser usually want? list-bin is a plumbing command with the primary purpose of being able to extract a build artifact, using something likecp $(cabal -v0 list-bin some-exe) destination, most likely in a build script/CI job. It seems obvious that the large portion of users wants to extract executable artifacts (as extracting test/benchmark artifacts seems less interesting to the average user).Now, there is the following scenarios to consider:
pepperand wants to extract the single executable artifactmill.cabal list-binwould achieve the goal. Raised an error before, would selectpepper:exe:millnow.pepperandsalt.cabal list-binwould not match a component. Raised an error before, and would raise it again.pepperand wants to extract the artifact fromsalt:exe:mill.cabal list-binwould do the unexpected thing. Raised an error before, would selectpepper:exe:millnow (but not the intendedsalt:exe:mill)The change would not affect any existing CI jobs, since we don't introduce additional error paths, but we lift some. Any user who tried to use
cabal list-binwould have changed to specify an explicit target. These we do not need to worry about. What about future users? Here only 3) is of concern, as 1) is desirable, and 2) does not change the behavior.Why is this the change in 3) unproblematic? For one, if your cwd is in a different package,
cabal installandcabal testwouldn't have worked either, so the user would have already specified:It's very unlikely any user would be specifying an exe/test component first, but be silent about what is passed to
list-bin. And even if the user does, they would get rapid feedback that the wrong component was extracted.This is offset by the benefit of increased coherence between the commands. This leads to less mental overhead for the users, when they have to re-study the target selection algorithm for each command they want to use, or get confused why
cabal buildworks,cabal runworks,cabal testworks, butcabal list-bindoes not. I'm saying this as a user who struggled for nearly 2 years with whycabal <cmd> <target>would break and have differing behavior depending on the choice of<cmd>.How do you feel about this?
Mikolaj commentedon Jun 8, 2021
I'm swayed, but have no strong opinion,
Mikolaj commentedon Jun 12, 2021
@fgaz: would you weight in?
fgaz commentedon Jun 22, 2021
@dminuoso's argument is convincing, but it's about backward compatibility, and while we definitely have to consider that too, my specific concern was a bit different.
I had in mind something like this:
cabal list-bin pwherepis a package with an exea, soprefers top:exe:aqwith an exepand forgets to update the scriptq:exe:p!BUT this is a contrived example, and
runbehaves the same anyway and is probably also used in scripts and suchso unless someone else objects i'd be okay with it
Mikolaj commentedon Jul 16, 2021
@dminuoso: what's your take on that? Are we unblocked?
Set exe as default component run and list-bin
Set exe as default component run and list-bin