From fc65a6a5f0bb5c771ec86738fda078ab3f20ec3d Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sat, 11 Jan 2025 00:53:28 +0000 Subject: [PATCH] Fix #6675 Add install-msys and ancillary matters --- ChangeLog.md | 8 ++++ doc/commands/config_command.md | 17 +++++++ doc/commands/setup_command.md | 7 +-- doc/configure/global_flags.md | 20 +++++++++ doc/configure/yaml/non-project.md | 24 +++++++++- src/Stack/Config.hs | 2 + src/Stack/ConfigCmd.hs | 13 ++++++ src/Stack/Options/ConfigParser.hs | 8 +++- src/Stack/Setup.hs | 10 +++-- src/Stack/SetupCmd.hs | 74 +++++++++++++++++++------------ src/Stack/Types/Config.hs | 3 ++ src/Stack/Types/ConfigMonoid.hs | 8 ++++ 12 files changed, 157 insertions(+), 37 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index ac8d552d40..41a9ea21f4 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/doc/commands/config_command.md b/doc/commands/config_command.md index acde2c8b7a..65ae3ef7f6 100644 --- a/doc/commands/config_command.md +++ b/doc/commands/config_command.md @@ -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. @@ -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) diff --git a/doc/commands/setup_command.md b/doc/commands/setup_command.md index 08994c3118..aceea791a4 100644 --- a/doc/commands/setup_command.md +++ b/doc/commands/setup_command.md @@ -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: @@ -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" diff --git a/doc/configure/global_flags.md b/doc/configure/global_flags.md index 523a06ce22..78bdbd0fc5 100644 --- a/doc/configure/global_flags.md +++ b/doc/configure/global_flags.md @@ -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 ` to specify the number of concurrent @@ -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) diff --git a/doc/configure/yaml/non-project.md b/doc/configure/yaml/non-project.md index 51ad15f308..9314978677 100644 --- a/doc/configure/yaml/non-project.md +++ b/doc/configure/yaml/non-project.md @@ -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. @@ -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 ~~~ diff --git a/src/Stack/Config.hs b/src/Stack/Config.hs index 620a7eb90f..74418d3868 100644 --- a/src/Stack/Config.hs +++ b/src/Stack/Config.hs @@ -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 @@ -587,6 +588,7 @@ configFromConfigMonoid , latestSnapshot , systemGHC , installGHC + , installMsys , skipGHCCheck , skipMsys , msysEnvironment diff --git a/src/Stack/ConfigCmd.hs b/src/Stack/ConfigCmd.hs index 0da0bceccf..2a22b5404b 100644 --- a/src/Stack/ConfigCmd.hs +++ b/src/Stack/ConfigCmd.hs @@ -43,6 +43,7 @@ import Stack.Prelude import Stack.Types.Config ( Config (..), HasConfig (..) ) import Stack.Types.ConfigMonoid ( configMonoidInstallGHCName + , configMonoidInstallMsysName , configMonoidRecommendStackUpgradeName , configMonoidSystemGHCName ) @@ -71,6 +72,7 @@ data ConfigCmdSet | ConfigCmdSetResolver !(Unresolved AbstractSnapshot) | ConfigCmdSetSystemGhc !CommandScope !Bool | ConfigCmdSetInstallGhc !CommandScope !Bool + | ConfigCmdSetInstallMsys !CommandScope !Bool | ConfigCmdSetRecommendStackUpgrade !CommandScope !Bool | ConfigCmdSetDownloadPrefix !CommandScope !Text @@ -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 @@ -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 @@ -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 _ _) = @@ -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 diff --git a/src/Stack/Options/ConfigParser.hs b/src/Stack/Options/ConfigParser.hs index 11fefce385..3739a95c46 100644 --- a/src/Stack/Options/ConfigParser.hs +++ b/src/Stack/Options/ConfigParser.hs @@ -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 @@ -45,6 +45,7 @@ configOptsParser currentDir hide0 = , nixOpts , systemGHC , installGHC + , installMsys , skipGHCCheck , arch , ghcVariant @@ -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" diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index bdb01b56dd..6215bc7ae9 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -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 @@ -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 @@ -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" @@ -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) diff --git a/src/Stack/SetupCmd.hs b/src/Stack/SetupCmd.hs index 0cb04397c9..fef250e49b 100644 --- a/src/Stack/SetupCmd.hs +++ b/src/Stack/SetupCmd.hs @@ -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) @@ -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 diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index 7498db5297..f405b9c7f0 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -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 diff --git a/src/Stack/Types/ConfigMonoid.hs b/src/Stack/Types/ConfigMonoid.hs index d5c94fb3a2..af4c143cd5 100644 --- a/src/Stack/Types/ConfigMonoid.hs +++ b/src/Stack/Types/ConfigMonoid.hs @@ -11,6 +11,7 @@ module Stack.Types.ConfigMonoid , configMonoidAllowDifferentUserName , configMonoidGHCVariantName , configMonoidInstallGHCName + , configMonoidInstallMsysName , configMonoidRecommendStackUpgradeName , configMonoidSystemGHCName ) where @@ -83,6 +84,8 @@ data ConfigMonoid = ConfigMonoid -- ^ See: 'configSystemGHC' , installGHC :: !FirstTrue -- ^ See: 'configInstallGHC' + , installMsys :: !(First Bool) + -- ^ See: 'configInstallMsys' , skipGHCCheck :: !FirstFalse -- ^ See: 'configSkipGHCCheck' , skipMsys :: !FirstFalse @@ -248,6 +251,7 @@ parseConfigMonoidObject rootDir obj = do First <$> jsonSubWarningsT (obj ..:? configMonoidPackageIndexName) systemGHC <- First <$> obj ..:? configMonoidSystemGHCName installGHC <- FirstTrue <$> obj ..:? configMonoidInstallGHCName + installMsys <- First <$> obj ..:? configMonoidInstallMsysName skipGHCCheck <- FirstFalse <$> obj ..:? configMonoidSkipGHCCheckName skipMsys <- FirstFalse <$> obj ..:? configMonoidSkipMsysName msysEnvironment <- First <$> obj ..:? configMonoidMsysEnvironmentName @@ -366,6 +370,7 @@ parseConfigMonoidObject rootDir obj = do , packageIndex , systemGHC , installGHC + , installMsys , skipGHCCheck , skipMsys , msysEnvironment @@ -461,6 +466,9 @@ configMonoidSystemGHCName = "system-ghc" configMonoidInstallGHCName :: Text configMonoidInstallGHCName = "install-ghc" +configMonoidInstallMsysName :: Text +configMonoidInstallMsysName = "install-msys" + configMonoidSkipGHCCheckName :: Text configMonoidSkipGHCCheckName = "skip-ghc-check"