Skip to content

Commit

Permalink
Fix #6675 Add install-msys and ancillary matters
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Jan 11, 2025
1 parent cb77235 commit fc65a6a
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 37 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Behavior changes:

Other enhancements:

* In YAML configuration files, the `install-msys` key is introduced, to enable
or disable the download and installation of Stack-supplied MSYS2 when
necessary (subject to `skip-msys: false`). The default is the same as the
`install-ghc` setting (including if that is set at the command line).
Consequently, the default behaviour of Stack is unaffected.
* Add the `stack config set install-msys` command to configure the
`install-msys` option in YAML configuration files.

Bug fixes:

## v3.3.1 - 2024-12-28
Expand Down
17 changes: 17 additions & 0 deletions doc/commands/config_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ stack config set COMMAND
Available commands:
install-ghc Configure whether or not Stack should automatically
install GHC when necessary.
install-msys Configure whether or not Stack should automatically
install MSYS2 when necessary.
package-index Configure Stack's package index
recommend-stack-upgrade Configure whether or not Stack should notify the user
if it identifes a new version of Stack is available.
Expand Down Expand Up @@ -79,6 +81,21 @@ the project-level configuration file (`stack.yaml`, by default) is altered. The
`--global` flag specifies the user-specific global configuration file
(`config.yaml`).

## The `stack config set install-msys` command

:octicons-tag-24: UNRELEASED

~~~text
stack config set install-msys [--global] true|false
~~~

