-
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
Refactor CmdInstall / fix bug in #9697 #9706
Conversation
edf950b
to
ffe8d2c
Compare
Nice! I'll look through this in a moment. However, I'm concerned about moving the #9697 fix to I'm very fairly certain both cabal install situations need the fix |
Yes, I am happy to do that (and was indeed wondering ...) I would need to unpack the logic a bit more but if you know what to do please shoot! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR in general looks good to me, but the local configuration must be applied to the install target regardless of whether there is a project or not.
I think the right thing to do here is pass an empty list of package names to targetPkgNames
when there is no project (it is not a hack, there simply won't be any packages to install if a target such as "all" is used), and when there is a project use the list of packages from the base context.
@andreabedini can I leave fixing this regression up to you via this MR in its finished state, or should I put up a patch that simply fixes the regression faster? FWIW I'm happy to wait for this small refactor instead of fixing it standalone. |
ffe8d2c
to
4de55c1
Compare
I added both "with project" and "without project" cases. Note that in both cases I am taking the names from the target selectors (along with the project packages specifiers in the "with project" case). I think this is correct if we want to add local configuration to the packages that the user asks for. Unless we want to apply the local configuration just like
Would you expect (It might be a good idea to do what cabal build would do, but then why are we going through sdists in the first place?) |
Thanks!
I think this is exactly the right behaviour, we apply the local configuration to the targets (not the local packages).
So, no. Thanks again! |
Ok, in this case I think this is ready 👍 |
4de55c1
to
e0ee667
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, thanks for fixing this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is much better in general. Left a few comments.
(specs, selectors) <- | ||
-- if every selector is already resolved as a packageid, return without further parsing. | ||
if null unresolvedTargetStrings | ||
then return (parsedSpecifiers, parsedTargets) | ||
else do | ||
(resolvedSpecifiers, resolvedTargets) <- | ||
resolveTargetSelectorsInProjectBaseContext verbosity baseCtx targetStrings targetFilter | ||
return (resolvedSpecifiers ++ parsedSpecifiers, resolvedTargets ++ parsedTargets) | ||
|
||
-- Treat all direct targets of install command as local packages, see note in 'installAction' | ||
let config = | ||
addLocalConfigToPkgs (projectConfig baseCtx) $ | ||
concatMap (targetPkgNames $ localPackages baseCtx) selectors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer pass specs
to addLocalConfigToPkgs
, why so? Could you remind me what the specs
here are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a target string had to be resolved inside the project conterxt, then pkgSpecs will include the project packages turned into source distributions. We want to apply the local configuration only to the actual targets. This was basically what prompted me to clarify the behaviour we wanted. I'll add this as a note.
(uris, packageSpecifiers) = partitionEithers $ map woPackageSpecifiers tss | ||
packageTargets = map woPackageTargets tss | ||
|
||
-- Treat all direct targets of install command as local packages, see note in 'installAction' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- Treat all direct targets of install command as local packages, see note in 'installAction' | |
-- Apply the local configuration (e.g. cli flags) to all direct targets of install command, see note in 'installAction' |
Has the documentation been already updated? |
Which documentation do you mean? |
We should make sure this lands asap. The bug it fixes starts hitting people who try to test drive cabal-head (which more and more people are doing, it looks like). |
Can we have a test that something elementary like |
Adding some comments and fixing a typo. It will be ready soon. w.r.t to tests, there is the one in #9707 but it would be better if we had one in a project context too. |
4d55140
to
656d06b
Compare
Thanks Andrea, that’s perfect. @mpickering is working on a test for this. I think we go ahead and merge it in the meanwhile. IIRC there are some difficulties in the test suite to set up a test like this, so Matthew is also fixing that first. |
CmdInstall.installAction is ~300 lines long and full of nested scopes and ad-hoc logic. This change hopes to make it more readable and understandable. - Lift withProject and withoutProject out of installAction and split their relative concerns. E.g. not parsing URIs is installAction's concern not withProject's (which would just return a constant []). - Split an intermediate step into a separate function, resolveTargetSelectorsInProjectBaseContext. - Reuse withGlobalConfig and specFromPkgId (renamed from pidPackageSpecifiers). - Avoid trying withProject a second time in case no target is specified. - Fix a bug introduced in 802a326 where establishProjectBaseContext is called in a non-project setting. Also simplify its original implementation by moving the change into withProject rather than calling establishProjectBaseContext a second time. - Document the interaction between cabal v2-install and local configuration and add few comments.
656d06b
to
7b1746f
Compare
Before this PR, when running
and that was it. Adding After this PR, the same
|
I am going to look at this tomorrow (and thank you for testing!) |
@tomsmeding I am afraid I cannot reproduce. I am in a directory with a cabal file.
and I get (with and without
This is the same beaviour as the current release:
|
Well, there is a reason. As we decided to honour project configuration in
That would be a bug! Do you have a minimal reproducible example I can try? |
eep, i just realized that #9697 means we apply cabal.project configuration to This is to say that But if course we want to allow flags to affect the result of install -- which was the initial thing we set out to fix, no? |
@gbaz I've clarified and replied to that comment on #9697 (comment) |
@andreabedini Here is https://paste.tomsmeding.com/VQiFSDpi/raw/1 Notes:
It looks like my (1.) (different error message for I have not |
@tomsmeding Could you please open a separate issue if this is still a problem? (and if you haven't already) |
CmdInstall.installAction is ~300 lines long and full of nested scopes and ad-hoc logic. This change hopes to make it more readable and understandable.
Please read Github PR Conventions and then fill in one of these two templates.
Template Α: This PR modifies
cabal
behaviourInclude the following checklist in your PR:
Template Β: This PR does not modify
cabal
behaviour (documentation, tests, refactoring, etc.)Include the following checklist in your PR: