Skip to content

Commit

Permalink
Implementation of "--copy-compiler-tool" #2643
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Aug 20, 2017
1 parent 8122230 commit dae1662
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Behavior changes:
without an accompanying `-RTS`.
* When auto-detecting `--ghc-build`, `tinfo6` is now preferred over
`standard` if both versions of libtinfo are installed
* Addition of `stack build --copy-compiler-tool`, to allow tools like
intero to be installed globally for a particular compiler.
[#2643](https://github.com/commercialhaskell/stack/issues/2643)

Other enhancements:

Expand Down
3 changes: 2 additions & 1 deletion src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ constructPlan ls0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackage
, planFinals = M.fromList finals
, planUnregisterLocal = mkUnregisterLocal tasks dirtyReason localDumpPkgs sourceMap initialBuildSteps
, planInstallExes =
if boptsInstallExes $ bcoBuildOpts baseConfigOpts0
if boptsInstallExes (bcoBuildOpts baseConfigOpts0) ||
boptsInstallCompilerTool (bcoBuildOpts baseConfigOpts0)
then installExes
else Map.empty
}
Expand Down
7 changes: 5 additions & 2 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,10 @@ copyExecutables exes | Map.null exes = return ()
copyExecutables exes = do
snapBin <- (</> bindirSuffix) `liftM` installationRootDeps
localBin <- (</> bindirSuffix) `liftM` installationRootLocal
destDir <- view $ configL.to configLocalBin
compilerSpecific <- boptsInstallCompilerTool <$> view buildOptsL
destDir <- if compilerSpecific
then bindirCompilerTools
else view $ configL.to configLocalBin
ensureDir destDir

destDir' <- liftIO . D.canonicalizePath . toFilePath $ destDir
Expand Down Expand Up @@ -560,7 +563,7 @@ copyExecutables exes = do
, T.pack destDir'
, ":"]
forM_ installed $ \exe -> $logInfo ("- " <> exe)
warnInstallSearchPathIssues destDir' installed
unless compilerSpecific $ warnInstallSearchPathIssues destDir' installed


-- | Windows can't write over the current executable. Instead, we rename the
Expand Down
3 changes: 3 additions & 0 deletions src/Stack/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ buildOptsFromMonoid BuildOptsMonoid{..} = BuildOpts
, boptsInstallExes = fromFirst
(boptsInstallExes defaultBuildOpts)
buildMonoidInstallExes
, boptsInstallCompilerTool = fromFirst
(boptsInstallCompilerTool defaultBuildOpts)
buildMonoidInstallCompilerTool
, boptsPreFetch = fromFirst
(boptsPreFetch defaultBuildOpts)
buildMonoidPreFetch
Expand Down
11 changes: 8 additions & 3 deletions src/Stack/Options/BuildMonoidParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ buildOptsMonoidParser hide0 =
libProfiling <*> exeProfiling <*> libStripping <*>
exeStripping <*> haddock <*> haddockOptsParser hideBool <*>
openHaddocks <*> haddockDeps <*> haddockInternal <*>
haddockHyperlinkSource <*> copyBins <*> preFetch <*> keepGoing <*>
forceDirty <*> tests <*> testOptsParser hideBool <*> benches <*>
haddockHyperlinkSource <*> copyBins <*> copyCompilerTool <*>
preFetch <*> keepGoing <*> forceDirty <*>
tests <*> testOptsParser hideBool <*> benches <*>
benchOptsParser hideBool <*> reconfigure <*> cabalVerbose <*> splitObjs <*> skipComponents
where
hideBool = hide0 /= BuildCmdGlobalOpts
Expand Down Expand Up @@ -62,7 +63,6 @@ buildOptsMonoidParser hide0 =
\debuggers/profiling tools/other utilities that use \
\debugging symbols." <>
hideExceptGhci)

libProfiling =
firstBoolFlags
"library-profiling"
Expand Down Expand Up @@ -110,6 +110,11 @@ buildOptsMonoidParser hide0 =
"copy-bins"
"copying binaries to the local-bin-path (see 'stack path')"
hide
copyCompilerTool =
firstBoolFlags
"copy-compiler-tool"
"copying binaries of targets to compiler-tools-bin (see 'stack path')"
hide
keepGoing =
firstBoolFlags
"keep-going"
Expand Down
6 changes: 6 additions & 0 deletions src/Stack/Path.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ path keys =
global <- GhcPkg.getGlobalDB menv whichCompiler
snaproot <- installationRootDeps
localroot <- installationRootLocal
toolsDir <- bindirCompilerTools
distDir <- distRelativeDir
hpcDir <- hpcReportDir
compiler <- getCompilerPath whichCompiler
Expand Down Expand Up @@ -83,6 +84,7 @@ path keys =
global
snaproot
localroot
toolsDir
distDir
hpcDir
extra
Expand All @@ -107,6 +109,7 @@ data PathInfo = PathInfo
, piGlobalDb :: Path Abs Dir
, piSnapRoot :: Path Abs Dir
, piLocalRoot :: Path Abs Dir
, piToolsDir :: Path Abs Dir
, piDistDir :: Path Rel Dir
, piHpcDir :: Path Abs Dir
, piExtraDbs :: [Path Abs Dir]
Expand Down Expand Up @@ -155,6 +158,9 @@ paths =
, ( "Directory containing the compiler binary (e.g. ghc)"
, "compiler-bin"
, T.pack . toFilePathNoTrailingSep . parent . piCompiler )
, ( "Directory containing binaries specific to a particular compiler (e.g. intero)"
, "compiler-tools-bin"
, T.pack . toFilePathNoTrailingSep . piToolsDir )
, ( "Local bin dir where stack installs executables (e.g. ~/.local/bin)"
, "local-bin"
, view $ configL.to configLocalBin.to toFilePathNoTrailingSep.to T.pack)
Expand Down
20 changes: 18 additions & 2 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ module Stack.Types.Config
,hpcReportDir
,installationRootDeps
,installationRootLocal
,bindirCompilerTools
,hoogleRoot
,hoogleDatabasePath
,packageDatabaseDeps
Expand Down Expand Up @@ -1232,6 +1233,20 @@ installationRootLocal = do
psc <- useShaPathOnWindows =<< platformSnapAndCompilerRel
return $ workDir </> $(mkRelDir "install") </> psc

