Skip to content

Commit

Permalink
Re #6379 Introduce notify-if-arch-unknown configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Dec 25, 2023
1 parent 5b30901 commit 5d1c9e3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
14 changes: 12 additions & 2 deletions doc/yaml_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Options/ConfigParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/Stack/Types/ConfigMonoid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <-
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit 5d1c9e3

Please sign in to comment.