`stack config set install-msys true` or `false` sets the
[`install-msys`](../configure/yaml/non-project.md#install-msys) non-project
specific configuration option in a configuration file, accordingly. By default,
the project-level configuration file (`stack.yaml`, by default) is altered. The
`--global` flag specifies the user-specific global configuration file
(`config.yaml`).

## The `stack config set package-index download-prefix` command

[:octicons-tag-24: 2.9.3](https://github.com/commercialhaskell/stack/releases/tag/v2.9.3)
Expand Down
7 changes: 4 additions & 3 deletions doc/commands/setup_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stack setup [GHC_VERSION] [--[no-]reinstall] [--ghc-bindist URL]
[--ghcjs-boot-options GHCJS_BOOT] [--[no-]ghcjs-boot-clean]
~~~

`stack setup` attempts to install a version of GHC.
`stack setup` attempts to install a version of GHC and, on Windows, MSYS2.

By default:

Expand All @@ -28,8 +28,9 @@ option specifying a custom GHC variant. For further information about the
specific configuration option documentation.

If Stack is configured not to install GHC (`install-ghc: false` or passing the
`--no-install-ghc` flag) then `stack setup` will warn that the flag and the
command are inconsistent and take no action.
`--no-install-ghc` flag) or not to install MSYS2 (`install-msys: false` or
passing the `--no-install-msys` flag) then `stack setup` will warn that the flag
and the command are inconsistent and take no action.

=== "Linux"

Expand Down
20 changes: 20 additions & 0 deletions doc/configure/global_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ Stack-supplied MSYS2 when necessary. For further information, see the
documentation for the corresponding non-project specific configuration
[option](yaml/non-project.md#install-ghc).

## `--[no-]install-msys` flag

:octicons-tag-24: UNRELEASED

Restrictions: Windows systems only

Default: Same as the [`install-ghc`](yaml/non-project.md#install-ghc) setting
(including if that is set on the command line)

If Stack is checking for the Stack-supplied MSYS2 when Stack is setting up the
environment, enables/disables the download and installation of MSYS2 when
necessary. For further information, see the documentation for the corresponding
non-project specific configuration [option](yaml/non-project.md#install-msys).

To skip entirely checking for the Stack-supplied MSYS2, see the documentation
for the [`skip-msys`](yaml/non-project.md#skip-msys) configuration option.

## `--jobs` or `-j` option

Pass the option `--jobs <number_of_jobs>` to specify the number of concurrent
Expand Down Expand Up @@ -269,6 +286,9 @@ environment. For further information, see the documentation for the
corresponding non-project specific configuration
[option](yaml/non-project.md#skip-msys).

To prevent installation of MSYS2, if it is not installed, see the documentation
for the [`install-msys`](yaml/non-project.md#install-msys) configuration option.

## `--snapshot` option

[:octicons-tag-24: 2.15.1](https://github.com/commercialhaskell/stack/releases/tag/v2.15.1)
Expand Down
24 changes: 23 additions & 1 deletion doc/configure/yaml/non-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -872,12 +872,31 @@ will receive a warning if this configuration value is set.
Default: `true`
([:octicons-tag-24: 1.5.0](https://github.com/commercialhaskell/stack/releases/tag/v1.5.0))

Command line equivalent (takes precedence): `--[no-]install-ghc` flag
Command line equivalent (takes precedence):
[`--[no-]install-ghc`](../global_flags.md#-no-install-ghc-flag) flag

Whether or not to download and install GHC when necessary. On Windows,
`install-ghc: false` also disables the download and installation of the
Stack-supplied MSYS2 when necessary.

## install-msys

:octicons-tag-24: UNRELEASED

Restrictions: Windows systems only

Default: same as the [`install-ghc`](#install-ghc) setting (including if that is
set on the command line)

Command line equivalent (takes precedence):
[`--[no-]install-msys`](../global_flags.md#-no-install-msys-flag) flag

If Stack is checking for the Stack-supplied MSYS2 when Stack is setting up the
environment, whether or not to download and install MSYS2 when necessary.

To skip entirely checking for the Stack-supplied MSYS2, see the documentation
for the [`skip-msys`](#skip-msys) configuration option.

## jobs

Default: the number of CPUs (cores) that the machine has.
Expand Down Expand Up @@ -1481,6 +1500,9 @@ Command line equivalent (takes precedence):
Skips checking for the Stack-supplied MSYS2 (and installing that MSYS2, if it is
not installed) when Stack is setting up the environment.

To prevent installation of MSYS2, if it is not installed, see the documentation
for the [`install-msys`](#install-msys) configuration option.

~~~yaml
skip-msys: true
~~~
Expand Down
2 changes: 2 additions & 0 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ configFromConfigMonoid
configMonoid.compilerRepository
ghcBuild = getFirst configMonoid.ghcBuild
installGHC = fromFirstTrue configMonoid.installGHC
installMsys = fromFirst installGHC configMonoid.installMsys
skipGHCCheck = fromFirstFalse configMonoid.skipGHCCheck
skipMsys = fromFirstFalse configMonoid.skipMsys
defMsysEnvironment = case platform of
Expand Down Expand Up @@ -587,6 +588,7 @@ configFromConfigMonoid
, latestSnapshot
, systemGHC
, installGHC
, installMsys
, skipGHCCheck
, skipMsys
, msysEnvironment
Expand Down
13 changes: 13 additions & 0 deletions src/Stack/ConfigCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Stack.Prelude
import Stack.Types.Config ( Config (..), HasConfig (..) )
import Stack.Types.ConfigMonoid
( configMonoidInstallGHCName
, configMonoidInstallMsysName
, configMonoidRecommendStackUpgradeName
, configMonoidSystemGHCName
)
Expand Down Expand Up @@ -71,6 +72,7 @@ data ConfigCmdSet
| ConfigCmdSetResolver !(Unresolved AbstractSnapshot)
| ConfigCmdSetSystemGhc !CommandScope !Bool
| ConfigCmdSetInstallGhc !CommandScope !Bool
| ConfigCmdSetInstallMsys !CommandScope !Bool
| ConfigCmdSetRecommendStackUpgrade !CommandScope !Bool
| ConfigCmdSetDownloadPrefix !CommandScope !Text

Expand All @@ -86,6 +88,7 @@ configCmdSetScope (ConfigCmdSetSnapshot _) = CommandScopeProject
configCmdSetScope (ConfigCmdSetResolver _) = CommandScopeProject
configCmdSetScope (ConfigCmdSetSystemGhc scope _) = scope
configCmdSetScope (ConfigCmdSetInstallGhc scope _) = scope
configCmdSetScope (ConfigCmdSetInstallMsys scope _) = scope
configCmdSetScope (ConfigCmdSetRecommendStackUpgrade scope _) = scope
configCmdSetScope (ConfigCmdSetDownloadPrefix scope _) = scope

Expand Down Expand Up @@ -267,6 +270,7 @@ cfgCmdSetValue root (ConfigCmdSetResolver newSnapshot) =
snapshotValue root newSnapshot
cfgCmdSetValue _ (ConfigCmdSetSystemGhc _ bool') = pure $ Yaml.Bool bool'
cfgCmdSetValue _ (ConfigCmdSetInstallGhc _ bool') = pure $ Yaml.Bool bool'
cfgCmdSetValue _ (ConfigCmdSetInstallMsys _ bool') = pure $ Yaml.Bool bool'
cfgCmdSetValue _ (ConfigCmdSetRecommendStackUpgrade _ bool') =
pure $ Yaml.Bool bool'
cfgCmdSetValue _ (ConfigCmdSetDownloadPrefix _ url) = pure $ Yaml.String url
Expand All @@ -288,6 +292,7 @@ cfgCmdSetKeys (ConfigCmdSetSnapshot _) = [["snapshot"], ["resolver"]]
cfgCmdSetKeys (ConfigCmdSetResolver _) = [["resolver"], ["snapshot"]]
cfgCmdSetKeys (ConfigCmdSetSystemGhc _ _) = [[configMonoidSystemGHCName]]
cfgCmdSetKeys (ConfigCmdSetInstallGhc _ _) = [[configMonoidInstallGHCName]]
cfgCmdSetKeys (ConfigCmdSetInstallMsys _ _) = [[configMonoidInstallMsysName]]
cfgCmdSetKeys (ConfigCmdSetRecommendStackUpgrade _ _) =
[[configMonoidRecommendStackUpgradeName]]
cfgCmdSetKeys (ConfigCmdSetDownloadPrefix _ _) =
Expand Down Expand Up @@ -341,6 +346,14 @@ configCmdSetParser =
( OA.progDesc
"Configure whether or not Stack should automatically install \
\GHC when necessary." ))
, OA.command (T.unpack configMonoidInstallMsysName)
( OA.info
( ConfigCmdSetInstallMsys
<$> globalScopeFlag
<*> boolArgument )
( OA.progDesc
"Configure whether or not Stack should automatically install \
\MSYS2 when necessary." ))
, OA.command (T.unpack configMonoidRecommendStackUpgradeName)
( OA.info
( ConfigCmdSetRecommendStackUpgrade
Expand Down
8 changes: 7 additions & 1 deletion src/Stack/Options/ConfigParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import qualified System.FilePath as FilePath
-- | Command-line arguments parser for configuration.
configOptsParser :: FilePath -> GlobalOptsContext -> Parser ConfigMonoid
configOptsParser currentDir hide0 =
( \stackRoot workDir buildOpts dockerOpts nixOpts systemGHC installGHC arch
( \stackRoot workDir buildOpts dockerOpts nixOpts systemGHC installGHC installMsys arch
ghcVariant ghcBuild jobs extraIncludeDirs extraLibDirs
customPreprocessorExts overrideGccPath overrideHpack hpackForce skipGHCCheck skipMsys
localBinPath setupInfoLocations modifyCodePage allowDifferentUser dumpLogs
Expand All @@ -45,6 +45,7 @@ configOptsParser currentDir hide0 =
, nixOpts
, systemGHC
, installGHC
, installMsys
, skipGHCCheck
, arch
, ghcVariant
Expand Down Expand Up @@ -100,6 +101,11 @@ configOptsParser currentDir hide0 =
"downloading and installing GHC if necessary. (Can be done manually \
\with 'stack setup'.)"
hide
<*> firstBoolFlagsNoDefault
"install-msys"
"downloading and installing MSYS2 if necessary (Windows only). (Can be \
\done manually with 'stack setup'.) (default: same as 'install-ghc')"
hide
<*> optionalFirst (strOption
( long "arch"
<> metavar "ARCH"
Expand Down
10 changes: 6 additions & 4 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ defaultSetupInfoYaml =
"https://raw.githubusercontent.com/commercialhaskell/stackage-content/master/stack/stack-setup-2.yaml"

data SetupOpts = SetupOpts
{ installIfMissing :: !Bool
{ installGhcIfMissing :: !Bool
, installMsysIfMissing :: !Bool
, useSystem :: !Bool
-- ^ Should we use a system compiler installation, if available?
, wantedCompiler :: !WantedCompiler
Expand Down Expand Up @@ -661,7 +662,8 @@ setupEnv needTargets buildOptsCLI mResolveMissingGHC = do
actual <- either throwIO pure $ wantedToActual wcVersion
let wc = actual^.whichCompilerL
sopts = SetupOpts
{ installIfMissing = config.installGHC
{ installGhcIfMissing = config.installGHC
, installMsysIfMissing = config.installMsys
, useSystem = config.systemGHC
, wantedCompiler = wcVersion
, compilerCheck = config.compilerCheck
Expand Down Expand Up @@ -1120,7 +1122,7 @@ ensureMsys sopts getSetupInfo' = do
case getInstalledTool installed (mkPackageName "msys2") (const True) of
Just tool -> pure (Just tool)
Nothing
| sopts.installIfMissing -> do
| sopts.installMsysIfMissing -> do
si <- runMemoized getSetupInfo'
let msysDir = fillSep
[ style Dir "msys2-yyyymmdd"
Expand Down Expand Up @@ -1185,7 +1187,7 @@ installGhcBindist sopts getSetupInfo' installed = do
case existingCompilers of
(tool, build_):_ -> pure (tool, build_)
[]
| sopts.installIfMissing -> do
| sopts.installGhcIfMissing -> do
si <- runMemoized getSetupInfo'
downloadAndInstallPossibleCompilers
(map snd possibleCompilers)
Expand Down
74 changes: 46 additions & 28 deletions src/Stack/SetupCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,50 @@ data SetupCmdOpts = SetupCmdOpts
setupCmd :: SetupCmdOpts -> RIO Runner ()
setupCmd sco = withConfig YesReexec $ do
installGHC <- view $ configL . to (.installGHC)
if installGHC
then
withBuildConfig $ do
(wantedCompiler, compilerCheck, mConfigFile) <-
case sco.compilerVersion of
Just v -> pure (v, MatchMinor, Nothing)
Nothing -> do
wantedCompilerVersion <- view wantedCompilerVersionL
compilerCheck <- view (configL . to (.compilerCheck))
configFile <- view configFileL
-- We are indifferent as to whether the configuration file is a
-- user-specific global or a project-level one.
let eitherConfigFile = EE.fromEither configFile
pure
( wantedCompilerVersion
, compilerCheck
, Just eitherConfigFile
)
setup sco wantedCompiler compilerCheck mConfigFile
else
prettyWarnL
[ "The"
, style Shell "--no-install-ghc"
, flow "flag is inconsistent with"
, style Shell (flow "stack setup") <> "."
, flow "No action taken."
]
installMsys <- view $ configL . to (.installMsys)
case (installGHC, installMsys) of
(True, True) -> withBuildConfig $ do
(wantedCompiler, compilerCheck, mConfigFile) <-
case sco.compilerVersion of
Just v -> pure (v, MatchMinor, Nothing)
Nothing -> do
wantedCompilerVersion <- view wantedCompilerVersionL
compilerCheck <- view (configL . to (.compilerCheck))
configFile <- view configFileL
-- We are indifferent as to whether the configuration file is a
-- user-specific global or a project-level one.
let eitherConfigFile = EE.fromEither configFile
pure
( wantedCompilerVersion
, compilerCheck
, Just eitherConfigFile
)
setup sco wantedCompiler compilerCheck mConfigFile
(False, True) -> warn
[ styledNoInstallGHC
, singleFlag
]
(True, False) -> warn
[ styledNoInstallMsys
, singleFlag
]
(False, False) -> warn
[ styledNoInstallGHC
, "and"
, styledNoInstallMsys
, flow "flags are"
]
where
styledNoInstallGHC = style Shell "--no-install-ghc"
styledNoInstallMsys = style Shell "--no-install-msys"
singleFlag = flow "flag is"
warn docs = prettyWarnL $
["The"]
<> docs
<> [ flow "inconsistent with"
, style Shell (flow "stack setup") <> "."
, flow "No action taken."
]

setup ::
(HasBuildConfig env, HasGHCVariant env)
Expand All @@ -78,7 +95,8 @@ setup ::
setup sco wantedCompiler compilerCheck configFile = do
config <- view configL
sandboxedGhc <- (.sandboxed) . fst <$> ensureCompilerAndMsys SetupOpts
{ installIfMissing = True
{ installGhcIfMissing = True
, installMsysIfMissing = True
, useSystem = config.systemGHC && not sco.forceReinstall
, wantedCompiler
, compilerCheck
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 @@ -97,6 +97,9 @@ data Config = Config
, installGHC :: !Bool
-- ^ Should we automatically install GHC if missing or the wrong
-- version is available? Can be overridden by command line options.
, installMsys :: !Bool
-- ^ On Windows, should we automatically install MSYS2 if missing? Can be
-- overridden by command line options.
, skipGHCCheck :: !Bool
-- ^ Don't bother checking the GHC version or architecture.
, skipMsys :: !Bool
Expand Down
Loading

0 comments on commit fc65a6a

Please sign in to comment.