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

Fix #6583 Error S-6362 acknowledges compiler set at command line #6586

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Bug fixes:
that form.
* On Unix-like operating systems, the `test --coverage` command now finds
package keys even for very long package names.
* The Error S-6362 message now acknowledges when the wanted compiler has been
specified at the command line.

## v2.15.7 - 2024-05-12

Expand Down
4 changes: 2 additions & 2 deletions doc/maintainers/stack_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
In connection with considering Stack's support of the
[Haskell Error Index](https://errors.haskell.org/) initiative, this page seeks
to take stock of the errors that Stack itself can raise, by reference to the
`master` branch of the Stack repository. Last updated: 2024-05-05.
`master` branch of the Stack repository. Last updated: 2024-05-17.

* `Stack.main`: catches exceptions from action `commandLineHandler`.

Expand Down Expand Up @@ -384,7 +384,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
[S-8664] | InvalidFlagSpecification [UnusedFlags]
[S-8100] | GHCProfOptionInvalid
[S-1727] | NotOnlyLocal [PackageName] [Text]
[S-6362] | CompilerVersionMismatch (Maybe (ActualCompiler, Arch)) (WantedCompiler, Arch) GHCVariant CompilerBuild VersionCheck (Maybe (Path Abs File)) Text
[S-6362] | CompilerVersionMismatch (Maybe (ActualCompiler, Arch)) (WantedCompiler, Arch) GHCVariant CompilerBuild VersionCheck WantedCompilerSetter Text
~~~

- `Stack.Types.Compiler.CompilerException`
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ library:
- Stack.Types.UploadOpts
- Stack.Types.Version
- Stack.Types.VersionedDownloadInfo
- Stack.Types.WantedCompilerSetter
- Stack.Uninstall
- Stack.Unpack
- Stack.Update
Expand Down
11 changes: 9 additions & 2 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,19 @@ import Stack.Types.GHCVariant
( GHCVariant (..), HasGHCVariant (..), ghcVariantName
, ghcVariantSuffix
)
import Stack.Types.GlobalOpts ( GlobalOpts (..) )
import Stack.Types.Platform
( HasPlatform (..), PlatformVariant (..)
, platformOnlyRelDir )
import Stack.Types.Runner ( HasRunner (..) )
import Stack.Types.Runner ( HasRunner (..), Runner (..) )
import Stack.Types.SetupInfo ( SetupInfo (..) )
import Stack.Types.SourceMap
( SMActual (..), SMWanted (..), SourceMap (..) )
import Stack.Types.Version
( VersionCheck, stackMinorVersion, stackVersion )
import Stack.Types.VersionedDownloadInfo
( VersionedDownloadInfo (..) )
import Stack.Types.WantedCompilerSetter ( WantedCompilerSetter (..) )
import qualified System.Directory as D
import System.Environment ( getExecutablePath, lookupEnv )
import System.IO.Error ( isPermissionError )
Expand Down Expand Up @@ -1156,6 +1158,11 @@ installGhcBindist sopts getSetupInfo' installed = do
(Just tool, False) -> [(tool, compilerBuild)]
_ -> [])
possibleCompilers
globalOpts = config.runner.globalOpts
wantedCompilerSetter
| isJust globalOpts.compiler = CompilerAtCommandLine
| isJust globalOpts.snapshot = SnapshotAtCommandLine
| otherwise = YamlConfiguration sopts.stackYaml
logDebug $
"Found already installed GHC builds: "
<> mconcat (intersperse ", " (map (fromString . compilerBuildName . snd) existingCompilers))
Expand Down Expand Up @@ -1200,7 +1207,7 @@ installGhcBindist sopts getSetupInfo' installed = do
[] -> CompilerBuildStandard
(_, compilerBuild):_ -> compilerBuild)
sopts.compilerCheck
sopts.stackYaml
wantedCompilerSetter
suggestion

-- | Ensure compiler is installed.
Expand Down
36 changes: 29 additions & 7 deletions src/Stack/Types/Build/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Stack.Types.NamedComponent
import Stack.Types.Package ( Package (..), packageIdentifier )
import Stack.Types.ParentMap ( ParentMap )
import Stack.Types.Version ( VersionCheck (..), VersionRange )
import Stack.Types.WantedCompilerSetter ( WantedCompilerSetter (..) )

-- | Type representing exceptions thrown by functions exported by modules with
-- names beginning @Stack.Build@.
Expand Down Expand Up @@ -257,7 +258,7 @@ data BuildPrettyException
GHCVariant -- expected
CompilerBuild -- expected
VersionCheck
(Maybe (Path Abs File)) -- Path to the stack.yaml file
WantedCompilerSetter -- Way that the wanted compiler is set
StyleDoc -- recommended resolution
deriving (Show, Typeable)

Expand Down Expand Up @@ -390,7 +391,15 @@ instance Pretty BuildPrettyException where
(map (fromString . T.unpack) exes :: [StyleDoc])
)
<> line
pretty (CompilerVersionMismatch mactual (expected, eArch) ghcVariant ghcBuild check mstack resolution) =
pretty ( CompilerVersionMismatch
mactual
(expected, eArch)
ghcVariant
ghcBuild
check
wantedCompilerSetter
resolution
) =
"[S-6362]"
<> line
<> fillSep
Expand All @@ -415,12 +424,25 @@ instance Pretty BuildPrettyException where
, parens
( fillSep
[ flow "based on"
, case mstack of
Nothing -> flow "command line arguments"
Just stack -> fillSep
[ flow "snapshot setting in"
, pretty stack
, case wantedCompilerSetter of
CompilerAtCommandLine -> fillSep
[ "the"
, style Shell "--compiler"
, "option"
]
SnapshotAtCommandLine -> fillSep
[ "the"
, style Shell "--snapshot" <> ","
, "or"
, style Shell "--resolver" <> ","
, "option"
]
YamlConfiguration mStack -> case mStack of
Nothing -> flow "command line arguments"
Just stack -> fillSep
[ flow "the configuration in"
, pretty stack
]
]
)
<> "."
Expand Down
17 changes: 17 additions & 0 deletions src/Stack/Types/WantedCompilerSetter.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{-# LANGUAGE NoImplicitPrelude #-}

module Stack.Types.WantedCompilerSetter
( WantedCompilerSetter (..)
) where

import Stack.Prelude

-- | Type representing ways that a wanted compiler is set.
data WantedCompilerSetter
= CompilerAtCommandLine
-- ^ At the command line with --compiler option.
| SnapshotAtCommandLine
-- ^ At the command line with --snapshot (or --resolver) option.
| YamlConfiguration (Maybe (Path Abs File))
-- ^ Via a YAML configuration file.
deriving (Show, Typeable)
1 change: 1 addition & 0 deletions stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ library
Stack.Types.UploadOpts
Stack.Types.Version
Stack.Types.VersionedDownloadInfo
Stack.Types.WantedCompilerSetter
Stack.Uninstall
Stack.Unpack
Stack.Update
Expand Down