Skip to content

Commit 2e7e684

Browse files
committed
Merge pull request commercialhaskell#2016 from sjakobi/1546-ghc-path
stack path: Rename --ghc-paths to --programs-path, add --compiler-path commercialhaskell#1546
2 parents 75294eb + 43ede53 commit 2e7e684

5 files changed

Lines changed: 45 additions & 24 deletions

File tree

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Behavior changes:
1313
* `stack init` now ignores symlinks when searching for cabal files. It also now
1414
ignores any directory that begins with `.` (as well as `dist` dirs) - before
1515
it would only ignore `.git`, `.stack-work`, and `dist`.
16+
* The `stack path --ghc-paths` option is renamed to `--programs-path`.
17+
`--compiler-path` is added, which points directly at the compiler used in
18+
the current project.
1619

1720
Other enhancements:
1821

doc/GUIDE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,8 @@ global-stack-root: /home/michael/.stack
14731473
project-root: /home/michael/wai
14741474
config-location: /home/michael/wai/stack.yaml
14751475
bin-path: /home/michael/.stack/snapshots/x86_64-linux/lts-2.17/7.8.4/bin:/home/michael/.stack/programs/x86_64-linux/ghc-7.8.4/bin:/home/michael/.stack/programs/x86_64-linux/ghc-7.10.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
1476-
ghc-paths: /home/michael/.stack/programs/x86_64-linux
1476+
programs-path: /home/michael/.stack/programs/x86_64-linux
1477+
compiler-path: /home/michael/.stack/programs/x86_64-linux/ghc-7.8.4/bin/ghc
14771478
local-bin-path: /home/michael/.local/bin
14781479
extra-include-dirs:
14791480
extra-library-dirs:
@@ -1491,7 +1492,7 @@ these keys you're interested in, which can be convenient for scripting. As a
14911492
simple example, let's find out which versions of GHC are installed locally:
14921493
14931494
```
1494-
michael@d30748af6d3d:~/wai$ ls $(stack path --ghc-paths)/*.installed
1495+
michael@d30748af6d3d:~/wai$ ls $(stack path --programs-path)/*.installed
14951496
/home/michael/.stack/programs/x86_64-linux/ghc-7.10.2.installed
14961497
/home/michael/.stack/programs/x86_64-linux/ghc-7.8.4.installed
14971498
```
@@ -1504,7 +1505,7 @@ what needs to be removed:
15041505
1. The stack executable itself
15051506
2. The stack root, e.g. `$HOME/.stack` on non-Windows systems.
15061507
* See `stack path --global-stack-root`
1507-
* On Windows, you will also need to delete `stack path --ghc-paths`
1508+
* On Windows, you will also need to delete `stack path --programs-paths`
15081509
3. Any local `.stack-work` directories inside a project
15091510
15101511
## exec

src/Stack/Build/Execute.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Control.Concurrent.MVar.Lifted
2323
import Control.Concurrent.STM
2424
import Control.Exception.Enclosed (catchIO)
2525
import Control.Exception.Lifted
26-
import Control.Monad (liftM, when, unless, void, join)
26+
import Control.Monad (liftM, when, unless, void)
2727
import Control.Monad.Catch (MonadCatch, MonadMask)
2828
import Control.Monad.Extra (anyM, (&&^))
2929
import Control.Monad.IO.Class
@@ -785,11 +785,8 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
785785
, esLocaleUtf8 = True
786786
}
787787
menv <- liftIO $ configEnvOverride config envSettings
788-
-- When looking for ghc to build Setup.hs we want to ignore local binaries, see:
789-
-- https://github.com/commercialhaskell/stack/issues/1052
790-
menvWithoutLocals <- liftIO $ configEnvOverride config envSettings { esIncludeLocals = False }
791-
getGhcPath <- runOnce $ liftIO $ join $ findExecutable menvWithoutLocals "ghc"
792-
getGhcjsPath <- runOnce $ liftIO $ join $ findExecutable menvWithoutLocals "ghcjs"
788+
getGhcPath <- runOnce $ getCompilerPath Ghc
789+
getGhcjsPath <- runOnce $ getCompilerPath Ghcjs
793790
distRelativeDir' <- distRelativeDir
794791
esetupexehs <-
795792
-- Avoid broken Setup.hs files causing problems for simple build

