-
Notifications
You must be signed in to change notification settings - Fork 846
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
Add --cabal-install
#2995
Add --cabal-install
#2995
Conversation
src/Stack/Setup.hs
Outdated
@@ -140,6 +140,8 @@ data SetupOpts = SetupOpts | |||
, soptsUpgradeCabal :: !Bool | |||
-- ^ Upgrade the global Cabal library in the database to the newest | |||
-- version. Only works reliably with a stack-managed installation. | |||
, soptsInstallCabal :: !(Maybe Version) | |||
-- ^ Install a specific version of Cabal. |
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.
Can you fuse the soptsUpgradeCabal
and soptsInstallCabal
fields into one? This should make it impossible to have nonsensical states where soptsUpgradeCabal == True
and soptsInstallCabal == Just <x>
.
Maybe it would even be good to avoid the additional --install-cabal
flag and only add an optional argument to --upgrade-cabal
?! That would help combating CLI inflation :). Not sure if it's possible with optparse-applicative though…
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.
This sounds like a good idea. I haven't seen an 'optional argument' but will have a look and see what is possible.
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.
Oh, I see that options with optional arguments are not supported but there is a hint to try something else. I think it implies having a default though ... which won't work.
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.
Fusing the two fields and parsing the two options as alternatives would still make sense IMO. As a result the usage info should look roughly like this:
stack setup … [--upgrade-cabal | --install-cabal VERSION] …
The combined field should have a type like Maybe UpgradeTo
with
data UpgradeTo = Latest | Specific Version
or so.
The default value (which applies when neither option is used) is Nothing
.
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.
BTW, as an example stack clean
uses the Alternative
instance of the option parser:
Usage: stack clean ([PACKAGE] | [--full]) [--help]
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.
Oh! That was really helpful, thanks for even more pointers :)
I haven't done a thorough review yet, only added an inline comment on the design so far. Could you in any case please fix your commit description to use the correct flag name? Cheers! :) |
Oh yes, fixed that one 😄 |
I've done another pass on this and reduced the diff quite a bit. It should be much easier to review. If there are any other ideas on the merge of |
Latest stab at it is c0942c6. |
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.
Looks pretty good already but I had a few comments anyway.
src/Stack/Setup.hs
Outdated
$logWarn "This may fail, caveat emptor!" | ||
upgradeCabal menv wc | ||
upgradeCabal menv wc (fromJust cabalVersion) |
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.
It would be nicer to use forM_
instead of when isJust …
and fromJust
.
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.
Not sure how to get the when isJust
out of it? Please see 734dae4.
src/Stack/Setup.hs
Outdated
[] -> error "No Cabal library found in index, cannot upgrade" | ||
[PackageIdentifier name' version] | ||
| name == name' -> return version | ||
[PackageIdentifier name' version] | name == name' -> return version |
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.
This block seems unnecessarily monadic, could be pure.
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.
I don't know what this means 😄
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 only monadic bit about this case expression is the return
s – this should be a let-expression instead of using <-
.
src/Stack/Setup.hs
Outdated
, case cabalVersion of | ||
Specific _ -> " (specified)" | ||
Latest -> " (latest)" | ||
, ". No work to be done." |
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 string that is being formed here doesn't look right. Anyway, I think we should support installing an older version here. Not sure if that requires adding logic to unregister or hide the old version.
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.
This formatting corresponds to stopping the same version being installed. If you want to get an old version, you just fire off --install-cabal FOO
instead of --upgrade-cabal
. Good question regarding the unregister/hide stuff. Will investigate.
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.
Examples are:
λ :main ["setup", "--upgrade-cabal"]
Currently installed Cabal is 1.24.2.0 (latest). No work to be done.
And:
λ :main ["setup", "--install-cabal", "1.24.2.0"]
Currently installed Cabal is 1.24.2.0 (specified). No work to be done.
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.
Ok, I think I misread the diff a bit. Still, even when version
< installed
, we want to setup that old version
of Cabal.
src/Stack/Setup.hs
Outdated
-- Nothing below: use the newest .cabal file revision | ||
m <- unpackPackageIdents menv tmpdir Nothing (Map.singleton ident Nothing) | ||
|
||
compilerPath <- join $ findExecutable menv (compilerExeName wc) | ||
newestDir <- parseRelDir $ versionString newest | ||
newestDir <- parseRelDir $ versionString version |
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.
For consistency, that should probably be "versionDir".
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.
Fixed 👍
src/Stack/Types/Version.hs
Outdated
@@ -64,6 +65,9 @@ instance Exception VersionParseFail | |||
instance Show VersionParseFail where | |||
show (VersionParseFail bs) = "Invalid version: " ++ show bs | |||
|
|||
-- | A package version or the latest. | |||
data UpgradeTo = Specific Version | Latest deriving (Show) | |||
|
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 description is way more general than the name of the type. Can you come up with a more general name maybe?
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.
Hmmm ... tried the description again. I like the name, it was your recommendation :)
src/Stack/Setup.hs
Outdated
@@ -494,7 +494,7 @@ ensureCompiler sopts = do | |||
unless needLocal $ do | |||
$logWarn "Trying to change a Cabal library on a GHC not installed by stack." | |||
$logWarn "This may fail, caveat emptor!" | |||
upgradeCabal menv wc (fromJust cabalVersion) | |||
forM_ cabalVersion (upgradeCabal menv wc) |
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.
No, the forM_
should wrap the entire block:
forM_ cabalVersion $ \v -> do
unless …
Looks like good stuff! I certainly recommend making sure the downgrade case works. I'd also have expected it to require unregistering the old one. |
Moving over the discussion from #3019: Upgrading the global Cabal package is an ugly hack that I added in towards the beginning of Stack. It was necessary for cases where a custom setup script required some new functionality in Cabal that was not present in the shipped-with-GHC version. However, since then, we've had a significant change:
So I'd like to go in almost the opposite direction of this PR (apologies to @lwm and @sjakobi for only commenting now):
I'd go so far as considering upstream—in Stackage itself—beginning to block packages that don't define a custom-setup stanza. |
I'm pretty sure that overriding the Cabal version will work with |
Not sure if I'm missing something but it doesn't seem to work:
Judging from the build paths stack used |
Is this using custom setup at all?
…On Wed, Feb 22, 2017, 9:46 PM Simon Jakobi ***@***.***> wrote:
@snoyberg <https://github.com/snoyberg>
I'm pretty sure that overriding the Cabal version will work with master
Not sure if I'm missing something but it doesn't seem to work:
~/tmp $ stack --resolver lts-8.2 new cabal-setup
~/tmp $ cd cabal-setup/
~/t/cabal-setup $ vim stack.yaml # Add Cabal-1.24.0.0 to extra-deps
~/t/cabal-setup $ stack build
Warning: File listed in cabal-setup.cabal file does not exist: README.md
cabal-setup-0.1.0.0: configure (lib + exe)
Configuring cabal-setup-0.1.0.0...
cabal-setup-0.1.0.0: build (lib + exe)
Preprocessing library cabal-setup-0.1.0.0...
[1 of 1] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Lib.o )
Preprocessing executable 'cabal-setup-exe' for cabal-setup-0.1.0.0...
[1 of 1] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/cabal-setup-exe/cabal-setup-exe-tmp/Main.o )
Linking .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/cabal-setup-exe/cabal-setup-exe ...
Warning: File listed in cabal-setup.cabal file does not exist: README.md
cabal-setup-0.1.0.0: copy/register
Installing library in
/home/simon/tmp/cabal-setup/.stack-work/install/x86_64-linux/lts-8.2/8.0.2/lib/x86_64-linux-ghc-8.0.2/cabal-setup-0.1.0.0-Bd2jGUn5HBKJ5lzwApT2Rh
Installing executable(s) in
/home/simon/tmp/cabal-setup/.stack-work/install/x86_64-linux/lts-8.2/8.0.2/bin
Registering cabal-setup-0.1.0.0...
Judging from the build paths stack used Cabal-1.24.2.0 instead of 1.24.0.0
to build the Setup.hs.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2995 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADBB0SGLB3SQ7u-uEFENmZKfVoD2ADPks5rfJCkgaJpZM4L9-vq>
.
|
No, but should that be a requirement for testing compatibility between stack and Cabal? |
Ah, I hadn't understood that this is the case you're trying to address. I
guess this feature makes sense in that context. Ignore my objections.
…On Wed, Feb 22, 2017, 9:51 PM Simon Jakobi ***@***.***> wrote:
Is this using custom setup at all?
No, but should that be a requirement for testing compatibility between
stack and Cabal?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2995 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADBB_XgKOb9PE4toeKFiDjMJvPb4Hlsks5rfJG4gaJpZM4L9-vq>
.
|
Ah, good! Maybe the usage info for |
SGTM 👍
…On Wed, Feb 22, 2017, 10:22 PM Simon Jakobi ***@***.***> wrote:
Ah, good! Maybe the usage info for --upgrade-cabal and install-cabal
should note that these flags are only for debugging now.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2995 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADBB6GW8RGHc9dalkzXzocYNMHVpsPOks5rfJj6gaJpZM4L9-vq>
.
|
Kind of fell off on this one. Is this PR still relevant? I see lots of movement around Cabal stuff. |
@lwm I think the main unresolved issue is handling the downgrade case. Currently with this patch, if I have Cabal-1.24.2.0 and run I think this is still relevant. I don't see how custom-setup obviates the need for this, since the global cabal is still used for everything else. |
Thanks for feedback @mgsloan and @sjakobi. I've given this another stab. Apologies that the diff on this latest patch diverged so far but I tried a new approach. It appears the downgrade case is covered now but it takes so long to get a cabal install on my crappy machine, I didn't spend long testing ;) |
Failure unrelated ... tests seem to be borked: src/test/Stack/ConfigSpec.hs:154:22:
No instance for (FromJSON (WithJSONWarnings ConfigMonoid))
arising from a use of ‘decodeEither’
In the expression: decodeEither defaultConfigYaml
In an equation for ‘parsed’:
parsed = decodeEither defaultConfigYaml
In the expression:
do { let parsed :: Either String (WithJSONWarnings ConfigMonoid)
parsed = decodeEither defaultConfigYaml;
isRight parsed `shouldBe` True } |
@lwm My mistake, sorry! Should be fixed after rebasing. |
No worries @mgsloan! Travis said OK but now Appveyor said:
The never ending pull request lives on! |
Oops, fixed that too. I'm going to go ahead and merge this. Thanks!! |
Manually tested.
Based on #2386 (comment). Thanks @sjakobi for the pointers!