Skip to content
Merged
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
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 <- view configL
platform <- platformGhcRelDir
compilerVersion <- envConfigCompilerVersion <$> view envConfigL
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
56 changes: 56 additions & 0 deletions test/integration/tests/2643-copy-compiler-tool/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import StackTest
import System.Directory

main :: IO ()
main = do
-- init
stack ["init", defaultResolverArg]

-- place to throw some exes
createDirectory "binny"

-- check assumptions on exec and the build flags and clean
stack ["build", "--flag", "*:build-baz"]
stack ["exec", "--", "baz-exe" ++ exeExt]
stackErr ["exec", "--", "bar-exe" ++ exeExt]
stack ["clean", "--full"]
stackErr ["exec", "--", "baz-exe" ++ exeExt]

-- install one exe normally
stack ["install",
"--local-bin-path", "./binny",
"--flag", "*:build-foo"
]

-- and install two compiler-tools, opposite ways
-- (build or install)
stack ["build",
"--local-bin-path", "./binny",
"--copy-compiler-tool",
"--flag", "*:build-bar"
]
stack ["install",
"--local-bin-path", "./binny",
"--copy-compiler-tool",
"--flag", "*:build-baz"
]

-- nuke the built things that go in .stack-work/, so we can test if
-- the installed ones exist for sure
stack ["clean", "--full"]

-- bar and baz were installed as compiler tools, should work fine
stack ["exec", "--", "bar-exe" ++ exeExt]
stack ["exec", "--", "baz-exe" ++ exeExt]

-- foo was installed as a normal exe (in .binny/, which can't be on PATH),
-- so shouldn't
stackErr ["exec", "--", "foo-exe" ++ exeExt]

-- check existences make sense
doesExist $ "./binny/foo-exe" ++ exeExt
doesNotExist $ "./binny/bar-exe" ++ exeExt
doesNotExist $ "./binny/baz-exe" ++ exeExt

-- just check that this exists
stack ["path", "--compiler-tools-bin"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = putStrLn "twotwotwo"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = putStrLn "threethreethree"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = putStrLn "oneoneone"
30 changes: 30 additions & 0 deletions test/integration/tests/2643-copy-compiler-tool/files/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2017

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Your name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions test/integration/tests/2643-copy-compiler-tool/files/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: copy-compiler-tool-test
version: 0.1.0.0
synopsis: Initial project template from stack
description: Please see README.md
homepage: http://invalid/
license: BSD3
license-file: LICENSE
author: Your name here
maintainer: your.address@example.com
-- copyright:
category: Web
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10

flag build-foo
manual: True
default: False
description: Build foo

flag build-bar
manual: True
default: False
description: Build bar

flag build-baz
manual: True
default: False
description: Build baz

executable foo-exe
main-is: Foo.hs
build-depends: base
default-language: Haskell2010
if !flag(build-foo)
buildable: False

executable bar-exe
main-is: Bar.hs
build-depends: base
default-language: Haskell2010
if !flag(build-bar)
buildable: False

executable baz-exe
main-is: Baz.hs
build-depends: base
default-language: Haskell2010
if !flag(build-baz)
buildable: False

source-repository head
type: git
location: https://invalid/