src/Stack/Types/Config.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module Stack.Types.Config
4343
,EnvConfig(..)
4444
,HasEnvConfig(..)
4545
,getWhichCompiler
46+
,getCompilerPath
4647
-- * Details
4748
-- ** ApplyGhcOptions
4849
,ApplyGhcOptions(..)
@@ -126,7 +127,7 @@ module Stack.Types.Config
126127
import Control.Applicative
127128
import Control.Arrow ((&&&))
128129
import Control.Exception
129-
import Control.Monad (liftM, mzero, forM)
130+
import Control.Monad (liftM, mzero, forM, join)
130131
import Control.Monad.Catch (MonadThrow, throwM)
131132
import Control.Monad.Logger (LogLevel(..))
132133
import Control.Monad.Reader (MonadReader, ask, asks, MonadIO, liftIO)
@@ -174,7 +175,7 @@ import Stack.Types.PackageName
174175
import Stack.Types.TemplateName
175176
import Stack.Types.Version
176177
import System.PosixCompat.Types (UserID, GroupID, FileMode)
177-
import System.Process.Read (EnvOverride)
178+
import System.Process.Read (EnvOverride, findExecutable)
178179

179180
-- Re-exports
180181
import Stack.Types.Config.Build as X
@@ -1413,6 +1414,19 @@ minimalEnvSettings =
14131414
getWhichCompiler :: (MonadReader env m, HasEnvConfig env) => m WhichCompiler
14141415
getWhichCompiler = asks (whichCompiler . envConfigCompilerVersion . getEnvConfig)
14151416

1417+
-- | Get the path for the given compiler ignoring any local binaries.
1418+
--
1419+
-- https://github.com/commercialhaskell/stack/issues/1052
1420+
getCompilerPath
1421+
:: (MonadIO m, MonadThrow m, MonadReader env m, HasConfig env)
1422+
=> WhichCompiler
1423+
-> m (Path Abs File)
1424+
getCompilerPath wc = do
1425+
config <- asks getConfig
1426+
eoWithoutLocals <- liftIO $
1427+
configEnvOverride config minimalEnvSettings { esLocaleUtf8 = True }
1428+
join (findExecutable eoWithoutLocals (compilerExeName wc))
1429+
14161430
data ProjectAndConfigMonoid
14171431
= ProjectAndConfigMonoid !Project !ConfigMonoid
14181432

src/main/Main.hs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ pathCmd keys go =
536536
localroot <- installationRootLocal
537537
distDir <- distRelativeDir
538538
hpcDir <- hpcReportDir
539+
compilerPath <- getCompilerPath =<< getWhichCompiler
539540
forM_
540541
-- filter the chosen paths in flags (keys),
541542
-- or show all of them if no specific paths chosen.
@@ -561,20 +562,22 @@ pathCmd keys go =
561562
localroot
562563
distDir
563564
hpcDir
564-
extra))))
565+
extra
566+
compilerPath))))
565567

566568
-- | Passed to all the path printers as a source of info.
567569
data PathInfo = PathInfo
568-
{ piBuildConfig :: BuildConfig
569-
, piEnvOverride :: EnvOverride
570-
, piSnapDb :: Path Abs Dir
571-
, piLocalDb :: Path Abs Dir
572-
, piGlobalDb :: Path Abs Dir
573-
, piSnapRoot :: Path Abs Dir
574-
, piLocalRoot :: Path Abs Dir
575-
, piDistDir :: Path Rel Dir
576-
, piHpcDir :: Path Abs Dir
577-
, piExtraDbs :: [Path Abs Dir]
570+
{ piBuildConfig :: BuildConfig
571+
, piEnvOverride :: EnvOverride
572+
, piSnapDb :: Path Abs Dir
573+
, piLocalDb :: Path Abs Dir
574+
, piGlobalDb :: Path Abs Dir
575+
, piSnapRoot :: Path Abs Dir
576+
, piLocalRoot :: Path Abs Dir
577+
, piDistDir :: Path Rel Dir
578+
, piHpcDir :: Path Abs Dir
579+
, piExtraDbs :: [Path Abs Dir]
580+
, piCompilerPath :: Path Abs File
578581
}
579582

580583
-- | The paths of interest to a user. The first tuple string is used
@@ -600,9 +603,12 @@ paths =
600603
, ( "PATH environment variable"
601604
, "bin-path"
602605
, T.pack . intercalate [searchPathSeparator] . eoPath . piEnvOverride )
603-
, ( "Installed GHCs (unpacked and archives)"
604-
, "ghc-paths"
606+
, ( "Install location for GHC and other core tools"
607+
, "programs-path"
605608
, T.pack . toFilePathNoTrailingSep . configLocalPrograms . bcConfig . piBuildConfig )
609+
, ( "Compiler (e.g. ghc)"
610+
, "compiler-path"
611+
, T.pack . toFilePath . piCompilerPath )
606612
, ( "Local bin path where stack installs executables"
607613
, "local-bin-path"
608614
, T.pack . toFilePathNoTrailingSep . configLocalBin . bcConfig . piBuildConfig )

0 commit comments

Comments
 (0)