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

cabal new-run foo should default to exe:foo (same for test and bench) #4676

Closed
nomeata opened this issue Aug 7, 2017 · 7 comments
Closed

Comments

@nomeata
Copy link
Contributor

nomeata commented Aug 7, 2017

If I have a project foo.cabal that defines both a library and an executable named foo, which is a common situation, then currently

$ cabal new-run foo -- some args

complains that it does not know whether I want to run foo the library or foo the executable, and makes me write

$ cabal new-run exe:foo -- some args

I see how this behavior makes sense for cabal new-build etc, but I do not even know what it means to cabal new-run a library. And even if that makes sense, I believe the ambiguity should just be resolved to the executable by default.

@23Skidoo 23Skidoo added this to the 2.2 milestone Aug 8, 2017
@23Skidoo
Copy link
Member

23Skidoo commented Aug 8, 2017

@fgaz, can you take a look at this? I think that old-run doesn't have this problem.

@fgaz
Copy link
Member

fgaz commented Aug 8, 2017

Yup, old cabal works. cabal new-run without an explicit target also works.

@fgaz
Copy link
Member

fgaz commented Aug 8, 2017

The problem is that the target resolution happens before any new-run code.

The Distribution.Client.TargetSelector:matchTargetSelector function isn't aware of the command and can't filter the targets depending on it.

If no explicit targets are specified, that function doesn't get called at all because, up in the call stack, resolveTargetSelectors matches on [] and returns TargetImplicitCwd which then can be filtered by CmdRun.hs.

If we want to fix this we probably want to pass the action directly to readTargetSelectors in every Cmd*.hs. But then what do we pass? A TargetAction? Then we'll have to add a RunAction and do some refactoring. Another action type?

Or maybe we should pass a filtering function like we do in runProjectPreBuildPhase.

@ezyang
Copy link
Contributor

ezyang commented Aug 9, 2017

My suggestion is to add another parameter, but don't try very hard to make it general. Like it could just be data WhichTargets = AllTargets | ExeTargets. If you figure out there's a better thing to do later we can refactor again.

@hvr
Copy link
Member

hvr commented Aug 9, 2017

Does the same issue occur for new-test and new-bench?

@fgaz
Copy link
Member

fgaz commented Aug 9, 2017

Yes. All new-* commands have this issue

@fgaz fgaz changed the title cabal new-run foo should default to exe:foo cabal new-run foo should default to exe:foo (same for test and bench) Aug 9, 2017
@fgaz fgaz removed their assignment May 29, 2018
@fgaz fgaz modified the milestones: 2.2, 3.0 May 29, 2018
@fgaz
Copy link
Member

fgaz commented Jun 22, 2018

@ezyang as per #4602 (comment), this probably needs a general solution now

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

No branches or pull requests

5 participants