-- | Installation root for compiler tools
bindirCompilerTools :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => m (Path Abs Dir)
bindirCompilerTools = do
config <- asks getConfig
platform <- platformGhcRelDir
compilerVersion <- asks (envConfigCompilerVersion . getEnvConfig)
compiler <- parseRelDir $ compilerVersionString compilerVersion
return $
configStackRoot config </>
$(mkRelDir "compiler-tools") </>
platform </>
compiler </>
bindirSuffix

-- | Hoogle directory.
hoogleRoot :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => m (Path Abs Dir)
hoogleRoot = do
Expand Down Expand Up @@ -1376,9 +1391,10 @@ extraBinDirs :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
extraBinDirs = do
deps <- installationRootDeps
local <- installationRootLocal
tools <- bindirCompilerTools
return $ \locals -> if locals
then [local </> bindirSuffix, deps </> bindirSuffix]
else [deps </> bindirSuffix]
then [local </> bindirSuffix, deps </> bindirSuffix, tools]
else [deps </> bindirSuffix, tools]

-- | Get the minimal environment override, useful for just calling external
-- processes like git or ghc
Expand Down
8 changes: 8 additions & 0 deletions src/Stack/Types/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ data BuildOpts =
-- @hscolour@. Disable for no sources.
,boptsInstallExes :: !Bool
-- ^ Install executables to user path after building?
,boptsInstallCompilerTool :: !Bool
-- ^ Install executables to compiler tools path after building?
,boptsPreFetch :: !Bool
-- ^ Fetch all packages immediately
-- ^ Watch files for changes and automatically rebuild
Expand Down Expand Up @@ -100,6 +102,7 @@ defaultBuildOpts = BuildOpts
, boptsHaddockInternal = False
, boptsHaddockHyperlinkSource = True
, boptsInstallExes = False
, boptsInstallCompilerTool = False
, boptsPreFetch = False
, boptsKeepGoing = Nothing
, boptsForceDirty = False
Expand Down Expand Up @@ -166,6 +169,7 @@ data BuildOptsMonoid = BuildOptsMonoid
, buildMonoidHaddockInternal :: !(First Bool)
, buildMonoidHaddockHyperlinkSource :: !(First Bool)
, buildMonoidInstallExes :: !(First Bool)
, buildMonoidInstallCompilerTool :: !(First Bool)
, buildMonoidPreFetch :: !(First Bool)
, buildMonoidKeepGoing :: !(First Bool)
, buildMonoidForceDirty :: !(First Bool)
Expand Down Expand Up @@ -195,6 +199,7 @@ instance FromJSON (WithJSONWarnings BuildOptsMonoid) where
buildMonoidHaddockInternal <- First <$> o ..:? buildMonoidHaddockInternalArgName
buildMonoidHaddockHyperlinkSource <- First <$> o ..:? buildMonoidHaddockHyperlinkSourceArgName
buildMonoidInstallExes <- First <$> o ..:? buildMonoidInstallExesArgName
buildMonoidInstallCompilerTool <- First <$> o ..:? buildMonoidInstallCompilerToolArgName
buildMonoidPreFetch <- First <$> o ..:? buildMonoidPreFetchArgName
buildMonoidKeepGoing <- First <$> o ..:? buildMonoidKeepGoingArgName
buildMonoidForceDirty <- First <$> o ..:? buildMonoidForceDirtyArgName
Expand Down Expand Up @@ -241,6 +246,9 @@ buildMonoidHaddockHyperlinkSourceArgName = "haddock-hyperlink-source"
buildMonoidInstallExesArgName :: Text
buildMonoidInstallExesArgName = "copy-bins"

buildMonoidInstallCompilerToolArgName :: Text
buildMonoidInstallCompilerToolArgName = "copy-compiler-tool"

buildMonoidPreFetchArgName :: Text
buildMonoidPreFetchArgName = "prefetch"

Expand Down

0 comments on commit dae1662

Please sign in to comment.