Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dot and ls dependencies work without ghc installed #4405

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Bug fixes:
[#4314](https://github.com/commercialhaskell/stack/pull/4314)
* Add `--cabal-files` flag to `stack ide targets` command.
* Don't download ghc when using `stack clean`.
* `dot` and `ls dependencies` commands no longer require GHC to be installed. Also, ensures the `--no-install-ghc` flag is respected. See: [#4390](https://github.com/commercialhaskell/stack/issues/4390)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better as two lines; respecting --no-install-ghc in bug fixes and the lack of GHC requirement merged with the stack clean line above, and moved to Other enhancements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that 2nd second sentence is misleading, the flag was respected at least in version 1.7.1 already:

qrilka@qdesktop ~/ws/h/stack-test-ghc-7.8.4 $ cat stack.yaml 
resolver: ghc-7.8.4
qrilka@qdesktop ~/ws/h/stack-test-ghc-7.8.4 $ stack --no-install-ghc clean
No compiler found, expected minor version match with ghc-7.8.4 (x86_64-tinfo6) (based on resolver setting in /home/qrilka/ws/h/stack-test-ghc-7.8.4/stack.yaml).
To install the correct GHC into /home/qrilka/.stack/programs/x86_64-linux/, try running "stack setup" or use the "--install-ghc" flag.
qrilka@qdesktop ~/ws/h/stack-test-ghc-7.8.4 $ stack --numeric-version
1.7.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's perfectly clear, thanks!!


## v1.9.1

Expand Down
19 changes: 14 additions & 5 deletions src/Stack/Runners.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RankNTypes #-}

-- | Utilities for running stack commands.
module Stack.Runners
Expand Down Expand Up @@ -261,10 +262,18 @@ munlockFile Nothing = return ()
munlockFile (Just lk) = liftIO $ unlockFile lk

-- Plumbing for --test and --bench flags
-- Force enable --no-install-ghc and --skip-ghc-check flags
withBuildConfigDot :: DotOpts -> GlobalOpts -> RIO EnvConfig () -> IO ()
withBuildConfigDot opts go f = withBuildConfig go' f
withBuildConfigDot opts go = withBuildConfig (updateGlobalOpts go)
where
go' =
(if dotTestTargets opts then set (globalOptsBuildOptsMonoidL.buildOptsMonoidTestsL) (Just True) else id) $
(if dotBenchTargets opts then set (globalOptsBuildOptsMonoidL.buildOptsMonoidBenchmarksL) (Just True) else id)
go
updateGlobalOpts
= updateOpts (dotTestTargets opts) (globalOptsBuildOptsMonoidL.buildOptsMonoidTestsL) (Just True)
. updateOpts (dotBenchTargets opts) (globalOptsBuildOptsMonoidL.buildOptsMonoidBenchmarksL) (Just True)
. set (globalOptsL.configMonoidSkipGHCCheckL) (Just True)
. set (globalOptsL.configMonoidInstallGHCL) (Just False)

-- helper function for update some option
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- helper function for update some option
-- helper function to update an option

It would be good to document what the Bool represents.

updateOpts :: Bool -> Lens' opts v -> v -> opts -> opts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this combinator 👍

updateOpts isRequired opt v
| isRequired = set opt v
| otherwise = id
16 changes: 12 additions & 4 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ instance Show SetupException where
show UnsupportedSetupConfiguration =
"I don't know how to install GHC on your system configuration, please install manually"

checkDownloadCompiler :: (HasConfig env, HasGHCVariant env)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @qrilka noted, this could do with some documentation. We may want to change the WithDownloadCompiler enum as a result.

=> SetupOpts
-> WithDownloadCompiler
-> RIO env (Maybe ExtraDirs, Maybe CompilerBuild, Bool)
checkDownloadCompiler _ SkipDownloadCompiler = return (Nothing, Nothing, False)
checkDownloadCompiler sopts WithDownloadCompiler
| installIfMissing = ensureCompiler sopts
| otherwise = return (Nothing, Nothing, False)
where
installIfMissing = soptsInstallIfMissing sopts

-- | Modify the environment variables (like PATH) appropriately, possibly doing installation too
setupEnv :: (HasBuildConfig env, HasGHCVariant env)
=> Maybe Text -- ^ Message to give user when necessary GHC is not available
Expand Down Expand Up @@ -234,10 +245,7 @@ setupEnv mResolveMissingGHC = do
, soptsGHCJSBootOpts = ["--clean"]
}

(mghcBin, mCompilerBuild, _) <-
case bcDownloadCompiler bconfig of
SkipDownloadCompiler -> return (Nothing, Nothing, False)
WithDownloadCompiler -> ensureCompiler sopts
(mghcBin, mCompilerBuild, _) <- checkDownloadCompiler sopts (bcDownloadCompiler bconfig)

-- Modify the initial environment to include the GHC path, if a local GHC
-- is being used
Expand Down
12 changes: 12 additions & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ module Stack.Types.Config
,loadedSnapshotL
,shouldForceGhcColorFlag
,appropriateGhcColorFlag
,configMonoidSkipGHCCheckL
,configMonoidInstallGHCL
-- * Lens reexport
,view
,to
Expand Down Expand Up @@ -1984,3 +1986,13 @@ appropriateGhcColorFlag :: (HasRunner env, HasEnvConfig env)
appropriateGhcColorFlag = f <$> shouldForceGhcColorFlag
where f True = Just ghcColorForceFlag
f False = Nothing

configMonoidSkipGHCCheckL :: Lens' ConfigMonoid (Maybe Bool)
configMonoidSkipGHCCheckL =
lens (getFirst . configMonoidSkipGHCCheck)
(\configMonoid t -> configMonoid {configMonoidSkipGHCCheck = First t})

configMonoidInstallGHCL :: Lens' ConfigMonoid (Maybe Bool)
configMonoidInstallGHCL =
lens (getFirst . configMonoidInstallGHC)
(\configMonoid t -> configMonoid {configMonoidInstallGHC = First t})