From 5376ff83b1fc95e293eae39b2150719012440503 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Fri, 17 May 2024 23:37:12 +0100 Subject: [PATCH] Fix #6583 Error S-6362 acknowledges compiler set at command line --- ChangeLog.md | 2 ++ doc/maintainers/stack_errors.md | 4 +-- package.yaml | 1 + src/Stack/Setup.hs | 11 ++++++-- src/Stack/Types/Build/Exception.hs | 36 ++++++++++++++++++++----- src/Stack/Types/WantedCompilerSetter.hs | 17 ++++++++++++ stack.cabal | 1 + 7 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 src/Stack/Types/WantedCompilerSetter.hs diff --git a/ChangeLog.md b/ChangeLog.md index cf421493d3..8fc67238c8 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/doc/maintainers/stack_errors.md b/doc/maintainers/stack_errors.md index d7d1dd60f7..bbc46c0e4d 100644 --- a/doc/maintainers/stack_errors.md +++ b/doc/maintainers/stack_errors.md @@ -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`. @@ -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` diff --git a/package.yaml b/package.yaml index cbb12cd5a1..91533b8858 100644 --- a/package.yaml +++ b/package.yaml @@ -341,6 +341,7 @@ library: - Stack.Types.UploadOpts - Stack.Types.Version - Stack.Types.VersionedDownloadInfo + - Stack.Types.WantedCompilerSetter - Stack.Uninstall - Stack.Unpack - Stack.Update diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index 0d59a3f941..451a19dc07 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -158,10 +158,11 @@ 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 (..) ) @@ -169,6 +170,7 @@ 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 ) @@ -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)) @@ -1200,7 +1207,7 @@ installGhcBindist sopts getSetupInfo' installed = do [] -> CompilerBuildStandard (_, compilerBuild):_ -> compilerBuild) sopts.compilerCheck - sopts.stackYaml + wantedCompilerSetter suggestion -- | Ensure compiler is installed. diff --git a/src/Stack/Types/Build/Exception.hs b/src/Stack/Types/Build/Exception.hs index 1aea0eaca1..57b178a6ea 100644 --- a/src/Stack/Types/Build/Exception.hs +++ b/src/Stack/Types/Build/Exception.hs @@ -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@. @@ -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) @@ -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 @@ -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 + ] ] ) <> "." diff --git a/src/Stack/Types/WantedCompilerSetter.hs b/src/Stack/Types/WantedCompilerSetter.hs new file mode 100644 index 0000000000..f9653b1b4d --- /dev/null +++ b/src/Stack/Types/WantedCompilerSetter.hs @@ -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) diff --git a/stack.cabal b/stack.cabal index 00034a6c82..7b93f78bc0 100644 --- a/stack.cabal +++ b/stack.cabal @@ -336,6 +336,7 @@ library Stack.Types.UploadOpts Stack.Types.Version Stack.Types.VersionedDownloadInfo + Stack.Types.WantedCompilerSetter Stack.Uninstall Stack.Unpack Stack.Update