Repository navigation
Reduce duplication in CmdRun - #4607
Conversation
| -- ^ A function that selects a subset of the plan and returns it, | ||
| -- It can also return some arbitrary data, which can be useful in case | ||
| -- the caller needs it. | ||
| -> (ElaboratedInstallPlan -> IO (ElaboratedInstallPlan, a)) |
There was a problem hiding this comment.
Why do you need polymorphism here if you're only ever using this value in monomorphic context -- it's either ignored (()) or (UnitId, ComponentId)? IMO it makes more sense to stick a (UnitId, ComponentId) member into the ProjectBuildStatus record.
There was a problem hiding this comment.
I don't have a strong preference on "return directly" vs. "stuff it in the ProjectBuildStatus", but for polymorphic vs. monomorphic, the polymorphic version is nice for forward-compatibility, e.g. if future consumers want some other information out of the pre-build phase target selection process.
If we stick with "return directly", perhaps there should be, like, a runProjectPreBuildPhase_ f = fst <$> runProjectPreBuildPhase (\x -> (f x, ()) or something like that which has the old type. Then existing uses would be a bit less noisy.
There was a problem hiding this comment.
Well, if I add another field it has to be Maybe (UnitId, ComponentId) or equivalent, because that record is used in other commands too. But then I'd have to unwrap that Maybe and rely on the assumption that I set it to Just in preBuild.
There was a problem hiding this comment.
Oh, right, a wrapper.
Then the only question is whether to add the _ to the wrapper or the wrapped. In base it's the wrapper I think
There was a problem hiding this comment.
I'm wary of over-abstracting the code prematurely for the sake of future consumers that may never materialise. If they do, refactoring is easy in Haskell. Existing type is nice because there's only one place you need to look at to see the data that's produced in the pre-build step.
But then I'd have to unwrap that
Maybeand rely on the assumption that I set it toJustin preBuild.
That's okay IMO, just make it a fatal error if you get Nothing.
There was a problem hiding this comment.
BTW, it probably makes sense to you to tackle new-bench and new-test (i.e. #3638) after this.
There was a problem hiding this comment.
Isn't new-test already done, according to that issue (also, it works for me)?
Or we have to redo it, since the current one relies on the "old" Setup, as most of the new-commands do (I think. They seem to do so.)?
new-ench builds but does not run the benchmark, same as run before my pr.
There was a problem hiding this comment.
Sorry, you're right, new-test is implemented using the setup wrapper because it needs to run hooks and we have a test command in the setup interface. new-bench can have custom hooks attached too and should also work this way.
new-test seems to be confused by non-trivial project structure, though, so it still makes sense to look at it:
~/code/haskell/cabal[master]$ cabal new-test
cabal: No targets given and there is no package in the current directory. Use
the target 'all' for all packages in the project or specify packages or
components by name or location. See 'cabal build --help' for more details on
target options.
~/code/haskell/cabal[master]$ cabal new-test cabal-install
cabal: Cannot test the package cabal-install-2.1.0.0 because none of the
components are available to build: the test suite 'unit-tests', the test suite
'solver-quickcheck', the test suite 'memory-usage-tests' and the test suite
'integration-tests2' are all marked as 'buildable: False'
~/code/haskell/cabal[master]$ cabal new-test cabal-install:unit-tests
cabal: Cannot run the test suite 'unit-tests' because it is marked as
'buildable: False' within the 'cabal-install.cabal' file (at least for the
current configuration). If you believe it should be buildable then check the
.cabal file to see if the buildable property is conditional on flags.
Alternatively you may simply have to edit the .cabal file to declare it as
buildable and fix any resulting build problems.
~/code/haskell/cabal[master]$ cabal new-test cabal-install:unit-tests --enable-tests
cabal: Cannot run the test suite 'unit-tests' because it is marked as
'buildable: False' within the 'cabal-install.cabal' file (at least for the
current configuration). If you believe it should be buildable then check the
.cabal file to see if the buildable property is conditional on flags.
Alternatively you may simply have to edit the .cabal file to declare it as
buildable and fix any resulting build problems.
~/code/haskell/cabal[master]$ cabal new-configure --enable-tests
'cabal.project.local' file already exists. Now overwriting it.
In order, the following would be built (use -v for more details):
Assertion failed
CallStack (from HasCallStack):
assert, called at ./Distribution/Client/ProjectPlanning.hs:280:5 in main:Distribution.Client.ProjectPlanning
There was a problem hiding this comment.
Anyhow, I still think that sticking TargetMap into ProjectBuildContext makes sense.
There was a problem hiding this comment.
Hmm, so I'll fall back to the one-element assumption, but at least there isn't much duplication now.
I still think the polymorphic solution is cleaner-ish, but I'll proceed with your solution if the others don't chime in in a couple of days
df5b7c2 to
4bccd3e
Compare
|
Hey @fgaz, do you need me to look at this commit? It looks like a bunch of people commented already and I don't want to pile on. Let me know. |
|
Let me preface this by saying, it doesn't matter, ship something and be willing to refactor it later if it needs to be done differently. That being said, let me be philosophical for a moment. The crux of the problem is that the logical interpretation of I think the approach which is most faithful to the original intent of the code is to refine |
|
Needs to be rebased. |
Previously, the extraction of the target from the targetStrings was done twice: inside the function passed to 'runProjectPreBuildPhase' and right after it. Now 'runProjectPreBuildPhase' is able to return information from that function, and the duplication was removed, along with some assumptions about the number of targets.
863be56 to
484bb6c
Compare
Return a monomorphic TargetsMap from selectPlanSubset and put it in the final ProjectBuildContext. This causes slight duplication in CmdRun.hs, but not as bas as when we didn't return anything. In exchange, the final return type is much simpler. Note that CmdConfigure returns an empty TargetsMap, as configure doesn't accept targets.
|
I'm going to merge once it's green |
80c698e to
8ede238
Compare
|
@fgaz Thanks! Very nice to be able to use |
followup of #4586
Previously, the extraction of the target from the targetStrings was done
twice: inside the function passed to 'runProjectPreBuildPhase' and right
after it.
Now 'runProjectPreBuildPhase' is able to return information from that
function, and the duplication was removed, along with some assumptions
about the number of targets.
This is one of the possible approaches, the other being adding a field in ProjectBuildContext.
The only way to avoid a Maybe or a sum type in said field, is parameterizing it.
Which has the advantage of not having to modify all the Cmd*.hs files and passing
()s everywhere, but after some thinking I like the first solution the best.