From 5d1c9e3c48b927687901dff6970aa7fa3d77d86c Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sun, 24 Dec 2023 21:35:47 +0000 Subject: [PATCH] Re #6379 Introduce `notify-if-arch-unknown` configuration option --- ChangeLog.md | 3 +++ doc/yaml_configuration.md | 14 ++++++++++++-- src/Stack/Config.hs | 23 ++++++++++++++--------- src/Stack/Options/ConfigParser.hs | 2 +- src/Stack/Types/Config.hs | 3 +++ src/Stack/Types/ConfigMonoid.hs | 7 +++++++ 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 653c16275d..191e0e2b72 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -65,6 +65,9 @@ Other enhancements: `stack> build (lib + exe + test) with ghc-9.6.3`). * Add flag `--candidate` to Stack's `unpack` command, to allow package candidates to be unpacked locally. +* Stack will notify the user if a specified architecture value is unknown to + Cabal (the library). In YAML configuration files, the `notify-if-arch-unknown` + key is introduced, to allow the notification to be muted if unwanted. Bug fixes: diff --git a/doc/yaml_configuration.md b/doc/yaml_configuration.md index f9d8bf593a..08d9ddc207 100644 --- a/doc/yaml_configuration.md +++ b/doc/yaml_configuration.md @@ -474,8 +474,9 @@ See [`setup-info`](#setup-info). `aarch64` / `arm64`), or other values (which are case-sensitive and treated as an unknown 'other' architecture of the specified name). -Stack will warn the user if the specified machine architecture is an unknown -'other' architecture. +By default, Stack will warn the user if the specified machine architecture is an +unknown 'other' architecture. The warning can be muted; see +[`notify-if-arch-unknown`](#notify-if-arch-unknown) !!! note @@ -1237,6 +1238,15 @@ for details). For further information, see the [Nix integration](nix_integration.md#configuration) documentation. +### notify-if-arch-unknown + +:octicons-tag-24: UNRELEASED + +Default: `true` + +If the specified machine architecture value is unknown to Cabal (the library), +should Stack notify the user of that? + ### notify-if-cabal-untested :octicons-tag-24: UNRELEASED diff --git a/src/Stack/Config.hs b/src/Stack/Config.hs index acba62bfac..79ae8fb2a7 100644 --- a/src/Stack/Config.hs +++ b/src/Stack/Config.hs @@ -48,7 +48,7 @@ import Data.Monoid.Map ( MonoidMap (..) ) import qualified Data.Text as T import qualified Data.Yaml as Yaml import Distribution.System - ( Arch (OtherArch), OS (..), Platform (..), buildPlatform ) + ( Arch (..), OS (..), Platform (..), buildPlatform ) import qualified Distribution.Text ( simpleParse ) import Distribution.Version ( simplifyVersionRange ) import GHC.Conc ( getNumProcessors ) @@ -322,14 +322,6 @@ configFromConfigMonoid configRequireStackVersion = simplifyVersionRange (getIntersectingVersionRange configMonoidRequireStackVersion) configCompilerCheck = fromFirst MatchMinor configMonoidCompilerCheck - case arch of - OtherArch "aarch64" -> pure () - OtherArch unk -> - prettyWarnL - [ flow "Unknown value for architecture setting:" - , style Shell (fromString unk) <> "." - ] - _ -> pure () configPlatformVariant <- liftIO $ maybe PlatformVariantNone PlatformVariant <$> lookupEnv platformVariantEnvVar let configBuild = buildOptsFromMonoid configMonoidBuildOpts @@ -427,6 +419,7 @@ configFromConfigMonoid configNotifyIfNixOnPath = fromFirstTrue configMonoidNotifyIfNixOnPath configNotifyIfGhcUntested = fromFirstTrue configMonoidNotifyIfGhcUntested configNotifyIfCabalUntested = fromFirstTrue configMonoidNotifyIfCabalUntested + configNotifyIfArchUnknown = fromFirstTrue configMonoidNotifyIfArchUnknown configNoRunCompile = fromFirstFalse configMonoidNoRunCompile configAllowDifferentUser <- case getFirst configMonoidAllowDifferentUser of @@ -618,6 +611,18 @@ loadConfig inner = do (mconcat $ configArgs : addConfigMonoid extraConfigs) withConfig $ \config -> do + let Platform arch _ = configPlatform config + case arch of + OtherArch unknownArch + | configNotifyIfArchUnknown config -> + prettyWarnL + [ flow "Unknown value for architecture setting:" + , style Shell (fromString unknownArch) <> "." + , flow "To mute this message in future, set" + , style Shell (flow "notify-if-arch-unknown: false") + , flow "in Stack's configuration." + ] + _ -> pure () unless (stackVersion `withinRange` configRequireStackVersion config) (throwM (BadStackVersionException (configRequireStackVersion config))) unless (configAllowDifferentUser config) $ do diff --git a/src/Stack/Options/ConfigParser.hs b/src/Stack/Options/ConfigParser.hs index d1ad530c83..a99c4161f0 100644 --- a/src/Stack/Options/ConfigParser.hs +++ b/src/Stack/Options/ConfigParser.hs @@ -100,7 +100,7 @@ configOptsParser currentDir hide0 = <*> optionalFirst (strOption ( long "arch" <> metavar "ARCH" - <> help "System architecture, e.g. i386, x86_64." + <> help "System architecture, e.g. i386, x86_64, aarch64." <> hide )) <*> optionalFirst (ghcVariantParser (hide0 /= OuterGlobalOpts)) diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index 02672a8b71..8ce3797cb1 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -186,6 +186,9 @@ data Config = Config -- ^ Notify if Stack has not been tested with the GHC version? , configNotifyIfCabalUntested :: !Bool -- ^ Notify if Stack has not been tested with the Cabal version? + , configNotifyIfArchUnknown :: !Bool + -- ^ Notify if the specified machine architecture is unknown to Cabal (the + -- library)? , configNoRunCompile :: !Bool -- ^ Use --no-run and --compile options when using `stack script` , configStackDeveloperMode :: !Bool diff --git a/src/Stack/Types/ConfigMonoid.hs b/src/Stack/Types/ConfigMonoid.hs index 75cf02c58b..b9a7241afd 100644 --- a/src/Stack/Types/ConfigMonoid.hs +++ b/src/Stack/Types/ConfigMonoid.hs @@ -174,6 +174,8 @@ data ConfigMonoid = ConfigMonoid -- ^ See 'configNotifyIfGhcUntested' , configMonoidNotifyIfCabalUntested :: !FirstTrue -- ^ See 'configNotifyIfCabalUntested' + , configMonoidNotifyIfArchUnknown :: !FirstTrue + -- ^ See 'configNotifyIfArchUnknown' , configMonoidCasaOpts :: !CasaOptsMonoid -- ^ Casa configuration options. , configMonoidCasaRepoPrefix :: !(First CasaRepoPrefix) @@ -350,6 +352,8 @@ parseConfigMonoidObject rootDir obj = do FirstTrue <$> obj ..:? configMonoidNotifyIfGhcUntestedName configMonoidNotifyIfCabalUntested <- FirstTrue <$> obj ..:? configMonoidNotifyIfCabalUntestedName + configMonoidNotifyIfArchUnknown <- + FirstTrue <$> obj ..:? configMonoidNotifyIfArchUnknownName configMonoidCasaOpts <- jsonSubWarnings (obj ..:? configMonoidCasaOptsName ..!= mempty) configMonoidCasaRepoPrefix <- @@ -536,6 +540,9 @@ configMonoidNotifyIfGhcUntestedName = "notify-if-ghc-untested" configMonoidNotifyIfCabalUntestedName :: Text configMonoidNotifyIfCabalUntestedName = "notify-if-cabal-untested" +configMonoidNotifyIfArchUnknownName :: Text +configMonoidNotifyIfArchUnknownName = "notify-if-arch-unknown" + configMonoidCasaOptsName :: Text configMonoidCasaOptsName = "casa"