stack-2.9.3.1/doc/0000755000000000000000000000000014445022466011733 5ustar0000000000000000stack-2.9.3.1/src/0000755000000000000000000000000014331513215011744 5ustar0000000000000000stack-2.9.3.1/src/Control/0000755000000000000000000000000014266741654013405 5ustar0000000000000000stack-2.9.3.1/src/Control/Concurrent/0000755000000000000000000000000014445022466015517 5ustar0000000000000000stack-2.9.3.1/src/Data/0000755000000000000000000000000014331513215012615 5ustar0000000000000000stack-2.9.3.1/src/Data/Attoparsec/0000755000000000000000000000000014445022466014733 5ustar0000000000000000stack-2.9.3.1/src/Data/Monoid/0000755000000000000000000000000014445022466014053 5ustar0000000000000000stack-2.9.3.1/src/Network/0000755000000000000000000000000014331513215013375 5ustar0000000000000000stack-2.9.3.1/src/Network/HTTP/0000755000000000000000000000000014445022466014165 5ustar0000000000000000stack-2.9.3.1/src/Options/0000755000000000000000000000000014266741654013420 5ustar0000000000000000stack-2.9.3.1/src/Options/Applicative/0000755000000000000000000000000014445022466015651 5ustar0000000000000000stack-2.9.3.1/src/Options/Applicative/Builder/0000755000000000000000000000000014445022466017237 5ustar0000000000000000stack-2.9.3.1/src/Path/0000755000000000000000000000000014445022466012651 5ustar0000000000000000stack-2.9.3.1/src/Stack/0000755000000000000000000000000014445113031013007 5ustar0000000000000000stack-2.9.3.1/src/Stack/Build/0000755000000000000000000000000014445022466014061 5ustar0000000000000000stack-2.9.3.1/src/Stack/Config/0000755000000000000000000000000014445022466014227 5ustar0000000000000000stack-2.9.3.1/src/Stack/Constants/0000755000000000000000000000000014445022466014776 5ustar0000000000000000stack-2.9.3.1/src/Stack/Ghci/0000755000000000000000000000000014445022466013674 5ustar0000000000000000stack-2.9.3.1/src/Stack/Options/0000755000000000000000000000000014445022466014455 5ustar0000000000000000stack-2.9.3.1/src/Stack/Setup/0000755000000000000000000000000014445022466014122 5ustar0000000000000000stack-2.9.3.1/src/Stack/Storage/0000755000000000000000000000000014445106224014421 5ustar0000000000000000stack-2.9.3.1/src/Stack/Types/0000755000000000000000000000000014445022466014126 5ustar0000000000000000stack-2.9.3.1/src/Stack/Types/Config/0000755000000000000000000000000014445022466015333 5ustar0000000000000000stack-2.9.3.1/src/System/0000755000000000000000000000000014331513215013230 5ustar0000000000000000stack-2.9.3.1/src/System/Process/0000755000000000000000000000000014445022466014657 5ustar0000000000000000stack-2.9.3.1/src/main/0000755000000000000000000000000014445022466012701 5ustar0000000000000000stack-2.9.3.1/src/setup-shim/0000755000000000000000000000000014445022466014053 5ustar0000000000000000stack-2.9.3.1/src/test/0000755000000000000000000000000014445022466012734 5ustar0000000000000000stack-2.9.3.1/src/test/Stack/0000755000000000000000000000000014445022466014001 5ustar0000000000000000stack-2.9.3.1/src/test/Stack/Build/0000755000000000000000000000000014445022466015040 5ustar0000000000000000stack-2.9.3.1/src/test/Stack/Config/0000755000000000000000000000000014445022466015206 5ustar0000000000000000stack-2.9.3.1/src/test/Stack/Ghci/0000755000000000000000000000000014445022466014653 5ustar0000000000000000stack-2.9.3.1/src/test/Stack/Types/0000755000000000000000000000000014445022466015105 5ustar0000000000000000stack-2.9.3.1/src/test/Stack/Untar/0000755000000000000000000000000014331513215015061 5ustar0000000000000000stack-2.9.3.1/src/unix/0000755000000000000000000000000014445022466012740 5ustar0000000000000000stack-2.9.3.1/src/unix/System/0000755000000000000000000000000014445022466014224 5ustar0000000000000000stack-2.9.3.1/src/unix/System/Info/0000755000000000000000000000000014445022466015117 5ustar0000000000000000stack-2.9.3.1/src/unix/cbits/0000755000000000000000000000000014331513215014033 5ustar0000000000000000stack-2.9.3.1/src/windows/0000755000000000000000000000000014445022466013447 5ustar0000000000000000stack-2.9.3.1/src/windows/System/0000755000000000000000000000000014445111644014730 5ustar0000000000000000stack-2.9.3.1/src/windows/System/Info/0000755000000000000000000000000014445022466015626 5ustar0000000000000000stack-2.9.3.1/src/windows/System/Posix/0000755000000000000000000000000014445111644016032 5ustar0000000000000000stack-2.9.3.1/test/0000755000000000000000000000000014266741655012156 5ustar0000000000000000stack-2.9.3.1/test/integration/0000755000000000000000000000000014445022466014470 5ustar0000000000000000stack-2.9.3.1/test/integration/lib/0000755000000000000000000000000014445022466015236 5ustar0000000000000000stack-2.9.3.1/test/package-dump/0000755000000000000000000000000014353310352014473 5ustar0000000000000000stack-2.9.3.1/src/Control/Concurrent/Execute.hs0000644000000000000000000001407314445022466017462 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE RecordWildCards #-} -- Concurrent execution with dependencies. Types currently hard-coded for needs -- of stack, but could be generalized easily. module Control.Concurrent.Execute ( ActionType (..) , ActionId (..) , ActionContext (..) , Action (..) , Concurrency (..) , runActions ) where import Control.Concurrent.STM (retry) import Stack.Prelude import Data.List (sortBy) import qualified Data.Set as Set -- | Type representing exceptions thrown by functions exported by the -- "Control.Concurrent.Execute" module. data ExecuteException = InconsistentDependenciesBug deriving (Show, Typeable) instance Exception ExecuteException where displayException InconsistentDependenciesBug = bugReport "[S-2816]" "Inconsistent dependencies were discovered while executing your build \ \plan." data ActionType = ATBuild -- ^ Action for building a package's library and executables. If -- 'taskAllInOne' is 'True', then this will also build benchmarks -- and tests. It is 'False' when then library's benchmarks or -- test-suites have cyclic dependencies. | ATBuildFinal -- ^ Task for building the package's benchmarks and test-suites. -- Requires that the library was already built. | ATRunTests -- ^ Task for running the package's test-suites. | ATRunBenchmarks -- ^ Task for running the package's benchmarks. deriving (Show, Eq, Ord) data ActionId = ActionId !PackageIdentifier !ActionType deriving (Show, Eq, Ord) data Action = Action { actionId :: !ActionId , actionDeps :: !(Set ActionId) , actionDo :: !(ActionContext -> IO ()) , actionConcurrency :: !Concurrency } data Concurrency = ConcurrencyAllowed | ConcurrencyDisallowed deriving (Eq) data ActionContext = ActionContext { acRemaining :: !(Set ActionId) -- ^ Does not include the current action , acDownstream :: [Action] -- ^ Actions which depend on the current action , acConcurrency :: !Concurrency -- ^ Whether this action may be run concurrently with others } data ExecuteState = ExecuteState { esActions :: TVar [Action] , esExceptions :: TVar [SomeException] , esInAction :: TVar (Set ActionId) , esCompleted :: TVar Int , esKeepGoing :: Bool } runActions :: Int -- ^ threads -> Bool -- ^ keep going after one task has failed -> [Action] -> (TVar Int -> TVar (Set ActionId) -> IO ()) -- ^ progress updated -> IO [SomeException] runActions threads keepGoing actions0 withProgress = do es <- ExecuteState <$> newTVarIO (sortActions actions0) <*> newTVarIO [] <*> newTVarIO Set.empty <*> newTVarIO 0 <*> pure keepGoing _ <- async $ withProgress (esCompleted es) (esInAction es) if threads <= 1 then runActions' es else replicateConcurrently_ threads $ runActions' es readTVarIO $ esExceptions es -- | Sort actions such that those that can't be run concurrently are at -- the end. sortActions :: [Action] -> [Action] sortActions = sortBy (compareConcurrency `on` actionConcurrency) where -- NOTE: Could derive Ord. However, I like to make this explicit so -- that changes to the datatype must consider how it's affecting -- this. compareConcurrency ConcurrencyAllowed ConcurrencyDisallowed = LT compareConcurrency ConcurrencyDisallowed ConcurrencyAllowed = GT compareConcurrency _ _ = EQ runActions' :: ExecuteState -> IO () runActions' ExecuteState {..} = loop where breakOnErrs inner = do errs <- readTVar esExceptions if null errs || esKeepGoing then inner else pure $ pure () withActions inner = do as <- readTVar esActions if null as then pure $ pure () else inner as loop = join $ atomically $ breakOnErrs $ withActions $ \as -> case break (Set.null . actionDeps) as of (_, []) -> do inAction <- readTVar esInAction if Set.null inAction then do unless esKeepGoing $ modifyTVar esExceptions (toException InconsistentDependenciesBug:) pure $ pure () else retry (xs, action:ys) -> do inAction <- readTVar esInAction case actionConcurrency action of ConcurrencyAllowed -> pure () ConcurrencyDisallowed -> unless (Set.null inAction) retry let as' = xs ++ ys remaining = Set.union (Set.fromList $ map actionId as') inAction writeTVar esActions as' modifyTVar esInAction (Set.insert $ actionId action) pure $ mask $ \restore -> do eres <- try $ restore $ actionDo action ActionContext { acRemaining = remaining , acDownstream = downstreamActions (actionId action) as' , acConcurrency = actionConcurrency action } atomically $ do modifyTVar esInAction (Set.delete $ actionId action) modifyTVar esCompleted (+1) case eres of Left err -> modifyTVar esExceptions (err:) Right () -> let dropDep a = a { actionDeps = Set.delete (actionId action) $ actionDeps a } in modifyTVar esActions $ map dropDep restore loop downstreamActions :: ActionId -> [Action] -> [Action] downstreamActions aid = filter (\a -> aid `Set.member` actionDeps a) stack-2.9.3.1/src/Data/Attoparsec/Args.hs0000644000000000000000000000302714445022466016165 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} -- | Parsing of Stack command line arguments module Data.Attoparsec.Args ( EscapingMode (..) , argsParser , parseArgs , parseArgsFromString ) where import Data.Attoparsec.Text (()) import qualified Data.Attoparsec.Text as P import qualified Data.Text as T import Stack.Prelude -- | Mode for parsing escape characters. data EscapingMode = Escaping | NoEscaping deriving (Show,Eq,Enum) -- | Parse arguments using 'argsParser'. parseArgs :: EscapingMode -> Text -> Either String [String] parseArgs mode = P.parseOnly (argsParser mode) -- | Parse using 'argsParser' from a string. parseArgsFromString :: EscapingMode -> String -> Either String [String] parseArgsFromString mode = P.parseOnly (argsParser mode) . T.pack -- | A basic argument parser. It supports space-separated text, and -- string quotation with identity escaping: \x -> x. argsParser :: EscapingMode -> P.Parser [String] argsParser mode = many (P.skipSpace *> (quoted <|> unquoted)) <* P.skipSpace <* (P.endOfInput "unterminated string") where unquoted = P.many1 naked quoted = P.char '"' *> str <* P.char '"' str = many ( case mode of Escaping -> escaped <|> nonquote NoEscaping -> nonquote ) escaped = P.char '\\' *> P.anyChar nonquote = P.satisfy (/= '"') naked = P.satisfy (not . flip elem ("\" " :: String)) stack-2.9.3.1/src/Data/Attoparsec/Combinators.hs0000644000000000000000000000132514445022466017550 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} -- | More readable combinators for writing parsers. module Data.Attoparsec.Combinators ( alternating , appending , concating , pured ) where import Stack.Prelude -- | Concatenate two parsers. appending :: (Applicative f,Semigroup a) => f a -> f a -> f a appending a b = (<>) <$> a <*> b -- | Alternative parsers. alternating :: Alternative f => f a -> f a -> f a alternating a b = a <|> b -- | Pure something. pured :: (Applicative g,Applicative f) => g a -> g (f a) pured = fmap pure -- | Concating the result of an action. concating :: (Monoid m,Applicative f) => f [m] -> f m concating = fmap mconcat stack-2.9.3.1/src/Data/Attoparsec/Interpreter.hs0000644000000000000000000001344614445022466017602 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {- | This module implements parsing of additional arguments embedded in a comment when Stack is invoked as a script interpreter ===Specifying arguments in script interpreter mode @/stack/@ can execute a Haskell source file using @/runghc/@ and if required it can also install and setup the compiler and any package dependencies automatically. For using a Haskell source file as an executable script on a Unix like OS, the first line of the file must specify @stack@ as the interpreter using a shebang directive e.g. > #!/usr/bin/env stack Additional arguments can be specified in a haskell comment following the @#!@ line. The contents inside the comment must be a single valid stack command line, starting with @stack@ as the command and followed by the options to use for executing this file. The comment must be on the line immediately following the @#!@ line. The comment must start in the first column of the line. When using a block style comment the command can be split on multiple lines. Here is an example of a single line comment: > #!/usr/bin/env stack > -- stack --resolver lts-3.14 --install-ghc runghc --package random Here is an example of a multi line block comment: @ #!\/usr\/bin\/env stack {\- stack --resolver lts-3.14 --install-ghc runghc --package random -\} @ When the @#!@ line is not present, the file can still be executed using @stack \@ command if the file starts with a valid stack interpreter comment. This can be used to execute the file on Windows for example. Nested block comments are not supported. -} module Data.Attoparsec.Interpreter ( interpreterArgsParser -- for unit tests , getInterpreterArgs ) where import Data.Attoparsec.Args import Data.Attoparsec.Text (()) import qualified Data.Attoparsec.Text as P import Data.Char (isSpace) import Conduit import Data.Conduit.Attoparsec import Data.List (intercalate) import Data.Text (pack) import Stack.Prelude import System.FilePath (takeExtension) import System.IO (hPutStrLn) -- | Parser to extract the Stack command line embedded inside a comment -- after validating the placement and formatting rules for a valid -- interpreter specification. interpreterArgsParser :: Bool -> String -> P.Parser String interpreterArgsParser isLiterate progName = P.option "" sheBangLine *> interpreterComment where sheBangLine = P.string "#!" *> P.manyTill P.anyChar P.endOfLine commentStart psr = (psr (progName ++ " options comment")) *> P.skipSpace *> (P.string (pack progName) show progName) -- Treat newlines as spaces inside the block comment anyCharNormalizeSpace = let normalizeSpace c = if isSpace c then ' ' else c in P.satisfyWith normalizeSpace $ const True comment start end = commentStart start *> ((end >> pure "") <|> (P.space *> (P.manyTill anyCharNormalizeSpace end "-}"))) horizontalSpace = P.satisfy P.isHorizontalSpace lineComment = comment "--" (P.endOfLine <|> P.endOfInput) literateLineComment = comment (">" *> horizontalSpace *> "--") (P.endOfLine <|> P.endOfInput) blockComment = comment "{-" (P.string "-}") literateBlockComment = (">" *> horizontalSpace *> "{-") *> P.skipMany (("" <$ horizontalSpace) <|> (P.endOfLine *> ">")) *> (P.string (pack progName) progName) *> P.manyTill' (P.satisfy (not . P.isEndOfLine) <|> (' ' <$ (P.endOfLine *> ">" ">"))) "-}" interpreterComment = if isLiterate then literateLineComment <|> literateBlockComment else lineComment <|> blockComment -- | Extract Stack arguments from a correctly placed and correctly formatted -- comment when it is being used as an interpreter getInterpreterArgs :: String -> IO [String] getInterpreterArgs file = do eArgStr <- withSourceFile file parseFile case eArgStr of Left err -> handleFailure $ decodeError err Right str -> parseArgStr str where parseFile src = runConduit $ src .| decodeUtf8C .| sinkParserEither (interpreterArgsParser isLiterate stackProgName) isLiterate = takeExtension file == ".lhs" -- FIXME We should print anything only when explicit verbose mode is -- specified by the user on command line. But currently the -- implementation does not accept or parse any command line flags in -- interpreter mode. We can only invoke the interpreter as -- "stack " strictly without any options. stackWarn s = hPutStrLn stderr $ stackProgName ++ ": WARNING! " ++ s handleFailure err = do mapM_ stackWarn (lines err) stackWarn "Missing or unusable Stack options specification" stackWarn "Using runghc without any additional Stack options" pure ["runghc"] parseArgStr str = case P.parseOnly (argsParser Escaping) (pack str) of Left err -> handleFailure ("Error parsing command specified in the " ++ "Stack options comment: " ++ err) Right [] -> handleFailure "Empty argument list in Stack options comment" Right args -> pure args decodeError e = case e of ParseError ctxs _ (Position l col _) -> if null ctxs then "Parse error" else ("Expecting " ++ intercalate " or " ctxs) ++ " at line " ++ show l ++ ", column " ++ show col DivergentParser -> "Divergent parser" stack-2.9.3.1/src/Data/Monoid/Map.hs0000644000000000000000000000121314445022466015121 0ustar0000000000000000{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} module Data.Monoid.Map ( MonoidMap (..) ) where import qualified Data.Map as M import Stack.Prelude -- | Utility newtype wrapper to make Map's Monoid also use the -- element's Monoid. newtype MonoidMap k a = MonoidMap (Map k a) deriving (Eq, Functor, Generic, Ord, Read, Show) instance (Ord k, Semigroup a) => Semigroup (MonoidMap k a) where MonoidMap mp1 <> MonoidMap mp2 = MonoidMap (M.unionWith (<>) mp1 mp2) instance (Ord k, Semigroup a) => Monoid (MonoidMap k a) where mappend = (<>) mempty = MonoidMap mempty stack-2.9.3.1/src/Network/HTTP/StackClient.hs0000644000000000000000000002277614445022466016743 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} -- | -- Wrapper functions of 'Network.HTTP.Simple' and 'Network.HTTP.Client' to -- add the 'User-Agent' HTTP request header to each request. module Network.HTTP.StackClient ( httpJSON , httpLbs , httpNoBody , httpSink , withResponse , setRequestCheckStatus , setRequestMethod , setRequestHeader , addRequestHeader , setRequestBody , getResponseHeaders , getResponseBody , getResponseStatusCode , parseRequest , getUri , path , checkResponse , parseUrlThrow , requestHeaders , getGlobalManager , applyDigestAuth , displayDigestAuthException , Request , RequestBody (RequestBodyBS, RequestBodyLBS) , Response (..) , HttpException (..) , HttpExceptionContent (..) , notFound404 , hAccept , hContentLength , hContentMD5 , methodPut , formDataBody , partFileRequestBody , partBS , partLBS , setGitHubHeaders , download , redownload , verifiedDownload , verifiedDownloadWithProgress , CheckHexDigest (..) , DownloadRequest , drRetryPolicyDefault , VerifiedDownloadException (..) , HashCheck (..) , mkDownloadRequest , setHashChecks , setLengthCheck , setRetryPolicy , setForceDownload ) where import Control.Monad.State ( get, put, modify ) import Data.Aeson ( FromJSON ) import qualified Data.ByteString as Strict import Data.Conduit ( ConduitM, ConduitT, awaitForever, (.|), yield, await ) import Data.Conduit.Lift ( evalStateC ) import qualified Data.Conduit.List as CL import Data.Monoid ( Sum (..) ) import qualified Data.Text as T import Data.Time.Clock ( NominalDiffTime, diffUTCTime, getCurrentTime ) import Network.HTTP.Client ( HttpException (..), HttpExceptionContent (..), Request , RequestBody (..), Response (..), checkResponse, getUri , parseRequest, parseUrlThrow, path ) import Network.HTTP.Client.MultipartFormData ( formDataBody, partBS, partFileRequestBody, partLBS ) import Network.HTTP.Client.TLS ( applyDigestAuth, displayDigestAuthException , getGlobalManager ) import Network.HTTP.Conduit ( requestHeaders ) import Network.HTTP.Download hiding ( download, redownload, verifiedDownload ) import qualified Network.HTTP.Download as Download import Network.HTTP.Simple ( addRequestHeader, getResponseBody, getResponseHeaders , getResponseStatusCode, setRequestBody , setRequestCheckStatus, setRequestHeader, setRequestMethod ) import qualified Network.HTTP.Simple import Network.HTTP.Types ( hAccept, hContentLength, hContentMD5, methodPut , notFound404 ) import Path import Prelude ( until, (!!) ) import RIO import RIO.PrettyPrint ( HasTerm ) import Text.Printf ( printf ) setUserAgent :: Request -> Request setUserAgent = setRequestHeader "User-Agent" ["The Haskell Stack"] httpJSON :: (MonadIO m, FromJSON a) => Request -> m (Response a) httpJSON = Network.HTTP.Simple.httpJSON . setUserAgent httpLbs :: MonadIO m => Request -> m (Response LByteString) httpLbs = Network.HTTP.Simple.httpLbs . setUserAgent httpNoBody :: MonadIO m => Request -> m (Response ()) httpNoBody = Network.HTTP.Simple.httpNoBody . setUserAgent httpSink :: MonadUnliftIO m => Request -> (Response () -> ConduitM Strict.ByteString Void m a) -> m a httpSink = Network.HTTP.Simple.httpSink . setUserAgent withResponse :: (MonadUnliftIO m, MonadIO n) => Request -> (Response (ConduitM i Strict.ByteString n ()) -> m a) -> m a withResponse = Network.HTTP.Simple.withResponse . setUserAgent -- | Set the user-agent request header setGitHubHeaders :: Request -> Request setGitHubHeaders = setRequestHeader "Accept" ["application/vnd.github.v3+json"] -- | Download the given URL to the given location. If the file already exists, -- no download is performed. Otherwise, creates the parent directory, downloads -- to a temporary file, and on file download completion moves to the -- appropriate destination. -- -- Throws an exception if things go wrong download :: HasTerm env => Request -> Path Abs File -- ^ destination -> RIO env Bool -- ^ Was a downloaded performed (True) or did the file already exist (False)? download req dest = Download.download (setUserAgent req) dest -- | Same as 'download', but will download a file a second time if it is already present. -- -- Returns 'True' if the file was downloaded, 'False' otherwise redownload :: HasTerm env => Request -> Path Abs File -- ^ destination -> RIO env Bool redownload req dest = Download.redownload (setUserAgent req) dest -- | Copied and extended version of Network.HTTP.Download.download. -- -- Has the following additional features: -- * Verifies that response content-length header (if present) -- matches expected length -- * Limits the download to (close to) the expected # of bytes -- * Verifies that the expected # bytes were downloaded (not too few) -- * Verifies md5 if response includes content-md5 header -- * Verifies the expected hashes -- -- Throws VerifiedDownloadException. -- Throws IOExceptions related to file system operations. -- Throws HttpException. verifiedDownload :: HasTerm env => DownloadRequest -> Path Abs File -- ^ destination -> (Maybe Integer -> ConduitM ByteString Void (RIO env) ()) -- ^ custom hook to observe progress -> RIO env Bool -- ^ Whether a download was performed verifiedDownload dr destpath progressSink = Download.verifiedDownload dr' destpath progressSink where dr' = modifyRequest setUserAgent dr verifiedDownloadWithProgress :: HasTerm env => DownloadRequest -> Path Abs File -> Text -> Maybe Int -> RIO env Bool verifiedDownloadWithProgress req destpath lbl msize = verifiedDownload req destpath (chattyDownloadProgress lbl msize) chattyDownloadProgress :: ( HasLogFunc env , MonadIO m , MonadReader env m ) => Text -> Maybe Int -> f -> ConduitT ByteString c m () chattyDownloadProgress label mtotalSize _ = do _ <- logSticky $ RIO.display label <> ": download has begun" CL.map (Sum . Strict.length) .| chunksOverTime 1 .| go where go = evalStateC 0 $ awaitForever $ \(Sum size) -> do modify (+ size) totalSoFar <- get logSticky $ fromString $ case mtotalSize of Nothing -> chattyProgressNoTotal totalSoFar Just 0 -> chattyProgressNoTotal totalSoFar Just totalSize -> chattyProgressWithTotal totalSoFar totalSize -- Example: ghc: 42.13 KiB downloaded... chattyProgressNoTotal totalSoFar = printf ("%s: " <> bytesfmt "%7.2f" totalSoFar <> " downloaded...") (T.unpack label) -- Example: ghc: 50.00 MiB / 100.00 MiB (50.00%) downloaded... chattyProgressWithTotal totalSoFar total = printf ("%s: " <> bytesfmt "%7.2f" totalSoFar <> " / " <> bytesfmt "%.2f" total <> " (%6.2f%%) downloaded...") (T.unpack label) percentage where percentage :: Double percentage = fromIntegral totalSoFar / fromIntegral total * 100 -- | Given a printf format string for the decimal part and a number of -- bytes, formats the bytes using an appropriate unit and returns the -- formatted string. -- -- >>> bytesfmt "%.2" 512368 -- "500.359375 KiB" bytesfmt :: Integral a => String -> a -> String bytesfmt formatter bs = printf (formatter <> " %s") (fromIntegral (signum bs) * dec :: Double) (bytesSuffixes !! i) where (dec,i) = getSuffix (abs bs) getSuffix n = until p (\(x,y) -> (x / 1024, y+1)) (fromIntegral n,0) where p (n',numDivs) = n' < 1024 || numDivs == (length bytesSuffixes - 1) bytesSuffixes :: [String] bytesSuffixes = ["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"] -- Await eagerly (collect with monoidal append), -- but space out yields by at least the given amount of time. -- The final yield may come sooner, and may be a superfluous mempty. -- Note that Integer and Float literals can be turned into NominalDiffTime -- (these literals are interpreted as "seconds") chunksOverTime :: (Monoid a, Semigroup a, MonadIO m) => NominalDiffTime -> ConduitM a a m () chunksOverTime diff = do currentTime <- liftIO getCurrentTime evalStateC (currentTime, mempty) go where -- State is a tuple of: -- * the last time a yield happened (or the beginning of the sink) -- * the accumulated awaits since the last yield go = await >>= \case Nothing -> do (_, acc) <- get yield acc Just a -> do (lastTime, acc) <- get let acc' = acc <> a currentTime <- liftIO getCurrentTime if diff < diffUTCTime currentTime lastTime then put (currentTime, mempty) >> yield acc' else put (lastTime, acc') go stack-2.9.3.1/src/Options/Applicative/Args.hs0000644000000000000000000000255214353310533017076 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} -- | Accepting arguments to be passed through to a sub-process. module Options.Applicative.Args ( argsArgument , argsOption , cmdOption ) where import Data.Attoparsec.Args ( EscapingMode (..), parseArgsFromString ) import qualified Options.Applicative as O import Stack.Prelude -- | An argument which accepts a list of arguments -- e.g. @--ghc-options="-X P.hs \"this\""@. argsArgument :: O.Mod O.ArgumentFields [String] -> O.Parser [String] argsArgument = O.argument (do s <- O.str either O.readerError pure (parseArgsFromString Escaping s)) -- | An option which accepts a list of arguments -- e.g. @--ghc-options="-X P.hs \"this\""@. argsOption :: O.Mod O.OptionFields [String] -> O.Parser [String] argsOption = O.option (do s <- O.str either O.readerError pure (parseArgsFromString Escaping s)) -- | An option which accepts a command and a list of arguments -- e.g. @--exec "echo hello world"@ cmdOption :: O.Mod O.OptionFields (String, [String]) -> O.Parser (String, [String]) cmdOption = O.option (do s <- O.str xs <- either O.readerError pure (parseArgsFromString Escaping s) case xs of [] -> O.readerError "Must provide a command" x:xs' -> pure (x, xs')) stack-2.9.3.1/src/Options/Applicative/Builder/Extra.hs0000644000000000000000000003102114445022466020653 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Extra functions for optparse-applicative. module Options.Applicative.Builder.Extra ( boolFlags , boolFlagsNoDefault , firstBoolFlagsNoDefault , firstBoolFlagsTrue , firstBoolFlagsFalse , enableDisableFlags , enableDisableFlagsNoDefault , extraHelpOption , execExtraHelp , textOption , textArgument , optionalFirst , optionalFirstTrue , optionalFirstFalse , absFileOption , relFileOption , absDirOption , relDirOption , eitherReader' , fileCompleter , fileExtCompleter , dirCompleter , PathCompleterOpts (..) , defaultPathCompleterOpts , pathCompleterWith , unescapeBashArg , showHelpText ) where import Data.List ( isPrefixOf ) import qualified Data.Text as T import Options.Applicative ( ArgumentFields, Completer, FlagFields, Mod, OptionFields , ParseError (..), Parser, ReadM, abortOption, argument , completer, eitherReader, execParser, flag', fullDesc, help , hidden, idm, info, infoOption, internal, long, metavar , mkCompleter, option, progDesc, strArgument ) import Options.Applicative.Types ( readerAsk ) import Path ( parseAbsDir, parseAbsFile, parseRelDir, parseRelFile ) import Stack.Prelude import System.Directory ( doesDirectoryExist, getCurrentDirectory , getDirectoryContents ) import System.Environment ( withArgs ) import System.FilePath ( (), isRelative, splitFileName, takeBaseName , takeExtension ) -- | Type representing exceptions thrown by functions exported by the -- "Options.Applicative.Builder.Extra" module. data OptionsApplicativeExtraException = FlagNotFoundBug deriving (Show, Typeable) instance Exception OptionsApplicativeExtraException where displayException FlagNotFoundBug = "Error: [S-2797]\n" ++ "The impossible happened! No valid flags found in \ \enableDisableFlagsNoDefault. Please report this bug at Stack's \ \repository." -- | Enable/disable flags for a 'Bool'. boolFlags :: Bool -- ^ Default value -> String -- ^ Flag name -> String -- ^ Help suffix -> Mod FlagFields Bool -> Parser Bool boolFlags defaultValue name helpSuffix = enableDisableFlags defaultValue True False name $ concat [ helpSuffix , " (default: " , if defaultValue then "enabled" else "disabled" , ")" ] -- | Enable/disable flags for a 'Bool', without a default case (to allow -- chaining with '<|>'). boolFlagsNoDefault :: String -- ^ Flag name -> String -- ^ Help suffix -> Mod FlagFields Bool -> Parser Bool boolFlagsNoDefault = enableDisableFlagsNoDefault True False -- | Flag with no default of True or False firstBoolFlagsNoDefault :: String -> String -> Mod FlagFields (Maybe Bool) -> Parser (First Bool) firstBoolFlagsNoDefault name helpSuffix mod' = First <$> enableDisableFlags Nothing (Just True) (Just False) name helpSuffix mod' -- | Flag with a Semigroup instance and a default of True firstBoolFlagsTrue :: String -> String -> Mod FlagFields FirstTrue -> Parser FirstTrue firstBoolFlagsTrue name helpSuffix = enableDisableFlags mempty (FirstTrue (Just True)) (FirstTrue (Just False)) name $ helpSuffix ++ " (default: enabled)" -- | Flag with a Semigroup instance and a default of False firstBoolFlagsFalse :: String -> String -> Mod FlagFields FirstFalse -> Parser FirstFalse firstBoolFlagsFalse name helpSuffix = enableDisableFlags mempty (FirstFalse (Just True)) (FirstFalse (Just False)) name $ helpSuffix ++ " (default: disabled)" -- | Enable/disable flags for any type. enableDisableFlags :: a -- ^ Default value -> a -- ^ Enabled value -> a -- ^ Disabled value -> String -- ^ Name -> String -- ^ Help suffix -> Mod FlagFields a -> Parser a enableDisableFlags defaultValue enabledValue disabledValue name helpSuffix mods = enableDisableFlagsNoDefault enabledValue disabledValue name helpSuffix mods <|> pure defaultValue -- | Enable/disable flags for any type, without a default (to allow chaining with '<|>') enableDisableFlagsNoDefault :: a -- ^ Enabled value -> a -- ^ Disabled value -> String -- ^ Name -> String -- ^ Help suffix -> Mod FlagFields a -> Parser a enableDisableFlagsNoDefault enabledValue disabledValue name helpSuffix mods = last <$> some ( ( flag' enabledValue ( hidden <> internal <> long name <> help helpSuffix <> mods ) <|> flag' disabledValue ( hidden <> internal <> long ("no-" ++ name) <> help helpSuffix <> mods ) ) <|> flag' disabledValue ( long ("[no-]" ++ name) <> help ("Enable/disable " ++ helpSuffix) <> mods ) ) where last xs = case reverse xs of [] -> impureThrow FlagNotFoundBug x:_ -> x -- | Show an extra help option (e.g. @--docker-help@ shows help for all -- @--docker*@ args). -- -- To actually have that help appear, use 'execExtraHelp' before executing the -- main parser. extraHelpOption :: Bool -- ^ Hide from the brief description? -> String -- ^ Program name, e.g. @"stack"@ -> String -- ^ Option glob expression, e.g. @"docker*"@ -> String -- ^ Help option name, e.g. @"docker-help"@ -> Parser (a -> a) extraHelpOption hide progName fakeName helpName = infoOption (optDesc' ++ ".") (long helpName <> hidden <> internal) <*> infoOption (optDesc' ++ ".") ( long fakeName <> help optDesc' <> (if hide then hidden <> internal else idm) ) where optDesc' = concat [ "Run '" , takeBaseName progName , " --" , helpName , "' for details" ] -- | Display extra help if extra help option passed in arguments. -- -- Since optparse-applicative doesn't allow an arbitrary IO action for an -- 'abortOption', this was the best way I found that doesn't require manually -- formatting the help. execExtraHelp :: [String] -- ^ Command line arguments -> String -- ^ Extra help option name, e.g. @"docker-help"@ -> Parser a -- ^ Option parser for the relevant command -> String -- ^ Option description -> IO () execExtraHelp args helpOpt parser pd = when (args == ["--" ++ helpOpt]) $ withArgs ["--help"] $ do _ <- execParser (info ( hiddenHelper <*> ( (,) <$> parser <*> some (strArgument (metavar "OTHER ARGUMENTS") :: Parser String) ) ) (fullDesc <> progDesc pd)) pure () where hiddenHelper = abortOption showHelpText (long "help" <> hidden <> internal) -- | 'option', specialized to 'Text'. textOption :: Mod OptionFields Text -> Parser Text textOption = option (T.pack <$> readerAsk) -- | 'argument', specialized to 'Text'. textArgument :: Mod ArgumentFields Text -> Parser Text textArgument = argument (T.pack <$> readerAsk) -- | Like 'optional', but returning a 'First'. optionalFirst :: Alternative f => f a -> f (First a) optionalFirst = fmap First . optional -- | Like 'optional', but returning a 'FirstTrue'. optionalFirstTrue :: Alternative f => f Bool -> f FirstTrue optionalFirstTrue = fmap FirstTrue . optional -- | Like 'optional', but returning a 'FirstFalse'. optionalFirstFalse :: Alternative f => f Bool -> f FirstFalse optionalFirstFalse = fmap FirstFalse . optional absFileOption :: Mod OptionFields (Path Abs File) -> Parser (Path Abs File) absFileOption mods = option (eitherReader' parseAbsFile) $ completer (pathCompleterWith defaultPathCompleterOpts { pcoRelative = False }) <> mods relFileOption :: Mod OptionFields (Path Rel File) -> Parser (Path Rel File) relFileOption mods = option (eitherReader' parseRelFile) $ completer (pathCompleterWith defaultPathCompleterOpts { pcoAbsolute = False }) <> mods absDirOption :: Mod OptionFields (Path Abs Dir) -> Parser (Path Abs Dir) absDirOption mods = option (eitherReader' parseAbsDir) $ completer ( pathCompleterWith defaultPathCompleterOpts { pcoRelative = False , pcoFileFilter = const False } ) <> mods relDirOption :: Mod OptionFields (Path Rel Dir) -> Parser (Path Rel Dir) relDirOption mods = option (eitherReader' parseRelDir) $ completer ( pathCompleterWith defaultPathCompleterOpts { pcoAbsolute = False , pcoFileFilter = const False } ) <> mods -- | Like 'eitherReader', but accepting any @'Show' e@ on the 'Left'. eitherReader' :: Show e => (String -> Either e a) -> ReadM a eitherReader' f = eitherReader (mapLeft show . f) data PathCompleterOpts = PathCompleterOpts { pcoAbsolute :: Bool , pcoRelative :: Bool , pcoRootDir :: Maybe FilePath , pcoFileFilter :: FilePath -> Bool , pcoDirFilter :: FilePath -> Bool } defaultPathCompleterOpts :: PathCompleterOpts defaultPathCompleterOpts = PathCompleterOpts { pcoAbsolute = True , pcoRelative = True , pcoRootDir = Nothing , pcoFileFilter = const True , pcoDirFilter = const True } fileCompleter :: Completer fileCompleter = pathCompleterWith defaultPathCompleterOpts fileExtCompleter :: [String] -> Completer fileExtCompleter exts = pathCompleterWith defaultPathCompleterOpts { pcoFileFilter = (`elem` exts) . takeExtension } dirCompleter :: Completer dirCompleter = pathCompleterWith defaultPathCompleterOpts { pcoFileFilter = const False } pathCompleterWith :: PathCompleterOpts -> Completer pathCompleterWith PathCompleterOpts {..} = mkCompleter $ \inputRaw -> do -- Unescape input, to handle single and double quotes. Note that the -- results do not need to be re-escaped, due to some fiddly bash -- magic. let input = unescapeBashArg inputRaw let (inputSearchDir0, searchPrefix) = splitFileName input inputSearchDir = if inputSearchDir0 == "./" then "" else inputSearchDir0 msearchDir <- case (isRelative inputSearchDir, pcoAbsolute, pcoRelative) of (True, _, True) -> do rootDir <- maybe getCurrentDirectory pure pcoRootDir pure $ Just (rootDir inputSearchDir) (False, True, _) -> pure $ Just inputSearchDir _ -> pure Nothing case msearchDir of Nothing | input == "" && pcoAbsolute -> pure ["/"] | otherwise -> pure [] Just searchDir -> do entries <- getDirectoryContents searchDir `catch` \(_ :: IOException) -> pure [] fmap catMaybes $ forM entries $ \entry -> -- Skip . and .. unless user is typing . or .. if entry `elem` ["..", "."] && searchPrefix `notElem` ["..", "."] then pure Nothing else if searchPrefix `isPrefixOf` entry then do let path = searchDir entry case (pcoFileFilter path, pcoDirFilter path) of (True, True) -> pure $ Just (inputSearchDir entry) (fileAllowed, dirAllowed) -> do isDir <- doesDirectoryExist path if (if isDir then dirAllowed else fileAllowed) then pure $ Just (inputSearchDir entry) else pure Nothing else pure Nothing unescapeBashArg :: String -> String unescapeBashArg ('\'' : rest) = rest unescapeBashArg ('\"' : rest) = go rest where pattern = "$`\"\\\n" :: String go [] = [] go ('\\' : x : xs) | x `elem` pattern = x : xs | otherwise = '\\' : x : go xs go (x : xs) = x : go xs unescapeBashArg input = go input where go [] = [] go ('\\' : x : xs) = x : go xs go (x : xs) = x : go xs showHelpText :: ParseError showHelpText = ShowHelpText Nothing stack-2.9.3.1/src/Options/Applicative/Complicated.hs0000644000000000000000000001506314445022466020436 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} -- | Simple interface to complicated program arguments. -- -- This is a "fork" of the @optparse-simple@ package that has some workarounds -- for optparse-applicative issues that become problematic with programs that -- have many options and subcommands. Because it makes the interface more -- complex, these workarounds are not suitable for pushing upstream to -- optparse-applicative. module Options.Applicative.Complicated ( addCommand , addSubCommands , complicatedOptions , complicatedParser ) where import Control.Monad.Trans.Except ( runExceptT ) import Control.Monad.Trans.Writer ( runWriter, tell ) import Options.Applicative ( CommandFields, Parser, ParserFailure, ParserHelp , ParserInfo (..), ParserResult (..), (<**>), abortOption , command, execParserPure, footer, fullDesc , handleParseResult, header, help, info, infoOption, long , metavar, noBacktrack, prefs, progDesc, showHelpOnEmpty ) import Options.Applicative.Builder.Extra ( showHelpText ) import Options.Applicative.Builder.Internal ( Mod (..), mkCommand, mkParser ) import Options.Applicative.Types ( OptReader (..) ) import Stack.Prelude import Stack.Types.Config ( AddCommand, GlobalOptsMonoid, Runner ) import System.Environment ( getArgs ) -- | Generate and execute a complicated options parser. complicatedOptions :: Version -- ^ numeric version -> Maybe String -- ^ version string -> String -- ^ Hpack numeric version, as string -> String -- ^ header -> String -- ^ program description (displayed between usage and options listing in the -- help output) -> String -- ^ footer -> Parser GlobalOptsMonoid -- ^ common settings -> Maybe ( ParserFailure ParserHelp -> [String] -> IO (GlobalOptsMonoid, (RIO Runner (), GlobalOptsMonoid)) ) -- ^ optional handler for parser failure; 'handleParseResult' is called by -- default -> AddCommand -- ^ commands (use 'addCommand') -> IO (GlobalOptsMonoid, RIO Runner ()) complicatedOptions numericVersion stringVersion numericHpackVersion h pd footerStr commonParser mOnFailure commandParser = do args <- getArgs (a, (b, c)) <- let parserPrefs = prefs $ noBacktrack <> showHelpOnEmpty in case execParserPure parserPrefs parser args of -- call onFailure handler if it's present and parsing options failed Failure f | Just onFailure <- mOnFailure -> onFailure f args parseResult -> handleParseResult parseResult pure (mappend c a, b) where parser = info ( helpOption <*> versionOptions <*> complicatedParser "COMMAND|FILE" commonParser commandParser ) desc desc = fullDesc <> header h <> progDesc pd <> footer footerStr versionOptions = case stringVersion of Nothing -> versionOption (versionString numericVersion) Just s -> versionOption s <*> numericVersionOption <*> numericHpackVersionOption versionOption s = infoOption s ( long "version" <> help "Show version" ) numericVersionOption = infoOption (versionString numericVersion) ( long "numeric-version" <> help "Show only version number" ) numericHpackVersionOption = infoOption numericHpackVersion ( long "hpack-numeric-version" <> help "Show only Hpack's version number" ) -- | Add a command to the options dispatcher. addCommand :: String -- ^ command string -> String -- ^ title of command -> String -- ^ footer of command help -> (opts -> RIO Runner ()) -- ^ constructor to wrap up command in common data type -> (opts -> GlobalOptsMonoid -> GlobalOptsMonoid) -- ^ extend common settings from local settings -> Parser GlobalOptsMonoid -- ^ common parser -> Parser opts -- ^ command parser -> AddCommand addCommand cmd title footerStr constr extendCommon = addCommand' cmd title footerStr (\a c -> (constr a, extendCommon a c)) -- | Add a command that takes sub-commands to the options dispatcher. addSubCommands :: String -- ^ command string -> String -- ^ title of command -> String -- ^ footer of command help -> Parser GlobalOptsMonoid -- ^ common parser -> AddCommand -- ^ sub-commands (use 'addCommand') -> AddCommand addSubCommands cmd title footerStr commonParser commandParser = addCommand' cmd title footerStr (\(c1, (a, c2)) c3 -> (a, mconcat [c3, c2, c1])) commonParser (complicatedParser "COMMAND" commonParser commandParser) -- | Add a command to the options dispatcher. addCommand' :: String -- ^ command string -> String -- ^ title of command -> String -- ^ footer of command help -> (opts -> GlobalOptsMonoid -> (RIO Runner (),GlobalOptsMonoid)) -- ^ constructor to wrap up command in common data type -> Parser GlobalOptsMonoid -- ^ common parser -> Parser opts -- ^ command parser -> AddCommand addCommand' cmd title footerStr constr commonParser inner = lift $ tell $ command cmd ( info (constr <$> inner <*> commonParser) (progDesc title <> footer footerStr) ) -- | Generate a complicated options parser. complicatedParser :: String -- ^ metavar for the sub-command -> Parser GlobalOptsMonoid -- ^ common settings -> AddCommand -- ^ commands (use 'addCommand') -> Parser (GlobalOptsMonoid, (RIO Runner (), GlobalOptsMonoid)) complicatedParser commandMetavar commonParser commandParser = (,) <$> commonParser <*> case runWriter (runExceptT commandParser) of (Right (), d) -> hsubparser' commandMetavar d (Left b, _) -> pure (b, mempty) -- | Subparser with @--help@ argument. Borrowed with slight modification -- from Options.Applicative.Extra. hsubparser' :: String -> Mod CommandFields a -> Parser a hsubparser' commandMetavar m = mkParser d g rdr where Mod _ d g = metavar commandMetavar `mappend` m (groupName, cmds, subs) = mkCommand m rdr = CmdReader groupName cmds (fmap add_helper . subs) add_helper pinfo = pinfo { infoParser = infoParser pinfo <**> helpOption } -- | Non-hidden help option. helpOption :: Parser (a -> a) helpOption = abortOption showHelpText $ long "help" <> help "Show this help text" stack-2.9.3.1/src/Path/CheckInstall.hs0000644000000000000000000000434614445022466015560 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} module Path.CheckInstall ( warnInstallSearchPathIssues ) where import Control.Monad.Extra ( anyM, (&&^) ) import qualified Data.Text as T import Stack.Prelude import Stack.Types.Config import qualified System.Directory as D import qualified System.FilePath as FP -- | Checks if the installed executable will be available on the user's -- PATH. This doesn't use @envSearchPath menv@ because it includes paths -- only visible when running in the Stack environment. warnInstallSearchPathIssues :: HasConfig env => FilePath -> [Text] -> RIO env () warnInstallSearchPathIssues destDir installed = do searchPath <- liftIO FP.getSearchPath destDirIsInPATH <- liftIO $ anyM (\dir -> D.doesDirectoryExist dir &&^ fmap (FP.equalFilePath destDir) (D.canonicalizePath dir)) searchPath if destDirIsInPATH then forM_ installed $ \exe -> do mexePath <- (liftIO . D.findExecutable . T.unpack) exe case mexePath of Just exePath -> do exeDir <- (liftIO . fmap FP.takeDirectory . D.canonicalizePath) exePath unless (exeDir `FP.equalFilePath` destDir) $ do prettyWarnL [ flow "The" , style File . fromString . T.unpack $ exe , flow "executable found on the PATH environment variable is" , style File . fromString $ exePath , flow "and not the version that was just installed." , flow "This means that" , style File . fromString . T.unpack $ exe , "calls on the command line will not use this version." ] Nothing -> do prettyWarnL [ flow "Installation path" , style Dir . fromString $ destDir , flow "is on the PATH but the" , style File . fromString . T.unpack $ exe , flow "executable that was just installed could not be found on the PATH." ] else do prettyWarnL [ flow "Installation path " , style Dir . fromString $ destDir , "not found on the PATH environment variable." ] stack-2.9.3.1/src/Path/Extra.hs0000644000000000000000000001127514445022466014276 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ViewPatterns #-} -- | Extra Path utilities. module Path.Extra ( toFilePathNoTrailingSep , dropRoot , parseCollapsedAbsDir , parseCollapsedAbsFile , concatAndCollapseAbsDir , rejectMissingFile , rejectMissingDir , pathToByteString , pathToLazyByteString , pathToText , tryGetModificationTime ) where import Data.Time ( UTCTime ) import Path import Path.IO import Path.Internal ( Path (..) ) import RIO import System.IO.Error ( isDoesNotExistError ) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy.Char8 as BSL import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified System.FilePath as FP -- | Convert to FilePath but don't add a trailing slash. toFilePathNoTrailingSep :: Path loc Dir -> FilePath toFilePathNoTrailingSep = FP.dropTrailingPathSeparator . toFilePath -- | Collapse intermediate "." and ".." directories from path, then parse -- it with 'parseAbsDir'. -- (probably should be moved to the Path module) parseCollapsedAbsDir :: MonadThrow m => FilePath -> m (Path Abs Dir) parseCollapsedAbsDir = parseAbsDir . collapseFilePath -- | Collapse intermediate "." and ".." directories from path, then parse -- it with 'parseAbsFile'. -- (probably should be moved to the Path module) parseCollapsedAbsFile :: MonadThrow m => FilePath -> m (Path Abs File) parseCollapsedAbsFile = parseAbsFile . collapseFilePath -- | Add a relative FilePath to the end of a Path -- We can't parse the FilePath first because we need to account for ".." -- in the FilePath (#2895) concatAndCollapseAbsDir :: MonadThrow m => Path Abs Dir -> FilePath -> m (Path Abs Dir) concatAndCollapseAbsDir base rel = parseCollapsedAbsDir (toFilePath base FP. rel) -- | Collapse intermediate "." and ".." directories from a path. -- -- > collapseFilePath "./foo" == "foo" -- > collapseFilePath "/bar/../baz" == "/baz" -- > collapseFilePath "/../baz" == "/../baz" -- > collapseFilePath "parent/foo/baz/../bar" == "parent/foo/bar" -- > collapseFilePath "parent/foo/baz/../../bar" == "parent/bar" -- > collapseFilePath "parent/foo/.." == "parent" -- > collapseFilePath "/parent/foo/../../bar" == "/bar" -- -- (adapted from @Text.Pandoc.Shared@) collapseFilePath :: FilePath -> FilePath collapseFilePath = FP.joinPath . reverse . foldl' go [] . FP.splitDirectories where go rs "." = rs go r@(p:rs) ".." = case p of ".." -> "..":r (checkPathSeparator -> True) -> "..":r _ -> rs go _ (checkPathSeparator -> True) = [[FP.pathSeparator]] go rs x = x:rs checkPathSeparator [x] = FP.isPathSeparator x checkPathSeparator _ = False -- | Drop the root (either @\/@ on POSIX or @C:\\@, @D:\\@, etc. on -- Windows). dropRoot :: Path Abs t -> Path Rel t dropRoot (Path l) = Path (FP.dropDrive l) -- | If given file in 'Maybe' does not exist, ensure we have 'Nothing'. This -- is to be used in conjunction with 'forgivingAbsence' and -- 'resolveFile'. -- -- Previously the idiom @forgivingAbsence (resolveFile …)@ alone was used, -- which relied on 'canonicalizePath' throwing 'isDoesNotExistError' when -- path does not exist. As it turns out, this behavior is actually not -- intentional and unreliable, see -- . This was “fixed” in -- version @1.2.3.0@ of @directory@ package (now it never throws). To make -- it work with all versions, we need to use the following idiom: -- -- > forgivingAbsence (resolveFile …) >>= rejectMissingFile rejectMissingFile :: MonadIO m => Maybe (Path Abs File) -> m (Maybe (Path Abs File)) rejectMissingFile Nothing = pure Nothing rejectMissingFile (Just p) = bool Nothing (Just p) `liftM` doesFileExist p -- | See 'rejectMissingFile'. rejectMissingDir :: MonadIO m => Maybe (Path Abs Dir) -> m (Maybe (Path Abs Dir)) rejectMissingDir Nothing = pure Nothing rejectMissingDir (Just p) = bool Nothing (Just p) `liftM` doesDirExist p -- | Convert to a lazy ByteString using toFilePath and UTF8. pathToLazyByteString :: Path b t -> BSL.ByteString pathToLazyByteString = BSL.fromStrict . pathToByteString -- | Convert to a ByteString using toFilePath and UTF8. pathToByteString :: Path b t -> BS.ByteString pathToByteString = T.encodeUtf8 . pathToText pathToText :: Path b t -> T.Text pathToText = T.pack . toFilePath tryGetModificationTime :: MonadIO m => Path Abs File -> m (Either () UTCTime) tryGetModificationTime = liftIO . tryJust (guard . isDoesNotExistError) . getModificationTime stack-2.9.3.1/src/Path/Find.hs0000644000000000000000000000767514445022466014104 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} -- | Finding files. module Path.Find ( findFileUp , findDirUp , findFiles , findInParents ) where import qualified Data.List as L import Path import Path.IO hiding (findFiles) import RIO import System.IO.Error ( isPermissionError ) import System.PosixCompat.Files ( getSymbolicLinkStatus, isSymbolicLink ) -- | Find the location of a file matching the given predicate. findFileUp :: (MonadIO m,MonadThrow m) => Path Abs Dir -- ^ Start here. -> (Path Abs File -> Bool) -- ^ Predicate to match the file. -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory. -> m (Maybe (Path Abs File)) -- ^ Absolute file path. findFileUp = findPathUp snd -- | Find the location of a directory matching the given predicate. findDirUp :: (MonadIO m,MonadThrow m) => Path Abs Dir -- ^ Start here. -> (Path Abs Dir -> Bool) -- ^ Predicate to match the directory. -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory. -> m (Maybe (Path Abs Dir)) -- ^ Absolute directory path. findDirUp = findPathUp fst -- | Find the location of a path matching the given predicate. findPathUp :: (MonadIO m,MonadThrow m) => (([Path Abs Dir],[Path Abs File]) -> [Path Abs t]) -- ^ Choose path type from pair. -> Path Abs Dir -- ^ Start here. -> (Path Abs t -> Bool) -- ^ Predicate to match the path. -> Maybe (Path Abs Dir) -- ^ Do not ascend above this directory. -> m (Maybe (Path Abs t)) -- ^ Absolute path. findPathUp pathType dir p upperBound = do entries <- listDir dir case L.find p (pathType entries) of Just path -> pure (Just path) Nothing | Just dir == upperBound -> pure Nothing | parent dir == dir -> pure Nothing | otherwise -> findPathUp pathType (parent dir) p upperBound -- | Find files matching predicate below a root directory. -- -- NOTE: this skips symbolic directory links, to avoid loops. This may -- not make sense for all uses of file finding. -- -- TODO: write one of these that traverses symbolic links but -- efficiently ignores loops. findFiles :: Path Abs Dir -- ^ Root directory to begin with. -> (Path Abs File -> Bool) -- ^ Predicate to match files. -> (Path Abs Dir -> Bool) -- ^ Predicate for which directories to traverse. -> IO [Path Abs File] -- ^ List of matching files. findFiles dir p traversep = do (dirs,files) <- catchJust (\ e -> if isPermissionError e then Just () else Nothing) (listDir dir) (\ _ -> pure ([], [])) filteredFiles <- evaluate $ force (filter p files) filteredDirs <- filterM (fmap not . isSymLink) dirs subResults <- forM filteredDirs (\entry -> if traversep entry then findFiles entry p traversep else pure []) pure (concat (filteredFiles : subResults)) isSymLink :: Path Abs t -> IO Bool isSymLink = fmap isSymbolicLink . getSymbolicLinkStatus . toFilePath -- | @findInParents f path@ applies @f@ to @path@ and its 'parent's until -- it finds a 'Just' or reaches the root directory. findInParents :: MonadIO m => (Path Abs Dir -> m (Maybe a)) -> Path Abs Dir -> m (Maybe a) findInParents f path = do mres <- f path case mres of Just res -> pure (Just res) Nothing -> do let next = parent path if next == path then pure Nothing else findInParents f next stack-2.9.3.1/src/Stack/Build.hs0000644000000000000000000004170114445022466014420 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Build the project. module Stack.Build ( build , buildLocalTargets , loadPackage , mkBaseConfigOpts , queryBuildInfo , splitObjsWarning , CabalVersionException (..) ) where import Data.Aeson ( Value (Object, Array), (.=), object ) import qualified Data.Aeson.Key as Key import qualified Data.Aeson.KeyMap as KeyMap import Data.List ( (\\), isPrefixOf ) import Data.List.Extra ( groupSort ) import qualified Data.List.NonEmpty as NE import qualified Data.Map as Map import qualified Data.Set as Set import qualified Data.Text as T import Data.Text.Encoding ( decodeUtf8 ) import qualified Data.Text.IO as TIO import Data.Text.Read ( decimal ) import qualified Data.Vector as V import qualified Data.Yaml as Yaml import qualified Distribution.PackageDescription as C import Distribution.Types.Dependency ( depLibraries ) import Distribution.Version ( mkVersion ) import Path ( parent ) import Stack.Build.ConstructPlan import Stack.Build.Execute import Stack.Build.Installed import Stack.Build.Source import Stack.Package import Stack.Prelude hiding ( loadPackage ) import Stack.Setup ( withNewLocalBuildTargets ) import Stack.Types.Build import Stack.Types.Compiler ( compilerVersionText, getGhcVersion ) import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.SourceMap import System.Terminal ( fixCodePage ) data CabalVersionException = AllowNewerNotSupported Version | CabalVersionNotSupported Version deriving (Show, Typeable) instance Exception CabalVersionException where displayException (AllowNewerNotSupported cabalVer) = concat [ "Error: [S-8503]\n" , "'--allow-newer' requires Cabal version 1.22 or greater, but " , "version " , versionString cabalVer , " was found." ] displayException (CabalVersionNotSupported cabalVer) = concat [ "Error: [S-5973]\n" , "Stack no longer supports Cabal versions before 1.19.2, " , "but version " , versionString cabalVer , " was found. To fix this, consider updating the resolver to lts-3.0 " , "or later or to nightly-2015-05-05 or later." ] data QueryException = SelectorNotFound [Text] | IndexOutOfRange [Text] | NoNumericSelector [Text] | CannotApplySelector Value [Text] deriving (Show, Typeable) instance Exception QueryException where displayException (SelectorNotFound sels) = err "[S-4419]" "Selector not found" sels displayException (IndexOutOfRange sels) = err "[S-8422]" "Index out of range" sels displayException (NoNumericSelector sels) = err "[S-4360]" "Encountered array and needed numeric selector" sels displayException (CannotApplySelector value sels) = err "[S-1711]" ("Cannot apply selector to " ++ show value) sels -- | Helper function for 'QueryException' instance of 'Show' err :: String -> String -> [Text] -> String err msg code sels = "Error: " ++ code ++ "\n" ++ msg ++ ": " ++ show sels -- | Build. -- -- If a buildLock is passed there is an important contract here. That lock must -- protect the snapshot, and it must be safe to unlock it if there are no further -- modifications to the snapshot to be performed by this build. build :: HasEnvConfig env => Maybe (Set (Path Abs File) -> IO ()) -- ^ callback after discovering all local files -> RIO env () build msetLocalFiles = do mcp <- view $ configL.to configModifyCodePage ghcVersion <- view $ actualCompilerVersionL.to getGhcVersion fixCodePage mcp ghcVersion $ do bopts <- view buildOptsL sourceMap <- view $ envConfigL.to envConfigSourceMap locals <- projectLocalPackages depsLocals <- localDependencies let allLocals = locals <> depsLocals checkSubLibraryDependencies (Map.elems $ smProject sourceMap) boptsCli <- view $ envConfigL.to envConfigBuildOptsCLI -- Set local files, necessary for file watching stackYaml <- view stackYamlL for_ msetLocalFiles $ \setLocalFiles -> do files <- if boptsCLIWatchAll boptsCli then sequence [lpFiles lp | lp <- allLocals] else forM allLocals $ \lp -> do let pn = packageName (lpPackage lp) case Map.lookup pn (smtTargets $ smTargets sourceMap) of Nothing -> pure Set.empty Just (TargetAll _) -> lpFiles lp Just (TargetComps components) -> lpFilesForComponents components lp liftIO $ setLocalFiles $ Set.insert stackYaml $ Set.unions files checkComponentsBuildable allLocals installMap <- toInstallMap sourceMap (installedMap, globalDumpPkgs, snapshotDumpPkgs, localDumpPkgs) <- getInstalled installMap baseConfigOpts <- mkBaseConfigOpts boptsCli plan <- constructPlan baseConfigOpts localDumpPkgs loadPackage sourceMap installedMap (boptsCLIInitialBuildSteps boptsCli) allowLocals <- view $ configL.to configAllowLocals unless allowLocals $ case justLocals plan of [] -> pure () localsIdents -> throwM $ LocalPackagesPresent localsIdents checkCabalVersion warnAboutSplitObjs bopts warnIfExecutablesWithSameNameCouldBeOverwritten locals plan when (boptsPreFetch bopts) $ preFetch plan if boptsCLIDryrun boptsCli then printPlan plan else executePlan boptsCli baseConfigOpts locals globalDumpPkgs snapshotDumpPkgs localDumpPkgs installedMap (smtTargets $ smTargets sourceMap) plan buildLocalTargets :: HasEnvConfig env => NonEmpty Text -> RIO env (Either SomeException ()) buildLocalTargets targets = tryAny $ withNewLocalBuildTargets (NE.toList targets) $ build Nothing justLocals :: Plan -> [PackageIdentifier] justLocals = map taskProvides . filter ((== Local) . taskLocation) . Map.elems . planTasks checkCabalVersion :: HasEnvConfig env => RIO env () checkCabalVersion = do allowNewer <- view $ configL.to configAllowNewer cabalVer <- view cabalVersionL -- https://github.com/haskell/cabal/issues/2023 when (allowNewer && cabalVer < mkVersion [1, 22]) $ throwM $ AllowNewerNotSupported cabalVer -- Since --exact-configuration is always passed, some old cabal -- versions can no longer be used. See the following link for why -- it's 1.19.2: -- https://github.com/haskell/cabal/blob/580fe6b6bf4e1648b2f66c1cb9da9f1f1378492c/cabal-install/Distribution/Client/Setup.hs#L592 when (cabalVer < mkVersion [1, 19, 2]) $ throwM $ CabalVersionNotSupported cabalVer -- | See https://github.com/commercialhaskell/stack/issues/1198. warnIfExecutablesWithSameNameCouldBeOverwritten :: HasLogFunc env => [LocalPackage] -> Plan -> RIO env () warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do logDebug "Checking if we are going to build multiple executables with the same name" forM_ (Map.toList warnings) $ \(exe,(toBuild,otherLocals)) -> do let exe_s | length toBuild > 1 = "several executables with the same name:" | otherwise = "executable" exesText pkgs = T.intercalate ", " ["'" <> T.pack (packageNameString p) <> ":" <> exe <> "'" | p <- pkgs] (logWarn . display . T.unlines . concat) [ [ "Building " <> exe_s <> " " <> exesText toBuild <> "." ] , [ "Only one of them will be available via 'stack exec' or locally installed." | length toBuild > 1 ] , [ "Other executables with the same name might be overwritten: " <> exesText otherLocals <> "." | not (null otherLocals) ] ] where -- Cases of several local packages having executables with the same name. -- The Map entries have the following form: -- -- executable name: ( package names for executables that are being built -- , package names for other local packages that have an -- executable with the same name -- ) warnings :: Map Text ([PackageName],[PackageName]) warnings = Map.mapMaybe (\(pkgsToBuild,localPkgs) -> case (pkgsToBuild,NE.toList localPkgs \\ NE.toList pkgsToBuild) of (_ :| [],[]) -> -- We want to build the executable of single local package -- and there are no other local packages with an executable of -- the same name. Nothing to warn about, ignore. Nothing (_,otherLocals) -> -- We could be here for two reasons (or their combination): -- 1) We are building two or more executables with the same -- name that will end up overwriting each other. -- 2) In addition to the executable(s) that we want to build -- there are other local packages with an executable of the -- same name that might get overwritten. -- Both cases warrant a warning. Just (NE.toList pkgsToBuild,otherLocals)) (Map.intersectionWith (,) exesToBuild localExes) exesToBuild :: Map Text (NonEmpty PackageName) exesToBuild = collect [ (exe,pkgName') | (pkgName',task) <- Map.toList (planTasks plan) , TTLocalMutable lp <- [taskType task] , exe <- (Set.toList . exeComponents . lpComponents) lp ] localExes :: Map Text (NonEmpty PackageName) localExes = collect [ (exe,packageName pkg) | pkg <- map lpPackage locals , exe <- Set.toList (packageExes pkg) ] collect :: Ord k => [(k,v)] -> Map k (NonEmpty v) collect = Map.map NE.fromList . Map.fromDistinctAscList . groupSort warnAboutSplitObjs :: HasLogFunc env => BuildOpts -> RIO env () warnAboutSplitObjs bopts | boptsSplitObjs bopts = do logWarn $ "Building with --split-objs is enabled. " <> fromString splitObjsWarning warnAboutSplitObjs _ = pure () splitObjsWarning :: String splitObjsWarning = unwords [ "Note that this feature is EXPERIMENTAL, and its behavior may be changed and improved." , "You will need to clean your workdirs before use. If you want to compile all dependencies" , "with split-objs, you will need to delete the snapshot (and all snapshots that could" , "reference that snapshot)." ] -- | Get the @BaseConfigOpts@ necessary for constructing configure options mkBaseConfigOpts :: (HasEnvConfig env) => BuildOptsCLI -> RIO env BaseConfigOpts mkBaseConfigOpts boptsCli = do bopts <- view buildOptsL snapDBPath <- packageDatabaseDeps localDBPath <- packageDatabaseLocal snapInstallRoot <- installationRootDeps localInstallRoot <- installationRootLocal packageExtraDBs <- packageDatabaseExtra pure BaseConfigOpts { bcoSnapDB = snapDBPath , bcoLocalDB = localDBPath , bcoSnapInstallRoot = snapInstallRoot , bcoLocalInstallRoot = localInstallRoot , bcoBuildOpts = bopts , bcoBuildOptsCLI = boptsCli , bcoExtraDBs = packageExtraDBs } -- | Provide a function for loading package information from the package index loadPackage :: (HasBuildConfig env, HasSourceMap env) => PackageLocationImmutable -> Map FlagName Bool -> [Text] -- ^ GHC options -> [Text] -- ^ Cabal configure options -> RIO env Package loadPackage loc flags ghcOptions cabalConfigOpts = do compiler <- view actualCompilerVersionL platform <- view platformL let pkgConfig = PackageConfig { packageConfigEnableTests = False , packageConfigEnableBenchmarks = False , packageConfigFlags = flags , packageConfigGhcOptions = ghcOptions , packageConfigCabalConfigOpts = cabalConfigOpts , packageConfigCompilerVersion = compiler , packageConfigPlatform = platform } resolvePackage pkgConfig <$> loadCabalFileImmutable loc -- | Query information about the build and print the result to stdout in YAML format. queryBuildInfo :: HasEnvConfig env => [Text] -- ^ selectors -> RIO env () queryBuildInfo selectors0 = rawBuildInfo >>= select id selectors0 >>= liftIO . TIO.putStrLn . addGlobalHintsComment . decodeUtf8 . Yaml.encode where select _ [] value = pure value select front (sel:sels) value = case value of Object o -> case KeyMap.lookup (Key.fromText sel) o of Nothing -> throwIO $ SelectorNotFound sels' Just value' -> cont value' Array v -> case decimal sel of Right (i, "") | i >= 0 && i < V.length v -> cont $ v V.! i | otherwise -> throwIO $ IndexOutOfRange sels' _ -> throwIO $ NoNumericSelector sels' _ -> throwIO $ CannotApplySelector value sels' where cont = select (front . (sel:)) sels sels' = front [sel] -- Include comments to indicate that this portion of the "stack -- query" API is not necessarily stable. addGlobalHintsComment | null selectors0 = T.replace globalHintsLine ("\n" <> globalHintsComment <> globalHintsLine) -- Append comment instead of pre-pending. The reasoning here is -- that something *could* expect that the result of 'stack query -- global-hints ghc-boot' is just a string literal. Seems easier -- for to expect the first line of the output to be the literal. | ["global-hints"] `isPrefixOf` selectors0 = (<> ("\n" <> globalHintsComment)) | otherwise = id globalHintsLine = "\nglobal-hints:\n" globalHintsComment = T.concat [ "# Note: global-hints is experimental and may be renamed / removed in the future.\n" , "# See https://github.com/commercialhaskell/stack/issues/3796" ] -- | Get the raw build information object rawBuildInfo :: HasEnvConfig env => RIO env Value rawBuildInfo = do locals <- projectLocalPackages wantedCompiler <- view $ wantedCompilerVersionL.to (utf8BuilderToText . display) actualCompiler <- view $ actualCompilerVersionL.to compilerVersionText pure $ object [ "locals" .= Object (KeyMap.fromList $ map localToPair locals) , "compiler" .= object [ "wanted" .= wantedCompiler , "actual" .= actualCompiler ] ] where localToPair lp = (Key.fromText $ T.pack $ packageNameString $ packageName p, value) where p = lpPackage lp value = object [ "version" .= CabalString (packageVersion p) , "path" .= toFilePath (parent $ lpCabalFile lp) ] checkComponentsBuildable :: MonadThrow m => [LocalPackage] -> m () checkComponentsBuildable lps = unless (null unbuildable) $ throwM $ SomeTargetsNotBuildable unbuildable where unbuildable = [ (packageName (lpPackage lp), c) | lp <- lps , c <- Set.toList (lpUnbuildable lp) ] -- | Find if sublibrary dependency exist in each project checkSubLibraryDependencies :: HasLogFunc env => [ProjectPackage] -> RIO env () checkSubLibraryDependencies proj = do forM_ proj $ \p -> do C.GenericPackageDescription _ _ _ lib subLibs foreignLibs exes tests benches <- liftIO $ cpGPD . ppCommon $ p let dependencies = concatMap getDeps subLibs <> concatMap getDeps foreignLibs <> concatMap getDeps exes <> concatMap getDeps tests <> concatMap getDeps benches <> maybe [] C.condTreeConstraints lib libraries = concatMap (toList . depLibraries) dependencies when (subLibDepExist libraries) (logWarn "SubLibrary dependency is not supported, this will almost certainly fail") where getDeps (_, C.CondNode _ dep _) = dep subLibDepExist lib = any (\x -> case x of C.LSubLibName _ -> True C.LMainLibName -> False ) lib stack-2.9.3.1/src/Stack/Build/Cache.hs0000644000000000000000000003710214445022466015423 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Cache information about previous builds module Stack.Build.Cache ( tryGetBuildCache , tryGetConfigCache , tryGetCabalMod , tryGetSetupConfigMod , tryGetPackageProjectRoot , getInstalledExes , tryGetFlagCache , deleteCaches , markExeInstalled , markExeNotInstalled , writeFlagCache , writeBuildCache , writeConfigCache , writeCabalMod , writeSetupConfigMod , writePackageProjectRoot , TestStatus (..) , setTestStatus , getTestStatus , writePrecompiledCache , readPrecompiledCache -- Exported for testing , BuildCache (..) ) where import Crypto.Hash ( hashWith, SHA256 (..) ) import qualified Data.ByteArray as Mem ( convert ) import Data.ByteString.Builder ( byteString ) import qualified Data.Map as M import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Yaml as Yaml import Foreign.C.Types ( CTime ) import Path import Path.IO import Stack.Constants import Stack.Constants.Config import Stack.Prelude import Stack.Storage.Project import Stack.Storage.User import Stack.Types.Build import Stack.Types.Cache import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.NamedComponent import Stack.Types.SourceMap ( smRelDir ) import System.PosixCompat.Files ( modificationTime, getFileStatus, setFileTimes ) -- | Directory containing files to mark an executable as installed exeInstalledDir :: (HasEnvConfig env) => InstallLocation -> RIO env (Path Abs Dir) exeInstalledDir Snap = ( relDirInstalledPackages) `liftM` installationRootDeps exeInstalledDir Local = ( relDirInstalledPackages) `liftM` installationRootLocal -- | Get all of the installed executables getInstalledExes :: (HasEnvConfig env) => InstallLocation -> RIO env [PackageIdentifier] getInstalledExes loc = do dir <- exeInstalledDir loc (_, files) <- liftIO $ handleIO (const $ pure ([], [])) $ listDir dir pure $ concat $ M.elems $ -- If there are multiple install records (from a Stack version -- before https://github.com/commercialhaskell/stack/issues/2373 -- was fixed), then we don't know which is correct - ignore them. M.fromListWith (\_ _ -> []) $ map (\x -> (pkgName x, [x])) $ mapMaybe (parsePackageIdentifier . toFilePath . filename) files -- | Mark the given executable as installed markExeInstalled :: (HasEnvConfig env) => InstallLocation -> PackageIdentifier -> RIO env () markExeInstalled loc ident = do dir <- exeInstalledDir loc ensureDir dir ident' <- parseRelFile $ packageIdentifierString ident let fp = dir ident' -- Remove old install records for this package. -- TODO: This is a bit in-efficient. Put all this metadata into one file? installed <- getInstalledExes loc forM_ (filter (\x -> pkgName ident == pkgName x) installed) (markExeNotInstalled loc) -- TODO consideration for the future: list all of the executables -- installed, and invalidate this file in getInstalledExes if they no -- longer exist writeBinaryFileAtomic fp "Installed" -- | Mark the given executable as not installed markExeNotInstalled :: (HasEnvConfig env) => InstallLocation -> PackageIdentifier -> RIO env () markExeNotInstalled loc ident = do dir <- exeInstalledDir loc ident' <- parseRelFile $ packageIdentifierString ident liftIO $ ignoringAbsence (removeFile $ dir ident') buildCacheFile :: (HasEnvConfig env, MonadReader env m, MonadThrow m) => Path Abs Dir -> NamedComponent -> m (Path Abs File) buildCacheFile dir component = do cachesDir <- buildCachesDir dir smh <- view $ envConfigL.to envConfigSourceMapHash smDirName <- smRelDir smh let nonLibComponent prefix name = prefix <> "-" <> T.unpack name cacheFileName <- parseRelFile $ case component of CLib -> "lib" CInternalLib name -> nonLibComponent "internal-lib" name CExe name -> nonLibComponent "exe" name CTest name -> nonLibComponent "test" name CBench name -> nonLibComponent "bench" name pure $ cachesDir smDirName cacheFileName -- | Try to read the dirtiness cache for the given package directory. tryGetBuildCache :: HasEnvConfig env => Path Abs Dir -> NamedComponent -> RIO env (Maybe (Map FilePath FileCacheInfo)) tryGetBuildCache dir component = do fp <- buildCacheFile dir component ensureDir $ parent fp either (const Nothing) (Just . buildCacheTimes) <$> liftIO (tryAny (Yaml.decodeFileThrow (toFilePath fp))) -- | Try to read the dirtiness cache for the given package directory. tryGetConfigCache :: HasEnvConfig env => Path Abs Dir -> RIO env (Maybe ConfigCache) tryGetConfigCache dir = loadConfigCache $ configCacheKey dir ConfigCacheTypeConfig -- | Try to read the mod time of the Cabal file from the last build tryGetCabalMod :: HasEnvConfig env => Path Abs Dir -> RIO env (Maybe CTime) tryGetCabalMod dir = do fp <- toFilePath <$> configCabalMod dir tryGetFileMod fp -- | Try to read the mod time of setup-config file from the last build tryGetSetupConfigMod :: HasEnvConfig env => Path Abs Dir -> RIO env (Maybe CTime) tryGetSetupConfigMod dir = do fp <- toFilePath <$> configSetupConfigMod dir tryGetFileMod fp tryGetFileMod :: MonadIO m => FilePath -> m (Maybe CTime) tryGetFileMod fp = liftIO $ either (const Nothing) (Just . modificationTime) <$> tryIO (getFileStatus fp) -- | Try to read the project root from the last build of a package tryGetPackageProjectRoot :: HasEnvConfig env => Path Abs Dir -> RIO env (Maybe ByteString) tryGetPackageProjectRoot dir = do fp <- toFilePath <$> configPackageProjectRoot dir tryReadFileBinary fp tryReadFileBinary :: MonadIO m => FilePath -> m (Maybe ByteString) tryReadFileBinary fp = liftIO $ either (const Nothing) Just <$> tryIO (readFileBinary fp) -- | Write the dirtiness cache for this package's files. writeBuildCache :: HasEnvConfig env => Path Abs Dir -> NamedComponent -> Map FilePath FileCacheInfo -> RIO env () writeBuildCache dir component times = do fp <- toFilePath <$> buildCacheFile dir component liftIO $ Yaml.encodeFile fp BuildCache { buildCacheTimes = times } -- | Write the dirtiness cache for this package's configuration. writeConfigCache :: HasEnvConfig env => Path Abs Dir -> ConfigCache -> RIO env () writeConfigCache dir = saveConfigCache (configCacheKey dir ConfigCacheTypeConfig) -- | See 'tryGetCabalMod' writeCabalMod :: HasEnvConfig env => Path Abs Dir -> CTime -> RIO env () writeCabalMod dir x = do fp <- configCabalMod dir writeBinaryFileAtomic fp "Just used for its modification time" liftIO $ setFileTimes (toFilePath fp) x x -- | See 'tryGetSetupConfigMod' writeSetupConfigMod :: HasEnvConfig env => Path Abs Dir -> Maybe CTime -> RIO env () writeSetupConfigMod dir Nothing = do fp <- configSetupConfigMod dir ignoringAbsence $ removeFile fp writeSetupConfigMod dir (Just x) = do fp <- configSetupConfigMod dir writeBinaryFileAtomic fp "Just used for its modification time" liftIO $ setFileTimes (toFilePath fp) x x -- | See 'tryGetPackageProjectRoot' writePackageProjectRoot :: HasEnvConfig env => Path Abs Dir -> ByteString -> RIO env () writePackageProjectRoot dir projectRoot = do fp <- configPackageProjectRoot dir writeBinaryFileAtomic fp (byteString projectRoot) -- | Delete the caches for the project. deleteCaches :: HasEnvConfig env => Path Abs Dir -> RIO env () deleteCaches dir {- FIXME confirm that this is acceptable to remove bfp <- buildCacheFile dir removeFileIfExists bfp -} = deactiveConfigCache $ configCacheKey dir ConfigCacheTypeConfig flagCacheKey :: (HasEnvConfig env) => Installed -> RIO env ConfigCacheKey flagCacheKey installed = do installationRoot <- installationRootLocal case installed of Library _ gid _ -> pure $ configCacheKey installationRoot (ConfigCacheTypeFlagLibrary gid) Executable ident -> pure $ configCacheKey installationRoot (ConfigCacheTypeFlagExecutable ident) -- | Loads the flag cache for the given installed extra-deps tryGetFlagCache :: HasEnvConfig env => Installed -> RIO env (Maybe ConfigCache) tryGetFlagCache gid = do key <- flagCacheKey gid loadConfigCache key writeFlagCache :: HasEnvConfig env => Installed -> ConfigCache -> RIO env () writeFlagCache gid cache = do key <- flagCacheKey gid saveConfigCache key cache successBS, failureBS, unknownBS :: IsString s => s successBS = "success" failureBS = "failure" unknownBS = "unknown" -- | Status of a test suite data TestStatus = TSSuccess | TSFailure | TSUnknown -- | Mark test suite status setTestStatus :: HasEnvConfig env => Path Abs Dir -> TestStatus -> RIO env () setTestStatus dir status = do fp <- testSuccessFile dir writeBinaryFileAtomic fp $ case status of TSSuccess -> successBS TSFailure -> failureBS TSUnknown -> unknownBS -- | Check if the test suite already passed getTestStatus :: HasEnvConfig env => Path Abs Dir -> RIO env TestStatus getTestStatus dir = do fp <- testSuccessFile dir -- we could ensure the file is the right size first, -- but we're not expected an attack from the user's filesystem eres <- tryIO (readFileBinary $ toFilePath fp) pure $ case eres of Right bs | bs == successBS -> TSSuccess | bs == failureBS -> TSFailure _ -> TSUnknown -------------------------------------- -- Precompiled Cache -- -- Idea is simple: cache information about packages built in other snapshots, -- and then for identical matches (same flags, config options, dependencies) -- just copy over the executables and reregister the libraries. -------------------------------------- -- | The key containing information on the given package/configuration -- combination. The key contains a hash of the non-directory configure -- options for quick lookup if there's a match. -- -- We only pay attention to non-directory options. We don't want to avoid a -- cache hit just because it was installed in a different directory. getPrecompiledCacheKey :: HasEnvConfig env => PackageLocationImmutable -> ConfigureOpts -> Bool -- ^ build haddocks -> Set GhcPkgId -- ^ dependencies -> RIO env PrecompiledCacheKey getPrecompiledCacheKey loc copts buildHaddocks installedPackageIDs = do compiler <- view actualCompilerVersionL cabalVersion <- view cabalVersionL -- The goal here is to come up with a string representing the -- package location which is unique. Luckily @TreeKey@s are exactly -- that! treeKey <- getPackageLocationTreeKey loc let packageKey = utf8BuilderToText $ display treeKey platformGhcDir <- platformGhcRelDir -- In Cabal versions 1.22 and later, the configure options contain the -- installed package IDs, which is what we need for a unique hash. -- Unfortunately, earlier Cabals don't have the information, so we must -- supplement it with the installed package IDs directly. -- See issue: https://github.com/commercialhaskell/stack/issues/1103 let input = (coNoDirs copts, installedPackageIDs) optionsHash = Mem.convert $ hashWith SHA256 $ encodeUtf8 $ tshow input pure $ precompiledCacheKey platformGhcDir compiler cabalVersion packageKey optionsHash buildHaddocks -- | Write out information about a newly built package writePrecompiledCache :: HasEnvConfig env => BaseConfigOpts -> PackageLocationImmutable -> ConfigureOpts -> Bool -- ^ build haddocks -> Set GhcPkgId -- ^ dependencies -> Installed -- ^ library -> [GhcPkgId] -- ^ sublibraries, in the GhcPkgId format -> Set Text -- ^ executables -> RIO env () writePrecompiledCache baseConfigOpts loc copts buildHaddocks depIDs mghcPkgId sublibs exes = do key <- getPrecompiledCacheKey loc copts buildHaddocks depIDs ec <- view envConfigL let stackRootRelative = makeRelative (view stackRootL ec) mlibpath <- case mghcPkgId of Executable _ -> pure Nothing Library _ ipid _ -> Just <$> pathFromPkgId stackRootRelative ipid sublibpaths <- mapM (pathFromPkgId stackRootRelative) sublibs exes' <- forM (Set.toList exes) $ \exe -> do name <- parseRelFile $ T.unpack exe stackRootRelative $ bcoSnapInstallRoot baseConfigOpts bindirSuffix name let precompiled = PrecompiledCache { pcLibrary = mlibpath , pcSubLibs = sublibpaths , pcExes = exes' } savePrecompiledCache key precompiled -- reuse precompiled cache with haddocks also in case when haddocks are not required when buildHaddocks $ do key' <- getPrecompiledCacheKey loc copts False depIDs savePrecompiledCache key' precompiled where pathFromPkgId stackRootRelative ipid = do ipid' <- parseRelFile $ ghcPkgIdString ipid ++ ".conf" stackRootRelative $ bcoSnapDB baseConfigOpts ipid' -- | Check the cache for a precompiled package matching the given -- configuration. readPrecompiledCache :: forall env. HasEnvConfig env => PackageLocationImmutable -- ^ target package -> ConfigureOpts -> Bool -- ^ build haddocks -> Set GhcPkgId -- ^ dependencies -> RIO env (Maybe (PrecompiledCache Abs)) readPrecompiledCache loc copts buildHaddocks depIDs = do key <- getPrecompiledCacheKey loc copts buildHaddocks depIDs mcache <- loadPrecompiledCache key maybe (pure Nothing) (fmap Just . mkAbs) mcache where -- Since commit ed9ccc08f327bad68dd2d09a1851ce0d055c0422, -- pcLibrary paths are stored as relative to the Stack -- root. Therefore, we need to prepend the Stack root when -- checking that the file exists. For the older cached paths, the -- file will contain an absolute path, which will make `stackRoot -- ` a no-op. mkAbs :: PrecompiledCache Rel -> RIO env (PrecompiledCache Abs) mkAbs pc0 = do stackRoot <- view stackRootL let mkAbs' = (stackRoot ) pure PrecompiledCache { pcLibrary = mkAbs' <$> pcLibrary pc0 , pcSubLibs = mkAbs' <$> pcSubLibs pc0 , pcExes = mkAbs' <$> pcExes pc0 } stack-2.9.3.1/src/Stack/Build/ConstructPlan.hs0000644000000000000000000013351514445022466017224 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE ViewPatterns #-} -- | Construct a @Plan@ for how to build module Stack.Build.ConstructPlan ( constructPlan ) where import Control.Monad.RWS.Strict hiding ( (<>) ) import Control.Monad.State.Strict ( execState ) import qualified Data.List as L import qualified Data.Map.Strict as M import qualified Data.Map.Strict as Map import Data.Monoid.Map ( MonoidMap(..) ) import qualified Data.Set as Set import qualified Data.Text as T import Distribution.Types.BuildType ( BuildType (Configure) ) import Distribution.Types.PackageName ( mkPackageName ) import Generics.Deriving.Monoid ( memptydefault, mappenddefault ) import Path ( parent ) import RIO.Process ( findExecutable, HasProcessContext (..) ) import Stack.Build.Cache import Stack.Build.Haddock import Stack.Build.Installed import Stack.Build.Source import Stack.Constants import Stack.Package import Stack.PackageDump import Stack.Prelude hiding ( loadPackage ) import Stack.SourceMap import Stack.Types.Build import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.Dependency ( DepValue (DepValue), DepType (AsLibrary) ) import Stack.Types.GhcPkgId import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.SourceMap import Stack.Types.Version import System.Environment ( lookupEnv ) import System.IO ( putStrLn ) data PackageInfo = -- | This indicates that the package is already installed, and -- that we shouldn't build it from source. This is only the case -- for global packages. PIOnlyInstalled InstallLocation Installed -- | This indicates that the package isn't installed, and we know -- where to find its source. | PIOnlySource PackageSource -- | This indicates that the package is installed and we know -- where to find its source. We may want to reinstall from source. | PIBoth PackageSource Installed deriving (Show) combineSourceInstalled :: PackageSource -> (InstallLocation, Installed) -> PackageInfo combineSourceInstalled ps (location, installed) = assert (psVersion ps == installedVersion installed) $ case location of -- Always trust something in the snapshot Snap -> PIOnlyInstalled location installed Local -> PIBoth ps installed type CombinedMap = Map PackageName PackageInfo combineMap :: Map PackageName PackageSource -> InstalledMap -> CombinedMap combineMap = Map.mergeWithKey (\_ s i -> Just $ combineSourceInstalled s i) (fmap PIOnlySource) (fmap (uncurry PIOnlyInstalled)) data AddDepRes = ADRToInstall Task | ADRFound InstallLocation Installed deriving Show data W = W { wFinals :: !(Map PackageName (Either ConstructPlanException Task)) , wInstall :: !(Map Text InstallLocation) -- ^ executable to be installed, and location where the binary is placed , wDirty :: !(Map PackageName Text) -- ^ why a local package is considered dirty , wWarnings :: !([Text] -> [Text]) -- ^ Warnings , wParents :: !ParentMap -- ^ Which packages a given package depends on, along with the package's version } deriving Generic instance Semigroup W where (<>) = mappenddefault instance Monoid W where mempty = memptydefault mappend = (<>) type M = RWST -- TODO replace with more efficient WS stack on top of StackT Ctx W (Map PackageName (Either ConstructPlanException AddDepRes)) IO data Ctx = Ctx { baseConfigOpts :: !BaseConfigOpts , loadPackage :: !(PackageLocationImmutable -> Map FlagName Bool -> [Text] -> [Text] -> M Package) , combinedMap :: !CombinedMap , ctxEnvConfig :: !EnvConfig , callStack :: ![PackageName] , wanted :: !(Set PackageName) , localNames :: !(Set PackageName) , mcurator :: !(Maybe Curator) , pathEnvVar :: !Text } instance HasPlatform Ctx instance HasGHCVariant Ctx instance HasLogFunc Ctx where logFuncL = configL.logFuncL instance HasRunner Ctx where runnerL = configL.runnerL instance HasStylesUpdate Ctx where stylesUpdateL = runnerL.stylesUpdateL instance HasTerm Ctx where useColorL = runnerL.useColorL termWidthL = runnerL.termWidthL instance HasConfig Ctx instance HasPantryConfig Ctx where pantryConfigL = configL.pantryConfigL instance HasProcessContext Ctx where processContextL = configL.processContextL instance HasBuildConfig Ctx instance HasSourceMap Ctx where sourceMapL = envConfigL.sourceMapL instance HasCompiler Ctx where compilerPathsL = envConfigL.compilerPathsL instance HasEnvConfig Ctx where envConfigL = lens ctxEnvConfig (\x y -> x { ctxEnvConfig = y }) -- | Computes a build plan. This means figuring out which build 'Task's -- to take, and the interdependencies among the build 'Task's. In -- particular: -- -- 1) It determines which packages need to be built, based on the -- transitive deps of the current targets. For local packages, this is -- indicated by the 'lpWanted' boolean. For extra packages to build, -- this comes from the @extraToBuild0@ argument of type @Set -- PackageName@. These are usually packages that have been specified on -- the commandline. -- -- 2) It will only rebuild an upstream package if it isn't present in -- the 'InstalledMap', or if some of its dependencies have changed. -- -- 3) It will only rebuild a local package if its files are dirty or -- some of its dependencies have changed. constructPlan :: forall env. HasEnvConfig env => BaseConfigOpts -> [DumpPackage] -- ^ locally registered -> (PackageLocationImmutable -> Map FlagName Bool -> [Text] -> [Text] -> RIO EnvConfig Package) -- ^ load upstream package -> SourceMap -> InstalledMap -> Bool -> RIO env Plan constructPlan baseConfigOpts0 localDumpPkgs loadPackage0 sourceMap installedMap initialBuildSteps = do logDebug "Constructing the build plan" when hasBaseInDeps $ prettyWarn $ flow "You are trying to upgrade/downgrade base, which is almost certainly not what you really want. Please, consider using another GHC version if you need a certain version of base, or removing base from extra-deps. See more at https://github.com/commercialhaskell/stack/issues/3940." <> line econfig <- view envConfigL globalCabalVersion <- view $ compilerPathsL.to cpCabalVersion sources <- getSources globalCabalVersion mcur <- view $ buildConfigL.to bcCurator let onTarget = void . addDep let inner = mapM_ onTarget $ Map.keys (smtTargets $ smTargets sourceMap) pathEnvVar' <- liftIO $ maybe mempty T.pack <$> lookupEnv "PATH" let ctx = mkCtx econfig globalCabalVersion sources mcur pathEnvVar' ((), m, W efinals installExes dirtyReason warnings parents) <- liftIO $ runRWST inner ctx M.empty mapM_ (logWarn . display) (warnings []) let toEither (_, Left e) = Left e toEither (k, Right v) = Right (k, v) (errlibs, adrs) = partitionEithers $ map toEither $ M.toList m (errfinals, finals) = partitionEithers $ map toEither $ M.toList efinals errs = errlibs ++ errfinals if null errs then do let toTask (_, ADRFound _ _) = Nothing toTask (name, ADRToInstall task) = Just (name, task) tasks = M.fromList $ mapMaybe toTask adrs takeSubset = case boptsCLIBuildSubset $ bcoBuildOptsCLI baseConfigOpts0 of BSAll -> pure BSOnlySnapshot -> pure . stripLocals BSOnlyDependencies -> pure . stripNonDeps (M.keysSet $ smDeps sourceMap) BSOnlyLocals -> errorOnSnapshot takeSubset Plan { planTasks = tasks , planFinals = M.fromList finals , planUnregisterLocal = mkUnregisterLocal tasks dirtyReason localDumpPkgs initialBuildSteps , planInstallExes = if boptsInstallExes (bcoBuildOpts baseConfigOpts0) || boptsInstallCompilerTool (bcoBuildOpts baseConfigOpts0) then installExes else Map.empty } else do planDebug $ show errs stackYaml <- view stackYamlL stackRoot <- view stackRootL throwM $ PrettyException $ ConstructPlanFailed errs stackYaml stackRoot parents (wanted ctx) prunedGlobalDeps where hasBaseInDeps = Map.member (mkPackageName "base") (smDeps sourceMap) mkCtx econfig globalCabalVersion sources mcur pathEnvVar' = Ctx { baseConfigOpts = baseConfigOpts0 , loadPackage = \w x y z -> runRIO econfig $ applyForceCustomBuild globalCabalVersion <$> loadPackage0 w x y z , combinedMap = combineMap sources installedMap , ctxEnvConfig = econfig , callStack = [] , wanted = Map.keysSet (smtTargets $ smTargets sourceMap) , localNames = Map.keysSet (smProject sourceMap) , mcurator = mcur , pathEnvVar = pathEnvVar' } prunedGlobalDeps = flip Map.mapMaybe (smGlobal sourceMap) $ \gp -> case gp of ReplacedGlobalPackage deps -> let pruned = filter (not . inSourceMap) deps in if null pruned then Nothing else Just pruned GlobalPackage _ -> Nothing inSourceMap pname = pname `Map.member` smDeps sourceMap || pname `Map.member` smProject sourceMap getSources globalCabalVersion = do let loadLocalPackage' pp = do lp <- loadLocalPackage pp pure lp { lpPackage = applyForceCustomBuild globalCabalVersion $ lpPackage lp } pPackages <- for (smProject sourceMap) $ \pp -> do lp <- loadLocalPackage' pp pure $ PSFilePath lp bopts <- view $ configL.to configBuild deps <- for (smDeps sourceMap) $ \dp -> case dpLocation dp of PLImmutable loc -> pure $ PSRemote loc (getPLIVersion loc) (dpFromSnapshot dp) (dpCommon dp) PLMutable dir -> do pp <- mkProjectPackage YesPrintWarnings dir (shouldHaddockDeps bopts) lp <- loadLocalPackage' pp pure $ PSFilePath lp pure $ pPackages <> deps -- | Throw an exception if there are any snapshot packages in the plan. errorOnSnapshot :: Plan -> RIO env Plan errorOnSnapshot plan@(Plan tasks _finals _unregister installExes) = do let snapTasks = Map.keys $ Map.filter (\t -> taskLocation t == Snap) tasks let snapExes = Map.keys $ Map.filter (== Snap) installExes unless (null snapTasks && null snapExes) $ throwIO $ NotOnlyLocal snapTasks snapExes pure plan data NotOnlyLocal = NotOnlyLocal [PackageName] [Text] deriving (Show, Typeable) instance Exception NotOnlyLocal where displayException (NotOnlyLocal packages exes) = concat [ "Error: [S-1727]\n" , "Specified only-locals, but I need to build snapshot contents:\n" , if null packages then "" else concat [ "Packages: " , L.intercalate ", " (map packageNameString packages) , "\n" ] , if null exes then "" else concat [ "Executables: " , L.intercalate ", " (map T.unpack exes) , "\n" ] ] -- | State to be maintained during the calculation of local packages -- to unregister. data UnregisterState = UnregisterState { usToUnregister :: !(Map GhcPkgId (PackageIdentifier, Text)) , usKeep :: ![DumpPackage] , usAnyAdded :: !Bool } -- | Determine which packages to unregister based on the given tasks and -- already registered local packages mkUnregisterLocal :: Map PackageName Task -- ^ Tasks -> Map PackageName Text -- ^ Reasons why packages are dirty and must be rebuilt -> [DumpPackage] -- ^ Local package database dump -> Bool -- ^ If true, we're doing a special initialBuildSteps -- build - don't unregister target packages. -> Map GhcPkgId (PackageIdentifier, Text) mkUnregisterLocal tasks dirtyReason localDumpPkgs initialBuildSteps = -- We'll take multiple passes through the local packages. This -- will allow us to detect that a package should be unregistered, -- as well as all packages directly or transitively depending on -- it. loop Map.empty localDumpPkgs where loop toUnregister keep -- If any new packages were added to the unregister Map, we -- need to loop through the remaining packages again to detect -- if a transitive dependency is being unregistered. | usAnyAdded us = loop (usToUnregister us) (usKeep us) -- Nothing added, so we've already caught them all. Return the -- Map we've already calculated. | otherwise = usToUnregister us where -- Run the unregister checking function on all packages we -- currently think we'll be keeping. us = execState (mapM_ go keep) UnregisterState { usToUnregister = toUnregister , usKeep = [] , usAnyAdded = False } go dp = do us <- get case go' (usToUnregister us) ident deps of -- Not unregistering, add it to the keep list Nothing -> put us { usKeep = dp : usKeep us } -- Unregistering, add it to the unregister Map and -- indicate that a package was in fact added to the -- unregister Map so we loop again. Just reason -> put us { usToUnregister = Map.insert gid (ident, reason) (usToUnregister us) , usAnyAdded = True } where gid = dpGhcPkgId dp ident = dpPackageIdent dp deps = dpDepends dp go' toUnregister ident deps -- If we're planning on running a task on it, then it must be -- unregistered, unless it's a target and an initial-build-steps -- build is being done. | Just task <- Map.lookup name tasks = if initialBuildSteps && taskIsTarget task && taskProvides task == ident then Nothing else Just $ fromMaybe "" $ Map.lookup name dirtyReason -- Check if a dependency is going to be unregistered | (dep, _):_ <- mapMaybe (`Map.lookup` toUnregister) deps = Just $ "Dependency being unregistered: " <> T.pack (packageIdentifierString dep) -- None of the above, keep it! | otherwise = Nothing where name :: PackageName name = pkgName ident -- | Given a 'LocalPackage' and its 'lpTestBench', adds a 'Task' for -- running its tests and benchmarks. -- -- If @isAllInOne@ is 'True', then this means that the build step will -- also build the tests. Otherwise, this indicates that there's a cyclic -- dependency and an additional build step needs to be done. -- -- This will also add all the deps needed to build the tests / -- benchmarks. If @isAllInOne@ is 'True' (the common case), then all of -- these should have already been taken care of as part of the build -- step. addFinal :: LocalPackage -> Package -> Bool -> Bool -> M () addFinal lp package isAllInOne buildHaddocks = do depsRes <- addPackageDeps package res <- case depsRes of Left e -> pure $ Left e Right (missing, present, _minLoc) -> do ctx <- ask pure $ Right Task { taskProvides = PackageIdentifier (packageName package) (packageVersion package) , taskConfigOpts = TaskConfigOpts missing $ \missing' -> let allDeps = Map.union present missing' in configureOpts (view envConfigL ctx) (baseConfigOpts ctx) allDeps True -- local Mutable package , taskBuildHaddock = buildHaddocks , taskPresent = present , taskType = TTLocalMutable lp , taskAllInOne = isAllInOne , taskCachePkgSrc = CacheSrcLocal (toFilePath (parent (lpCabalFile lp))) , taskAnyMissing = not $ Set.null missing , taskBuildTypeConfig = packageBuildTypeConfig package } tell mempty { wFinals = Map.singleton (packageName package) res } -- | Given a 'PackageName', adds all of the build tasks to build the -- package, if needed. -- -- 'constructPlan' invokes this on all the target packages, setting -- @treatAsDep'@ to False, because those packages are direct build -- targets. 'addPackageDeps' invokes this while recursing into the -- dependencies of a package. As such, it sets @treatAsDep'@ to True, -- forcing this package to be marked as a dependency, even if it is -- directly wanted. This makes sense - if we left out packages that are -- deps, it would break the --only-dependencies build plan. addDep :: PackageName -> M (Either ConstructPlanException AddDepRes) addDep name = do ctx <- ask m <- get case Map.lookup name m of Just res -> do planDebug $ "addDep: Using cached result for " ++ show name ++ ": " ++ show res pure res Nothing -> do res <- if name `elem` callStack ctx then do planDebug $ "addDep: Detected cycle " ++ show name ++ ": " ++ show (callStack ctx) pure $ Left $ DependencyCycleDetected $ name : callStack ctx else local (\ctx' -> ctx' { callStack = name : callStack ctx' }) $ do let mpackageInfo = Map.lookup name $ combinedMap ctx planDebug $ "addDep: Package info for " ++ show name ++ ": " ++ show mpackageInfo case mpackageInfo of -- TODO look up in the package index and see if there's a -- recommendation available Nothing -> pure $ Left $ UnknownPackage name Just (PIOnlyInstalled loc installed) -> do -- FIXME Slightly hacky, no flags since -- they likely won't affect executable -- names. This code does not feel right. let version = installedVersion installed askPkgLoc = liftRIO $ do mrev <- getLatestHackageRevision YesRequireHackageIndex name version case mrev of Nothing -> do -- this could happen for GHC boot libraries missing from Hackage logWarn $ "No latest package revision found for: " <> fromString (packageNameString name) <> ", dependency callstack: " <> displayShow (map packageNameString $ callStack ctx) pure Nothing Just (_rev, cfKey, treeKey) -> pure . Just $ PLIHackage (PackageIdentifier name version) cfKey treeKey tellExecutablesUpstream name askPkgLoc loc Map.empty pure $ Right $ ADRFound loc installed Just (PIOnlySource ps) -> do tellExecutables name ps installPackage name ps Nothing Just (PIBoth ps installed) -> do tellExecutables name ps installPackage name ps (Just installed) updateLibMap name res pure res -- FIXME what's the purpose of this? Add a Haddock! tellExecutables :: PackageName -> PackageSource -> M () tellExecutables _name (PSFilePath lp) | lpWanted lp = tellExecutablesPackage Local $ lpPackage lp | otherwise = pure () -- Ignores ghcOptions because they don't matter for enumerating -- executables. tellExecutables name (PSRemote pkgloc _version _fromSnapshot cp) = tellExecutablesUpstream name (pure $ Just pkgloc) Snap (cpFlags cp) tellExecutablesUpstream :: PackageName -> M (Maybe PackageLocationImmutable) -> InstallLocation -> Map FlagName Bool -> M () tellExecutablesUpstream name retrievePkgLoc loc flags = do ctx <- ask when (name `Set.member` wanted ctx) $ do mPkgLoc <- retrievePkgLoc forM_ mPkgLoc $ \pkgLoc -> do p <- loadPackage ctx pkgLoc flags [] [] tellExecutablesPackage loc p tellExecutablesPackage :: InstallLocation -> Package -> M () tellExecutablesPackage loc p = do cm <- asks combinedMap -- Determine which components are enabled so we know which ones to copy let myComps = case Map.lookup (packageName p) cm of Nothing -> assert False Set.empty Just (PIOnlyInstalled _ _) -> Set.empty Just (PIOnlySource ps) -> goSource ps Just (PIBoth ps _) -> goSource ps goSource (PSFilePath lp) | lpWanted lp = exeComponents (lpComponents lp) | otherwise = Set.empty goSource PSRemote{} = Set.empty tell mempty { wInstall = Map.fromList $ map (, loc) $ Set.toList $ filterComps myComps $ packageExes p } where filterComps myComps x | Set.null myComps = x | otherwise = Set.intersection x myComps -- | Given a 'PackageSource' and perhaps an 'Installed' value, adds -- build 'Task's for the package and its dependencies. installPackage :: PackageName -> PackageSource -> Maybe Installed -> M (Either ConstructPlanException AddDepRes) installPackage name ps minstalled = do ctx <- ask case ps of PSRemote pkgLoc _version _fromSnapshot cp -> do planDebug $ "installPackage: Doing all-in-one build for upstream package " ++ show name package <- loadPackage ctx pkgLoc (cpFlags cp) (cpGhcOptions cp) (cpCabalConfigOpts cp) resolveDepsAndInstall True (cpHaddocks cp) ps package minstalled PSFilePath lp -> do case lpTestBench lp of Nothing -> do planDebug $ "installPackage: No test / bench component for " ++ show name ++ " so doing an all-in-one build." resolveDepsAndInstall True (lpBuildHaddocks lp) ps (lpPackage lp) minstalled Just tb -> do -- Attempt to find a plan which performs an all-in-one -- build. Ignore the writer action + reset the state if -- it fails. s <- get res <- pass $ do res <- addPackageDeps tb let writerFunc w = case res of Left _ -> mempty _ -> w pure (res, writerFunc) case res of Right deps -> do planDebug $ "installPackage: For " ++ show name ++ ", successfully added package deps" -- in curator builds we can't do all-in-one build as test/benchmark failure -- could prevent library from being available to its dependencies -- but when it's already available it's OK to do that splitRequired <- expectedTestOrBenchFailures <$> asks mcurator let isAllInOne = not splitRequired adr <- installPackageGivenDeps isAllInOne (lpBuildHaddocks lp) ps tb minstalled deps let finalAllInOne = case adr of ADRToInstall _ | splitRequired -> False _ -> True -- FIXME: this redundantly adds the deps (but -- they'll all just get looked up in the map) addFinal lp tb finalAllInOne False pure $ Right adr Left _ -> do -- Reset the state to how it was before -- attempting to find an all-in-one build -- plan. planDebug $ "installPackage: Before trying cyclic plan, resetting lib result map to " ++ show s put s -- Otherwise, fall back on building the -- tests / benchmarks in a separate step. res' <- resolveDepsAndInstall False (lpBuildHaddocks lp) ps (lpPackage lp) minstalled when (isRight res') $ do -- Insert it into the map so that it's -- available for addFinal. updateLibMap name res' addFinal lp tb False False pure res' where expectedTestOrBenchFailures maybeCurator = fromMaybe False $ do curator <- maybeCurator pure $ Set.member name (curatorExpectTestFailure curator) || Set.member name (curatorExpectBenchmarkFailure curator) resolveDepsAndInstall :: Bool -> Bool -> PackageSource -> Package -> Maybe Installed -> M (Either ConstructPlanException AddDepRes) resolveDepsAndInstall isAllInOne buildHaddocks ps package minstalled = do res <- addPackageDeps package case res of Left err -> pure $ Left err Right deps -> liftM Right $ installPackageGivenDeps isAllInOne buildHaddocks ps package minstalled deps -- | Checks if we need to install the given 'Package', given the results -- of 'addPackageDeps'. If dependencies are missing, the package is -- dirty, or it's not installed, then it needs to be installed. installPackageGivenDeps :: Bool -> Bool -> PackageSource -> Package -> Maybe Installed -> ( Set PackageIdentifier , Map PackageIdentifier GhcPkgId , IsMutable ) -> M AddDepRes installPackageGivenDeps isAllInOne buildHaddocks ps package minstalled (missing, present, minMutable) = do let name = packageName package ctx <- ask mRightVersionInstalled <- case (minstalled, Set.null missing) of (Just installed, True) -> do shouldInstall <- checkDirtiness ps installed package present buildHaddocks pure $ if shouldInstall then Nothing else Just installed (Just _, False) -> do let t = T.intercalate ", " $ map (T.pack . packageNameString . pkgName) (Set.toList missing) tell mempty { wDirty = Map.singleton name $ "missing dependencies: " <> addEllipsis t } pure Nothing (Nothing, _) -> pure Nothing let loc = psLocation ps mutable = installLocationIsMutable loc <> minMutable pure $ case mRightVersionInstalled of Just installed -> ADRFound loc installed Nothing -> ADRToInstall Task { taskProvides = PackageIdentifier (packageName package) (packageVersion package) , taskConfigOpts = TaskConfigOpts missing $ \missing' -> let allDeps = Map.union present missing' in configureOpts (view envConfigL ctx) (baseConfigOpts ctx) allDeps (psLocal ps) mutable package , taskBuildHaddock = buildHaddocks , taskPresent = present , taskType = case ps of PSFilePath lp -> TTLocalMutable lp PSRemote pkgLoc _version _fromSnapshot _cp -> TTRemotePackage mutable package pkgLoc , taskAllInOne = isAllInOne , taskCachePkgSrc = toCachePkgSrc ps , taskAnyMissing = not $ Set.null missing , taskBuildTypeConfig = packageBuildTypeConfig package } -- | Is the build type of the package Configure packageBuildTypeConfig :: Package -> Bool packageBuildTypeConfig pkg = packageBuildType pkg == Configure -- Update response in the lib map. If it is an error, and there's -- already an error about cyclic dependencies, prefer the cyclic error. updateLibMap :: PackageName -> Either ConstructPlanException AddDepRes -> M () updateLibMap name val = modify $ \mp -> case (M.lookup name mp, val) of (Just (Left DependencyCycleDetected{}), Left _) -> mp _ -> M.insert name val mp addEllipsis :: Text -> Text addEllipsis t | T.length t < 100 = t | otherwise = T.take 97 t <> "..." -- | Given a package, recurses into all of its dependencies. The results -- indicate which packages are missing, meaning that their 'GhcPkgId's -- will be figured out during the build, after they've been built. The -- 2nd part of the tuple result indicates the packages that are already -- installed which will be used. -- -- The 3rd part of the tuple is an 'InstallLocation'. If it is 'Local', -- then the parent package must be installed locally. Otherwise, if it -- is 'Snap', then it can either be installed locally or in the -- snapshot. addPackageDeps :: Package -> M ( Either ConstructPlanException ( Set PackageIdentifier , Map PackageIdentifier GhcPkgId , IsMutable ) ) addPackageDeps package = do ctx <- ask checkAndWarnForUnknownTools package let deps' = packageDeps package deps <- forM (Map.toList deps') $ \(depname, DepValue range depType) -> do eres <- addDep depname let getLatestApplicableVersionAndRev :: M (Maybe (Version, BlobKey)) getLatestApplicableVersionAndRev = do vsAndRevs <- runRIO ctx $ getHackagePackageVersions YesRequireHackageIndex UsePreferredVersions depname pure $ do lappVer <- latestApplicableVersion range $ Map.keysSet vsAndRevs revs <- Map.lookup lappVer vsAndRevs (cabalHash, _) <- Map.maxView revs Just (lappVer, cabalHash) case eres of Left e -> do addParent depname range Nothing let bd = case e of UnknownPackage name -> assert (name == depname) NotInBuildPlan DependencyCycleDetected names -> BDDependencyCycleDetected names -- ultimately we won't show any -- information on this to the user, we'll -- allow the dependency failures alone to -- display to avoid spamming the user too -- much DependencyPlanFailures _ _ -> Couldn'tResolveItsDependencies (packageVersion package) mlatestApplicable <- getLatestApplicableVersionAndRev pure $ Left (depname, (range, mlatestApplicable, bd)) Right adr | depType == AsLibrary && not (adrHasLibrary adr) -> pure $ Left (depname, (range, Nothing, HasNoLibrary)) Right adr -> do addParent depname range Nothing inRange <- if adrVersion adr `withinRange` range then pure True else do let warn_ reason = tell mempty { wWarnings = (msg:) } where msg = T.concat [ "WARNING: Ignoring " , T.pack $ packageNameString $ packageName package , "'s bounds on " , T.pack $ packageNameString depname , " (" , versionRangeText range , "); using " , T.pack $ packageIdentifierString $ PackageIdentifier depname (adrVersion adr) , ".\nReason: " , reason , "." ] allowNewer <- view $ configL.to configAllowNewer allowNewerDeps <- view $ configL.to configAllowNewerDeps let inSnapshotCheck = do -- We ignore dependency information for packages in a snapshot x <- inSnapshot (packageName package) (packageVersion package) y <- inSnapshot depname (adrVersion adr) if x && y then do warn_ "trusting snapshot over Cabal file dependency information" pure True else pure False if allowNewer then do warn_ "allow-newer enabled" case allowNewerDeps of Nothing -> pure True Just boundsIgnoredDeps -> pure $ packageName package `elem` boundsIgnoredDeps else do when (isJust allowNewerDeps) $ warn_ "allow-newer-deps are specified but allow-newer isn't enabled" inSnapshotCheck if inRange then case adr of ADRToInstall task -> pure $ Right (Set.singleton $ taskProvides task, Map.empty, taskTargetIsMutable task) ADRFound loc (Executable _) -> pure $ Right (Set.empty, Map.empty, installLocationIsMutable loc) ADRFound loc (Library ident gid _) -> pure $ Right (Set.empty, Map.singleton ident gid, installLocationIsMutable loc) else do mlatestApplicable <- getLatestApplicableVersionAndRev pure $ Left (depname, (range, mlatestApplicable, DependencyMismatch $ adrVersion adr)) case partitionEithers deps of -- Note that the Monoid for 'InstallLocation' means that if any -- is 'Local', the result is 'Local', indicating that the parent -- package must be installed locally. Otherwise the result is -- 'Snap', indicating that the parent can either be installed -- locally or in the snapshot. ([], pairs) -> pure $ Right $ mconcat pairs (errs, _) -> pure $ Left $ DependencyPlanFailures package (Map.fromList errs) where adrVersion (ADRToInstall task) = pkgVersion $ taskProvides task adrVersion (ADRFound _ installed) = installedVersion installed -- Update the parents map, for later use in plan construction errors -- - see 'getShortestDepsPath'. addParent depname range mversion = tell mempty { wParents = MonoidMap $ M.singleton depname val } where val = (First mversion, [(packageIdentifier package, range)]) adrHasLibrary :: AddDepRes -> Bool adrHasLibrary (ADRToInstall task) = taskHasLibrary task adrHasLibrary (ADRFound _ Library{}) = True adrHasLibrary (ADRFound _ Executable{}) = False taskHasLibrary :: Task -> Bool taskHasLibrary task = case taskType task of TTLocalMutable lp -> packageHasLibrary $ lpPackage lp TTRemotePackage _ p _ -> packageHasLibrary p -- make sure we consider internal libraries as libraries too packageHasLibrary :: Package -> Bool packageHasLibrary p = not (Set.null (packageInternalLibraries p)) || case packageLibraries p of HasLibraries _ -> True NoLibraries -> False checkDirtiness :: PackageSource -> Installed -> Package -> Map PackageIdentifier GhcPkgId -> Bool -> M Bool checkDirtiness ps installed package present buildHaddocks = do ctx <- ask moldOpts <- runRIO ctx $ tryGetFlagCache installed let configOpts = configureOpts (view envConfigL ctx) (baseConfigOpts ctx) present (psLocal ps) (installLocationIsMutable $ psLocation ps) -- should be Local i.e. mutable always package wantConfigCache = ConfigCache { configCacheOpts = configOpts , configCacheDeps = Set.fromList $ Map.elems present , configCacheComponents = case ps of PSFilePath lp -> Set.map (encodeUtf8 . renderComponent) $ lpComponents lp PSRemote{} -> Set.empty , configCacheHaddock = buildHaddocks , configCachePkgSrc = toCachePkgSrc ps , configCachePathEnvVar = pathEnvVar ctx } config = view configL ctx mreason <- case moldOpts of Nothing -> pure $ Just "old configure information not found" Just oldOpts | Just reason <- describeConfigDiff config oldOpts wantConfigCache -> pure $ Just reason | True <- psForceDirty ps -> pure $ Just "--force-dirty specified" | otherwise -> do dirty <- psDirty ps pure $ case dirty of Just files -> Just $ "local file changes: " <> addEllipsis (T.pack $ unwords $ Set.toList files) Nothing -> Nothing case mreason of Nothing -> pure False Just reason -> do tell mempty { wDirty = Map.singleton (packageName package) reason } pure True describeConfigDiff :: Config -> ConfigCache -> ConfigCache -> Maybe Text describeConfigDiff config old new | configCachePkgSrc old /= configCachePkgSrc new = Just $ "switching from " <> pkgSrcName (configCachePkgSrc old) <> " to " <> pkgSrcName (configCachePkgSrc new) | not (configCacheDeps new `Set.isSubsetOf` configCacheDeps old) = Just "dependencies changed" | not $ Set.null newComponents = Just $ "components added: " `T.append` T.intercalate ", " (map (decodeUtf8With lenientDecode) (Set.toList newComponents)) | not (configCacheHaddock old) && configCacheHaddock new = Just "rebuilding with haddocks" | oldOpts /= newOpts = Just $ T.pack $ concat [ "flags changed from " , show oldOpts , " to " , show newOpts ] | otherwise = Nothing where stripGhcOptions = go where go [] = [] go ("--ghc-option":x:xs) = go' Ghc x xs go ("--ghc-options":x:xs) = go' Ghc x xs go ((T.stripPrefix "--ghc-option=" -> Just x):xs) = go' Ghc x xs go ((T.stripPrefix "--ghc-options=" -> Just x):xs) = go' Ghc x xs go (x:xs) = x : go xs go' wc x xs = checkKeepers wc x $ go xs checkKeepers wc x xs = case filter isKeeper $ T.words x of [] -> xs keepers -> T.pack (compilerOptionsCabalFlag wc) : T.unwords keepers : xs -- GHC options which affect build results and therefore should always -- force a rebuild -- -- For the most part, we only care about options generated by Stack -- itself isKeeper = (== "-fhpc") -- more to be added later userOpts = filter (not . isStackOpt) . (if configRebuildGhcOptions config then id else stripGhcOptions) . map T.pack . (\(ConfigureOpts x y) -> x ++ y) . configCacheOpts (oldOpts, newOpts) = removeMatching (userOpts old) (userOpts new) removeMatching (x:xs) (y:ys) | x == y = removeMatching xs ys removeMatching xs ys = (xs, ys) newComponents = configCacheComponents new `Set.difference` configCacheComponents old pkgSrcName (CacheSrcLocal fp) = T.pack fp pkgSrcName CacheSrcUpstream = "upstream source" psForceDirty :: PackageSource -> Bool psForceDirty (PSFilePath lp) = lpForceDirty lp psForceDirty PSRemote{} = False psDirty :: (MonadIO m, HasEnvConfig env, MonadReader env m) => PackageSource -> m (Maybe (Set FilePath)) psDirty (PSFilePath lp) = runMemoizedWith $ lpDirtyFiles lp psDirty PSRemote {} = pure Nothing -- files never change in a remote package psLocal :: PackageSource -> Bool psLocal (PSFilePath _ ) = True psLocal PSRemote{} = False psLocation :: PackageSource -> InstallLocation psLocation (PSFilePath _) = Local psLocation PSRemote{} = Snap -- | Get all of the dependencies for a given package, including build -- tool dependencies. checkAndWarnForUnknownTools :: Package -> M () checkAndWarnForUnknownTools p = do -- Check whether the tool is on the PATH before warning about it. warnings <- fmap catMaybes $ forM (Set.toList $ packageUnknownTools p) $ \name@(ExeName toolName) -> do let settings = minimalEnvSettings { esIncludeLocals = True } config <- view configL menv <- liftIO $ configProcessContextSettings config settings mfound <- runRIO menv $ findExecutable $ T.unpack toolName case mfound of Left _ -> pure $ Just $ ToolWarning name (packageName p) Right _ -> pure Nothing tell mempty { wWarnings = (map toolWarningText warnings ++) } pure () -- | Warn about tools in the snapshot definition. States the tool name -- expected and the package name using it. data ToolWarning = ToolWarning ExeName PackageName deriving Show toolWarningText :: ToolWarning -> Text toolWarningText (ToolWarning (ExeName toolName) pkgName') = "No packages found in snapshot which provide a " <> T.pack (show toolName) <> " executable, which is a build-tool dependency of " <> T.pack (packageNameString pkgName') -- | Strip out anything from the @Plan@ intended for the local database stripLocals :: Plan -> Plan stripLocals plan = plan { planTasks = Map.filter checkTask $ planTasks plan , planFinals = Map.empty , planUnregisterLocal = Map.empty , planInstallExes = Map.filter (/= Local) $ planInstallExes plan } where checkTask task = taskLocation task == Snap stripNonDeps :: Set PackageName -> Plan -> Plan stripNonDeps deps plan = plan { planTasks = Map.filter checkTask $ planTasks plan , planFinals = Map.empty , planInstallExes = Map.empty -- TODO maybe don't disable this? } where checkTask task = taskProvides task `Set.member` missingForDeps providesDep task = pkgName (taskProvides task) `Set.member` deps missing = Map.fromList $ map (taskProvides &&& tcoMissing . taskConfigOpts) $ Map.elems (planTasks plan) missingForDeps = flip execState mempty $ do for_ (Map.elems $ planTasks plan) $ \task -> when (providesDep task) $ collectMissing mempty (taskProvides task) collectMissing dependents pid = do when (pid `elem` dependents) $ impureThrow $ TaskCycleBug pid modify'(<> Set.singleton pid) mapM_ (collectMissing (pid:dependents)) (fromMaybe mempty $ M.lookup pid missing) -- | Is the given package/version combo defined in the snapshot or in the global database? inSnapshot :: PackageName -> Version -> M Bool inSnapshot name version = do ctx <- ask pure $ fromMaybe False $ do ps <- Map.lookup name (combinedMap ctx) case ps of PIOnlySource (PSRemote _ srcVersion FromSnapshot _) -> pure $ srcVersion == version PIBoth (PSRemote _ srcVersion FromSnapshot _) _ -> pure $ srcVersion == version -- OnlyInstalled occurs for global database PIOnlyInstalled loc (Library pid _gid _lic) -> assert (loc == Snap) $ assert (pkgVersion pid == version) $ Just True _ -> pure False -- TODO: Consider intersecting version ranges for multiple deps on a -- package. This is why VersionRange is in the parent map. -- Switch this to 'True' to enable some debugging putStrLn in this module planDebug :: MonadIO m => String -> m () planDebug = if False then liftIO . putStrLn else \_ -> pure () stack-2.9.3.1/src/Stack/Build/Execute.hs0000644000000000000000000033513314445022466016027 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeFamilies #-} -- | Perform a build module Stack.Build.Execute ( printPlan , preFetch , executePlan -- * Running Setup.hs , ExecuteEnv , withExecuteEnv , withSingleContext , ExcludeTHLoading (..) , KeepOutputOpen (..) ) where import Control.Concurrent.Execute import Control.Concurrent.STM ( check ) import Crypto.Hash import Data.Attoparsec.Text ( char, choice, digit, parseOnly ) import qualified Data.Attoparsec.Text as P ( string ) import qualified Data.ByteArray as Mem ( convert ) import qualified Data.ByteString as S import qualified Data.ByteString.Builder import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Base64.URL as B64URL import Data.Char ( isSpace ) import Conduit import qualified Data.Conduit.Binary as CB import qualified Data.Conduit.Filesystem as CF import qualified Data.Conduit.List as CL import Data.Conduit.Process.Typed ( createSource ) import qualified Data.Conduit.Text as CT import qualified Data.List as L import Data.List.NonEmpty ( nonEmpty ) import qualified Data.List.NonEmpty as NonEmpty ( toList ) import Data.List.Split ( chunksOf ) import qualified Data.Map.Strict as M import qualified Data.Map.Strict as Map import qualified Data.Set as Set import qualified Data.Text as T import Data.Text.Encoding ( decodeUtf8 ) import Data.Tuple import Data.Time ( ZonedTime, getZonedTime, formatTime, defaultTimeLocale ) import qualified Data.ByteString.Char8 as S8 import qualified Distribution.PackageDescription as C import qualified Distribution.Simple.Build.Macros as C import Distribution.System ( OS (Windows), Platform (Platform) ) import qualified Distribution.Text as C import Distribution.Types.PackageName ( mkPackageName ) import Distribution.Types.UnqualComponentName ( mkUnqualComponentName ) import Distribution.Verbosity ( showForCabal ) import Distribution.Version ( mkVersion ) import Pantry.Internal.Companion import Path import Path.CheckInstall import Path.Extra ( toFilePathNoTrailingSep, rejectMissingFile ) import Path.IO hiding ( findExecutable, makeAbsolute, withSystemTempDir ) import RIO.Process import Stack.Build.Cache import Stack.Build.Haddock import Stack.Build.Installed import Stack.Build.Source import Stack.Build.Target import Stack.Config import Stack.Constants import Stack.Constants.Config import Stack.Coverage import Stack.DefaultColorWhen ( defaultColorWhen ) import Stack.GhcPkg import Stack.Package import Stack.PackageDump import Stack.Prelude import Stack.Types.Build import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.PackageFile import Stack.Types.Version import qualified System.Directory as D import System.Environment ( getExecutablePath, lookupEnv ) import System.FileLock ( withTryFileLock, SharedExclusive (Exclusive) , withFileLock ) import qualified System.FilePath as FP import System.IO.Error ( isDoesNotExistError ) import System.PosixCompat.Files ( createLink, modificationTime, getFileStatus ) import System.Random ( randomIO ) -- | Has an executable been built or not? data ExecutableBuildStatus = ExecutableBuilt | ExecutableNotBuilt deriving (Show, Eq, Ord) -- | Fetch the packages necessary for a build, for example in combination with a dry run. preFetch :: HasEnvConfig env => Plan -> RIO env () preFetch plan | Set.null pkgLocs = logDebug "Nothing to fetch" | otherwise = do logDebug $ "Prefetching: " <> mconcat (L.intersperse ", " (display <$> Set.toList pkgLocs)) fetchPackages pkgLocs where pkgLocs = Set.unions $ map toPkgLoc $ Map.elems $ planTasks plan toPkgLoc task = case taskType task of TTLocalMutable{} -> Set.empty TTRemotePackage _ _ pkgloc -> Set.singleton pkgloc -- | Print a description of build plan for human consumption. printPlan :: HasRunner env => Plan -> RIO env () printPlan plan = do case Map.elems $ planUnregisterLocal plan of [] -> logInfo "No packages would be unregistered." xs -> do logInfo "Would unregister locally:" forM_ xs $ \(ident, reason) -> logInfo $ fromString (packageIdentifierString ident) <> if T.null reason then "" else " (" <> display reason <> ")" logInfo "" case Map.elems $ planTasks plan of [] -> logInfo "Nothing to build." xs -> do logInfo "Would build:" mapM_ (logInfo . displayTask) xs let hasTests = not . Set.null . testComponents . taskComponents hasBenches = not . Set.null . benchComponents . taskComponents tests = Map.elems $ Map.filter hasTests $ planFinals plan benches = Map.elems $ Map.filter hasBenches $ planFinals plan unless (null tests) $ do logInfo "" logInfo "Would test:" mapM_ (logInfo . displayTask) tests unless (null benches) $ do logInfo "" logInfo "Would benchmark:" mapM_ (logInfo . displayTask) benches logInfo "" case Map.toList $ planInstallExes plan of [] -> logInfo "No executables to be installed." xs -> do logInfo "Would install executables:" forM_ xs $ \(name, loc) -> logInfo $ display name <> " from " <> (case loc of Snap -> "snapshot" Local -> "local") <> " database" -- | For a dry run displayTask :: Task -> Utf8Builder displayTask task = fromString (packageIdentifierString (taskProvides task)) <> ": database=" <> (case taskLocation task of Snap -> "snapshot" Local -> "local") <> ", source=" <> (case taskType task of TTLocalMutable lp -> fromString $ toFilePath $ parent $ lpCabalFile lp TTRemotePackage _ _ pl -> display pl) <> (if Set.null missing then "" else ", after: " <> mconcat (L.intersperse "," (fromString . packageIdentifierString <$> Set.toList missing))) where missing = tcoMissing $ taskConfigOpts task data ExecuteEnv = ExecuteEnv { eeConfigureLock :: !(MVar ()) , eeInstallLock :: !(MVar ()) , eeBuildOpts :: !BuildOpts , eeBuildOptsCLI :: !BuildOptsCLI , eeBaseConfigOpts :: !BaseConfigOpts , eeGhcPkgIds :: !(TVar (Map PackageIdentifier Installed)) , eeTempDir :: !(Path Abs Dir) , eeSetupHs :: !(Path Abs File) -- ^ Temporary Setup.hs for simple builds , eeSetupShimHs :: !(Path Abs File) -- ^ Temporary SetupShim.hs, to provide access to initial-build-steps , eeSetupExe :: !(Maybe (Path Abs File)) -- ^ Compiled version of eeSetupHs , eeCabalPkgVer :: !Version , eeTotalWanted :: !Int , eeLocals :: ![LocalPackage] , eeGlobalDB :: !(Path Abs Dir) , eeGlobalDumpPkgs :: !(Map GhcPkgId DumpPackage) , eeSnapshotDumpPkgs :: !(TVar (Map GhcPkgId DumpPackage)) , eeLocalDumpPkgs :: !(TVar (Map GhcPkgId DumpPackage)) , eeLogFiles :: !(TChan (Path Abs Dir, Path Abs File)) , eeCustomBuilt :: !(IORef (Set PackageName)) -- ^ Stores which packages with custom-setup have already had their -- Setup.hs built. , eeLargestPackageName :: !(Maybe Int) -- ^ For nicer interleaved output: track the largest package name size , eePathEnvVar :: !Text -- ^ Value of the PATH environment variable } buildSetupArgs :: [String] buildSetupArgs = [ "-rtsopts" , "-threaded" , "-clear-package-db" , "-global-package-db" , "-hide-all-packages" , "-package" , "base" , "-main-is" , "StackSetupShim.mainOverride" ] simpleSetupCode :: Builder simpleSetupCode = "import Distribution.Simple\nmain = defaultMain" simpleSetupHash :: String simpleSetupHash = T.unpack $ decodeUtf8 $ S.take 8 $ B64URL.encode $ Mem.convert $ hashWith SHA256 $ toStrictBytes $ Data.ByteString.Builder.toLazyByteString $ encodeUtf8Builder (T.pack (unwords buildSetupArgs)) <> setupGhciShimCode <> simpleSetupCode -- | Get a compiled Setup exe getSetupExe :: HasEnvConfig env => Path Abs File -- ^ Setup.hs input file -> Path Abs File -- ^ SetupShim.hs input file -> Path Abs Dir -- ^ temporary directory -> RIO env (Maybe (Path Abs File)) getSetupExe setupHs setupShimHs tmpdir = do wc <- view $ actualCompilerVersionL.whichCompilerL platformDir <- platformGhcRelDir config <- view configL cabalVersionString <- view $ cabalVersionL.to versionString actualCompilerVersionString <- view $ actualCompilerVersionL.to compilerVersionString platform <- view platformL let baseNameS = concat [ "Cabal-simple_" , simpleSetupHash , "_" , cabalVersionString , "_" , actualCompilerVersionString ] exeNameS = baseNameS ++ case platform of Platform _ Windows -> ".exe" _ -> "" outputNameS = case wc of Ghc -> exeNameS setupDir = view stackRootL config relDirSetupExeCache platformDir exePath <- (setupDir ) <$> parseRelFile exeNameS exists <- liftIO $ D.doesFileExist $ toFilePath exePath if exists then pure $ Just exePath else do tmpExePath <- fmap (setupDir ) $ parseRelFile $ "tmp-" ++ exeNameS tmpOutputPath <- fmap (setupDir ) $ parseRelFile $ "tmp-" ++ outputNameS ensureDir setupDir let args = buildSetupArgs ++ [ "-package" , "Cabal-" ++ cabalVersionString , toFilePath setupHs , toFilePath setupShimHs , "-o" , toFilePath tmpOutputPath ] compilerPath <- getCompilerPath withWorkingDir (toFilePath tmpdir) $ proc (toFilePath compilerPath) args (\pc0 -> do let pc = setStdout (useHandleOpen stderr) pc0 runProcess_ pc) `catch` \ece -> throwM $ PrettyException $ SetupHsBuildFailure (eceExitCode ece) Nothing compilerPath args Nothing [] renameFile tmpExePath exePath pure $ Just exePath -- | Execute a function that takes an 'ExecuteEnv'. withExecuteEnv :: forall env a. HasEnvConfig env => BuildOpts -> BuildOptsCLI -> BaseConfigOpts -> [LocalPackage] -> [DumpPackage] -- ^ global packages -> [DumpPackage] -- ^ snapshot packages -> [DumpPackage] -- ^ local packages -> Maybe Int -- ^ largest package name, for nicer interleaved output -> (ExecuteEnv -> RIO env a) -> RIO env a withExecuteEnv bopts boptsCli baseConfigOpts locals globalPackages snapshotPackages localPackages mlargestPackageName inner = createTempDirFunction stackProgName $ \tmpdir -> do configLock <- liftIO $ newMVar () installLock <- liftIO $ newMVar () idMap <- liftIO $ newTVarIO Map.empty config <- view configL customBuiltRef <- newIORef Set.empty -- Create files for simple setup and setup shim, if necessary let setupSrcDir = view stackRootL config relDirSetupExeSrc ensureDir setupSrcDir setupFileName <- parseRelFile ("setup-" ++ simpleSetupHash ++ ".hs") let setupHs = setupSrcDir setupFileName setupHsExists <- doesFileExist setupHs unless setupHsExists $ writeBinaryFileAtomic setupHs simpleSetupCode setupShimFileName <- parseRelFile ("setup-shim-" ++ simpleSetupHash ++ ".hs") let setupShimHs = setupSrcDir setupShimFileName setupShimHsExists <- doesFileExist setupShimHs unless setupShimHsExists $ writeBinaryFileAtomic setupShimHs setupGhciShimCode setupExe <- getSetupExe setupHs setupShimHs tmpdir cabalPkgVer <- view cabalVersionL globalDB <- view $ compilerPathsL.to cpGlobalDB snapshotPackagesTVar <- liftIO $ newTVarIO (toDumpPackagesByGhcPkgId snapshotPackages) localPackagesTVar <- liftIO $ newTVarIO (toDumpPackagesByGhcPkgId localPackages) logFilesTChan <- liftIO $ atomically newTChan let totalWanted = length $ filter lpWanted locals pathEnvVar <- liftIO $ maybe mempty T.pack <$> lookupEnv "PATH" inner ExecuteEnv { eeBuildOpts = bopts , eeBuildOptsCLI = boptsCli -- Uncertain as to why we cannot run configures in parallel. This -- appears to be a Cabal library bug. Original issue: -- https://github.com/commercialhaskell/stack/issues/84. Ideally -- we'd be able to remove this. , eeConfigureLock = configLock , eeInstallLock = installLock , eeBaseConfigOpts = baseConfigOpts , eeGhcPkgIds = idMap , eeTempDir = tmpdir , eeSetupHs = setupHs , eeSetupShimHs = setupShimHs , eeSetupExe = setupExe , eeCabalPkgVer = cabalPkgVer , eeTotalWanted = totalWanted , eeLocals = locals , eeGlobalDB = globalDB , eeGlobalDumpPkgs = toDumpPackagesByGhcPkgId globalPackages , eeSnapshotDumpPkgs = snapshotPackagesTVar , eeLocalDumpPkgs = localPackagesTVar , eeLogFiles = logFilesTChan , eeCustomBuilt = customBuiltRef , eeLargestPackageName = mlargestPackageName , eePathEnvVar = pathEnvVar } `finally` dumpLogs logFilesTChan totalWanted where toDumpPackagesByGhcPkgId = Map.fromList . map (\dp -> (dpGhcPkgId dp, dp)) createTempDirFunction | boptsKeepTmpFiles bopts = withKeepSystemTempDir | otherwise = withSystemTempDir dumpLogs :: TChan (Path Abs Dir, Path Abs File) -> Int -> RIO env () dumpLogs chan totalWanted = do allLogs <- fmap reverse $ liftIO $ atomically drainChan case allLogs of -- No log files generated, nothing to dump [] -> pure () firstLog:_ -> do toDump <- view $ configL.to configDumpLogs case toDump of DumpAllLogs -> mapM_ (dumpLog "") allLogs DumpWarningLogs -> mapM_ dumpLogIfWarning allLogs DumpNoLogs | totalWanted > 1 -> logInfo $ "Build output has been captured to log files, use " <> "--dump-logs to see it on the console" | otherwise -> pure () logInfo $ "Log files have been written to: " <> fromString (toFilePath (parent (snd firstLog))) -- We only strip the colors /after/ we've dumped logs, so that -- we get pretty colors in our dump output on the terminal. colors <- shouldForceGhcColorFlag when colors $ liftIO $ mapM_ (stripColors . snd) allLogs where drainChan :: STM [(Path Abs Dir, Path Abs File)] drainChan = do mx <- tryReadTChan chan case mx of Nothing -> pure [] Just x -> do xs <- drainChan pure $ x:xs dumpLogIfWarning :: (Path Abs Dir, Path Abs File) -> RIO env () dumpLogIfWarning (pkgDir, filepath) = do firstWarning <- withSourceFile (toFilePath filepath) $ \src -> runConduit $ src .| CT.decodeUtf8Lenient .| CT.lines .| CL.map stripCR .| CL.filter isWarning .| CL.take 1 unless (null firstWarning) $ dumpLog " due to warnings" (pkgDir, filepath) isWarning :: Text -> Bool isWarning t = ": Warning:" `T.isSuffixOf` t -- prior to GHC 8 || ": warning:" `T.isInfixOf` t -- GHC 8 is slightly different || "mwarning:" `T.isInfixOf` t -- colorized output dumpLog :: String -> (Path Abs Dir, Path Abs File) -> RIO env () dumpLog msgSuffix (pkgDir, filepath) = do logInfo $ "\n-- Dumping log file" <> fromString msgSuffix <> ": " <> fromString (toFilePath filepath) <> "\n" compilerVer <- view actualCompilerVersionL withSourceFile (toFilePath filepath) $ \src -> runConduit $ src .| CT.decodeUtf8Lenient .| mungeBuildOutput ExcludeTHLoading ConvertPathsToAbsolute pkgDir compilerVer .| CL.mapM_ (logInfo . display) logInfo $ "\n-- End of log file: " <> fromString (toFilePath filepath) <> "\n" stripColors :: Path Abs File -> IO () stripColors fp = do let colorfp = toFilePath fp ++ "-color" withSourceFile (toFilePath fp) $ \src -> withSinkFile colorfp $ \sink -> runConduit $ src .| sink withSourceFile colorfp $ \src -> withSinkFile (toFilePath fp) $ \sink -> runConduit $ src .| noColors .| sink where noColors = do CB.takeWhile (/= 27) -- ESC mnext <- CB.head case mnext of Nothing -> pure () Just x -> assert (x == 27) $ do -- Color sequences always end with an m CB.dropWhile (/= 109) -- m CB.drop 1 -- drop the m itself noColors -- | Perform the actual plan executePlan :: HasEnvConfig env => BuildOptsCLI -> BaseConfigOpts -> [LocalPackage] -> [DumpPackage] -- ^ global packages -> [DumpPackage] -- ^ snapshot packages -> [DumpPackage] -- ^ local packages -> InstalledMap -> Map PackageName Target -> Plan -> RIO env () executePlan boptsCli baseConfigOpts locals globalPackages snapshotPackages localPackages installedMap targets plan = do logDebug "Executing the build plan" bopts <- view buildOptsL withExecuteEnv bopts boptsCli baseConfigOpts locals globalPackages snapshotPackages localPackages mlargestPackageName (executePlan' installedMap targets plan) copyExecutables (planInstallExes plan) config <- view configL menv' <- liftIO $ configProcessContextSettings config EnvSettings { esIncludeLocals = True , esIncludeGhcPackagePath = True , esStackExe = True , esLocaleUtf8 = False , esKeepGhcRts = False } withProcessContext menv' $ forM_ (boptsCLIExec boptsCli) $ \(cmd, args) -> proc cmd args runProcess_ where mlargestPackageName = Set.lookupMax $ Set.map (length . packageNameString) $ Map.keysSet (planTasks plan) <> Map.keysSet (planFinals plan) copyExecutables :: HasEnvConfig env => Map Text InstallLocation -> RIO env () copyExecutables exes | Map.null exes = pure () copyExecutables exes = do snapBin <- ( bindirSuffix) `liftM` installationRootDeps localBin <- ( bindirSuffix) `liftM` installationRootLocal compilerSpecific <- boptsInstallCompilerTool <$> view buildOptsL destDir <- if compilerSpecific then bindirCompilerTools else view $ configL.to configLocalBin ensureDir destDir destDir' <- liftIO . D.canonicalizePath . toFilePath $ destDir platform <- view platformL let ext = case platform of Platform _ Windows -> ".exe" _ -> "" currExe <- liftIO getExecutablePath -- needed for windows, see below installed <- forMaybeM (Map.toList exes) $ \(name, loc) -> do let bindir = case loc of Snap -> snapBin Local -> localBin mfp <- liftIO $ forgivingAbsence (resolveFile bindir $ T.unpack name ++ ext) >>= rejectMissingFile case mfp of Nothing -> do logWarn $ "Couldn't find executable " <> display name <> " in directory " <> fromString (toFilePath bindir) pure Nothing Just file -> do let destFile = destDir' FP. T.unpack name ++ ext logInfo $ "Copying from " <> fromString (toFilePath file) <> " to " <> fromString destFile liftIO $ case platform of Platform _ Windows | FP.equalFilePath destFile currExe -> windowsRenameCopy (toFilePath file) destFile _ -> D.copyFile (toFilePath file) destFile pure $ Just (name <> T.pack ext) unless (null installed) $ do logInfo "" logInfo $ "Copied executables to " <> fromString destDir' <> ":" forM_ installed $ \exe -> logInfo ("- " <> display exe) unless compilerSpecific $ warnInstallSearchPathIssues destDir' installed -- | Windows can't write over the current executable. Instead, we rename the -- current executable to something else and then do the copy. windowsRenameCopy :: FilePath -> FilePath -> IO () windowsRenameCopy src dest = do D.copyFile src new D.renameFile dest old D.renameFile new dest where new = dest ++ ".new" old = dest ++ ".old" -- | Perform the actual plan (internal) executePlan' :: HasEnvConfig env => InstalledMap -> Map PackageName Target -> Plan -> ExecuteEnv -> RIO env () executePlan' installedMap0 targets plan ee@ExecuteEnv {..} = do when (toCoverage $ boptsTestOpts eeBuildOpts) deleteHpcReports cv <- view actualCompilerVersionL case nonEmpty . Map.toList $ planUnregisterLocal plan of Nothing -> pure () Just ids -> do localDB <- packageDatabaseLocal unregisterPackages cv localDB ids liftIO $ atomically $ modifyTVar' eeLocalDumpPkgs $ \initMap -> foldl' (flip Map.delete) initMap $ Map.keys (planUnregisterLocal plan) run <- askRunInIO -- If running tests concurrently with each other, then create an MVar -- which is empty while each test is being run. concurrentTests <- view $ configL.to configConcurrentTests mtestLock <- if concurrentTests then pure Nothing else Just <$> liftIO (newMVar ()) let actions = concatMap (toActions installedMap' mtestLock run ee) $ Map.elems $ Map.mergeWithKey (\_ b f -> Just (Just b, Just f)) (fmap (\b -> (Just b, Nothing))) (fmap (\f -> (Nothing, Just f))) (planTasks plan) (planFinals plan) threads <- view $ configL.to configJobs let keepGoing = fromMaybe (not (M.null (planFinals plan))) (boptsKeepGoing eeBuildOpts) terminal <- view terminalL errs <- liftIO $ runActions threads keepGoing actions $ \doneVar actionsVar -> do let total = length actions loop prev | prev == total = run $ logStickyDone ("Completed " <> display total <> " action(s).") | otherwise = do inProgress <- readTVarIO actionsVar let packageNames = map (\(ActionId pkgID _) -> pkgName pkgID) (toList inProgress) nowBuilding :: [PackageName] -> Utf8Builder nowBuilding [] = "" nowBuilding names = mconcat $ ": " : L.intersperse ", " (map (fromString . packageNameString) names) when terminal $ run $ logSticky $ "Progress " <> display prev <> "/" <> display total <> nowBuilding packageNames done <- atomically $ do done <- readTVar doneVar check $ done /= prev pure done loop done when (total > 1) $ loop 0 when (toCoverage $ boptsTestOpts eeBuildOpts) $ do generateHpcUnifiedReport generateHpcMarkupIndex unless (null errs) $ throwM $ PrettyException (ExecutionFailure errs) when (boptsHaddock eeBuildOpts) $ do snapshotDumpPkgs <- liftIO (readTVarIO eeSnapshotDumpPkgs) localDumpPkgs <- liftIO (readTVarIO eeLocalDumpPkgs) generateLocalHaddockIndex eeBaseConfigOpts localDumpPkgs eeLocals generateDepsHaddockIndex eeBaseConfigOpts eeGlobalDumpPkgs snapshotDumpPkgs localDumpPkgs eeLocals generateSnapHaddockIndex eeBaseConfigOpts eeGlobalDumpPkgs snapshotDumpPkgs when (boptsOpenHaddocks eeBuildOpts) $ do let planPkgs, localPkgs, installedPkgs, availablePkgs :: Map PackageName (PackageIdentifier, InstallLocation) planPkgs = Map.map (taskProvides &&& taskLocation) (planTasks plan) localPkgs = Map.fromList [(packageName p, (packageIdentifier p, Local)) | p <- map lpPackage eeLocals] installedPkgs = Map.map (swap . second installedPackageIdentifier) installedMap' availablePkgs = Map.unions [planPkgs, localPkgs, installedPkgs] openHaddocksInBrowser eeBaseConfigOpts availablePkgs (Map.keysSet targets) where installedMap' = Map.difference installedMap0 $ Map.fromList $ map (\(ident, _) -> (pkgName ident, ())) $ Map.elems $ planUnregisterLocal plan unregisterPackages :: (HasProcessContext env, HasLogFunc env, HasPlatform env, HasCompiler env) => ActualCompiler -> Path Abs Dir -> NonEmpty (GhcPkgId, (PackageIdentifier, Text)) -> RIO env () unregisterPackages cv localDB ids = do let logReason ident reason = logInfo $ fromString (packageIdentifierString ident) <> ": unregistering" <> if T.null reason then "" else " (" <> display reason <> ")" let unregisterSinglePkg select (gid, (ident, reason)) = do logReason ident reason pkg <- getGhcPkgExe unregisterGhcPkgIds pkg localDB $ select ident gid :| [] case cv of -- GHC versions >= 8.2.1 support batch unregistering of packages. See -- https://gitlab.haskell.org/ghc/ghc/issues/12637 ACGhc v | v >= mkVersion [8, 2, 1] -> do platform <- view platformL -- According to https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation -- the maximum command line length on Windows since XP is 8191 characters. -- We use conservative batch size of 100 ids on this OS thus argument name '-ipid', package name, -- its version and a hash should fit well into this limit. -- On Unix-like systems we're limited by ARG_MAX which is normally hundreds -- of kilobytes so batch size of 500 should work fine. let batchSize = case platform of Platform _ Windows -> 100 _ -> 500 let chunksOfNE size = mapMaybe nonEmpty . chunksOf size . NonEmpty.toList for_ (chunksOfNE batchSize ids) $ \batch -> do for_ batch $ \(_, (ident, reason)) -> logReason ident reason pkg <- getGhcPkgExe unregisterGhcPkgIds pkg localDB $ fmap (Right . fst) batch -- GHC versions >= 7.9 support unregistering of packages via their -- GhcPkgId. ACGhc v | v >= mkVersion [7, 9] -> for_ ids . unregisterSinglePkg $ \_ident gid -> Right gid _ -> for_ ids . unregisterSinglePkg $ \ident _gid -> Left ident toActions :: HasEnvConfig env => InstalledMap -> Maybe (MVar ()) -> (RIO env () -> IO ()) -> ExecuteEnv -> (Maybe Task, Maybe Task) -- build and final -> [Action] toActions installedMap mtestLock runInBase ee (mbuild, mfinal) = abuild ++ afinal where abuild = case mbuild of Nothing -> [] Just task@Task {..} -> [ Action { actionId = ActionId taskProvides ATBuild , actionDeps = Set.map (\ident -> ActionId ident ATBuild) (tcoMissing taskConfigOpts) , actionDo = \ac -> runInBase $ singleBuild ac ee task installedMap False , actionConcurrency = ConcurrencyAllowed } ] afinal = case mfinal of Nothing -> [] Just task@Task {..} -> (if taskAllInOne then id else (:) Action { actionId = ActionId taskProvides ATBuildFinal , actionDeps = addBuild (Set.map (\ident -> ActionId ident ATBuild) (tcoMissing taskConfigOpts)) , actionDo = \ac -> runInBase $ singleBuild ac ee task installedMap True , actionConcurrency = ConcurrencyAllowed }) $ -- These are the "final" actions - running tests and benchmarks. (if Set.null tests then id else (:) Action { actionId = ActionId taskProvides ATRunTests , actionDeps = finalDeps , actionDo = \ac -> withLock mtestLock $ runInBase $ do singleTest topts (Set.toList tests) ac ee task installedMap -- Always allow tests tasks to run concurrently with -- other tasks, particularly build tasks. Note that -- 'mtestLock' can optionally make it so that only -- one test is run at a time. , actionConcurrency = ConcurrencyAllowed }) $ (if Set.null benches then id else (:) Action { actionId = ActionId taskProvides ATRunBenchmarks , actionDeps = finalDeps , actionDo = \ac -> runInBase $ do singleBench beopts (Set.toList benches) ac ee task installedMap -- Never run benchmarks concurrently with any other task, see #3663 , actionConcurrency = ConcurrencyDisallowed }) [] where comps = taskComponents task tests = testComponents comps benches = benchComponents comps finalDeps = if taskAllInOne then addBuild mempty else Set.singleton (ActionId taskProvides ATBuildFinal) addBuild = case mbuild of Nothing -> id Just _ -> Set.insert $ ActionId taskProvides ATBuild withLock Nothing f = f withLock (Just lock) f = withMVar lock $ \() -> f bopts = eeBuildOpts ee topts = boptsTestOpts bopts beopts = boptsBenchmarkOpts bopts -- | Generate the ConfigCache getConfigCache :: HasEnvConfig env => ExecuteEnv -> Task -> InstalledMap -> Bool -> Bool -> RIO env (Map PackageIdentifier GhcPkgId, ConfigCache) getConfigCache ExecuteEnv {..} task@Task {..} installedMap enableTest enableBench = do let extra = -- We enable tests if the test suite dependencies are already -- installed, so that we avoid unnecessary recompilation based on -- cabal_macros.h changes when switching between 'stack build' and -- 'stack test'. See: -- https://github.com/commercialhaskell/stack/issues/805 case taskType of TTLocalMutable _ -> -- FIXME: make this work with exact-configuration. -- Not sure how to plumb the info atm. See -- https://github.com/commercialhaskell/stack/issues/2049 [ "--enable-tests" | enableTest] ++ [ "--enable-benchmarks" | enableBench] TTRemotePackage{} -> [] idMap <- liftIO $ readTVarIO eeGhcPkgIds let getMissing ident = case Map.lookup ident idMap of Nothing -- Expect to instead find it in installedMap if it's -- an initialBuildSteps target. | boptsCLIInitialBuildSteps eeBuildOptsCLI && taskIsTarget task, Just (_, installed) <- Map.lookup (pkgName ident) installedMap -> installedToGhcPkgId ident installed Just installed -> installedToGhcPkgId ident installed _ -> throwM $ PackageIdMissingBug ident installedToGhcPkgId ident (Library ident' x _) = assert (ident == ident') $ Just (ident, x) installedToGhcPkgId _ (Executable _) = Nothing missing' = Map.fromList $ mapMaybe getMissing $ Set.toList missing TaskConfigOpts missing mkOpts = taskConfigOpts opts = mkOpts missing' allDeps = Set.fromList $ Map.elems missing' ++ Map.elems taskPresent cache = ConfigCache { configCacheOpts = opts { coNoDirs = coNoDirs opts ++ map T.unpack extra } , configCacheDeps = allDeps , configCacheComponents = case taskType of TTLocalMutable lp -> Set.map (encodeUtf8 . renderComponent) $ lpComponents lp TTRemotePackage{} -> Set.empty , configCacheHaddock = taskBuildHaddock , configCachePkgSrc = taskCachePkgSrc , configCachePathEnvVar = eePathEnvVar } allDepsMap = Map.union missing' taskPresent pure (allDepsMap, cache) -- | Ensure that the configuration for the package matches what is given ensureConfig :: HasEnvConfig env => ConfigCache -- ^ newConfigCache -> Path Abs Dir -- ^ package directory -> ExecuteEnv -> RIO env () -- ^ announce -> (ExcludeTHLoading -> [String] -> RIO env ()) -- ^ cabal -> Path Abs File -- ^ Cabal file -> Task -> RIO env Bool ensureConfig newConfigCache pkgDir ExecuteEnv {..} announce cabal cabalfp task = do newCabalMod <- liftIO $ modificationTime <$> getFileStatus (toFilePath cabalfp) setupConfigfp <- setupConfigFromDir pkgDir let getNewSetupConfigMod = liftIO $ either (const Nothing) (Just . modificationTime) <$> tryJust (guard . isDoesNotExistError) (getFileStatus (toFilePath setupConfigfp)) newSetupConfigMod <- getNewSetupConfigMod newProjectRoot <- S8.pack . toFilePath <$> view projectRootL -- See https://github.com/commercialhaskell/stack/issues/3554 taskAnyMissingHack <- view $ actualCompilerVersionL.to getGhcVersion.to (< mkVersion [8, 4]) needConfig <- if boptsReconfigure eeBuildOpts || (taskAnyMissing task && taskAnyMissingHack) then pure True else do -- We can ignore the components portion of the config -- cache, because it's just used to inform 'construct -- plan that we need to plan to build additional -- components. These components don't affect the actual -- package configuration. let ignoreComponents cc = cc { configCacheComponents = Set.empty } -- Determine the old and new configuration in the local directory, to -- determine if we need to reconfigure. mOldConfigCache <- tryGetConfigCache pkgDir mOldCabalMod <- tryGetCabalMod pkgDir -- Cabal's setup-config is created per OS/Cabal version, multiple -- projects using the same package could get a conflict because of this mOldSetupConfigMod <- tryGetSetupConfigMod pkgDir mOldProjectRoot <- tryGetPackageProjectRoot pkgDir pure $ fmap ignoreComponents mOldConfigCache /= Just (ignoreComponents newConfigCache) || mOldCabalMod /= Just newCabalMod || mOldSetupConfigMod /= newSetupConfigMod || mOldProjectRoot /= Just newProjectRoot let ConfigureOpts dirs nodirs = configCacheOpts newConfigCache when (taskBuildTypeConfig task) ensureConfigureScript when needConfig $ withMVar eeConfigureLock $ \_ -> do deleteCaches pkgDir announce cp <- view compilerPathsL let (GhcPkgExe pkgPath) = cpPkg cp let programNames = case cpWhich cp of Ghc -> [ ("ghc", toFilePath (cpCompiler cp)) , ("ghc-pkg", toFilePath pkgPath) ] exes <- forM programNames $ \(name, file) -> do mpath <- findExecutable file pure $ case mpath of Left _ -> [] Right x -> pure $ concat ["--with-", name, "=", x] -- Configure cabal with arguments determined by -- Stack.Types.Build.configureOpts cabal KeepTHLoading $ "configure" : concat [ concat exes , dirs , nodirs ] -- Only write the cache for local packages. Remote packages are built -- in a temporary directory so the cache would never be used anyway. case taskType task of TTLocalMutable{} -> writeConfigCache pkgDir newConfigCache TTRemotePackage{} -> pure () writeCabalMod pkgDir newCabalMod -- This file gets updated one more time by the configure step, so get -- the most recent value. We could instead change our logic above to -- check if our config mod file is newer than the file above, but this -- seems reasonable too. getNewSetupConfigMod >>= writeSetupConfigMod pkgDir writePackageProjectRoot pkgDir newProjectRoot pure needConfig where -- When build-type is Configure, we need to have a configure -- script in the local directory. If it doesn't exist, build it -- with autoreconf -i. See: -- https://github.com/commercialhaskell/stack/issues/3534 ensureConfigureScript = do let fp = pkgDir relFileConfigure exists <- doesFileExist fp unless exists $ do logInfo $ "Trying to generate configure with autoreconf in " <> fromString (toFilePath pkgDir) let autoreconf = if osIsWindows then readProcessNull "sh" ["autoreconf", "-i"] else readProcessNull "autoreconf" ["-i"] -- On Windows 10, an upstream issue with the `sh autoreconf -i` -- command means that command clears, but does not then restore, the -- ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for native terminals. The -- following hack re-enables the lost ANSI-capability. fixupOnWindows = when osIsWindows (void $ liftIO defaultColorWhen) withWorkingDir (toFilePath pkgDir) $ autoreconf `catchAny` \ex -> do fixupOnWindows logWarn $ "Unable to run autoreconf: " <> displayShow ex when osIsWindows $ do logInfo $ "Check that executable perl is on the path in Stack's " <> "MSYS2 \\usr\\bin folder, and working, and that script file " <> "autoreconf is on the path in that location. To check that " <> "perl or autoreconf are on the path in the required location, " <> "run commands:" logInfo "" logInfo " stack exec where -- perl" logInfo " stack exec where -- autoreconf" logInfo "" logInfo $ "If perl or autoreconf is not on the path in the " <> "required location, add them with command (note that the " <> "relevant package name is 'autoconf' not 'autoreconf'):" logInfo "" logInfo " stack exec pacman -- --sync --refresh autoconf" logInfo "" logInfo $ "Some versions of perl from MSYS2 are broken. See " <> "https://github.com/msys2/MSYS2-packages/issues/1611 and " <> "https://github.com/commercialhaskell/stack/pull/4781. To " <> "test if perl in the required location is working, try command:" logInfo "" logInfo " stack exec perl -- --version" logInfo "" fixupOnWindows -- | Make a padded prefix for log messages packageNamePrefix :: ExecuteEnv -> PackageName -> Utf8Builder packageNamePrefix ee name' = let name = packageNameString name' paddedName = case eeLargestPackageName ee of Nothing -> name Just len -> assert (len >= length name) $ take len $ name ++ L.repeat ' ' in fromString paddedName <> "> " announceTask :: HasLogFunc env => ExecuteEnv -> Task -> Utf8Builder -> RIO env () announceTask ee task action = logInfo $ packageNamePrefix ee (pkgName (taskProvides task)) <> action -- | Ensure we're the only action using the directory. See -- withLockedDistDir :: HasEnvConfig env => (Utf8Builder -> RIO env ()) -- ^ announce -> Path Abs Dir -- ^ root directory for package -> RIO env a -> RIO env a withLockedDistDir announce root inner = do distDir <- distRelativeDir let lockFP = root distDir relFileBuildLock ensureDir $ parent lockFP mres <- withRunInIO $ \run -> withTryFileLock (toFilePath lockFP) Exclusive $ \_lock -> run inner case mres of Just res -> pure res Nothing -> do let complainer delay = do delay 5000000 -- 5 seconds announce $ "blocking for directory lock on " <> fromString (toFilePath lockFP) forever $ do delay 30000000 -- 30 seconds announce $ "still blocking for directory lock on " <> fromString (toFilePath lockFP) <> "; maybe another Stack process is running?" withCompanion (\x -> complainer x) $ \stopComplaining -> withRunInIO $ \run -> withFileLock (toFilePath lockFP) Exclusive $ \_ -> run $ stopComplaining *> inner -- | How we deal with output from GHC, either dumping to a log file or the -- console (with some prefix). data OutputType = OTLogFile !(Path Abs File) !Handle | OTConsole !(Maybe Utf8Builder) -- | This sets up a context for executing build steps which need to run -- Cabal (via a compiled Setup.hs). In particular it does the following: -- -- * Ensures the package exists in the file system, downloading if necessary. -- -- * Opens a log file if the built output shouldn't go to stderr. -- -- * Ensures that either a simple Setup.hs is built, or the package's -- custom setup is built. -- -- * Provides the user a function with which run the Cabal process. withSingleContext :: forall env a. HasEnvConfig env => ActionContext -> ExecuteEnv -> Task -> Map PackageIdentifier GhcPkgId -- ^ All dependencies' package ids to provide to Setup.hs. -> Maybe String -> ( Package -- Package info -> Path Abs File -- Cabal file path -> Path Abs Dir -- Package root directory file path -- Note that the `Path Abs Dir` argument is redundant with the `Path Abs File` -- argument, but we provide both to avoid recalculating `parent` of the `File`. -> (KeepOutputOpen -> ExcludeTHLoading -> [String] -> RIO env ()) -- Function to run Cabal with args -> (Utf8Builder -> RIO env ()) -- An 'announce' function, for different build phases -> OutputType -> RIO env a) -> RIO env a withSingleContext ActionContext {..} ee@ExecuteEnv {..} task@Task {..} allDeps msuffix inner0 = withPackage $ \package cabalfp pkgDir -> withOutputType pkgDir package $ \outputType -> withCabal package pkgDir outputType $ \cabal -> inner0 package cabalfp pkgDir cabal announce outputType where announce = announceTask ee task wanted = case taskType of TTLocalMutable lp -> lpWanted lp TTRemotePackage{} -> False -- Output to the console if this is the last task, and the user -- asked to build it specifically. When the action is a -- 'ConcurrencyDisallowed' action (benchmarks), then we can also be -- sure to have exclusive access to the console, so output is also -- sent to the console in this case. -- -- See the discussion on #426 for thoughts on sending output to the -- console from concurrent tasks. console = (wanted && all (\(ActionId ident _) -> ident == taskProvides) (Set.toList acRemaining) && eeTotalWanted == 1 ) || (acConcurrency == ConcurrencyDisallowed) withPackage inner = case taskType of TTLocalMutable lp -> do let root = parent $ lpCabalFile lp withLockedDistDir announce root $ inner (lpPackage lp) (lpCabalFile lp) root TTRemotePackage _ package pkgloc -> do suffix <- parseRelDir $ packageIdentifierString $ packageIdent package let dir = eeTempDir suffix unpackPackageLocation dir pkgloc -- See: https://github.com/commercialhaskell/stack/issues/157 distDir <- distRelativeDir let oldDist = dir relDirDist newDist = dir distDir exists <- doesDirExist oldDist when exists $ do -- Previously used takeDirectory, but that got confused -- by trailing slashes, see: -- https://github.com/commercialhaskell/stack/issues/216 -- -- Instead, use Path which is a bit more resilient ensureDir $ parent newDist renameDir oldDist newDist let name = pkgName taskProvides cabalfpRel <- parseRelFile $ packageNameString name ++ ".cabal" let cabalfp = dir cabalfpRel inner package cabalfp dir withOutputType pkgDir package inner -- Not in interleaved mode. When building a single wanted package, dump -- to the console with no prefix. | console = inner $ OTConsole Nothing -- If the user requested interleaved output, dump to the console with a -- prefix. | boptsInterleavedOutput eeBuildOpts = inner $ OTConsole $ Just $ packageNamePrefix ee $ packageName package -- Neither condition applies, dump to a file. | otherwise = do logPath <- buildLogPath package msuffix ensureDir (parent logPath) let fp = toFilePath logPath -- We only want to dump logs for local non-dependency packages case taskType of TTLocalMutable lp | lpWanted lp -> liftIO $ atomically $ writeTChan eeLogFiles (pkgDir, logPath) _ -> pure () withBinaryFile fp WriteMode $ \h -> inner $ OTLogFile logPath h withCabal :: Package -> Path Abs Dir -> OutputType -> ((KeepOutputOpen -> ExcludeTHLoading -> [String] -> RIO env ()) -> RIO env a) -> RIO env a withCabal package pkgDir outputType inner = do config <- view configL unless (configAllowDifferentUser config) $ checkOwnership (pkgDir configWorkDir config) let envSettings = EnvSettings { esIncludeLocals = taskLocation task == Local , esIncludeGhcPackagePath = False , esStackExe = False , esLocaleUtf8 = True , esKeepGhcRts = False } menv <- liftIO $ configProcessContextSettings config envSettings distRelativeDir' <- distRelativeDir esetupexehs <- -- Avoid broken Setup.hs files causing problems for simple build -- types, see: -- https://github.com/commercialhaskell/stack/issues/370 case (packageBuildType package, eeSetupExe) of (C.Simple, Just setupExe) -> pure $ Left setupExe _ -> liftIO $ Right <$> getSetupHs pkgDir inner $ \keepOutputOpen stripTHLoading args -> do let cabalPackageArg -- Omit cabal package dependency when building -- Cabal. See -- https://github.com/commercialhaskell/stack/issues/1356 | packageName package == mkPackageName "Cabal" = [] | otherwise = ["-package=" ++ packageIdentifierString (PackageIdentifier cabalPackageName eeCabalPkgVer)] packageDBArgs = ( "-clear-package-db" : "-global-package-db" : map (("-package-db=" ++) . toFilePathNoTrailingSep) (bcoExtraDBs eeBaseConfigOpts) ) ++ ( ("-package-db=" ++ toFilePathNoTrailingSep (bcoSnapDB eeBaseConfigOpts)) : ("-package-db=" ++ toFilePathNoTrailingSep (bcoLocalDB eeBaseConfigOpts)) : ["-hide-all-packages"] ) warnCustomNoDeps :: RIO env () warnCustomNoDeps = case (taskType, packageBuildType package) of (TTLocalMutable lp, C.Custom) | lpWanted lp -> do prettyWarnL [ flow "Package" , fromString $ packageNameString $ packageName package , flow "uses a custom Cabal build, but does not use a custom-setup stanza" ] _ -> pure () getPackageArgs :: Path Abs Dir -> RIO env [String] getPackageArgs setupDir = case packageSetupDeps package of -- The package is using the Cabal custom-setup -- configuration introduced in Cabal 1.24. In -- this case, the package is providing an -- explicit list of dependencies, and we -- should simply use all of them. Just customSetupDeps -> do unless (Map.member (mkPackageName "Cabal") customSetupDeps) $ prettyWarnL [ fromString $ packageNameString $ packageName package , "has a setup-depends field, but it does not mention a Cabal dependency. This is likely to cause build errors." ] matchedDeps <- forM (Map.toList customSetupDeps) $ \(name, range) -> do let matches (PackageIdentifier name' version) = name == name' && version `withinRange` range case filter (matches . fst) (Map.toList allDeps) of x:xs -> do unless (null xs) (logWarn ("Found multiple installed packages for custom-setup dep: " <> fromString (packageNameString name))) pure ("-package-id=" ++ ghcPkgIdString (snd x), Just (fst x)) [] -> do logWarn ("Could not find custom-setup dep: " <> fromString (packageNameString name)) pure ("-package=" ++ packageNameString name, Nothing) let depsArgs = map fst matchedDeps -- Generate setup_macros.h and provide it to ghc let macroDeps = mapMaybe snd matchedDeps cppMacrosFile = setupDir relFileSetupMacrosH cppArgs = ["-optP-include", "-optP" ++ toFilePath cppMacrosFile] writeBinaryFileAtomic cppMacrosFile (encodeUtf8Builder (T.pack (C.generatePackageVersionMacros (packageVersion package) macroDeps))) pure (packageDBArgs ++ depsArgs ++ cppArgs) -- This branch is usually taken for builds, and -- is always taken for `stack sdist`. -- -- This approach is debatable. It adds access to the -- snapshot package database for Cabal. There are two -- possible objections: -- -- 1. This doesn't isolate the build enough; arbitrary -- other packages available could cause the build to -- succeed or fail. -- -- 2. This doesn't provide enough packages: we should also -- include the local database when building local packages. -- -- Currently, this branch is only taken via `stack -- sdist` or when explicitly requested in the -- stack.yaml file. Nothing -> do warnCustomNoDeps pure $ cabalPackageArg ++ -- NOTE: This is different from -- packageDBArgs above in that it does not -- include the local database and does not -- pass in the -hide-all-packages argument ("-clear-package-db" : "-global-package-db" : map (("-package-db=" ++) . toFilePathNoTrailingSep) (bcoExtraDBs eeBaseConfigOpts) ++ ["-package-db=" ++ toFilePathNoTrailingSep (bcoSnapDB eeBaseConfigOpts)]) setupArgs = ("--builddir=" ++ toFilePathNoTrailingSep distRelativeDir') : args runExe :: Path Abs File -> [String] -> RIO env () runExe exeName fullArgs = do compilerVer <- view actualCompilerVersionL runAndOutput compilerVer `catch` \ece -> do (mlogFile, bss) <- case outputType of OTConsole _ -> pure (Nothing, []) OTLogFile logFile h -> if keepOutputOpen == KeepOpen then pure (Nothing, []) -- expected failure build continues further else do liftIO $ hClose h fmap (Just logFile,) $ withSourceFile (toFilePath logFile) $ \src -> runConduit $ src .| CT.decodeUtf8Lenient .| mungeBuildOutput stripTHLoading makeAbsolute pkgDir compilerVer .| CL.consume throwM $ PrettyException $ CabalExitedUnsuccessfully (eceExitCode ece) taskProvides exeName fullArgs mlogFile bss where runAndOutput :: ActualCompiler -> RIO env () runAndOutput compilerVer = withWorkingDir (toFilePath pkgDir) $ withProcessContext menv $ case outputType of OTLogFile _ h -> do let prefixWithTimestamps = if configPrefixTimestamps config then PrefixWithTimestamps else WithoutTimestamps void $ sinkProcessStderrStdout (toFilePath exeName) fullArgs (sinkWithTimestamps prefixWithTimestamps h) (sinkWithTimestamps prefixWithTimestamps h) OTConsole mprefix -> let prefix = fold mprefix in void $ sinkProcessStderrStdout (toFilePath exeName) fullArgs (outputSink KeepTHLoading LevelWarn compilerVer prefix) (outputSink stripTHLoading LevelInfo compilerVer prefix) outputSink :: HasCallStack => ExcludeTHLoading -> LogLevel -> ActualCompiler -> Utf8Builder -> ConduitM S.ByteString Void (RIO env) () outputSink excludeTH level compilerVer prefix = CT.decodeUtf8Lenient .| mungeBuildOutput excludeTH makeAbsolute pkgDir compilerVer .| CL.mapM_ (logGeneric "" level . (prefix <>) . display) -- If users want control, we should add a config option for this makeAbsolute :: ConvertPathsToAbsolute makeAbsolute = case stripTHLoading of ExcludeTHLoading -> ConvertPathsToAbsolute KeepTHLoading -> KeepPathsAsIs exeName <- case esetupexehs of Left setupExe -> pure setupExe Right setuphs -> do distDir <- distDirFromDir pkgDir let setupDir = distDir relDirSetup outputFile = setupDir relFileSetupLower customBuilt <- liftIO $ readIORef eeCustomBuilt if Set.member (packageName package) customBuilt then pure outputFile else do ensureDir setupDir compilerPath <- view $ compilerPathsL.to cpCompiler packageArgs <- getPackageArgs setupDir runExe compilerPath $ [ "--make" , "-odir", toFilePathNoTrailingSep setupDir , "-hidir", toFilePathNoTrailingSep setupDir , "-i", "-i." ] ++ packageArgs ++ [ toFilePath setuphs , toFilePath eeSetupShimHs , "-main-is" , "StackSetupShim.mainOverride" , "-o", toFilePath outputFile , "-threaded" ] ++ -- Apply GHC options -- https://github.com/commercialhaskell/stack/issues/4526 map T.unpack ( Map.findWithDefault [] AGOEverything (configGhcOptionsByCat config) ++ case configApplyGhcOptions config of AGOEverything -> boptsCLIGhcOptions eeBuildOptsCLI AGOTargets -> [] AGOLocals -> []) liftIO $ atomicModifyIORef' eeCustomBuilt $ \oldCustomBuilt -> (Set.insert (packageName package) oldCustomBuilt, ()) pure outputFile let cabalVerboseArg = let CabalVerbosity cv = boptsCabalVerbose eeBuildOpts in "--verbose=" <> showForCabal cv runExe exeName $ cabalVerboseArg:setupArgs -- Implements running a package's build, used to implement 'ATBuild' and -- 'ATBuildFinal' tasks. In particular this does the following: -- -- * Checks if the package exists in the precompiled cache, and if so, -- add it to the database instead of performing the build. -- -- * Runs the configure step if needed ('ensureConfig') -- -- * Runs the build step -- -- * Generates haddocks -- -- * Registers the library and copies the built executables into the -- local install directory. Note that this is literally invoking Cabal -- with @copy@, and not the copying done by @stack install@ - that is -- handled by 'copyExecutables'. singleBuild :: forall env. (HasEnvConfig env, HasRunner env) => ActionContext -> ExecuteEnv -> Task -> InstalledMap -> Bool -- ^ Is this a final build? -> RIO env () singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap isFinalBuild = do (allDepsMap, cache) <- getConfigCache ee task installedMap enableTests enableBenchmarks mprecompiled <- getPrecompiled cache minstalled <- case mprecompiled of Just precompiled -> copyPreCompiled precompiled Nothing -> do mcurator <- view $ buildConfigL.to bcCurator realConfigAndBuild cache mcurator allDepsMap case minstalled of Nothing -> pure () Just installed -> do writeFlagCache installed cache liftIO $ atomically $ modifyTVar eeGhcPkgIds $ Map.insert taskProvides installed where pname = pkgName taskProvides doHaddock mcurator package = taskBuildHaddock && not isFinalBuild && -- Works around haddock failing on bytestring-builder since it has no modules -- when bytestring is new enough. packageHasExposedModules package && -- Special help for the curator tool to avoid haddocks that are known to fail maybe True (Set.notMember pname . curatorSkipHaddock) mcurator expectHaddockFailure mcurator = maybe False (Set.member pname . curatorExpectHaddockFailure) mcurator fulfillHaddockExpectations mcurator action | expectHaddockFailure mcurator = do eres <- tryAny $ action KeepOpen case eres of Right () -> logWarn $ fromString (packageNameString pname) <> ": unexpected Haddock success" Left _ -> pure () fulfillHaddockExpectations _ action = do action CloseOnException buildingFinals = isFinalBuild || taskAllInOne enableTests = buildingFinals && any isCTest (taskComponents task) enableBenchmarks = buildingFinals && any isCBench (taskComponents task) annSuffix executableBuildStatuses = if result == "" then "" else " (" <> result <> ")" where result = T.intercalate " + " $ concat [ ["lib" | taskAllInOne && hasLib] , ["internal-lib" | taskAllInOne && hasSubLib] , ["exe" | taskAllInOne && hasExe] , ["test" | enableTests] , ["bench" | enableBenchmarks] ] (hasLib, hasSubLib, hasExe) = case taskType of TTLocalMutable lp -> let package = lpPackage lp hasLibrary = case packageLibraries package of NoLibraries -> False HasLibraries _ -> True hasSubLibrary = not . Set.null $ packageInternalLibraries package hasExecutables = not . Set.null $ exesToBuild executableBuildStatuses lp in (hasLibrary, hasSubLibrary, hasExecutables) -- This isn't true, but we don't want to have this info for -- upstream deps. _ -> (False, False, False) getPrecompiled cache = case taskType of TTRemotePackage Immutable _ loc -> do mpc <- readPrecompiledCache loc (configCacheOpts cache) (configCacheHaddock cache) (configCacheDeps cache) case mpc of Nothing -> pure Nothing -- Only pay attention to precompiled caches that refer to packages within -- the snapshot. Just pc | maybe False (bcoSnapInstallRoot eeBaseConfigOpts `isProperPrefixOf`) (pcLibrary pc) -> pure Nothing -- If old precompiled cache files are left around but snapshots are deleted, -- it is possible for the precompiled file to refer to the very library -- we're building, and if flags are changed it may try to copy the library -- to itself. This check prevents that from happening. Just pc -> do let allM _ [] = pure True allM f (x:xs) = do b <- f x if b then allM f xs else pure False b <- liftIO $ allM doesFileExist $ maybe id (:) (pcLibrary pc) $ pcExes pc pure $ if b then Just pc else Nothing _ -> pure Nothing copyPreCompiled (PrecompiledCache mlib sublibs exes) = do wc <- view $ actualCompilerVersionL.whichCompilerL announceTask ee task "using precompiled package" -- We need to copy .conf files for the main library and all sublibraries which exist in the cache, -- from their old snapshot to the new one. However, we must unregister any such library in the new -- snapshot, in case it was built with different flags. let subLibNames = map T.unpack . Set.toList $ case taskType of TTLocalMutable lp -> packageInternalLibraries $ lpPackage lp TTRemotePackage _ p _ -> packageInternalLibraries p PackageIdentifier name version = taskProvides mainLibName = packageNameString name mainLibVersion = versionString version pkgName = mainLibName ++ "-" ++ mainLibVersion -- z-package-z-internal for internal lib internal of package package toCabalInternalLibName n = concat ["z-", mainLibName, "-z-", n, "-", mainLibVersion] allToUnregister = map (const pkgName) (maybeToList mlib) ++ map toCabalInternalLibName subLibNames allToRegister = maybeToList mlib ++ sublibs unless (null allToRegister) $ do withMVar eeInstallLock $ \() -> do -- We want to ignore the global and user databases. -- Unfortunately, ghc-pkg doesn't take such arguments on the -- command line. Instead, we'll set GHC_PACKAGE_PATH. See: -- https://github.com/commercialhaskell/stack/issues/1146 let modifyEnv = Map.insert (ghcPkgPathEnvVar wc) (T.pack $ toFilePathNoTrailingSep $ bcoSnapDB eeBaseConfigOpts) withModifyEnvVars modifyEnv $ do GhcPkgExe ghcPkgExe <- getGhcPkgExe -- first unregister everything that needs to be unregistered forM_ allToUnregister $ \packageName -> catchAny (readProcessNull (toFilePath ghcPkgExe) [ "unregister", "--force", packageName]) (const (pure ())) -- now, register the cached conf files forM_ allToRegister $ \libpath -> proc (toFilePath ghcPkgExe) [ "register", "--force", toFilePath libpath] readProcess_ liftIO $ forM_ exes $ \exe -> do ensureDir bindir let dst = bindir filename exe createLink (toFilePath exe) (toFilePath dst) `catchIO` \_ -> copyFile exe dst case (mlib, exes) of (Nothing, _:_) -> markExeInstalled (taskLocation task) taskProvides _ -> pure () -- Find the package in the database let pkgDbs = [bcoSnapDB eeBaseConfigOpts] case mlib of Nothing -> pure $ Just $ Executable taskProvides Just _ -> do mpkgid <- loadInstalledPkg pkgDbs eeSnapshotDumpPkgs pname pure $ Just $ case mpkgid of Nothing -> assert False $ Executable taskProvides Just pkgid -> Library taskProvides pkgid Nothing where bindir = bcoSnapInstallRoot eeBaseConfigOpts bindirSuffix realConfigAndBuild cache mcurator allDepsMap = withSingleContext ac ee task allDepsMap Nothing $ \package cabalfp pkgDir cabal0 announce _outputType -> do let cabal = cabal0 CloseOnException executableBuildStatuses <- getExecutableBuildStatuses package pkgDir when (not (cabalIsSatisfied executableBuildStatuses) && taskIsTarget task) (logInfo ("Building all executables for `" <> fromString (packageNameString (packageName package)) <> "' once. After a successful build of all of them, only specified executables will be rebuilt.")) _neededConfig <- ensureConfig cache pkgDir ee (announce ("configure" <> display (annSuffix executableBuildStatuses))) cabal cabalfp task let installedMapHasThisPkg :: Bool installedMapHasThisPkg = case Map.lookup (packageName package) installedMap of Just (_, Library ident _ _) -> ident == taskProvides Just (_, Executable _) -> True _ -> False case ( boptsCLIOnlyConfigure eeBuildOptsCLI , boptsCLIInitialBuildSteps eeBuildOptsCLI && taskIsTarget task) of -- A full build is done if there are downstream actions, -- because their configure step will require that this -- package is built. See -- https://github.com/commercialhaskell/stack/issues/2787 (True, _) | null acDownstream -> pure Nothing (_, True) | null acDownstream || installedMapHasThisPkg -> do initialBuildSteps executableBuildStatuses cabal announce pure Nothing _ -> fulfillCuratorBuildExpectations pname mcurator enableTests enableBenchmarks Nothing $ Just <$> realBuild cache package pkgDir cabal0 announce executableBuildStatuses initialBuildSteps executableBuildStatuses cabal announce = do announce ("initial-build-steps" <> display (annSuffix executableBuildStatuses)) cabal KeepTHLoading ["repl", "stack-initial-build-steps"] realBuild :: ConfigCache -> Package -> Path Abs Dir -> (KeepOutputOpen -> ExcludeTHLoading -> [String] -> RIO env ()) -> (Utf8Builder -> RIO env ()) -> Map Text ExecutableBuildStatus -> RIO env Installed realBuild cache package pkgDir cabal0 announce executableBuildStatuses = do let cabal = cabal0 CloseOnException wc <- view $ actualCompilerVersionL.whichCompilerL markExeNotInstalled (taskLocation task) taskProvides case taskType of TTLocalMutable lp -> do when enableTests $ setTestStatus pkgDir TSUnknown caches <- runMemoizedWith $ lpNewBuildCaches lp mapM_ (uncurry (writeBuildCache pkgDir)) (Map.toList caches) TTRemotePackage{} -> pure () -- FIXME: only output these if they're in the build plan. let postBuildCheck _succeeded = do mlocalWarnings <- case taskType of TTLocalMutable lp -> do warnings <- checkForUnlistedFiles taskType pkgDir -- TODO: Perhaps only emit these warnings for non extra-dep? pure (Just (lpCabalFile lp, warnings)) _ -> pure Nothing -- NOTE: once -- https://github.com/commercialhaskell/stack/issues/2649 -- is resolved, we will want to partition the warnings -- based on variety, and output in different lists. let showModuleWarning (UnlistedModulesWarning comp modules) = "- In" <+> fromString (T.unpack (renderComponent comp)) <> ":" <> line <> indent 4 ( mconcat $ L.intersperse line $ map (style Good . fromString . C.display) modules ) forM_ mlocalWarnings $ \(cabalfp, warnings) -> do unless (null warnings) $ prettyWarn $ flow "The following modules should be added to \ \exposed-modules or other-modules in" <+> pretty cabalfp <> ":" <> line <> indent 4 ( mconcat $ L.intersperse line $ map showModuleWarning warnings ) <> blankLine <> flow "Missing modules in the Cabal file are likely \ \to cause undefined reference errors from the \ \linker, along with other problems." () <- announce ("build" <> display (annSuffix executableBuildStatuses)) config <- view configL extraOpts <- extraBuildOptions wc eeBuildOpts let stripTHLoading | configHideTHLoading config = ExcludeTHLoading | otherwise = KeepTHLoading cabal stripTHLoading (("build" :) $ (++ extraOpts) $ case (taskType, taskAllInOne, isFinalBuild) of (_, True, True) -> throwM AllInOneBuildBug (TTLocalMutable lp, False, False) -> primaryComponentOptions executableBuildStatuses lp (TTLocalMutable lp, False, True) -> finalComponentOptions lp (TTLocalMutable lp, True, False) -> primaryComponentOptions executableBuildStatuses lp ++ finalComponentOptions lp (TTRemotePackage{}, _, _) -> []) `catch` \ex -> case ex of CabalExitedUnsuccessfully{} -> postBuildCheck False >> throwM (PrettyException ex) _ -> throwM ex postBuildCheck True mcurator <- view $ buildConfigL.to bcCurator when (doHaddock mcurator package) $ do announce "haddock" sourceFlag <- if not (boptsHaddockHyperlinkSource eeBuildOpts) then pure [] else do -- See #2429 for why the temp dir is used ec <- withWorkingDir (toFilePath eeTempDir) $ proc "haddock" ["--hyperlinked-source"] $ \pc -> withProcessWait (setStdout createSource $ setStderr createSource pc) $ \p -> runConcurrently $ Concurrently (runConduit $ getStdout p .| CL.sinkNull) *> Concurrently (runConduit $ getStderr p .| CL.sinkNull) *> Concurrently (waitExitCode p) case ec of -- Fancy crosslinked source ExitSuccess -> pure ["--haddock-option=--hyperlinked-source"] -- Older hscolour colouring ExitFailure _ -> do hscolourExists <- doesExecutableExist "HsColour" unless hscolourExists $ logWarn ("Warning: haddock not generating hyperlinked sources because 'HsColour' not\n" <> "found on PATH (use 'stack install hscolour' to install).") pure ["--hyperlink-source" | hscolourExists] -- For GHC 8.4 and later, provide the --quickjump option. actualCompiler <- view actualCompilerVersionL let quickjump = case actualCompiler of ACGhc ghcVer | ghcVer >= mkVersion [8, 4] -> ["--haddock-option=--quickjump"] _ -> [] fulfillHaddockExpectations mcurator $ \keep -> cabal0 keep KeepTHLoading $ concat [ ["haddock", "--html", "--hoogle", "--html-location=../$pkg-$version/"] , sourceFlag , ["--internal" | boptsHaddockInternal eeBuildOpts] , [ "--haddock-option=" <> opt | opt <- hoAdditionalArgs (boptsHaddockOpts eeBuildOpts) ] , quickjump ] let hasLibrary = case packageLibraries package of NoLibraries -> False HasLibraries _ -> True packageHasComponentSet f = not $ Set.null $ f package hasInternalLibrary = packageHasComponentSet packageInternalLibraries hasExecutables = packageHasComponentSet packageExes shouldCopy = not isFinalBuild && (hasLibrary || hasInternalLibrary || hasExecutables) when shouldCopy $ withMVar eeInstallLock $ \() -> do announce "copy/register" eres <- try $ cabal KeepTHLoading ["copy"] case eres of Left err@CabalExitedUnsuccessfully{} -> throwM $ CabalCopyFailed (packageBuildType package == C.Simple) (displayException err) _ -> pure () when hasLibrary $ cabal KeepTHLoading ["register"] -- copy ddump-* files case T.unpack <$> boptsDdumpDir eeBuildOpts of Just ddumpPath | buildingFinals && not (null ddumpPath) -> do distDir <- distRelativeDir ddumpDir <- parseRelDir ddumpPath logDebug $ fromString ("ddump-dir: " <> toFilePath ddumpDir) logDebug $ fromString ("dist-dir: " <> toFilePath distDir) runConduitRes $ CF.sourceDirectoryDeep False (toFilePath distDir) .| CL.filter (L.isInfixOf ".dump-") .| CL.mapM_ (\src -> liftIO $ do parentDir <- parent <$> parseRelDir src destBaseDir <- (ddumpDir ) <$> stripProperPrefix distDir parentDir -- exclude .stack-work dir unless (".stack-work" `L.isInfixOf` toFilePath destBaseDir) $ do ensureDir destBaseDir src' <- parseRelFile src copyFile src' (destBaseDir filename src')) _ -> pure () let (installedPkgDb, installedDumpPkgsTVar) = case taskLocation task of Snap -> ( bcoSnapDB eeBaseConfigOpts , eeSnapshotDumpPkgs ) Local -> ( bcoLocalDB eeBaseConfigOpts , eeLocalDumpPkgs ) let ident = PackageIdentifier (packageName package) (packageVersion package) -- only pure the sublibs to cache them if we also cache the main lib (that is, if it exists) (mpkgid, sublibsPkgIds) <- case packageLibraries package of HasLibraries _ -> do sublibsPkgIds <- fmap catMaybes $ forM (Set.toList $ packageInternalLibraries package) $ \sublib -> do -- z-haddock-library-z-attoparsec for internal lib attoparsec of haddock-library let sublibName = T.concat ["z-", T.pack $ packageNameString $ packageName package, "-z-", sublib] case parsePackageName $ T.unpack sublibName of Nothing -> pure Nothing -- invalid lib, ignored Just subLibName -> loadInstalledPkg [installedPkgDb] installedDumpPkgsTVar subLibName mpkgid <- loadInstalledPkg [installedPkgDb] installedDumpPkgsTVar (packageName package) case mpkgid of Nothing -> throwM $ Couldn'tFindPkgId $ packageName package Just pkgid -> pure (Library ident pkgid Nothing, sublibsPkgIds) NoLibraries -> do markExeInstalled (taskLocation task) taskProvides -- TODO unify somehow with writeFlagCache? pure (Executable ident, []) -- don't pure sublibs in this case case taskType of TTRemotePackage Immutable _ loc -> writePrecompiledCache eeBaseConfigOpts loc (configCacheOpts cache) (configCacheHaddock cache) (configCacheDeps cache) mpkgid sublibsPkgIds (packageExes package) _ -> pure () case taskType of -- For packages from a package index, pkgDir is in the tmp -- directory. We eagerly delete it if no other tasks -- require it, to reduce space usage in tmp (#3018). TTRemotePackage{} -> do let remaining = filter (\(ActionId x _) -> x == taskProvides) (Set.toList acRemaining) when (null remaining) $ removeDirRecur pkgDir TTLocalMutable{} -> pure () pure mpkgid loadInstalledPkg pkgDbs tvar name = do pkgexe <- getGhcPkgExe dps <- ghcPkgDescribe pkgexe name pkgDbs $ conduitDumpPackage .| CL.consume case dps of [] -> pure Nothing [dp] -> do liftIO $ atomically $ modifyTVar' tvar (Map.insert (dpGhcPkgId dp) dp) pure $ Just (dpGhcPkgId dp) _ -> throwM $ MulipleResultsBug name dps -- | Get the build status of all the package executables. Do so by -- testing whether their expected output file exists, e.g. -- -- .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/alpha/alpha -- .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/alpha/alpha.exe -- .stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/alpha/alpha.jsexe/ (NOTE: a dir) getExecutableBuildStatuses :: HasEnvConfig env => Package -> Path Abs Dir -> RIO env (Map Text ExecutableBuildStatus) getExecutableBuildStatuses package pkgDir = do distDir <- distDirFromDir pkgDir platform <- view platformL fmap M.fromList (mapM (checkExeStatus platform distDir) (Set.toList (packageExes package))) -- | Check whether the given executable is defined in the given dist directory. checkExeStatus :: HasLogFunc env => Platform -> Path b Dir -> Text -> RIO env (Text, ExecutableBuildStatus) checkExeStatus platform distDir name = do exename <- parseRelDir (T.unpack name) exists <- checkPath (distDir relDirBuild exename) pure ( name , if exists then ExecutableBuilt else ExecutableNotBuilt) where checkPath base = case platform of Platform _ Windows -> do fileandext <- parseRelFile (file ++ ".exe") doesFileExist (base fileandext) _ -> do fileandext <- parseRelFile file doesFileExist (base fileandext) where file = T.unpack name -- | Check if any unlisted files have been found, and add them to the build cache. checkForUnlistedFiles :: HasEnvConfig env => TaskType -> Path Abs Dir -> RIO env [PackageWarning] checkForUnlistedFiles (TTLocalMutable lp) pkgDir = do caches <- runMemoizedWith $ lpNewBuildCaches lp (addBuildCache,warnings) <- addUnlistedToBuildCache (lpPackage lp) (lpCabalFile lp) (lpComponents lp) caches forM_ (M.toList addBuildCache) $ \(component, newToCache) -> do let cache = Map.findWithDefault Map.empty component caches writeBuildCache pkgDir component $ Map.unions (cache : newToCache) pure warnings checkForUnlistedFiles TTRemotePackage{} _ = pure [] -- | Implements running a package's tests. Also handles producing -- coverage reports if coverage is enabled. singleTest :: HasEnvConfig env => TestOpts -> [Text] -> ActionContext -> ExecuteEnv -> Task -> InstalledMap -> RIO env () singleTest topts testsToRun ac ee task installedMap = do -- FIXME: Since this doesn't use cabal, we should be able to avoid using a -- full blown 'withSingleContext'. (allDepsMap, _cache) <- getConfigCache ee task installedMap True False mcurator <- view $ buildConfigL.to bcCurator let pname = pkgName $ taskProvides task expectFailure = expectTestFailure pname mcurator withSingleContext ac ee task allDepsMap (Just "test") $ \package _cabalfp pkgDir _cabal announce outputType -> do config <- view configL let needHpc = toCoverage topts toRun <- if toDisableRun topts then do announce "Test running disabled by --no-run-tests flag." pure False else if toRerunTests topts then pure True else do status <- getTestStatus pkgDir case status of TSSuccess -> do unless (null testsToRun) $ announce "skipping already passed test" pure False TSFailure | expectFailure -> do announce "skipping already failed test that's expected to fail" pure False | otherwise -> do announce "rerunning previously failed test" pure True TSUnknown -> pure True when toRun $ do buildDir <- distDirFromDir pkgDir hpcDir <- hpcDirFromDir pkgDir when needHpc (ensureDir hpcDir) let suitesToRun = [ testSuitePair | testSuitePair <- Map.toList $ packageTests package , let testName = fst testSuitePair , testName `elem` testsToRun ] errs <- liftM Map.unions $ forM suitesToRun $ \(testName, suiteInterface) -> do let stestName = T.unpack testName (testName', isTestTypeLib) <- case suiteInterface of C.TestSuiteLibV09{} -> pure (stestName ++ "Stub", True) C.TestSuiteExeV10{} -> pure (stestName, False) interface -> throwM (TestSuiteTypeUnsupported interface) let exeName = testName' ++ case configPlatform config of Platform _ Windows -> ".exe" _ -> "" tixPath <- liftM (pkgDir ) $ parseRelFile $ exeName ++ ".tix" exePath <- liftM (buildDir ) $ parseRelFile $ "build/" ++ testName' ++ "/" ++ exeName exists <- doesFileExist exePath -- in Stack.Package.packageFromPackageDescription we filter out -- package itself of any dependencies so any tests requiring loading -- of their own package library will fail -- so to prevent this we return it back here but unfortunately unconditionally installed <- case Map.lookup pname installedMap of Just (_, installed) -> pure $ Just installed Nothing -> do idMap <- liftIO $ readTVarIO (eeGhcPkgIds ee) pure $ Map.lookup (taskProvides task) idMap let pkgGhcIdList = case installed of Just (Library _ ghcPkgId _) -> [ghcPkgId] _ -> [] -- doctest relies on template-haskell in QuickCheck-based tests thGhcId <- case L.find ((== "template-haskell") . pkgName . dpPackageIdent. snd) (Map.toList $ eeGlobalDumpPkgs ee) of Just (ghcId, _) -> pure ghcId Nothing -> throwIO TemplateHaskellNotFoundBug -- env variable GHC_ENVIRONMENT is set for doctest so module names for -- packages with proper dependencies should no longer get ambiguous -- see e.g. https://github.com/doctest/issues/119 -- also we set HASKELL_DIST_DIR to a package dist directory so -- doctest will be able to load modules autogenerated by Cabal let setEnv f pc = modifyEnvVars pc $ \envVars -> Map.insert "HASKELL_DIST_DIR" (T.pack $ toFilePath buildDir) $ Map.insert "GHC_ENVIRONMENT" (T.pack f) envVars fp' = eeTempDir ee testGhcEnvRelFile -- Add a random suffix to avoid conflicts between parallel jobs -- See https://github.com/commercialhaskell/stack/issues/5024 randomInt <- liftIO (randomIO :: IO Int) let randomSuffix = "." <> show (abs randomInt) fp <- toFilePath <$> addExtension randomSuffix fp' let snapDBPath = toFilePathNoTrailingSep (bcoSnapDB $ eeBaseConfigOpts ee) localDBPath = toFilePathNoTrailingSep (bcoLocalDB $ eeBaseConfigOpts ee) ghcEnv = "clear-package-db\n" <> "global-package-db\n" <> "package-db " <> fromString snapDBPath <> "\n" <> "package-db " <> fromString localDBPath <> "\n" <> foldMap (\ghcId -> "package-id " <> display (unGhcPkgId ghcId) <> "\n") (pkgGhcIdList ++ thGhcId:M.elems allDepsMap) writeFileUtf8Builder fp ghcEnv menv <- liftIO $ setEnv fp =<< configProcessContextSettings config EnvSettings { esIncludeLocals = taskLocation task == Local , esIncludeGhcPackagePath = True , esStackExe = True , esLocaleUtf8 = False , esKeepGhcRts = False } let emptyResult = Map.singleton testName Nothing withProcessContext menv $ if exists then do -- We clear out the .tix files before doing a run. when needHpc $ do tixexists <- doesFileExist tixPath when tixexists $ logWarn ("Removing HPC file " <> fromString (toFilePath tixPath)) liftIO $ ignoringAbsence (removeFile tixPath) let args = toAdditionalArgs topts argsDisplay = case args of [] -> "" _ -> ", args: " <> T.intercalate " " (map showProcessArgDebug args) announce $ "test (suite: " <> display testName <> display argsDisplay <> ")" -- Clear "Progress: ..." message before -- redirecting output. case outputType of OTConsole _ -> do logStickyDone "" liftIO $ hFlush stdout liftIO $ hFlush stderr OTLogFile _ _ -> pure () let output = case outputType of OTConsole Nothing -> Nothing <$ inherit OTConsole (Just prefix) -> fmap (\src -> Just $ runConduit $ src .| CT.decodeUtf8Lenient .| CT.lines .| CL.map stripCR .| CL.mapM_ (\t -> logInfo $ prefix <> display t)) createSource OTLogFile _ h -> Nothing <$ useHandleOpen h optionalTimeout action | Just maxSecs <- toMaximumTimeSeconds topts, maxSecs > 0 = do timeout (maxSecs * 1000000) action | otherwise = Just <$> action mec <- withWorkingDir (toFilePath pkgDir) $ optionalTimeout $ proc (toFilePath exePath) args $ \pc0 -> do changeStdin <- if isTestTypeLib then do logPath <- buildLogPath package (Just stestName) ensureDir (parent logPath) pure $ setStdin $ byteStringInput $ BL.fromStrict $ encodeUtf8 $ fromString $ show (logPath, mkUnqualComponentName (T.unpack testName)) else do isTerminal <- view $ globalOptsL.to globalTerminal if toAllowStdin topts && isTerminal then pure id else pure $ setStdin $ byteStringInput mempty let pc = changeStdin $ setStdout output $ setStderr output pc0 withProcessWait pc $ \p -> do case (getStdout p, getStderr p) of (Nothing, Nothing) -> pure () (Just x, Just y) -> concurrently_ x y (x, y) -> assert False $ concurrently_ (fromMaybe (pure ()) x) (fromMaybe (pure ()) y) waitExitCode p -- Add a trailing newline, incase the test -- output didn't finish with a newline. case outputType of OTConsole Nothing -> logInfo "" _ -> pure () -- Move the .tix file out of the package -- directory into the hpc work dir, for -- tidiness. when needHpc $ updateTixFile (packageName package) tixPath testName' let announceResult result = announce $ "Test suite " <> display testName <> " " <> result case mec of Just ExitSuccess -> do announceResult "passed" pure Map.empty Nothing -> do announceResult "timed out" if expectFailure then pure Map.empty else pure $ Map.singleton testName Nothing Just ec -> do announceResult "failed" if expectFailure then pure Map.empty else pure $ Map.singleton testName (Just ec) else do unless expectFailure $ logError $ displayShow $ TestSuiteExeMissing (packageBuildType package == C.Simple) exeName (packageNameString (packageName package)) (T.unpack testName) pure emptyResult when needHpc $ do let testsToRun' = map f testsToRun f tName = case Map.lookup tName (packageTests package) of Just C.TestSuiteLibV09{} -> tName <> "Stub" _ -> tName generateHpcReport pkgDir package testsToRun' bs <- liftIO $ case outputType of OTConsole _ -> pure "" OTLogFile logFile h -> do hClose h S.readFile $ toFilePath logFile let succeeded = Map.null errs unless (succeeded || expectFailure) $ throwM $ TestSuiteFailure (taskProvides task) errs (case outputType of OTLogFile fp _ -> Just fp OTConsole _ -> Nothing) bs setTestStatus pkgDir $ if succeeded then TSSuccess else TSFailure -- | Implements running a package's benchmarks. singleBench :: HasEnvConfig env => BenchmarkOpts -> [Text] -> ActionContext -> ExecuteEnv -> Task -> InstalledMap -> RIO env () singleBench beopts benchesToRun ac ee task installedMap = do (allDepsMap, _cache) <- getConfigCache ee task installedMap False True withSingleContext ac ee task allDepsMap (Just "bench") $ \_package _cabalfp _pkgDir cabal announce _outputType -> do let args = map T.unpack benchesToRun <> maybe [] ((:[]) . ("--benchmark-options=" <>)) (beoAdditionalArgs beopts) toRun <- if beoDisableRun beopts then do announce "Benchmark running disabled by --no-run-benchmarks flag." pure False else do pure True when toRun $ do announce "benchmarks" cabal CloseOnException KeepTHLoading ("bench" : args) data ExcludeTHLoading = ExcludeTHLoading | KeepTHLoading data ConvertPathsToAbsolute = ConvertPathsToAbsolute | KeepPathsAsIs -- | special marker for expected failures in curator builds, using those -- we need to keep log handle open as build continues further even after a failure data KeepOutputOpen = KeepOpen | CloseOnException deriving Eq -- | Strip Template Haskell "Loading package" lines and making paths absolute. mungeBuildOutput :: forall m. MonadIO m => ExcludeTHLoading -- ^ exclude TH loading? -> ConvertPathsToAbsolute -- ^ convert paths to absolute? -> Path Abs Dir -- ^ package's root directory -> ActualCompiler -- ^ compiler we're building with -> ConduitM Text Text m () mungeBuildOutput excludeTHLoading makeAbsolute pkgDir compilerVer = void $ CT.lines .| CL.map stripCR .| CL.filter (not . isTHLoading) .| filterLinkerWarnings .| toAbsolute where -- | Is this line a Template Haskell "Loading package" line -- ByteString isTHLoading :: Text -> Bool isTHLoading = case excludeTHLoading of KeepTHLoading -> const False ExcludeTHLoading -> \bs -> "Loading package " `T.isPrefixOf` bs && ("done." `T.isSuffixOf` bs || "done.\r" `T.isSuffixOf` bs) filterLinkerWarnings :: ConduitM Text Text m () filterLinkerWarnings -- Check for ghc 7.8 since it's the only one prone to producing -- linker warnings on Windows x64 | getGhcVersion compilerVer >= mkVersion [7, 8] = doNothing | otherwise = CL.filter (not . isLinkerWarning) isLinkerWarning :: Text -> Bool isLinkerWarning str = ("ghc.exe: warning:" `T.isPrefixOf` str || "ghc.EXE: warning:" `T.isPrefixOf` str) && "is linked instead of __imp_" `T.isInfixOf` str -- | Convert GHC error lines with file paths to have absolute file paths toAbsolute :: ConduitM Text Text m () toAbsolute = case makeAbsolute of KeepPathsAsIs -> doNothing ConvertPathsToAbsolute -> CL.mapM toAbsolutePath toAbsolutePath :: Text -> m Text toAbsolutePath bs = do let (x, y) = T.break (== ':') bs mabs <- if isValidSuffix y then liftIO $ liftM (fmap ((T.takeWhile isSpace x <>) . T.pack . toFilePath)) $ forgivingAbsence (resolveFile pkgDir (T.unpack $ T.dropWhile isSpace x)) `catch` \(_ :: PathException) -> pure Nothing else pure Nothing case mabs of Nothing -> pure bs Just fp -> pure $ fp `T.append` y doNothing :: ConduitM Text Text m () doNothing = awaitForever yield -- | Match the error location format at the end of lines isValidSuffix = isRight . parseOnly lineCol lineCol = char ':' >> choice [ num >> char ':' >> num >> optional (char '-' >> num) >> pure () , char '(' >> num >> char ',' >> num >> P.string ")-(" >> num >> char ',' >> num >> char ')' >> pure () ] >> char ':' >> pure () where num = some digit -- | Whether to prefix log lines with timestamps. data PrefixWithTimestamps = PrefixWithTimestamps | WithoutTimestamps -- | Write stream of lines to handle, but adding timestamps. sinkWithTimestamps :: MonadIO m => PrefixWithTimestamps -> Handle -> ConduitT ByteString Void m () sinkWithTimestamps prefixWithTimestamps h = case prefixWithTimestamps of PrefixWithTimestamps -> CB.lines .| CL.mapM addTimestamp .| CL.map (<> "\n") .| sinkHandle h WithoutTimestamps -> sinkHandle h where addTimestamp theLine = do now <- liftIO getZonedTime pure (formatZonedTimeForLog now <> " " <> theLine) -- | Format a time in ISO8601 format. We choose ZonedTime over UTCTime -- because a user expects to see logs in their local time, and would -- be confused to see UTC time. Stack's debug logs also use the local -- time zone. formatZonedTimeForLog :: ZonedTime -> ByteString formatZonedTimeForLog = S8.pack . formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%6Q" -- | Find the Setup.hs or Setup.lhs in the given directory. If none exists, -- throw an exception. getSetupHs :: Path Abs Dir -- ^ project directory -> IO (Path Abs File) getSetupHs dir = do exists1 <- doesFileExist fp1 if exists1 then pure fp1 else do exists2 <- doesFileExist fp2 if exists2 then pure fp2 else throwM $ NoSetupHsFound dir where fp1 = dir relFileSetupHs fp2 = dir relFileSetupLhs -- Do not pass `-hpcdir` as GHC option if the coverage is not enabled. -- This helps running stack-compiled programs with dynamic interpreters like `hint`. -- Cfr: https://github.com/commercialhaskell/stack/issues/997 extraBuildOptions :: (HasEnvConfig env, HasRunner env) => WhichCompiler -> BuildOpts -> RIO env [String] extraBuildOptions wc bopts = do colorOpt <- appropriateGhcColorFlag let optsFlag = compilerOptionsCabalFlag wc baseOpts = maybe "" (" " ++) colorOpt if toCoverage (boptsTestOpts bopts) then do hpcIndexDir <- toFilePathNoTrailingSep <$> hpcRelativeDir pure [optsFlag, "-hpcdir " ++ hpcIndexDir ++ baseOpts] else pure [optsFlag, baseOpts] -- Library, internal and foreign libraries and executable build components. primaryComponentOptions :: Map Text ExecutableBuildStatus -> LocalPackage -> [String] primaryComponentOptions executableBuildStatuses lp = -- TODO: get this information from target parsing instead, -- which will allow users to turn off library building if -- desired (case packageLibraries package of NoLibraries -> [] HasLibraries names -> map T.unpack $ T.append "lib:" (T.pack (packageNameString (packageName package))) : map (T.append "flib:") (Set.toList names)) ++ map (T.unpack . T.append "lib:") (Set.toList $ packageInternalLibraries package) ++ map (T.unpack . T.append "exe:") (Set.toList $ exesToBuild executableBuildStatuses lp) where package = lpPackage lp -- | History of this function: -- -- * Normally it would do either all executables or if the user -- specified requested components, just build them. Afterwards, due -- to this Cabal bug , -- we had to make Stack build all executables every time. -- -- * In this -- was flagged up as very undesirable behavior on a large project, -- hence the behavior below that we build all executables once -- (modulo success), and thereafter pay attention to user-wanted -- components. -- exesToBuild :: Map Text ExecutableBuildStatus -> LocalPackage -> Set Text exesToBuild executableBuildStatuses lp = if cabalIsSatisfied executableBuildStatuses && lpWanted lp then exeComponents (lpComponents lp) else packageExes (lpPackage lp) -- | Do the current executables satisfy Cabal's bugged out requirements? cabalIsSatisfied :: Map k ExecutableBuildStatus -> Bool cabalIsSatisfied = all (== ExecutableBuilt) . M.elems -- Test-suite and benchmark build components. finalComponentOptions :: LocalPackage -> [String] finalComponentOptions lp = map (T.unpack . renderComponent) $ Set.toList $ Set.filter (\c -> isCTest c || isCBench c) (lpComponents lp) taskComponents :: Task -> Set NamedComponent taskComponents task = case taskType task of TTLocalMutable lp -> lpComponents lp -- FIXME probably just want lpWanted TTRemotePackage{} -> Set.empty expectTestFailure :: PackageName -> Maybe Curator -> Bool expectTestFailure pname mcurator = maybe False (Set.member pname . curatorExpectTestFailure) mcurator expectBenchmarkFailure :: PackageName -> Maybe Curator -> Bool expectBenchmarkFailure pname mcurator = maybe False (Set.member pname . curatorExpectBenchmarkFailure) mcurator fulfillCuratorBuildExpectations :: (HasLogFunc env, HasCallStack) => PackageName -> Maybe Curator -> Bool -> Bool -> b -> RIO env b -> RIO env b fulfillCuratorBuildExpectations pname mcurator enableTests _ defValue action | enableTests && expectTestFailure pname mcurator = do eres <- tryAny action case eres of Right res -> do logWarn $ fromString (packageNameString pname) <> ": unexpected test build success" pure res Left _ -> pure defValue fulfillCuratorBuildExpectations pname mcurator _ enableBench defValue action | enableBench && expectBenchmarkFailure pname mcurator = do eres <- tryAny action case eres of Right res -> do logWarn $ fromString (packageNameString pname) <> ": unexpected benchmark build success" pure res Left _ -> pure defValue fulfillCuratorBuildExpectations _ _ _ _ _ action = do action stack-2.9.3.1/src/Stack/Build/Haddock.hs0000644000000000000000000003127114445022466015756 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Generate haddocks module Stack.Build.Haddock ( generateLocalHaddockIndex , generateDepsHaddockIndex , generateSnapHaddockIndex , openHaddocksInBrowser , shouldHaddockPackage , shouldHaddockDeps ) where import qualified Data.Foldable as F import qualified Data.HashSet as HS import qualified Data.Map.Strict as Map import qualified Data.Set as Set import Data.Time ( UTCTime ) import Path import Path.Extra import Path.IO import RIO.List ( intercalate ) import RIO.Process import Stack.Constants import Stack.PackageDump import Stack.Prelude import Stack.Types.Build import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.Package import qualified System.FilePath as FP import Web.Browser ( openBrowser ) openHaddocksInBrowser :: HasTerm env => BaseConfigOpts -> Map PackageName (PackageIdentifier, InstallLocation) -- ^ Available packages and their locations for the current project -> Set PackageName -- ^ Build targets as determined by 'Stack.Build.Source.loadSourceMap' -> RIO env () openHaddocksInBrowser bco pkgLocations buildTargets = do let cliTargets = (boptsCLITargets . bcoBuildOptsCLI) bco getDocIndex = do let localDocs = haddockIndexFile (localDepsDocDir bco) localExists <- doesFileExist localDocs if localExists then pure localDocs else do let snapDocs = haddockIndexFile (snapDocDir bco) snapExists <- doesFileExist snapDocs if snapExists then pure snapDocs else throwIO HaddockIndexNotFound docFile <- case (cliTargets, map (`Map.lookup` pkgLocations) (Set.toList buildTargets)) of ([_], [Just (pkgId, iloc)]) -> do pkgRelDir <- (parseRelDir . packageIdentifierString) pkgId let docLocation = case iloc of Snap -> snapDocDir bco Local -> localDocDir bco let docFile = haddockIndexFile (docLocation pkgRelDir) exists <- doesFileExist docFile if exists then pure docFile else do logWarn $ "Expected to find documentation at " <> fromString (toFilePath docFile) <> ", but that file is missing. Opening doc index instead." getDocIndex _ -> getDocIndex prettyInfo $ "Opening" <+> pretty docFile <+> "in the browser." _ <- liftIO $ openBrowser (toFilePath docFile) pure () -- | Determine whether we should haddock for a package. shouldHaddockPackage :: BuildOpts -> Set PackageName -- ^ Packages that we want to generate haddocks for -- in any case (whether or not we are going to generate -- haddocks for dependencies) -> PackageName -> Bool shouldHaddockPackage bopts wanted name = if Set.member name wanted then boptsHaddock bopts else shouldHaddockDeps bopts -- | Determine whether to build haddocks for dependencies. shouldHaddockDeps :: BuildOpts -> Bool shouldHaddockDeps bopts = fromMaybe (boptsHaddock bopts) (boptsHaddockDeps bopts) -- | Generate Haddock index and contents for local packages. generateLocalHaddockIndex :: (HasProcessContext env, HasLogFunc env, HasCompiler env) => BaseConfigOpts -> Map GhcPkgId DumpPackage -- ^ Local package dump -> [LocalPackage] -> RIO env () generateLocalHaddockIndex bco localDumpPkgs locals = do let dumpPackages = mapMaybe (\LocalPackage{lpPackage = Package{packageName, packageVersion}} -> F.find (\dp -> dpPackageIdent dp == PackageIdentifier packageName packageVersion) localDumpPkgs) locals generateHaddockIndex "local packages" bco dumpPackages "." (localDocDir bco) -- | Generate Haddock index and contents for local packages and their dependencies. generateDepsHaddockIndex :: (HasProcessContext env, HasLogFunc env, HasCompiler env) => BaseConfigOpts -> Map GhcPkgId DumpPackage -- ^ Global dump information -> Map GhcPkgId DumpPackage -- ^ Snapshot dump information -> Map GhcPkgId DumpPackage -- ^ Local dump information -> [LocalPackage] -> RIO env () generateDepsHaddockIndex bco globalDumpPkgs snapshotDumpPkgs localDumpPkgs locals = do let deps = (mapMaybe (`lookupDumpPackage` allDumpPkgs) . nubOrd . findTransitiveDepends . mapMaybe getGhcPkgId) locals depDocDir = localDepsDocDir bco generateHaddockIndex "local packages and dependencies" bco deps ".." depDocDir where getGhcPkgId :: LocalPackage -> Maybe GhcPkgId getGhcPkgId LocalPackage{lpPackage = Package{packageName, packageVersion}} = let pkgId = PackageIdentifier packageName packageVersion mdpPkg = F.find (\dp -> dpPackageIdent dp == pkgId) localDumpPkgs in fmap dpGhcPkgId mdpPkg findTransitiveDepends :: [GhcPkgId] -> [GhcPkgId] findTransitiveDepends = (`go` HS.empty) . HS.fromList where go todo checked = case HS.toList todo of [] -> HS.toList checked (ghcPkgId:_) -> let deps = case lookupDumpPackage ghcPkgId allDumpPkgs of Nothing -> HS.empty Just pkgDP -> HS.fromList (dpDepends pkgDP) deps' = deps `HS.difference` checked todo' = HS.delete ghcPkgId (deps' `HS.union` todo) checked' = HS.insert ghcPkgId checked in go todo' checked' allDumpPkgs = [localDumpPkgs, snapshotDumpPkgs, globalDumpPkgs] -- | Generate Haddock index and contents for all snapshot packages. generateSnapHaddockIndex :: (HasProcessContext env, HasLogFunc env, HasCompiler env) => BaseConfigOpts -> Map GhcPkgId DumpPackage -- ^ Global package dump -> Map GhcPkgId DumpPackage -- ^ Snapshot package dump -> RIO env () generateSnapHaddockIndex bco globalDumpPkgs snapshotDumpPkgs = generateHaddockIndex "snapshot packages" bco (Map.elems snapshotDumpPkgs ++ Map.elems globalDumpPkgs) "." (snapDocDir bco) -- | Generate Haddock index and contents for specified packages. generateHaddockIndex :: (HasProcessContext env, HasLogFunc env, HasCompiler env) => Text -> BaseConfigOpts -> [DumpPackage] -> FilePath -> Path Abs Dir -> RIO env () generateHaddockIndex descr bco dumpPackages docRelFP destDir = do ensureDir destDir interfaceOpts <- (liftIO . fmap nubOrd . mapMaybeM toInterfaceOpt) dumpPackages unless (null interfaceOpts) $ do let destIndexFile = haddockIndexFile destDir eindexModTime <- liftIO (tryGetModificationTime destIndexFile) let needUpdate = case eindexModTime of Left _ -> True Right indexModTime -> or [mt > indexModTime | (_,mt,_,_) <- interfaceOpts] if needUpdate then do logInfo $ "Updating Haddock index for " <> Stack.Prelude.display descr <> " in\n" <> fromString (toFilePath destIndexFile) liftIO (mapM_ copyPkgDocs interfaceOpts) haddockExeName <- view $ compilerPathsL.to (toFilePath . cpHaddock) withWorkingDir (toFilePath destDir) $ readProcessNull haddockExeName (map (("--optghc=-package-db=" ++ ) . toFilePathNoTrailingSep) [bcoSnapDB bco, bcoLocalDB bco] ++ hoAdditionalArgs (boptsHaddockOpts (bcoBuildOpts bco)) ++ ["--gen-contents", "--gen-index"] ++ [x | (xs,_,_,_) <- interfaceOpts, x <- xs]) else logInfo $ "Haddock index for " <> Stack.Prelude.display descr <> " already up to date at:\n" <> fromString (toFilePath destIndexFile) where toInterfaceOpt :: DumpPackage -> IO (Maybe ([String], UTCTime, Path Abs File, Path Abs File)) toInterfaceOpt DumpPackage {dpHaddockInterfaces, dpPackageIdent, dpHaddockHtml} = case dpHaddockInterfaces of [] -> pure Nothing srcInterfaceFP:_ -> do srcInterfaceAbsFile <- parseCollapsedAbsFile srcInterfaceFP let (PackageIdentifier name _) = dpPackageIdent destInterfaceRelFP = docRelFP FP. packageIdentifierString dpPackageIdent FP. (packageNameString name FP.<.> "haddock") docPathRelFP = fmap ((docRelFP FP.) . FP.takeFileName) dpHaddockHtml interfaces = intercalate "," $ maybeToList docPathRelFP ++ [srcInterfaceFP] destInterfaceAbsFile <- parseCollapsedAbsFile (toFilePath destDir FP. destInterfaceRelFP) esrcInterfaceModTime <- tryGetModificationTime srcInterfaceAbsFile pure $ case esrcInterfaceModTime of Left _ -> Nothing Right srcInterfaceModTime -> Just ( [ "-i", interfaces ] , srcInterfaceModTime , srcInterfaceAbsFile , destInterfaceAbsFile ) copyPkgDocs :: (a, UTCTime, Path Abs File, Path Abs File) -> IO () copyPkgDocs (_,srcInterfaceModTime,srcInterfaceAbsFile,destInterfaceAbsFile) = do -- Copy dependencies' haddocks to documentation directory. This way, relative @../$pkg-$ver@ -- links work and it's easy to upload docs to a web server or otherwise view them in a -- non-local-filesystem context. We copy instead of symlink for two reasons: (1) symlinks -- aren't reliably supported on Windows, and (2) the filesystem containing dependencies' -- docs may not be available where viewing the docs (e.g. if building in a Docker -- container). edestInterfaceModTime <- tryGetModificationTime destInterfaceAbsFile case edestInterfaceModTime of Left _ -> doCopy Right destInterfaceModTime | destInterfaceModTime < srcInterfaceModTime -> doCopy | otherwise -> pure () where doCopy = do ignoringAbsence (removeDirRecur destHtmlAbsDir) ensureDir destHtmlAbsDir onException (copyDirRecur' (parent srcInterfaceAbsFile) destHtmlAbsDir) (ignoringAbsence (removeDirRecur destHtmlAbsDir)) destHtmlAbsDir = parent destInterfaceAbsFile -- | Find first DumpPackage matching the GhcPkgId lookupDumpPackage :: GhcPkgId -> [Map GhcPkgId DumpPackage] -> Maybe DumpPackage lookupDumpPackage ghcPkgId dumpPkgs = listToMaybe $ mapMaybe (Map.lookup ghcPkgId) dumpPkgs -- | Path of haddock index file. haddockIndexFile :: Path Abs Dir -> Path Abs File haddockIndexFile destDir = destDir relFileIndexHtml -- | Path of local packages documentation directory. localDocDir :: BaseConfigOpts -> Path Abs Dir localDocDir bco = bcoLocalInstallRoot bco docDirSuffix -- | Path of documentation directory for the dependencies of local packages localDepsDocDir :: BaseConfigOpts -> Path Abs Dir localDepsDocDir bco = localDocDir bco relDirAll -- | Path of snapshot packages documentation directory. snapDocDir :: BaseConfigOpts -> Path Abs Dir snapDocDir bco = bcoSnapInstallRoot bco docDirSuffix stack-2.9.3.1/src/Stack/Build/Installed.hs0000644000000000000000000002363514445022466016345 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} -- Determine which packages are already installed module Stack.Build.Installed ( InstalledMap , Installed (..) , getInstalled , InstallMap , toInstallMap ) where import Data.Conduit import qualified Data.Conduit.List as CL import qualified Data.Set as Set import qualified Data.Map.Strict as Map import Path import Stack.Build.Cache import Stack.Constants import Stack.PackageDump import Stack.Prelude import Stack.SourceMap (getPLIVersion, loadVersion) import Stack.Types.Build import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.Package import Stack.Types.SourceMap toInstallMap :: MonadIO m => SourceMap -> m InstallMap toInstallMap sourceMap = do projectInstalls <- for (smProject sourceMap) $ \pp -> do version <- loadVersion (ppCommon pp) pure (Local, version) depInstalls <- for (smDeps sourceMap) $ \dp -> case dpLocation dp of PLImmutable pli -> pure (Snap, getPLIVersion pli) PLMutable _ -> do version <- loadVersion (dpCommon dp) pure (Local, version) pure $ projectInstalls <> depInstalls -- | Returns the new InstalledMap and all of the locally registered packages. getInstalled :: HasEnvConfig env => InstallMap -- ^ does not contain any installed information -> RIO env ( InstalledMap , [DumpPackage] -- globally installed , [DumpPackage] -- snapshot installed , [DumpPackage] -- locally installed ) getInstalled {-opts-} installMap = do logDebug "Finding out which packages are already installed" snapDBPath <- packageDatabaseDeps localDBPath <- packageDatabaseLocal extraDBPaths <- packageDatabaseExtra let loadDatabase' = loadDatabase {-opts mcache-} installMap (installedLibs0, globalDumpPkgs) <- loadDatabase' Nothing [] (installedLibs1, _extraInstalled) <- foldM (\lhs' pkgdb -> loadDatabase' (Just (ExtraGlobal, pkgdb)) (fst lhs') ) (installedLibs0, globalDumpPkgs) extraDBPaths (installedLibs2, snapshotDumpPkgs) <- loadDatabase' (Just (InstalledTo Snap, snapDBPath)) installedLibs1 (installedLibs3, localDumpPkgs) <- loadDatabase' (Just (InstalledTo Local, localDBPath)) installedLibs2 let installedLibs = Map.fromList $ map lhPair installedLibs3 -- Add in the executables that are installed, making sure to only trust a -- listed installation under the right circumstances (see below) let exesToSM loc = Map.unions . map (exeToSM loc) exeToSM loc (PackageIdentifier name version) = case Map.lookup name installMap of -- Doesn't conflict with anything, so that's OK Nothing -> m Just (iLoc, iVersion) -- Not the version we want, ignore it | version /= iVersion || mismatchingLoc loc iLoc -> Map.empty | otherwise -> m where m = Map.singleton name (loc, Executable $ PackageIdentifier name version) mismatchingLoc installed target | target == installed = False | installed == Local = False -- snapshot dependency could end up -- in a local install as being mutable | otherwise = True exesSnap <- getInstalledExes Snap exesLocal <- getInstalledExes Local let installedMap = Map.unions [ exesToSM Local exesLocal , exesToSM Snap exesSnap , installedLibs ] pure ( installedMap , globalDumpPkgs , snapshotDumpPkgs , localDumpPkgs ) -- | Outputs both the modified InstalledMap and the Set of all installed packages in this database -- -- The goal is to ascertain that the dependencies for a package are present, -- that it has profiling if necessary, and that it matches the version and -- location needed by the SourceMap loadDatabase :: HasEnvConfig env => InstallMap -- ^ to determine which installed things we should include -> Maybe (InstalledPackageLocation, Path Abs Dir) -- ^ package database, Nothing for global -> [LoadHelper] -- ^ from parent databases -> RIO env ([LoadHelper], [DumpPackage]) loadDatabase installMap mdb lhs0 = do pkgexe <- getGhcPkgExe (lhs1', dps) <- ghcPkgDump pkgexe (fmap snd (maybeToList mdb)) $ conduitDumpPackage .| sink lhs1 <- mapMaybeM (processLoadResult mdb) lhs1' let lhs = pruneDeps id lhId lhDeps const (lhs0 ++ lhs1) pure (map (\lh -> lh { lhDeps = [] }) $ Map.elems lhs, dps) where mloc = fmap fst mdb sinkDP = CL.map (isAllowed installMap mloc &&& toLoadHelper mloc) .| CL.consume sink = getZipSink $ (,) <$> ZipSink sinkDP <*> ZipSink CL.consume processLoadResult :: HasLogFunc env => Maybe (InstalledPackageLocation, Path Abs Dir) -> (Allowed, LoadHelper) -> RIO env (Maybe LoadHelper) processLoadResult _ (Allowed, lh) = pure (Just lh) processLoadResult mdb (reason, lh) = do logDebug $ "Ignoring package " <> fromString (packageNameString (fst (lhPair lh))) <> maybe mempty (\db -> ", from " <> displayShow db <> ",") mdb <> " due to" <> case reason of UnknownPkg -> " it being unknown to the resolver / extra-deps." WrongLocation mloc loc -> " wrong location: " <> displayShow (mloc, loc) WrongVersion actual wanted -> " wanting version " <> fromString (versionString wanted) <> " instead of " <> fromString (versionString actual) pure Nothing data Allowed = Allowed | UnknownPkg | WrongLocation (Maybe InstalledPackageLocation) InstallLocation | WrongVersion Version Version deriving (Eq, Show) -- | Check if a can be included in the set of installed packages or not, based -- on the package selections made by the user. This does not perform any -- dirtiness or flag change checks. isAllowed :: InstallMap -> Maybe InstalledPackageLocation -> DumpPackage -> Allowed isAllowed installMap mloc dp = case Map.lookup name installMap of Nothing -> -- If the sourceMap has nothing to say about this package, -- check if it represents a sublibrary first -- See: https://github.com/commercialhaskell/stack/issues/3899 case dpParentLibIdent dp of Just (PackageIdentifier parentLibName version') -> case Map.lookup parentLibName installMap of Nothing -> checkNotFound Just instInfo | version' == version -> checkFound instInfo | otherwise -> checkNotFound -- different versions Nothing -> checkNotFound Just pii -> checkFound pii where PackageIdentifier name version = dpPackageIdent dp -- Ensure that the installed location matches where the sourceMap says it -- should be installed checkLocation Snap = True -- snapshot deps could become mutable after getting any mutable dependency checkLocation Local = mloc == Just (InstalledTo Local) || mloc == Just ExtraGlobal -- 'locally' installed snapshot packages can come from extra dbs -- Check if a package is allowed if it is found in the sourceMap checkFound (installLoc, installVer) | not (checkLocation installLoc) = WrongLocation mloc installLoc | version /= installVer = WrongVersion version installVer | otherwise = Allowed -- check if a package is allowed if it is not found in the sourceMap checkNotFound = case mloc of -- The sourceMap has nothing to say about this global package, so we can use it Nothing -> Allowed Just ExtraGlobal -> Allowed -- For non-global packages, don't include unknown packages. -- See: https://github.com/commercialhaskell/stack/issues/292 Just _ -> UnknownPkg data LoadHelper = LoadHelper { lhId :: !GhcPkgId , lhDeps :: ![GhcPkgId] , lhPair :: !(PackageName, (InstallLocation, Installed)) } deriving Show toLoadHelper :: Maybe InstalledPackageLocation -> DumpPackage -> LoadHelper toLoadHelper mloc dp = LoadHelper { lhId = gid , lhDeps = -- We always want to consider the wired in packages as having all -- of their dependencies installed, since we have no ability to -- reinstall them. This is especially important for using different -- minor versions of GHC, where the dependencies of wired-in -- packages may change slightly and therefore not match the -- snapshot. if name `Set.member` wiredInPackages then [] else dpDepends dp , lhPair = (name, (toPackageLocation mloc, Library ident gid (Right <$> dpLicense dp))) } where gid = dpGhcPkgId dp ident@(PackageIdentifier name _) = dpPackageIdent dp toPackageLocation :: Maybe InstalledPackageLocation -> InstallLocation toPackageLocation Nothing = Snap toPackageLocation (Just ExtraGlobal) = Snap toPackageLocation (Just (InstalledTo loc)) = loc stack-2.9.3.1/src/Stack/Build/Source.hs0000644000000000000000000005121314445022466015657 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -- Load information on package sources module Stack.Build.Source ( projectLocalPackages , localDependencies , loadCommonPackage , loadLocalPackage , loadSourceMap , getLocalFlags , addUnlistedToBuildCache , hashSourceMapData ) where import Stack.Prelude import qualified Pantry.SHA256 as SHA256 import Data.ByteString.Builder (toLazyByteString) import Conduit (ZipSink (..), withSourceFile) import qualified Distribution.PackageDescription as C import qualified Data.List as L import qualified Data.Map as Map import qualified Data.Map.Strict as M import qualified Data.Set as Set import Stack.Build.Cache import Stack.Build.Haddock (shouldHaddockDeps) import Stack.Build.Target import Stack.Package import Stack.SourceMap import Stack.Types.Build import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.PackageFile import Stack.Types.SourceMap import System.FilePath (takeFileName) import System.IO.Error (isDoesNotExistError) -- | loads and returns project packages projectLocalPackages :: HasEnvConfig env => RIO env [LocalPackage] projectLocalPackages = do sm <- view $ envConfigL.to envConfigSourceMap for (toList $ smProject sm) loadLocalPackage -- | loads all local dependencies - project packages and local extra-deps localDependencies :: HasEnvConfig env => RIO env [LocalPackage] localDependencies = do bopts <- view $ configL.to configBuild sourceMap <- view $ envConfigL . to envConfigSourceMap forMaybeM (Map.elems $ smDeps sourceMap) $ \dp -> case dpLocation dp of PLMutable dir -> do pp <- mkProjectPackage YesPrintWarnings dir (shouldHaddockDeps bopts) Just <$> loadLocalPackage pp _ -> pure Nothing -- | Given the parsed targets and build command line options constructs -- a source map loadSourceMap :: HasBuildConfig env => SMTargets -> BuildOptsCLI -> SMActual DumpedGlobalPackage -> RIO env SourceMap loadSourceMap smt boptsCli sma = do bconfig <- view buildConfigL let compiler = smaCompiler sma project = M.map applyOptsFlagsPP $ smaProject sma bopts = configBuild (bcConfig bconfig) applyOptsFlagsPP p@ProjectPackage{ppCommon = c} = p{ppCommon = applyOptsFlags (M.member (cpName c) (smtTargets smt)) True c} deps0 = smtDeps smt <> smaDeps sma deps = M.map applyOptsFlagsDep deps0 applyOptsFlagsDep d@DepPackage{dpCommon = c} = d{dpCommon = applyOptsFlags (M.member (cpName c) (smtDeps smt)) False c} applyOptsFlags isTarget isProjectPackage common = let name = cpName common flags = getLocalFlags boptsCli name ghcOptions = generalGhcOptions bconfig boptsCli isTarget isProjectPackage cabalConfigOpts = loadCabalConfigOpts bconfig (cpName common) isTarget isProjectPackage in common { cpFlags = if M.null flags then cpFlags common else flags , cpGhcOptions = ghcOptions ++ cpGhcOptions common , cpCabalConfigOpts = cabalConfigOpts ++ cpCabalConfigOpts common , cpHaddocks = if isTarget then boptsHaddock bopts else shouldHaddockDeps bopts } packageCliFlags = Map.fromList $ mapMaybe maybeProjectFlags $ Map.toList (boptsCLIFlags boptsCli) maybeProjectFlags (ACFByName name, fs) = Just (name, fs) maybeProjectFlags _ = Nothing globals = pruneGlobals (smaGlobal sma) (Map.keysSet deps) logDebug "Checking flags" checkFlagsUsedThrowing packageCliFlags FSCommandLine project deps logDebug "SourceMap constructed" pure SourceMap { smTargets = smt , smCompiler = compiler , smProject = project , smDeps = deps , smGlobal = globals } -- | Get a 'SourceMapHash' for a given 'SourceMap' -- -- Basic rules: -- -- * If someone modifies a GHC installation in any way after Stack -- looks at it, they voided the warranty. This includes installing a -- brand new build to the same directory, or registering new -- packages to the global database. -- -- * We should include everything in the hash that would relate to -- immutable packages and identifying the compiler itself. Mutable -- packages (both project packages and dependencies) will never make -- it into the snapshot database, and can be ignored. -- -- * Target information is only relevant insofar as it effects the -- dependency map. The actual current targets for this build are -- irrelevant to the cache mechanism, and can be ignored. -- -- * Make sure things like profiling and haddocks are included in the hash -- hashSourceMapData :: (HasBuildConfig env, HasCompiler env) => BuildOptsCLI -> SourceMap -> RIO env SourceMapHash hashSourceMapData boptsCli sm = do compilerPath <- getUtf8Builder . fromString . toFilePath <$> getCompilerPath compilerInfo <- getCompilerInfo immDeps <- forM (Map.elems (smDeps sm)) depPackageHashableContent bc <- view buildConfigL let -- extra bytestring specifying GHC options supposed to be applied to -- GHC boot packages so we'll have different hashes when bare -- resolver 'ghc-X.Y.Z' is used, no extra-deps and e.g. user wants builds -- with profiling or without bootGhcOpts = map display (generalGhcOptions bc boptsCli False False) hashedContent = toLazyByteString $ compilerPath <> compilerInfo <> getUtf8Builder (mconcat bootGhcOpts) <> mconcat immDeps pure $ SourceMapHash (SHA256.hashLazyBytes hashedContent) depPackageHashableContent :: (HasConfig env) => DepPackage -> RIO env Builder depPackageHashableContent DepPackage {..} = do case dpLocation of PLMutable _ -> pure "" PLImmutable pli -> do let flagToBs (f, enabled) = if enabled then "" else "-" <> fromString (C.unFlagName f) flags = map flagToBs $ Map.toList (cpFlags dpCommon) ghcOptions = map display (cpGhcOptions dpCommon) cabalConfigOpts = map display (cpCabalConfigOpts dpCommon) haddocks = if cpHaddocks dpCommon then "haddocks" else "" hash = immutableLocSha pli pure $ hash <> haddocks <> getUtf8Builder (mconcat flags) <> getUtf8Builder (mconcat ghcOptions) <> getUtf8Builder (mconcat cabalConfigOpts) -- | All flags for a local package. getLocalFlags :: BuildOptsCLI -> PackageName -> Map FlagName Bool getLocalFlags boptsCli name = Map.unions [ Map.findWithDefault Map.empty (ACFByName name) cliFlags , Map.findWithDefault Map.empty ACFAllProjectPackages cliFlags ] where cliFlags = boptsCLIFlags boptsCli -- | Get the options to pass to @./Setup.hs configure@ loadCabalConfigOpts :: BuildConfig -> PackageName -> Bool -> Bool -> [Text] loadCabalConfigOpts bconfig name isTarget isLocal = concat [ Map.findWithDefault [] CCKEverything (configCabalConfigOpts config) , if isLocal then Map.findWithDefault [] CCKLocals (configCabalConfigOpts config) else [] , if isTarget then Map.findWithDefault [] CCKTargets (configCabalConfigOpts config) else [] , Map.findWithDefault [] (CCKPackage name) (configCabalConfigOpts config) ] where config = view configL bconfig -- | Get the configured options to pass from GHC, based on the build -- configuration and commandline. generalGhcOptions :: BuildConfig -> BuildOptsCLI -> Bool -> Bool -> [Text] generalGhcOptions bconfig boptsCli isTarget isLocal = concat [ Map.findWithDefault [] AGOEverything (configGhcOptionsByCat config) , if isLocal then Map.findWithDefault [] AGOLocals (configGhcOptionsByCat config) else [] , if isTarget then Map.findWithDefault [] AGOTargets (configGhcOptionsByCat config) else [] , concat [["-fhpc"] | isLocal && toCoverage (boptsTestOpts bopts)] , if boptsLibProfile bopts || boptsExeProfile bopts then ["-fprof-auto","-fprof-cafs"] else [] , if not $ boptsLibStrip bopts || boptsExeStrip bopts then ["-g"] else [] , if includeExtraOptions then boptsCLIGhcOptions boptsCli else [] ] where bopts = configBuild config config = view configL bconfig includeExtraOptions = case configApplyGhcOptions config of AGOTargets -> isTarget AGOLocals -> isLocal AGOEverything -> True splitComponents :: [NamedComponent] -> (Set Text, Set Text, Set Text) splitComponents = go id id id where go a b c [] = (Set.fromList $ a [], Set.fromList $ b [], Set.fromList $ c []) go a b c (CLib:xs) = go a b c xs go a b c (CInternalLib x:xs) = go (a . (x:)) b c xs go a b c (CExe x:xs) = go (a . (x:)) b c xs go a b c (CTest x:xs) = go a (b . (x:)) c xs go a b c (CBench x:xs) = go a b (c . (x:)) xs loadCommonPackage :: forall env. (HasBuildConfig env, HasSourceMap env) => CommonPackage -> RIO env Package loadCommonPackage common = do config <- getPackageConfig (cpFlags common) (cpGhcOptions common) (cpCabalConfigOpts common) gpkg <- liftIO $ cpGPD common pure $ resolvePackage config gpkg -- | Upgrade the initial project package info to a full-blown @LocalPackage@ -- based on the selected components loadLocalPackage :: forall env. (HasBuildConfig env, HasSourceMap env) => ProjectPackage -> RIO env LocalPackage loadLocalPackage pp = do sm <- view sourceMapL let common = ppCommon pp bopts <- view buildOptsL mcurator <- view $ buildConfigL.to bcCurator config <- getPackageConfig (cpFlags common) (cpGhcOptions common) (cpCabalConfigOpts common) gpkg <- ppGPD pp let name = cpName common mtarget = M.lookup name (smtTargets $ smTargets sm) (exeCandidates, testCandidates, benchCandidates) = case mtarget of Just (TargetComps comps) -> splitComponents $ Set.toList comps Just (TargetAll _packageType) -> ( packageExes pkg , if boptsTests bopts && maybe True (Set.notMember name . curatorSkipTest) mcurator then Map.keysSet (packageTests pkg) else Set.empty , if boptsBenchmarks bopts && maybe True (Set.notMember name . curatorSkipBenchmark) mcurator then packageBenchmarks pkg else Set.empty ) Nothing -> mempty -- See https://github.com/commercialhaskell/stack/issues/2862 isWanted = case mtarget of Nothing -> False -- FIXME: When issue #1406 ("stack 0.1.8 lost ability to -- build individual executables or library") is resolved, -- 'hasLibrary' is only relevant if the library is -- part of the target spec. Just _ -> let hasLibrary = case packageLibraries pkg of NoLibraries -> False HasLibraries _ -> True in hasLibrary || not (Set.null nonLibComponents) || not (Set.null $ packageInternalLibraries pkg) filterSkippedComponents = Set.filter (not . (`elem` boptsSkipComponents bopts)) (exes, tests, benches) = (filterSkippedComponents exeCandidates, filterSkippedComponents testCandidates, filterSkippedComponents benchCandidates) nonLibComponents = toComponents exes tests benches toComponents e t b = Set.unions [ Set.map CExe e , Set.map CTest t , Set.map CBench b ] btconfig = config { packageConfigEnableTests = not $ Set.null tests , packageConfigEnableBenchmarks = not $ Set.null benches } -- We resolve the package in 2 different configurations: -- -- - pkg doesn't have tests or benchmarks enabled. -- -- - btpkg has them enabled if they are present. -- -- The latter two configurations are used to compute the deps -- when --enable-benchmarks or --enable-tests are configured. -- This allows us to do an optimization where these are passed -- if the deps are present. This can avoid doing later -- unnecessary reconfigures. pkg = resolvePackage config gpkg btpkg | Set.null tests && Set.null benches = Nothing | otherwise = Just (resolvePackage btconfig gpkg) componentFiles <- memoizeRefWith $ fst <$> getPackageFilesForTargets pkg (ppCabalFP pp) nonLibComponents checkCacheResults <- memoizeRefWith $ do componentFiles' <- runMemoizedWith componentFiles forM (Map.toList componentFiles') $ \(component, files) -> do mbuildCache <- tryGetBuildCache (ppRoot pp) component checkCacheResult <- checkBuildCache (fromMaybe Map.empty mbuildCache) (Set.toList files) pure (component, checkCacheResult) let dirtyFiles = do checkCacheResults' <- checkCacheResults let allDirtyFiles = Set.unions $ map (\(_, (x, _)) -> x) checkCacheResults' pure $ if not (Set.null allDirtyFiles) then let tryStripPrefix y = fromMaybe y (L.stripPrefix (toFilePath $ ppRoot pp) y) in Just $ Set.map tryStripPrefix allDirtyFiles else Nothing newBuildCaches = M.fromList . map (\(c, (_, cache)) -> (c, cache)) <$> checkCacheResults pure LocalPackage { lpPackage = pkg , lpTestBench = btpkg , lpComponentFiles = componentFiles , lpBuildHaddocks = cpHaddocks (ppCommon pp) , lpForceDirty = boptsForceDirty bopts , lpDirtyFiles = dirtyFiles , lpNewBuildCaches = newBuildCaches , lpCabalFile = ppCabalFP pp , lpWanted = isWanted , lpComponents = nonLibComponents -- TODO: refactor this so that it's easier to be sure that these -- components are indeed unbuildable. -- -- The reasoning here is that if the STLocalComps specification -- made it through component parsing, but the components aren't -- present, then they must not be buildable. , lpUnbuildable = toComponents (exes `Set.difference` packageExes pkg) (tests `Set.difference` Map.keysSet (packageTests pkg)) (benches `Set.difference` packageBenchmarks pkg) } -- | Compare the current filesystem state to the cached information, and -- determine (1) if the files are dirty, and (2) the new cache values. checkBuildCache :: forall m. (MonadIO m) => Map FilePath FileCacheInfo -- ^ old cache -> [Path Abs File] -- ^ files in package -> m (Set FilePath, Map FilePath FileCacheInfo) checkBuildCache oldCache files = do fileTimes <- liftM Map.fromList $ forM files $ \fp -> do mdigest <- liftIO (getFileDigestMaybe (toFilePath fp)) pure (toFilePath fp, mdigest) liftM (mconcat . Map.elems) $ sequence $ Map.mergeWithKey (\fp mdigest fci -> Just (go fp mdigest (Just fci))) (Map.mapWithKey (\fp mdigest -> go fp mdigest Nothing)) (Map.mapWithKey (\fp fci -> go fp Nothing (Just fci))) fileTimes oldCache where go :: FilePath -> Maybe SHA256 -> Maybe FileCacheInfo -> m (Set FilePath, Map FilePath FileCacheInfo) -- Filter out the cabal_macros file to avoid spurious recompilations go fp _ _ | takeFileName fp == "cabal_macros.h" = pure (Set.empty, Map.empty) -- Common case where it's in the cache and on the filesystem. go fp (Just digest') (Just fci) | fciHash fci == digest' = pure (Set.empty, Map.singleton fp fci) | otherwise = pure (Set.singleton fp, Map.singleton fp $ FileCacheInfo digest') -- Missing file. Add it to dirty files, but no FileCacheInfo. go fp Nothing _ = pure (Set.singleton fp, Map.empty) -- Missing cache. Add it to dirty files and compute FileCacheInfo. go fp (Just digest') Nothing = pure (Set.singleton fp, Map.singleton fp $ FileCacheInfo digest') -- | Returns entries to add to the build cache for any newly found unlisted modules addUnlistedToBuildCache :: HasEnvConfig env => Package -> Path Abs File -> Set NamedComponent -> Map NamedComponent (Map FilePath a) -> RIO env (Map NamedComponent [Map FilePath FileCacheInfo], [PackageWarning]) addUnlistedToBuildCache pkg cabalFP nonLibComponents buildCaches = do (componentFiles, warnings) <- getPackageFilesForTargets pkg cabalFP nonLibComponents results <- forM (M.toList componentFiles) $ \(component, files) -> do let buildCache = M.findWithDefault M.empty component buildCaches newFiles = Set.toList $ Set.map toFilePath files `Set.difference` Map.keysSet buildCache addBuildCache <- mapM addFileToCache newFiles pure ((component, addBuildCache), warnings) pure (M.fromList (map fst results), concatMap snd results) where addFileToCache fp = do mdigest <- getFileDigestMaybe fp case mdigest of Nothing -> pure Map.empty Just digest' -> pure . Map.singleton fp $ FileCacheInfo digest' -- | Gets list of Paths for files relevant to a set of components in a package. -- Note that the library component, if any, is always automatically added to the -- set of components. getPackageFilesForTargets :: HasEnvConfig env => Package -> Path Abs File -> Set NamedComponent -> RIO env (Map NamedComponent (Set (Path Abs File)), [PackageWarning]) getPackageFilesForTargets pkg cabalFP nonLibComponents = do (components',compFiles,otherFiles,warnings) <- getPackageFiles (packageFiles pkg) cabalFP let necessaryComponents = Set.insert CLib $ Set.filter isCInternalLib (M.keysSet components') components = necessaryComponents `Set.union` nonLibComponents componentsFiles = M.map (\files -> Set.union otherFiles (Set.map dotCabalGetPath $ Set.fromList files)) $ M.filterWithKey (\component _ -> component `elem` components) compFiles pure (componentsFiles, warnings) -- | Get file digest, if it exists getFileDigestMaybe :: MonadIO m => FilePath -> m (Maybe SHA256) getFileDigestMaybe fp = do liftIO (catch (liftM Just . withSourceFile fp $ getDigest) (\e -> if isDoesNotExistError e then pure Nothing else throwM e)) where getDigest src = runConduit $ src .| getZipSink (ZipSink SHA256.sinkHash) -- | Get 'PackageConfig' for package given its name. getPackageConfig :: (HasBuildConfig env, HasSourceMap env) => Map FlagName Bool -> [Text] -- ^ GHC options -> [Text] -- ^ cabal config opts -> RIO env PackageConfig getPackageConfig flags ghcOptions cabalConfigOpts = do platform <- view platformL compilerVersion <- view actualCompilerVersionL pure PackageConfig { packageConfigEnableTests = False , packageConfigEnableBenchmarks = False , packageConfigFlags = flags , packageConfigGhcOptions = ghcOptions , packageConfigCabalConfigOpts = cabalConfigOpts , packageConfigCompilerVersion = compilerVersion , packageConfigPlatform = platform } stack-2.9.3.1/src/Stack/Build/Target.hs0000644000000000000000000005022014445022466015642 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE ViewPatterns #-} -- | Parsing command line targets -- -- There are two relevant data sources for performing this parsing: -- the project configuration, and command line arguments. Project -- configurations includes the resolver (defining a LoadedSnapshot of -- global and snapshot packages), local dependencies, and project -- packages. It also defines local flag overrides. -- -- The command line arguments specify both additional local flag -- overrides and targets in their raw form. -- -- Flags are simple: we just combine CLI flags with config flags and -- make one big map of flags, preferring CLI flags when present. -- -- Raw targets can be a package name, a package name with component, -- just a component, or a package name and version number. We first -- must resolve these raw targets into both simple targets and -- additional dependencies. This works as follows: -- -- * If a component is specified, find a unique project package which -- defines that component, and convert it into a name+component -- target. -- -- * Ensure that all name+component values refer to valid components -- in the given project package. -- -- * For names, check if the name is present in the snapshot, local -- deps, or project packages. If it is not, then look up the most -- recent version in the package index and convert to a -- name+version. -- -- * For name+version, first ensure that the name is not used by a -- project package. Next, if that name+version is present in the -- snapshot or local deps _and_ its location is PLIndex, we have the -- package. Otherwise, add to local deps with the appropriate -- PLIndex. -- -- If in either of the last two bullets we added a package to local -- deps, print a warning to the user recommending modifying the -- extra-deps. -- -- Combine the various 'ResolveResults's together into 'Target' -- values, by combining various components for a single package and -- ensuring that no conflicting statements were made about targets. -- -- At this point, we now have a Map from package name to SimpleTarget, -- and an updated Map of local dependencies. We still have the -- aggregated flags, and the snapshot and project packages. -- -- Finally, we upgrade the snapshot by using -- calculatePackagePromotion. module Stack.Build.Target ( -- * Types Target (..) , NeedTargets (..) , PackageType (..) , parseTargets -- * Convenience helpers , gpdVersion -- * Test suite exports , parseRawTarget , RawTarget (..) , UnresolvedComponent (..) ) where import qualified Data.Map as Map import qualified Data.Set as Set import qualified Data.Text as T import Path import Path.Extra ( rejectMissingDir ) import Path.IO import RIO.Process ( HasProcessContext ) import Stack.SourceMap import Stack.Prelude import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.Build import Stack.Types.SourceMap -- | Do we need any targets? For example, `stack build` will fail if -- no targets are provided. data NeedTargets = NeedTargets | AllowNoTargets --------------------------------------------------------------------------------- -- Get the RawInput --------------------------------------------------------------------------------- -- | Raw target information passed on the command line. newtype RawInput = RawInput { unRawInput :: Text } getRawInput :: BuildOptsCLI -> Map PackageName ProjectPackage -> ([Text], [RawInput]) getRawInput boptscli locals = let textTargets' = boptsCLITargets boptscli textTargets = -- Handle the no targets case, which means we pass in the names of all project packages if null textTargets' then map (T.pack . packageNameString) (Map.keys locals) else textTargets' in (textTargets', map RawInput textTargets) --------------------------------------------------------------------------------- -- Turn RawInput into RawTarget --------------------------------------------------------------------------------- -- | The name of a component, which applies to executables, test -- suites, and benchmarks type ComponentName = Text -- | Either a fully resolved component, or a component name that could be -- either an executable, test, or benchmark data UnresolvedComponent = ResolvedComponent !NamedComponent | UnresolvedComponent !ComponentName deriving (Show, Eq, Ord) -- | Raw command line input, without checking against any databases or list of -- locals. Does not deal with directories data RawTarget = RTPackageComponent !PackageName !UnresolvedComponent | RTComponent !ComponentName | RTPackage !PackageName -- Explicitly _not_ supporting revisions on the command line. If -- you want that, you should be modifying your stack.yaml! (In -- fact, you should probably do that anyway, we're just letting -- people be lazy, since we're Haskeletors.) | RTPackageIdentifier !PackageIdentifier deriving (Show, Eq) -- | Same as @parseRawTarget@, but also takes directories into account. parseRawTargetDirs :: MonadIO m => Path Abs Dir -- ^ current directory -> Map PackageName ProjectPackage -> RawInput -- ^ raw target information from the commandline -> m (Either Text [(RawInput, RawTarget)]) parseRawTargetDirs root locals ri = case parseRawTarget t of Just rt -> pure $ Right [(ri, rt)] Nothing -> do mdir <- liftIO $ forgivingAbsence (resolveDir root (T.unpack t)) >>= rejectMissingDir case mdir of Nothing -> pure $ Left $ "Directory not found: " `T.append` t Just dir -> case mapMaybe (childOf dir) $ Map.toList locals of [] -> pure $ Left $ "No local directories found as children of " `T.append` t names -> pure $ Right $ map ((ri, ) . RTPackage) names where childOf dir (name, pp) = if dir == ppRoot pp || isProperPrefixOf dir (ppRoot pp) then Just name else Nothing RawInput t = ri -- | If this function returns @Nothing@, the input should be treated as a -- directory. parseRawTarget :: Text -> Maybe RawTarget parseRawTarget t = (RTPackageIdentifier <$> parsePackageIdentifier s) <|> (RTPackage <$> parsePackageName s) <|> (RTComponent <$> T.stripPrefix ":" t) <|> parsePackageComponent where s = T.unpack t parsePackageComponent = case T.splitOn ":" t of [pname, "lib"] | Just pname' <- parsePackageName (T.unpack pname) -> Just $ RTPackageComponent pname' $ ResolvedComponent CLib [pname, cname] | Just pname' <- parsePackageName (T.unpack pname) -> Just $ RTPackageComponent pname' $ UnresolvedComponent cname [pname, typ, cname] | Just pname' <- parsePackageName (T.unpack pname) , Just wrapper <- parseCompType typ -> Just $ RTPackageComponent pname' $ ResolvedComponent $ wrapper cname _ -> Nothing parseCompType t' = case t' of "exe" -> Just CExe "test" -> Just CTest "bench" -> Just CBench _ -> Nothing --------------------------------------------------------------------------------- -- Resolve the raw targets --------------------------------------------------------------------------------- data ResolveResult = ResolveResult { rrName :: !PackageName , rrRaw :: !RawInput , rrComponent :: !(Maybe NamedComponent) -- ^ Was a concrete component specified? , rrAddedDep :: !(Maybe PackageLocationImmutable) -- ^ Only if we're adding this as a dependency , rrPackageType :: !PackageType } -- | Convert a 'RawTarget' into a 'ResolveResult' (see description on -- the module). resolveRawTarget :: (HasLogFunc env, HasPantryConfig env, HasProcessContext env) => SMActual GlobalPackage -> Map PackageName PackageLocation -> (RawInput, RawTarget) -> RIO env (Either Text ResolveResult) resolveRawTarget sma allLocs (ri, rt) = go rt where locals = smaProject sma deps = smaDeps sma globals = smaGlobal sma -- Helper function: check if a 'NamedComponent' matches the given 'ComponentName' isCompNamed :: ComponentName -> NamedComponent -> Bool isCompNamed _ CLib = False isCompNamed t1 (CInternalLib t2) = t1 == t2 isCompNamed t1 (CExe t2) = t1 == t2 isCompNamed t1 (CTest t2) = t1 == t2 isCompNamed t1 (CBench t2) = t1 == t2 go (RTComponent cname) = do -- Associated list from component name to package that defines -- it. We use an assoc list and not a Map so we can detect -- duplicates. allPairs <- fmap concat $ flip Map.traverseWithKey locals $ \name pp -> do comps <- ppComponents pp pure $ map (name, ) $ Set.toList comps pure $ case filter (isCompNamed cname . snd) allPairs of [] -> Left $ cname `T.append` " doesn't seem to be a local target. Run 'stack ide targets' for a list of available targets" [(name, comp)] -> Right ResolveResult { rrName = name , rrRaw = ri , rrComponent = Just comp , rrAddedDep = Nothing , rrPackageType = PTProject } matches -> Left $ T.concat [ "Ambiguous component name " , cname , ", matches: " , T.pack $ show matches ] go (RTPackageComponent name ucomp) = case Map.lookup name locals of Nothing -> pure $ Left $ T.pack $ "Unknown local package: " ++ packageNameString name Just pp -> do comps <- ppComponents pp pure $ case ucomp of ResolvedComponent comp | comp `Set.member` comps -> Right ResolveResult { rrName = name , rrRaw = ri , rrComponent = Just comp , rrAddedDep = Nothing , rrPackageType = PTProject } | otherwise -> Left $ T.pack $ concat [ "Component " , show comp , " does not exist in package " , packageNameString name ] UnresolvedComponent comp -> case filter (isCompNamed comp) $ Set.toList comps of [] -> Left $ T.concat [ "Component " , comp , " does not exist in package " , T.pack $ packageNameString name ] [x] -> Right ResolveResult { rrName = name , rrRaw = ri , rrComponent = Just x , rrAddedDep = Nothing , rrPackageType = PTProject } matches -> Left $ T.concat [ "Ambiguous component name " , comp , " for package " , T.pack $ packageNameString name , ": " , T.pack $ show matches ] go (RTPackage name) | Map.member name locals = pure $ Right ResolveResult { rrName = name , rrRaw = ri , rrComponent = Nothing , rrAddedDep = Nothing , rrPackageType = PTProject } | Map.member name deps = pure $ deferToConstructPlan name | Just gp <- Map.lookup name globals = case gp of GlobalPackage _ -> pure $ deferToConstructPlan name ReplacedGlobalPackage _ -> hackageLatest name | otherwise = hackageLatest name -- Note that we use getLatestHackageRevision below, even though it's -- non-reproducible, to avoid user confusion. In any event, -- reproducible builds should be done by updating your config -- files! go (RTPackageIdentifier ident@(PackageIdentifier name version)) | Map.member name locals = pure $ Left $ T.concat [ tshow (packageNameString name) , " target has a specific version number, but it is a local package." , "\nTo avoid confusion, we will not install the specified version or build the local one." , "\nTo build the local package, specify the target without an explicit version." ] | otherwise = case Map.lookup name allLocs of -- Installing it from the package index, so we're cool -- with overriding it if necessary Just (PLImmutable (PLIHackage (PackageIdentifier _name versionLoc) _cfKey _treeKey)) -> if version == versionLoc then pure $ deferToConstructPlan name else hackageLatestRevision name version -- The package was coming from something besides the -- index, so refuse to do the override Just loc' -> pure $ Left $ T.concat [ "Package with identifier was targeted on the command line: " , T.pack $ packageIdentifierString ident , ", but it was specified from a non-index location: " , T.pack $ show loc' , ".\nRecommendation: add the correctly desired version to extra-deps." ] -- Not present at all, add it from Hackage Nothing -> do mrev <- getLatestHackageRevision YesRequireHackageIndex name version pure $ case mrev of Nothing -> deferToConstructPlan name Just (_rev, cfKey, treeKey) -> Right ResolveResult { rrName = name , rrRaw = ri , rrComponent = Nothing , rrAddedDep = Just $ PLIHackage (PackageIdentifier name version) cfKey treeKey , rrPackageType = PTDependency } hackageLatest name = do mloc <- getLatestHackageLocation YesRequireHackageIndex name UsePreferredVersions pure $ case mloc of Nothing -> deferToConstructPlan name Just loc -> do Right ResolveResult { rrName = name , rrRaw = ri , rrComponent = Nothing , rrAddedDep = Just loc , rrPackageType = PTDependency } hackageLatestRevision name version = do mrev <- getLatestHackageRevision YesRequireHackageIndex name version pure $ case mrev of Nothing -> deferToConstructPlan name Just (_rev, cfKey, treeKey) -> Right ResolveResult { rrName = name , rrRaw = ri , rrComponent = Nothing , rrAddedDep = Just $ PLIHackage (PackageIdentifier name version) cfKey treeKey , rrPackageType = PTDependency } -- This is actually an error case. We _could_ pure a -- Left value here, but it turns out to be better to defer -- this until the ConstructPlan phase, and let it complain -- about the missing package so that we get more errors -- together, plus the fancy colored output from that -- module. deferToConstructPlan name = Right ResolveResult { rrName = name , rrRaw = ri , rrComponent = Nothing , rrAddedDep = Nothing , rrPackageType = PTDependency } --------------------------------------------------------------------------------- -- Combine the ResolveResults --------------------------------------------------------------------------------- combineResolveResults :: forall env. HasLogFunc env => [ResolveResult] -> RIO env ([Text], Map PackageName Target, Map PackageName PackageLocationImmutable) combineResolveResults results = do addedDeps <- fmap Map.unions $ forM results $ \result -> case rrAddedDep result of Nothing -> pure Map.empty Just pl -> do pure $ Map.singleton (rrName result) pl let m0 = Map.unionsWith (++) $ map (\rr -> Map.singleton (rrName rr) [rr]) results (errs, ms) = partitionEithers $ flip map (Map.toList m0) $ \(name, rrs) -> let mcomps = map rrComponent rrs in -- Confirm that there is either exactly 1 with no component, or -- that all rrs are components case rrs of [] -> assert False $ Left "Somehow got no rrComponent values, that can't happen" [rr] | isNothing (rrComponent rr) -> Right $ Map.singleton name $ TargetAll $ rrPackageType rr _ | all isJust mcomps -> Right $ Map.singleton name $ TargetComps $ Set.fromList $ catMaybes mcomps | otherwise -> Left $ T.concat [ "The package " , T.pack $ packageNameString name , " was specified in multiple, incompatible ways: " , T.unwords $ map (unRawInput . rrRaw) rrs ] pure (errs, Map.unions ms, addedDeps) --------------------------------------------------------------------------------- -- OK, let's do it! --------------------------------------------------------------------------------- parseTargets :: HasBuildConfig env => NeedTargets -> Bool -> BuildOptsCLI -> SMActual GlobalPackage -> RIO env SMTargets parseTargets needTargets haddockDeps boptscli smActual = do logDebug "Parsing the targets" bconfig <- view buildConfigL workingDir <- getCurrentDir locals <- view $ buildConfigL.to (smwProject . bcSMWanted) let (textTargets', rawInput) = getRawInput boptscli locals (errs1, concat -> rawTargets) <- fmap partitionEithers $ forM rawInput $ parseRawTargetDirs workingDir locals let depLocs = Map.map dpLocation $ smaDeps smActual (errs2, resolveResults) <- fmap partitionEithers $ forM rawTargets $ resolveRawTarget smActual depLocs (errs3, targets, addedDeps) <- combineResolveResults resolveResults case concat [errs1, errs2, errs3] of [] -> pure () errs -> throwIO $ TargetParseException errs case (Map.null targets, needTargets) of (False, _) -> pure () (True, AllowNoTargets) -> pure () (True, NeedTargets) | null textTargets' && bcImplicitGlobal bconfig -> throwIO $ TargetParseException ["The specified targets matched no packages.\nPerhaps you need to run 'stack init'?"] | null textTargets' && Map.null locals -> throwIO $ TargetParseException ["The project contains no local packages (packages not marked with 'extra-dep')"] | otherwise -> throwIO $ TargetParseException ["The specified targets matched no packages"] addedDeps' <- mapM (additionalDepPackage haddockDeps . PLImmutable) addedDeps pure SMTargets { smtTargets = targets , smtDeps = addedDeps' } where bcImplicitGlobal bconfig = case configProject $ bcConfig bconfig of PCProject _ -> False PCGlobalProject -> True PCNoProject _ -> False stack-2.9.3.1/src/Stack/BuildPlan.hs0000644000000000000000000005113014445022466015230 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Resolving a build plan for a set of packages in a given Stackage -- snapshot. module Stack.BuildPlan ( BuildPlanException (..) , BuildPlanCheck (..) , checkSnapBuildPlan , DepError (..) , DepErrors , removeSrcPkgDefaultFlags , selectBestSnapshot , showItems ) where import Stack.Prelude hiding (Display (..)) import qualified Data.Foldable as F import qualified Data.Set as Set import Data.List (intercalate) import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Map as Map import qualified Data.Text as T import qualified Distribution.Package as C import Distribution.PackageDescription (GenericPackageDescription, flagDefault, flagManual, flagName, genPackageFlags) import qualified Distribution.PackageDescription as C import Distribution.System (Platform) import Distribution.Text (display) import Distribution.Types.UnqualComponentName (unUnqualComponentName) import qualified Distribution.Version as C import Stack.Constants import Stack.Package import Stack.SourceMap import Stack.Types.SourceMap import Stack.Types.Version import Stack.Types.Config import Stack.Types.Compiler -- | Type representing exceptions thrown by functions exported by the -- "Stack.BuildPlan" module. data BuildPlanException = UnknownPackages (Path Abs File) -- stack.yaml file (Map PackageName (Maybe Version, Set PackageName)) -- truly unknown (Map PackageName (Set PackageIdentifier)) -- shadowed | SnapshotNotFound SnapName | NeitherCompilerOrResolverSpecified T.Text | DuplicatePackagesBug deriving (Show, Typeable) instance Exception BuildPlanException where displayException (SnapshotNotFound snapName) = unlines [ "Error: [S-2045]" , "SnapshotNotFound " ++ snapName' , "Non existing resolver: " ++ snapName' ++ "." , "For a complete list of available snapshots see https://www.stackage.org/snapshots" ] where snapName' = show snapName displayException (UnknownPackages stackYaml unknown shadowed) = "Error: [S-7571]\n" ++ unlines (unknown' ++ shadowed') where unknown' :: [String] unknown' | Map.null unknown = [] | otherwise = concat [ ["The following packages do not exist in the build plan:"] , map go (Map.toList unknown) , case mapMaybe goRecommend $ Map.toList unknown of [] -> [] rec -> ("Recommended action: modify the extra-deps field of " ++ toFilePath stackYaml ++ " to include the following:") : (rec ++ ["Note: further dependencies may need to be added"]) , case mapMaybe getNoKnown $ Map.toList unknown of [] -> [] noKnown -> [ "There are no known versions of the following packages:" , intercalate ", " $ map packageNameString noKnown ] ] where go (dep, (_, users)) | Set.null users = packageNameString dep go (dep, (_, users)) = concat [ packageNameString dep , " (used by " , intercalate ", " $ map packageNameString $ Set.toList users , ")" ] goRecommend (name, (Just version, _)) = Just $ "- " ++ packageIdentifierString (PackageIdentifier name version) goRecommend (_, (Nothing, _)) = Nothing getNoKnown (name, (Nothing, _)) = Just name getNoKnown (_, (Just _, _)) = Nothing shadowed' :: [String] shadowed' | Map.null shadowed = [] | otherwise = concat [ ["The following packages are shadowed by local packages:"] , map go (Map.toList shadowed) , ["Recommended action: modify the extra-deps field of " ++ toFilePath stackYaml ++ " to include the following:"] , extraDeps , ["Note: further dependencies may need to be added"] ] where go (dep, users) | Set.null users = packageNameString dep ++ " (internal Stack error: this should never be null)" go (dep, users) = concat [ packageNameString dep , " (used by " , intercalate ", " $ map (packageNameString . pkgName) $ Set.toList users , ")" ] extraDeps = map (\ident -> "- " ++ packageIdentifierString ident) $ Set.toList $ Set.unions $ Map.elems shadowed displayException (NeitherCompilerOrResolverSpecified url) = concat [ "Error: [S-8559]\n" , "Failed to load custom snapshot at " , T.unpack url , ", because no 'compiler' or 'resolver' is specified." ] displayException DuplicatePackagesBug = bugReport "[S-5743]" "Duplicate packages are not expected here." gpdPackages :: [GenericPackageDescription] -> Map PackageName Version gpdPackages = Map.fromList . map (toPair . C.package . C.packageDescription) where toPair (C.PackageIdentifier name version) = (name, version) gpdPackageDeps :: GenericPackageDescription -> ActualCompiler -> Platform -> Map FlagName Bool -> Map PackageName VersionRange gpdPackageDeps gpd ac platform flags = Map.filterWithKey (const . not . isLocalLibrary) (packageDependencies pkgConfig pkgDesc) where isLocalLibrary name' = name' == name || name' `Set.member` subs name = gpdPackageName gpd subs = Set.fromList $ map (C.mkPackageName . unUnqualComponentName . fst) $ C.condSubLibraries gpd -- Since tests and benchmarks are both enabled, doesn't matter -- if we choose modified or unmodified pkgDesc = pdpModifiedBuildable $ resolvePackageDescription pkgConfig gpd pkgConfig = PackageConfig { packageConfigEnableTests = True , packageConfigEnableBenchmarks = True , packageConfigFlags = flags , packageConfigGhcOptions = [] , packageConfigCabalConfigOpts = [] , packageConfigCompilerVersion = ac , packageConfigPlatform = platform } -- Remove any src package flags having default values -- Remove any package entries with no flags set removeSrcPkgDefaultFlags :: [C.GenericPackageDescription] -> Map PackageName (Map FlagName Bool) -> Map PackageName (Map FlagName Bool) removeSrcPkgDefaultFlags gpds flags = let defaults = Map.unions (map gpdDefaultFlags gpds) flags' = Map.differenceWith removeSame flags defaults in Map.filter (not . Map.null) flags' where removeSame f1 f2 = let diff v v' = if v == v' then Nothing else Just v in Just $ Map.differenceWith diff f1 f2 gpdDefaultFlags gpd = let tuples = map getDefault (C.genPackageFlags gpd) in Map.singleton (gpdPackageName gpd) (Map.fromList tuples) getDefault f | C.flagDefault f = (C.flagName f, True) | otherwise = (C.flagName f, False) -- | Find the set of @FlagName@s necessary to get the given -- @GenericPackageDescription@ to compile against the given @BuildPlan@. Will -- only modify non-manual flags, and will prefer default values for flags. -- Returns the plan which produces least number of dep errors selectPackageBuildPlan :: Platform -> ActualCompiler -> Map PackageName Version -> GenericPackageDescription -> (Map PackageName (Map FlagName Bool), DepErrors) selectPackageBuildPlan platform compiler pool gpd = (selectPlan . limitSearchSpace . NonEmpty.map makePlan) flagCombinations where selectPlan :: NonEmpty (a, DepErrors) -> (a, DepErrors) selectPlan = F.foldr1 fewerErrors where fewerErrors p1 p2 | nErrors p1 == 0 = p1 | nErrors p1 <= nErrors p2 = p1 | otherwise = p2 where nErrors = Map.size . snd -- Avoid exponential complexity in flag combinations making us sad pandas. -- See: https://github.com/commercialhaskell/stack/issues/543 limitSearchSpace :: NonEmpty a -> NonEmpty a limitSearchSpace (x :| xs) = x :| take (maxFlagCombinations - 1) xs where maxFlagCombinations = 128 makePlan :: [(FlagName, Bool)] -> (Map PackageName (Map FlagName Bool), DepErrors) makePlan flags = checkPackageBuildPlan platform compiler pool (Map.fromList flags) gpd flagCombinations :: NonEmpty [(FlagName, Bool)] flagCombinations = mapM getOptions (genPackageFlags gpd) where getOptions :: C.PackageFlag -> NonEmpty (FlagName, Bool) getOptions f | flagManual f = (fname, flagDefault f) :| [] | flagDefault f = (fname, True) :| [(fname, False)] | otherwise = (fname, False) :| [(fname, True)] where fname = flagName f -- | Check whether with the given set of flags a package's dependency -- constraints can be satisfied against a given build plan or pool of packages. checkPackageBuildPlan :: Platform -> ActualCompiler -> Map PackageName Version -> Map FlagName Bool -> GenericPackageDescription -> (Map PackageName (Map FlagName Bool), DepErrors) checkPackageBuildPlan platform compiler pool flags gpd = (Map.singleton pkg flags, errs) where pkg = gpdPackageName gpd errs = checkPackageDeps pkg constraints pool constraints = gpdPackageDeps gpd compiler platform flags -- | Checks if the given package dependencies can be satisfied by the given set -- of packages. Will fail if a package is either missing or has a version -- outside of the version range. checkPackageDeps :: PackageName -- ^ package using dependencies, for constructing DepErrors -> Map PackageName VersionRange -- ^ dependency constraints -> Map PackageName Version -- ^ Available package pool or index -> DepErrors checkPackageDeps myName deps packages = Map.unionsWith combineDepError $ map go $ Map.toList deps where go :: (PackageName, VersionRange) -> DepErrors go (name, range) = case Map.lookup name packages of Nothing -> Map.singleton name DepError { deVersion = Nothing , deNeededBy = Map.singleton myName range } Just v | withinRange v range -> Map.empty | otherwise -> Map.singleton name DepError { deVersion = Just v , deNeededBy = Map.singleton myName range } type DepErrors = Map PackageName DepError data DepError = DepError { deVersion :: !(Maybe Version) , deNeededBy :: !(Map PackageName VersionRange) } deriving Show -- | Combine two 'DepError's for the same 'Version'. combineDepError :: DepError -> DepError -> DepError combineDepError (DepError a x) (DepError b y) = assert (a == b) $ DepError a (Map.unionWith C.intersectVersionRanges x y) -- | Given a bundle of packages (a list of @GenericPackageDescriptions@'s) to -- build and an available package pool (snapshot) check whether the bundle's -- dependencies can be satisfied. If flags is passed as Nothing flag settings -- will be chosen automatically. checkBundleBuildPlan :: Platform -> ActualCompiler -> Map PackageName Version -> Maybe (Map PackageName (Map FlagName Bool)) -> [GenericPackageDescription] -> (Map PackageName (Map FlagName Bool), DepErrors) checkBundleBuildPlan platform compiler pool flags gpds = (Map.unionsWith dupError (map fst plans) , Map.unionsWith combineDepError (map snd plans)) where plans = map (pkgPlan flags) gpds pkgPlan Nothing gpd = selectPackageBuildPlan platform compiler pool' gpd pkgPlan (Just f) gpd = checkPackageBuildPlan platform compiler pool' (flags' f gpd) gpd flags' f gpd = fromMaybe Map.empty (Map.lookup (gpdPackageName gpd) f) pool' = Map.union (gpdPackages gpds) pool dupError _ _ = impureThrow DuplicatePackagesBug data BuildPlanCheck = BuildPlanCheckOk (Map PackageName (Map FlagName Bool)) | BuildPlanCheckPartial (Map PackageName (Map FlagName Bool)) DepErrors | BuildPlanCheckFail (Map PackageName (Map FlagName Bool)) DepErrors ActualCompiler -- | Compare 'BuildPlanCheck', where GT means a better plan. compareBuildPlanCheck :: BuildPlanCheck -> BuildPlanCheck -> Ordering compareBuildPlanCheck (BuildPlanCheckPartial _ e1) (BuildPlanCheckPartial _ e2) = -- Note: order of comparison flipped, since it's better to have fewer errors. compare (Map.size e2) (Map.size e1) compareBuildPlanCheck (BuildPlanCheckFail _ e1 _) (BuildPlanCheckFail _ e2 _) = let numUserPkgs e = Map.size $ Map.unions (Map.elems (fmap deNeededBy e)) in compare (numUserPkgs e2) (numUserPkgs e1) compareBuildPlanCheck BuildPlanCheckOk{} BuildPlanCheckOk{} = EQ compareBuildPlanCheck BuildPlanCheckOk{} BuildPlanCheckPartial{} = GT compareBuildPlanCheck BuildPlanCheckOk{} BuildPlanCheckFail{} = GT compareBuildPlanCheck BuildPlanCheckPartial{} BuildPlanCheckFail{} = GT compareBuildPlanCheck _ _ = LT instance Show BuildPlanCheck where show BuildPlanCheckOk {} = "" show (BuildPlanCheckPartial f e) = T.unpack $ showDepErrors f e show (BuildPlanCheckFail f e c) = T.unpack $ showCompilerErrors f e c -- | Check a set of 'GenericPackageDescription's and a set of flags against a -- given snapshot. Returns how well the snapshot satisfies the dependencies of -- the packages. checkSnapBuildPlan :: (HasConfig env, HasGHCVariant env) => [ResolvedPath Dir] -> Maybe (Map PackageName (Map FlagName Bool)) -> SnapshotCandidate env -> RIO env BuildPlanCheck checkSnapBuildPlan pkgDirs flags snapCandidate = do platform <- view platformL sma <- snapCandidate pkgDirs gpds <- liftIO $ forM (Map.elems $ smaProject sma) (cpGPD . ppCommon) let compiler = smaCompiler sma globalVersion (GlobalPackageVersion v) = v depVersion dep | PLImmutable loc <- dpLocation dep = Just $ packageLocationVersion loc | otherwise = Nothing snapPkgs = Map.union (Map.mapMaybe depVersion $ smaDeps sma) (Map.map globalVersion $ smaGlobal sma) (f, errs) = checkBundleBuildPlan platform compiler snapPkgs flags gpds cerrs = compilerErrors compiler errs if Map.null errs then pure $ BuildPlanCheckOk f else if Map.null cerrs then do pure $ BuildPlanCheckPartial f errs else pure $ BuildPlanCheckFail f cerrs compiler where compilerErrors compiler errs | whichCompiler compiler == Ghc = ghcErrors errs | otherwise = Map.empty isGhcWiredIn p _ = p `Set.member` wiredInPackages ghcErrors = Map.filterWithKey isGhcWiredIn -- | Find a snapshot and set of flags that is compatible with and matches as -- best as possible with the given 'GenericPackageDescription's. selectBestSnapshot :: (HasConfig env, HasGHCVariant env) => [ResolvedPath Dir] -> NonEmpty SnapName -> RIO env (SnapshotCandidate env, RawSnapshotLocation, BuildPlanCheck) selectBestSnapshot pkgDirs snaps = do prettyInfo $ fillSep [ flow "Selecting the best among" , fromString $ show (NonEmpty.length snaps) , "snapshots..." ] <> line F.foldr1 go (NonEmpty.map (getResult <=< snapshotLocation) snaps) where go mold mnew = do old@(_snap, _loc, bpc) <- mold case bpc of BuildPlanCheckOk {} -> pure old _ -> fmap (betterSnap old) mnew getResult loc = do candidate <- loadProjectSnapshotCandidate loc NoPrintWarnings False result <- checkSnapBuildPlan pkgDirs Nothing candidate reportResult result loc pure (candidate, loc, result) betterSnap (s1, l1, r1) (s2, l2, r2) | compareBuildPlanCheck r1 r2 /= LT = (s1, l1, r1) | otherwise = (s2, l2, r2) reportResult BuildPlanCheckOk {} loc = prettyNote $ fillSep [ flow "Matches" , pretty $ PrettyRawSnapshotLocation loc ] <> line reportResult r@BuildPlanCheckPartial {} loc = prettyWarn $ fillSep [ flow "Partially matches" , pretty $ PrettyRawSnapshotLocation loc ] <> blankLine <> indent 4 (string (show r)) reportResult r@BuildPlanCheckFail {} loc = prettyWarn $ fillSep [ flow "Rejected" , pretty $ PrettyRawSnapshotLocation loc ] <> blankLine <> indent 4 (string (show r)) showItems :: [String] -> Text showItems items = T.concat (map formatItem items) where formatItem item = T.concat [ " - " , T.pack item , "\n" ] showPackageFlags :: PackageName -> Map FlagName Bool -> Text showPackageFlags pkg fl = if not $ Map.null fl then T.concat [ " - " , T.pack $ packageNameString pkg , ": " , T.pack $ intercalate ", " $ map formatFlags (Map.toList fl) , "\n" ] else "" where formatFlags (f, v) = show f ++ " = " ++ show v showMapPackages :: Map PackageName a -> Text showMapPackages mp = showItems $ map packageNameString $ Map.keys mp showCompilerErrors :: Map PackageName (Map FlagName Bool) -> DepErrors -> ActualCompiler -> Text showCompilerErrors flags errs compiler = T.concat [ compilerVersionText compiler , " cannot be used for these packages:\n" , showMapPackages $ Map.unions (Map.elems (fmap deNeededBy errs)) , showDepErrors flags errs -- TODO only in debug mode ] showDepErrors :: Map PackageName (Map FlagName Bool) -> DepErrors -> Text showDepErrors flags errs = T.concat [ T.concat $ map formatError (Map.toList errs) , if T.null flagVals then "" else "Using package flags:\n" <> flagVals ] where formatError (depName, DepError mversion neededBy) = T.concat [ showDepVersion depName mversion , T.concat (map showRequirement (Map.toList neededBy)) ] showDepVersion depName mversion = T.concat [ T.pack $ packageNameString depName , case mversion of Nothing -> " not found" Just version -> T.concat [ " version " , T.pack $ versionString version , " found" ] , "\n" ] showRequirement (user, range) = T.concat [ " - " , T.pack $ packageNameString user , " requires " , T.pack $ display range , "\n" ] flagVals = T.concat (map showFlags userPkgs) userPkgs = Map.keys $ Map.unions (Map.elems (fmap deNeededBy errs)) showFlags pkg = maybe "" (showPackageFlags pkg) (Map.lookup pkg flags) stack-2.9.3.1/src/Stack/Clean.hs0000644000000000000000000000674214445022466014411 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} -- | Clean a project. module Stack.Clean ( clean , CleanOpts (..) , CleanCommand (..) ) where import Data.List ( (\\), intercalate ) import qualified Data.Map.Strict as Map import Path.IO ( ignoringAbsence, removeDirRecur ) import Stack.Config ( withBuildConfig ) import Stack.Constants.Config ( rootDistDirFromDir, workDirFromDir ) import Stack.Prelude import Stack.Types.Config import Stack.Types.SourceMap -- | Type representing exceptions thrown by functions exported by the -- "Stack.Clean" module. data CleanException = NonLocalPackages [PackageName] | DeletionFailures [(Path Abs Dir, SomeException)] deriving (Show, Typeable) instance Exception CleanException where displayException (NonLocalPackages pkgs) = concat [ "Error: [S-9463]\n" , "The following packages are not part of this project: " , intercalate ", " (map show pkgs) ] displayException (DeletionFailures failures) = concat [ "Error: [S-6321]\n" , "Exception while recursively deleting:\n" , concatMap (\(dir, e) -> toFilePath dir <> "\n" <> displayException e <> "\n") failures , "Perhaps you do not have permission to delete these files or they \ \are in use?" ] -- | Deletes build artifacts in the current project. clean :: CleanOpts -> RIO Config () clean cleanOpts = do toDelete <- withBuildConfig $ dirsToDelete cleanOpts logDebug $ "Need to delete: " <> fromString (show (map toFilePath toDelete)) failures <- catMaybes <$> mapM cleanDir toDelete case failures of [] -> pure () _ -> throwIO $ DeletionFailures failures cleanDir :: Path Abs Dir -> RIO Config (Maybe (Path Abs Dir, SomeException)) cleanDir dir = do logDebug $ "Deleting directory: " <> fromString (toFilePath dir) liftIO (ignoringAbsence (removeDirRecur dir) >> pure Nothing) `catchAny` \ex -> pure $ Just (dir, ex) dirsToDelete :: CleanOpts -> RIO BuildConfig [Path Abs Dir] dirsToDelete cleanOpts = do packages <- view $ buildConfigL.to (smwProject . bcSMWanted) case cleanOpts of CleanShallow [] -> -- Filter out packages listed as extra-deps mapM (rootDistDirFromDir . ppRoot) $ Map.elems packages CleanShallow targets -> do let localPkgNames = Map.keys packages getPkgDir pkgName' = fmap ppRoot (Map.lookup pkgName' packages) case targets \\ localPkgNames of [] -> mapM rootDistDirFromDir (mapMaybe getPkgDir targets) xs -> throwM (NonLocalPackages xs) CleanFull -> do pkgWorkDirs <- mapM (workDirFromDir . ppRoot) $ Map.elems packages projectWorkDir <- getProjectWorkDir pure (projectWorkDir : pkgWorkDirs) -- | Options for @stack clean@. data CleanOpts = CleanShallow [PackageName] -- ^ Delete the "dist directories" as defined in 'Stack.Constants.Config.distRelativeDir' -- for the given local packages. If no packages are given, all project packages -- should be cleaned. | CleanFull -- ^ Delete all work directories in the project. -- | Clean commands data CleanCommand = Clean | Purge stack-2.9.3.1/src/Stack/Config.hs0000644000000000000000000013040014445113031014546 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} -- | The general Stack configuration that starts everything off. This should -- be smart to fallback if there is no stack.yaml, instead relying on -- whatever files are available. -- -- If there is no stack.yaml, and there is a cabal.config, we -- read in those constraints, and if there's a cabal.sandbox.config, -- we read any constraints from there and also find the package -- database from there, etc. And if there's nothing, we should -- probably default to behaving like cabal, possibly with spitting out -- a warning that "you should run `stk init` to make things better". module Stack.Config ( loadConfig , loadConfigYaml , packagesParser , getImplicitGlobalProjectDir , getSnapshots , makeConcreteResolver , checkOwnership , getInContainer , getInNixShell , defaultConfigYaml , getProjectConfig , withBuildConfig , withNewLogFunc ) where import Control.Monad.Extra ( firstJustM ) import Data.Array.IArray ( (!), (//) ) import qualified Data.ByteString as S import Data.ByteString.Builder ( byteString ) import Data.Coerce ( coerce ) import qualified Data.IntMap as IntMap import qualified Data.Map as Map import qualified Data.Map.Merge.Strict as MS import qualified Data.Monoid import Data.Monoid.Map ( MonoidMap (..) ) import qualified Data.Text as T import qualified Data.Yaml as Yaml import Distribution.System ( Arch (OtherArch), OS (..), Platform (..), buildPlatform ) import qualified Distribution.Text import Distribution.Version ( simplifyVersionRange ) import GHC.Conc ( getNumProcessors ) import Network.HTTP.StackClient ( httpJSON, parseUrlThrow, getResponseBody ) import Options.Applicative ( Parser, help, long, metavar, strOption ) import Pantry.Internal.AesonExtended import Path import Path.Extra ( toFilePathNoTrailingSep ) import Path.Find ( findInParents ) import Path.IO import RIO.List ( unzip ) import RIO.Process import RIO.Time ( toGregorian ) import Stack.Build.Haddock ( shouldHaddockDeps ) import Stack.Config.Build import Stack.Config.Docker import Stack.Config.Nix import Stack.Constants import Stack.Lock ( lockCachedWanted ) import Stack.Prelude import Stack.SourceMap import Stack.Storage.Project ( initProjectStorage ) import Stack.Storage.User ( initUserStorage ) import Stack.Storage.Util ( handleMigrationException ) import Stack.Types.Build import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.Docker import Stack.Types.Nix import Stack.Types.Resolver import Stack.Types.SourceMap import Stack.Types.Version ( IntersectingVersionRange (..), VersionCheck (..) , stackVersion, withinRange ) import System.Console.ANSI ( hSupportsANSIWithoutEmulation, setSGRCode ) import System.Environment import System.Info.ShortPathName ( getShortPathName ) import System.PosixCompat.Files ( fileOwner, getFileStatus ) import System.Posix.User ( getEffectiveUserID ) -- | If deprecated path exists, use it and print a warning. -- Otherwise, return the new path. tryDeprecatedPath :: HasLogFunc env => Maybe T.Text -- ^ Description of file for warning (if Nothing, no deprecation warning is displayed) -> (Path Abs a -> RIO env Bool) -- ^ Test for existence -> Path Abs a -- ^ New path -> Path Abs a -- ^ Deprecated path -> RIO env (Path Abs a, Bool) -- ^ (Path to use, whether it already exists) tryDeprecatedPath mWarningDesc exists new old = do newExists <- exists new if newExists then pure (new, True) else do oldExists <- exists old if oldExists then do case mWarningDesc of Nothing -> pure () Just desc -> logWarn $ "Warning: Location of " <> display desc <> " at '" <> fromString (toFilePath old) <> "' is deprecated; rename it to '" <> fromString (toFilePath new) <> "' instead" pure (old, True) else pure (new, False) -- | Get the location of the implicit global project directory. -- If the directory already exists at the deprecated location, its location is returned. -- Otherwise, the new location is returned. getImplicitGlobalProjectDir :: HasLogFunc env => Config -> RIO env (Path Abs Dir) getImplicitGlobalProjectDir config = --TEST no warning printed liftM fst $ tryDeprecatedPath Nothing doesDirExist (implicitGlobalProjectDir stackRoot) (implicitGlobalProjectDirDeprecated stackRoot) where stackRoot = view stackRootL config -- | Download the 'Snapshots' value from stackage.org. getSnapshots :: HasConfig env => RIO env Snapshots getSnapshots = do latestUrlText <- askLatestSnapshotUrl latestUrl <- parseUrlThrow (T.unpack latestUrlText) logDebug $ "Downloading snapshot versions file from " <> display latestUrlText result <- httpJSON latestUrl logDebug "Done downloading and parsing snapshot versions file" pure $ getResponseBody result -- | Turn an 'AbstractResolver' into a 'Resolver'. makeConcreteResolver :: HasConfig env => AbstractResolver -> RIO env RawSnapshotLocation makeConcreteResolver (ARResolver r) = pure r makeConcreteResolver ar = do r <- case ar of ARGlobal -> do config <- view configL implicitGlobalDir <- getImplicitGlobalProjectDir config let fp = implicitGlobalDir stackDotYaml iopc <- loadConfigYaml (parseProjectAndConfigMonoid (parent fp)) fp ProjectAndConfigMonoid project _ <- liftIO iopc pure $ projectResolver project ARLatestNightly -> RSLSynonym . Nightly . snapshotsNightly <$> getSnapshots ARLatestLTSMajor x -> do snapshots <- getSnapshots case IntMap.lookup x $ snapshotsLts snapshots of Nothing -> throwIO $ NoLTSWithMajorVersion x Just y -> pure $ RSLSynonym $ LTS x y ARLatestLTS -> do snapshots <- getSnapshots if IntMap.null $ snapshotsLts snapshots then throwIO NoLTSFound else let (x, y) = IntMap.findMax $ snapshotsLts snapshots in pure $ RSLSynonym $ LTS x y logInfo $ "Selected resolver: " <> display r pure r -- | Get the latest snapshot resolver available. getLatestResolver :: HasConfig env => RIO env RawSnapshotLocation getLatestResolver = do snapshots <- getSnapshots let mlts = uncurry LTS <$> listToMaybe (reverse (IntMap.toList (snapshotsLts snapshots))) pure $ RSLSynonym $ fromMaybe (Nightly (snapshotsNightly snapshots)) mlts -- Interprets ConfigMonoid options. configFromConfigMonoid :: HasRunner env => Path Abs Dir -- ^ Stack root, e.g. ~/.stack -> Path Abs File -- ^ user config file path, e.g. ~/.stack/config.yaml -> Maybe AbstractResolver -> ProjectConfig (Project, Path Abs File) -> ConfigMonoid -> (Config -> RIO env a) -> RIO env a configFromConfigMonoid configStackRoot configUserConfigPath configResolver configProject ConfigMonoid{..} inner = do -- If --stack-work is passed, prefer it. Otherwise, if STACK_WORK -- is set, use that. If neither, use the default ".stack-work" mstackWorkEnv <- liftIO $ lookupEnv stackWorkEnvVar let mproject = case configProject of PCProject pair -> Just pair PCGlobalProject -> Nothing PCNoProject _deps -> Nothing configAllowLocals = case configProject of PCProject _ -> True PCGlobalProject -> True PCNoProject _ -> False configWorkDir0 <- maybe (pure relDirStackWork) (liftIO . parseRelDir) mstackWorkEnv let configWorkDir = fromFirst configWorkDir0 configMonoidWorkDir configLatestSnapshot = fromFirst "https://s3.amazonaws.com/haddock.stackage.org/snapshots.json" configMonoidLatestSnapshot clConnectionCount = fromFirst 8 configMonoidConnectionCount configHideTHLoading = fromFirstTrue configMonoidHideTHLoading configPrefixTimestamps = fromFirst False configMonoidPrefixTimestamps configGHCVariant = getFirst configMonoidGHCVariant configCompilerRepository = fromFirst defaultCompilerRepository configMonoidCompilerRepository configGHCBuild = getFirst configMonoidGHCBuild configInstallGHC = fromFirstTrue configMonoidInstallGHC configSkipGHCCheck = fromFirstFalse configMonoidSkipGHCCheck configSkipMsys = fromFirstFalse configMonoidSkipMsys configExtraIncludeDirs = configMonoidExtraIncludeDirs configExtraLibDirs = configMonoidExtraLibDirs configCustomPreprocessorExts = configMonoidCustomPreprocessorExts configOverrideGccPath = getFirst configMonoidOverrideGccPath -- Only place in the codebase where platform is hard-coded. In theory -- in the future, allow it to be configured. (Platform defArch defOS) = buildPlatform arch = fromMaybe defArch $ getFirst configMonoidArch >>= Distribution.Text.simpleParse os = defOS configPlatform = Platform arch os configRequireStackVersion = simplifyVersionRange (getIntersectingVersionRange configMonoidRequireStackVersion) configCompilerCheck = fromFirst MatchMinor configMonoidCompilerCheck case arch of OtherArch "aarch64" -> pure () OtherArch unk -> logWarn $ "Warning: Unknown value for architecture setting: " <> displayShow unk _ -> pure () configPlatformVariant <- liftIO $ maybe PlatformVariantNone PlatformVariant <$> lookupEnv platformVariantEnvVar let configBuild = buildOptsFromMonoid configMonoidBuildOpts configDocker <- dockerOptsFromMonoid (fmap fst mproject) configResolver configMonoidDockerOpts configNix <- nixOptsFromMonoid configMonoidNixOpts os configSystemGHC <- case (getFirst configMonoidSystemGHC, nixEnable configNix) of (Just False, True) -> throwM NixRequiresSystemGhc _ -> pure (fromFirst (dockerEnable configDocker || nixEnable configNix) configMonoidSystemGHC) when (isJust configGHCVariant && configSystemGHC) $ throwM ManualGHCVariantSettingsAreIncompatibleWithSystemGHC rawEnv <- liftIO getEnvironment pathsEnv <- either throwM pure $ augmentPathMap (map toFilePath configMonoidExtraPath) (Map.fromList (map (T.pack *** T.pack) rawEnv)) origEnv <- mkProcessContext pathsEnv let configProcessContextSettings _ = pure origEnv configLocalProgramsBase <- case getFirst configMonoidLocalProgramsBase of Nothing -> getDefaultLocalProgramsBase configStackRoot configPlatform origEnv Just path -> pure path let localProgramsFilePath = toFilePath configLocalProgramsBase when (osIsWindows && ' ' `elem` localProgramsFilePath) $ do ensureDir configLocalProgramsBase -- getShortPathName returns the long path name when a short name does not -- exist. shortLocalProgramsFilePath <- liftIO $ getShortPathName localProgramsFilePath when (' ' `elem` shortLocalProgramsFilePath) $ do logError $ "Error: [S-8432]\n"<> "Stack's 'programs' path contains a space character and has no " <> "alternative short ('8 dot 3') name. This will cause problems " <> "with packages that use the GNU project's 'configure' shell " <> "script. Use the 'local-programs-path' configuration option to " <> "specify an alternative path. The current path is: " <> display (T.pack localProgramsFilePath) platformOnlyDir <- runReaderT platformOnlyRelDir (configPlatform, configPlatformVariant) let configLocalPrograms = configLocalProgramsBase platformOnlyDir configLocalBin <- case getFirst configMonoidLocalBinPath of Nothing -> do localDir <- getAppUserDataDir "local" pure $ localDir relDirBin Just userPath -> (case mproject of -- Not in a project Nothing -> resolveDir' userPath -- Resolves to the project dir and appends the user path if it is relative Just (_, configYaml) -> resolveDir (parent configYaml) userPath) -- TODO: Either catch specific exceptions or add a -- parseRelAsAbsDirMaybe utility and use it along with -- resolveDirMaybe. `catchAny` const (throwIO (NoSuchDirectory userPath)) configJobs <- case getFirst configMonoidJobs of Nothing -> liftIO getNumProcessors Just i -> pure i let configConcurrentTests = fromFirst True configMonoidConcurrentTests let configTemplateParams = configMonoidTemplateParameters configScmInit = getFirst configMonoidScmInit configCabalConfigOpts = coerce configMonoidCabalConfigOpts configGhcOptionsByName = coerce configMonoidGhcOptionsByName configGhcOptionsByCat = coerce configMonoidGhcOptionsByCat configSetupInfoLocations = configMonoidSetupInfoLocations configSetupInfoInline = configMonoidSetupInfoInline configPvpBounds = fromFirst (PvpBounds PvpBoundsNone False) configMonoidPvpBounds configModifyCodePage = fromFirstTrue configMonoidModifyCodePage configRebuildGhcOptions = fromFirstFalse configMonoidRebuildGhcOptions configApplyGhcOptions = fromFirst AGOLocals configMonoidApplyGhcOptions configAllowNewer = fromFirst False configMonoidAllowNewer configAllowNewerDeps = coerce configMonoidAllowNewerDeps configDefaultTemplate = getFirst configMonoidDefaultTemplate configDumpLogs = fromFirst DumpWarningLogs configMonoidDumpLogs configSaveHackageCreds = fromFirst True configMonoidSaveHackageCreds configHackageBaseUrl = fromFirst "https://hackage.haskell.org/" configMonoidHackageBaseUrl configHideSourcePaths = fromFirstTrue configMonoidHideSourcePaths configRecommendUpgrade = fromFirstTrue configMonoidRecommendUpgrade configNoRunCompile = fromFirstFalse configMonoidNoRunCompile configAllowDifferentUser <- case getFirst configMonoidAllowDifferentUser of Just True -> pure True _ -> getInContainer configRunner' <- view runnerL useAnsi <- liftIO $ fromMaybe True <$> hSupportsANSIWithoutEmulation stderr let stylesUpdate' = (configRunner' ^. stylesUpdateL) <> configMonoidStyles useColor' = runnerUseColor configRunner' mUseColor = do colorWhen <- getFirst configMonoidColorWhen pure $ case colorWhen of ColorNever -> False ColorAlways -> True ColorAuto -> useAnsi useColor'' = fromMaybe useColor' mUseColor configRunner'' = configRunner' & processContextL .~ origEnv & stylesUpdateL .~ stylesUpdate' & useColorL .~ useColor'' go = runnerGlobalOpts configRunner' pic <- case getFirst configMonoidPackageIndex of Nothing -> case getFirst configMonoidPackageIndices of Nothing -> pure defaultPackageIndexConfig Just [pic] -> do logWarn $ fromString packageIndicesWarning pure pic Just x -> throwIO $ MultiplePackageIndices x Just pic -> pure pic mpantryRoot <- liftIO $ lookupEnv pantryRootEnvVar pantryRoot <- case mpantryRoot of Just dir -> case parseAbsDir dir of Nothing -> throwIO $ ParseAbsolutePathException pantryRootEnvVar dir Just x -> pure x Nothing -> pure $ configStackRoot relDirPantry let snapLoc = case getFirst configMonoidSnapshotLocation of Nothing -> defaultSnapshotLocation Just addr -> customSnapshotLocation where customSnapshotLocation (LTS x y) = mkRSLUrl $ addr' <> "/lts/" <> display x <> "/" <> display y <> ".yaml" customSnapshotLocation (Nightly date) = let (year, month, day) = toGregorian date in mkRSLUrl $ addr' <> "/nightly/" <> display year <> "/" <> display month <> "/" <> display day <> ".yaml" mkRSLUrl builder = RSLUrl (utf8BuilderToText builder) Nothing addr' = display $ T.dropWhileEnd (=='/') addr let configStackDeveloperMode = fromFirst stackDeveloperModeDefault configMonoidStackDeveloperMode withNewLogFunc go useColor'' stylesUpdate' $ \logFunc -> do let configRunner = configRunner'' & logFuncL .~ logFunc withLocalLogFunc logFunc $ handleMigrationException $ withPantryConfig pantryRoot pic (maybe HpackBundled HpackCommand $ getFirst configMonoidOverrideHpack) clConnectionCount (fromFirst defaultCasaRepoPrefix configMonoidCasaRepoPrefix) defaultCasaMaxPerRequest snapLoc (\configPantryConfig -> initUserStorage (configStackRoot relFileStorage) (\configUserStorage -> inner Config {..})) -- | Runs the provided action with the given 'LogFunc' in the environment withLocalLogFunc :: HasLogFunc env => LogFunc -> RIO env a -> RIO env a withLocalLogFunc logFunc = local (set logFuncL logFunc) -- | Runs the provided action with a new 'LogFunc', given a 'StylesUpdate'. withNewLogFunc :: MonadUnliftIO m => GlobalOpts -> Bool -- ^ Use color -> StylesUpdate -> (LogFunc -> m a) -> m a withNewLogFunc go useColor (StylesUpdate update) inner = do logOptions0 <- logOptionsHandle stderr False let logOptions = setLogUseColor useColor $ setLogLevelColors logLevelColors $ setLogSecondaryColor secondaryColor $ setLogAccentColors (const highlightColor) $ setLogUseTime (globalTimeInLog go) $ setLogMinLevel (globalLogLevel go) $ setLogVerboseFormat (globalLogLevel go <= LevelDebug) $ setLogTerminal (globalTerminal go) logOptions0 withLogFunc logOptions inner where styles = defaultStyles // update logLevelColors :: LogLevel -> Utf8Builder logLevelColors level = fromString $ setSGRCode $ snd $ styles ! logLevelToStyle level secondaryColor = fromString $ setSGRCode $ snd $ styles ! Secondary highlightColor = fromString $ setSGRCode $ snd $ styles ! Highlight -- | Get the default location of the local programs directory. getDefaultLocalProgramsBase :: MonadThrow m => Path Abs Dir -> Platform -> ProcessContext -> m (Path Abs Dir) getDefaultLocalProgramsBase configStackRoot configPlatform override = case configPlatform of -- For historical reasons, on Windows a subdirectory of LOCALAPPDATA is -- used instead of a subdirectory of STACK_ROOT. Unifying the defaults would -- mean that Windows users would manually have to move data from the old -- location to the new one, which is undesirable. Platform _ Windows -> do let envVars = view envVarsL override case T.unpack <$> Map.lookup "LOCALAPPDATA" envVars of Just t -> case parseAbsDir t of Nothing -> throwM $ ParseAbsolutePathException "LOCALAPPDATA" t Just lad -> pure $ lad relDirUpperPrograms relDirStackProgName Nothing -> pure defaultBase _ -> pure defaultBase where defaultBase = configStackRoot relDirPrograms -- | Load the configuration, using current directory, environment variables, -- and defaults as necessary. loadConfig :: HasRunner env => (Config -> RIO env a) -> RIO env a loadConfig inner = do mstackYaml <- view $ globalOptsL.to globalStackYaml mproject <- loadProjectConfig mstackYaml mresolver <- view $ globalOptsL.to globalResolver configArgs <- view $ globalOptsL.to globalConfigMonoid (configRoot, stackRoot, userOwnsStackRoot) <- determineStackRootAndOwnership configArgs let (mproject', addConfigMonoid) = case mproject of PCProject (proj, fp, cm) -> (PCProject (proj, fp), (cm:)) PCGlobalProject -> (PCGlobalProject, id) PCNoProject deps -> (PCNoProject deps, id) userConfigPath <- getDefaultUserConfigPath configRoot extraConfigs0 <- getExtraConfigs userConfigPath >>= mapM (\file -> loadConfigYaml (parseConfigMonoid (parent file)) file) let extraConfigs = -- non-project config files' existence of a docker section should never default docker -- to enabled, so make it look like they didn't exist map (\c -> c {configMonoidDockerOpts = (configMonoidDockerOpts c) {dockerMonoidDefaultEnable = Any False}}) extraConfigs0 let withConfig = configFromConfigMonoid stackRoot userConfigPath mresolver mproject' (mconcat $ configArgs : addConfigMonoid extraConfigs) withConfig $ \config -> do unless (stackVersion `withinRange` configRequireStackVersion config) (throwM (BadStackVersionException (configRequireStackVersion config))) unless (configAllowDifferentUser config) $ do unless userOwnsStackRoot $ throwM (UserDoesn'tOwnDirectory stackRoot) forM_ (configProjectRoot config) $ \dir -> checkOwnership (dir configWorkDir config) inner config -- | Load the build configuration, adds build-specific values to config loaded by @loadConfig@. -- values. withBuildConfig :: RIO BuildConfig a -> RIO Config a withBuildConfig inner = do config <- ask -- If provided, turn the AbstractResolver from the command line -- into a Resolver that can be used below. -- The configResolver and mcompiler are provided on the command -- line. In order to properly deal with an AbstractResolver, we -- need a base directory (to deal with custom snapshot relative -- paths). We consider the current working directory to be the -- correct base. Let's calculate the mresolver first. mresolver <- forM (configResolver config) $ \aresolver -> do logDebug ("Using resolver: " <> display aresolver <> " specified on command line") makeConcreteResolver aresolver (project', stackYamlFP) <- case configProject config of PCProject (project, fp) -> do forM_ (projectUserMsg project) (logWarn . fromString) pure (project, fp) PCNoProject extraDeps -> do p <- case mresolver of Nothing -> throwIO NoResolverWhenUsingNoProject Just _ -> getEmptyProject mresolver extraDeps pure (p, configUserConfigPath config) PCGlobalProject -> do logDebug "Run from outside a project, using implicit global project config" destDir <- getImplicitGlobalProjectDir config let dest :: Path Abs File dest = destDir stackDotYaml dest' :: FilePath dest' = toFilePath dest ensureDir destDir exists <- doesFileExist dest if exists then do iopc <- loadConfigYaml (parseProjectAndConfigMonoid destDir) dest ProjectAndConfigMonoid project _ <- liftIO iopc when (view terminalL config) $ case configResolver config of Nothing -> logDebug $ "Using resolver: " <> display (projectResolver project) <> " from implicit global project's config file: " <> fromString dest' Just _ -> pure () pure (project, dest) else do logInfo ("Writing implicit global project config file to: " <> fromString dest') logInfo "Note: You can change the snapshot via the resolver field there." p <- getEmptyProject mresolver [] liftIO $ do writeBinaryFileAtomic dest $ byteString $ S.concat [ "# This is the implicit global project's config file, which is only used when\n" , "# 'stack' is run outside of a real project. Settings here do _not_ act as\n" , "# defaults for all projects. To change Stack's default settings, edit\n" , "# '", encodeUtf8 (T.pack $ toFilePath $ configUserConfigPath config), "' instead.\n" , "#\n" , "# For more information about Stack's configuration, see\n" , "# http://docs.haskellstack.org/en/stable/yaml_configuration/\n" , "#\n" , Yaml.encode p] writeBinaryFileAtomic (parent dest relFileReadmeTxt) $ "This is the implicit global project, which is " <> "used only when 'stack' is run\noutside of a " <> "real project.\n" pure (p, dest) mcompiler <- view $ globalOptsL.to globalCompiler let project = project' { projectCompiler = mcompiler <|> projectCompiler project' , projectResolver = fromMaybe (projectResolver project') mresolver } extraPackageDBs <- mapM resolveDir' (projectExtraPackageDBs project) wanted <- lockCachedWanted stackYamlFP (projectResolver project) $ fillProjectWanted stackYamlFP config project -- Unfortunately redoes getProjectWorkDir, since we don't have a BuildConfig yet workDir <- view workDirL let projectStorageFile = parent stackYamlFP workDir relFileStorage initProjectStorage projectStorageFile $ \projectStorage -> do let bc = BuildConfig { bcConfig = config , bcSMWanted = wanted , bcExtraPackageDBs = extraPackageDBs , bcStackYaml = stackYamlFP , bcCurator = projectCurator project , bcProjectStorage = projectStorage } runRIO bc inner where getEmptyProject :: Maybe RawSnapshotLocation -> [PackageIdentifierRevision] -> RIO Config Project getEmptyProject mresolver extraDeps = do r <- case mresolver of Just resolver -> do logInfo ("Using resolver: " <> display resolver <> " specified on command line") pure resolver Nothing -> do r'' <- getLatestResolver logInfo ("Using latest snapshot resolver: " <> display r'') pure r'' pure Project { projectUserMsg = Nothing , projectPackages = [] , projectDependencies = map (RPLImmutable . flip RPLIHackage Nothing) extraDeps , projectFlags = mempty , projectResolver = r , projectCompiler = Nothing , projectExtraPackageDBs = [] , projectCurator = Nothing , projectDropPackages = mempty } fillProjectWanted :: (HasProcessContext env, HasLogFunc env, HasPantryConfig env) => Path Abs t -> Config -> Project -> Map RawPackageLocationImmutable PackageLocationImmutable -> WantedCompiler -> Map PackageName (Bool -> RIO env DepPackage) -> RIO env (SMWanted, [CompletedPLI]) fillProjectWanted stackYamlFP config project locCache snapCompiler snapPackages = do let bopts = configBuild config packages0 <- for (projectPackages project) $ \fp@(RelFilePath t) -> do abs' <- resolveDir (parent stackYamlFP) (T.unpack t) let resolved = ResolvedPath fp abs' pp <- mkProjectPackage YesPrintWarnings resolved (boptsHaddock bopts) pure (cpName $ ppCommon pp, pp) -- prefetch git repos to avoid cloning per subdirectory -- see https://github.com/commercialhaskell/stack/issues/5411 let gitRepos = mapMaybe (\case (RPLImmutable (RPLIRepo repo rpm)) -> Just (repo, rpm) _ -> Nothing) (projectDependencies project) logDebug ("Prefetching git repos: " <> display (T.pack (show gitRepos))) fetchReposRaw gitRepos (deps0, mcompleted) <- fmap unzip . forM (projectDependencies project) $ \rpl -> do (pl, mCompleted) <- case rpl of RPLImmutable rpli -> do (compl, mcompl) <- case Map.lookup rpli locCache of Just compl -> pure (compl, Just compl) Nothing -> do cpl <- completePackageLocation rpli if cplHasCabalFile cpl then pure (cplComplete cpl, Just $ cplComplete cpl) else do warnMissingCabalFile rpli pure (cplComplete cpl, Nothing) pure (PLImmutable compl, CompletedPLI rpli <$> mcompl) RPLMutable p -> pure (PLMutable p, Nothing) dp <- additionalDepPackage (shouldHaddockDeps bopts) pl pure ((cpName $ dpCommon dp, dp), mCompleted) checkDuplicateNames $ map (second (PLMutable . ppResolvedDir)) packages0 ++ map (second dpLocation) deps0 let packages1 = Map.fromList packages0 snPackages = snapPackages `Map.difference` packages1 `Map.difference` Map.fromList deps0 `Map.withoutKeys` projectDropPackages project snDeps <- for snPackages $ \getDep -> getDep (shouldHaddockDeps bopts) let deps1 = Map.fromList deps0 `Map.union` snDeps let mergeApply m1 m2 f = MS.merge MS.preserveMissing MS.dropMissing (MS.zipWithMatched f) m1 m2 pFlags = projectFlags project packages2 = mergeApply packages1 pFlags $ \_ p flags -> p{ppCommon=(ppCommon p){cpFlags=flags}} deps2 = mergeApply deps1 pFlags $ \_ d flags -> d{dpCommon=(dpCommon d){cpFlags=flags}} checkFlagsUsedThrowing pFlags FSStackYaml packages1 deps1 let pkgGhcOptions = configGhcOptionsByName config deps = mergeApply deps2 pkgGhcOptions $ \_ d options -> d{dpCommon=(dpCommon d){cpGhcOptions=options}} packages = mergeApply packages2 pkgGhcOptions $ \_ p options -> p{ppCommon=(ppCommon p){cpGhcOptions=options}} unusedPkgGhcOptions = pkgGhcOptions `Map.restrictKeys` Map.keysSet packages2 `Map.restrictKeys` Map.keysSet deps2 unless (Map.null unusedPkgGhcOptions) $ throwM $ InvalidGhcOptionsSpecification (Map.keys unusedPkgGhcOptions) let wanted = SMWanted { smwCompiler = fromMaybe snapCompiler (projectCompiler project) , smwProject = packages , smwDeps = deps , smwSnapshotLocation = projectResolver project } pure (wanted, catMaybes mcompleted) -- | Check if there are any duplicate package names and, if so, throw an -- exception. checkDuplicateNames :: MonadThrow m => [(PackageName, PackageLocation)] -> m () checkDuplicateNames locals = case filter hasMultiples $ Map.toList $ Map.fromListWith (++) $ map (second pure) locals of [] -> pure () x -> throwM $ DuplicateLocalPackageNames x where hasMultiples (_, _:_:_) = True hasMultiples _ = False -- | Get the Stack root, e.g. @~/.stack@, and determine whether the user owns it. -- -- On Windows, the second value is always 'True'. determineStackRootAndOwnership :: (MonadIO m) => ConfigMonoid -- ^ Parsed command-line arguments -> m (Path Abs Dir, Path Abs Dir, Bool) determineStackRootAndOwnership clArgs = liftIO $ do (configRoot, stackRoot) <- do case getFirst (configMonoidStackRoot clArgs) of Just x -> pure (x, x) Nothing -> do mstackRoot <- lookupEnv stackRootEnvVar case mstackRoot of Nothing -> do wantXdg <- fromMaybe "" <$> lookupEnv stackXdgEnvVar if not (null wantXdg) then do xdgRelDir <- parseRelDir stackProgName (,) <$> getXdgDir XdgConfig (Just xdgRelDir) <*> getXdgDir XdgData (Just xdgRelDir) else do oldStyleRoot <- getAppUserDataDir stackProgName pure (oldStyleRoot, oldStyleRoot) Just x -> case parseAbsDir x of Nothing -> throwIO $ ParseAbsolutePathException stackRootEnvVar x Just parsed -> pure (parsed, parsed) (existingStackRootOrParentDir, userOwnsIt) <- do mdirAndOwnership <- findInParents getDirAndOwnership stackRoot case mdirAndOwnership of Just x -> pure x Nothing -> throwIO (BadStackRoot stackRoot) when (existingStackRootOrParentDir /= stackRoot) $ if userOwnsIt then ensureDir stackRoot else throwIO $ Won'tCreateStackRootInDirectoryOwnedByDifferentUser stackRoot existingStackRootOrParentDir configRoot' <- canonicalizePath configRoot stackRoot' <- canonicalizePath stackRoot pure (configRoot', stackRoot', userOwnsIt) -- | @'checkOwnership' dir@ throws 'UserDoesn'tOwnDirectory' if @dir@ -- isn't owned by the current user. -- -- If @dir@ doesn't exist, its parent directory is checked instead. -- If the parent directory doesn't exist either, @'NoSuchDirectory' ('parent' dir)@ -- is thrown. checkOwnership :: (MonadIO m) => Path Abs Dir -> m () checkOwnership dir = do mdirAndOwnership <- firstJustM getDirAndOwnership [dir, parent dir] case mdirAndOwnership of Just (_, True) -> pure () Just (dir', False) -> throwIO (UserDoesn'tOwnDirectory dir') Nothing -> (throwIO . NoSuchDirectory) $ (toFilePathNoTrailingSep . parent) dir -- | @'getDirAndOwnership' dir@ returns @'Just' (dir, 'True')@ when @dir@ -- exists and the current user owns it in the sense of 'isOwnedByUser'. getDirAndOwnership :: (MonadIO m) => Path Abs Dir -> m (Maybe (Path Abs Dir, Bool)) getDirAndOwnership dir = liftIO $ forgivingAbsence $ do ownership <- isOwnedByUser dir pure (dir, ownership) -- | Check whether the current user (determined with 'getEffectiveUserId') is -- the owner for the given path. -- -- Will always pure 'True' on Windows. isOwnedByUser :: MonadIO m => Path Abs t -> m Bool isOwnedByUser path = liftIO $ do if osIsWindows then pure True else do fileStatus <- getFileStatus (toFilePath path) user <- getEffectiveUserID pure (user == fileOwner fileStatus) -- | 'True' if we are currently running inside a Docker container. getInContainer :: (MonadIO m) => m Bool getInContainer = liftIO (isJust <$> lookupEnv inContainerEnvVar) -- | 'True' if we are currently running inside a Nix. getInNixShell :: (MonadIO m) => m Bool getInNixShell = liftIO (isJust <$> lookupEnv inNixShellEnvVar) -- | Determine the extra config file locations which exist. -- -- Returns most local first getExtraConfigs :: HasLogFunc env => Path Abs File -- ^ use config path -> RIO env [Path Abs File] getExtraConfigs userConfigPath = do defaultStackGlobalConfigPath <- getDefaultGlobalConfigPath liftIO $ do env <- getEnvironment mstackConfig <- maybe (pure Nothing) (fmap Just . parseAbsFile) $ lookup "STACK_CONFIG" env mstackGlobalConfig <- maybe (pure Nothing) (fmap Just . parseAbsFile) $ lookup "STACK_GLOBAL_CONFIG" env filterM doesFileExist $ fromMaybe userConfigPath mstackConfig : maybe [] pure (mstackGlobalConfig <|> defaultStackGlobalConfigPath) -- | Load and parse YAML from the given config file. Throws -- 'ParseConfigFileException' when there's a decoding error. loadConfigYaml :: HasLogFunc env => (Value -> Yaml.Parser (WithJSONWarnings a)) -> Path Abs File -> RIO env a loadConfigYaml parser path = do eres <- loadYaml parser path case eres of Left err -> liftIO $ throwM $ PrettyException (ParseConfigFileException path err) Right res -> pure res -- | Load and parse YAML from the given file. loadYaml :: HasLogFunc env => (Value -> Yaml.Parser (WithJSONWarnings a)) -> Path Abs File -> RIO env (Either Yaml.ParseException a) loadYaml parser path = do eres <- liftIO $ Yaml.decodeFileEither (toFilePath path) case eres of Left err -> pure (Left err) Right val -> case Yaml.parseEither parser val of Left err -> pure (Left (Yaml.AesonException err)) Right (WithJSONWarnings res warnings) -> do logJSONWarnings (toFilePath path) warnings pure (Right res) -- | Get the location of the project config file, if it exists. getProjectConfig :: HasLogFunc env => StackYamlLoc -- ^ Override stack.yaml -> RIO env (ProjectConfig (Path Abs File)) getProjectConfig (SYLOverride stackYaml) = pure $ PCProject stackYaml getProjectConfig SYLGlobalProject = pure PCGlobalProject getProjectConfig SYLDefault = do env <- liftIO getEnvironment case lookup "STACK_YAML" env of Just fp -> do logInfo "Getting project config file from STACK_YAML environment" liftM PCProject $ resolveFile' fp Nothing -> do currDir <- getCurrentDir maybe PCGlobalProject PCProject <$> findInParents getStackDotYaml currDir where getStackDotYaml dir = do let fp = dir stackDotYaml fp' = toFilePath fp logDebug $ "Checking for project config at: " <> fromString fp' exists <- doesFileExist fp if exists then pure $ Just fp else pure Nothing getProjectConfig (SYLNoProject extraDeps) = pure $ PCNoProject extraDeps -- | Find the project config file location, respecting environment variables -- and otherwise traversing parents. If no config is found, we supply a default -- based on current directory. loadProjectConfig :: HasLogFunc env => StackYamlLoc -- ^ Override stack.yaml -> RIO env (ProjectConfig (Project, Path Abs File, ConfigMonoid)) loadProjectConfig mstackYaml = do mfp <- getProjectConfig mstackYaml case mfp of PCProject fp -> do currDir <- getCurrentDir logDebug $ "Loading project config file " <> fromString (maybe (toFilePath fp) toFilePath (stripProperPrefix currDir fp)) PCProject <$> load fp PCGlobalProject -> do logDebug "No project config file found, using defaults." pure PCGlobalProject PCNoProject extraDeps -> do logDebug "Ignoring config files" pure $ PCNoProject extraDeps where load fp = do iopc <- loadConfigYaml (parseProjectAndConfigMonoid (parent fp)) fp ProjectAndConfigMonoid project config <- liftIO iopc pure (project, fp, config) -- | Get the location of the default Stack configuration file. -- If a file already exists at the deprecated location, its location is returned. -- Otherwise, the new location is returned. getDefaultGlobalConfigPath :: HasLogFunc env => RIO env (Maybe (Path Abs File)) getDefaultGlobalConfigPath = case (defaultGlobalConfigPath, defaultGlobalConfigPathDeprecated) of (Just new,Just old) -> liftM (Just . fst ) $ tryDeprecatedPath (Just "non-project global configuration file") doesFileExist new old (Just new,Nothing) -> pure (Just new) _ -> pure Nothing -- | Get the location of the default user configuration file. -- If a file already exists at the deprecated location, its location is returned. -- Otherwise, the new location is returned. getDefaultUserConfigPath :: HasLogFunc env => Path Abs Dir -> RIO env (Path Abs File) getDefaultUserConfigPath stackRoot = do (path, exists) <- tryDeprecatedPath (Just "non-project configuration file") doesFileExist (defaultUserConfigPath stackRoot) (defaultUserConfigPathDeprecated stackRoot) unless exists $ do ensureDir (parent path) liftIO $ writeBinaryFileAtomic path defaultConfigYaml pure path packagesParser :: Parser [String] packagesParser = many (strOption (long "package" <> metavar "PACKAGE" <> help "Add a package (can be specified multiple times)")) defaultConfigYaml :: (IsString s, Semigroup s) => s defaultConfigYaml = "# This file contains default non-project-specific settings for Stack, used\n" <> "# in all projects. For more information about Stack's configuration, see\n" <> "# http://docs.haskellstack.org/en/stable/yaml_configuration/\n" <> "\n" <> "# The following parameters are used by 'stack new' to automatically fill fields\n" <> "# in the Cabal file. We recommend uncommenting them and filling them out if\n" <> "# you intend to use 'stack new'.\n" <> "# See https://docs.haskellstack.org/en/stable/yaml_configuration/#templates\n" <> "templates:\n" <> " params:\n" <> "# author-name:\n" <> "# author-email:\n" <> "# copyright:\n" <> "# github-username:\n" <> "\n" <> "# The following parameter specifies Stack's output styles; STYLES is a\n" <> "# colon-delimited sequence of key=value, where 'key' is a style name and\n" <> "# 'value' is a semicolon-delimited list of 'ANSI' SGR (Select Graphic\n" <> "# Rendition) control codes (in decimal). Use 'stack ls stack-colors --basic'\n" <> "# to see the current sequence.\n" <> "# stack-colors: STYLES\n" stack-2.9.3.1/src/Stack/Config/Build.hs0000644000000000000000000001016314445022466015623 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE RecordWildCards #-} -- | Build configuration module Stack.Config.Build ( benchmarkOptsFromMonoid , buildOptsFromMonoid , haddockOptsFromMonoid , testOptsFromMonoid ) where import Distribution.Verbosity ( normal ) import Stack.Prelude import Stack.Types.Config -- | Interprets BuildOptsMonoid options. buildOptsFromMonoid :: BuildOptsMonoid -> BuildOpts buildOptsFromMonoid BuildOptsMonoid{..} = BuildOpts { boptsLibProfile = fromFirstFalse (buildMonoidLibProfile <> FirstFalse (if tracing || profiling then Just True else Nothing)) , boptsExeProfile = fromFirstFalse (buildMonoidExeProfile <> FirstFalse (if tracing || profiling then Just True else Nothing)) , boptsLibStrip = fromFirstTrue (buildMonoidLibStrip <> FirstTrue (if noStripping then Just False else Nothing)) , boptsExeStrip = fromFirstTrue (buildMonoidExeStrip <> FirstTrue (if noStripping then Just False else Nothing)) , boptsHaddock = fromFirstFalse buildMonoidHaddock , boptsHaddockOpts = haddockOptsFromMonoid buildMonoidHaddockOpts , boptsOpenHaddocks = fromFirstFalse buildMonoidOpenHaddocks , boptsHaddockDeps = getFirst buildMonoidHaddockDeps , boptsHaddockInternal = fromFirstFalse buildMonoidHaddockInternal , boptsHaddockHyperlinkSource = fromFirstTrue buildMonoidHaddockHyperlinkSource , boptsInstallExes = fromFirstFalse buildMonoidInstallExes , boptsInstallCompilerTool = fromFirstFalse buildMonoidInstallCompilerTool , boptsPreFetch = fromFirstFalse buildMonoidPreFetch , boptsKeepGoing = getFirst buildMonoidKeepGoing , boptsKeepTmpFiles = fromFirstFalse buildMonoidKeepTmpFiles , boptsForceDirty = fromFirstFalse buildMonoidForceDirty , boptsTests = fromFirstFalse buildMonoidTests , boptsTestOpts = testOptsFromMonoid buildMonoidTestOpts additionalArgs , boptsBenchmarks = fromFirstFalse buildMonoidBenchmarks , boptsBenchmarkOpts = benchmarkOptsFromMonoid buildMonoidBenchmarkOpts additionalArgs , boptsReconfigure = fromFirstFalse buildMonoidReconfigure , boptsCabalVerbose = fromFirst (CabalVerbosity normal) buildMonoidCabalVerbose , boptsSplitObjs = fromFirstFalse buildMonoidSplitObjs , boptsSkipComponents = buildMonoidSkipComponents , boptsInterleavedOutput = fromFirstTrue buildMonoidInterleavedOutput , boptsDdumpDir = getFirst buildMonoidDdumpDir } where -- These options are not directly used in bopts, instead they -- transform other options. tracing = getAny buildMonoidTrace profiling = getAny buildMonoidProfile noStripping = getAny buildMonoidNoStrip -- Additional args for tracing / profiling additionalArgs = if tracing || profiling then Just $ "+RTS" : catMaybes [trac, prof, Just "-RTS"] else Nothing trac = if tracing then Just "-xc" else Nothing prof = if profiling then Just "-p" else Nothing haddockOptsFromMonoid :: HaddockOptsMonoid -> HaddockOpts haddockOptsFromMonoid HaddockOptsMonoid{..} = defaultHaddockOpts { hoAdditionalArgs = hoMonoidAdditionalArgs } testOptsFromMonoid :: TestOptsMonoid -> Maybe [String] -> TestOpts testOptsFromMonoid TestOptsMonoid{..} madditional = defaultTestOpts { toRerunTests = fromFirstTrue toMonoidRerunTests , toAdditionalArgs = fromMaybe [] madditional <> toMonoidAdditionalArgs , toCoverage = fromFirstFalse toMonoidCoverage , toDisableRun = fromFirstFalse toMonoidDisableRun , toMaximumTimeSeconds = fromFirst (toMaximumTimeSeconds defaultTestOpts) toMonoidMaximumTimeSeconds , toAllowStdin = fromFirstTrue toMonoidAllowStdin } benchmarkOptsFromMonoid :: BenchmarkOptsMonoid -> Maybe [String] -> BenchmarkOpts benchmarkOptsFromMonoid BenchmarkOptsMonoid{..} madditional = defaultBenchmarkOpts { beoAdditionalArgs = fmap (\args -> unwords args <> " ") madditional <> getFirst beoMonoidAdditionalArgs , beoDisableRun = fromFirst (beoDisableRun defaultBenchmarkOpts) beoMonoidDisableRun } stack-2.9.3.1/src/Stack/Config/Docker.hs0000644000000000000000000001025614445022466015776 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -- | Docker configuration module Stack.Config.Docker ( ConfigDockerException (..) , addDefaultTag , dockerOptsFromMonoid ) where import Data.List ( find ) import qualified Data.Text as T import Distribution.Version ( simplifyVersionRange ) import Stack.Prelude import Stack.Types.Version import Stack.Types.Config import Stack.Types.Docker import Stack.Types.Resolver -- | Type representing exceptions thrown by functions exported by the -- "Stack.Config.Docker" module. data ConfigDockerException = ResolverNotSupportedException !(Maybe Project) !(Maybe AbstractResolver) -- ^ Only LTS resolvers are supported for default image tag. deriving (Show, Typeable) instance Exception ConfigDockerException where displayException (ResolverNotSupportedException mproject maresolver) = concat [ "Error: [S-8575]\n" , "Resolver not supported for Docker images:\n " , case (mproject, maresolver) of (Nothing, Nothing) -> "no resolver specified" (_, Just aresolver) -> T.unpack $ utf8BuilderToText $ display aresolver (Just project, Nothing) -> T.unpack $ utf8BuilderToText $ display $ projectResolver project , "\nUse an LTS resolver, or set the '" , T.unpack dockerImageArgName , "' explicitly, in your configuration file."] -- | Add a default Docker tag name to a given base image. addDefaultTag :: MonadThrow m => String -- ^ base -> Maybe Project -> Maybe AbstractResolver -> m String addDefaultTag base mproject maresolver = do let exc = throwM $ ResolverNotSupportedException mproject maresolver lts <- case maresolver of Just (ARResolver (RSLSynonym lts@(LTS _ _))) -> pure lts Just _aresolver -> exc Nothing -> case projectResolver <$> mproject of Just (RSLSynonym lts@(LTS _ _)) -> pure lts _ -> exc pure $ base ++ ":" ++ show lts -- | Interprets DockerOptsMonoid options. dockerOptsFromMonoid :: MonadThrow m => Maybe Project -> Maybe AbstractResolver -> DockerOptsMonoid -> m DockerOpts dockerOptsFromMonoid mproject maresolver DockerOptsMonoid{..} = do let dockerImage = case getFirst dockerMonoidRepoOrImage of Nothing -> addDefaultTag "fpco/stack-build" mproject maresolver Just (DockerMonoidImage image) -> pure image Just (DockerMonoidRepo repo) -> case find (`elem` (":@" :: String)) repo of Nothing -> addDefaultTag repo mproject maresolver -- Repo already specified a tag or digest, so don't append default Just _ -> pure repo let dockerEnable = fromFirst (getAny dockerMonoidDefaultEnable) dockerMonoidEnable dockerRegistryLogin = fromFirst (isJust (emptyToNothing (getFirst dockerMonoidRegistryUsername))) dockerMonoidRegistryLogin dockerRegistryUsername = emptyToNothing (getFirst dockerMonoidRegistryUsername) dockerRegistryPassword = emptyToNothing (getFirst dockerMonoidRegistryPassword) dockerAutoPull = fromFirstTrue dockerMonoidAutoPull dockerDetach = fromFirstFalse dockerMonoidDetach dockerPersist = fromFirstFalse dockerMonoidPersist dockerContainerName = emptyToNothing (getFirst dockerMonoidContainerName) dockerNetwork = emptyToNothing (getFirst dockerMonoidNetwork) dockerRunArgs = dockerMonoidRunArgs dockerMount = dockerMonoidMount dockerMountMode = emptyToNothing (getFirst dockerMonoidMountMode) dockerEnv = dockerMonoidEnv dockerSetUser = getFirst dockerMonoidSetUser dockerRequireDockerVersion = simplifyVersionRange (getIntersectingVersionRange dockerMonoidRequireDockerVersion) dockerStackExe = getFirst dockerMonoidStackExe pure DockerOpts{..} where emptyToNothing Nothing = Nothing emptyToNothing (Just s) | null s = Nothing | otherwise = Just s stack-2.9.3.1/src/Stack/Config/Nix.hs0000644000000000000000000001064714445022466015331 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -- | Nix configuration module Stack.Config.Nix ( nixCompiler , nixCompilerVersion , nixOptsFromMonoid ) where import Control.Monad.Extra ( ifM ) import qualified Data.Text as T import qualified Data.Text.IO as TIO import Distribution.System ( OS (..) ) import Stack.Constants ( osIsWindows ) import Stack.Prelude import Stack.Types.Config ( HasRunner ) import Stack.Types.Nix ( NixOpts (..), NixOptsMonoid (..) ) import System.Directory ( doesFileExist ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Config.Nix" module. data ConfigNixException = NixCannotUseShellFileAndPackagesException -- ^ Nix can't be given packages and a shell file at the same time | GHCMajorVersionUnspecified | OnlyGHCSupported deriving (Show, Typeable) instance Exception ConfigNixException where displayException NixCannotUseShellFileAndPackagesException = "Error: [S-2726]\n" ++ "You cannot have packages and a shell-file filled at the same time \ \in your nix-shell configuration." displayException GHCMajorVersionUnspecified = "Error: [S-9317]\n" ++ "GHC major version not specified." displayException OnlyGHCSupported = "Error: [S-8605]\n" ++ "Only GHC is supported by 'stack --nix'." -- | Interprets NixOptsMonoid options. nixOptsFromMonoid :: HasRunner env => NixOptsMonoid -> OS -> RIO env NixOpts nixOptsFromMonoid NixOptsMonoid{..} os = do let defaultPure = case os of OSX -> False _ -> True nixPureShell = fromFirst defaultPure nixMonoidPureShell nixPackages = fromFirst [] nixMonoidPackages nixInitFile = getFirst nixMonoidInitFile nixShellOptions = fromFirst [] nixMonoidShellOptions ++ prefixAll (T.pack "-I") (fromFirst [] nixMonoidPath) nixAddGCRoots = fromFirstFalse nixMonoidAddGCRoots -- Enable Nix-mode by default on NixOS, unless Docker-mode was specified osIsNixOS <- isNixOS let nixEnable0 = fromFirst osIsNixOS nixMonoidEnable nixEnable <- case () of _ | nixEnable0 && osIsWindows -> do logInfo "Note: Disabling nix integration, since this is being run in Windows" pure False | otherwise -> pure nixEnable0 when (not (null nixPackages) && isJust nixInitFile) $ throwIO NixCannotUseShellFileAndPackagesException pure NixOpts{..} where prefixAll p (x:xs) = p : x : prefixAll p xs prefixAll _ _ = [] nixCompiler :: WantedCompiler -> Either ConfigNixException T.Text nixCompiler compilerVersion = case compilerVersion of WCGhc version -> case T.split (== '.') (fromString $ versionString version) of x : y : minor -> Right $ case minor of [] -> -- The minor version is not specified. Select the latest minor -- version in Nixpkgs corresponding to the requested major -- version. let major = T.concat [x, y] in "(let compilers = builtins.filter \ \(name: builtins.match \ \\"ghc" <> major <> "[[:digit:]]*\" name != null) \ \(lib.attrNames haskell.compiler); in \ \if compilers == [] \ \then abort \"No compiler found for GHC " <> T.pack (versionString version) <> "\"\ \else haskell.compiler.${builtins.head compilers})" _ -> "haskell.compiler.ghc" <> T.concat (x : y : minor) _ -> Left GHCMajorVersionUnspecified WCGhcjs{} -> Left OnlyGHCSupported WCGhcGit{} -> Left OnlyGHCSupported nixCompilerVersion :: WantedCompiler -> Either ConfigNixException T.Text nixCompilerVersion compilerVersion = case compilerVersion of WCGhc version -> case T.split (== '.') (fromString $ versionString version) of x : y : minor -> Right $ "ghc" <> T.concat (x : y : minor) _ -> Left GHCMajorVersionUnspecified WCGhcjs{} -> Left OnlyGHCSupported WCGhcGit{} -> Left OnlyGHCSupported isNixOS :: MonadIO m => m Bool isNixOS = liftIO $ do let fp = "/etc/os-release" ifM (doesFileExist fp) (T.isInfixOf "ID=nixos" <$> TIO.readFile fp) (pure False) stack-2.9.3.1/src/Stack/ConfigCmd.hs0000644000000000000000000003254114445022466015214 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Make changes to project or global configuration. module Stack.ConfigCmd ( ConfigCmdSet (..) , configCmdSetParser , cfgCmdSet , cfgCmdSetName , configCmdEnvParser , cfgCmdEnv , cfgCmdEnvName , cfgCmdName ) where import qualified Data.Aeson.Key as Key import qualified Data.Aeson.KeyMap as KeyMap import Data.Attoparsec.Text as P ( Parser, parseOnly, skip, skipWhile, string, takeText , takeWhile ) import qualified Data.Map.Merge.Strict as Map import qualified Data.List.NonEmpty as NE import qualified Data.Text as T import qualified Data.Yaml as Yaml import qualified Options.Applicative as OA import Options.Applicative.Builder.Extra import qualified Options.Applicative.Types as OA import Pantry ( loadSnapshot ) import Path import qualified RIO.Map as Map import RIO.Process ( envVarsL ) import Stack.Config ( makeConcreteResolver, getProjectConfig , getImplicitGlobalProjectDir ) import Stack.Constants import Stack.Prelude import Stack.Types.Config import Stack.Types.Resolver import System.Environment ( getEnvironment ) -- | Type repesenting exceptions thrown by functions exported by the -- "Stack.ConfigCmd" module. data ConfigCmdException = NoProjectConfigAvailable deriving (Show, Typeable) instance Exception ConfigCmdException where displayException NoProjectConfigAvailable = "Error: [S-3136]\n" ++ "'config' command used when no project configuration available." data ConfigCmdSet = ConfigCmdSetResolver !(Unresolved AbstractResolver) | ConfigCmdSetSystemGhc !CommandScope !Bool | ConfigCmdSetInstallGhc !CommandScope !Bool | ConfigCmdSetDownloadPrefix !CommandScope !Text data CommandScope = CommandScopeGlobal -- ^ Apply changes to the global configuration, -- typically at @~/.stack/config.yaml@. | CommandScopeProject -- ^ Apply changes to the project @stack.yaml@. configCmdSetScope :: ConfigCmdSet -> CommandScope configCmdSetScope (ConfigCmdSetResolver _) = CommandScopeProject configCmdSetScope (ConfigCmdSetSystemGhc scope _) = scope configCmdSetScope (ConfigCmdSetInstallGhc scope _) = scope configCmdSetScope (ConfigCmdSetDownloadPrefix scope _) = scope cfgCmdSet :: (HasConfig env, HasGHCVariant env) => ConfigCmdSet -> RIO env () cfgCmdSet cmd = do conf <- view configL configFilePath <- case configCmdSetScope cmd of CommandScopeProject -> do mstackYamlOption <- view $ globalOptsL.to globalStackYaml mstackYaml <- getProjectConfig mstackYamlOption case mstackYaml of PCProject stackYaml -> pure stackYaml PCGlobalProject -> liftM ( stackDotYaml) (getImplicitGlobalProjectDir conf) PCNoProject _extraDeps -> throwIO NoProjectConfigAvailable -- maybe modify the ~/.stack/config.yaml file instead? CommandScopeGlobal -> pure (configUserConfigPath conf) rawConfig <- liftIO (readFileUtf8 (toFilePath configFilePath)) config <- either throwM pure (Yaml.decodeEither' $ encodeUtf8 rawConfig) newValue <- cfgCmdSetValue (parent configFilePath) cmd let yamlLines = T.lines rawConfig cmdKeys = cfgCmdSetKeys cmd -- Text newValue' = T.stripEnd $ decodeUtf8With lenientDecode $ Yaml.encode newValue -- Text file = toFilePath configFilePath -- String file' = display $ T.pack file -- Utf8Builder newYamlLines <- case inConfig config cmdKeys of Nothing -> do logInfo $ file' <> " has been extended." pure $ writeLines yamlLines "" cmdKeys newValue' Just oldValue -> if oldValue == newValue then do logInfo $ file' <> " already contained the intended \ \configuration and remains unchanged." pure yamlLines else switchLine file' (NE.last cmdKeys) newValue' [] yamlLines liftIO $ writeFileUtf8 file (T.unlines newYamlLines) where -- This assumes that if the key does not exist, the lines that can be -- appended to include it are of a form like: -- -- key1: -- key2: -- key3: value -- writeLines yamlLines spaces cmdKeys value = case NE.tail cmdKeys of [] -> yamlLines <> [spaces <> NE.head cmdKeys <> ": " <> value] ks -> writeLines (yamlLines <> [spaces <> NE.head cmdKeys <> ":"]) (spaces <> " ") (NE.fromList ks) value inConfig v cmdKeys = case v of Yaml.Object obj -> case KeyMap.lookup (Key.fromText (NE.head cmdKeys)) obj of Nothing -> Nothing Just v' -> case NE.tail cmdKeys of [] -> Just v' ks -> inConfig v' (NE.fromList ks) _ -> Nothing switchLine file cmdKey _ searched [] = do logWarn $ display cmdKey <> " not found in YAML file " <> file <> " as a single line. Multi-line key:value formats are not supported." pure $ reverse searched switchLine file cmdKey newValue searched (oldLine:rest) = case parseOnly (parseLine cmdKey) oldLine of Left _ -> switchLine file cmdKey newValue (oldLine:searched) rest Right (kt, spaces1, spaces2, spaces3, comment) -> do let newLine = spaces1 <> renderKey cmdKey kt <> spaces2 <> ":" <> spaces3 <> newValue <> comment logInfo $ file <> " has been updated." pure $ reverse searched <> (newLine:rest) parseLine :: Text -> Parser (KeyType, Text, Text, Text, Text) parseLine key = do spaces1 <- P.takeWhile (== ' ') kt <- parseKey key spaces2 <- P.takeWhile (== ' ') skip (== ':') spaces3 <- P.takeWhile (== ' ') skipWhile (/= ' ') comment <- takeText pure (kt, spaces1, spaces2, spaces3, comment) -- If the key is, for example, install-ghc, this recognises install-ghc, -- 'install-ghc' or "install-ghc". parseKey :: Text -> Parser KeyType parseKey k = parsePlainKey k <|> parseSingleQuotedKey k <|> parseDoubleQuotedKey k parsePlainKey :: Text -> Parser KeyType parsePlainKey key = do _ <- P.string key pure PlainKey parseSingleQuotedKey :: Text -> Parser KeyType parseSingleQuotedKey = parseQuotedKey SingleQuotedKey '\'' parseDoubleQuotedKey :: Text -> Parser KeyType parseDoubleQuotedKey = parseQuotedKey DoubleQuotedKey '"' parseQuotedKey :: KeyType -> Char -> Text -> Parser KeyType parseQuotedKey kt c key = do skip (==c) _ <- P.string key skip (==c) pure kt renderKey :: Text -> KeyType -> Text renderKey key kt = case kt of PlainKey -> key SingleQuotedKey -> '\'' `T.cons` key `T.snoc` '\'' DoubleQuotedKey -> '"' `T.cons` key `T.snoc` '"' -- |Type representing types of representations of keys in YAML files. data KeyType = PlainKey -- ^ For example: install-ghc | SingleQuotedKey -- ^ For example: 'install-ghc' | DoubleQuotedKey -- ^ For example: "install-ghc" deriving (Eq, Show) cfgCmdSetValue :: (HasConfig env, HasGHCVariant env) => Path Abs Dir -- ^ root directory of project -> ConfigCmdSet -> RIO env Yaml.Value cfgCmdSetValue root (ConfigCmdSetResolver newResolver) = do newResolver' <- resolvePaths (Just root) newResolver concreteResolver <- makeConcreteResolver newResolver' -- Check that the snapshot actually exists void $ loadSnapshot =<< completeSnapshotLocation concreteResolver pure (Yaml.toJSON concreteResolver) cfgCmdSetValue _ (ConfigCmdSetSystemGhc _ bool') = pure $ Yaml.Bool bool' cfgCmdSetValue _ (ConfigCmdSetInstallGhc _ bool') = pure $ Yaml.Bool bool' cfgCmdSetValue _ (ConfigCmdSetDownloadPrefix _ url) = pure $ Yaml.String url cfgCmdSetKeys :: ConfigCmdSet -> NonEmpty Text cfgCmdSetKeys (ConfigCmdSetResolver _) = ["resolver"] cfgCmdSetKeys (ConfigCmdSetSystemGhc _ _) = [configMonoidSystemGHCName] cfgCmdSetKeys (ConfigCmdSetInstallGhc _ _) = [configMonoidInstallGHCName] cfgCmdSetKeys (ConfigCmdSetDownloadPrefix _ _) = ["package-index", "download-prefix"] cfgCmdName :: String cfgCmdName = "config" cfgCmdSetName :: String cfgCmdSetName = "set" cfgCmdEnvName :: String cfgCmdEnvName = "env" configCmdSetParser :: OA.Parser ConfigCmdSet configCmdSetParser = OA.hsubparser $ mconcat [ OA.command "resolver" ( OA.info ( ConfigCmdSetResolver <$> OA.argument readAbstractResolver ( OA.metavar "SNAPSHOT" <> OA.help "E.g. \"nightly\" or \"lts-7.2\"" )) ( OA.progDesc "Change the resolver of the current project." )) , OA.command (T.unpack configMonoidSystemGHCName) ( OA.info ( ConfigCmdSetSystemGhc <$> scopeFlag <*> boolArgument ) ( OA.progDesc "Configure whether Stack should use a system GHC \ \installation or not." )) , OA.command (T.unpack configMonoidInstallGHCName) ( OA.info ( ConfigCmdSetInstallGhc <$> scopeFlag <*> boolArgument ) ( OA.progDesc "Configure whether Stack should automatically install \ \GHC when necessary." )) , OA.command "package-index" ( OA.info ( OA.hsubparser $ OA.command "download-prefix" ( OA.info ( ConfigCmdSetDownloadPrefix <$> scopeFlag <*> urlArgument ) ( OA.progDesc "Configure download prefix for Stack's package \ \index." ))) ( OA.progDesc "Configure Stack's package index" )) ] scopeFlag :: OA.Parser CommandScope scopeFlag = OA.flag CommandScopeProject CommandScopeGlobal ( OA.long "global" <> OA.help "Modify the user-specific global configuration file ('config.yaml') \ \instead of the project-level configuration file ('stack.yaml')." ) readBool :: OA.ReadM Bool readBool = do s <- OA.readerAsk case s of "true" -> pure True "false" -> pure False _ -> OA.readerError ("Invalid value " ++ show s ++ ": Expected \"true\" or \"false\"") boolArgument :: OA.Parser Bool boolArgument = OA.argument readBool ( OA.metavar "true|false" <> OA.completeWith ["true", "false"] ) urlArgument :: OA.Parser Text urlArgument = OA.strArgument ( OA.metavar "URL" <> OA.value defaultDownloadPrefix <> OA.showDefault <> OA.help "Location of package index. It is highly recommended to use only the \ \official Hackage server or a mirror." ) configCmdEnvParser :: OA.Parser EnvSettings configCmdEnvParser = EnvSettings <$> boolFlags True "locals" "include local package information" mempty <*> boolFlags True "ghc-package-path" "set GHC_PACKAGE_PATH environment variable" mempty <*> boolFlags True "stack-exe" "set STACK_EXE environment variable" mempty <*> boolFlags False "locale-utf8" "set the GHC_CHARENC environment variable to UTF-8" mempty <*> boolFlags False "keep-ghc-rts" "keep any GHCRTS environment variable" mempty data EnvVarAction = EVASet !Text | EVAUnset deriving Show cfgCmdEnv :: EnvSettings -> RIO EnvConfig () cfgCmdEnv es = do origEnv <- liftIO $ Map.fromList . map (first fromString) <$> getEnvironment mkPC <- view $ configL.to configProcessContextSettings pc <- liftIO $ mkPC es let newEnv = pc ^. envVarsL actions = Map.merge (pure EVAUnset) (Map.traverseMissing $ \_k new -> pure (EVASet new)) (Map.zipWithMaybeAMatched $ \_k old new -> pure $ if fromString old == new then Nothing else Just (EVASet new)) origEnv newEnv toLine key EVAUnset = "unset " <> encodeUtf8Builder key <> ";\n" toLine key (EVASet value) = encodeUtf8Builder key <> "='" <> encodeUtf8Builder (T.concatMap escape value) <> -- TODO more efficient to use encodeUtf8BuilderEscaped "'; export " <> encodeUtf8Builder key <> ";\n" escape '\'' = "'\"'\"'" escape c = T.singleton c hPutBuilder stdout $ Map.foldMapWithKey toLine actions stack-2.9.3.1/src/Stack/Constants.hs0000644000000000000000000004541114445022466015337 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} -- keep TH usage here -- | Constants used throughout the project. module Stack.Constants ( buildPlanDir , buildPlanCacheDir , haskellFileExts , haskellDefaultPreprocessorExts , stackDotYaml , stackWorkEnvVar , stackRootEnvVar , stackXdgEnvVar , stackRootOptionName , stackGlobalConfigOptionName , pantryRootEnvVar , deprecatedStackRootOptionName , inContainerEnvVar , inNixShellEnvVar , stackProgNameUpper , wiredInPackages , cabalPackageName , implicitGlobalProjectDirDeprecated , implicitGlobalProjectDir , defaultUserConfigPathDeprecated , defaultUserConfigPath , defaultGlobalConfigPathDeprecated , defaultGlobalConfigPath , platformVariantEnvVar , compilerOptionsCabalFlag , ghcColorForceFlag , minTerminalWidth , maxTerminalWidth , defaultTerminalWidth , osIsWindows , relFileSetupHs , relFileSetupLhs , relFileHpackPackageConfig , relDirGlobalAutogen , relDirAutogen , relDirLogs , relFileCabalMacrosH , relDirBuild , relDirBin , relDirPantry , relDirPrograms , relDirUpperPrograms , relDirStackProgName , relDirStackWork , relFileReadmeTxt , relDirScript , relFileConfigYaml , relDirSnapshots , relDirGlobalHints , relFileGlobalHintsYaml , relDirInstall , relDirCompilerTools , relDirHoogle , relFileDatabaseHoo , relDirPkgdb , relFileStorage , relDirLoadedSnapshotCache , bindirSuffix , docDirSuffix , relDirHpc , relDirLib , relDirShare , relDirLibexec , relDirEtc , setupGhciShimCode , relDirSetupExeCache , relDirSetupExeSrc , relFileConfigure , relDirDist , relFileSetupMacrosH , relDirSetup , relFileSetupLower , relDirMingw , relDirMingw32 , relDirMingw64 , relDirLocal , relDirUsr , relDirInclude , relFileIndexHtml , relDirAll , relFilePackageCache , relFileDockerfile , relDirHaskellStackGhci , relFileGhciScript , relDirCombined , relFileHpcIndexHtml , relDirCustom , relDirPackageConfInplace , relDirExtraTixFiles , relDirInstalledPackages , backupUrlRelPath , relDirDotLocal , relDirDotSsh , relDirDotStackProgName , relDirUnderHome , relDirSrc , relFileLibtinfoSo5 , relFileLibtinfoSo6 , relFileLibncurseswSo6 , relFileLibgmpSo10 , relFileLibgmpSo3 , relDirNewCabal , relFileSetupExe , relFileSetupUpper , relFile7zexe , relFile7zdll , relFileMainHs , relFileStack , relFileStackDotExe , relFileStackDotTmpDotExe , relFileStackDotTmp , ghcShowOptionsOutput , hadrianScriptsWindows , hadrianScriptsPosix , usrLibDirs , testGhcEnvRelFile , relFileBuildLock , stackDeveloperModeDefault , globalFooter ) where import Data.ByteString.Builder ( byteString ) import Data.Char ( toUpper ) import Data.FileEmbed ( embedFile, makeRelativeToProject ) import qualified Data.Set as Set import Distribution.Package ( mkPackageName ) import Hpack.Config ( packageConfig ) import qualified Language.Haskell.TH.Syntax as TH ( runIO, lift ) import Path as FL import Stack.Prelude import Stack.Types.Compiler ( WhichCompiler (..) ) import System.Permissions ( osIsWindows ) import System.Process ( readProcess ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Constants" module. data ConstantsException = WiredInPackagesNotParsedBug deriving (Show, Typeable) instance Exception ConstantsException where displayException WiredInPackagesNotParsedBug = bugReport "[S-6057]" "Parse error in wiredInPackages." -- | Extensions used for Haskell modules. Excludes preprocessor ones. haskellFileExts :: [Text] haskellFileExts = ["hs", "hsc", "lhs"] -- | Extensions for modules that are preprocessed by common preprocessors. haskellDefaultPreprocessorExts :: [Text] haskellDefaultPreprocessorExts = ["gc", "chs", "hsc", "x", "y", "ly", "cpphs"] -- | Name of the 'stack' program, uppercased stackProgNameUpper :: String stackProgNameUpper = map toUpper stackProgName -- | The filename used for the Stack project-level configuration file. stackDotYaml :: Path Rel File stackDotYaml = $(mkRelFile "stack.yaml") -- | Environment variable used to override the '.stack-work' relative dir. stackWorkEnvVar :: String stackWorkEnvVar = "STACK_WORK" -- | Environment variable used to override the '~/.stack' location. stackRootEnvVar :: String stackRootEnvVar = "STACK_ROOT" -- | Environment variable used to indicate XDG directories should be used. stackXdgEnvVar :: String stackXdgEnvVar = "STACK_XDG" -- | Option name for the global Stack root. stackRootOptionName :: String stackRootOptionName = "stack-root" -- | Option name for the global Stack configuration file. stackGlobalConfigOptionName :: String stackGlobalConfigOptionName = "global-config" -- | Environment variable used to override the location of the Pantry store pantryRootEnvVar :: String pantryRootEnvVar = "PANTRY_ROOT" -- | Deprecated option name for the global Stack root. -- -- Deprecated since stack-1.1.0. -- -- TODO: Remove occurrences of this variable and use 'stackRootOptionName' only -- after an appropriate deprecation period. deprecatedStackRootOptionName :: String deprecatedStackRootOptionName = "global-stack-root" -- | Environment variable used to indicate Stack is running in container. inContainerEnvVar :: String inContainerEnvVar = stackProgNameUpper ++ "_IN_CONTAINER" -- | Environment variable used to indicate Stack is running in container. -- although we already have STACK_IN_NIX_EXTRA_ARGS that is set in the same conditions, -- it can happen that STACK_IN_NIX_EXTRA_ARGS is set to empty. inNixShellEnvVar :: String inNixShellEnvVar = map toUpper stackProgName ++ "_IN_NIX_SHELL" -- | The comment to \'see -- https://downloads.haskell.org/~ghc/7.10.1/docs/html/libraries/ghc/src/Module.html#integerPackageKey\' -- appears to be out of date. -- -- See \'Note [About units]\' and \'Wired-in units\' at -- https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/Unit.hs. -- -- The \'wired-in packages\' appear to have been replaced by those that have (e.g) -- -- > ghc-options: -this-unit-id ghc-prim -- -- in their Cabal file because they are \'magic\'. wiredInPackages :: Set PackageName wiredInPackages = case mparsed of Just parsed -> Set.fromList parsed Nothing -> impureThrow WiredInPackagesNotParsedBug where mparsed = mapM parsePackageName [ "ghc-prim" -- A magic package , "integer-gmp" -- No longer magic > 1.0.3.0. With GHC 9.2.5 at least, there seems to be -- no problem in using it. , "integer-simple" -- A magic package , "base" -- A magic package , "rts" -- Said to be not a \'real\' package , "template-haskell" -- A magic package , "dph-seq" -- Deprecated in favour of dph-prim-seq, which does not appear to be -- magic. With GHC 9.2.5 at least, there seems to be no problem in using -- it. , "dph-par" -- Deprecated in favour of dph-prim-par, which does not appear to be -- magic. With GHC 9.2.5 at least, there seems to be no problem in using -- it. , "ghc" -- A magic package , "interactive" -- Could not identify information about this package name. With GHC 9.2.5 -- at least, there seems to be no problem in using it. , "ghc-bignum" -- A magic package ] -- | Just to avoid repetition and magic strings. cabalPackageName :: PackageName cabalPackageName = mkPackageName "Cabal" -- | Deprecated implicit global project directory used when outside of a project. implicitGlobalProjectDirDeprecated :: Path Abs Dir -- ^ Stack root. -> Path Abs Dir implicitGlobalProjectDirDeprecated p = p $(mkRelDir "global") -- | Implicit global project directory used when outside of a project. -- Normally, @getImplicitGlobalProjectDir@ should be used instead. implicitGlobalProjectDir :: Path Abs Dir -- ^ Stack root. -> Path Abs Dir implicitGlobalProjectDir p = p $(mkRelDir "global-project") -- | Deprecated default global config path. defaultUserConfigPathDeprecated :: Path Abs Dir -> Path Abs File defaultUserConfigPathDeprecated = ( $(mkRelFile "stack.yaml")) -- | Default global config path. -- Normally, @getDefaultUserConfigPath@ should be used instead. defaultUserConfigPath :: Path Abs Dir -> Path Abs File defaultUserConfigPath = ( $(mkRelFile "config.yaml")) -- | Deprecated default global config path. -- Note that this will be @Nothing@ on Windows, which is by design. defaultGlobalConfigPathDeprecated :: Maybe (Path Abs File) defaultGlobalConfigPathDeprecated = parseAbsFile "/etc/stack/config" -- | Default global config path. -- Normally, @getDefaultGlobalConfigPath@ should be used instead. -- Note that this will be @Nothing@ on Windows, which is by design. defaultGlobalConfigPath :: Maybe (Path Abs File) defaultGlobalConfigPath = parseAbsFile "/etc/stack/config.yaml" -- | Path where build plans are stored. buildPlanDir :: Path Abs Dir -- ^ Stack root -> Path Abs Dir buildPlanDir = ( $(mkRelDir "build-plan")) -- | Path where binary caches of the build plans are stored. buildPlanCacheDir :: Path Abs Dir -- ^ Stack root -> Path Abs Dir buildPlanCacheDir = ( $(mkRelDir "build-plan-cache")) -- | Environment variable that stores a variant to append to platform-specific directory -- names. Used to ensure incompatible binaries aren't shared between Docker builds and host platformVariantEnvVar :: String platformVariantEnvVar = stackProgNameUpper ++ "_PLATFORM_VARIANT" -- | Provides --ghc-options for 'Ghc' compilerOptionsCabalFlag :: WhichCompiler -> String compilerOptionsCabalFlag Ghc = "--ghc-options" -- | The flag to pass to GHC when we want to force its output to be -- colorized. ghcColorForceFlag :: String ghcColorForceFlag = "-fdiagnostics-color=always" -- | The minimum allowed terminal width. Used for pretty-printing. minTerminalWidth :: Int minTerminalWidth = 40 -- | The maximum allowed terminal width. Used for pretty-printing. maxTerminalWidth :: Int maxTerminalWidth = 200 -- | The default terminal width. Used for pretty-printing when we can't -- automatically detect it and when the user doesn't supply one. defaultTerminalWidth :: Int defaultTerminalWidth = 100 relFileSetupHs :: Path Rel File relFileSetupHs = $(mkRelFile "Setup.hs") relFileSetupLhs :: Path Rel File relFileSetupLhs = $(mkRelFile "Setup.lhs") relFileHpackPackageConfig :: Path Rel File relFileHpackPackageConfig = $(mkRelFile packageConfig) relDirGlobalAutogen :: Path Rel Dir relDirGlobalAutogen = $(mkRelDir "global-autogen") relDirAutogen :: Path Rel Dir relDirAutogen = $(mkRelDir "autogen") relDirLogs :: Path Rel Dir relDirLogs = $(mkRelDir "logs") relFileCabalMacrosH :: Path Rel File relFileCabalMacrosH = $(mkRelFile "cabal_macros.h") relDirBuild :: Path Rel Dir relDirBuild = $(mkRelDir "build") relDirBin :: Path Rel Dir relDirBin = $(mkRelDir "bin") relDirPantry :: Path Rel Dir relDirPantry = $(mkRelDir "pantry") relDirPrograms :: Path Rel Dir relDirPrograms = $(mkRelDir "programs") relDirUpperPrograms :: Path Rel Dir relDirUpperPrograms = $(mkRelDir "Programs") relDirStackProgName :: Path Rel Dir relDirStackProgName = $(mkRelDir stackProgName) relDirStackWork :: Path Rel Dir relDirStackWork = $(mkRelDir ".stack-work") relFileReadmeTxt :: Path Rel File relFileReadmeTxt = $(mkRelFile "README.txt") relDirScript :: Path Rel Dir relDirScript = $(mkRelDir "script") relFileConfigYaml :: Path Rel File relFileConfigYaml = $(mkRelFile "config.yaml") relDirSnapshots :: Path Rel Dir relDirSnapshots = $(mkRelDir "snapshots") relDirGlobalHints :: Path Rel Dir relDirGlobalHints = $(mkRelDir "global-hints") relFileGlobalHintsYaml :: Path Rel File relFileGlobalHintsYaml = $(mkRelFile "global-hints.yaml") relDirInstall :: Path Rel Dir relDirInstall = $(mkRelDir "install") relDirCompilerTools :: Path Rel Dir relDirCompilerTools = $(mkRelDir "compiler-tools") relDirHoogle :: Path Rel Dir relDirHoogle = $(mkRelDir "hoogle") relFileDatabaseHoo :: Path Rel File relFileDatabaseHoo = $(mkRelFile "database.hoo") relDirPkgdb :: Path Rel Dir relDirPkgdb = $(mkRelDir "pkgdb") relFileStorage :: Path Rel File relFileStorage = $(mkRelFile "stack.sqlite3") relDirLoadedSnapshotCache :: Path Rel Dir relDirLoadedSnapshotCache = $(mkRelDir "loaded-snapshot-cached") -- | Suffix applied to an installation root to get the bin dir bindirSuffix :: Path Rel Dir bindirSuffix = relDirBin -- | Suffix applied to an installation root to get the doc dir docDirSuffix :: Path Rel Dir docDirSuffix = $(mkRelDir "doc") relDirHpc :: Path Rel Dir relDirHpc = $(mkRelDir "hpc") relDirLib :: Path Rel Dir relDirLib = $(mkRelDir "lib") relDirShare :: Path Rel Dir relDirShare = $(mkRelDir "share") relDirLibexec :: Path Rel Dir relDirLibexec = $(mkRelDir "libexec") relDirEtc :: Path Rel Dir relDirEtc = $(mkRelDir "etc") setupGhciShimCode :: Builder setupGhciShimCode = byteString $(do path <- makeRelativeToProject "src/setup-shim/StackSetupShim.hs" embedFile path) relDirSetupExeCache :: Path Rel Dir relDirSetupExeCache = $(mkRelDir "setup-exe-cache") relDirSetupExeSrc :: Path Rel Dir relDirSetupExeSrc = $(mkRelDir "setup-exe-src") relFileConfigure :: Path Rel File relFileConfigure = $(mkRelFile "configure") relDirDist :: Path Rel Dir relDirDist = $(mkRelDir "dist") relFileSetupMacrosH :: Path Rel File relFileSetupMacrosH = $(mkRelFile "setup_macros.h") relDirSetup :: Path Rel Dir relDirSetup = $(mkRelDir "setup") relFileSetupLower :: Path Rel File relFileSetupLower = $(mkRelFile "setup") relDirMingw :: Path Rel Dir relDirMingw = $(mkRelDir "mingw") relDirMingw32 :: Path Rel Dir relDirMingw32 = $(mkRelDir "mingw32") relDirMingw64 :: Path Rel Dir relDirMingw64 = $(mkRelDir "mingw64") relDirLocal :: Path Rel Dir relDirLocal = $(mkRelDir "local") relDirUsr :: Path Rel Dir relDirUsr = $(mkRelDir "usr") relDirInclude :: Path Rel Dir relDirInclude = $(mkRelDir "include") relFileIndexHtml :: Path Rel File relFileIndexHtml = $(mkRelFile "index.html") relDirAll :: Path Rel Dir relDirAll = $(mkRelDir "all") relFilePackageCache :: Path Rel File relFilePackageCache = $(mkRelFile "package.cache") relFileDockerfile :: Path Rel File relFileDockerfile = $(mkRelFile "Dockerfile") relDirHaskellStackGhci :: Path Rel Dir relDirHaskellStackGhci = $(mkRelDir "haskell-stack-ghci") relFileGhciScript :: Path Rel File relFileGhciScript = $(mkRelFile "ghci-script") relDirCombined :: Path Rel Dir relDirCombined = $(mkRelDir "combined") relFileHpcIndexHtml :: Path Rel File relFileHpcIndexHtml = $(mkRelFile "hpc_index.html") relDirCustom :: Path Rel Dir relDirCustom = $(mkRelDir "custom") relDirPackageConfInplace :: Path Rel Dir relDirPackageConfInplace = $(mkRelDir "package.conf.inplace") relDirExtraTixFiles :: Path Rel Dir relDirExtraTixFiles = $(mkRelDir "extra-tix-files") relDirInstalledPackages :: Path Rel Dir relDirInstalledPackages = $(mkRelDir "installed-packages") backupUrlRelPath :: Path Rel File backupUrlRelPath = $(mkRelFile "downloaded.template.file.hsfiles") relDirDotLocal :: Path Rel Dir relDirDotLocal = $(mkRelDir ".local") relDirDotSsh :: Path Rel Dir relDirDotSsh = $(mkRelDir ".ssh") relDirDotStackProgName :: Path Rel Dir relDirDotStackProgName = $(mkRelDir ('.' : stackProgName)) relDirUnderHome :: Path Rel Dir relDirUnderHome = $(mkRelDir "_home") relDirSrc :: Path Rel Dir relDirSrc = $(mkRelDir "src") relFileLibtinfoSo5 :: Path Rel File relFileLibtinfoSo5 = $(mkRelFile "libtinfo.so.5") relFileLibtinfoSo6 :: Path Rel File relFileLibtinfoSo6 = $(mkRelFile "libtinfo.so.6") relFileLibncurseswSo6 :: Path Rel File relFileLibncurseswSo6 = $(mkRelFile "libncursesw.so.6") relFileLibgmpSo10 :: Path Rel File relFileLibgmpSo10 = $(mkRelFile "libgmp.so.10") relFileLibgmpSo3 :: Path Rel File relFileLibgmpSo3 = $(mkRelFile "libgmp.so.3") relDirNewCabal :: Path Rel Dir relDirNewCabal = $(mkRelDir "new-cabal") relFileSetupExe :: Path Rel File relFileSetupExe = $(mkRelFile "Setup.exe") relFileSetupUpper :: Path Rel File relFileSetupUpper = $(mkRelFile "Setup") relFile7zexe :: Path Rel File relFile7zexe = $(mkRelFile "7z.exe") relFile7zdll :: Path Rel File relFile7zdll = $(mkRelFile "7z.dll") relFileMainHs :: Path Rel File relFileMainHs = $(mkRelFile "Main.hs") relFileStackDotExe :: Path Rel File relFileStackDotExe = $(mkRelFile "stack.exe") relFileStackDotTmpDotExe :: Path Rel File relFileStackDotTmpDotExe = $(mkRelFile "stack.tmp.exe") relFileStackDotTmp :: Path Rel File relFileStackDotTmp = $(mkRelFile "stack.tmp") relFileStack :: Path Rel File relFileStack = $(mkRelFile "stack") -- Technically, we should be consulting the user's current ghc, -- but that would require loading up a BuildConfig. ghcShowOptionsOutput :: [String] ghcShowOptionsOutput = $(TH.runIO (readProcess "ghc" ["--show-options"] "") >>= TH.lift . lines) -- | Relative paths inside a GHC repo to the Hadrian build batch script. -- The second path is maintained for compatibility with older GHC versions. hadrianScriptsWindows :: [Path Rel File] hadrianScriptsWindows = [$(mkRelFile "hadrian/build-stack.bat"), $(mkRelFile "hadrian/build.stack.bat")] -- | Relative paths inside a GHC repo to the Hadrian build shell script -- The second path is maintained for compatibility with older GHC versions. hadrianScriptsPosix :: [Path Rel File] hadrianScriptsPosix = [$(mkRelFile "hadrian/build-stack"), $(mkRelFile "hadrian/build.stack.sh")] -- | Used in Stack.Setup for detecting libtinfo, see comments at use site usrLibDirs :: [Path Abs Dir] #if WINDOWS usrLibDirs = [] #else usrLibDirs = [$(mkAbsDir "/usr/lib"),$(mkAbsDir "/usr/lib64")] #endif -- | Relative file path for a temporary GHC environment file for tests testGhcEnvRelFile :: Path Rel File testGhcEnvRelFile = $(mkRelFile "test-ghc-env") -- | File inside a dist directory to use for locking relFileBuildLock :: Path Rel File relFileBuildLock = $(mkRelFile "build-lock") -- | What should the default be for stack-developer-mode stackDeveloperModeDefault :: Bool stackDeveloperModeDefault = STACK_DEVELOPER_MODE_DEFAULT -- | The footer to the help for Stack's subcommands globalFooter :: String globalFooter = "Command 'stack --help' for global options that apply to all subcommands." stack-2.9.3.1/src/Stack/Constants/Config.hs0000644000000000000000000001474014445022466016545 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} module Stack.Constants.Config ( distDirFromDir , rootDistDirFromDir , setupConfigFromDir , workDirFromDir , distRelativeDir , imageStagingDir , projectDockerSandboxDir , configCabalMod , configSetupConfigMod , configPackageProjectRoot , buildCachesDir , testSuccessFile , testBuiltFile , hpcRelativeDir , hpcDirFromDir , objectInterfaceDirL , ghciDirL , templatesDir ) where import Path import Stack.Constants import Stack.Prelude import Stack.Types.Config -- | Output .o/.hi directory. objectInterfaceDirL :: HasBuildConfig env => Getting r env (Path Abs Dir) objectInterfaceDirL = to $ \env -> -- FIXME is this idiomatic lens code? let workDir = view workDirL env root = view projectRootL env in root workDir $(mkRelDir "odir/") -- | GHCi files directory. ghciDirL :: HasBuildConfig env => Getting r env (Path Abs Dir) ghciDirL = to $ \env -> -- FIXME is this idiomatic lens code? let workDir = view workDirL env root = view projectRootL env in root workDir $(mkRelDir "ghci/") -- | The directory containing the files used for dirtiness check of source files. buildCachesDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -- ^ Package directory. -> m (Path Abs Dir) buildCachesDir dir = liftM ( $(mkRelDir "stack-build-caches")) (distDirFromDir dir) -- | The filename used to mark tests as having succeeded testSuccessFile :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -- ^ Package directory -> m (Path Abs File) testSuccessFile dir = liftM ( $(mkRelFile "stack-test-success")) (distDirFromDir dir) -- | The filename used to mark tests as having built testBuiltFile :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -- ^ Package directory -> m (Path Abs File) testBuiltFile dir = liftM ( $(mkRelFile "stack-test-built")) (distDirFromDir dir) -- | The filename used for modification check of .cabal configCabalMod :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -- ^ Package directory. -> m (Path Abs File) configCabalMod dir = liftM ( $(mkRelFile "stack-cabal-mod")) (distDirFromDir dir) -- | The filename used for modification check of setup-config configSetupConfigMod :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -- ^ Package directory. -> m (Path Abs File) configSetupConfigMod dir = liftM ( $(mkRelFile "stack-setup-config-mod")) (distDirFromDir dir) -- | The filename used for the project root from the last build of a package configPackageProjectRoot :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -- ^ Package directory. -> m (Path Abs File) configPackageProjectRoot dir = liftM ( $(mkRelFile "stack-project-root")) (distDirFromDir dir) -- | Directory for HPC work. hpcDirFromDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -- ^ Package directory. -> m (Path Abs Dir) hpcDirFromDir fp = liftM (fp ) hpcRelativeDir -- | Relative location of directory for HPC work. hpcRelativeDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => m (Path Rel Dir) hpcRelativeDir = liftM ( $(mkRelDir "hpc")) distRelativeDir -- | Package's setup-config storing Cabal configuration setupConfigFromDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -> m (Path Abs File) setupConfigFromDir fp = do dist <- distDirFromDir fp pure $ dist $(mkRelFile "setup-config") -- | Package's build artifacts directory. distDirFromDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => Path Abs Dir -> m (Path Abs Dir) distDirFromDir fp = liftM (fp ) distRelativeDir -- | The directory containing all dist directories, including all -- different GHC/Cabal combos. rootDistDirFromDir :: (MonadReader env m, HasConfig env) => Path Abs Dir -> m (Path Abs Dir) rootDistDirFromDir fp = liftM (fp ) rootDistRelativeDir -- | Relative directory to the top dist directory, containing -- individual GHC/Cabal combo as subdirs. rootDistRelativeDir :: (MonadReader env m, HasConfig env) => m (Path Rel Dir) rootDistRelativeDir = do workDir <- view workDirL pure $ workDir $(mkRelDir "dist") -- | Package's working directory. workDirFromDir :: (MonadReader env m, HasConfig env) => Path Abs Dir -> m (Path Abs Dir) workDirFromDir fp = view $ workDirL.to (fp ) -- | Directory for project templates. templatesDir :: Config -> Path Abs Dir templatesDir config = view stackRootL config $(mkRelDir "templates") -- | Relative location of build artifacts. distRelativeDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => m (Path Rel Dir) distRelativeDir = do cabalPkgVer <- view cabalVersionL platform <- platformGhcRelDir -- Cabal version envDir <- parseRelDir $ packageIdentifierString $ PackageIdentifier cabalPackageName cabalPkgVer platformAndCabal <- useShaPathOnWindows (platform envDir) allDist <- rootDistRelativeDir pure $ allDist platformAndCabal -- | Docker sandbox from project root. projectDockerSandboxDir :: (MonadReader env m, HasConfig env) => Path Abs Dir -- ^ Project root -> m (Path Abs Dir) -- ^ Docker sandbox projectDockerSandboxDir projectRoot = do workDir <- view workDirL pure $ projectRoot workDir $(mkRelDir "docker/") -- | Image staging dir from project root. imageStagingDir :: (MonadReader env m, HasConfig env, MonadThrow m) => Path Abs Dir -- ^ Project root -> Int -- ^ Index of image -> m (Path Abs Dir) -- ^ Docker sandbox imageStagingDir projectRoot imageIdx = do workDir <- view workDirL idxRelDir <- parseRelDir (show imageIdx) pure $ projectRoot workDir $(mkRelDir "image") idxRelDir stack-2.9.3.1/src/Stack/Coverage.hs0000644000000000000000000006270114445022466015117 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} -- | Generate HPC (Haskell Program Coverage) reports module Stack.Coverage ( deleteHpcReports , updateTixFile , generateHpcReport , HpcReportOpts (..) , generateHpcReportForTargets , generateHpcUnifiedReport , generateHpcMarkupIndex ) where import qualified Data.ByteString.Char8 as S8 import qualified Data.ByteString.Lazy as BL import qualified Data.List as L import qualified Data.Map.Strict as Map import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.Lazy as LT import Distribution.Version ( mkVersion ) import Path import Path.Extra ( toFilePathNoTrailingSep ) import Path.IO import RIO.Process import Stack.Build.Target import Stack.Constants import Stack.Constants.Config import Stack.Package import Stack.Prelude import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.SourceMap import System.FilePath ( isPathSeparator ) import Trace.Hpc.Tix import Web.Browser (openBrowser) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Coverage" module. data CoverageException = NonTestSuiteTarget PackageName | NoTargetsOrTixSpecified | NotLocalPackage PackageName deriving (Show, Typeable) instance Exception CoverageException where displayException (NonTestSuiteTarget name) = concat [ "Error: [S-6361]\n" , "Can't specify anything except test-suites as hpc report targets (" , packageNameString name , ") is used with a non test-suite target." ] displayException NoTargetsOrTixSpecified = "Error: [S-2321]\n" ++ "Not generating combined report, because no targets or tix files \ \are specified." displayException (NotLocalPackage name) = concat [ "Error: [S-9975]" , "Expected a local package, but " , packageNameString name , " is either an extra-dep or in the snapshot." ] -- | Invoked at the beginning of running with "--coverage" deleteHpcReports :: HasEnvConfig env => RIO env () deleteHpcReports = do hpcDir <- hpcReportDir liftIO $ ignoringAbsence (removeDirRecur hpcDir) -- | Move a tix file into a sub-directory of the hpc report directory. Deletes -- the old one if one is present. updateTixFile :: HasEnvConfig env => PackageName -> Path Abs File -> String -> RIO env () updateTixFile pkgName' tixSrc testName = do exists <- doesFileExist tixSrc when exists $ do tixDest <- tixFilePath pkgName' testName liftIO $ ignoringAbsence (removeFile tixDest) ensureDir (parent tixDest) -- Remove exe modules because they are problematic. This could be -- revisited if there's a GHC version that fixes -- https://ghc.haskell.org/trac/ghc/ticket/1853 mtix <- readTixOrLog tixSrc case mtix of Nothing -> logError $ "Error: [S-2887]\n" <> "Failed to read " <> fromString (toFilePath tixSrc) Just tix -> do liftIO $ writeTix (toFilePath tixDest) (removeExeModules tix) -- TODO: ideally we'd do a file move, but IIRC this can -- have problems. Something about moving between drives -- on windows? copyFile tixSrc =<< parseAbsFile (toFilePath tixDest ++ ".premunging") liftIO $ ignoringAbsence (removeFile tixSrc) -- | Get the directory used for hpc reports for the given pkgId. hpcPkgPath :: HasEnvConfig env => PackageName -> RIO env (Path Abs Dir) hpcPkgPath pkgName' = do outputDir <- hpcReportDir pkgNameRel <- parseRelDir (packageNameString pkgName') pure (outputDir pkgNameRel) -- | Get the tix file location, given the name of the file (without extension), -- and the package identifier string. tixFilePath :: HasEnvConfig env => PackageName -> String -> RIO env (Path Abs File) tixFilePath pkgName' testName = do pkgPath <- hpcPkgPath pkgName' tixRel <- parseRelFile (testName ++ "/" ++ testName ++ ".tix") pure (pkgPath tixRel) -- | Generates the HTML coverage report and shows a textual coverage summary for a package. generateHpcReport :: HasEnvConfig env => Path Abs Dir -> Package -> [Text] -> RIO env () generateHpcReport pkgDir package tests = do compilerVersion <- view actualCompilerVersionL -- If we're using > GHC 7.10, the hpc 'include' parameter must specify a ghc package key. See -- https://github.com/commercialhaskell/stack/issues/785 let pkgName' = T.pack $ packageNameString (packageName package) pkgId = packageIdentifierString (packageIdentifier package) ghcVersion = getGhcVersion compilerVersion hasLibrary = case packageLibraries package of NoLibraries -> False HasLibraries _ -> True internalLibs = packageInternalLibraries package eincludeName <- -- Pre-7.8 uses plain PKG-version in tix files. if ghcVersion < mkVersion [7, 10] then pure $ Right $ Just [pkgId] -- We don't expect to find a package key if there is no library. else if not hasLibrary && Set.null internalLibs then pure $ Right Nothing -- Look in the inplace DB for the package key. -- See https://github.com/commercialhaskell/stack/issues/1181#issuecomment-148968986 else do -- GHC 8.0 uses package id instead of package key. -- See https://github.com/commercialhaskell/stack/issues/2424 let hpcNameField = if ghcVersion >= mkVersion [8, 0] then "id" else "key" eincludeName <- findPackageFieldForBuiltPackage pkgDir (packageIdentifier package) internalLibs hpcNameField case eincludeName of Left err -> do logError $ display err pure $ Left err Right includeNames -> pure $ Right $ Just $ map T.unpack includeNames forM_ tests $ \testName -> do tixSrc <- tixFilePath (packageName package) (T.unpack testName) let report = "coverage report for " <> pkgName' <> "'s test-suite \"" <> testName <> "\"" reportDir = parent tixSrc case eincludeName of Left err -> generateHpcErrorReport reportDir (display (sanitize (T.unpack err))) -- Restrict to just the current library code, if there is a library in the package (see -- #634 - this will likely be customizable in the future) Right mincludeName -> do let extraArgs = case mincludeName of Nothing -> [] Just includeNames -> "--include" : L.intersperse "--include" (map (\n -> n ++ ":") includeNames) mreportPath <- generateHpcReportInternal tixSrc reportDir report extraArgs extraArgs forM_ mreportPath (displayReportPath "The" report . pretty) generateHpcReportInternal :: HasEnvConfig env => Path Abs File -> Path Abs Dir -> Text -> [String] -> [String] -> RIO env (Maybe (Path Abs File)) generateHpcReportInternal tixSrc reportDir report extraMarkupArgs extraReportArgs = do -- If a .tix file exists, move it to the HPC output directory and generate a -- report for it. tixFileExists <- doesFileExist tixSrc if not tixFileExists then do logError $ "Error: [S-4634]\n" <> "Didn't find .tix for " <> display report <> " - expected to find it at " <> fromString (toFilePath tixSrc) <> "." pure Nothing else (`catch` \(err :: ProcessException) -> do logError $ displayShow err generateHpcErrorReport reportDir $ display $ sanitize $ displayException err pure Nothing) $ (`onException` logError ("Error: [S-8215]\n" <> "Error occurred while producing " <> display report)) $ do -- Directories for .mix files. hpcRelDir <- hpcRelativeDir -- Compute arguments used for both "hpc markup" and "hpc report". pkgDirs <- view $ buildConfigL.to (map ppRoot . Map.elems . smwProject . bcSMWanted) let args = -- Use index files from all packages (allows cross-package coverage results). concatMap (\x -> ["--srcdir", toFilePathNoTrailingSep x]) pkgDirs ++ -- Look for index files in the correct dir (relative to each pkgdir). ["--hpcdir", toFilePathNoTrailingSep hpcRelDir, "--reset-hpcdirs"] logInfo $ "Generating " <> display report outputLines <- liftM (map (S8.filter (/= '\r')) . S8.lines . BL.toStrict . fst) $ proc "hpc" ( "report" : toFilePath tixSrc : (args ++ extraReportArgs) ) readProcess_ if all ("(0/0)" `S8.isSuffixOf`) outputLines then do let msg html = "Error: [S-6829]\n"<> "The " <> display report <> " did not consider any code. One possible cause of this is" <> " if your test-suite builds the library code (see Stack " <> (if html then "" else "") <> "issue #1008" <> (if html then "" else "") <> "). It may also indicate a bug in Stack or" <> " the hpc program. Please report this issue if you think" <> " your coverage report should have meaningful results." logError (msg False) generateHpcErrorReport reportDir (msg True) pure Nothing else do let reportPath = reportDir relFileHpcIndexHtml -- Print output, stripping @\r@ characters because Windows. forM_ outputLines (logInfo . displayBytesUtf8) -- Generate the markup. void $ proc "hpc" ( "markup" : toFilePath tixSrc : ("--destdir=" ++ toFilePathNoTrailingSep reportDir) : (args ++ extraMarkupArgs) ) readProcess_ pure (Just reportPath) data HpcReportOpts = HpcReportOpts { hroptsInputs :: [Text] , hroptsAll :: Bool , hroptsDestDir :: Maybe String , hroptsOpenBrowser :: Bool } deriving (Show) generateHpcReportForTargets :: HasEnvConfig env => HpcReportOpts -> [Text] -> [Text] -> RIO env () generateHpcReportForTargets opts tixFiles targetNames = do targetTixFiles <- -- When there aren't any package component arguments, and --all -- isn't passed, default to not considering any targets. if not (hroptsAll opts) && null targetNames then pure [] else do when (hroptsAll opts && not (null targetNames)) $ logWarn $ "Since --all is used, it is redundant to specify these targets: " <> displayShow targetNames targets <- view $ envConfigL.to envConfigSourceMap.to smTargets.to smtTargets liftM concat $ forM (Map.toList targets) $ \(name, target) -> case target of TargetAll PTDependency -> throwIO $ NotLocalPackage name TargetComps comps -> do pkgPath <- hpcPkgPath name forM (toList comps) $ \nc -> case nc of CTest testName -> liftM (pkgPath ) $ parseRelFile (T.unpack testName ++ "/" ++ T.unpack testName ++ ".tix") _ -> throwIO $ NonTestSuiteTarget name TargetAll PTProject -> do pkgPath <- hpcPkgPath name exists <- doesDirExist pkgPath if exists then do (dirs, _) <- listDir pkgPath liftM concat $ forM dirs $ \dir -> do (_, files) <- listDir dir pure (filter ((".tix" `L.isSuffixOf`) . toFilePath) files) else pure [] tixPaths <- liftM (\xs -> xs ++ targetTixFiles) $ mapM (resolveFile' . T.unpack) tixFiles when (null tixPaths) $ throwIO NoTargetsOrTixSpecified outputDir <- hpcReportDir reportDir <- case hroptsDestDir opts of Nothing -> pure (outputDir relDirCombined relDirCustom) Just destDir -> do dest <- resolveDir' destDir ensureDir dest pure dest let report = "combined report" mreportPath <- generateUnionReport report reportDir tixPaths forM_ mreportPath $ \reportPath -> if hroptsOpenBrowser opts then do prettyInfo $ "Opening" <+> pretty reportPath <+> "in the browser." void $ liftIO $ openBrowser (toFilePath reportPath) else displayReportPath "The" report (pretty reportPath) generateHpcUnifiedReport :: HasEnvConfig env => RIO env () generateHpcUnifiedReport = do outputDir <- hpcReportDir ensureDir outputDir (dirs, _) <- listDir outputDir tixFiles0 <- liftM (concat . concat) $ forM (filter (("combined" /=) . dirnameString) dirs) $ \dir -> do (dirs', _) <- listDir dir forM dirs' $ \dir' -> do (_, files) <- listDir dir' pure (filter ((".tix" `L.isSuffixOf`) . toFilePath) files) extraTixFiles <- findExtraTixFiles let tixFiles = tixFiles0 ++ extraTixFiles reportDir = outputDir relDirCombined relDirAll -- Previously, the test below was: -- -- if length tixFiles < 2 -- then logInfo $ -- (if null tixFiles then "No tix files" else "Only one tix file") <> -- " found in " <> -- fromString (toFilePath outputDir) <> -- ", so not generating a unified coverage report." -- else ... -- -- However, a single *.tix file does not necessarily mean that a unified -- coverage report is redundant. For example, one package may test the library -- of another package that does not test its own library. See -- https://github.com/commercialhaskell/stack/issues/5713 -- -- As an interim solution, a unified coverage report will always be produced -- even if may be redundant in some circumstances. if null tixFiles then logInfo $ "No tix files found in " <> fromString (toFilePath outputDir) <> ", so not generating a unified coverage report." else do let report = "unified report" mreportPath <- generateUnionReport report reportDir tixFiles forM_ mreportPath (displayReportPath "The" report . pretty) generateUnionReport :: HasEnvConfig env => Text -> Path Abs Dir -> [Path Abs File] -> RIO env (Maybe (Path Abs File)) generateUnionReport report reportDir tixFiles = do (errs, tix) <- fmap (unionTixes . map removeExeModules) (mapMaybeM readTixOrLog tixFiles) logDebug $ "Using the following tix files: " <> fromString (show tixFiles) unless (null errs) $ logWarn $ "The following modules are left out of the " <> display report <> " due to version mismatches: " <> mconcat (L.intersperse ", " (map fromString errs)) tixDest <- liftM (reportDir ) $ parseRelFile (dirnameString reportDir ++ ".tix") ensureDir (parent tixDest) liftIO $ writeTix (toFilePath tixDest) tix generateHpcReportInternal tixDest reportDir report [] [] readTixOrLog :: HasLogFunc env => Path b File -> RIO env (Maybe Tix) readTixOrLog path = do mtix <- liftIO (readTix (toFilePath path)) `catchAny` \errorCall -> do logError $ "Error: [S-3521]\n" <> "Error while reading tix: " <> fromString (displayException errorCall) pure Nothing when (isNothing mtix) $ logError $ "Error: [S-7786]\n" <> "Failed to read tix file " <> fromString (toFilePath path) pure mtix -- | Module names which contain '/' have a package name, and so they weren't built into the -- executable. removeExeModules :: Tix -> Tix removeExeModules (Tix ms) = Tix (filter (\(TixModule name _ _ _) -> '/' `elem` name) ms) unionTixes :: [Tix] -> ([String], Tix) unionTixes tixes = (Map.keys errs, Tix (Map.elems outputs)) where (errs, outputs) = Map.mapEither id $ Map.unionsWith merge $ map toMap tixes toMap (Tix ms) = Map.fromList (map (\x@(TixModule k _ _ _) -> (k, Right x)) ms) merge (Right (TixModule k hash1 len1 tix1)) (Right (TixModule _ hash2 len2 tix2)) | hash1 == hash2 && len1 == len2 = Right (TixModule k hash1 len1 (zipWith (+) tix1 tix2)) merge _ _ = Left () generateHpcMarkupIndex :: HasEnvConfig env => RIO env () generateHpcMarkupIndex = do outputDir <- hpcReportDir let outputFile = outputDir relFileIndexHtml ensureDir outputDir (dirs, _) <- listDir outputDir rows <- liftM (catMaybes . concat) $ forM dirs $ \dir -> do (subdirs, _) <- listDir dir forM subdirs $ \subdir -> do let indexPath = subdir relFileHpcIndexHtml exists' <- doesFileExist indexPath if not exists' then pure Nothing else do relPath <- stripProperPrefix outputDir indexPath let package = dirname dir testsuite = dirname subdir pure $ Just $ T.concat [ "" , pathToHtml package , "" , pathToHtml testsuite , "" ] writeBinaryFileAtomic outputFile $ "" <> -- Part of the css from HPC's output HTML "" <> "" <> "" <> (if null rows then "No hpc_index.html files found in \"" <> encodeUtf8Builder (pathToHtml outputDir) <> "\"." else "" <> "

NOTE: This is merely a listing of the html files found in the coverage reports directory. Some of these reports may be old.

" <> "" <> foldMap encodeUtf8Builder rows <> "
PackageTestSuiteModification Time
") <> "" unless (null rows) $ displayReportPath "\nAn" "index of the generated HTML coverage reports" (pretty outputFile) generateHpcErrorReport :: MonadIO m => Path Abs Dir -> Utf8Builder -> m () generateHpcErrorReport dir err = do ensureDir dir let fp = toFilePath (dir relFileHpcIndexHtml) writeFileUtf8Builder fp $ "" <> "

HPC Report Generation Error

" <> "

" <> err <> "

" <> "" pathToHtml :: Path b t -> Text pathToHtml = T.dropWhileEnd (=='/') . sanitize . toFilePath -- | Escape HTML symbols (copied from Text.Hastache) htmlEscape :: LT.Text -> LT.Text htmlEscape = LT.concatMap proc_ where proc_ '&' = "&" proc_ '\\' = "\" proc_ '"' = """ proc_ '\'' = "'" proc_ '<' = "<" proc_ '>' = ">" proc_ h = LT.singleton h sanitize :: String -> Text sanitize = LT.toStrict . htmlEscape . LT.pack dirnameString :: Path r Dir -> String dirnameString = L.dropWhileEnd isPathSeparator . toFilePath . dirname findPackageFieldForBuiltPackage :: HasEnvConfig env => Path Abs Dir -> PackageIdentifier -> Set.Set Text -> Text -> RIO env (Either Text [Text]) findPackageFieldForBuiltPackage pkgDir pkgId internalLibs field = do distDir <- distDirFromDir pkgDir let inplaceDir = distDir relDirPackageConfInplace pkgIdStr = packageIdentifierString pkgId notFoundErr = pure $ Left $ "Failed to find package key for " <> T.pack pkgIdStr extractField path = do contents <- readFileUtf8 (toFilePath path) case asum (map (T.stripPrefix (field <> ": ")) (T.lines contents)) of Just result -> pure $ Right $ T.strip result Nothing -> notFoundErr cabalVer <- view cabalVersionL if cabalVer < mkVersion [1, 24] then do -- here we don't need to handle internal libs path <- liftM (inplaceDir ) $ parseRelFile (pkgIdStr ++ "-inplace.conf") logDebug $ "Parsing config in Cabal < 1.24 location: " <> fromString (toFilePath path) exists <- doesFileExist path if exists then fmap (:[]) <$> extractField path else notFoundErr else do -- With Cabal-1.24, it's in a different location. logDebug $ "Scanning " <> fromString (toFilePath inplaceDir) <> " for files matching " <> fromString pkgIdStr (_, files) <- handleIO (const $ pure ([], [])) $ listDir inplaceDir logDebug $ displayShow files -- From all the files obtained from the scanning process above, we -- need to identify which are .conf files and then ensure that -- there is at most one .conf file for each library and internal -- library (some might be missing if that component has not been -- built yet). We should error if there are more than one .conf -- file for a component or if there are no .conf files at all in -- the searched location. let toFilename = T.pack . toFilePath . filename -- strip known prefix and suffix from the found files to determine only the conf files stripKnown = T.stripSuffix ".conf" <=< T.stripPrefix (T.pack (pkgIdStr ++ "-")) stripped = mapMaybe (\file -> fmap (,file) . stripKnown . toFilename $ file) files -- which component could have generated each of these conf files stripHash n = let z = T.dropWhile (/= '-') n in if T.null z then "" else T.tail z matchedComponents = map (\(n, f) -> (stripHash n, [f])) stripped byComponents = Map.restrictKeys (Map.fromListWith (++) matchedComponents) $ Set.insert "" internalLibs logDebug $ displayShow byComponents if Map.null $ Map.filter (\fs -> length fs > 1) byComponents then case concat $ Map.elems byComponents of [] -> notFoundErr -- for each of these files, we need to extract the requested field paths -> do (errors, keys) <- partitionEithers <$> traverse extractField paths case errors of (a:_) -> pure $ Left a -- the first error only, since they're repeated anyway [] -> pure $ Right keys else pure $ Left $ "Multiple files matching " <> T.pack (pkgIdStr ++ "-*.conf") <> " found in " <> T.pack (toFilePath inplaceDir) <> ". Maybe try 'stack clean' on this package?" displayReportPath :: (HasTerm env) => StyleDoc -> Text -> StyleDoc -> RIO env () displayReportPath prefix report reportPath = prettyInfo $ prefix <+> fromString (T.unpack report) <+> "is available at" <+> reportPath findExtraTixFiles :: HasEnvConfig env => RIO env [Path Abs File] findExtraTixFiles = do outputDir <- hpcReportDir let dir = outputDir relDirExtraTixFiles dirExists <- doesDirExist dir if dirExists then do (_, files) <- listDir dir pure $ filter ((".tix" `L.isSuffixOf`) . toFilePath) files else pure [] stack-2.9.3.1/src/Stack/DefaultColorWhen.hs0000644000000000000000000000214014445022466016560 0ustar0000000000000000module Stack.DefaultColorWhen ( defaultColorWhen ) where import Stack.Prelude ( stdout ) import Stack.Types.Config ( ColorWhen (ColorAuto, ColorNever) ) import System.Console.ANSI ( hSupportsANSIWithoutEmulation ) import System.Environment ( lookupEnv ) -- | The default adopts the standard proposed at http://no-color.org/, that -- color should not be added by default if the @NO_COLOR@ environment variable -- is present. defaultColorWhen :: IO ColorWhen defaultColorWhen = do -- On Windows, 'hSupportsANSIWithoutEmulation' has the side effect of enabling -- ANSI for ANSI-capable native (ConHost) terminals, if not already -- ANSI-enabled. Consequently, it is actioned even if @NO_COLOR@ might exist, -- as @NO_COLOR@ might be overridden in a yaml configuration file or at the -- command line. supportsANSI <- hSupportsANSIWithoutEmulation stdout mIsNoColor <- lookupEnv "NO_COLOR" pure $ case mIsNoColor of Just _ -> ColorNever _ -> case supportsANSI of Just False -> ColorNever _ -> ColorAuto stack-2.9.3.1/src/Stack/Docker.hs0000644000000000000000000006555114445111644014576 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Run commands in Docker containers module Stack.Docker ( dockerCmdName , dockerHelpOptName , dockerPullCmdName , entrypoint , preventInContainer , pull , reset , reExecArgName , DockerException (..) , getProjectRoot , runContainerAndExit ) where import qualified Crypto.Hash as Hash ( Digest, MD5, hash ) import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as LBS import Data.Char ( isAscii, isDigit ) import Data.Conduit.List ( sinkNull ) import Data.Conduit.Process.Typed hiding ( proc ) import Data.List ( dropWhileEnd, isInfixOf, isPrefixOf ) import Data.List.Extra ( trim ) import qualified Data.Map.Strict as Map import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Time ( UTCTime ) import qualified Data.Version ( parseVersion ) import Distribution.Version ( mkVersion, mkVersion' ) import Pantry.Internal.AesonExtended ( FromJSON (..), (.:), (.:?), (.!=), eitherDecode ) import Path import Path.Extra ( toFilePathNoTrailingSep ) import Path.IO hiding ( canonicalizePath ) import qualified RIO.Directory import RIO.Process import Stack.Config ( getInContainer ) import Stack.Constants import Stack.Constants.Config import Stack.Prelude import Stack.Setup ( ensureDockerStackExe ) import Stack.Storage.User ( loadDockerImageExeCache, saveDockerImageExeCache ) import Stack.Types.Config import Stack.Types.Docker import Stack.Types.Version ( showStackVersion, withinRange ) import System.Environment ( getArgs, getEnv, getEnvironment, getExecutablePath , getProgName ) import qualified System.FilePath as FP import System.IO.Error ( isDoesNotExistError ) import System.IO.Unsafe ( unsafePerformIO ) #ifndef WINDOWS import System.Posix.Signals import qualified System.Posix.User as PosixUser #endif import System.Posix.User as User import qualified System.PosixCompat.Files as Files import System.Terminal ( hIsTerminalDeviceOrMinTTY ) import Text.ParserCombinators.ReadP ( readP_to_S ) -- | Function to get command and arguments to run in Docker container getCmdArgs :: HasConfig env => DockerOpts -> Inspect -> Bool -> RIO env (FilePath,[String],[(String,String)],[Mount]) getCmdArgs docker imageInfo isRemoteDocker = do config <- view configL deUser <- if fromMaybe (not isRemoteDocker) (dockerSetUser docker) then liftIO $ do duUid <- User.getEffectiveUserID duGid <- User.getEffectiveGroupID duGroups <- nubOrd <$> User.getGroups duUmask <- Files.setFileCreationMask 0o022 -- Only way to get old umask seems to be to change it, so set it back afterward _ <- Files.setFileCreationMask duUmask pure (Just DockerUser{..}) else pure Nothing args <- fmap (["--" ++ reExecArgName ++ "=" ++ showStackVersion ,"--" ++ dockerEntrypointArgName ,show DockerEntrypoint{..}] ++) (liftIO getArgs) case dockerStackExe (configDocker config) of Just DockerStackExeHost | configPlatform config == dockerContainerPlatform -> do exePath <- resolveFile' =<< liftIO getExecutablePath cmdArgs args exePath | otherwise -> throwIO UnsupportedStackExeHostPlatformException Just DockerStackExeImage -> do progName <- liftIO getProgName pure (FP.takeBaseName progName, args, [], []) Just (DockerStackExePath path) -> do cmdArgs args path Just DockerStackExeDownload -> exeDownload args Nothing | configPlatform config == dockerContainerPlatform -> do (exePath,exeTimestamp,misCompatible) <- do exePath <- resolveFile' =<< liftIO getExecutablePath exeTimestamp <- getModificationTime exePath isKnown <- loadDockerImageExeCache (iiId imageInfo) exePath exeTimestamp pure (exePath, exeTimestamp, isKnown) case misCompatible of Just True -> cmdArgs args exePath Just False -> exeDownload args Nothing -> do e <- try $ sinkProcessStderrStdout "docker" [ "run" , "-v" , toFilePath exePath ++ ":" ++ "/tmp/stack" , T.unpack (iiId imageInfo) , "/tmp/stack" , "--version"] sinkNull sinkNull let compatible = case e of Left ExitCodeException{} -> False Right _ -> True saveDockerImageExeCache (iiId imageInfo) exePath exeTimestamp compatible if compatible then cmdArgs args exePath else exeDownload args Nothing -> exeDownload args where exeDownload args = do exePath <- ensureDockerStackExe dockerContainerPlatform cmdArgs args exePath cmdArgs args exePath = do -- MSS 2020-04-21 previously used replaceExtension, but semantics changed in path 0.7 -- In any event, I'm not even sure _why_ we need to drop a file extension here -- Originally introduced here: https://github.com/commercialhaskell/stack/commit/6218dadaf5fd7bf312bb1bd0db63b4784ba78cb2 let exeBase = case splitExtension exePath of Left _ -> exePath Right (x, _) -> x let mountPath = hostBinDir FP. toFilePath (filename exeBase) pure (mountPath, args, [], [Mount (toFilePath exePath) mountPath]) -- | Error if running in a container. preventInContainer :: MonadIO m => m () -> m () preventInContainer inner = do inContainer <- getInContainer if inContainer then throwIO OnlyOnHostException else inner -- | Run a command in a new Docker container, then exit the process. runContainerAndExit :: HasConfig env => RIO env void runContainerAndExit = do config <- view configL let docker = configDocker config checkDockerVersion docker (env,isStdinTerminal,isStderrTerminal,homeDir) <- liftIO $ (,,,) <$> getEnvironment <*> hIsTerminalDeviceOrMinTTY stdin <*> hIsTerminalDeviceOrMinTTY stderr <*> getHomeDir isStdoutTerminal <- view terminalL let dockerHost = lookup "DOCKER_HOST" env dockerCertPath = lookup "DOCKER_CERT_PATH" env bamboo = lookup "bamboo_buildKey" env jenkins = lookup "JENKINS_HOME" env msshAuthSock = lookup "SSH_AUTH_SOCK" env muserEnv = lookup "USER" env isRemoteDocker = maybe False (isPrefixOf "tcp://") dockerHost mstackYaml <- for (lookup "STACK_YAML" env) RIO.Directory.makeAbsolute image <- either throwIO pure (dockerImage docker) when (isRemoteDocker && maybe False (isInfixOf "boot2docker") dockerCertPath) (logWarn "Warning: Using boot2docker is NOT supported, and not likely to perform well.") maybeImageInfo <- inspect image imageInfo@Inspect{..} <- case maybeImageInfo of Just ii -> pure ii Nothing | dockerAutoPull docker -> do pullImage docker image mii2 <- inspect image case mii2 of Just ii2 -> pure ii2 Nothing -> throwM (InspectFailedException image) | otherwise -> throwM (NotPulledException image) projectRoot <- getProjectRoot sandboxDir <- projectDockerSandboxDir projectRoot let ImageConfig {..} = iiConfig imageEnvVars = map (break (== '=')) icEnv platformVariant = show $ hashRepoName image stackRoot = view stackRootL config sandboxHomeDir = sandboxDir homeDirName isTerm = not (dockerDetach docker) && isStdinTerminal && isStdoutTerminal && isStderrTerminal keepStdinOpen = not (dockerDetach docker) && -- Workaround for https://github.com/docker/docker/issues/12319 -- This is fixed in Docker 1.9.1, but will leave the workaround -- in place for now, for users who haven't upgraded yet. (isTerm || (isNothing bamboo && isNothing jenkins)) let mpath = T.pack <$> lookupImageEnv "PATH" imageEnvVars when (isNothing mpath) $ do logWarn "The Docker image does not set the PATH env var" logWarn "This will likely fail, see https://github.com/commercialhaskell/stack/issues/2742" newPathEnv <- either throwM pure $ augmentPath [ hostBinDir , toFilePath (sandboxHomeDir relDirDotLocal relDirBin)] mpath (cmnd,args,envVars,extraMount) <- getCmdArgs docker imageInfo isRemoteDocker pwd <- getCurrentDir liftIO $ mapM_ ensureDir [sandboxHomeDir, stackRoot] -- Since $HOME is now mounted in the same place in the container we can -- just symlink $HOME/.ssh to the right place for the stack docker user let sshDir = homeDir sshRelDir sshDirExists <- doesDirExist sshDir sshSandboxDirExists <- liftIO (Files.fileExist (toFilePathNoTrailingSep (sandboxHomeDir sshRelDir))) when (sshDirExists && not sshSandboxDirExists) (liftIO (Files.createSymbolicLink (toFilePathNoTrailingSep sshDir) (toFilePathNoTrailingSep (sandboxHomeDir sshRelDir)))) let mountSuffix = maybe "" (":" ++) (dockerMountMode docker) containerID <- withWorkingDir (toFilePath projectRoot) $ trim . decodeUtf8 <$> readDockerProcess (concat [["create" ,"-e",inContainerEnvVar ++ "=1" ,"-e",stackRootEnvVar ++ "=" ++ toFilePathNoTrailingSep stackRoot ,"-e",platformVariantEnvVar ++ "=dk" ++ platformVariant ,"-e","HOME=" ++ toFilePathNoTrailingSep sandboxHomeDir ,"-e","PATH=" ++ T.unpack newPathEnv ,"-e","PWD=" ++ toFilePathNoTrailingSep pwd ,"-v",toFilePathNoTrailingSep homeDir ++ ":" ++ toFilePathNoTrailingSep homeDir ++ mountSuffix ,"-v",toFilePathNoTrailingSep stackRoot ++ ":" ++ toFilePathNoTrailingSep stackRoot ++ mountSuffix ,"-v",toFilePathNoTrailingSep projectRoot ++ ":" ++ toFilePathNoTrailingSep projectRoot ++ mountSuffix ,"-v",toFilePathNoTrailingSep sandboxHomeDir ++ ":" ++ toFilePathNoTrailingSep sandboxHomeDir ++ mountSuffix ,"-w",toFilePathNoTrailingSep pwd] ,case dockerNetwork docker of Nothing -> ["--net=host"] Just name -> ["--net=" ++ name] ,case muserEnv of Nothing -> [] Just userEnv -> ["-e","USER=" ++ userEnv] ,case msshAuthSock of Nothing -> [] Just sshAuthSock -> ["-e","SSH_AUTH_SOCK=" ++ sshAuthSock ,"-v",sshAuthSock ++ ":" ++ sshAuthSock] ,case mstackYaml of Nothing -> [] Just stackYaml -> ["-e","STACK_YAML=" ++ stackYaml ,"-v",stackYaml++ ":" ++ stackYaml ++ ":ro"] -- Disable the deprecated entrypoint in FP Complete-generated images ,["--entrypoint=/usr/bin/env" | isJust (lookupImageEnv oldSandboxIdEnvVar imageEnvVars) && (icEntrypoint == ["/usr/local/sbin/docker-entrypoint"] || icEntrypoint == ["/root/entrypoint.sh"])] ,concatMap (\(k,v) -> ["-e", k ++ "=" ++ v]) envVars ,concatMap (mountArg mountSuffix) (extraMount ++ dockerMount docker) ,concatMap (\nv -> ["-e", nv]) (dockerEnv docker) ,case dockerContainerName docker of Just name -> ["--name=" ++ name] Nothing -> [] ,["-t" | isTerm] ,["-i" | keepStdinOpen] ,dockerRunArgs docker ,[image] ,[cmnd] ,args]) -- MSS 2018-08-30 can the CPP below be removed entirely, and instead exec the -- `docker` process so that it can handle the signals directly? #ifndef WINDOWS run <- askRunInIO oldHandlers <- forM [sigINT,sigABRT,sigHUP,sigPIPE,sigTERM,sigUSR1,sigUSR2] $ \sig -> do let sigHandler = run $ do readProcessNull "docker" ["kill","--signal=" ++ show sig,containerID] when (sig `elem` [sigTERM,sigABRT]) $ do -- Give the container 30 seconds to exit gracefully, then send a sigKILL to force it threadDelay 30000000 readProcessNull "docker" ["kill",containerID] oldHandler <- liftIO $ installHandler sig (Catch sigHandler) Nothing pure (sig, oldHandler) #endif let args' = concat [["start"] ,["-a" | not (dockerDetach docker)] ,["-i" | keepStdinOpen] ,[containerID]] e <- try (proc "docker" args' $ runProcess_ . setDelegateCtlc False) `finally` (do unless (dockerPersist docker || dockerDetach docker) $ readProcessNull "docker" ["rm","-f",containerID] `catch` (\(_::ExitCodeException) -> pure ()) #ifndef WINDOWS forM_ oldHandlers $ \(sig,oldHandler) -> liftIO $ installHandler sig oldHandler Nothing #endif ) case e of Left ExitCodeException{eceExitCode} -> exitWith eceExitCode Right () -> exitSuccess where -- This is using a hash of the Docker repository (without tag or digest) to ensure -- binaries/libraries aren't shared between Docker and host (or incompatible Docker images) hashRepoName :: String -> Hash.Digest Hash.MD5 hashRepoName = Hash.hash . BS.pack . takeWhile (\c -> c /= ':' && c /= '@') lookupImageEnv name vars = case lookup name vars of Just ('=':val) -> Just val _ -> Nothing mountArg mountSuffix (Mount host container) = ["-v",host ++ ":" ++ container ++ mountSuffix] sshRelDir = relDirDotSsh -- | Inspect Docker image or container. inspect :: (HasProcessContext env, HasLogFunc env) => String -> RIO env (Maybe Inspect) inspect image = do results <- inspects [image] case Map.toList results of [] -> pure Nothing [(_,i)] -> pure (Just i) _ -> throwIO (InvalidInspectOutputException "expect a single result") -- | Inspect multiple Docker images and/or containers. inspects :: (HasProcessContext env, HasLogFunc env) => [String] -> RIO env (Map Text Inspect) inspects [] = pure Map.empty inspects images = do maybeInspectOut <- -- not using 'readDockerProcess' as the error from a missing image -- needs to be recovered. try (BL.toStrict . fst <$> proc "docker" ("inspect" : images) readProcess_) case maybeInspectOut of Right inspectOut -> -- filtering with 'isAscii' to workaround @docker inspect@ output containing invalid UTF-8 case eitherDecode (LBS.pack (filter isAscii (decodeUtf8 inspectOut))) of Left msg -> throwIO (InvalidInspectOutputException msg) Right results -> pure (Map.fromList (map (\r -> (iiId r,r)) results)) Left ece | any (`LBS.isPrefixOf` eceStderr ece) missingImagePrefixes -> pure Map.empty Left e -> throwIO e where missingImagePrefixes = ["Error: No such image", "Error: No such object:"] -- | Pull latest version of configured Docker image from registry. pull :: HasConfig env => RIO env () pull = do config <- view configL let docker = configDocker config checkDockerVersion docker either throwIO (pullImage docker) (dockerImage docker) -- | Pull Docker image from registry. pullImage :: (HasProcessContext env, HasLogFunc env) => DockerOpts -> String -> RIO env () pullImage docker image = do logInfo ("Pulling image from registry: '" <> fromString image <> "'") when (dockerRegistryLogin docker) (do logInfo "You may need to log in." proc "docker" (concat [["login"] ,maybe [] (\n -> ["--username=" ++ n]) (dockerRegistryUsername docker) ,maybe [] (\p -> ["--password=" ++ p]) (dockerRegistryPassword docker) ,[takeWhile (/= '/') image]]) runProcess_) -- We redirect the stdout of the process to stderr so that the output -- of @docker pull@ will not interfere with the output of other -- commands when using --auto-docker-pull. See issue #2733. ec <- proc "docker" ["pull", image] $ \pc0 -> do let pc = setStdout (useHandleOpen stderr) $ setStderr (useHandleOpen stderr) $ setStdin closed pc0 runProcess pc case ec of ExitSuccess -> pure () ExitFailure _ -> throwIO (PullFailedException image) -- | Check docker version (throws exception if incorrect) checkDockerVersion :: (HasProcessContext env, HasLogFunc env) => DockerOpts -> RIO env () checkDockerVersion docker = do dockerExists <- doesExecutableExist "docker" unless dockerExists (throwIO DockerNotInstalledException) dockerVersionOut <- readDockerProcess ["--version"] case words (decodeUtf8 dockerVersionOut) of (_:_:v:_) -> case fmap mkVersion' $ parseVersion' $ stripVersion v of Just v' | v' < minimumDockerVersion -> throwIO (DockerTooOldException minimumDockerVersion v') | v' `elem` prohibitedDockerVersions -> throwIO (DockerVersionProhibitedException prohibitedDockerVersions v') | not (v' `withinRange` dockerRequireDockerVersion docker) -> throwIO (BadDockerVersionException (dockerRequireDockerVersion docker) v') | otherwise -> pure () _ -> throwIO InvalidVersionOutputException _ -> throwIO InvalidVersionOutputException where minimumDockerVersion = mkVersion [1, 6, 0] prohibitedDockerVersions = [] stripVersion v = takeWhile (/= '-') (dropWhileEnd (not . isDigit) v) -- version is parsed by Data.Version provided code to avoid -- Cabal's Distribution.Version lack of support for leading zeros in version parseVersion' = fmap fst . listToMaybe . reverse . readP_to_S Data.Version.parseVersion -- | Remove the project's Docker sandbox. reset :: HasConfig env => Bool -> RIO env () reset keepHome = do projectRoot <- getProjectRoot dockerSandboxDir <- projectDockerSandboxDir projectRoot liftIO (removeDirectoryContents dockerSandboxDir [homeDirName | keepHome] []) -- | The Docker container "entrypoint": special actions performed when first entering -- a container, such as switching the UID/GID to the "outside-Docker" user's. entrypoint :: (HasProcessContext env, HasLogFunc env) => Config -> DockerEntrypoint -> RIO env () entrypoint config@Config{} DockerEntrypoint{..} = modifyMVar_ entrypointMVar $ \alreadyRan -> do -- Only run the entrypoint once unless alreadyRan $ do envOverride <- view processContextL homeDir <- liftIO $ parseAbsDir =<< getEnv "HOME" -- Get the UserEntry for the 'stack' user in the image, if it exists estackUserEntry0 <- liftIO $ tryJust (guard . isDoesNotExistError) $ User.getUserEntryForName stackUserName -- Switch UID/GID if needed, and update user's home directory case deUser of Nothing -> pure () Just (DockerUser 0 _ _ _) -> pure () Just du -> withProcessContext envOverride $ updateOrCreateStackUser estackUserEntry0 homeDir du case estackUserEntry0 of Left _ -> pure () Right ue -> do -- If the 'stack' user exists in the image, copy any build plans and package indices from -- its original home directory to the host's Stack root, to avoid needing to download them origStackHomeDir <- liftIO $ parseAbsDir (User.homeDirectory ue) let origStackRoot = origStackHomeDir relDirDotStackProgName buildPlanDirExists <- doesDirExist (buildPlanDir origStackRoot) when buildPlanDirExists $ do (_, buildPlans) <- listDir (buildPlanDir origStackRoot) forM_ buildPlans $ \srcBuildPlan -> do let destBuildPlan = buildPlanDir (view stackRootL config) filename srcBuildPlan exists <- doesFileExist destBuildPlan unless exists $ do ensureDir (parent destBuildPlan) copyFile srcBuildPlan destBuildPlan pure True where updateOrCreateStackUser estackUserEntry homeDir DockerUser{..} = do case estackUserEntry of Left _ -> do -- If no 'stack' user in image, create one with correct UID/GID and home directory readProcessNull "groupadd" ["-o" ,"--gid",show duGid ,stackUserName] readProcessNull "useradd" ["-oN" ,"--uid",show duUid ,"--gid",show duGid ,"--home",toFilePathNoTrailingSep homeDir ,stackUserName] Right _ -> do -- If there is already a 'stack' user in the image, adjust its UID/GID and home directory readProcessNull "usermod" ["-o" ,"--uid",show duUid ,"--home",toFilePathNoTrailingSep homeDir ,stackUserName] readProcessNull "groupmod" ["-o" ,"--gid",show duGid ,stackUserName] forM_ duGroups $ \gid -> do readProcessNull "groupadd" ["-o" ,"--gid",show gid ,"group" ++ show gid] -- 'setuid' to the wanted UID and GID liftIO $ do User.setGroupID duGid #ifndef WINDOWS PosixUser.setGroups duGroups #endif User.setUserID duUid _ <- Files.setFileCreationMask duUmask pure () stackUserName = "stack"::String -- | MVar used to ensure the Docker entrypoint is performed exactly once entrypointMVar :: MVar Bool {-# NOINLINE entrypointMVar #-} entrypointMVar = unsafePerformIO (newMVar False) -- | Remove the contents of a directory, without removing the directory itself. -- This is used instead of 'FS.removeTree' to clear bind-mounted directories, since -- removing the root of the bind-mount won't work. removeDirectoryContents :: Path Abs Dir -- ^ Directory to remove contents of -> [Path Rel Dir] -- ^ Top-level directory names to exclude from removal -> [Path Rel File] -- ^ Top-level file names to exclude from removal -> IO () removeDirectoryContents path excludeDirs excludeFiles = do isRootDir <- doesDirExist path when isRootDir (do (lsd,lsf) <- listDir path forM_ lsd (\d -> unless (dirname d `elem` excludeDirs) (removeDirRecur d)) forM_ lsf (\f -> unless (filename f `elem` excludeFiles) (removeFile f))) -- | Produce a strict 'S.ByteString' from the stdout of a -- process. Throws a 'ReadProcessException' exception if the -- process fails. -- -- The stderr output is passed straight through, which is desirable for some cases -- e.g. docker pull, in which docker uses stderr for progress output. -- -- Use 'readProcess_' directly to customize this. readDockerProcess :: (HasProcessContext env, HasLogFunc env) => [String] -> RIO env BS.ByteString readDockerProcess args = BL.toStrict <$> proc "docker" args readProcessStdout_ -- | Name of home directory within docker sandbox. homeDirName :: Path Rel Dir homeDirName = relDirUnderHome -- | Directory where 'stack' executable is bind-mounted in Docker container -- This refers to a path in the Linux *container*, and so should remain a -- 'FilePath' (not 'Path Abs Dir') so that it works when the host runs Windows. hostBinDir :: FilePath hostBinDir = "/opt/host/bin" -- | Convenience function to decode ByteString to String. decodeUtf8 :: BS.ByteString -> String decodeUtf8 bs = T.unpack (T.decodeUtf8 bs) -- | Fail with friendly error if project root not set. getProjectRoot :: HasConfig env => RIO env (Path Abs Dir) getProjectRoot = do mroot <- view $ configL.to configProjectRoot maybe (throwIO CannotDetermineProjectRootException) pure mroot -- | Environment variable that contained the old sandbox ID. -- | Use of this variable is deprecated, and only used to detect old images. oldSandboxIdEnvVar :: String oldSandboxIdEnvVar = "DOCKER_SANDBOX_ID" -- | Parsed result of @docker inspect@. data Inspect = Inspect {iiConfig :: ImageConfig ,iiCreated :: UTCTime ,iiId :: Text ,iiVirtualSize :: Maybe Integer} deriving (Show) -- | Parse @docker inspect@ output. instance FromJSON Inspect where parseJSON v = do o <- parseJSON v Inspect <$> o .: "Config" <*> o .: "Created" <*> o .: "Id" <*> o .:? "VirtualSize" -- | Parsed @Config@ section of @docker inspect@ output. data ImageConfig = ImageConfig {icEnv :: [String] ,icEntrypoint :: [String]} deriving (Show) -- | Parse @Config@ section of @docker inspect@ output. instance FromJSON ImageConfig where parseJSON v = do o <- parseJSON v ImageConfig <$> fmap join (o .:? "Env") .!= [] <*> fmap join (o .:? "Entrypoint") .!= [] stack-2.9.3.1/src/Stack/Dot.hs0000644000000000000000000006140114445022466014106 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} module Stack.Dot ( dot , listDependencies , DotOpts (..) , DotPayload (..) , ListDepsOpts (..) , ListDepsFormat (..) , ListDepsFormatOpts (..) , resolveDependencies , printGraph , pruneGraph ) where import Data.Aeson import qualified Data.ByteString.Lazy.Char8 as LBC8 import qualified Data.Foldable as F import qualified Data.Sequence as Seq import qualified Data.Set as Set import qualified Data.Map as Map import qualified Data.Text as Text import qualified Data.Text.IO as Text import qualified Data.Traversable as T import Distribution.License ( License (BSD3), licenseFromSPDX ) import qualified Distribution.PackageDescription as PD import qualified Distribution.SPDX.License as SPDX import Distribution.Text ( display ) import Distribution.Types.PackageName ( mkPackageName ) import qualified Path import RIO.Process ( HasProcessContext (..) ) import Stack.Build ( loadPackage ) import Stack.Build.Installed ( getInstalled, toInstallMap ) import Stack.Build.Source import Stack.Build.Target( NeedTargets (..), parseTargets ) import Stack.Constants import Stack.Package import Stack.Prelude hiding ( Display (..), pkgName, loadPackage ) import qualified Stack.Prelude ( pkgName ) import Stack.Runners import Stack.SourceMap import Stack.Types.Build import Stack.Types.Compiler ( wantedToActual ) import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.SourceMap -- | Type representing exceptions thrown by functions exported by the -- "Stack.Dot" module. data DotException = DependencyNotFoundBug GhcPkgId | PackageNotFoundBug PackageName deriving (Show, Typeable) instance Exception DotException where displayException (DependencyNotFoundBug depId) = bugReport "[S-7071]" $ concat [ "Expected to find " , ghcPkgIdString depId , " in global DB." ] displayException (PackageNotFoundBug pkgName) = bugReport "[S-7151]" $ concat [ "The '" , packageNameString pkgName , "' package was not found in any of the dependency sources." ] -- | Options record for @stack dot@ data DotOpts = DotOpts { dotIncludeExternal :: !Bool -- ^ Include external dependencies , dotIncludeBase :: !Bool -- ^ Include dependencies on base , dotDependencyDepth :: !(Maybe Int) -- ^ Limit the depth of dependency resolution to (Just n) or continue until -- fixpoint , dotPrune :: !(Set PackageName) -- ^ Package names to prune from the graph , dotTargets :: [Text] -- ^ Stack TARGETs to trace dependencies for , dotFlags :: !(Map ApplyCLIFlag (Map FlagName Bool)) -- ^ Flags to apply when calculating dependencies , dotTestTargets :: Bool -- ^ Like the "--test" flag for build, affects the meaning of 'dotTargets'. , dotBenchTargets :: Bool -- ^ Like the "--bench" flag for build, affects the meaning of 'dotTargets'. , dotGlobalHints :: Bool -- ^ Use global hints instead of relying on an actual GHC installation. } data ListDepsFormatOpts = ListDepsFormatOpts { listDepsSep :: !Text -- ^ Separator between the package name and details. , listDepsLicense :: !Bool -- ^ Print dependency licenses instead of versions. } data ListDepsFormat = ListDepsText ListDepsFormatOpts | ListDepsTree ListDepsFormatOpts | ListDepsJSON | ListDepsConstraints data ListDepsOpts = ListDepsOpts { listDepsFormat :: !ListDepsFormat -- ^ Format of printing dependencies , listDepsDotOpts :: !DotOpts -- ^ The normal dot options. } -- | Visualize the project's dependencies as a graphviz graph dot :: DotOpts -> RIO Runner () dot dotOpts = do (localNames, prunedGraph) <- createPrunedDependencyGraph dotOpts printGraph dotOpts localNames prunedGraph -- | Information about a package in the dependency graph, when available. data DotPayload = DotPayload { payloadVersion :: Maybe Version -- ^ The package version. , payloadLicense :: Maybe (Either SPDX.License License) -- ^ The license the package was released under. , payloadLocation :: Maybe PackageLocation -- ^ The location of the package. } deriving (Eq, Show) -- | Create the dependency graph and also prune it as specified in the dot -- options. Returns a set of local names and a map from package names to -- dependencies. createPrunedDependencyGraph :: DotOpts -> RIO Runner (Set PackageName, Map PackageName (Set PackageName, DotPayload)) createPrunedDependencyGraph dotOpts = withDotConfig dotOpts $ do localNames <- view $ buildConfigL.to (Map.keysSet . smwProject . bcSMWanted) logDebug "Creating dependency graph" resultGraph <- createDependencyGraph dotOpts let pkgsToPrune = if dotIncludeBase dotOpts then dotPrune dotOpts else Set.insert "base" (dotPrune dotOpts) prunedGraph = pruneGraph localNames pkgsToPrune resultGraph logDebug "Returning pruned dependency graph" pure (localNames, prunedGraph) -- | Create the dependency graph, the result is a map from a package -- name to a tuple of dependencies and payload if available. This -- function mainly gathers the required arguments for -- @resolveDependencies@. createDependencyGraph :: DotOpts -> RIO DotConfig (Map PackageName (Set PackageName, DotPayload)) createDependencyGraph dotOpts = do sourceMap <- view sourceMapL locals <- for (toList $ smProject sourceMap) loadLocalPackage let graph = Map.fromList $ projectPackageDependencies dotOpts (filter lpWanted locals) globalDump <- view $ to dcGlobalDump -- TODO: Can there be multiple entries for wired-in-packages? If so, -- this will choose one arbitrarily.. let globalDumpMap = Map.fromList $ map (\dp -> (Stack.Prelude.pkgName (dpPackageIdent dp), dp)) globalDump globalIdMap = Map.fromList $ map (\dp -> (dpGhcPkgId dp, dpPackageIdent dp)) globalDump let depLoader = createDepLoader sourceMap globalDumpMap globalIdMap loadPackageDeps loadPackageDeps name version loc flags ghcOptions cabalConfigOpts -- Skip packages that can't be loaded - see -- https://github.com/commercialhaskell/stack/issues/2967 | name `elem` [mkPackageName "rts", mkPackageName "ghc"] = pure ( Set.empty , DotPayload (Just version) (Just $ Right BSD3) Nothing ) | otherwise = fmap (packageAllDeps &&& makePayload loc) (loadPackage loc flags ghcOptions cabalConfigOpts) resolveDependencies (dotDependencyDepth dotOpts) graph depLoader where makePayload loc pkg = DotPayload (Just $ packageVersion pkg) (Just $ packageLicense pkg) (Just $ PLImmutable loc) listDependencies :: ListDepsOpts -> RIO Runner () listDependencies opts = do let dotOpts = listDepsDotOpts opts (pkgs, resultGraph) <- createPrunedDependencyGraph dotOpts liftIO $ case listDepsFormat opts of ListDepsTree treeOpts -> Text.putStrLn "Packages" >> printTree treeOpts dotOpts 0 [] (treeRoots opts pkgs) resultGraph ListDepsJSON -> printJSON pkgs resultGraph ListDepsText textOpts -> void $ Map.traverseWithKey (go "" textOpts) (snd <$> resultGraph) ListDepsConstraints -> do let constraintOpts = ListDepsFormatOpts " ==" False Text.putStrLn "constraints:" void $ Map.traverseWithKey (go " , " constraintOpts) (snd <$> resultGraph) where go prefix lineOpts name payload = Text.putStrLn $ prefix <> listDepsLine lineOpts name payload data DependencyTree = DependencyTree (Set PackageName) (Map PackageName (Set PackageName, DotPayload)) instance ToJSON DependencyTree where toJSON (DependencyTree _ dependencyMap) = toJSON $ foldToList dependencyToJSON dependencyMap foldToList :: (k -> a -> b) -> Map k a -> [b] foldToList f = Map.foldrWithKey (\k a bs -> bs ++ [f k a]) [] dependencyToJSON :: PackageName -> (Set PackageName, DotPayload) -> Value dependencyToJSON pkg (deps, payload) = let fieldsAlwaysPresent = [ "name" .= packageNameString pkg , "license" .= licenseText payload , "version" .= versionText payload , "dependencies" .= Set.map packageNameString deps ] loc = catMaybes [("location" .=) . pkgLocToJSON <$> payloadLocation payload] in object $ fieldsAlwaysPresent ++ loc pkgLocToJSON :: PackageLocation -> Value pkgLocToJSON (PLMutable (ResolvedPath _ dir)) = object [ "type" .= ("project package" :: Text) , "url" .= ("file://" ++ Path.toFilePath dir) ] pkgLocToJSON (PLImmutable (PLIHackage pkgid _ _)) = object [ "type" .= ("hackage" :: Text) , "url" .= ("https://hackage.haskell.org/package/" ++ display pkgid) ] pkgLocToJSON (PLImmutable (PLIArchive archive _)) = let url = case archiveLocation archive of ALUrl u -> u ALFilePath (ResolvedPath _ path) -> Text.pack $ "file://" ++ Path.toFilePath path in object [ "type" .= ("archive" :: Text) , "url" .= url , "sha256" .= archiveHash archive , "size" .= archiveSize archive ] pkgLocToJSON (PLImmutable (PLIRepo repo _)) = object [ "type" .= case repoType repo of RepoGit -> "git" :: Text RepoHg -> "hg" :: Text , "url" .= repoUrl repo , "commit" .= repoCommit repo , "subdir" .= repoSubdir repo ] printJSON :: Set PackageName -> Map PackageName (Set PackageName, DotPayload) -> IO () printJSON pkgs dependencyMap = LBC8.putStrLn $ encode $ DependencyTree pkgs dependencyMap treeRoots :: ListDepsOpts -> Set PackageName -> Set PackageName treeRoots opts projectPackages' = let targets = dotTargets $ listDepsDotOpts opts in if null targets then projectPackages' else Set.fromList $ map (mkPackageName . Text.unpack) targets printTree :: ListDepsFormatOpts -> DotOpts -> Int -> [Int] -> Set PackageName -> Map PackageName (Set PackageName, DotPayload) -> IO () printTree opts dotOpts depth remainingDepsCounts packages dependencyMap = F.sequence_ $ Seq.mapWithIndex go (toSeq packages) where toSeq = Seq.fromList . Set.toList go index name = let newDepsCounts = remainingDepsCounts ++ [Set.size packages - index - 1] in case Map.lookup name dependencyMap of Just (deps, payload) -> do printTreeNode opts dotOpts depth newDepsCounts deps payload name if Just depth == dotDependencyDepth dotOpts then pure () else printTree opts dotOpts (depth + 1) newDepsCounts deps dependencyMap -- TODO: Define this behaviour, maybe pure an error? Nothing -> pure () printTreeNode :: ListDepsFormatOpts -> DotOpts -> Int -> [Int] -> Set PackageName -> DotPayload -> PackageName -> IO () printTreeNode opts dotOpts depth remainingDepsCounts deps payload name = let remainingDepth = fromMaybe 999 (dotDependencyDepth dotOpts) - depth hasDeps = not $ null deps in Text.putStrLn $ treeNodePrefix "" remainingDepsCounts hasDeps remainingDepth <> " " <> listDepsLine opts name payload treeNodePrefix :: Text -> [Int] -> Bool -> Int -> Text treeNodePrefix t [] _ _ = t treeNodePrefix t [0] True 0 = t <> "└──" treeNodePrefix t [_] True 0 = t <> "├──" treeNodePrefix t [0] True _ = t <> "└─┬" treeNodePrefix t [_] True _ = t <> "├─┬" treeNodePrefix t [0] False _ = t <> "└──" treeNodePrefix t [_] False _ = t <> "├──" treeNodePrefix t (0:ns) d remainingDepth = treeNodePrefix (t <> " ") ns d remainingDepth treeNodePrefix t (_:ns) d remainingDepth = treeNodePrefix (t <> "│ ") ns d remainingDepth listDepsLine :: ListDepsFormatOpts -> PackageName -> DotPayload -> Text listDepsLine opts name payload = Text.pack (packageNameString name) <> listDepsSep opts <> payloadText opts payload payloadText :: ListDepsFormatOpts -> DotPayload -> Text payloadText opts payload = if listDepsLicense opts then licenseText payload else versionText payload licenseText :: DotPayload -> Text licenseText payload = maybe "" (Text.pack . display . either licenseFromSPDX id) (payloadLicense payload) versionText :: DotPayload -> Text versionText payload = maybe "" (Text.pack . display) (payloadVersion payload) -- | @pruneGraph dontPrune toPrune graph@ prunes all packages in -- @graph@ with a name in @toPrune@ and removes resulting orphans -- unless they are in @dontPrune@ pruneGraph :: (F.Foldable f, F.Foldable g, Eq a) => f PackageName -> g PackageName -> Map PackageName (Set PackageName, a) -> Map PackageName (Set PackageName, a) pruneGraph dontPrune names = pruneUnreachable dontPrune . Map.mapMaybeWithKey (\pkg (pkgDeps,x) -> if pkg `F.elem` names then Nothing else let filtered = Set.filter (\n -> n `F.notElem` names) pkgDeps in if Set.null filtered && not (Set.null pkgDeps) then Nothing else Just (filtered,x)) -- | Make sure that all unreachable nodes (orphans) are pruned pruneUnreachable :: (Eq a, F.Foldable f) => f PackageName -> Map PackageName (Set PackageName, a) -> Map PackageName (Set PackageName, a) pruneUnreachable dontPrune = fixpoint prune where fixpoint :: Eq a => (a -> a) -> a -> a fixpoint f v = if f v == v then v else fixpoint f (f v) prune graph' = Map.filterWithKey (\k _ -> reachable k) graph' where reachable k = k `F.elem` dontPrune || k `Set.member` reachables reachables = F.fold (fst <$> graph') -- | Resolve the dependency graph up to (Just depth) or until fixpoint is reached resolveDependencies :: (Applicative m, Monad m) => Maybe Int -> Map PackageName (Set PackageName, DotPayload) -> (PackageName -> m (Set PackageName, DotPayload)) -> m (Map PackageName (Set PackageName, DotPayload)) resolveDependencies (Just 0) graph _ = pure graph resolveDependencies limit graph loadPackageDeps = do let values = Set.unions (fst <$> Map.elems graph) keys = Map.keysSet graph next = Set.difference values keys if Set.null next then pure graph else do x <- T.traverse (\name -> (name,) <$> loadPackageDeps name) (F.toList next) resolveDependencies (subtract 1 <$> limit) (Map.unionWith unifier graph (Map.fromList x)) loadPackageDeps where unifier (pkgs1,v1) (pkgs2,_) = (Set.union pkgs1 pkgs2, v1) -- | Given a SourceMap and a dependency loader, load the set of dependencies for -- a package createDepLoader :: SourceMap -> Map PackageName DumpPackage -> Map GhcPkgId PackageIdentifier -> (PackageName -> Version -> PackageLocationImmutable -> Map FlagName Bool -> [Text] -> [Text] -> RIO DotConfig (Set PackageName, DotPayload)) -> PackageName -> RIO DotConfig (Set PackageName, DotPayload) createDepLoader sourceMap globalDumpMap globalIdMap loadPackageDeps pkgName = do fromMaybe (throwIO $ PackageNotFoundBug pkgName) (projectPackageDeps <|> dependencyDeps <|> globalDeps) where projectPackageDeps = loadDeps <$> Map.lookup pkgName (smProject sourceMap) where loadDeps pp = do pkg <- loadCommonPackage (ppCommon pp) pure (packageAllDeps pkg, payloadFromLocal pkg Nothing) dependencyDeps = loadDeps <$> Map.lookup pkgName (smDeps sourceMap) where loadDeps DepPackage{dpLocation=PLMutable dir} = do pp <- mkProjectPackage YesPrintWarnings dir False pkg <- loadCommonPackage (ppCommon pp) pure (packageAllDeps pkg, payloadFromLocal pkg (Just $ PLMutable dir)) loadDeps dp@DepPackage{dpLocation=PLImmutable loc} = do let common = dpCommon dp gpd <- liftIO $ cpGPD common let PackageIdentifier name version = PD.package $ PD.packageDescription gpd flags = cpFlags common ghcOptions = cpGhcOptions common cabalConfigOpts = cpCabalConfigOpts common assert (pkgName == name) (loadPackageDeps pkgName version loc flags ghcOptions cabalConfigOpts) -- If package is a global package, use info from ghc-pkg (#4324, #3084) globalDeps = pure . getDepsFromDump <$> Map.lookup pkgName globalDumpMap where getDepsFromDump dump = (Set.fromList deps, payloadFromDump dump) where deps = map ghcIdToPackageName (dpDepends dump) ghcIdToPackageName depId = maybe (impureThrow $ DependencyNotFoundBug depId) Stack.Prelude.pkgName (Map.lookup depId globalIdMap) payloadFromLocal pkg loc = DotPayload (Just $ packageVersion pkg) (Just $ packageLicense pkg) loc payloadFromDump dp = DotPayload (Just $ pkgVersion $ dpPackageIdent dp) (Right <$> dpLicense dp) Nothing -- | Resolve the direct (depth 0) external dependencies of the given local -- packages (assumed to come from project packages) projectPackageDependencies :: DotOpts -> [LocalPackage] -> [(PackageName, (Set PackageName, DotPayload))] projectPackageDependencies dotOpts locals = map (\lp -> let pkg = localPackageToPackage lp pkgDir = Path.parent $ lpCabalFile lp loc = PLMutable $ ResolvedPath (RelFilePath "N/A") pkgDir in (packageName pkg, (deps pkg, lpPayload pkg loc))) locals where deps pkg = if dotIncludeExternal dotOpts then Set.delete (packageName pkg) (packageAllDeps pkg) else Set.intersection localNames (packageAllDeps pkg) localNames = Set.fromList $ map (packageName . lpPackage) locals lpPayload pkg loc = DotPayload (Just $ packageVersion pkg) (Just $ packageLicense pkg) (Just loc) -- | Print a graphviz graph of the edges in the Map and highlight the given -- local packages printGraph :: (Applicative m, MonadIO m) => DotOpts -> Set PackageName -- ^ all locals -> Map PackageName (Set PackageName, DotPayload) -> m () printGraph dotOpts locals graph = do liftIO $ Text.putStrLn "strict digraph deps {" printLocalNodes dotOpts filteredLocals printLeaves graph void (Map.traverseWithKey printEdges (fst <$> graph)) liftIO $ Text.putStrLn "}" where filteredLocals = Set.filter (\local' -> local' `Set.notMember` dotPrune dotOpts) locals -- | Print the local nodes with a different style depending on options printLocalNodes :: (F.Foldable t, MonadIO m) => DotOpts -> t PackageName -> m () printLocalNodes dotOpts locals = liftIO $ Text.putStrLn (Text.intercalate "\n" lpNodes) where applyStyle :: Text -> Text applyStyle n = if dotIncludeExternal dotOpts then n <> " [style=dashed];" else n <> " [style=solid];" lpNodes :: [Text] lpNodes = map (applyStyle . nodeName) (F.toList locals) -- | Print nodes without dependencies printLeaves :: MonadIO m => Map PackageName (Set PackageName, DotPayload) -> m () printLeaves = F.mapM_ printLeaf . Map.keysSet . Map.filter Set.null . fmap fst -- | @printDedges p ps@ prints an edge from p to every ps printEdges :: MonadIO m => PackageName -> Set PackageName -> m () printEdges package deps = F.forM_ deps (printEdge package) -- | Print an edge between the two package names printEdge :: MonadIO m => PackageName -> PackageName -> m () printEdge from to' = liftIO $ Text.putStrLn (Text.concat [ nodeName from , " -> " , nodeName to' , ";" ]) -- | Convert a package name to a graph node name. nodeName :: PackageName -> Text nodeName name = "\"" <> Text.pack (packageNameString name) <> "\"" -- | Print a node with no dependencies printLeaf :: MonadIO m => PackageName -> m () printLeaf package = liftIO . Text.putStrLn . Text.concat $ if isWiredIn package then ["{rank=max; ", nodeName package, " [shape=box]; };"] else ["{rank=max; ", nodeName package, "; };"] -- | Check if the package is wired in (shipped with) ghc isWiredIn :: PackageName -> Bool isWiredIn = (`Set.member` wiredInPackages) localPackageToPackage :: LocalPackage -> Package localPackageToPackage lp = fromMaybe (lpPackage lp) (lpTestBench lp) -- Plumbing for --test and --bench flags withDotConfig :: DotOpts -> RIO DotConfig a -> RIO Runner a withDotConfig opts inner = local (over globalOptsL modifyGO) $ if dotGlobalHints opts then withConfig NoReexec $ withBuildConfig withGlobalHints else withConfig YesReexec withReal where withGlobalHints = do bconfig <- view buildConfigL globals <- globalsFromHints $ smwCompiler $ bcSMWanted bconfig fakeGhcPkgId <- parseGhcPkgId "ignored" actual <- either throwIO pure $ wantedToActual $ smwCompiler $ bcSMWanted bconfig let smActual = SMActual { smaCompiler = actual , smaProject = smwProject $ bcSMWanted bconfig , smaDeps = smwDeps $ bcSMWanted bconfig , smaGlobal = Map.mapWithKey toDump globals } toDump :: PackageName -> Version -> DumpPackage toDump name version = DumpPackage { dpGhcPkgId = fakeGhcPkgId , dpPackageIdent = PackageIdentifier name version , dpParentLibIdent = Nothing , dpLicense = Nothing , dpLibDirs = [] , dpLibraries = [] , dpHasExposedModules = True , dpExposedModules = mempty , dpDepends = [] , dpHaddockInterfaces = [] , dpHaddockHtml = Nothing , dpIsExposed = True } actualPkgs = Map.keysSet (smaDeps smActual) <> Map.keysSet (smaProject smActual) prunedActual = smActual { smaGlobal = pruneGlobals (smaGlobal smActual) actualPkgs } targets <- parseTargets NeedTargets False boptsCLI prunedActual logDebug "Loading source map" sourceMap <- loadSourceMap targets boptsCLI smActual let dc = DotConfig { dcBuildConfig = bconfig , dcSourceMap = sourceMap , dcGlobalDump = toList $ smaGlobal smActual } logDebug "DotConfig fully loaded" runRIO dc inner withReal = withEnvConfig NeedTargets boptsCLI $ do envConfig <- ask let sourceMap = envConfigSourceMap envConfig installMap <- toInstallMap sourceMap (_, globalDump, _, _) <- getInstalled installMap let dc = DotConfig { dcBuildConfig = envConfigBuildConfig envConfig , dcSourceMap = sourceMap , dcGlobalDump = globalDump } runRIO dc inner boptsCLI = defaultBuildOptsCLI { boptsCLITargets = dotTargets opts , boptsCLIFlags = dotFlags opts } modifyGO = (if dotTestTargets opts then set (globalOptsBuildOptsMonoidL.buildOptsMonoidTestsL) (Just True) else id) . (if dotBenchTargets opts then set (globalOptsBuildOptsMonoidL.buildOptsMonoidBenchmarksL) (Just True) else id) data DotConfig = DotConfig { dcBuildConfig :: !BuildConfig , dcSourceMap :: !SourceMap , dcGlobalDump :: ![DumpPackage] } instance HasLogFunc DotConfig where logFuncL = runnerL.logFuncL instance HasPantryConfig DotConfig where pantryConfigL = configL.pantryConfigL instance HasTerm DotConfig where useColorL = runnerL.useColorL termWidthL = runnerL.termWidthL instance HasStylesUpdate DotConfig where stylesUpdateL = runnerL.stylesUpdateL instance HasGHCVariant DotConfig instance HasPlatform DotConfig instance HasRunner DotConfig where runnerL = configL.runnerL instance HasProcessContext DotConfig where processContextL = runnerL.processContextL instance HasConfig DotConfig instance HasBuildConfig DotConfig where buildConfigL = lens dcBuildConfig (\x y -> x { dcBuildConfig = y }) instance HasSourceMap DotConfig where sourceMapL = lens dcSourceMap (\x y -> x { dcSourceMap = y }) stack-2.9.3.1/src/Stack/FileWatch.hs0000644000000000000000000001174214445022466015231 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} module Stack.FileWatch ( WatchMode (WatchModePoll) , fileWatch , fileWatchPoll ) where import Control.Concurrent.STM ( check ) import qualified Data.Map.Strict as Map import qualified Data.Set as Set import GHC.IO.Exception import Path import Stack.Prelude import System.FSNotify import System.IO ( getLine ) fileWatch :: (HasLogFunc env, HasTerm env) => ((Set (Path Abs File) -> IO ()) -> RIO env ()) -> RIO env () fileWatch = fileWatchConf defaultConfig fileWatchPoll :: (HasLogFunc env, HasTerm env) => ((Set (Path Abs File) -> IO ()) -> RIO env ()) -> RIO env () fileWatchPoll = fileWatchConf $ defaultConfig { confWatchMode = WatchModePoll 1000000 } -- | Run an action, watching for file changes -- -- The action provided takes a callback that is used to set the files to be -- watched. When any of those files are changed, we rerun the action again. fileWatchConf :: (HasLogFunc env, HasTerm env) => WatchConfig -> ((Set (Path Abs File) -> IO ()) -> RIO env ()) -> RIO env () fileWatchConf cfg inner = withRunInIO $ \run -> withManagerConf cfg $ \manager -> do allFiles <- newTVarIO Set.empty dirtyVar <- newTVarIO True watchVar <- newTVarIO Map.empty let onChange event = atomically $ do files <- readTVar allFiles when (eventPath event `Set.member` files) (writeTVar dirtyVar True) setWatched :: Set (Path Abs File) -> IO () setWatched files = do atomically $ writeTVar allFiles $ Set.map toFilePath files watch0 <- readTVarIO watchVar let actions = Map.mergeWithKey keepListening stopListening startListening watch0 newDirs watch1 <- forM (Map.toList actions) $ \(k, mmv) -> do mv <- mmv pure $ case mv of Nothing -> Map.empty Just v -> Map.singleton k v atomically $ writeTVar watchVar $ Map.unions watch1 where newDirs = Map.fromList $ map (, ()) $ Set.toList $ Set.map parent files keepListening _dir listen () = Just $ pure $ Just listen stopListening = Map.map $ \f -> do () <- f `catch` \ioe -> -- Ignore invalid argument error - it can happen if -- the directory is removed. case ioe_type ioe of InvalidArgument -> pure () _ -> throwIO ioe pure Nothing startListening = Map.mapWithKey $ \dir () -> do let dir' = fromString $ toFilePath dir listen <- watchDir manager dir' (const True) onChange pure $ Just listen let watchInput = do l <- getLine unless (l == "quit") $ do run $ case l of "help" -> do logInfo "" logInfo "help: display this help" logInfo "quit: exit" logInfo "build: force a rebuild" logInfo "watched: display watched files" "build" -> atomically $ writeTVar dirtyVar True "watched" -> do watch <- readTVarIO allFiles mapM_ (logInfo . fromString) (Set.toList watch) "" -> atomically $ writeTVar dirtyVar True _ -> logInfo $ "Unknown command: " <> displayShow l <> ". Try 'help'" watchInput race_ watchInput $ run $ forever $ do atomically $ do dirty <- readTVar dirtyVar check dirty eres <- tryAny $ inner setWatched -- Clear dirtiness flag after the build to avoid an infinite -- loop caused by the build itself triggering dirtiness. This -- could be viewed as a bug, since files changed during the -- build will not trigger an extra rebuild, but overall seems -- like better behavior. See -- https://github.com/commercialhaskell/stack/issues/822 atomically $ writeTVar dirtyVar False prettyInfo $ case eres of Left e -> let theStyle = case fromException e of Just ExitSuccess -> Good _ -> Error in style theStyle $ fromString $ displayException e _ -> style Good "Success! Waiting for next file change." logInfo "Type help for available commands. Press enter to force a rebuild." stack-2.9.3.1/src/Stack/GhcPkg.hs0000644000000000000000000001344314445022466014526 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} -- | Functions for the GHC package database. module Stack.GhcPkg ( createDatabase , findGhcPkgField , getGlobalDB , ghcPkgPathEnvVar , mkGhcPackagePath , unregisterGhcPkgIds ) where import qualified Data.ByteString.Char8 as S8 import qualified Data.ByteString.Lazy as BL import qualified Data.List as L import qualified Data.Text as T import qualified Data.Text.Encoding as T import Path ( (), parent ) import Path.Extra ( toFilePathNoTrailingSep ) import Path.IO ( doesDirExist, doesFileExist, ensureDir, resolveDir' ) import RIO.Process ( HasProcessContext, proc, readProcess_ ) import Stack.Constants ( relFilePackageCache ) import Stack.Prelude import Stack.Types.Config ( GhcPkgExe (..) ) import Stack.Types.GhcPkgId ( GhcPkgId, ghcPkgIdString ) import Stack.Types.Compiler ( WhichCompiler (..) ) import System.FilePath ( searchPathSeparator ) -- | Get the global package database getGlobalDB :: (HasProcessContext env, HasLogFunc env) => GhcPkgExe -> RIO env (Path Abs Dir) getGlobalDB pkgexe = do logDebug "Getting global package database location" -- This seems like a strange way to get the global package database -- location, but I don't know of a better one bs <- ghcPkg pkgexe [] ["list", "--global"] >>= either throwIO pure let fp = S8.unpack $ stripTrailingColon $ firstLine bs liftIO $ resolveDir' fp where stripTrailingColon bs | S8.null bs = bs | S8.last bs == ':' = S8.init bs | otherwise = bs firstLine = S8.takeWhile (\c -> c /= '\r' && c /= '\n') -- | Run the ghc-pkg executable ghcPkg :: (HasProcessContext env, HasLogFunc env) => GhcPkgExe -> [Path Abs Dir] -> [String] -> RIO env (Either SomeException S8.ByteString) ghcPkg pkgexe@(GhcPkgExe pkgPath) pkgDbs args = do eres <- go case eres of Left _ -> do mapM_ (createDatabase pkgexe) pkgDbs go Right _ -> pure eres where pkg = toFilePath pkgPath go = tryAny $ BL.toStrict . fst <$> proc pkg args' readProcess_ args' = packageDbFlags pkgDbs ++ args -- | Create a package database in the given directory, if it doesn't exist. createDatabase :: (HasProcessContext env, HasLogFunc env) => GhcPkgExe -> Path Abs Dir -> RIO env () createDatabase (GhcPkgExe pkgPath) db = do exists <- doesFileExist (db relFilePackageCache) unless exists $ do -- ghc-pkg requires that the database directory does not exist -- yet. If the directory exists but the package.cache file -- does, we're in a corrupted state. Check for that state. dirExists <- doesDirExist db args <- if dirExists then do logWarn $ "The package database located at " <> fromString (toFilePath db) <> " is corrupted (missing its package.cache file)." logWarn "Proceeding with a recache" pure ["--package-db", toFilePath db, "recache"] else do -- Creating the parent doesn't seem necessary, as ghc-pkg -- seems to be sufficiently smart. But I don't feel like -- finding out it isn't the hard way ensureDir (parent db) pure ["init", toFilePath db] void $ proc (toFilePath pkgPath) args $ \pc -> onException (readProcess_ pc) $ logError $ "Error: [S-9735]\n" <> "Unable to create package database at " <> fromString (toFilePath db) -- | Get the environment variable to use for the package DB paths. ghcPkgPathEnvVar :: WhichCompiler -> Text ghcPkgPathEnvVar Ghc = "GHC_PACKAGE_PATH" -- | Get the necessary ghc-pkg flags for setting up the given package database packageDbFlags :: [Path Abs Dir] -> [String] packageDbFlags pkgDbs = "--no-user-package-db" : map (\x -> "--package-db=" ++ toFilePath x) pkgDbs -- | Get the value of a field of the package. findGhcPkgField :: (HasProcessContext env, HasLogFunc env) => GhcPkgExe -> [Path Abs Dir] -- ^ package databases -> String -- ^ package identifier, or GhcPkgId -> Text -> RIO env (Maybe Text) findGhcPkgField pkgexe pkgDbs name field = do result <- ghcPkg pkgexe pkgDbs ["field", "--simple-output", name, T.unpack field] pure $ case result of Left{} -> Nothing Right bs -> fmap (stripCR . T.decodeUtf8) $ listToMaybe $ S8.lines bs -- | unregister list of package ghcids, batching available from GHC 8.2.1, -- see https://github.com/commercialhaskell/stack/issues/2662#issuecomment-460342402 -- using GHC package id where available (from GHC 7.9) unregisterGhcPkgIds :: (HasProcessContext env, HasLogFunc env) => GhcPkgExe -> Path Abs Dir -- ^ package database -> NonEmpty (Either PackageIdentifier GhcPkgId) -> RIO env () unregisterGhcPkgIds pkgexe pkgDb epgids = do eres <- ghcPkg pkgexe [pkgDb] args case eres of Left e -> logWarn $ displayShow e Right _ -> pure () where (idents, gids) = partitionEithers $ toList epgids args = "unregister" : "--user" : "--force" : map packageIdentifierString idents ++ if null gids then [] else "--ipid" : map ghcPkgIdString gids -- | Get the value for GHC_PACKAGE_PATH mkGhcPackagePath :: Bool -> Path Abs Dir -> Path Abs Dir -> [Path Abs Dir] -> Path Abs Dir -> Text mkGhcPackagePath locals localdb deps extras globaldb = T.pack $ L.intercalate [searchPathSeparator] $ concat [ [toFilePathNoTrailingSep localdb | locals] , [toFilePathNoTrailingSep deps] , [toFilePathNoTrailingSep db | db <- reverse extras] , [toFilePathNoTrailingSep globaldb] ] stack-2.9.3.1/src/Stack/Ghci.hs0000644000000000000000000013103714445022466014235 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TupleSections #-} -- | Run a GHCi configured with the user's package(s). module Stack.Ghci ( GhciOpts (..) , GhciPkgInfo (..) , GhciException (..) , ghci ) where import Control.Monad.State.Strict ( State, execState, get, modify ) import Data.ByteString.Builder ( byteString ) import qualified Data.ByteString.Char8 as S8 import qualified Data.ByteString.Lazy as LBS import Data.Foldable ( foldl ) import qualified Data.List as L import qualified Data.List.NonEmpty as NE import qualified Data.Map.Strict as M import qualified Data.Set as S import qualified Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Encoding as TLE import qualified Distribution.PackageDescription as C import Path import Path.Extra ( toFilePathNoTrailingSep ) import Path.IO hiding ( withSystemTempDir ) import RIO.Process ( HasProcessContext, exec, proc, readProcess_ , withWorkingDir ) import Stack.Build import Stack.Build.Installed import Stack.Build.Source import Stack.Build.Target import Stack.Constants import Stack.Constants.Config import Stack.Ghci.Script import Stack.Package import Stack.Prelude import Stack.Types.Build import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.PackageFile import Stack.Types.SourceMap import System.IO ( putStrLn ) import System.IO.Temp ( getCanonicalTemporaryDirectory ) import System.Permissions ( setScriptPerms ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Ghci" module. data GhciException = InvalidPackageOption String | LoadingDuplicateModules | MissingFileTarget String | Can'tSpecifyFilesAndTargets | Can'tSpecifyFilesAndMainIs | GhciTargetParseException [Text] deriving (Show, Typeable) instance Exception GhciException where displayException (InvalidPackageOption name) = "Error: [S-6716]\n" ++ "Failed to parse '--package' option " ++ name ++ "." displayException LoadingDuplicateModules = unlines [ "Error: [S-9632]" , "Not attempting to start ghci due to these duplicate modules." , "Use '--no-load' to try to start it anyway, without loading any \ \modules (but these are still likely to cause errors)." ] displayException (MissingFileTarget name) = "Error: [S-3600]\n" ++ "Cannot find file target " ++ name ++ "." displayException Can'tSpecifyFilesAndTargets = "Error: [S-9906]\n" ++ "Cannot use 'stack ghci' with both file targets and package targets." displayException Can'tSpecifyFilesAndMainIs = "Error: [S-5188]\n" ++ "Cannot use 'stack ghci' with both file targets and '--main-is' \ \flag." displayException (GhciTargetParseException xs) = "Error: [S-6948]\n" ++ show (TargetParseException xs) ++ "\nNote that to specify options to be passed to GHCi, use the \ \'--ghci-options' flag." -- | Command-line options for GHC. data GhciOpts = GhciOpts { ghciTargets :: ![Text] , ghciArgs :: ![String] , ghciGhcOptions :: ![String] , ghciFlags :: !(Map ApplyCLIFlag (Map FlagName Bool)) , ghciGhcCommand :: !(Maybe FilePath) , ghciNoLoadModules :: !Bool , ghciAdditionalPackages :: ![String] , ghciMainIs :: !(Maybe Text) , ghciLoadLocalDeps :: !Bool , ghciSkipIntermediate :: !Bool , ghciHidePackages :: !(Maybe Bool) , ghciNoBuild :: !Bool , ghciOnlyMain :: !Bool } deriving Show -- | Necessary information to load a package or its components. -- -- NOTE: GhciPkgInfo has paths as list instead of a Set to preserve files order -- as a workaround for bug https://ghc.haskell.org/trac/ghc/ticket/13786 data GhciPkgInfo = GhciPkgInfo { ghciPkgName :: !PackageName , ghciPkgOpts :: ![(NamedComponent, BuildInfoOpts)] , ghciPkgDir :: !(Path Abs Dir) , ghciPkgModules :: !ModuleMap , ghciPkgCFiles :: ![Path Abs File] -- ^ C files. , ghciPkgMainIs :: !(Map NamedComponent [Path Abs File]) , ghciPkgTargetFiles :: !(Maybe [Path Abs File]) , ghciPkgPackage :: !Package } deriving Show -- | Loaded package description and related info. data GhciPkgDesc = GhciPkgDesc { ghciDescPkg :: !Package , ghciDescCabalFp :: !(Path Abs File) , ghciDescTarget :: !Target } -- Mapping from a module name to a map with all of the paths that use -- that name. Each of those paths is associated with a set of components -- that contain it. Purpose of this complex structure is for use in -- 'checkForDuplicateModules'. type ModuleMap = Map ModuleName (Map (Path Abs File) (Set (PackageName, NamedComponent))) unionModuleMaps :: [ModuleMap] -> ModuleMap unionModuleMaps = M.unionsWith (M.unionWith S.union) -- | Launch a GHCi session for the given local package targets with the -- given options and configure it with the load paths and extensions -- of those targets. ghci :: HasEnvConfig env => GhciOpts -> RIO env () ghci opts@GhciOpts{..} = do let buildOptsCLI = defaultBuildOptsCLI { boptsCLITargets = [] , boptsCLIFlags = ghciFlags } sourceMap <- view $ envConfigL.to envConfigSourceMap installMap <- toInstallMap sourceMap locals <- projectLocalPackages depLocals <- localDependencies let localMap = M.fromList [(packageName $ lpPackage lp, lp) | lp <- locals ++ depLocals] -- FIXME:qrilka this looks wrong to go back to SMActual sma = SMActual { smaCompiler = smCompiler sourceMap , smaProject = smProject sourceMap , smaDeps = smDeps sourceMap , smaGlobal = smGlobal sourceMap } -- Parse --main-is argument. mainIsTargets <- parseMainIsTargets buildOptsCLI sma ghciMainIs -- Parse to either file targets or build targets etargets <- preprocessTargets buildOptsCLI sma ghciTargets (inputTargets, mfileTargets) <- case etargets of Right packageTargets -> pure (packageTargets, Nothing) Left rawFileTargets -> do case mainIsTargets of Nothing -> pure () Just _ -> throwM Can'tSpecifyFilesAndMainIs -- Figure out targets based on filepath targets (targetMap, fileInfo, extraFiles) <- findFileTargets locals rawFileTargets pure (targetMap, Just (fileInfo, extraFiles)) -- Get a list of all the local target packages. localTargets <- getAllLocalTargets opts inputTargets mainIsTargets localMap -- Get a list of all the non-local target packages. nonLocalTargets <- getAllNonLocalTargets inputTargets -- Check if additional package arguments are sensible. addPkgs <- checkAdditionalPackages ghciAdditionalPackages -- Load package descriptions. pkgDescs <- loadGhciPkgDescs buildOptsCLI localTargets -- If necessary, ask user about which main module to load. bopts <- view buildOptsL mainFile <- if ghciNoLoadModules then pure Nothing else do -- Figure out package files, in order to ask the user -- about which main module to load. See the note below for -- why this is done again after the build. This could -- potentially be done more efficiently, because all we -- need is the location of main modules, not the rest. pkgs0 <- getGhciPkgInfos installMap addPkgs (fmap fst mfileTargets) pkgDescs figureOutMainFile bopts mainIsTargets localTargets pkgs0 let pkgTargets pn targets = case targets of TargetAll _ -> [T.pack (packageNameString pn)] TargetComps comps -> [renderPkgComponent (pn, c) | c <- toList comps] -- Build required dependencies and setup local packages. buildDepsAndInitialSteps opts $ concatMap (\(pn, (_, t)) -> pkgTargets pn t) localTargets targetWarnings localTargets nonLocalTargets mfileTargets -- Load the list of modules _after_ building, to catch changes in -- unlisted dependencies (#1180) pkgs <- getGhciPkgInfos installMap addPkgs (fmap fst mfileTargets) pkgDescs checkForIssues pkgs -- Finally, do the invocation of ghci runGhci opts localTargets mainFile pkgs (maybe [] snd mfileTargets) (nonLocalTargets ++ addPkgs) preprocessTargets :: HasEnvConfig env => BuildOptsCLI -> SMActual GlobalPackage -> [Text] -> RIO env (Either [Path Abs File] (Map PackageName Target)) preprocessTargets buildOptsCLI sma rawTargets = do let (fileTargetsRaw, normalTargetsRaw) = L.partition (\t -> ".hs" `T.isSuffixOf` t || ".lhs" `T.isSuffixOf` t) rawTargets -- Only use file targets if we have no normal targets. if not (null fileTargetsRaw) && null normalTargetsRaw then do fileTargets <- forM fileTargetsRaw $ \fp0 -> do let fp = T.unpack fp0 mpath <- liftIO $ forgivingAbsence (resolveFile' fp) case mpath of Nothing -> throwM (MissingFileTarget fp) Just path -> pure path pure (Left fileTargets) else do -- Try parsing targets before checking if both file and -- module targets are specified (see issue#3342). let boptsCLI = buildOptsCLI { boptsCLITargets = normalTargetsRaw } normalTargets <- parseTargets AllowNoTargets False boptsCLI sma `catch` \ex -> case ex of TargetParseException xs -> throwM (GhciTargetParseException xs) _ -> throwM ex unless (null fileTargetsRaw) $ throwM Can'tSpecifyFilesAndTargets pure (Right $ smtTargets normalTargets) parseMainIsTargets :: HasEnvConfig env => BuildOptsCLI -> SMActual GlobalPackage -> Maybe Text -> RIO env (Maybe (Map PackageName Target)) parseMainIsTargets buildOptsCLI sma mtarget = forM mtarget $ \target -> do let boptsCLI = buildOptsCLI { boptsCLITargets = [target] } targets <- parseTargets AllowNoTargets False boptsCLI sma pure $ smtTargets targets -- | Display PackageName + NamedComponent displayPkgComponent :: (PackageName, NamedComponent) -> StyleDoc displayPkgComponent = style PkgComponent . fromString . T.unpack . renderPkgComponent findFileTargets :: HasEnvConfig env => [LocalPackage] -> [Path Abs File] -> RIO env (Map PackageName Target, Map PackageName [Path Abs File], [Path Abs File]) findFileTargets locals fileTargets = do filePackages <- forM locals $ \lp -> do (_,compFiles,_,_) <- getPackageFiles (packageFiles (lpPackage lp)) (lpCabalFile lp) pure (lp, M.map (map dotCabalGetPath) compFiles) let foundFileTargetComponents :: [(Path Abs File, [(PackageName, NamedComponent)])] foundFileTargetComponents = map (\fp -> (fp, ) $ L.sort $ concatMap (\(lp, files) -> map ((packageName (lpPackage lp), ) . fst) (filter (elem fp . snd) (M.toList files)) ) filePackages ) fileTargets results <- forM foundFileTargetComponents $ \(fp, xs) -> case xs of [] -> do prettyWarn $ vsep [ "Couldn't find a component for file target" <+> pretty fp <> ". This means that the correct ghc options might not be used." , "Attempting to load the file anyway." ] pure $ Left fp [x] -> do prettyInfo $ "Using configuration for" <+> displayPkgComponent x <+> "to load" <+> pretty fp pure $ Right (fp, x) (x:_) -> do prettyWarn $ "Multiple components contain file target" <+> pretty fp <> ":" <+> mconcat (L.intersperse ", " (map displayPkgComponent xs)) <> line <> "Guessing the first one," <+> displayPkgComponent x <> "." pure $ Right (fp, x) let (extraFiles, associatedFiles) = partitionEithers results targetMap = foldl unionTargets M.empty $ map (\(_, (name, comp)) -> M.singleton name (TargetComps (S.singleton comp))) associatedFiles infoMap = foldl (M.unionWith (<>)) M.empty $ map (\(fp, (name, _)) -> M.singleton name [fp]) associatedFiles pure (targetMap, infoMap, extraFiles) getAllLocalTargets :: HasEnvConfig env => GhciOpts -> Map PackageName Target -> Maybe (Map PackageName Target) -> Map PackageName LocalPackage -> RIO env [(PackageName, (Path Abs File, Target))] getAllLocalTargets GhciOpts{..} targets0 mainIsTargets localMap = do -- Use the 'mainIsTargets' as normal targets, for CLI concision. See -- #1845. This is a little subtle - we need to do the target parsing -- independently in order to handle the case where no targets are -- specified. let targets = maybe targets0 (unionTargets targets0) mainIsTargets packages <- view $ envConfigL.to envConfigSourceMap.to smProject -- Find all of the packages that are directly demanded by the -- targets. let directlyWanted = flip mapMaybe (M.toList packages) $ \(name, pp) -> case M.lookup name targets of Just simpleTargets -> Just (name, (ppCabalFP pp, simpleTargets)) Nothing -> Nothing -- Figure out let extraLoadDeps = getExtraLoadDeps ghciLoadLocalDeps localMap directlyWanted if (ghciSkipIntermediate && not ghciLoadLocalDeps) || null extraLoadDeps then pure directlyWanted else do let extraList = mconcat $ L.intersperse ", " (map (fromString . packageNameString . fst) extraLoadDeps) if ghciLoadLocalDeps then logInfo $ "The following libraries will also be loaded into GHCi because " <> "they are local dependencies of your targets, and you specified --load-local-deps:\n " <> extraList else logInfo $ "The following libraries will also be loaded into GHCi because " <> "they are intermediate dependencies of your targets:\n " <> extraList <> "\n(Use --skip-intermediate-deps to omit these)" pure (directlyWanted ++ extraLoadDeps) getAllNonLocalTargets :: Map PackageName Target -> RIO env [PackageName] getAllNonLocalTargets targets = do let isNonLocal (TargetAll PTDependency) = True isNonLocal _ = False pure $ map fst $ filter (isNonLocal . snd) (M.toList targets) buildDepsAndInitialSteps :: HasEnvConfig env => GhciOpts -> [Text] -> RIO env () buildDepsAndInitialSteps GhciOpts{..} localTargets = do let targets = localTargets ++ map T.pack ghciAdditionalPackages -- If necessary, do the build, for local packagee targets, only do -- 'initialBuildSteps'. case NE.nonEmpty targets of -- only new local targets could appear here Just nonEmptyTargets | not ghciNoBuild -> do eres <- buildLocalTargets nonEmptyTargets case eres of Right () -> pure () Left err -> do prettyError $ fromString (displayException err) prettyWarn "Build failed, but trying to launch GHCi anyway" _ -> pure () checkAdditionalPackages :: MonadThrow m => [String] -> m [PackageName] checkAdditionalPackages pkgs = forM pkgs $ \name -> do let mres = (pkgName <$> parsePackageIdentifier name) <|> parsePackageNameThrowing name maybe (throwM $ InvalidPackageOption name) pure mres runGhci :: HasEnvConfig env => GhciOpts -> [(PackageName, (Path Abs File, Target))] -> Maybe (Path Abs File) -> [GhciPkgInfo] -> [Path Abs File] -> [PackageName] -> RIO env () runGhci GhciOpts{..} targets mainFile pkgs extraFiles exposePackages = do config <- view configL let pkgopts = hidePkgOpts ++ genOpts ++ ghcOpts shouldHidePackages = fromMaybe (not (null pkgs && null exposePackages)) ghciHidePackages hidePkgOpts = if shouldHidePackages then ["-hide-all-packages"] ++ -- This is necessary, because current versions of ghci -- will entirely fail to start if base isn't visible. This -- is because it tries to use the interpreter to set -- buffering options on standard IO. (if null targets then ["-package", "base"] else []) ++ concatMap (\n -> ["-package", packageNameString n]) exposePackages else [] oneWordOpts bio | shouldHidePackages = bioOneWordOpts bio ++ bioPackageFlags bio | otherwise = bioOneWordOpts bio genOpts = nubOrd (concatMap (concatMap (oneWordOpts . snd) . ghciPkgOpts) pkgs) (omittedOpts, ghcOpts) = L.partition badForGhci $ concatMap (concatMap (bioOpts . snd) . ghciPkgOpts) pkgs ++ map T.unpack ( fold (configGhcOptionsByCat config) -- include everything, locals, and targets ++ concatMap (getUserOptions . ghciPkgName) pkgs ) getUserOptions pkg = M.findWithDefault [] pkg (configGhcOptionsByName config) badForGhci x = L.isPrefixOf "-O" x || elem x (words "-debug -threaded -ticky -static -Werror") unless (null omittedOpts) $ logWarn ("The following GHC options are incompatible with GHCi and have not been passed to it: " <> mconcat (L.intersperse " " (fromString <$> nubOrd omittedOpts))) oiDir <- view objectInterfaceDirL let odir = [ "-odir=" <> toFilePathNoTrailingSep oiDir , "-hidir=" <> toFilePathNoTrailingSep oiDir ] logInfo $ "Configuring GHCi with the following packages: " <> mconcat (L.intersperse ", " (map (fromString . packageNameString . ghciPkgName) pkgs)) compilerExeName <- view $ compilerPathsL.to cpCompiler.to toFilePath let execGhci extras = do menv <- liftIO $ configProcessContextSettings config defaultEnvSettings withPackageWorkingDir $ withProcessContext menv $ exec (fromMaybe compilerExeName ghciGhcCommand) (("--interactive" : ) $ -- This initial "-i" resets the include directories to -- not include CWD. If there aren't any packages, CWD -- is included. (if null pkgs then id else ("-i" : )) $ odir <> pkgopts <> extras <> ghciGhcOptions <> ghciArgs) withPackageWorkingDir = case pkgs of [pkg] -> withWorkingDir (toFilePath $ ghciPkgDir pkg) _ -> id -- TODO: Consider optimizing this check. Perhaps if no -- "with-ghc" is specified, assume that it is not using intero. checkIsIntero = -- Optimization dependent on the behavior of renderScript - -- it doesn't matter if it's intero or ghci when loading -- multiple packages. case pkgs of [_] -> do menv <- liftIO $ configProcessContextSettings config defaultEnvSettings output <- withProcessContext menv $ runGrabFirstLine (fromMaybe compilerExeName ghciGhcCommand) ["--version"] pure $ "Intero" `L.isPrefixOf` output _ -> pure False -- Since usage of 'exec' does not pure, we cannot do any cleanup -- on ghci exit. So, instead leave the generated files. To make this -- more efficient and avoid gratuitous generation of garbage, the -- file names are determined by hashing. This also has the nice side -- effect of making it possible to copy the ghci invocation out of -- the log and have it still work. tmpDirectory <- ( relDirHaskellStackGhci) <$> (parseAbsDir =<< liftIO getCanonicalTemporaryDirectory) ghciDir <- view ghciDirL ensureDir ghciDir ensureDir tmpDirectory macrosOptions <- writeMacrosFile ghciDir pkgs if ghciNoLoadModules then execGhci macrosOptions else do checkForDuplicateModules pkgs isIntero <- checkIsIntero scriptOptions <- writeGhciScript tmpDirectory (renderScript isIntero pkgs mainFile ghciOnlyMain extraFiles) execGhci (macrosOptions ++ scriptOptions) writeMacrosFile :: HasTerm env => Path Abs Dir -> [GhciPkgInfo] -> RIO env [String] writeMacrosFile outputDirectory pkgs = do fps <- fmap (nubOrd . catMaybes . concat) $ forM pkgs $ \pkg -> forM (ghciPkgOpts pkg) $ \(_, bio) -> do let cabalMacros = bioCabalMacros bio exists <- liftIO $ doesFileExist cabalMacros if exists then pure $ Just cabalMacros else do prettyWarnL ["Didn't find expected autogen file:", pretty cabalMacros] pure Nothing files <- liftIO $ mapM (S8.readFile . toFilePath) fps if null files then pure [] else do out <- liftIO $ writeHashedFile outputDirectory relFileCabalMacrosH $ S8.concat $ map (<> "\n#undef CURRENT_PACKAGE_KEY\n#undef CURRENT_COMPONENT_ID\n") files pure ["-optP-include", "-optP" <> toFilePath out] writeGhciScript :: (MonadIO m) => Path Abs Dir -> GhciScript -> m [String] writeGhciScript outputDirectory script = do scriptPath <- liftIO $ writeHashedFile outputDirectory relFileGhciScript $ LBS.toStrict $ scriptToLazyByteString script let scriptFilePath = toFilePath scriptPath setScriptPerms scriptFilePath pure ["-ghci-script=" <> scriptFilePath] writeHashedFile :: Path Abs Dir -> Path Rel File -> ByteString -> IO (Path Abs File) writeHashedFile outputDirectory relFile contents = do relSha <- shaPathForBytes contents let outDir = outputDirectory relSha outFile = outDir relFile alreadyExists <- doesFileExist outFile unless alreadyExists $ do ensureDir outDir writeBinaryFileAtomic outFile $ byteString contents pure outFile renderScript :: Bool -> [GhciPkgInfo] -> Maybe (Path Abs File) -> Bool -> [Path Abs File] -> GhciScript renderScript isIntero pkgs mainFile onlyMain extraFiles = do let cdPhase = case (isIntero, pkgs) of -- If only loading one package, set the cwd properly. -- Otherwise don't try. See -- https://github.com/commercialhaskell/stack/issues/3309 (True, [pkg]) -> cmdCdGhc (ghciPkgDir pkg) _ -> mempty addPhase = cmdAdd $ S.fromList (map Left allModules ++ addMain) addMain = case mainFile of Just path -> [Right path] _ -> [] modulePhase = cmdModule $ S.fromList allModules allModules = nubOrd $ concatMap (M.keys . ghciPkgModules) pkgs case getFileTargets pkgs <> extraFiles of [] -> if onlyMain then cdPhase <> if isJust mainFile then cmdAdd (S.fromList addMain) else mempty else cdPhase <> addPhase <> modulePhase fileTargets -> cmdAdd (S.fromList (map Right fileTargets)) -- Hacky check if module / main phase should be omitted. This should be -- improved if / when we have a better per-component load. getFileTargets :: [GhciPkgInfo] -> [Path Abs File] getFileTargets = concatMap (concat . maybeToList . ghciPkgTargetFiles) -- | Figure out the main-is file to load based on the targets. Asks the -- user for input if there is more than one candidate main-is file. figureOutMainFile :: HasRunner env => BuildOpts -> Maybe (Map PackageName Target) -> [(PackageName, (Path Abs File, Target))] -> [GhciPkgInfo] -> RIO env (Maybe (Path Abs File)) figureOutMainFile bopts mainIsTargets targets0 packages = do case candidates of [] -> pure Nothing [c@(_,_,fp)] -> do logInfo ("Using main module: " <> display (renderCandidate c)) pure (Just fp) candidate:_ -> do borderedWarning $ do logWarn "The main module to load is ambiguous. Candidates are: " forM_ (map renderCandidate candidates) (logWarn . display) logWarn "You can specify which one to pick by: " logWarn (" * Specifying targets to stack ghci e.g. stack ghci " <> display ( sampleTargetArg candidate)) logWarn (" * Specifying what the main is e.g. stack ghci " <> display (sampleMainIsArg candidate)) logWarn (" * Choosing from the candidate above [1.." <> display (length candidates) <> "]") liftIO userOption where targets = fromMaybe (M.fromList $ map (\(k, (_, x)) -> (k, x)) targets0) mainIsTargets candidates = do pkg <- packages case M.lookup (ghciPkgName pkg) targets of Nothing -> [] Just target -> do (component,mains) <- M.toList $ M.filterWithKey (\k _ -> k `S.member` wantedComponents) (ghciPkgMainIs pkg) main <- mains pure (ghciPkgName pkg, component, main) where wantedComponents = wantedPackageComponents bopts target (ghciPkgPackage pkg) renderCandidate c@(pkgName,namedComponent,mainIs) = let candidateIndex = T.pack . show . (+1) . fromMaybe 0 . L.elemIndex c pkgNameText = T.pack (packageNameString pkgName) in candidateIndex candidates <> ". Package `" <> pkgNameText <> "' component " <> -- This is the format that can be directly copy-pasted as -- an argument to `stack ghci`. pkgNameText <> ":" <> renderComp namedComponent <> " with main-is file: " <> T.pack (toFilePath mainIs) candidateIndices = take (length candidates) [1 :: Int ..] userOption = do option <- prompt "Specify main module to use (press enter to load none): " let selected = fromMaybe ((+1) $ length candidateIndices) (readMaybe (T.unpack option) :: Maybe Int) case L.elemIndex selected candidateIndices of Nothing -> do putStrLn "Not loading any main modules, as no valid module selected" putStrLn "" pure Nothing Just op -> do let (_,_,fp) = candidates L.!! op putStrLn ("Loading main module from candidate " <> show (op + 1) <> ", --main-is " <> toFilePath fp) putStrLn "" pure $ Just fp renderComp c = case c of CLib -> "lib" CInternalLib name -> "internal-lib:" <> name CExe name -> "exe:" <> name CTest name -> "test:" <> name CBench name -> "bench:" <> name sampleTargetArg (pkg,comp,_) = T.pack (packageNameString pkg) <> ":" <> renderComp comp sampleMainIsArg (pkg,comp,_) = "--main-is " <> T.pack (packageNameString pkg) <> ":" <> renderComp comp loadGhciPkgDescs :: HasEnvConfig env => BuildOptsCLI -> [(PackageName, (Path Abs File, Target))] -> RIO env [GhciPkgDesc] loadGhciPkgDescs buildOptsCLI localTargets = forM localTargets $ \(name, (cabalfp, target)) -> loadGhciPkgDesc buildOptsCLI name cabalfp target -- | Load package description information for a ghci target. loadGhciPkgDesc :: HasEnvConfig env => BuildOptsCLI -> PackageName -> Path Abs File -> Target -> RIO env GhciPkgDesc loadGhciPkgDesc buildOptsCLI name cabalfp target = do econfig <- view envConfigL compilerVersion <- view actualCompilerVersionL let SourceMap{..} = envConfigSourceMap econfig -- Currently this source map is being build with -- the default targets sourceMapGhcOptions = fromMaybe [] $ (cpGhcOptions . ppCommon <$> M.lookup name smProject) <|> (cpGhcOptions . dpCommon <$> M.lookup name smDeps) sourceMapCabalConfigOpts = fromMaybe [] $ (cpCabalConfigOpts . ppCommon <$> M.lookup name smProject) <|> (cpCabalConfigOpts . dpCommon <$> M.lookup name smDeps) sourceMapFlags = maybe mempty (cpFlags . ppCommon) $ M.lookup name smProject config = PackageConfig { packageConfigEnableTests = True , packageConfigEnableBenchmarks = True , packageConfigFlags = getLocalFlags buildOptsCLI name `M.union` sourceMapFlags , packageConfigGhcOptions = sourceMapGhcOptions , packageConfigCabalConfigOpts = sourceMapCabalConfigOpts , packageConfigCompilerVersion = compilerVersion , packageConfigPlatform = view platformL econfig } -- TODO we've already parsed this information, otherwise we -- wouldn't have figured out the cabalfp already. In the future: -- retain that GenericPackageDescription in the relevant data -- structures to avoid reparsing. (gpdio, _name, _cabalfp) <- loadCabalFilePath (Just stackProgName') (parent cabalfp) gpkgdesc <- liftIO $ gpdio YesPrintWarnings -- Source the package's *.buildinfo file created by configure if any. See -- https://www.haskell.org/cabal/users-guide/developing-packages.html#system-dependent-parameters buildinfofp <- parseRelFile (packageNameString name ++ ".buildinfo") hasDotBuildinfo <- doesFileExist (parent cabalfp buildinfofp) let mbuildinfofp | hasDotBuildinfo = Just (parent cabalfp buildinfofp) | otherwise = Nothing mbuildinfo <- forM mbuildinfofp readDotBuildinfo let pdp = resolvePackageDescription config gpkgdesc pkg = packageFromPackageDescription config (C.genPackageFlags gpkgdesc) $ maybe pdp (\bi -> let PackageDescriptionPair x y = pdp in PackageDescriptionPair (C.updatePackageDescription bi x) (C.updatePackageDescription bi y)) mbuildinfo pure GhciPkgDesc { ghciDescPkg = pkg , ghciDescCabalFp = cabalfp , ghciDescTarget = target } getGhciPkgInfos :: HasEnvConfig env => InstallMap -> [PackageName] -> Maybe (Map PackageName [Path Abs File]) -> [GhciPkgDesc] -> RIO env [GhciPkgInfo] getGhciPkgInfos installMap addPkgs mfileTargets localTargets = do (installedMap, _, _, _) <- getInstalled installMap let localLibs = [ packageName (ghciDescPkg desc) | desc <- localTargets , hasLocalComp isCLib (ghciDescTarget desc) ] forM localTargets $ \pkgDesc -> makeGhciPkgInfo installMap installedMap localLibs addPkgs mfileTargets pkgDesc -- | Make information necessary to load the given package in GHCi. makeGhciPkgInfo :: HasEnvConfig env => InstallMap -> InstalledMap -> [PackageName] -> [PackageName] -> Maybe (Map PackageName [Path Abs File]) -> GhciPkgDesc -> RIO env GhciPkgInfo makeGhciPkgInfo installMap installedMap locals addPkgs mfileTargets pkgDesc = do bopts <- view buildOptsL let pkg = ghciDescPkg pkgDesc cabalfp = ghciDescCabalFp pkgDesc target = ghciDescTarget pkgDesc name = packageName pkg (mods,files,opts) <- getPackageOpts (packageOpts pkg) installMap installedMap locals addPkgs cabalfp let filteredOpts = filterWanted opts filterWanted = M.filterWithKey (\k _ -> k `S.member` allWanted) allWanted = wantedPackageComponents bopts target pkg pure GhciPkgInfo { ghciPkgName = name , ghciPkgOpts = M.toList filteredOpts , ghciPkgDir = parent cabalfp , ghciPkgModules = unionModuleMaps $ map (\(comp, mp) -> M.map (\fp -> M.singleton fp (S.singleton (packageName pkg, comp))) mp) (M.toList (filterWanted mods)) , ghciPkgMainIs = M.map (mapMaybe dotCabalMainPath) files , ghciPkgCFiles = mconcat (M.elems (filterWanted (M.map (mapMaybe dotCabalCFilePath) files))) , ghciPkgTargetFiles = mfileTargets >>= M.lookup name , ghciPkgPackage = pkg } -- NOTE: this should make the same choices as the components code in -- 'loadLocalPackage'. Unfortunately for now we reiterate this logic -- (differently). wantedPackageComponents :: BuildOpts -> Target -> Package -> Set NamedComponent wantedPackageComponents _ (TargetComps cs) _ = cs wantedPackageComponents bopts (TargetAll PTProject) pkg = S.fromList $ (case packageLibraries pkg of NoLibraries -> [] HasLibraries names -> CLib : map CInternalLib (S.toList names)) ++ map CExe (S.toList (packageExes pkg)) <> map CInternalLib (S.toList $ packageInternalLibraries pkg) <> (if boptsTests bopts then map CTest (M.keys (packageTests pkg)) else []) <> (if boptsBenchmarks bopts then map CBench (S.toList (packageBenchmarks pkg)) else []) wantedPackageComponents _ _ _ = S.empty checkForIssues :: HasLogFunc env => [GhciPkgInfo] -> RIO env () checkForIssues pkgs = do when (length pkgs > 1) $ borderedWarning $ do -- Cabal flag issues could arise only when there are at least 2 packages unless (null cabalFlagIssues) $ borderedWarning $ do logWarn "Warning: There are cabal flags for this project which may prevent GHCi from loading your code properly." logWarn "In some cases it can also load some projects which would otherwise fail to build." logWarn "" mapM_ (logWarn . display) $ L.intercalate [""] cabalFlagIssues logWarn "" logWarn "To resolve, remove the flag(s) from the Cabal file(s) and instead put them at the top of the haskell files." logWarn "" logWarn "It isn't yet possible to load multiple packages into GHCi in all cases - see" logWarn "https://ghc.haskell.org/trac/ghc/ticket/10827" where cabalFlagIssues = concatMap mixedFlag [ ( "-XNoImplicitPrelude" , [ "-XNoImplicitPrelude will be used, but GHCi will likely fail to build things which depend on the implicit prelude."] ) , ( "-XCPP" , [ "-XCPP will be used, but it can cause issues with multiline strings." , "See https://downloads.haskell.org/~ghc/7.10.2/docs/html/users_guide/options-phases.html#cpp-string-gaps" ] ) , ( "-XNoTraditionalRecordSyntax" , [ "-XNoTraditionalRecordSyntax will be used, but it break modules which use record syntax." ] ) , ( "-XTemplateHaskell" , [ "-XTemplateHaskell will be used, but it may cause compilation issues due to different parsing of '$' when there's no space after it." ] ) , ( "-XQuasiQuotes" , [ "-XQuasiQuotes will be used, but it may cause parse failures due to a different meaning for list comprehension syntax like [x| ... ]" ] ) , ( "-XSafe" , [ "-XSafe will be used, but it will fail to compile unsafe modules." ] ) , ( "-XArrows" , [ "-XArrows will be used, but it will cause non-arrow usages of proc, (-<), (-<<) to fail" ] ) , ( "-XOverloadedStrings" , [ "-XOverloadedStrings will be used, but it can cause type ambiguity in code not usually compiled with it." ] ) , ( "-XOverloadedLists" , [ "-XOverloadedLists will be used, but it can cause type ambiguity in code not usually compiled with it." ] ) , ( "-XMonoLocalBinds" , [ "-XMonoLocalBinds will be used, but it can cause type errors in code which expects generalized local bindings." ] ) , ( "-XTypeFamilies" , [ "-XTypeFamilies will be used, but it implies -XMonoLocalBinds, and so can cause type errors in code which expects generalized local bindings." ] ) , ( "-XGADTs" , [ "-XGADTs will be used, but it implies -XMonoLocalBinds, and so can cause type errors in code which expects generalized local bindings." ] ) , ( "-XNewQualifiedOperators" , [ "-XNewQualifiedOperators will be used, but this will break usages of the old qualified operator syntax." ] ) ] mixedFlag (flag, msgs) = let x = partitionComps (== flag) in [ msgs ++ showWhich x | mixedSettings x ] mixedSettings (xs, ys) = xs /= [] && ys /= [] showWhich (haveIt, don'tHaveIt) = [ "It is specified for:" , " " <> renderPkgComponents haveIt , "But not for: " , " " <> renderPkgComponents don'tHaveIt ] partitionComps f = (map fst xs, map fst ys) where (xs, ys) = L.partition (any f . snd) compsWithOpts compsWithOpts = map (\(k, bio) -> (k, bioOneWordOpts bio ++ bioOpts bio)) compsWithBios compsWithBios = [ ((ghciPkgName pkg, c), bio) | pkg <- pkgs , (c, bio) <- ghciPkgOpts pkg ] borderedWarning :: HasLogFunc env => RIO env a -> RIO env a borderedWarning f = do logWarn "" logWarn "* * * * * * * *" x <- f logWarn "* * * * * * * *" logWarn "" pure x -- TODO: Should this also tell the user the filepaths, not just the -- module name? checkForDuplicateModules :: HasTerm env => [GhciPkgInfo] -> RIO env () checkForDuplicateModules pkgs = do unless (null duplicates) $ do borderedWarning $ do prettyWarn $ "Multiple files use the same module name:" <> line <> bulletedList (map prettyDuplicate duplicates) -- MSS 2020-10-13 Disabling, may remove entirely in the future -- See: https://github.com/commercialhaskell/stack/issues/5407#issuecomment-707339928 -- throwM LoadingDuplicateModules where duplicates :: [(ModuleName, Map (Path Abs File) (Set (PackageName, NamedComponent)))] duplicates = filter (\(_, mp) -> M.size mp > 1) $ M.toList $ unionModuleMaps (map ghciPkgModules pkgs) prettyDuplicate :: (ModuleName, Map (Path Abs File) (Set (PackageName, NamedComponent))) -> StyleDoc prettyDuplicate (mn, mp) = style Error (pretty mn) <+> "found at the following paths" <> line <> bulletedList (map fileDuplicate (M.toList mp)) fileDuplicate :: (Path Abs File, Set (PackageName, NamedComponent)) -> StyleDoc fileDuplicate (fp, comps) = pretty fp <+> parens (fillSep (punctuate "," (map displayPkgComponent (S.toList comps)))) targetWarnings :: HasBuildConfig env => [(PackageName, (Path Abs File, Target))] -> [PackageName] -> Maybe (Map PackageName [Path Abs File], [Path Abs File]) -> RIO env () targetWarnings localTargets nonLocalTargets mfileTargets = do unless (null nonLocalTargets) $ prettyWarnL [ flow "Some targets" , parens $ fillSep $ punctuate "," $ map (style Good . fromString . packageNameString) nonLocalTargets , flow "are not local packages, and so cannot be directly loaded." , flow "In future versions of Stack, this might be supported - see" , style Url "https://github.com/commercialhaskell/stack/issues/1441" , "." , flow "It can still be useful to specify these, as they will be passed to ghci via -package flags." ] when (null localTargets && isNothing mfileTargets) $ do smWanted <- view $ buildConfigL.to bcSMWanted stackYaml <- view stackYamlL prettyNote $ vsep [ flow "No local targets specified, so a plain ghci will be started with no package hiding or package options." , "" , flow $ T.unpack $ utf8BuilderToText $ "You are using snapshot: " <> display (smwSnapshotLocation smWanted) , "" , flow "If you want to use package hiding and options, then you can try one of the following:" , "" , bulletedList [ fillSep [ flow "If you want to start a different project configuration than" <+> pretty stackYaml <> ", then you can use" , style Shell "stack init" , flow "to create a new stack.yaml for the packages in the current directory." , line ] , flow "If you want to use the project configuration at" <+> pretty stackYaml <> ", then you can add to its 'packages' field." ] , "" ] -- Adds in intermediate dependencies between ghci targets. Note that it -- will return a Lib component for these intermediate dependencies even -- if they don't have a library (but that's fine for the usage within -- this module). -- -- If 'True' is passed for loadAllDeps, this loads all local deps, even -- if they aren't intermediate. getExtraLoadDeps :: Bool -> Map PackageName LocalPackage -> [(PackageName, (Path Abs File, Target))] -> [(PackageName, (Path Abs File, Target))] getExtraLoadDeps loadAllDeps localMap targets = M.toList $ (\mp -> foldl' (flip M.delete) mp (map fst targets)) $ M.mapMaybe id $ execState (mapM_ (mapM_ go . getDeps . fst) targets) (M.fromList (map (second Just) targets)) where getDeps :: PackageName -> [PackageName] getDeps name = case M.lookup name localMap of Just lp -> M.keys (packageDeps (lpPackage lp)) -- FIXME just Local? _ -> [] go :: PackageName -> State (Map PackageName (Maybe (Path Abs File, Target))) Bool go name = do cache <- get case (M.lookup name cache, M.lookup name localMap) of (Just (Just _), _) -> pure True (Just Nothing, _) | not loadAllDeps -> pure False (_, Just lp) -> do let deps = M.keys (packageDeps (lpPackage lp)) shouldLoad <- liftM or $ mapM go deps if shouldLoad then do modify (M.insert name (Just (lpCabalFile lp, TargetComps (S.singleton CLib)))) pure True else do modify (M.insert name Nothing) pure False (_, _) -> pure False unionTargets :: Ord k => Map k Target -> Map k Target -> Map k Target unionTargets = M.unionWith $ \l r -> case (l, r) of (TargetAll PTDependency, _) -> r (TargetComps sl, TargetComps sr) -> TargetComps (S.union sl sr) (TargetComps _, TargetAll PTProject) -> TargetAll PTProject (TargetComps _, _) -> l (TargetAll PTProject, _) -> TargetAll PTProject hasLocalComp :: (NamedComponent -> Bool) -> Target -> Bool hasLocalComp p t = case t of TargetComps s -> any p (S.toList s) TargetAll PTProject -> True _ -> False -- | Run a command and grab the first line of stdout, dropping -- stderr's contexts completely. runGrabFirstLine :: (HasProcessContext env, HasLogFunc env) => String -> [String] -> RIO env String runGrabFirstLine cmd0 args = proc cmd0 args $ \pc -> do (out, _err) <- readProcess_ pc pure $ TL.unpack $ TL.filter (/= '\r') $ TL.concat $ take 1 $ TL.lines $ TLE.decodeUtf8With lenientDecode out stack-2.9.3.1/src/Stack/Ghci/Script.hs0000644000000000000000000000527414445022466015504 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Ghci.Script ( GhciScript , ModuleName , cmdAdd , cmdCdGhc , cmdModule , scriptToLazyByteString , scriptToBuilder , scriptToFile ) where import Data.ByteString.Builder ( toLazyByteString ) import qualified Data.List as L import qualified Data.Set as S import Distribution.ModuleName hiding ( toFilePath ) import Path import Stack.Prelude hiding ( Module ) import System.IO ( hSetBinaryMode ) newtype GhciScript = GhciScript { unGhciScript :: [GhciCommand] } instance Semigroup GhciScript where GhciScript xs <> GhciScript ys = GhciScript (ys <> xs) instance Monoid GhciScript where mempty = GhciScript [] mappend = (<>) data GhciCommand = Add (Set (Either ModuleName (Path Abs File))) | CdGhc (Path Abs Dir) | Module (Set ModuleName) deriving (Show) cmdAdd :: Set (Either ModuleName (Path Abs File)) -> GhciScript cmdAdd = GhciScript . (:[]) . Add cmdCdGhc :: Path Abs Dir -> GhciScript cmdCdGhc = GhciScript . (:[]) . CdGhc cmdModule :: Set ModuleName -> GhciScript cmdModule = GhciScript . (:[]) . Module scriptToLazyByteString :: GhciScript -> LByteString scriptToLazyByteString = toLazyByteString . scriptToBuilder scriptToBuilder :: GhciScript -> Builder scriptToBuilder backwardScript = mconcat $ fmap commandToBuilder script where script = reverse $ unGhciScript backwardScript scriptToFile :: Path Abs File -> GhciScript -> IO () scriptToFile path script = withFile filepath WriteMode $ \hdl -> do hSetBuffering hdl (BlockBuffering Nothing) hSetBinaryMode hdl True hPutBuilder hdl (scriptToBuilder script) where filepath = toFilePath path -- Command conversion commandToBuilder :: GhciCommand -> Builder commandToBuilder (Add modules) | S.null modules = mempty | otherwise = ":add " <> mconcat (L.intersperse " " $ fmap (fromString . quoteFileName . either (mconcat . L.intersperse "." . components) toFilePath) (S.toAscList modules)) <> "\n" commandToBuilder (CdGhc path) = ":cd-ghc " <> fromString (quoteFileName (toFilePath path)) <> "\n" commandToBuilder (Module modules) | S.null modules = ":module +\n" | otherwise = ":module + " <> mconcat (L.intersperse " " $ fromString . quoteFileName . mconcat . L.intersperse "." . components <$> S.toAscList modules) <> "\n" -- | Make sure that a filename with spaces in it gets the proper quotes. quoteFileName :: String -> String quoteFileName x = if ' ' `elem` x then show x else x stack-2.9.3.1/src/Stack/Hoogle.hs0000644000000000000000000002250414445022466014576 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -- | A wrapper around hoogle. module Stack.Hoogle ( hoogleCmd ) where import qualified Data.ByteString.Lazy.Char8 as BL8 import Data.Char ( isSpace ) import qualified Data.Text as T import Distribution.PackageDescription ( packageDescription, package ) import Distribution.Types.PackageName ( mkPackageName ) import Distribution.Version ( mkVersion ) import Lens.Micro ( (?~) ) import Path ( parseAbsFile ) import Path.IO hiding ( findExecutable ) import qualified Stack.Build import Stack.Build.Target ( NeedTargets (NeedTargets) ) import Stack.Prelude import Stack.Runners import Stack.Types.Config import Stack.Types.SourceMap import qualified RIO.Map as Map import RIO.Process -- | Type representing exceptions thrown by functions exported by the -- "Stack.Hoogle" module. data HoogleException = HoogleDatabaseNotFound | HoogleNotFound !Text | HoogleOnPathNotFoundBug deriving (Show, Typeable) instance Exception HoogleException where displayException HoogleDatabaseNotFound = "Error: [S-3025]\n" ++ "No Hoogle database. Not building one due to '--no-setup'." displayException (HoogleNotFound e) = "Error: [S-1329]\n" ++ T.unpack e ++ "\n" ++ "Not installing Hoogle due to '--no-setup'." displayException HoogleOnPathNotFoundBug = bugReport "[S-9669]" "Cannot find Hoogle executable on PATH, after installing." -- | Helper type to duplicate log messages data Muted = Muted | NotMuted -- | Hoogle command. hoogleCmd :: ([String],Bool,Bool,Bool) -> RIO Runner () hoogleCmd (args,setup,rebuild,startServer) = local (over globalOptsL modifyGO) $ withConfig YesReexec $ withDefaultEnvConfig $ do hooglePath <- ensureHoogleInPath generateDbIfNeeded hooglePath runHoogle hooglePath args' where modifyGO :: GlobalOpts -> GlobalOpts modifyGO = globalOptsBuildOptsMonoidL . buildOptsMonoidHaddockL ?~ True args' :: [String] args' = if startServer then ["server", "--local", "--port", "8080"] else [] ++ args generateDbIfNeeded :: Path Abs File -> RIO EnvConfig () generateDbIfNeeded hooglePath = do databaseExists <- checkDatabaseExists if databaseExists && not rebuild then pure () else if setup || rebuild then do logWarn (if rebuild then "Rebuilding database ..." else "No Hoogle database yet. Automatically building haddocks and hoogle database (use --no-setup to disable) ...") buildHaddocks logInfo "Built docs." generateDb hooglePath logInfo "Generated DB." else throwIO HoogleDatabaseNotFound generateDb :: Path Abs File -> RIO EnvConfig () generateDb hooglePath = do do dir <- hoogleRoot createDirIfMissing True dir runHoogle hooglePath ["generate", "--local"] buildHaddocks :: RIO EnvConfig () buildHaddocks = do config <- view configL runRIO config $ -- a bit weird that we have to drop down like this catch (withDefaultEnvConfig $ Stack.Build.build Nothing) (\(_ :: ExitCode) -> pure ()) hooglePackageName = mkPackageName "hoogle" hoogleMinVersion = mkVersion [5, 0] hoogleMinIdent = PackageIdentifier hooglePackageName hoogleMinVersion installHoogle :: RIO EnvConfig (Path Abs File) installHoogle = requiringHoogle Muted $ do Stack.Build.build Nothing mhooglePath' <- findExecutable "hoogle" case mhooglePath' of Right hooglePath -> parseAbsFile hooglePath Left _ -> throwIO HoogleOnPathNotFoundBug requiringHoogle :: Muted -> RIO EnvConfig x -> RIO EnvConfig x requiringHoogle muted f = do hoogleTarget <- do sourceMap <- view $ sourceMapL . to smDeps case Map.lookup hooglePackageName sourceMap of Just hoogleDep -> case dpLocation hoogleDep of PLImmutable pli -> T.pack . packageIdentifierString <$> restrictMinHoogleVersion muted (packageLocationIdent pli) plm@(PLMutable _) -> do T.pack . packageIdentifierString . package . packageDescription <$> loadCabalFile (Just stackProgName') plm Nothing -> do -- not muted because this should happen only once logWarn "No hoogle version was found, trying to install the latest version" mpir <- getLatestHackageVersion YesRequireHackageIndex hooglePackageName UsePreferredVersions let hoogleIdent = case mpir of Nothing -> hoogleMinIdent Just (PackageIdentifierRevision _ ver _) -> PackageIdentifier hooglePackageName ver T.pack . packageIdentifierString <$> restrictMinHoogleVersion muted hoogleIdent config <- view configL let boptsCLI = defaultBuildOptsCLI { boptsCLITargets = [hoogleTarget] } runRIO config $ withEnvConfig NeedTargets boptsCLI f restrictMinHoogleVersion :: HasLogFunc env => Muted -> PackageIdentifier -> RIO env PackageIdentifier restrictMinHoogleVersion muted ident = do if ident < hoogleMinIdent then do muteableLog LevelWarn muted $ "Minimum " <> fromString (packageIdentifierString hoogleMinIdent) <> " is not in your index. Installing the minimum version." pure hoogleMinIdent else do muteableLog LevelInfo muted $ "Minimum version is " <> fromString (packageIdentifierString hoogleMinIdent) <> ". Found acceptable " <> fromString (packageIdentifierString ident) <> " in your index, requiring its installation." pure ident muteableLog :: HasLogFunc env => LogLevel -> Muted -> Utf8Builder -> RIO env () muteableLog logLevel muted msg = case muted of Muted -> pure () NotMuted -> logGeneric "" logLevel msg runHoogle :: Path Abs File -> [String] -> RIO EnvConfig () runHoogle hooglePath hoogleArgs = do config <- view configL menv <- liftIO $ configProcessContextSettings config envSettings dbpath <- hoogleDatabasePath let databaseArg = ["--database=" ++ toFilePath dbpath] withProcessContext menv $ proc (toFilePath hooglePath) (hoogleArgs ++ databaseArg) runProcess_ checkDatabaseExists = do path <- hoogleDatabasePath liftIO (doesFileExist path) ensureHoogleInPath :: RIO EnvConfig (Path Abs File) ensureHoogleInPath = do config <- view configL menv <- liftIO $ configProcessContextSettings config envSettings mhooglePath <- runRIO menv (findExecutable "hoogle") <> requiringHoogle NotMuted (findExecutable "hoogle") eres <- case mhooglePath of Left _ -> pure $ Left "Hoogle isn't installed." Right hooglePath -> do result <- withProcessContext menv $ proc hooglePath ["--numeric-version"] $ tryAny . fmap fst . readProcess_ let unexpectedResult got = Left $ T.concat [ "'" , T.pack hooglePath , " --numeric-version' did not respond with expected value. Got: " , got ] pure $ case result of Left err -> unexpectedResult $ T.pack (displayException err) Right bs -> case parseVersion (takeWhile (not . isSpace) (BL8.unpack bs)) of Nothing -> unexpectedResult $ T.pack (BL8.unpack bs) Just ver | ver >= hoogleMinVersion -> Right hooglePath | otherwise -> Left $ T.concat [ "Installed Hoogle is too old, " , T.pack hooglePath , " is version " , T.pack $ versionString ver , " but >= 5.0 is required." ] case eres of Right hooglePath -> parseAbsFile hooglePath Left err | setup -> do logWarn $ display err <> " Automatically installing (use --no-setup to disable) ..." installHoogle | otherwise -> throwIO $ HoogleNotFound err envSettings = EnvSettings { esIncludeLocals = True , esIncludeGhcPackagePath = True , esStackExe = True , esLocaleUtf8 = False , esKeepGhcRts = False } stack-2.9.3.1/src/Stack/IDE.hs0000644000000000000000000000403314445022466013757 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} -- | Functions for IDEs. module Stack.IDE ( OutputStream (..) , ListPackagesCmd (..) , listPackages , listTargets ) where import qualified Data.Map as Map import qualified Data.Set as Set import qualified Data.Text as T import Stack.Prelude import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.SourceMap import System.IO (putStrLn) data OutputStream = OutputLogInfo | OutputStdout data ListPackagesCmd = ListPackageNames | ListPackageCabalFiles outputFunc :: HasLogFunc env => OutputStream -> String -> RIO env () outputFunc OutputLogInfo = logInfo . fromString outputFunc OutputStdout = liftIO . putStrLn -- | List the packages inside the current project. listPackages :: HasBuildConfig env => OutputStream -> ListPackagesCmd -> RIO env () listPackages stream flag = do packages <- view $ buildConfigL.to (smwProject . bcSMWanted) let strs = case flag of ListPackageNames -> map packageNameString (Map.keys packages) ListPackageCabalFiles -> map (toFilePath . ppCabalFP) (Map.elems packages) mapM_ (outputFunc stream) strs -- | List the targets in the current project. listTargets :: forall env. HasBuildConfig env => OutputStream -> RIO env () listTargets stream = do packages <- view $ buildConfigL.to (smwProject . bcSMWanted) pairs <- concat <$> Map.traverseWithKey toNameAndComponent packages outputFunc stream $ T.unpack $ T.intercalate "\n" $ map renderPkgComponent pairs where toNameAndComponent :: PackageName -> ProjectPackage -> RIO env [(PackageName, NamedComponent)] toNameAndComponent pkgName' = fmap (map (pkgName', ) . Set.toList) . ppComponents stack-2.9.3.1/src/Stack/Init.hs0000644000000000000000000006724714445022466014301 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} module Stack.Init ( initProject , InitOpts (..) ) where import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.ByteString.Builder as B import qualified Data.ByteString.Char8 as BC import qualified Data.Foldable as F import qualified Data.IntMap as IntMap import Data.List.Extra ( groupSortOn ) import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Map.Strict as Map import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Yaml as Yaml import qualified Distribution.PackageDescription as C import qualified Distribution.Text as C import qualified Distribution.Version as C import Path import Path.Extra ( toFilePathNoTrailingSep ) import Path.Find ( findFiles ) import Path.IO hiding ( findFiles ) import qualified RIO.FilePath as FP import RIO.List ( (\\), intercalate, isSuffixOf, isPrefixOf ) import RIO.List.Partial ( minimumBy ) import Stack.BuildPlan import Stack.Config ( getSnapshots, makeConcreteResolver ) import Stack.Constants import Stack.Prelude import Stack.SourceMap import Stack.Types.Config import Stack.Types.Resolver import Stack.Types.Version ( stackMajorVersion ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Init" module. data InitException = NoPackagesToIgnoreBug deriving (Show, Typeable) instance Exception InitException where displayException NoPackagesToIgnoreBug = bugReport "[S-2747]" "No packages to ignore." data InitPrettyException = SnapshotDownloadFailure SomeException | ConfigFileAlreadyExists FilePath | PackageNameInvalid [(Path Abs File, PackageName)] deriving (Show, Typeable) instance Pretty InitPrettyException where pretty (ConfigFileAlreadyExists reldest) = "[S-8009]" <> line <> flow "Stack declined to create a project-level YAML configuration \ \file." <> blankLine <> fillSep [ flow "The file" , style File (fromString reldest) , "already exists. To overwrite it, pass the flag" , style Shell "--force" <> "." ] pretty (PackageNameInvalid rels) = "[S-5267]" <> line <> flow "Stack did not create project-level YAML configuration, as \ \(like Hackage) it requires a Cabal file name to match the \ \package it defines." <> blankLine <> flow "Please rename the following Cabal files:" <> line <> bulletedList ( map ( \(fp, name) -> fillSep [ style File (pretty fp) , "as" , style File (fromString (packageNameString name) <> ".cabal") ] ) rels ) pretty (SnapshotDownloadFailure e) = "[S-8332]" <> line <> flow "Stack failed to create project-level YAML configuration, as \ \it was unable to download the index of available snapshots." <> blankLine <> fillSep [ flow "This sometimes happens because Certificate Authorities \ \are missing on your system. You can try the Stack command \ \again or manually create the configuration file. For help \ \about the content of Stack's YAML configuration files, \ \see (for the most recent release of Stack)" , style Url "http://docs.haskellstack.org/en/stable/yaml_configuration/" <> "." ] <> blankLine <> flow "While downloading the snapshot index, Stack encountered the \ \following error:" <> blankLine <> string (displayException e) instance Exception InitPrettyException -- | Generate stack.yaml initProject :: (HasConfig env, HasGHCVariant env) => Path Abs Dir -> InitOpts -> Maybe AbstractResolver -> RIO env () initProject currDir initOpts mresolver = do let dest = currDir stackDotYaml reldest <- toFilePath `liftM` makeRelativeToCurrentDir dest exists <- doesFileExist dest when (not (forceOverwrite initOpts) && exists) $ throwIO $ PrettyException $ ConfigFileAlreadyExists reldest dirs <- mapM (resolveDir' . T.unpack) (searchDirs initOpts) let find = findCabalDirs (includeSubDirs initOpts) dirs' = if null dirs then [currDir] else dirs prettyInfo $ fillSep [ flow "Looking for Cabal or" , style File "package.yaml" , flow "files to use to initialise Stack's project-level YAML \ \configuration file." ] <> line cabaldirs <- Set.toList . Set.unions <$> mapM find dirs' (bundle, dupPkgs) <- cabalPackagesCheck cabaldirs let makeRelDir dir = case stripProperPrefix currDir dir of Nothing | currDir == dir -> "." | otherwise -> assert False $ toFilePathNoTrailingSep dir Just rel -> toFilePathNoTrailingSep rel fpToPkgDir fp = let absDir = parent fp in ResolvedPath (RelFilePath $ T.pack $ makeRelDir absDir) absDir pkgDirs = Map.map (fpToPkgDir . fst) bundle (snapshotLoc, flags, extraDeps, rbundle) <- getDefaultResolver initOpts mresolver pkgDirs let ignored = Map.difference bundle rbundle dupPkgMsg | dupPkgs /= [] = "Warning (added by new or init): Some packages were found to " <> "have names conflicting with others and have been commented " <> "out in the packages section.\n" | otherwise = "" missingPkgMsg | Map.size ignored > 0 = "Warning (added by new or init): Some packages were found to " <> "be incompatible with the resolver and have been left commented " <> "out in the packages section.\n" | otherwise = "" extraDepMsg | Map.size extraDeps > 0 = "Warning (added by new or init): Specified resolver could not " <> "satisfy all dependencies. Some external packages have been " <> "added as dependencies.\n" | otherwise = "" makeUserMsg msgs = let msg = concat msgs in if msg /= "" then msg <> "You can omit this message by removing it from " <> "stack.yaml\n" else "" userMsg = makeUserMsg [dupPkgMsg, missingPkgMsg, extraDepMsg] gpdByDir = Map.fromList [ (parent fp, gpd) | (fp, gpd) <- Map.elems bundle] gpds = Map.elems $ Map.mapMaybe (flip Map.lookup gpdByDir . resolvedAbsolute) rbundle deps <- for (Map.toList extraDeps) $ \(n, v) -> PLImmutable . cplComplete <$> completePackageLocation (RPLIHackage (PackageIdentifierRevision n v CFILatest) Nothing) let p = Project { projectUserMsg = if userMsg == "" then Nothing else Just userMsg , projectPackages = resolvedRelative <$> Map.elems rbundle , projectDependencies = map toRawPL deps , projectFlags = removeSrcPkgDefaultFlags gpds flags , projectResolver = snapshotLoc , projectCompiler = Nothing , projectExtraPackageDBs = [] , projectCurator = Nothing , projectDropPackages = mempty } makeRel = fmap toFilePath . makeRelativeToCurrentDir prettyInfo $ fillSep [ flow "Initialising Stack's project-level YAML configuration file \ \using snapshot" , pretty (PrettyRawSnapshotLocation snapshotLoc) <> "." ] prettyInfo $ let n = Map.size bundle + length dupPkgs in fillSep [ "Considered" , fromString $ show n , "user" , if n == 1 then "package." else "packages." ] when (dupPkgs /= []) $ do rels <- mapM makeRel dupPkgs prettyWarn $ fillSep [ flow "Ignoring these" , fromString $ show (length dupPkgs) , flow "duplicate packages:" ] <> line <> bulletedList (map (style File . fromString) rels) when (Map.size ignored > 0) $ do rels <- mapM makeRel (Map.elems (fmap fst ignored)) prettyWarn $ fillSep [ flow "Ignoring these" , fromString $ show (Map.size ignored) , flow "packages due to dependency conflicts:" ] <> line <> bulletedList (map (style File . fromString) rels) when (Map.size extraDeps > 0) $ do prettyWarn $ fillSep [ fromString $ show (Map.size extraDeps) , flow "external dependencies were added." ] prettyInfo $ fillSep [ flow $ if exists then "Overwriting existing configuration file" else "Writing configuration to" , style File (fromString reldest) <> "." ] writeBinaryFileAtomic dest $ renderStackYaml p (Map.elems $ fmap (makeRelDir . parent . fst) ignored) (map (makeRelDir . parent) dupPkgs) prettyInfo $ flow "Stack's project-level YAML configuration file has been \ \initialised." -- | Render a stack.yaml file with comments, see: -- https://github.com/commercialhaskell/stack/issues/226 renderStackYaml :: Project -> [FilePath] -> [FilePath] -> B.Builder renderStackYaml p ignoredPackages dupPackages = case Yaml.toJSON p of Yaml.Object o -> renderObject o _ -> assert False $ B.byteString $ Yaml.encode p where renderObject o = B.byteString headerHelp <> B.byteString "\n\n" <> F.foldMap (goComment o) comments <> goOthers (o `KeyMap.difference` KeyMap.fromList comments) <> B.byteString footerHelp <> "\n" goComment o (name, comment) = case (convert <$> KeyMap.lookup name o) <|> nonPresentValue name of Nothing -> assert (name == "user-message") mempty Just v -> B.byteString comment <> B.byteString "\n" <> v <> if name == "packages" then commentedPackages else "" <> B.byteString "\n" where convert v = B.byteString (Yaml.encode $ Yaml.object [(name, v)]) -- Some fields in stack.yaml are optional and may not be -- generated. For these, we provided commented out dummy -- values to go along with the comments. nonPresentValue "extra-deps" = Just "# extra-deps: []\n" nonPresentValue "flags" = Just "# flags: {}\n" nonPresentValue "extra-package-dbs" = Just "# extra-package-dbs: []\n" nonPresentValue _ = Nothing commentLine l | null l = "#" | otherwise = "# " ++ l commentHelp = BC.pack . intercalate "\n" . map commentLine commentedPackages = let ignoredComment = commentHelp [ "The following packages have been ignored due to incompatibility with the" , "resolver compiler, dependency conflicts with other packages" , "or unsatisfied dependencies." ] dupComment = commentHelp [ "The following packages have been ignored due to package name conflict " , "with other packages." ] in commentPackages ignoredComment ignoredPackages <> commentPackages dupComment dupPackages commentPackages comment pkgs | pkgs /= [] = B.byteString comment <> B.byteString "\n" <> B.byteString (BC.pack $ concat $ map (\x -> "#- " ++ x ++ "\n") pkgs ++ ["\n"]) | otherwise = "" goOthers o | KeyMap.null o = mempty | otherwise = assert False $ B.byteString $ Yaml.encode o -- Per Section Help comments = [ ("user-message" , userMsgHelp) , ("resolver" , resolverHelp) , ("packages" , packageHelp) , ("extra-deps" , extraDepsHelp) , ("flags" , "# Override default flag values for local packages and extra-deps") , ("extra-package-dbs", "# Extra package databases containing global packages") ] -- Help strings headerHelp = commentHelp [ "This file was automatically generated by 'stack init'" , "" , "Some commonly used options have been documented as comments in this file." , "For advanced use and comprehensive documentation of the format, please see:" , "https://docs.haskellstack.org/en/stable/yaml_configuration/" ] resolverHelp = commentHelp [ "Resolver to choose a 'specific' stackage snapshot or a compiler version." , "A snapshot resolver dictates the compiler version and the set of packages" , "to be used for project dependencies. For example:" , "" , "resolver: lts-3.5" , "resolver: nightly-2015-09-21" , "resolver: ghc-7.10.2" , "" , "The location of a snapshot can be provided as a file or url. Stack assumes" , "a snapshot provided as a file might change, whereas a url resource does not." , "" , "resolver: ./custom-snapshot.yaml" , "resolver: https://example.com/snapshots/2018-01-01.yaml" ] userMsgHelp = commentHelp [ "A warning or info to be displayed to the user on config load." ] packageHelp = commentHelp [ "User packages to be built." , "Various formats can be used as shown in the example below." , "" , "packages:" , "- some-directory" , "- https://example.com/foo/bar/baz-0.0.2.tar.gz" , " subdirs:" , " - auto-update" , " - wai" ] extraDepsHelp = commentHelp [ "Dependency packages to be pulled from upstream that are not in the resolver." , "These entries can reference officially published versions as well as" , "forks / in-progress versions pinned to a git hash. For example:" , "" , "extra-deps:" , "- acme-missiles-0.3" , "- git: https://github.com/commercialhaskell/stack.git" , " commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a" , "" ] footerHelp = commentHelp [ "Control whether we use the GHC we find on the path" , "system-ghc: true" , "" , "Require a specific version of Stack, using version ranges" , "require-stack-version: -any # Default" , "require-stack-version: \"" ++ C.display (C.orLaterVersion stackMajorVersion) ++ "\"" , "" , "Override the architecture used by Stack, especially useful on Windows" , "arch: i386" , "arch: x86_64" , "" , "Extra directories used by Stack for building" , "extra-include-dirs: [/path/to/dir]" , "extra-lib-dirs: [/path/to/dir]" , "" , "Allow a newer minor version of GHC than the snapshot specifies" , "compiler-check: newer-minor" ] getSnapshots' :: HasConfig env => RIO env Snapshots getSnapshots' = catchAny getSnapshots (\e -> throwIO $ PrettyException $ SnapshotDownloadFailure e) -- | Get the default resolver value getDefaultResolver :: (HasConfig env, HasGHCVariant env) => InitOpts -> Maybe AbstractResolver -> Map PackageName (ResolvedPath Dir) -- ^ Src package name: cabal dir -> RIO env ( RawSnapshotLocation , Map PackageName (Map FlagName Bool) , Map PackageName Version , Map PackageName (ResolvedPath Dir)) -- ^ ( Resolver -- , Flags for src packages and extra deps -- , Extra dependencies -- , Src packages actually considered) getDefaultResolver initOpts mresolver pkgDirs = do (candidate, loc) <- case mresolver of Nothing -> selectSnapResolver Just ar -> do sl <- makeConcreteResolver ar c <- loadProjectSnapshotCandidate sl NoPrintWarnings False pure (c, sl) getWorkingResolverPlan initOpts pkgDirs candidate loc where -- TODO support selecting best across regular and custom snapshots selectSnapResolver = do snaps <- fmap getRecommendedSnapshots getSnapshots' (c, l, r) <- selectBestSnapshot (Map.elems pkgDirs) snaps case r of BuildPlanCheckFail {} | not (omitPackages initOpts) -> throwM $ PrettyException $ NoMatchingSnapshot snaps _ -> pure (c, l) getWorkingResolverPlan :: (HasConfig env, HasGHCVariant env) => InitOpts -> Map PackageName (ResolvedPath Dir) -- ^ Src packages: cabal dir -> SnapshotCandidate env -> RawSnapshotLocation -> RIO env ( RawSnapshotLocation , Map PackageName (Map FlagName Bool) , Map PackageName Version , Map PackageName (ResolvedPath Dir)) -- ^ ( SnapshotDef -- , Flags for src packages and extra deps -- , Extra dependencies -- , Src packages actually considered) getWorkingResolverPlan initOpts pkgDirs0 snapCandidate snapLoc = do prettyInfo $ fillSep [ flow "Selected the snapshot" , pretty (PrettyRawSnapshotLocation snapLoc) <> "." ] go pkgDirs0 where go pkgDirs = do eres <- checkBundleResolver initOpts snapLoc snapCandidate (Map.elems pkgDirs) -- if some packages failed try again using the rest case eres of Right (f, edeps)-> pure (snapLoc, f, edeps, pkgDirs) Left ignored | Map.null available -> do prettyWarn $ flow "Could not find a working plan for any of the \ \user packages. Proceeding to create a YAML \ \configuration file anyway." pure (snapLoc, Map.empty, Map.empty, Map.empty) | otherwise -> do when (Map.size available == Map.size pkgDirs) $ throwM NoPackagesToIgnoreBug if length ignored > 1 then prettyWarn ( flow "Ignoring the following packages:" <> line <> bulletedList ( map (fromString . packageNameString) ignored ) ) else prettyWarn ( fillSep [ flow "Ignoring package:" , fromString ( case ignored of [] -> throwM NoPackagesToIgnoreBug x:_ -> packageNameString x ) ] ) go available where isAvailable k _ = k `notElem` ignored available = Map.filterWithKey isAvailable pkgDirs checkBundleResolver :: (HasConfig env, HasGHCVariant env) => InitOpts -> RawSnapshotLocation -> SnapshotCandidate env -> [ResolvedPath Dir] -- ^ Src package dirs -> RIO env (Either [PackageName] ( Map PackageName (Map FlagName Bool) , Map PackageName Version)) checkBundleResolver initOpts snapshotLoc snapCandidate pkgDirs = do result <- checkSnapBuildPlan pkgDirs Nothing snapCandidate case result of BuildPlanCheckOk f -> pure $ Right (f, Map.empty) BuildPlanCheckPartial _f e -> do -- FIXME:qrilka unused f if omitPackages initOpts then do warnPartial result logWarn "*** Omitting packages with unsatisfied dependencies" pure $ Left $ failedUserPkgs e else throwM $ PrettyException $ ResolverPartial snapshotLoc (show result) BuildPlanCheckFail _ e _ | omitPackages initOpts -> do logWarn $ "*** Resolver compiler mismatch: " <> display snapshotLoc logWarn $ display $ ind $ T.pack $ show result pure $ Left $ failedUserPkgs e | otherwise -> throwM $ PrettyException $ ResolverMismatch snapshotLoc (show result) where ind t = T.unlines $ fmap (" " <>) (T.lines t) warnPartial res = do logWarn $ "*** Resolver " <> display snapshotLoc <> " will need external packages: " logWarn $ display $ ind $ T.pack $ show res failedUserPkgs e = Map.keys $ Map.unions (Map.elems (fmap deNeededBy e)) getRecommendedSnapshots :: Snapshots -> NonEmpty SnapName getRecommendedSnapshots snapshots = -- in order - Latest LTS, Latest Nightly, all LTS most recent first case NonEmpty.nonEmpty supportedLtss of Just (mostRecent :| older) -> mostRecent :| (nightly : older) Nothing -> nightly :| [] where ltss = map (uncurry LTS) (IntMap.toDescList $ snapshotsLts snapshots) supportedLtss = filter (>= minSupportedLts) ltss nightly = Nightly (snapshotsNightly snapshots) -- |Yields the minimum LTS supported by Stack. minSupportedLts :: SnapName minSupportedLts = LTS 3 0 -- See https://github.com/commercialhaskell/stack/blob/master/ChangeLog.md -- under Stack version 2.1.1. data InitOpts = InitOpts { searchDirs :: ![T.Text] -- ^ List of sub directories to search for .cabal files , omitPackages :: Bool -- ^ Exclude conflicting or incompatible user packages , forceOverwrite :: Bool -- ^ Overwrite existing stack.yaml , includeSubDirs :: Bool -- ^ If True, include all .cabal files found in any sub directories } findCabalDirs :: HasConfig env => Bool -> Path Abs Dir -> RIO env (Set (Path Abs Dir)) findCabalDirs recurse dir = Set.fromList . map parent <$> liftIO (findFiles dir isHpackOrCabal subdirFilter) where subdirFilter subdir = recurse && not (isIgnored subdir) isHpack = (== "package.yaml") . toFilePath . filename isCabal = (".cabal" `isSuffixOf`) . toFilePath isHpackOrCabal x = isHpack x || isCabal x isIgnored path = "." `isPrefixOf` dirName || dirName `Set.member` ignoredDirs where dirName = FP.dropTrailingPathSeparator (toFilePath (dirname path)) -- | Special directories that we don't want to traverse for .cabal files ignoredDirs :: Set FilePath ignoredDirs = Set.fromList [ "dist" ] cabalPackagesCheck :: (HasConfig env, HasGHCVariant env) => [Path Abs Dir] -> RIO env ( Map PackageName (Path Abs File, C.GenericPackageDescription) , [Path Abs File]) cabalPackagesCheck cabaldirs = do when (null cabaldirs) $ prettyWarn $ fillSep [ flow "Stack did not find any local package directories. You may \ \want to create a package with" , style Shell (flow "stack new") , flow "instead." ] <> blankLine <> fillSep [ flow "Stack will create an empty project. If this is not what \ \you want, please delete the generated" , style File "stack.yaml" , "file." ] relpaths <- mapM prettyPath cabaldirs unless (null relpaths) $ prettyInfo $ flow "Using the Cabal packages:" <> line <> bulletedList (map (style File . fromString) relpaths) <> line -- A package name cannot be empty or missing otherwise it will result in -- Cabal solver failure. Stack requires packages name to match the Cabal -- file name. Just the latter check is enough to cover both the cases. ePackages <- for cabaldirs $ \dir -> do -- Pantry's 'loadCabalFilePath' throws 'MismatchedCabalName' (error -- [S-910]) if the Cabal file name does not match the package it -- defines. (gpdio, _name, cabalfp) <- loadCabalFilePath (Just stackProgName') dir eres <- liftIO $ try (gpdio YesPrintWarnings) case eres :: Either PantryException C.GenericPackageDescription of Right gpd -> pure $ Right (cabalfp, gpd) Left (MismatchedCabalName fp name) -> pure $ Left (fp, name) Left e -> throwIO e let (nameMismatchPkgs, packages) = partitionEithers ePackages when (nameMismatchPkgs /= []) $ throwIO $ PrettyException $ PackageNameInvalid nameMismatchPkgs let dupGroups = filter ((> 1) . length) . groupSortOn (gpdPackageName . snd) dupAll = concat $ dupGroups packages -- Among duplicates prefer to include the ones in upper level dirs pathlen = length . FP.splitPath . toFilePath . fst getmin = minimumBy (compare `on` pathlen) dupSelected = map getmin (dupGroups packages) dupIgnored = dupAll \\ dupSelected unique = packages \\ dupIgnored when (dupIgnored /= []) $ do dups <- mapM (mapM (prettyPath. fst)) (dupGroups packages) prettyWarn $ flow "The following packages have duplicate package names:" <> line <> foldMap ( \dup -> bulletedList (map fromString dup) <> line ) dups <> line <> flow "Packages with duplicate names will be ignored. Packages \ \in upper level directories will be preferred." <> line pure (Map.fromList $ map (\(file, gpd) -> (gpdPackageName gpd,(file, gpd))) unique , map fst dupIgnored) prettyPath :: (MonadIO m, RelPath (Path r t) ~ Path Rel t, AnyPath (Path r t)) => Path r t -> m FilePath prettyPath path = do eres <- liftIO $ try $ makeRelativeToCurrentDir path pure $ case eres of Left (_ :: PathException) -> toFilePath path Right res -> toFilePath res stack-2.9.3.1/src/Stack/List.hs0000644000000000000000000000635714445022466014304 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Stack.List ( listPackages ) where import RIO.List ( intercalate ) import qualified RIO.Map as Map import RIO.Process ( HasProcessContext ) import Stack.Prelude -- | Type representing exceptions thrown by functions exported by the -- "Stack.List" module. newtype ListException = CouldNotParsePackageSelectors [String] deriving (Show, Typeable) instance Exception ListException where displayException (CouldNotParsePackageSelectors strs) = unlines $ "Error: [S-4926]" : map ("- " ++) strs -- | Intended to work for the command line command. listPackages :: forall env. (HasPantryConfig env, HasLogFunc env, HasProcessContext env) => Maybe RawSnapshot -- ^ when looking up by name, take from this build plan -> [String] -- ^ names or identifiers -> RIO env () listPackages mSnapshot input = do let (errs1, names) = case mSnapshot of Just snapshot | null input -> ([], Map.keys (rsPackages snapshot)) _ -> partitionEithers $ map parse input (errs2, locs) <- partitionEithers <$> traverse toLoc names case errs1 ++ errs2 of [] -> pure () errs -> throwM $ CouldNotParsePackageSelectors errs mapM_ (logInfo . fromString . packageIdentifierString) locs where toLoc | Just snapshot <- mSnapshot = toLocSnapshot snapshot | otherwise = toLocNoSnapshot toLocNoSnapshot :: PackageName -> RIO env (Either String PackageIdentifier) toLocNoSnapshot name = do mloc1 <- getLatestHackageLocation YesRequireHackageIndex name UsePreferredVersions mloc <- case mloc1 of Just _ -> pure mloc1 Nothing -> do updated <- updateHackageIndex $ Just $ "Could not find package " <> fromString (packageNameString name) <> ", updating" case updated of UpdateOccurred -> getLatestHackageLocation YesRequireHackageIndex name UsePreferredVersions NoUpdateOccurred -> pure Nothing case mloc of Nothing -> do candidates <- getHackageTypoCorrections name pure $ Left $ concat [ "Could not find package " , packageNameString name , " on Hackage" , if null candidates then "" else ". Perhaps you meant: " ++ intercalate ", " (map packageNameString candidates) ] Just loc -> pure $ Right (packageLocationIdent loc) toLocSnapshot :: RawSnapshot -> PackageName -> RIO env (Either String PackageIdentifier) toLocSnapshot snapshot name = case Map.lookup name (rsPackages snapshot) of Nothing -> pure $ Left $ "Package does not appear in snapshot: " ++ packageNameString name Just sp -> do loc <- cplComplete <$> completePackageLocation (rspLocation sp) pure $ Right (packageLocationIdent loc) parse s = case parsePackageName s of Just x -> Right x Nothing -> Left $ "Could not parse as package name or identifier: " ++ s stack-2.9.3.1/src/Stack/Ls.hs0000644000000000000000000003212014445022466013732 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} module Stack.Ls ( lsCmd , lsParser ) where import Data.Aeson import Data.Array.IArray ( (//), elems ) import Distribution.Package ( mkPackageName ) import qualified Data.Aeson.Types as A import qualified Data.List as L import Data.Text hiding ( filter, intercalate, pack, reverse ) import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Data.Vector as V import Network.HTTP.StackClient ( httpJSON, addRequestHeader, getResponseBody, parseRequest , hAccept ) import qualified Options.Applicative as OA import Options.Applicative ( idm ) import Options.Applicative.Builder.Extra ( boolFlags ) import Path import RIO.List ( sort ) import Stack.Constants ( osIsWindows, globalFooter ) import Stack.Dot import Stack.Prelude hiding ( Snapshot (..), SnapName (..) ) import Stack.Runners import Stack.Options.DotParser ( listDepsOptsParser ) import Stack.Setup.Installed ( Tool (..), filterTools, listInstalled, toolString ) import Stack.Types.Config import System.Console.ANSI.Codes ( SGR (Reset), setSGRCode, sgrToCode ) import System.Process.Pager ( pageText ) import System.Directory ( listDirectory ) import System.IO ( putStrLn ) -- | Type representing exceptions thrown by functions exported by the "Stack.Ls" -- module. newtype LsException = ParseFailure [Value] deriving (Show, Typeable) instance Exception LsException where displayException (ParseFailure val) = "Error: [S-3421]\n" ++ "Failure to parse values as a snapshot: " ++ show val data LsView = Local | Remote deriving (Show, Eq, Ord) data SnapshotType = Lts | Nightly deriving (Show, Eq, Ord) data LsCmds = LsSnapshot SnapshotOpts | LsDependencies ListDepsOpts | LsStyles ListStylesOpts | LsTools ListToolsOpts data SnapshotOpts = SnapshotOpts { soptViewType :: LsView , soptLtsSnapView :: Bool , soptNightlySnapView :: Bool } deriving (Eq, Show, Ord) data ListStylesOpts = ListStylesOpts { coptBasic :: Bool , coptSGR :: Bool , coptExample :: Bool } deriving (Eq, Ord, Show) newtype ListToolsOpts = ListToolsOpts { toptFilter :: String } newtype LsCmdOpts = LsCmdOpts { lsView :: LsCmds } lsParser :: OA.Parser LsCmdOpts lsParser = LsCmdOpts <$> OA.hsubparser (lsSnapCmd <> lsDepsCmd <> lsStylesCmd <> lsToolsCmd) lsCmdOptsParser :: OA.Parser LsCmds lsCmdOptsParser = LsSnapshot <$> lsViewSnapCmd lsDepOptsParser :: OA.Parser LsCmds lsDepOptsParser = LsDependencies <$> listDepsOptsParser lsStylesOptsParser :: OA.Parser LsCmds lsStylesOptsParser = LsStyles <$> listStylesOptsParser lsToolsOptsParser :: OA.Parser LsCmds lsToolsOptsParser = LsTools <$> listToolsOptsParser listStylesOptsParser :: OA.Parser ListStylesOpts listStylesOptsParser = ListStylesOpts <$> boolFlags False "basic" "a basic report of the styles used. The default is a fuller \ \one" idm <*> boolFlags True "sgr" "the provision of the equivalent SGR instructions (provided \ \by default). Flag ignored for a basic report" idm <*> boolFlags True "example" "the provision of an example of the applied style (provided \ \by default for colored output). Flag ignored for a basic \ \report" idm listToolsOptsParser :: OA.Parser ListToolsOpts listToolsOptsParser = ListToolsOpts <$> OA.strOption ( OA.long "filter" <> OA.metavar "TOOL_NAME" <> OA.value "" <> OA.help "Filter by a tool name (eg 'ghc', 'ghc-git' or 'msys2') \ \- case sensitive. The default is no filter" ) lsViewSnapCmd :: OA.Parser SnapshotOpts lsViewSnapCmd = SnapshotOpts <$> (OA.hsubparser (lsViewRemoteCmd <> lsViewLocalCmd) <|> pure Local) <*> OA.switch (OA.long "lts" <> OA.short 'l' <> OA.help "Only show lts snapshots") <*> OA.switch (OA.long "nightly" <> OA.short 'n' <> OA.help "Only show nightly snapshots") lsSnapCmd :: OA.Mod OA.CommandFields LsCmds lsSnapCmd = OA.command "snapshots" $ OA.info lsCmdOptsParser $ OA.progDesc "View snapshots (local by default)" <> OA.footer localSnapshotMsg lsDepsCmd :: OA.Mod OA.CommandFields LsCmds lsDepsCmd = OA.command "dependencies" $ OA.info lsDepOptsParser $ OA.progDesc "View the dependencies" <> OA.footer globalFooter lsStylesCmd :: OA.Mod OA.CommandFields LsCmds lsStylesCmd = OA.command "stack-colors" (OA.info lsStylesOptsParser (OA.progDesc "View Stack's output styles")) <> OA.command "stack-colours" (OA.info lsStylesOptsParser (OA.progDesc "View Stack's output styles (alias for \ \'stack-colors')")) lsToolsCmd :: OA.Mod OA.CommandFields LsCmds lsToolsCmd = OA.command "tools" (OA.info lsToolsOptsParser (OA.progDesc "View Stack's installed tools")) data Snapshot = Snapshot { snapId :: Text , snapTitle :: Text , snapTime :: Text } deriving (Show, Eq, Ord) data SnapshotData = SnapshotData { _snapTotalCounts :: Integer , snaps :: [[Snapshot]] } deriving (Show, Eq, Ord) instance FromJSON Snapshot where parseJSON o@(Array _) = parseSnapshot o parseJSON _ = mempty instance FromJSON SnapshotData where parseJSON (Object s) = SnapshotData <$> s .: "totalCount" <*> s .: "snapshots" parseJSON _ = mempty toSnapshot :: [Value] -> Snapshot toSnapshot [String sid, String stitle, String stime] = Snapshot { snapId = sid , snapTitle = stitle , snapTime = stime } toSnapshot val = impureThrow $ ParseFailure val parseSnapshot :: Value -> A.Parser Snapshot parseSnapshot = A.withArray "array of snapshot" (pure . toSnapshot . V.toList) displayTime :: Snapshot -> [Text] displayTime Snapshot {..} = [snapTime] displaySnap :: Snapshot -> [Text] displaySnap Snapshot {..} = ["Resolver name: " <> snapId, "\n" <> snapTitle <> "\n\n"] displaySingleSnap :: [Snapshot] -> Text displaySingleSnap snapshots = case snapshots of [] -> mempty (x:xs) -> let snaps = displayTime x <> ["\n\n"] <> displaySnap x <> L.concatMap displaySnap xs in T.concat snaps renderData :: Bool -> Text -> IO () renderData True content = pageText content renderData False content = T.putStr content displaySnapshotData :: Bool -> SnapshotData -> IO () displaySnapshotData term sdata = case L.reverse $ snaps sdata of [] -> pure () xs -> let snaps = T.concat $ L.map displaySingleSnap xs in renderData term snaps filterSnapshotData :: SnapshotData -> SnapshotType -> SnapshotData filterSnapshotData sdata stype = sdata { snaps = filterSnapData } where snapdata = snaps sdata filterSnapData = case stype of Lts -> L.map (L.filter (\x -> "lts" `isPrefixOf` snapId x)) snapdata Nightly -> L.map (L.filter (\x -> "nightly" `isPrefixOf` snapId x)) snapdata displayLocalSnapshot :: Bool -> [String] -> IO () displayLocalSnapshot term xs = renderData term (localSnaptoText xs) localSnaptoText :: [String] -> Text localSnaptoText xs = T.intercalate "\n" $ L.map T.pack xs handleLocal :: LsCmdOpts -> RIO Runner () handleLocal lsOpts = do (instRoot :: Path Abs Dir) <- withConfig YesReexec $ withDefaultEnvConfig installationRootDeps isStdoutTerminal <- view terminalL let parentInstRoot = parent instRoot snapRootDir | osIsWindows = parentInstRoot | otherwise = parent parentInstRoot snapData' <- liftIO $ listDirectory $ toFilePath snapRootDir let snapData = L.sort snapData' case lsView lsOpts of LsSnapshot SnapshotOpts {..} -> case (soptLtsSnapView, soptNightlySnapView) of (True, False) -> liftIO $ displayLocalSnapshot isStdoutTerminal $ L.filter (L.isPrefixOf "lts") snapData (False, True) -> liftIO $ displayLocalSnapshot isStdoutTerminal $ L.filter (L.isPrefixOf "night") snapData _ -> liftIO $ displayLocalSnapshot isStdoutTerminal snapData LsDependencies _ -> pure () LsStyles _ -> pure () LsTools _ -> pure () handleRemote :: HasRunner env => LsCmdOpts -> RIO env () handleRemote lsOpts = do req <- liftIO $ parseRequest urlInfo isStdoutTerminal <- view terminalL let req' = addRequestHeader hAccept "application/json" req result <- httpJSON req' let snapData = getResponseBody result case lsView lsOpts of LsSnapshot SnapshotOpts {..} -> case (soptLtsSnapView, soptNightlySnapView) of (True, False) -> liftIO $ displaySnapshotData isStdoutTerminal $ filterSnapshotData snapData Lts (False, True) -> liftIO $ displaySnapshotData isStdoutTerminal $ filterSnapshotData snapData Nightly _ -> liftIO $ displaySnapshotData isStdoutTerminal snapData LsDependencies _ -> pure () LsStyles _ -> pure () LsTools _ -> pure () where urlInfo = "https://www.stackage.org/snapshots" lsCmd :: LsCmdOpts -> RIO Runner () lsCmd lsOpts = case lsView lsOpts of LsSnapshot SnapshotOpts {..} -> case soptViewType of Local -> handleLocal lsOpts Remote -> handleRemote lsOpts LsDependencies depOpts -> listDependencies depOpts LsStyles stylesOpts -> withConfig NoReexec $ listStylesCmd stylesOpts LsTools toolsOpts -> withConfig NoReexec $ listToolsCmd toolsOpts lsViewLocalCmd :: OA.Mod OA.CommandFields LsView lsViewLocalCmd = OA.command "local" $ OA.info (pure Local) $ OA.progDesc "View local snapshots" <> OA.footer localSnapshotMsg lsViewRemoteCmd :: OA.Mod OA.CommandFields LsView lsViewRemoteCmd = OA.command "remote" $ OA.info (pure Remote) $ OA.progDesc "View remote snapshots" <> OA.footer pagerMsg pagerMsg :: String pagerMsg = "On a terminal, uses a pager, if one is available. Respects the PAGER \ \environment variable (subject to that, prefers pager 'less' to 'more')." localSnapshotMsg :: String localSnapshotMsg = "A local snapshot is identified by a hash code. " <> pagerMsg -- | List Stack's output styles listStylesCmd :: ListStylesOpts -> RIO Config () listStylesCmd opts = do lc <- ask -- This is the same test as is used in Stack.Types.Runner.withRunner let useColor = view useColorL lc styles = elems $ defaultStyles // stylesUpdate (view stylesUpdateL lc) isComplex = not (coptBasic opts) showSGR = isComplex && coptSGR opts showExample = isComplex && coptExample opts && useColor styleReports = L.map (styleReport showSGR showExample) styles liftIO $ T.putStrLn $ T.intercalate (if isComplex then "\n" else ":") styleReports where styleReport :: Bool -> Bool -> StyleSpec -> Text styleReport showSGR showExample (k, sgrs) = k <> "=" <> codes <> (if showSGR then sgrsList else mempty) <> (if showExample then example else mempty) where codes = T.intercalate ";" (L.map (fromString . show) $ L.concatMap sgrToCode sgrs) sgrsList = " [" <> T.intercalate ", " (L.map (fromString . show) sgrs) <> "]" example = " " <> ansi <> "Example" <> reset ansi = fromString $ setSGRCode sgrs reset = fromString $ setSGRCode [Reset] -- | List Stack's installed tools, sorted (see instance of 'Ord' for 'Tool'). listToolsCmd :: ListToolsOpts -> RIO Config () listToolsCmd opts = do localPrograms <- view $ configL.to configLocalPrograms installed <- sort <$> listInstalled localPrograms let wanted = case toptFilter opts of [] -> installed "ghc-git" -> [t | t@(ToolGhcGit _ _) <- installed] pkgName -> filtered pkgName installed liftIO $ mapM_ (putStrLn . toolString) wanted where filtered pkgName installed = Tool <$> filterTools (mkPackageName pkgName) (const True) installed stack-2.9.3.1/src/Stack/Lock.hs0000644000000000000000000001543214445022466014253 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Stack.Lock ( lockCachedWanted , LockedLocation (..) , Locked (..) ) where import Data.ByteString.Builder ( byteString ) import qualified Data.List.NonEmpty as NE import qualified Data.Map as Map import qualified Data.Text as T import qualified Data.Yaml as Yaml import Pantry.Internal.AesonExtended import Path ( parent ) import Path.Extended ( addExtension ) import Path.IO ( doesFileExist ) import Stack.Prelude import Stack.SourceMap import Stack.Types.Config import Stack.Types.SourceMap -- | Type representing exceptions thrown by functions exported by the -- "Stack.Lock" module. data LockException = WritingLockFileError (Path Abs File) Locked deriving (Show, Typeable) instance Exception LockException where displayException (WritingLockFileError lockFile newLocked) = unlines [ "Error: [S-1353]" , "You indicated that Stack should error out on writing a lock file" , "Stack just tried to write the following lock file contents to " ++ toFilePath lockFile , T.unpack $ decodeUtf8With lenientDecode $ Yaml.encode newLocked ] data LockedLocation a b = LockedLocation { llOriginal :: a , llCompleted :: b } deriving (Eq, Show) instance (ToJSON a, ToJSON b) => ToJSON (LockedLocation a b) where toJSON ll = object [ "original" .= llOriginal ll, "completed" .= llCompleted ll ] instance ( FromJSON (WithJSONWarnings (Unresolved a)) , FromJSON (WithJSONWarnings (Unresolved b)) ) => FromJSON (WithJSONWarnings (Unresolved (LockedLocation a b))) where parseJSON = withObjectWarnings "LockedLocation" $ \o -> do original <- jsonSubWarnings $ o ..: "original" completed <- jsonSubWarnings $ o ..: "completed" pure $ LockedLocation <$> original <*> completed -- Special wrapper extracting only 1 RawPackageLocationImmutable -- serialization should not produce locations with multiple subdirs -- so we should be OK using just a head element newtype SingleRPLI = SingleRPLI { unSingleRPLI :: RawPackageLocationImmutable} instance FromJSON (WithJSONWarnings (Unresolved SingleRPLI)) where parseJSON v = do WithJSONWarnings unresolvedRPLIs ws <- parseJSON v let withWarnings x = WithJSONWarnings x ws pure $ withWarnings $ SingleRPLI . NE.head <$> unresolvedRPLIs data Locked = Locked { lckSnapshotLocations :: [LockedLocation RawSnapshotLocation SnapshotLocation] , lckPkgImmutableLocations :: [LockedLocation RawPackageLocationImmutable PackageLocationImmutable] } deriving (Eq, Show) instance ToJSON Locked where toJSON Locked {..} = object [ "snapshots" .= lckSnapshotLocations , "packages" .= lckPkgImmutableLocations ] instance FromJSON (WithJSONWarnings (Unresolved Locked)) where parseJSON = withObjectWarnings "Locked" $ \o -> do snapshots <- jsonSubWarningsT $ o ..: "snapshots" packages <- jsonSubWarningsT $ o ..: "packages" let unwrap ll = ll { llOriginal = unSingleRPLI (llOriginal ll) } pure $ Locked <$> sequenceA snapshots <*> (map unwrap <$> sequenceA packages) loadYamlThrow :: HasLogFunc env => (Value -> Yaml.Parser (WithJSONWarnings a)) -> Path Abs File -> RIO env a loadYamlThrow parser path = do eVal <- liftIO $ Yaml.decodeFileEither (toFilePath path) case eVal of Left parseException -> throwIO $ ParseConfigFileException path parseException Right val -> case Yaml.parseEither parser val of Left err -> throwIO $ Yaml.AesonException err Right (WithJSONWarnings res warnings) -> do logJSONWarnings (toFilePath path) warnings pure res lockCachedWanted :: (HasPantryConfig env, HasRunner env) => Path Abs File -> RawSnapshotLocation -> (Map RawPackageLocationImmutable PackageLocationImmutable -> WantedCompiler -> Map PackageName (Bool -> RIO env DepPackage) -> RIO env ( SMWanted, [CompletedPLI])) -> RIO env SMWanted lockCachedWanted stackFile resolver fillWanted = do lockFile <- liftIO $ addExtension ".lock" stackFile let getLockExists = doesFileExist lockFile lfb <- view lockFileBehaviorL readLockFile <- case lfb of LFBIgnore -> pure False LFBReadWrite -> getLockExists LFBReadOnly -> getLockExists LFBErrorOnWrite -> getLockExists locked <- if readLockFile then do logDebug "Using package location completions from a lock file" unresolvedLocked <- loadYamlThrow parseJSON lockFile resolvePaths (Just $ parent stackFile) unresolvedLocked else do logDebug "Not reading lock file" pure $ Locked [] [] let toMap :: Ord a => [LockedLocation a b] -> Map a b toMap = Map.fromList . map (\ll -> (llOriginal ll, llCompleted ll)) slocCache = toMap $ lckSnapshotLocations locked pkgLocCache = toMap $ lckPkgImmutableLocations locked debugRSL <- view rslInLogL (snap, slocCompleted, pliCompleted) <- loadAndCompleteSnapshotRaw' debugRSL resolver slocCache pkgLocCache let compiler = snapshotCompiler snap snPkgs = Map.mapWithKey (\n p h -> snapToDepPackage h n p) (snapshotPackages snap) (wanted, prjCompleted) <- fillWanted pkgLocCache compiler snPkgs let lockLocations = map (\(CompletedPLI r c) -> LockedLocation r c) differentSnapLocs (CompletedSL raw complete) | raw == toRawSL complete = Nothing | otherwise = Just $ LockedLocation raw complete newLocked = Locked { lckSnapshotLocations = mapMaybe differentSnapLocs slocCompleted , lckPkgImmutableLocations = lockLocations $ pliCompleted <> prjCompleted } when (newLocked /= locked) $ do case lfb of LFBReadWrite -> writeBinaryFileAtomic lockFile $ header <> byteString (Yaml.encode newLocked) LFBErrorOnWrite -> throwIO $ WritingLockFileError lockFile newLocked LFBIgnore -> pure () LFBReadOnly -> pure () pure wanted where header = "# This file was autogenerated by Stack.\n\ \# You should not edit this file by hand.\n\ \# For more information, please see the documentation at:\n\ \# https://docs.haskellstack.org/en/stable/lock_files\n\n" stack-2.9.3.1/src/Stack/New.hs0000644000000000000000000006424614445022466014123 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} -- | Create new a new project directory populated with a basic working -- project. module Stack.New ( new , NewOpts (..) , TemplateName , templatesHelp ) where import Control.Monad.Trans.Writer.Strict import Data.Aeson as A import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.ByteString.Base64 as B64 import Data.ByteString.Builder ( lazyByteString ) import qualified Data.ByteString.Lazy as LB import Data.Conduit import qualified Data.List as L import qualified Data.Map.Strict as M import qualified Data.Set as S import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Encoding as TLE import Data.Time.Calendar import Data.Time.Clock import Network.HTTP.StackClient ( HttpException (..), HttpExceptionContent (..) , Response (..), VerifiedDownloadException (..) , getResponseBody, httpLbs, mkDownloadRequest, notFound404 , parseRequest, parseUrlThrow, setForceDownload , setGitHubHeaders, setRequestCheckStatus , verifiedDownloadWithProgress ) import Path import Path.IO import RIO.Process import Stack.Constants import Stack.Constants.Config import Stack.Prelude import Stack.Types.Config import Stack.Types.TemplateName import qualified Text.Mustache as Mustache import qualified Text.Mustache.Render as Mustache import Text.ProjectTemplate -------------------------------------------------------------------------------- -- Exceptions -- | Type representing \'pretty\' exceptions thrown by functions exported by the -- "Stack.New" module. data NewPrettyException = ProjectDirAlreadyExists !String !(Path Abs Dir) | DownloadTemplateFailed !Text !String !VerifiedDownloadException | forall b. LoadTemplateFailed !TemplateName !(Path b File) | forall b. ExtractTemplateFailed !TemplateName !(Path b File) !String | TemplateInvalid !TemplateName !StyleDoc | MagicPackageNameInvalid !String | AttemptedOverwrites !Text ![Path Abs File] | DownloadTemplatesHelpFailed !HttpException | TemplatesHelpEncodingInvalid !String !UnicodeException deriving Typeable deriving instance Show NewPrettyException instance Pretty NewPrettyException where pretty (ProjectDirAlreadyExists name path) = "[S-2135]" <> line <> fillSep [ flow "Stack failed to create a new directory for project" , style Current (fromString name) <> "," , flow "as the directory" , style Dir (pretty path) , flow "already exists." ] pretty (DownloadTemplateFailed name url err) = "[S-1688]" <> line <> fillSep [ flow "Stack failed to download the template" , style Current (fromString . T.unpack $ name) , "from" , style Url (fromString url) <> "." ] <> blankLine <> ( if isNotFound then flow "Please check that the template exists at that \ \location." <> blankLine else mempty ) <> fillSep [ flow "While downloading, Stack encountered" , msg ] where (msg, isNotFound) = case err of DownloadHttpError (HttpExceptionRequest req content) -> let msg' = flow "an HTTP error. Stack made the request:" <> blankLine <> fromString (show req) <> blankLine <> flow "and the content of the error was:" <> blankLine <> fromString (show content) isNotFound404 = case content of StatusCodeException res _ -> responseStatus res == notFound404 _ -> False in (msg', isNotFound404) DownloadHttpError (InvalidUrlException url' reason) -> let msg' = fillSep [ flow "an HTTP error. The URL" , style Url (fromString url') , flow "was considered invalid because" , fromString reason <> "." ] in (msg', False) _ -> let msg' = flow "the following error:" <> blankLine <> fromString (displayException err) in (msg', False) pretty (LoadTemplateFailed name path) = "[S-3650]" <> line <> fillSep [ flow "Stack failed to load the downloaded template" , style Current (fromString $ T.unpack $ templateName name) , "from" , style File (pretty path) <> "." ] pretty (ExtractTemplateFailed name path err) = "[S-9582]" <> line <> fillSep [ flow "Stack failed to extract the loaded template" , style Current (fromString $ T.unpack $ templateName name) , "at" , style File (pretty path) <> "." ] <> blankLine <> flow "While extracting, Stack encountered the following error:" <> blankLine <> string err pretty (TemplateInvalid name why) = "[S-9490]" <> line <> fillSep [ flow "Stack failed to use the template" , style Current (fromString $ T.unpack $ templateName name) <> "," , "as" , why ] pretty (MagicPackageNameInvalid name) = "[S-5682]" <> line <> fillSep [ flow "Stack declined to create a new directory for project" , style Current (fromString name) <> "," , flow "as package" , fromString name , flow "is 'wired-in' to a version of GHC. That can cause build \ \errors." ] <> blankLine <> fillSep ( flow "The names blocked by Stack are:" : mkNarrativeList Nothing False ( map toStyleDoc (L.sort $ S.toList wiredInPackages) ) ) where toStyleDoc :: PackageName -> StyleDoc toStyleDoc = fromString . packageNameString pretty (AttemptedOverwrites name fps) = "[S-3113]" <> line <> fillSep [ flow "Stack declined to apply the template" , style Current (fromString . T.unpack $ name) <> "," , flow "as it would create files that already exist." ] <> blankLine <> flow "The template would create the following existing files:" <> line <> bulletedList (map (style File . pretty) fps) <> blankLine <> fillSep [ "Use the" , style Shell "--force" , "flag to ignore this and overwrite those files." ] pretty (DownloadTemplatesHelpFailed err) = "[S-8143]" <> line <> fillSep [ flow "Stack failed to download the help for" , style Shell "stack templates" <> "." ] <> blankLine <> flow "While downloading, Stack encountered the following error:" <> blankLine <> string (displayException err) pretty (TemplatesHelpEncodingInvalid url err) = "[S-6670]" <> line <> fillSep [ flow "Stack failed to decode the help for" , style Shell "stack templates" , flow "downloaded from" , style Url (fromString url) <> "." ] <> blankLine <> flow "While decoding, Stack encountered the following error:" <> blankLine <> string (displayException err) instance Exception NewPrettyException -------------------------------------------------------------------------------- -- Main project creation -- | Options for creating a new project. data NewOpts = NewOpts { newOptsProjectName :: PackageName -- ^ Name of the project to create. , newOptsCreateBare :: Bool -- ^ Whether to create the project without a directory. , newOptsTemplate :: Maybe TemplateName -- ^ Name of the template to use. , newOptsNonceParams :: Map Text Text -- ^ Nonce parameters specified just for this invocation. } -- | Create a new project with the given options. new :: HasConfig env => NewOpts -> Bool -> RIO env (Path Abs Dir) new opts forceOverwrite = do when (project `elem` wiredInPackages) $ throwM $ PrettyException $ MagicPackageNameInvalid projectName pwd <- getCurrentDir absDir <- if bare then pure pwd else do relDir <- parseRelDir (packageNameString project) liftM (pwd ) (pure relDir) exists <- doesDirExist absDir configTemplate <- view $ configL.to configDefaultTemplate let template = fromMaybe defaultTemplateName $ asum [ cliOptionTemplate , configTemplate ] if exists && not bare then throwM $ PrettyException $ ProjectDirAlreadyExists projectName absDir else do templateText <- loadTemplate template (logUsing absDir template) files <- applyTemplate project template (newOptsNonceParams opts) absDir templateText when (not forceOverwrite && bare) $ checkForOverwrite (templateName template) (M.keys files) writeTemplateFiles files runTemplateInits absDir pure absDir where cliOptionTemplate = newOptsTemplate opts project = newOptsProjectName opts projectName = packageNameString project bare = newOptsCreateBare opts logUsing absDir template templateFrom = let loading = case templateFrom of LocalTemp -> flow "Loading local" RemoteTemp -> "Downloading" in prettyInfo ( fillSep [ loading , "template" , style Current (fromString $ T.unpack $ templateName template) , flow "to create project" , style Current (fromString projectName) , "in" , ( if bare then flow "the current directory" else fillSep [ "directory" , style Dir (pretty $ dirname absDir) ] ) <> "..." ] ) data TemplateFrom = LocalTemp | RemoteTemp -- | Download and read in a template's text content. loadTemplate :: forall env. HasConfig env => TemplateName -> (TemplateFrom -> RIO env ()) -> RIO env Text loadTemplate name logIt = do templateDir <- view $ configL.to templatesDir case templatePath name of AbsPath absFile -> logIt LocalTemp >> loadLocalFile absFile eitherByteStringToText UrlPath s -> do let settings = asIsFromUrl s downloadFromUrl settings templateDir RelPath rawParam relFile -> catch (do f <- loadLocalFile relFile eitherByteStringToText logIt LocalTemp pure f) (\(e :: PrettyException) -> do case relSettings rawParam of Just settings -> do let url = tplDownloadUrl settings extract = tplExtract settings downloadTemplate url extract (templateDir relFile) Nothing -> throwM e ) RepoPath rtp -> do let settings = settingsFromRepoTemplatePath rtp downloadFromUrl settings templateDir where loadLocalFile :: Path b File -> (ByteString -> Either String Text) -> RIO env Text loadLocalFile path extract = do logDebug ("Opening local template: \"" <> fromString (toFilePath path) <> "\"") exists <- doesFileExist path if exists then do bs <- readFileBinary (toFilePath path) --readFileUtf8 (toFilePath path) case extract bs of Left err -> throwM $ PrettyException $ ExtractTemplateFailed name path err Right template -> pure template else throwM $ PrettyException $ LoadTemplateFailed name path relSettings :: String -> Maybe TemplateDownloadSettings relSettings req = do rtp <- parseRepoPathWithService defaultRepoService (T.pack req) pure (settingsFromRepoTemplatePath rtp) downloadFromUrl :: TemplateDownloadSettings -> Path Abs Dir -> RIO env Text downloadFromUrl settings templateDir = do let url = tplDownloadUrl settings rel = fromMaybe backupUrlRelPath (parseRelFile url) downloadTemplate url (tplExtract settings) (templateDir rel) downloadTemplate :: String -> (ByteString -> Either String Text) -> Path Abs File -> RIO env Text downloadTemplate url extract path = do req <- parseRequest url let dReq = setForceDownload True $ mkDownloadRequest (setRequestCheckStatus req) logIt RemoteTemp catch ( do let label = T.pack $ toFilePath path res <- verifiedDownloadWithProgress dReq path label Nothing if res then logStickyDone ("Downloaded " <> display label <> ".") else logStickyDone "Already downloaded." ) (useCachedVersionOrThrow url path) loadLocalFile path extract useCachedVersionOrThrow :: String -> Path Abs File -> VerifiedDownloadException -> RIO env () useCachedVersionOrThrow url path exception = do exists <- doesFileExist path if exists then prettyWarn ( flow "Tried to download the template but an error was \ \found. Using cached local version. It may not be the \ \most recent version though." ) else throwM $ PrettyException $ DownloadTemplateFailed (templateName name) url exception data TemplateDownloadSettings = TemplateDownloadSettings { tplDownloadUrl :: String , tplExtract :: ByteString -> Either String Text } eitherByteStringToText :: ByteString -> Either String Text eitherByteStringToText = mapLeft show . decodeUtf8' asIsFromUrl :: String -> TemplateDownloadSettings asIsFromUrl url = TemplateDownloadSettings { tplDownloadUrl = url , tplExtract = eitherByteStringToText } -- | Construct a URL for downloading from a repo. settingsFromRepoTemplatePath :: RepoTemplatePath -> TemplateDownloadSettings settingsFromRepoTemplatePath (RepoTemplatePath GitHub user name) = -- T.concat ["https://raw.githubusercontent.com", "/", user, "/stack-templates/master/", name] TemplateDownloadSettings { tplDownloadUrl = concat [ "https://api.github.com/repos/" , T.unpack user , "/stack-templates/contents/" , T.unpack name ] , tplExtract = \bs -> do decodedJson <- eitherDecode (LB.fromStrict bs) case decodedJson of Object o | Just (String content) <- KeyMap.lookup "content" o -> do let noNewlines = T.filter (/= '\n') bsContent <- B64.decode $ T.encodeUtf8 (noNewlines content) mapLeft show $ decodeUtf8' bsContent _ -> Left "Couldn't parse GitHub response as a JSON object with a \"content\" field" } settingsFromRepoTemplatePath (RepoTemplatePath GitLab user name) = asIsFromUrl $ concat [ "https://gitlab.com" , "/" , T.unpack user , "/stack-templates/raw/master/" , T.unpack name ] settingsFromRepoTemplatePath (RepoTemplatePath Bitbucket user name) = asIsFromUrl $ concat [ "https://bitbucket.org" , "/" , T.unpack user , "/stack-templates/raw/master/" , T.unpack name ] -- | Apply and unpack a template into a directory. applyTemplate :: HasConfig env => PackageName -> TemplateName -> Map Text Text -> Path Abs Dir -> Text -> RIO env (Map (Path Abs File) LB.ByteString) applyTemplate project template nonceParams dir templateText = do config <- view configL currentYear <- do now <- liftIO getCurrentTime let (year, _, _) = toGregorian (utctDay now) pure $ T.pack . show $ year let context = M.unions [nonceParams, nameParams, configParams, yearParam] where nameAsVarId = T.replace "-" "_" $ T.pack $ packageNameString project nameAsModule = T.filter (/= ' ') $ T.toTitle $ T.replace "-" " " $ T.pack $ packageNameString project nameParams = M.fromList [ ("name", T.pack $ packageNameString project) , ("name-as-varid", nameAsVarId) , ("name-as-module", nameAsModule) ] configParams = configTemplateParams config yearParam = M.singleton "year" currentYear files :: Map FilePath LB.ByteString <- catch ( execWriterT $ runConduit $ yield (T.encodeUtf8 templateText) .| unpackTemplate receiveMem id ) ( \(e :: ProjectTemplateException) -> throwM $ PrettyException $ TemplateInvalid template (string $ displayException e) ) when (M.null files) $ throwM $ PrettyException $ TemplateInvalid template (flow "the template does not contain any files.") let isPkgSpec f = ".cabal" `L.isSuffixOf` f || f == "package.yaml" unless (any isPkgSpec . M.keys $ files) $ throwM $ PrettyException $ TemplateInvalid template ( flow "the template does not contain a Cabal or package.yaml \ \file." ) -- Apply Mustache templating to a single file within the project template. let applyMustache bytes -- Workaround for performance problems with mustache and -- large files, applies to Yesod templates with large -- bootstrap CSS files. See -- https://github.com/commercialhaskell/stack/issues/4133. | LB.length bytes < 50000 , Right text <- TLE.decodeUtf8' bytes = do let etemplateCompiled = Mustache.compileTemplate (T.unpack (templateName template)) $ TL.toStrict text templateCompiled <- case etemplateCompiled of Left e -> throwM $ PrettyException $ TemplateInvalid template ( flow "Stack encountered the following error:" <> blankLine -- Text.Parsec.Error.ParseError is not an instance -- of Control.Exception. <> string (show e) ) Right t -> pure t let (substitutionErrors, applied) = Mustache.checkedSubstitute templateCompiled context missingKeys = S.fromList $ concatMap onlyMissingKeys substitutionErrors pure (LB.fromStrict $ encodeUtf8 applied, missingKeys) -- Too large or too binary | otherwise = pure (bytes, S.empty) -- Accumulate any missing keys as the file is processed processFile mks (fpOrig, bytes) = do -- Apply the mustache template to the filenames as well, so that we -- can have file names depend on the project name. (fp, mks1) <- applyMustache $ TLE.encodeUtf8 $ TL.pack fpOrig path <- parseRelFile $ TL.unpack $ TLE.decodeUtf8 fp (bytes', mks2) <- applyMustache bytes pure (mks <> mks1 <> mks2, (dir path, bytes')) (missingKeys, results) <- mapAccumLM processFile S.empty (M.toList files) unless (S.null missingKeys) $ do prettyNote $ missingParameters missingKeys (configUserConfigPath config) pure $ M.fromList results where onlyMissingKeys (Mustache.VariableNotFound ks) = map T.unpack ks onlyMissingKeys _ = [] mapAccumLM :: Monad m => (a -> b -> m(a, c)) -> a -> [b] -> m(a, [c]) mapAccumLM _ a [] = pure (a, []) mapAccumLM f a (x:xs) = do (a', c) <- f a x (a'', cs) <- mapAccumLM f a' xs pure (a'', c:cs) missingParameters :: Set String -> Path Abs File -> StyleDoc missingParameters missingKeys userConfigPath = fillSep ( flow "The following parameters were needed by the template but \ \not provided:" : mkNarrativeList Nothing False (map toStyleDoc (S.toList missingKeys)) ) <> blankLine <> fillSep [ flow "You can provide them in Stack's global YAML configuration \ \file" , "(" <> style File (pretty userConfigPath) <> ")" , "like this:" ] <> blankLine <> "templates:" <> line <> " params:" <> line <> vsep ( map (\key -> " " <> fromString key <> ": value") (S.toList missingKeys) ) <> blankLine <> flow "Or you can pass each one on the command line as parameters \ \like this:" <> blankLine <> style Shell ( fillSep [ flow "stack new" , fromString (packageNameString project) , fromString $ T.unpack (templateName template) , hsep $ map ( \key -> fillSep [ "-p" , "\"" <> fromString key <> ":value\"" ] ) (S.toList missingKeys) ] ) <> line where toStyleDoc :: String -> StyleDoc toStyleDoc = fromString -- | Check if we're going to overwrite any existing files. checkForOverwrite :: (MonadIO m, MonadThrow m) => Text -> [Path Abs File] -> m () checkForOverwrite name files = do overwrites <- filterM doesFileExist files unless (null overwrites) $ throwM $ PrettyException $ AttemptedOverwrites name overwrites -- | Write files to the new project directory. writeTemplateFiles :: MonadIO m => Map (Path Abs File) LB.ByteString -> m () writeTemplateFiles files = liftIO $ forM_ (M.toList files) (\(fp,bytes) -> do ensureDir (parent fp) writeBinaryFileAtomic fp $ lazyByteString bytes) -- | Run any initialization functions, such as Git. runTemplateInits :: HasConfig env => Path Abs Dir -> RIO env () runTemplateInits dir = do config <- view configL case configScmInit config of Nothing -> pure () Just Git -> withWorkingDir (toFilePath dir) $ catchAny (proc "git" ["init"] runProcess_) ( \_ -> prettyWarn $ fillSep [ flow "Stack failed to run a" , style Shell (flow "git init") , flow "command. Ignoring..." ] ) -- | Display help for the templates command. templatesHelp :: HasLogFunc env => RIO env () templatesHelp = do let url = defaultTemplatesHelpUrl req <- liftM setGitHubHeaders (parseUrlThrow url) resp <- catch (httpLbs req) (throwM . PrettyException. DownloadTemplatesHelpFailed) case decodeUtf8' $ LB.toStrict $ getResponseBody resp of Left err -> throwM $ PrettyException $ TemplatesHelpEncodingInvalid url err Right txt -> logInfo $ display txt -------------------------------------------------------------------------------- -- Defaults -- | The default service to use to download templates. defaultRepoService :: RepoService defaultRepoService = GitHub -- | Default web URL to get the `stack templates` help output. defaultTemplatesHelpUrl :: String defaultTemplatesHelpUrl = "https://raw.githubusercontent.com/commercialhaskell/stack-templates/master/STACK_HELP.md" stack-2.9.3.1/src/Stack/Nix.hs0000644000000000000000000001451314445022466014120 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} -- | Run commands in a nix-shell module Stack.Nix ( nixCmdName , nixHelpOptName , runShellAndExit ) where import qualified Data.Text as T import Path.IO ( resolveFile ) import RIO.Process ( exec, processContextL ) import Stack.Config ( getInContainer, withBuildConfig ) import Stack.Config.Nix ( nixCompiler, nixCompilerVersion ) import Stack.Constants ( inContainerEnvVar, inNixShellEnvVar , platformVariantEnvVar ) import Stack.Prelude import Stack.Types.Config import Stack.Types.Docker import Stack.Types.Nix import Stack.Types.Version ( showStackVersion ) import System.Environment ( getArgs, getExecutablePath, lookupEnv ) import qualified System.FilePath as F -- | Type representing exceptions thrown by functions exported by the -- "Stack.Nix" module. data NixException = CannotDetermineProjectRoot -- ^ Can't determine the project root (location of the shell file if any). deriving (Show, Typeable) instance Exception NixException where displayException CannotDetermineProjectRoot = "Error: [S-7384]\n" ++ "Cannot determine project root directory." runShellAndExit :: RIO Config void runShellAndExit = do inContainer <- getInContainer -- TODO we can probably assert that this is False based on Stack.Runners now origArgs <- liftIO getArgs let args | inContainer = origArgs -- internal-re-exec version already passed -- first stack when restarting in the container | otherwise = ("--" ++ reExecArgName ++ "=" ++ showStackVersion) : origArgs exePath <- liftIO getExecutablePath config <- view configL envOverride <- view processContextL local (set processContextL envOverride) $ do let cmnd = escape exePath args' = map escape args mshellFile <- case configProjectRoot config of Just projectRoot -> traverse (resolveFile projectRoot) $ nixInitFile (configNix config) Nothing -> pure Nothing -- This will never result in double loading the build config, since: -- -- 1. This function explicitly takes a Config, not a HasConfig -- -- 2. This function ends up exiting before running other code -- (thus the void return type) compilerVersion <- withBuildConfig $ view wantedCompilerVersionL ghc <- either throwIO pure $ nixCompiler compilerVersion ghcVersion <- either throwIO pure $ nixCompilerVersion compilerVersion let pkgsInConfig = nixPackages (configNix config) pkgs = pkgsInConfig ++ [ghc, "git", "gcc", "gmp"] pkgsStr = "[" <> T.intercalate " " pkgs <> "]" pureShell = nixPureShell (configNix config) addGCRoots = nixAddGCRoots (configNix config) nixopts = case mshellFile of Just fp -> [ toFilePath fp , "--arg" , "ghc" , "with (import {}); " ++ T.unpack ghc , "--argstr", "ghcVersion", T.unpack ghcVersion ] Nothing -> [ "-E" , T.unpack $ T.concat [ "with (import {}); " , "let inputs = ",pkgsStr,"; " , "libPath = lib.makeLibraryPath inputs; " , "stackExtraArgs = lib.concatMap (pkg: " , "[ ''--extra-lib-dirs=${lib.getLib pkg}/lib'' " , " ''--extra-include-dirs=${lib.getDev pkg}/include'' ]" , ") inputs; in " , "runCommand ''myEnv'' { " , "buildInputs = lib.optional stdenv.isLinux glibcLocales ++ inputs; " -- glibcLocales is necessary on Linux to avoid warnings about -- GHC being incapable to set the locale. , T.pack platformVariantEnvVar <> "=''nix''; " , T.pack inNixShellEnvVar <> "=1; " , if inContainer -- If shell is pure, this env var would not -- be seen by stack inside nix then T.pack inContainerEnvVar <> "=1; " else "" , "LD_LIBRARY_PATH = libPath;" -- LD_LIBRARY_PATH is set because for now it's needed by -- builds using Template Haskell , "STACK_IN_NIX_EXTRA_ARGS = stackExtraArgs; " -- overriding default locale so Unicode output using base -- won't be broken , "LANG=\"en_US.UTF-8\";" , "} \"\"" ] ] fullArgs = concat [ if pureShell then ["--pure"] else [] , if addGCRoots then [ "--indirect" , "--add-root" , toFilePath (configWorkDir config) F. "nix-gc-symlinks" F. "gc-root" ] else [] , map T.unpack (nixShellOptions (configNix config)) , nixopts , ["--run", unwords (cmnd:"$STACK_IN_NIX_EXTRA_ARGS":args')] -- Using --run instead of --command so we cannot end up in the -- nix-shell if stack build is Ctrl-C'd ] pathVar <- liftIO $ lookupEnv "PATH" logDebug $ "PATH is: " <> displayShow pathVar logDebug $ "Using a nix-shell environment " <> ( case mshellFile of Just path -> "from file: " <> fromString (toFilePath path) Nothing -> "with nix packages: " <> display (T.intercalate ", " pkgs) ) exec "nix-shell" fullArgs -- | Shell-escape quotes inside the string and enclose it in quotes. escape :: String -> String escape str = "'" ++ foldr (\c -> if c == '\'' then ("'\"'\"'"++) else (c:)) "" str ++ "'" -- | Command-line argument for "nix" nixCmdName :: String nixCmdName = "nix" nixHelpOptName :: String nixHelpOptName = nixCmdName ++ "-help" stack-2.9.3.1/src/Stack/Options/BenchParser.hs0000644000000000000000000000216314445022466017207 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Options.BenchParser ( benchOptsParser ) where import Options.Applicative ( Parser, flag', help, long, metavar, strOption ) import Options.Applicative.Builder.Extra ( optionalFirst ) import Stack.Prelude import Stack.Options.Utils ( hideMods ) import Stack.Types.Config ( BenchmarkOptsMonoid (..) ) -- | Parser for bench arguments. -- FIXME hiding options benchOptsParser :: Bool -> Parser BenchmarkOptsMonoid benchOptsParser hide0 = BenchmarkOptsMonoid <$> optionalFirst (strOption ( long "benchmark-arguments" <> long "ba" <> metavar "BENCH_ARGS" <> help "Forward BENCH_ARGS to the benchmark suite. Supports templates \ \from `cabal bench`" <> hide )) <*> optionalFirst (flag' True ( long "no-run-benchmarks" <> help "Disable running of benchmarks. (Benchmarks will still be \ \built.)" <> hide )) where hide = hideMods hide0 stack-2.9.3.1/src/Stack/Options/BuildMonoidParser.hs0000644000000000000000000001660314445022466020401 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.BuildMonoidParser ( buildOptsMonoidParser , cabalVerboseParser , cabalVerbosityOptsParser , cabalVerbosityParser ) where import qualified Data.Text as T import Distribution.Parsec ( eitherParsec ) import Options.Applicative ( Parser, eitherReader, flag, help, long, metavar, option , strOption ) import Options.Applicative.Builder.Extra ( firstBoolFlagsFalse, firstBoolFlagsNoDefault , firstBoolFlagsTrue, optionalFirst ) import Stack.Build ( splitObjsWarning ) import Stack.Prelude import Stack.Options.BenchParser ( benchOptsParser ) import Stack.Options.TestParser ( testOptsParser ) import Stack.Options.HaddockParser ( haddockOptsParser ) import Stack.Options.Utils ( GlobalOptsContext (..), hideMods ) import Stack.Types.Config.Build ( BuildOptsMonoid (..), CabalVerbosity , toFirstCabalVerbosity ) buildOptsMonoidParser :: GlobalOptsContext -> Parser BuildOptsMonoid buildOptsMonoidParser hide0 = BuildOptsMonoid <$> trace' <*> profile <*> noStrip <*> libProfiling <*> exeProfiling <*> libStripping <*> exeStripping <*> haddock <*> haddockOptsParser hideBool <*> openHaddocks <*> haddockDeps <*> haddockInternal <*> haddockHyperlinkSource <*> copyBins <*> copyCompilerTool <*> preFetch <*> keepGoing <*> keepTmpFiles <*> forceDirty <*> tests <*> testOptsParser hideBool <*> benches <*> benchOptsParser hideBool <*> reconfigure <*> cabalVerbose <*> splitObjs <*> skipComponents <*> interleavedOutput <*> ddumpDir where hideBool = hide0 /= BuildCmdGlobalOpts hide = hideMods hideBool hideExceptGhci = hideMods (hide0 `notElem` [BuildCmdGlobalOpts, GhciCmdGlobalOpts]) -- These use 'Any' because they are not settable in stack.yaml, so -- there is no need for options like --no-profile. trace' = Any <$> flag False True ( long "trace" <> help "Enable profiling in libraries, executables, etc. for all \ \expressions and generate a backtrace on exception" <> hideExceptGhci ) profile = Any <$> flag False True ( long "profile" <> help "Enable profiling in libraries, executables, etc. for all \ \expressions and generate a profiling report in tests or \ \benchmarks" <> hideExceptGhci ) noStrip = Any <$> flag False True ( long "no-strip" <> help "Disable DWARF debugging symbol stripping in libraries, \ \executables, etc. for all expressions, producing larger \ \executables but allowing the use of standard \ \debuggers/profiling tools/other utilities that use \ \debugging symbols." <> hideExceptGhci ) libProfiling = firstBoolFlagsFalse "library-profiling" "library profiling for TARGETs and all its dependencies" hide exeProfiling = firstBoolFlagsFalse "executable-profiling" "executable profiling for TARGETs and all its dependencies" hide libStripping = firstBoolFlagsTrue "library-stripping" "library stripping for TARGETs and all its dependencies" hide exeStripping = firstBoolFlagsTrue "executable-stripping" "executable stripping for TARGETs and all its dependencies" hide haddock = firstBoolFlagsFalse "haddock" "generating Haddocks the package(s) in this directory/configuration" hide openHaddocks = firstBoolFlagsFalse "open" "opening the local Haddock documentation in the browser" hide haddockDeps = firstBoolFlagsNoDefault "haddock-deps" "building Haddocks for dependencies (default: true if building Haddocks, \ \false otherwise)" hide haddockInternal = firstBoolFlagsFalse "haddock-internal" "building Haddocks for internal modules (like cabal haddock --internal)" hide haddockHyperlinkSource = firstBoolFlagsTrue "haddock-hyperlink-source" "building hyperlinked source for Haddock (like haddock \ \--hyperlinked-source)" hide copyBins = firstBoolFlagsFalse "copy-bins" "copying binaries to local-bin (see 'stack path')" hide copyCompilerTool = firstBoolFlagsFalse "copy-compiler-tool" "copying binaries of targets to compiler-tools-bin (see 'stack path')" hide keepGoing = firstBoolFlagsNoDefault "keep-going" "continue running after a step fails (default: false for build, true for \ \test/bench)" hide keepTmpFiles = firstBoolFlagsFalse "keep-tmp-files" "keep intermediate files and build directories" hide preFetch = firstBoolFlagsFalse "prefetch" "fetching packages necessary for the build immediately, useful with \ \--dry-run" hide forceDirty = firstBoolFlagsFalse "force-dirty" "forcing the treatment of all local packages as having dirty files, \ \useful for cases where Stack can't detect a file change" hide tests = firstBoolFlagsFalse "test" "testing the package(s) in this directory/configuration" hideExceptGhci benches = firstBoolFlagsFalse "bench" "benchmarking the package(s) in this directory/configuration" hideExceptGhci reconfigure = firstBoolFlagsFalse "reconfigure" "performing the configure step, even if unnecessary. Useful in some \ \corner cases with custom Setup.hs files" hide cabalVerbose = cabalVerbosityOptsParser hideBool splitObjs = firstBoolFlagsFalse "split-objs" ( "split-objs, to reduce output size (at the cost of build time). " ++ splitObjsWarning ) hide skipComponents = many (fmap T.pack (strOption ( long "skip" <> help "Skip given component (can be specified multiple times)" <> hide ))) interleavedOutput = firstBoolFlagsTrue "interleaved-output" "printing concurrent GHC output to the console with a prefix for the \ \package name" hide ddumpDir = optionalFirst (strOption ( long "ddump-dir" <> help "Specify output ddump-files" <> hide )) -- | Parser for Cabal verbosity options cabalVerbosityOptsParser :: Bool -> Parser (First CabalVerbosity) cabalVerbosityOptsParser hide = cabalVerbosityParser hide <|> cabalVerboseParser hide -- | Parser for Cabal verbosity option cabalVerbosityParser :: Bool -> Parser (First CabalVerbosity) cabalVerbosityParser hide = let pCabalVerbosity = option (eitherReader eitherParsec) ( long "cabal-verbosity" <> metavar "VERBOSITY" <> help "Cabal verbosity (accepts Cabal's numerical and extended syntax)" <> hideMods hide) in First . Just <$> pCabalVerbosity -- | Parser for the Cabal verbose flag, retained for backward compatibility cabalVerboseParser :: Bool -> Parser (First CabalVerbosity) cabalVerboseParser hide = let pVerboseFlag = firstBoolFlagsFalse "cabal-verbose" "asking Cabal to be verbose in its output" (hideMods hide) in toFirstCabalVerbosity <$> pVerboseFlag stack-2.9.3.1/src/Stack/Options/BuildParser.hs0000644000000000000000000000775514445022466017243 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Options.BuildParser ( buildOptsParser , flagsParser , targetsParser ) where import qualified Data.Map as Map import Options.Applicative import Options.Applicative.Args import Options.Applicative.Builder.Extra import Stack.Options.Completion import Stack.Options.PackageParser ( readFlag ) import Stack.Prelude import Stack.Types.Config -- | Parser for CLI-only build arguments buildOptsParser :: BuildCommand -> Parser BuildOptsCLI buildOptsParser cmd = BuildOptsCLI <$> targetsParser <*> switch ( long "dry-run" <> help "Don't build anything, just prepare to" ) <*> ( (\x y z -> concat [x, y, z]) <$> flag [] ["-Wall", "-Werror"] ( long "pedantic" <> help "Turn on -Wall and -Werror" ) <*> flag [] ["-O0"] ( long "fast" <> help "Turn off optimizations (-O0)" ) <*> many (textOption ( long "ghc-options" <> metavar "OPTIONS" <> completer ghcOptsCompleter <> help "Additional options passed to GHC" )) ) <*> flagsParser <*> ( flag' BSOnlyDependencies ( long "dependencies-only" <> help "A synonym for --only-dependencies" ) <|> flag' BSOnlySnapshot ( long "only-snapshot" <> help "Only build packages for the snapshot database, not the \ \local database" ) <|> flag' BSOnlyDependencies ( long "only-dependencies" <> help "Only build packages that are dependencies of targets on \ \the command line" ) <|> flag' BSOnlyLocals ( long "only-locals" <> help "Only build packages in the local database, fail if the \ \build plan includes the snapshot database" ) <|> pure BSAll ) <*> ( flag' FileWatch ( long "file-watch" <> help "Watch for changes in local files and automatically \ \rebuild. Ignores files in VCS boring/ignore file" ) <|> flag' FileWatchPoll ( long "file-watch-poll" <> help "Like --file-watch, but polling the filesystem instead of \ \using events" ) <|> pure NoFileWatch ) <*> switch ( long "watch-all" <> help "Watch all local files not taking targets into account" ) <*> many (cmdOption ( long "exec" <> metavar "COMMAND [ARGUMENT(S)]" <> help "Command and argument(s) to run after a successful build" )) <*> switch ( long "only-configure" <> help "Only perform the configure step, not any builds. Intended for \ \tool usage, may break when used on multiple packages at once!" ) <*> pure cmd <*> switch ( long "initial-build-steps" <> help "For target packages, only run initial build steps needed for \ \GHCi" <> internal ) targetsParser :: Parser [Text] targetsParser = many (textArgument ( metavar "TARGET" <> completer targetCompleter <> help "If none specified, use all local packages. See \ \https://docs.haskellstack.org/en/stable/build_command/#target-syntax \ \for details." )) flagsParser :: Parser (Map.Map ApplyCLIFlag (Map.Map FlagName Bool)) flagsParser = Map.unionsWith Map.union <$> many (option readFlag ( long "flag" <> completer flagCompleter <> metavar "PACKAGE:[-]FLAG" <> help "Override flags set in stack.yaml (applies to local packages \ \and extra-deps)" )) stack-2.9.3.1/src/Stack/Options/CleanParser.hs0000644000000000000000000000155314445022466017214 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.CleanParser ( cleanOptsParser ) where import Options.Applicative ( Parser, flag', help, long, metavar ) import Stack.Clean ( CleanCommand (..), CleanOpts (..) ) import Stack.Prelude import Stack.Types.PackageName ( packageNameArgument ) -- | Command-line parser for the clean command. cleanOptsParser :: CleanCommand -> Parser CleanOpts cleanOptsParser Clean = CleanShallow <$> packages <|> doFullClean where packages = many (packageNameArgument ( metavar "PACKAGE" <> help "If none specified, clean all project packages" )) doFullClean = flag' CleanFull ( long "full" <> help "Delete the project's Stack working directories (.stack-work by \ \default)." ) cleanOptsParser Purge = pure CleanFull stack-2.9.3.1/src/Stack/Options/ConfigParser.hs0000644000000000000000000002050214445022466017372 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.ConfigParser ( configOptsParser ) where import Data.Char ( toUpper ) import Options.Applicative ( Parser, auto, completer, completeWith, eitherReader, help , long, metavar, option, short, strOption ) import Options.Applicative.Builder.Extra ( PathCompleterOpts (..), absDirOption, absFileOption , defaultPathCompleterOpts, dirCompleter, firstBoolFlagsFalse , firstBoolFlagsNoDefault, firstBoolFlagsTrue, optionalFirst , pathCompleterWith ) import Path ( parseRelDir ) import Stack.Constants ( stackRootOptionName ) import Stack.Options.BuildMonoidParser ( buildOptsMonoidParser ) import Stack.Options.DockerParser ( dockerOptsParser ) import Stack.Options.GhcBuildParser ( ghcBuildParser ) import Stack.Options.GhcVariantParser ( ghcVariantParser ) import Stack.Options.NixParser ( nixOptsParser ) import Stack.Options.Utils ( GlobalOptsContext (..), hideMods ) import Stack.Prelude import Stack.Types.Config ( ConfigMonoid (..), DumpLogs (..), readColorWhen ) 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 ghcVariant ghcBuild jobs includes libs preprocs overrideGccPath overrideHpack skipGHCCheck skipMsys localBin setupInfoLocations modifyCodePage allowDifferentUser dumpLogs colorWhen snapLoc noRunCompile -> mempty { configMonoidStackRoot = stackRoot , configMonoidWorkDir = workDir , configMonoidBuildOpts = buildOpts , configMonoidDockerOpts = dockerOpts , configMonoidNixOpts = nixOpts , configMonoidSystemGHC = systemGHC , configMonoidInstallGHC = installGHC , configMonoidSkipGHCCheck = skipGHCCheck , configMonoidArch = arch , configMonoidGHCVariant = ghcVariant , configMonoidGHCBuild = ghcBuild , configMonoidJobs = jobs , configMonoidExtraIncludeDirs = includes , configMonoidExtraLibDirs = libs , configMonoidCustomPreprocessorExts = preprocs , configMonoidOverrideGccPath = overrideGccPath , configMonoidOverrideHpack = overrideHpack , configMonoidSkipMsys = skipMsys , configMonoidLocalBinPath = localBin , configMonoidSetupInfoLocations = setupInfoLocations , configMonoidModifyCodePage = modifyCodePage , configMonoidAllowDifferentUser = allowDifferentUser , configMonoidDumpLogs = dumpLogs , configMonoidColorWhen = colorWhen , configMonoidSnapshotLocation = snapLoc , configMonoidNoRunCompile = noRunCompile } ) <$> optionalFirst (absDirOption ( long stackRootOptionName <> metavar (map toUpper stackRootOptionName) <> help "Absolute path to the global Stack root directory (Overrides \ \any STACK_ROOT environment variable)" <> hide )) <*> optionalFirst (option (eitherReader (mapLeft showWorkDirError . parseRelDir)) ( long "work-dir" <> metavar "WORK-DIR" <> completer ( pathCompleterWith ( defaultPathCompleterOpts { pcoAbsolute = False, pcoFileFilter = const False } ) ) <> help "Relative path of work directory (Overrides any STACK_WORK \ \environment variable, default is '.stack-work')" <> hide )) <*> buildOptsMonoidParser hide0 <*> dockerOptsParser True <*> nixOptsParser True <*> firstBoolFlagsNoDefault "system-ghc" "using the system installed GHC (on the PATH) if it is available and \ \its version matches. Disabled by default." hide <*> firstBoolFlagsTrue "install-ghc" "downloading and installing GHC if necessary (can be done manually \ \with 'stack setup')" hide <*> optionalFirst (strOption ( long "arch" <> metavar "ARCH" <> help "System architecture, e.g. i386, x86_64" <> hide )) <*> optionalFirst (ghcVariantParser (hide0 /= OuterGlobalOpts)) <*> optionalFirst (ghcBuildParser (hide0 /= OuterGlobalOpts)) <*> optionalFirst (option auto ( long "jobs" <> short 'j' <> metavar "JOBS" <> help "Number of concurrent jobs to run" <> hide )) <*> many ((currentDir FilePath.) <$> strOption ( long "extra-include-dirs" <> metavar "DIR" <> completer dirCompleter <> help "Extra directories to check for C header files" <> hide )) <*> many ((currentDir FilePath.) <$> strOption ( long "extra-lib-dirs" <> metavar "DIR" <> completer dirCompleter <> help "Extra directories to check for libraries" <> hide )) <*> many (strOption ( long "custom-preprocessor-extensions" <> metavar "EXT" <> help "Extensions used for custom preprocessors" <> hide )) <*> optionalFirst (absFileOption ( long "with-gcc" <> metavar "PATH-TO-GCC" <> help "Use gcc found at PATH-TO-GCC" <> hide )) <*> optionalFirst (strOption ( long "with-hpack" <> metavar "HPACK" <> help "Use HPACK executable (overrides bundled Hpack)" <> hide )) <*> firstBoolFlagsFalse "skip-ghc-check" "skipping the GHC version and architecture check" hide <*> firstBoolFlagsFalse "skip-msys" "skipping the local MSYS installation (Windows only)" hide <*> optionalFirst ((currentDir FilePath.) <$> strOption ( long "local-bin-path" <> metavar "DIR" <> completer dirCompleter <> help "Install binaries to DIR" <> hide )) <*> many (strOption ( long "setup-info-yaml" <> help "Alternate URL or relative / absolute path for Stack \ \dependencies" <> metavar "URL" )) <*> firstBoolFlagsTrue "modify-code-page" "setting the codepage to support UTF-8 (Windows only)" hide <*> firstBoolFlagsNoDefault "allow-different-user" "permission for users other than the owner of the Stack root directory \ \to use a Stack installation (POSIX only) (default: true inside \ \Docker, otherwise false)" hide <*> fmap toDumpLogs (firstBoolFlagsNoDefault "dump-logs" "dump the build output logs for local packages to the console \ \(default: dump warning logs)" hide) <*> optionalFirst (option readColorWhen ( long "color" <> long "colour" <> metavar "WHEN" <> completeWith ["always", "never", "auto"] <> help "Specify when to use color in output; WHEN is 'always', \ \'never', or 'auto'. On Windows versions before Windows \ \10, for terminals that do not support color codes, the \ \default is 'never'; color may work on terminals that \ \support color codes" <> hide )) <*> optionalFirst (strOption ( long "snapshot-location-base" <> help "The base location of LTS/Nightly snapshots" <> metavar "URL" )) <*> firstBoolFlagsFalse "script-no-run-compile" "the use of options `--no-run --compile` with `stack script`" hide where hide = hideMods (hide0 /= OuterGlobalOpts) toDumpLogs (First (Just True)) = First (Just DumpAllLogs) toDumpLogs (First (Just False)) = First (Just DumpNoLogs) toDumpLogs (First Nothing) = First Nothing showWorkDirError err = show err ++ "\nNote that --work-dir must be a relative child directory, because \ \work-dirs outside of the package are not supported by Cabal." ++ "\nSee https://github.com/commercialhaskell/stack/issues/2954" stack-2.9.3.1/src/Stack/Options/Completion.hs0000644000000000000000000001003114445022466017115 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} module Stack.Options.Completion ( ghcOptsCompleter , targetCompleter , flagCompleter , projectExeCompleter ) where import Data.Char ( isSpace ) import Data.List ( isPrefixOf ) import qualified Data.Map as Map import Data.Maybe import qualified Data.Set as Set import qualified Data.Text as T import qualified Distribution.PackageDescription as C import Options.Applicative import Options.Applicative.Builder.Extra import Stack.Constants ( ghcShowOptionsOutput ) import Stack.Options.GlobalParser ( globalOptsFromMonoid ) import Stack.Runners import Stack.Prelude import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.SourceMap ghcOptsCompleter :: Completer ghcOptsCompleter = mkCompleter $ \inputRaw -> pure $ let input = unescapeBashArg inputRaw (curArgReversed, otherArgsReversed) = break isSpace (reverse input) curArg = reverse curArgReversed otherArgs = reverse otherArgsReversed in if null curArg then [] else map (otherArgs ++) $ filter (curArg `isPrefixOf`) ghcShowOptionsOutput -- TODO: Ideally this would pay attention to --stack-yaml, may require -- changes to optparse-applicative. buildConfigCompleter :: (String -> RIO EnvConfig [String]) -> Completer buildConfigCompleter inner = mkCompleter $ \inputRaw -> do let input = unescapeBashArg inputRaw case input of -- If it looks like a flag, skip this more costly completion. ('-': _) -> pure [] _ -> do go' <- globalOptsFromMonoid False mempty let go = go' { globalLogLevel = LevelOther "silent" } withRunnerGlobal go $ withConfig NoReexec $ withDefaultEnvConfig $ inner input targetCompleter :: Completer targetCompleter = buildConfigCompleter $ \input -> do packages <- view $ buildConfigL.to (smwProject . bcSMWanted) comps <- for packages ppComponents pure $ filter (input `isPrefixOf`) $ concatMap allComponentNames $ Map.toList comps where allComponentNames (name, comps) = map (T.unpack . renderPkgComponent . (name,)) (Set.toList comps) flagCompleter :: Completer flagCompleter = buildConfigCompleter $ \input -> do bconfig <- view buildConfigL gpds <- for (smwProject $ bcSMWanted bconfig) ppGPD let wildcardFlags = nubOrd $ concatMap (\(name, gpd) -> map (\fl -> "*:" ++ flagString name fl) (C.genPackageFlags gpd)) $ Map.toList gpds normalFlags = concatMap (\(name, gpd) -> map (\fl -> packageNameString name ++ ":" ++ flagString name fl) (C.genPackageFlags gpd)) $ Map.toList gpds flagString name fl = let flname = C.unFlagName $ C.flagName fl in (if flagEnabled name fl then "-" else "") ++ flname prjFlags = case configProject (bcConfig bconfig) of PCProject (p, _) -> projectFlags p PCGlobalProject -> mempty PCNoProject _ -> mempty flagEnabled name fl = fromMaybe (C.flagDefault fl) $ Map.lookup (C.flagName fl) $ Map.findWithDefault Map.empty name prjFlags pure $ filter (input `isPrefixOf`) $ case input of ('*' : ':' : _) -> wildcardFlags ('*' : _) -> wildcardFlags _ -> normalFlags projectExeCompleter :: Completer projectExeCompleter = buildConfigCompleter $ \input -> do packages <- view $ buildConfigL.to (smwProject . bcSMWanted) gpds <- Map.traverseWithKey (const ppGPD) packages pure $ filter (input `isPrefixOf`) $ nubOrd $ concatMap (\gpd -> map (C.unUnqualComponentName . fst) (C.condExecutables gpd) ) gpds stack-2.9.3.1/src/Stack/Options/DockerParser.hs0000644000000000000000000001336714445022466017407 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.DockerParser ( dockerOptsParser ) where import Data.List ( intercalate ) import qualified Data.Text as T import Distribution.Version ( anyVersion ) import Options.Applicative ( Parser, auto, completer, help, listCompleter, long, metavar , option, str, value ) import Options.Applicative.Args ( argsOption ) import Options.Applicative.Builder.Extra ( dirCompleter, eitherReader', fileCompleter , firstBoolFlagsFalse, firstBoolFlagsNoDefault , firstBoolFlagsTrue, optionalFirst ) import Stack.Docker ( dockerCmdName ) import Stack.Prelude import Stack.Options.Utils ( hideMods ) import Stack.Types.Version ( IntersectingVersionRange (..) ) import Stack.Types.Docker ( DockerMonoidRepoOrImage (..), DockerOptsMonoid (..) , dockerAutoPullArgName, dockerImageArgName , dockerContainerNameArgName, dockerDetachArgName , dockerEnvArgName, dockerPersistArgName , dockerRegistryLoginArgName, dockerRegistryPasswordArgName , dockerRegistryUsernameArgName, dockerRepoArgName , dockerRunArgsArgName, dockerMountArgName , dockerMountModeArgName, dockerNetworkArgName , dockerSetUserArgName, dockerStackExeArgName , dockerStackExeDownloadVal, dockerStackExeHostVal , dockerStackExeImageVal, parseDockerStackExe ) -- | Options parser configuration for Docker. dockerOptsParser :: Bool -> Parser DockerOptsMonoid dockerOptsParser hide0 = DockerOptsMonoid (Any False) <$> firstBoolFlagsNoDefault dockerCmdName "using a Docker container. --docker implies 'system-ghc: true'" hide <*> fmap First ( Just . DockerMonoidRepo <$> option str ( long (dockerOptName dockerRepoArgName) <> hide <> metavar "NAME" <> help "Docker repository name" ) <|> Just . DockerMonoidImage <$> option str ( long (dockerOptName dockerImageArgName) <> hide <> metavar "IMAGE" <> help "Exact Docker image ID (overrides docker-repo)" ) <|> pure Nothing ) <*> firstBoolFlagsNoDefault (dockerOptName dockerRegistryLoginArgName) "registry requires login" hide <*> firstStrOption ( long (dockerOptName dockerRegistryUsernameArgName) <> hide <> metavar "USERNAME" <> help "Docker registry username" ) <*> firstStrOption ( long (dockerOptName dockerRegistryPasswordArgName) <> hide <> metavar "PASSWORD" <> help "Docker registry password" ) <*> firstBoolFlagsTrue (dockerOptName dockerAutoPullArgName) "automatic pulling latest version of image" hide <*> firstBoolFlagsFalse (dockerOptName dockerDetachArgName) "running a detached Docker container" hide <*> firstBoolFlagsFalse (dockerOptName dockerPersistArgName) "not deleting container after it exits" hide <*> firstStrOption ( long (dockerOptName dockerContainerNameArgName) <> hide <> metavar "NAME" <> help "Docker container name" ) <*> firstStrOption ( long (dockerOptName dockerNetworkArgName) <> hide <> metavar "NETWORK" <> help "Docker network" ) <*> argsOption ( long (dockerOptName dockerRunArgsArgName) <> hide <> value [] <> metavar "'ARG1 [ARG2 ...]'" <> help "Additional options to pass to 'docker run'") <*> many (option auto ( long (dockerOptName dockerMountArgName) <> hide <> metavar "(PATH | HOST-PATH:CONTAINER-PATH)" <> completer dirCompleter <> help "Mount volumes from host in container (can be specified \ \multiple times)" )) <*> firstStrOption ( long (dockerOptName dockerMountModeArgName) <> hide <> metavar "SUFFIX" <> help "Volume mount mode suffix" ) <*> many (option str ( long (dockerOptName dockerEnvArgName) <> hide <> metavar "NAME=VALUE" <> help "Set environment variable in container (can be specified \ \multiple times)" )) <*> optionalFirst (option (eitherReader' parseDockerStackExe) ( let specialOpts = [ dockerStackExeDownloadVal , dockerStackExeHostVal , dockerStackExeImageVal ] in long (dockerOptName dockerStackExeArgName) <> hide <> metavar (intercalate "|" (specialOpts ++ ["PATH"])) <> completer (listCompleter specialOpts <> fileCompleter) <> help ( concat [ "Location of " , stackProgName , " executable used in container" ] ) )) <*> firstBoolFlagsNoDefault (dockerOptName dockerSetUserArgName) "setting user in container to match host" hide <*> pure (IntersectingVersionRange anyVersion) where dockerOptName optName = dockerCmdName ++ "-" ++ T.unpack optName firstStrOption = optionalFirst . option str hide = hideMods hide0 stack-2.9.3.1/src/Stack/Options/DotParser.hs0000644000000000000000000001141314445022466016714 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Options.DotParser ( dotOptsParser , formatSubCommand , licenseParser , listDepsConstraintsParser , listDepsFormatOptsParser , listDepsJsonParser , listDepsOptsParser , listDepsTextParser , listDepsTreeParser , separatorParser , toListDepsOptsParser ) where import Data.Char ( isSpace ) import Data.List.Split ( splitOn ) import qualified Data.Set as Set import qualified Data.Text as T import Distribution.Types.PackageName ( mkPackageName ) import Options.Applicative ( CommandFields, Mod, Parser, auto, command, help, idm, info , long, metavar, option, progDesc, showDefault, strOption , subparser, switch, value ) import Options.Applicative.Builder.Extra ( boolFlags, textOption ) import Stack.Dot ( DotOpts (..), ListDepsFormat (..), ListDepsFormatOpts (..) , ListDepsOpts (..) ) import Stack.Options.BuildParser ( flagsParser, targetsParser ) import Stack.Prelude -- | Parser for arguments to `stack dot` dotOptsParser :: Bool -> Parser DotOpts dotOptsParser externalDefault = DotOpts <$> includeExternal <*> includeBase <*> depthLimit <*> fmap (maybe Set.empty $ Set.fromList . splitNames) prunedPkgs <*> targetsParser <*> flagsParser <*> testTargets <*> benchTargets <*> globalHints where includeExternal = boolFlags externalDefault "external" "inclusion of external dependencies" idm includeBase = boolFlags True "include-base" "inclusion of dependencies on base" idm depthLimit = optional (option auto ( long "depth" <> metavar "DEPTH" <> help "Limit the depth of dependency resolution (Default: No limit)" )) prunedPkgs = optional (strOption ( long "prune" <> metavar "PACKAGES" <> help "Prune each package name from the comma separated list of package \ \names PACKAGES" )) testTargets = switch ( long "test" <> help "Consider dependencies of test components" ) benchTargets = switch ( long "bench" <> help "Consider dependencies of benchmark components" ) splitNames :: String -> [PackageName] splitNames = map ( mkPackageName . takeWhile (not . isSpace) . dropWhile isSpace ) . splitOn "," globalHints = switch ( long "global-hints" <> help "Do not require an install GHC; instead, use a hints file for \ \global packages" ) separatorParser :: Parser Text separatorParser = fmap escapeSep ( textOption ( long "separator" <> metavar "SEP" <> help "Separator between package name and package version." <> value " " <> showDefault ) ) where escapeSep s = T.replace "\\t" "\t" (T.replace "\\n" "\n" s) licenseParser :: Parser Bool licenseParser = boolFlags False "license" "printing of dependency licenses instead of versions" idm listDepsFormatOptsParser :: Parser ListDepsFormatOpts listDepsFormatOptsParser = ListDepsFormatOpts <$> separatorParser <*> licenseParser listDepsTreeParser :: Parser ListDepsFormat listDepsTreeParser = ListDepsTree <$> listDepsFormatOptsParser listDepsTextParser :: Parser ListDepsFormat listDepsTextParser = ListDepsText <$> listDepsFormatOptsParser listDepsJsonParser :: Parser ListDepsFormat listDepsJsonParser = pure ListDepsJSON listDepsConstraintsParser :: Parser ListDepsFormat listDepsConstraintsParser = pure ListDepsConstraints toListDepsOptsParser :: Parser ListDepsFormat -> Parser ListDepsOpts toListDepsOptsParser formatParser = ListDepsOpts <$> formatParser <*> dotOptsParser True formatSubCommand :: String -> String -> Parser ListDepsFormat -> Mod CommandFields ListDepsOpts formatSubCommand cmd desc formatParser = command cmd (info (toListDepsOptsParser formatParser) (progDesc desc)) -- | Parser for arguments to `stack ls dependencies`. listDepsOptsParser :: Parser ListDepsOpts listDepsOptsParser = subparser ( formatSubCommand "text" "Print dependencies as text (default)" listDepsTextParser <> formatSubCommand "cabal" "Print dependencies as exact Cabal constraints" listDepsConstraintsParser <> formatSubCommand "tree" "Print dependencies as tree" listDepsTreeParser <> formatSubCommand "json" "Print dependencies as JSON" listDepsJsonParser ) <|> toListDepsOptsParser listDepsTextParser stack-2.9.3.1/src/Stack/Options/ExecParser.hs0000644000000000000000000000524014445022466017053 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.ExecParser ( evalOptsParser , execOptsExtraParser , execOptsParser ) where import Options.Applicative import Options.Applicative.Builder.Extra import Options.Applicative.Args import Stack.Options.Completion import Stack.Prelude import Stack.Types.Config -- | Parser for exec command execOptsParser :: Maybe SpecialExecCmd -> Parser ExecOpts execOptsParser mcmd = ExecOpts <$> maybe eoCmdParser pure mcmd <*> eoArgsParser <*> execOptsExtraParser where eoCmdParser = ExecCmd <$> strArgument ( metavar "COMMAND" <> completer projectExeCompleter ) eoArgsParser = many (strArgument (metavar txt)) where txt = case mcmd of Nothing -> normalTxt Just ExecCmd{} -> normalTxt Just ExecRun -> "-- ARGUMENT(S) (e.g. stack run -- file.txt)" Just ExecGhc -> "-- ARGUMENT(S) (e.g. stack ghc -- X.hs -o x)" Just ExecRunGhc -> "-- ARGUMENT(S) (e.g. stack runghc -- X.hs)" normalTxt = "-- ARGUMENT(S) (e.g. stack exec ghc-pkg -- describe base)" evalOptsParser :: String -- ^ metavar -> Parser EvalOpts evalOptsParser meta = EvalOpts <$> eoArgsParser <*> execOptsExtraParser where eoArgsParser :: Parser String eoArgsParser = strArgument (metavar meta) -- | Parser for extra options to exec command execOptsExtraParser :: Parser ExecOptsExtra execOptsExtraParser = ExecOptsExtra <$> eoEnvSettingsParser <*> eoPackagesParser <*> eoRtsOptionsParser <*> eoCwdParser where eoEnvSettingsParser :: Parser EnvSettings eoEnvSettingsParser = EnvSettings True <$> boolFlags True "ghc-package-path" "setting the GHC_PACKAGE_PATH variable for the subprocess" idm <*> boolFlags True "stack-exe" "setting the STACK_EXE environment variable to the path for the \ \stack executable" idm <*> pure False <*> pure True eoPackagesParser :: Parser [String] eoPackagesParser = many (strOption ( long "package" <> metavar "PACKAGE" <> help "Add a package (can be specified multiple times)" )) eoRtsOptionsParser :: Parser [String] eoRtsOptionsParser = concat <$> many (argsOption ( long "rts-options" <> help "Explicit RTS options to pass to application" <> metavar "RTSFLAG" )) eoCwdParser :: Parser (Maybe FilePath) eoCwdParser = optional (strOption ( long "cwd" <> help "Sets the working directory before executing" <> metavar "DIR" <> completer dirCompleter )) stack-2.9.3.1/src/Stack/Options/GhcBuildParser.hs0000644000000000000000000000210714445022466017647 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.GhcBuildParser ( ghcBuildParser ) where import Options.Applicative ( Parser, completeWith, help, long, metavar, option ) import Options.Applicative.Types ( readerAsk, readerError ) import Stack.Options.Utils ( hideMods ) import Stack.Prelude import Stack.Types.CompilerBuild ( CompilerBuild, parseCompilerBuild ) -- | GHC build parser ghcBuildParser :: Bool -> Parser CompilerBuild ghcBuildParser hide = option readGHCBuild ( long "ghc-build" <> metavar "BUILD" <> completeWith [ "standard" , "gmp4" , "nopie" , "tinfo6" , "tinfo6-nopie" , "ncurses6" , "int-native" , "integersimple" ] <> help "Specialized GHC build, e.g. 'gmp4' or 'standard' (usually \ \auto-detected)" <> hideMods hide ) where readGHCBuild = do s <- readerAsk case parseCompilerBuild s of Left e -> readerError (displayException e) Right v -> pure v stack-2.9.3.1/src/Stack/Options/GhciParser.hs0000644000000000000000000000653514445022466017051 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Options.GhciParser ( ghciOptsParser ) where import Options.Applicative ( Parser, completer, flag, help, idm, internal, long, metavar , strOption, switch ) import Options.Applicative.Args ( argsOption ) import Options.Applicative.Builder.Extra ( boolFlags, boolFlagsNoDefault, fileExtCompleter , textArgument, textOption ) import Stack.Config ( packagesParser ) import Stack.Ghci ( GhciOpts (..) ) import Stack.Options.BuildParser ( flagsParser ) import Stack.Options.Completion ( ghcOptsCompleter, targetCompleter ) import Stack.Prelude -- | Parser for GHCI options ghciOptsParser :: Parser GhciOpts ghciOptsParser = GhciOpts <$> many (textArgument ( metavar "TARGET/FILE" <> completer (targetCompleter <> fileExtCompleter [".hs", ".lhs"]) <> help "If none specified, use all local packages. See \ \https://docs.haskellstack.org/en/stable/build_command/#target-syntax \ \for details. If a path to a .hs or .lhs file is specified, it \ \will be loaded." )) <*> ( (\x y -> x ++ concat y) <$> flag [] ["-Wall", "-Werror"] ( long "pedantic" <> help "Turn on -Wall and -Werror" ) <*> many (argsOption ( long "ghci-options" <> metavar "OPTIONS" <> completer ghcOptsCompleter <> help "Additional options passed to GHCi" )) ) <*> ( concat <$> many (argsOption ( long "ghc-options" <> metavar "OPTIONS" <> completer ghcOptsCompleter <> help "Additional options passed to both GHC and GHCi" )) ) <*> flagsParser <*> optional (strOption ( long "with-ghc" <> metavar "GHC" <> help "Use this GHC to run GHCi" )) <*> ( not <$> boolFlags True "load" "load modules on start-up" idm ) <*> packagesParser <*> optional (textOption ( long "main-is" <> metavar "TARGET" <> completer targetCompleter <> help "Specify which target should contain the main module to load, \ \such as for an executable for test suite or benchmark." )) <*> switch ( long "load-local-deps" <> help "Load all local dependencies of your targets" ) -- TODO: deprecate this? probably useless. <*> switch ( long "skip-intermediate-deps" <> help "Skip loading intermediate target dependencies" <> internal ) <*> optional (boolFlagsNoDefault "package-hiding" "package hiding" idm) <*> switch ( long "no-build" <> help "Don't build before launching GHCi" <> internal ) <*> switch ( long "only-main" <> help "Only load and import the main module. If no main module, no \ \modules will be loaded." ) stack-2.9.3.1/src/Stack/Options/GhcVariantParser.hs0000644000000000000000000000160714445022466020220 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.GhcVariantParser ( ghcVariantParser ) where import Options.Applicative ( Parser, help, long, metavar, option, readerError ) import Options.Applicative.Types ( readerAsk ) import Stack.Prelude import Stack.Options.Utils ( hideMods ) import Stack.Types.Config ( GHCVariant, parseGHCVariant ) -- | GHC variant parser ghcVariantParser :: Bool -> Parser GHCVariant ghcVariantParser hide = option readGHCVariant ( long "ghc-variant" <> metavar "VARIANT" <> help "Specialized GHC variant, e.g. int-native or integersimple \ \(incompatible with --system-ghc)" <> hideMods hide ) where readGHCVariant = do s <- readerAsk case parseGHCVariant s of Left e -> readerError (displayException e) Right v -> pure v stack-2.9.3.1/src/Stack/Options/GlobalParser.hs0000644000000000000000000001474614445022466017402 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE RecordWildCards #-} module Stack.Options.GlobalParser ( globalOptsFromMonoid , globalOptsParser , initOptsParser ) where import Options.Applicative ( Parser, auto, completer, help, hidden, internal, long , metavar, option, strOption, switch, value ) import Options.Applicative.Builder.Extra ( dirCompleter, fileExtCompleter, firstBoolFlagsFalse , firstBoolFlagsNoDefault, firstBoolFlagsTrue, optionalFirst , textArgument ) import Path.IO ( getCurrentDir, resolveDir', resolveFile' ) import qualified Stack.Docker as Docker import Stack.Init ( InitOpts (..) ) import Stack.Prelude import Stack.Options.ConfigParser ( configOptsParser ) import Stack.Options.LogLevelParser ( logLevelOptsParser ) import Stack.Options.ResolverParser ( abstractResolverOptsParser, compilerOptsParser ) import Stack.Options.Utils ( GlobalOptsContext (..), hideMods ) import Stack.Types.Config ( GlobalOpts (..), GlobalOptsMonoid (..) , LockFileBehavior (..), StackYamlLoc (..), defaultLogLevel , readLockFileBehavior, readStyles ) import Stack.Types.Docker ( dockerEntrypointArgName ) -- | Parser for global command-line options. globalOptsParser :: FilePath -> GlobalOptsContext -> Maybe LogLevel -> Parser GlobalOptsMonoid globalOptsParser currentDir kind defLogLevel = GlobalOptsMonoid <$> optionalFirst (strOption ( long Docker.reExecArgName <> hidden <> internal )) <*> optionalFirst (option auto ( long dockerEntrypointArgName <> hidden <> internal )) <*> (First <$> logLevelOptsParser hide0 defLogLevel) <*> firstBoolFlagsTrue "time-in-log" "inclusion of timings in logs, for the purposes of using diff with logs" hide <*> firstBoolFlagsFalse "rsl-in-log" "inclusion of raw snapshot layer (rsl) in logs" hide <*> configOptsParser currentDir kind <*> optionalFirst (abstractResolverOptsParser hide0) <*> pure (First Nothing) <*> optionalFirst (compilerOptsParser hide0) -- resolver root is only set via the script command <*> firstBoolFlagsNoDefault "terminal" "overriding terminal detection in the case of running in a false terminal" hide <*> option readStyles ( long "stack-colors" <> long "stack-colours" <> metavar "STYLES" <> value mempty <> help "Specify Stack's output styles; STYLES is a colon-delimited \ \sequence of key=value, where 'key' is a style name and 'value' \ \is a semicolon-delimited list of 'ANSI' SGR (Select Graphic \ \Rendition) control codes (in decimal). Use 'stack ls \ \stack-colors --basic' to see the current sequence. In shells \ \where a semicolon is a command separator, enclose STYLES in \ \quotes." <> hide ) <*> optionalFirst (option auto ( long "terminal-width" <> metavar "INT" <> help "Specify the width of the terminal, used for pretty-print \ \messages" <> hide )) <*> optionalFirst (strOption ( long "stack-yaml" <> metavar "STACK-YAML" <> completer (fileExtCompleter [".yaml"]) <> help ( "Override project stack.yaml file " <> "(overrides any STACK_YAML environment variable)" ) <> hide )) <*> optionalFirst (option readLockFileBehavior ( long "lock-file" <> help "Specify how to interact with lock files. Default: read/write. \ \If resolver is overridden: read-only" <> hide )) where hide = hideMods hide0 hide0 = kind /= OuterGlobalOpts -- | Create GlobalOpts from GlobalOptsMonoid. globalOptsFromMonoid :: MonadIO m => Bool -> GlobalOptsMonoid -> m GlobalOpts globalOptsFromMonoid defaultTerminal GlobalOptsMonoid{..} = do resolver <- for (getFirst globalMonoidResolver) $ \ur -> do root <- case globalMonoidResolverRoot of First Nothing -> getCurrentDir First (Just dir) -> resolveDir' dir resolvePaths (Just root) ur stackYaml <- case getFirst globalMonoidStackYaml of Nothing -> pure SYLDefault Just fp -> SYLOverride <$> resolveFile' fp pure GlobalOpts { globalReExecVersion = getFirst globalMonoidReExecVersion , globalDockerEntrypoint = getFirst globalMonoidDockerEntrypoint , globalLogLevel = fromFirst defaultLogLevel globalMonoidLogLevel , globalTimeInLog = fromFirstTrue globalMonoidTimeInLog , globalRSLInLog = fromFirstFalse globalMonoidRSLInLog , globalConfigMonoid = globalMonoidConfigMonoid , globalResolver = resolver , globalCompiler = getFirst globalMonoidCompiler , globalTerminal = fromFirst defaultTerminal globalMonoidTerminal , globalStylesUpdate = globalMonoidStyles , globalTermWidth = getFirst globalMonoidTermWidth , globalStackYaml = stackYaml , globalLockFileBehavior = let defLFB = case getFirst globalMonoidResolver of Nothing -> LFBReadWrite _ -> LFBReadOnly in fromFirst defLFB globalMonoidLockFileBehavior } initOptsParser :: Parser InitOpts initOptsParser = InitOpts <$> searchDirs <*> omitPackages <*> overwrite <*> fmap not ignoreSubDirs where searchDirs = many (textArgument ( metavar "DIR(S)" <> completer dirCompleter <> help "Directory, or directories, to include in the search for .cabal \ \files, when initialising. The default is the current directory." )) ignoreSubDirs = switch ( long "ignore-subdirs" <> help "Do not search for .cabal files in subdirectories, when \ \initialising." ) overwrite = switch ( long "force" <> help "Force an initialisation that overwrites any existing stack.yaml \ \file." ) omitPackages = switch ( long "omit-packages" <> help "Exclude conflicting or incompatible user packages, when \ \initialising." ) stack-2.9.3.1/src/Stack/Options/HaddockParser.hs0000644000000000000000000000145714445022466017532 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.HaddockParser ( haddockOptsParser ) where import Options.Applicative ( Parser, help, long, metavar ) import Options.Applicative.Args ( argsOption ) import Stack.Options.Utils ( hideMods ) import Stack.Prelude import Stack.Types.Config ( HaddockOptsMonoid (..) ) -- | Parser for haddock arguments. haddockOptsParser :: Bool -> Parser HaddockOptsMonoid haddockOptsParser hide0 = HaddockOptsMonoid <$> fmap (fromMaybe []) ( optional (argsOption ( long "haddock-arguments" <> metavar "HADDOCK_ARGS" <> help "Arguments passed to the haddock program" <> hide )) ) where hide = hideMods hide0 stack-2.9.3.1/src/Stack/Options/HpcReportParser.hs0000644000000000000000000000356714445022466020107 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.HpcReportParser ( hpcReportOptsParser , pvpBoundsOption ) where import qualified Data.Text as T import Options.Applicative ( Parser, completer, completeWith, help, long, metavar , option, readerError, strOption, switch ) import Options.Applicative.Builder.Extra ( dirCompleter, fileExtCompleter, textArgument ) import Options.Applicative.Types ( readerAsk ) import Stack.Coverage ( HpcReportOpts (..) ) import Stack.Options.Completion ( targetCompleter ) import Stack.Prelude import Stack.Types.Config ( PvpBounds, parsePvpBounds ) -- | Parser for @stack hpc report@. hpcReportOptsParser :: Parser HpcReportOpts hpcReportOptsParser = HpcReportOpts <$> many (textArgument ( metavar "TARGET_OR_TIX" <> completer (targetCompleter <> fileExtCompleter [".tix"]) )) <*> switch ( long "all" <> help "Use results from all packages and components involved in \ \previous --coverage run" ) <*> optional (strOption ( long "destdir" <> metavar "DIR" <> completer dirCompleter <> help "Output directory for HTML report" )) <*> switch ( long "open" <> help "Open the report in the browser" ) pvpBoundsOption :: Parser PvpBounds pvpBoundsOption = option readPvpBounds ( long "pvp-bounds" <> metavar "PVP-BOUNDS" <> completeWith ["none", "lower", "upper", "both"] <> help "How PVP version bounds should be added to Cabal file: none, lower, \ \upper, both" ) where readPvpBounds = do s <- readerAsk case parsePvpBounds $ T.pack s of Left e -> readerError e Right v -> pure v stack-2.9.3.1/src/Stack/Options/LogLevelParser.hs0000644000000000000000000000337314445022466017705 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Options.LogLevelParser ( logLevelOptsParser ) where import qualified Data.Text as T import Options.Applicative ( Parser, completeWith, flag', help, long, metavar, short , strOption ) import Stack.Options.Utils ( hideMods ) import Stack.Prelude -- | Parser for a logging level. logLevelOptsParser :: Bool -> Maybe LogLevel -> Parser (Maybe LogLevel) logLevelOptsParser hide defLogLevel = fmap (Just . parse) (strOption ( long "verbosity" <> metavar "VERBOSITY" <> completeWith ["silent", "error", "warn", "info", "debug"] <> help "Verbosity: silent, error, warn, info, debug" <> hideMods hide )) <|> flag' (Just verboseLevel) ( short 'v' <> long "verbose" <> help ( "Enable verbose mode: verbosity level \"" <> showLevel verboseLevel <> "\"" ) <> hideMods hide ) <|> flag' (Just silentLevel) ( long "silent" <> help ( "Enable silent mode: verbosity level \"" <> showLevel silentLevel <> "\"" ) <> hideMods hide ) <|> pure defLogLevel where verboseLevel = LevelDebug silentLevel = LevelOther "silent" showLevel l = case l of LevelDebug -> "debug" LevelInfo -> "info" LevelWarn -> "warn" LevelError -> "error" LevelOther x -> T.unpack x parse s = case s of "debug" -> LevelDebug "info" -> LevelInfo "warn" -> LevelWarn "error" -> LevelError _ -> LevelOther (T.pack s) stack-2.9.3.1/src/Stack/Options/NewParser.hs0000644000000000000000000000272114445022466016721 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.NewParser ( newOptsParser ) where import qualified Data.Map.Strict as M import Options.Applicative import Stack.Init import Stack.New import Stack.Options.GlobalParser import Stack.Prelude import Stack.Types.PackageName import Stack.Types.TemplateName -- | Parser for @stack new@. newOptsParser :: Parser (NewOpts,InitOpts) newOptsParser = (,) <$> newOpts <*> initOptsParser where newOpts = NewOpts <$> packageNameArgument ( metavar "PACKAGE_NAME" <> help "A valid package name." ) <*> switch ( long "bare" <> help "Do not create a subdirectory for the project" ) <*> optional (templateNameArgument ( metavar "TEMPLATE_NAME" <> help "Name of a template - can take the form\ \ [[service:]username/]template with optional service name\ \ (github, gitlab, or bitbucket) and username for the \ \service; or, a local filename such as foo.hsfiles or ~/foo; \ \or, a full URL such as https://example.com/foo.hsfiles." )) <*> fmap M.fromList (many (templateParamArgument ( short 'p' <> long "param" <> metavar "KEY:VALUE" <> help "Parameter for the template in the format key:value" ))) stack-2.9.3.1/src/Stack/Options/NixParser.hs0000644000000000000000000000415014445022466016724 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.NixParser ( nixOptsParser ) where import qualified Data.Text as T import Options.Applicative import Options.Applicative.Args import Options.Applicative.Builder.Extra import Stack.Nix import Stack.Options.Utils import Stack.Prelude import Stack.Types.Nix nixOptsParser :: Bool -> Parser NixOptsMonoid nixOptsParser hide0 = overrideActivation <$> ( NixOptsMonoid <$> firstBoolFlagsNoDefault nixCmdName "use of a Nix-shell. Implies 'system-ghc: true'" hide <*> firstBoolFlagsNoDefault "nix-pure" "use of a pure Nix-shell. Implies '--nix' and 'system-ghc: true'" hide <*> optionalFirst (textArgsOption ( long "nix-packages" <> metavar "NAMES" <> help "List of packages that should be available in the nix-shell \ \(space separated)" <> hide )) <*> optionalFirst (option str ( long "nix-shell-file" <> metavar "FILE" <> completer (fileExtCompleter [".nix"]) <> help "Nix file to be used to launch a nix-shell (for regular Nix \ \users)" <> hide )) <*> optionalFirst (textArgsOption ( long "nix-shell-options" <> metavar "OPTIONS" <> help "Additional options passed to nix-shell" <> hide )) <*> optionalFirst (textArgsOption ( long "nix-path" <> metavar "PATH_OPTIONS" <> help "Additional options to override NIX_PATH parts (notably \ \'nixpkgs')" <> hide )) <*> firstBoolFlagsFalse "nix-add-gc-roots" "addition of packages to the nix GC roots so nix-collect-garbage doesn't remove them" hide ) where hide = hideMods hide0 overrideActivation m = if fromFirst False (nixMonoidPureShell m) then m { nixMonoidEnable = (First . Just . fromFirst True) (nixMonoidEnable m) } else m textArgsOption = fmap (map T.pack) . argsOption stack-2.9.3.1/src/Stack/Options/PackageParser.hs0000644000000000000000000000221114445022466017515 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.PackageParser ( readFlag ) where import qualified Data.Map as Map import Options.Applicative ( ReadM, readerError ) import Options.Applicative.Types ( readerAsk ) import Stack.Prelude import Stack.Types.Config.Build ( ApplyCLIFlag (..) ) -- | Parser for package:[-]flag readFlag :: ReadM (Map ApplyCLIFlag (Map FlagName Bool)) readFlag = do s <- readerAsk case break (== ':') s of (pn, ':':mflag) -> do pn' <- case parsePackageName pn of Nothing | pn == "*" -> pure ACFAllProjectPackages | otherwise -> readerError $ "Invalid package name: " ++ pn Just x -> pure $ ACFByName x let (b, flagS) = case mflag of '-':x -> (False, x) _ -> (True, mflag) flagN <- case parseFlagName flagS of Nothing -> readerError $ "Invalid flag name: " ++ flagS Just x -> pure x pure $ Map.singleton pn' $ Map.singleton flagN b _ -> readerError "Must have a colon" stack-2.9.3.1/src/Stack/Options/ResolverParser.hs0000644000000000000000000000243514445022466017773 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} module Stack.Options.ResolverParser ( abstractResolverOptsParser , compilerOptsParser , readCompilerVersion ) where import qualified Data.Text as T import Options.Applicative ( Parser, ReadM, help, long, metavar, option, readerError ) import Options.Applicative.Types ( readerAsk ) import Stack.Options.Utils ( hideMods ) import Stack.Prelude import Stack.Types.Resolver ( AbstractResolver, readAbstractResolver ) -- | Parser for the resolver abstractResolverOptsParser :: Bool -> Parser (Unresolved AbstractResolver) abstractResolverOptsParser hide = option readAbstractResolver ( long "resolver" <> metavar "RESOLVER" <> help "Override resolver in project file" <> hideMods hide ) compilerOptsParser :: Bool -> Parser WantedCompiler compilerOptsParser hide = option readCompilerVersion ( long "compiler" <> metavar "COMPILER" <> help "Use the specified compiler" <> hideMods hide ) readCompilerVersion :: ReadM WantedCompiler readCompilerVersion = do s <- readerAsk case parseWantedCompiler (T.pack s) of Left{} -> readerError $ "Failed to parse compiler: " ++ s Right x -> pure x stack-2.9.3.1/src/Stack/Options/ScriptParser.hs0000644000000000000000000000460714445022466017441 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.ScriptParser ( ScriptExecute (..) , ScriptOpts (..) , ShouldRun (..) , scriptOptsParser ) where import Options.Applicative ( Parser, completer, eitherReader, flag', help, long , metavar, option, strArgument, strOption ) import Options.Applicative.Builder.Extra ( fileExtCompleter ) import Stack.Options.Completion ( ghcOptsCompleter ) import Stack.Prelude data ScriptOpts = ScriptOpts { soPackages :: ![String] , soFile :: !FilePath , soArgs :: ![String] , soCompile :: !ScriptExecute , soGhcOptions :: ![String] , soScriptExtraDeps :: ![PackageIdentifierRevision] , soShouldRun :: !ShouldRun } deriving Show data ScriptExecute = SEInterpret | SECompile | SEOptimize deriving Show data ShouldRun = YesRun | NoRun deriving Show scriptOptsParser :: Parser ScriptOpts scriptOptsParser = ScriptOpts <$> many (strOption ( long "package" <> metavar "PACKAGE" <> help "Add a package (can be specified multiple times)" )) <*> strArgument ( metavar "FILE" <> completer (fileExtCompleter [".hs", ".lhs"]) ) <*> many (strArgument ( metavar "-- ARGUMENT(S) (e.g. stack script X.hs -- argument(s) to \ \program)" )) <*> ( flag' SECompile ( long "compile" <> help "Compile the script without optimization and run the executable" ) <|> flag' SEOptimize ( long "optimize" <> help "Compile the script with optimization and run the executable" ) <|> pure SEInterpret ) <*> many (strOption ( long "ghc-options" <> metavar "OPTIONS" <> completer ghcOptsCompleter <> help "Additional options passed to GHC" )) <*> many (option extraDepRead ( long "extra-dep" <> metavar "PACKAGE-VERSION" <> help "Extra dependencies to be added to the snapshot" )) <*> ( flag' NoRun ( long "no-run" <> help "Don't run, just compile." ) <|> pure YesRun ) where extraDepRead = eitherReader $ mapLeft show . parsePackageIdentifierRevision . fromString stack-2.9.3.1/src/Stack/Options/SDistParser.hs0000644000000000000000000000173014445022466017215 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.SDistParser ( sdistOptsParser ) where import Options.Applicative import Options.Applicative.Builder.Extra import Stack.Prelude import Stack.SDist import Stack.Options.HpcReportParser ( pvpBoundsOption ) -- | Parser for arguments to `stack sdist` sdistOptsParser :: Parser SDistOpts sdistOptsParser = SDistOpts <$> many (strArgument ( metavar "DIR" <> completer dirCompleter )) <*> optional pvpBoundsOption <*> ignoreCheckSwitch <*> buildPackageOption <*> optional (strOption ( long "tar-dir" <> help "If specified, copy all the tar to this dir" )) where ignoreCheckSwitch = switch ( long "ignore-check" <> help "Do not check package for common mistakes" ) buildPackageOption = boolFlags False "test-tarball" "building of the resulting tarball" idm stack-2.9.3.1/src/Stack/Options/TestParser.hs0000644000000000000000000000266314445022466017114 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.TestParser ( testOptsParser ) where import Options.Applicative import Options.Applicative.Args import Options.Applicative.Builder.Extra import Stack.Options.Utils import Stack.Prelude import Stack.Types.Config -- | Parser for test arguments. -- FIXME hide args testOptsParser :: Bool -> Parser TestOptsMonoid testOptsParser hide0 = TestOptsMonoid <$> firstBoolFlagsTrue "rerun-tests" "running already successful tests" hide <*> fmap concat (many (argsOption ( long "test-arguments" <> long "ta" <> metavar "TEST_ARGS" <> help "Arguments passed in to the test suite program" <> hide ))) <*> optionalFirstFalse (flag' True ( long "coverage" <> help "Generate a code coverage report" <> hide )) <*> optionalFirstFalse (flag' True ( long "no-run-tests" <> help "Disable running of tests. (Tests will still be built.)" <> hide )) <*> optionalFirst (option (fmap Just auto) ( long "test-suite-timeout" <> help "Maximum test suite run time in seconds." <> hide )) <*> firstBoolFlagsTrue "tests-allow-stdin" "allow standard input in test executables" hide where hide = hideMods hide0 stack-2.9.3.1/src/Stack/Options/UploadParser.hs0000644000000000000000000000166514445022466017422 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.UploadParser ( UploadOpts (..) , UploadVariant (..) , uploadOptsParser ) where import Options.Applicative import Stack.Options.SDistParser ( sdistOptsParser ) import Stack.Prelude import Stack.SDist ( SDistOpts (..) ) data UploadOpts = UploadOpts { uoptsSDistOpts :: SDistOpts , uoptsUploadVariant :: UploadVariant -- ^ Says whether to publish the package or upload as a release candidate } data UploadVariant = Publishing -- ^ Publish the package | Candidate -- ^ Create a package candidate -- | Parser for arguments to `stack upload` uploadOptsParser :: Parser UploadOpts uploadOptsParser = UploadOpts <$> sdistOptsParser <*> uploadVariant where uploadVariant = flag Publishing Candidate (long "candidate" <> help "Upload as a package candidate") stack-2.9.3.1/src/Stack/Options/Utils.hs0000644000000000000000000000165514353310533016111 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Options.Utils ( GlobalOptsContext (..) , hideMods ) where import Options.Applicative ( Mod, hidden, idm, internal ) import Stack.Prelude -- | If argument is True, hides the option from usage and help hideMods :: Bool -> Mod f a hideMods hide = if hide then internal <> hidden else idm -- | Allows adjust global options depending on their context -- Note: This was being used to remove ambiguity between the local and global -- implementation of stack init --resolver option. Now that stack init has no -- local --resolver this is not being used anymore but the code is kept for any -- similar future use cases. data GlobalOptsContext = OuterGlobalOpts -- ^ Global options before subcommand name | OtherCmdGlobalOpts -- ^ Global options following any other subcommand | BuildCmdGlobalOpts | GhciCmdGlobalOpts deriving (Eq, Show) stack-2.9.3.1/src/Stack/Package.hs0000644000000000000000000010415214445022466014714 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Dealing with Cabal. module Stack.Package ( readDotBuildinfo , resolvePackage , packageFromPackageDescription , Package (..) , PackageDescriptionPair (..) , GetPackageOpts (..) , PackageConfig (..) , buildLogPath , PackageException (..) , resolvePackageDescription , packageDependencies , applyForceCustomBuild ) where import Data.List ( unzip ) import qualified Data.Map.Strict as M import qualified Data.Set as S import qualified Data.Text as T import Distribution.CabalSpecVersion import Distribution.Compiler import Distribution.Package hiding ( Package, packageName, packageVersion, PackageIdentifier ) import Distribution.PackageDescription hiding ( FlagName ) #if !MIN_VERSION_Cabal(3,8,1) import Distribution.PackageDescription.Parsec #endif import Distribution.Pretty ( prettyShow ) #if MIN_VERSION_Cabal(3,8,1) import Distribution.Simple.PackageDescription ( readHookedBuildInfo ) #endif import Distribution.System ( OS (..), Arch, Platform (..) ) import Distribution.Text ( display ) import qualified Distribution.Types.CondTree as Cabal import qualified Distribution.Types.ExeDependency as Cabal import qualified Distribution.Types.LegacyExeDependency as Cabal import Distribution.Types.MungedPackageName import qualified Distribution.Types.UnqualComponentName as Cabal import Distribution.Utils.Path ( getSymbolicPath ) import Distribution.Verbosity ( silent ) import Distribution.Version ( mkVersion, orLaterVersion, anyVersion ) import Path as FL hiding ( replaceExtension ) import Path.Extra import Path.IO hiding ( findFiles ) import Stack.Build.Installed import Stack.Constants import Stack.Constants.Config import Stack.Prelude hiding ( Display (..) ) import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.Version import System.FilePath ( replaceExtension ) import Stack.Types.Dependency ( DepValue (..), DepType (..) ) import Stack.Types.PackageFile ( GetPackageFileContext (..), DotCabalPath , GetPackageFiles (..) ) import Stack.PackageFile ( packageDescModulesAndFiles ) import Stack.ComponentFile -- | Read @.buildinfo@ ancillary files produced by some Setup.hs hooks. -- The file includes Cabal file syntax to be merged into the package description -- derived from the package's Cabal file. -- -- NOTE: not to be confused with BuildInfo, an Stack-internal datatype. readDotBuildinfo :: MonadIO m => Path Abs File -> m HookedBuildInfo readDotBuildinfo buildinfofp = liftIO $ readHookedBuildInfo silent (toFilePath buildinfofp) -- | Resolve a parsed Cabal file into a 'Package', which contains all of -- the info needed for Stack to build the 'Package' given the current -- configuration. resolvePackage :: PackageConfig -> GenericPackageDescription -> Package resolvePackage packageConfig gpkg = packageFromPackageDescription packageConfig (genPackageFlags gpkg) (resolvePackageDescription packageConfig gpkg) packageFromPackageDescription :: PackageConfig -> [PackageFlag] -> PackageDescriptionPair -> Package packageFromPackageDescription packageConfig pkgFlags (PackageDescriptionPair pkgNoMod pkg) = Package { packageName = name , packageVersion = pkgVersion pkgId , packageLicense = licenseRaw pkg , packageDeps = deps , packageFiles = pkgFiles , packageUnknownTools = unknownTools , packageGhcOptions = packageConfigGhcOptions packageConfig , packageCabalConfigOpts = packageConfigCabalConfigOpts packageConfig , packageFlags = packageConfigFlags packageConfig , packageDefaultFlags = M.fromList [(flagName flag, flagDefault flag) | flag <- pkgFlags] , packageAllDeps = M.keysSet deps , packageLibraries = let mlib = do lib <- library pkg guard $ buildable $ libBuildInfo lib Just lib in case mlib of Nothing -> NoLibraries Just _ -> HasLibraries foreignLibNames , packageInternalLibraries = subLibNames , packageTests = M.fromList [(T.pack (Cabal.unUnqualComponentName $ testName t), testInterface t) | t <- testSuites pkgNoMod , buildable (testBuildInfo t) ] , packageBenchmarks = S.fromList [T.pack (Cabal.unUnqualComponentName $ benchmarkName b) | b <- benchmarks pkgNoMod , buildable (benchmarkBuildInfo b) ] -- Same comment about buildable applies here too. , packageExes = S.fromList [T.pack (Cabal.unUnqualComponentName $ exeName biBuildInfo) | biBuildInfo <- executables pkg , buildable (buildInfo biBuildInfo)] -- This is an action used to collect info needed for "stack ghci". -- This info isn't usually needed, so computation of it is deferred. , packageOpts = GetPackageOpts $ \installMap installedMap omitPkgs addPkgs cabalfp -> do (componentsModules,componentFiles,_,_) <- getPackageFiles pkgFiles cabalfp let internals = S.toList $ internalLibComponents $ M.keysSet componentsModules excludedInternals <- mapM (parsePackageNameThrowing . T.unpack) internals mungedInternals <- mapM (parsePackageNameThrowing . T.unpack . toInternalPackageMungedName) internals componentsOpts <- generatePkgDescOpts installMap installedMap (excludedInternals ++ omitPkgs) (mungedInternals ++ addPkgs) cabalfp pkg componentFiles pure (componentsModules,componentFiles,componentsOpts) , packageHasExposedModules = maybe False (not . null . exposedModules) (library pkg) , packageBuildType = buildType pkg , packageSetupDeps = msetupDeps , packageCabalSpec = specVersion pkg } where extraLibNames = S.union subLibNames foreignLibNames subLibNames = S.fromList $ map (T.pack . Cabal.unUnqualComponentName) $ mapMaybe (libraryNameString . libName) -- this is a design bug in the Cabal API: this should statically be known to exist $ filter (buildable . libBuildInfo) $ subLibraries pkg foreignLibNames = S.fromList $ map (T.pack . Cabal.unUnqualComponentName . foreignLibName) $ filter (buildable . foreignLibBuildInfo) $ foreignLibs pkg toInternalPackageMungedName = T.pack . prettyShow . MungedPackageName (pkgName pkgId) . maybeToLibraryName . Just . Cabal.mkUnqualComponentName . T.unpack -- Gets all of the modules, files, build files, and data files that -- constitute the package. This is primarily used for dirtiness -- checking during build, as well as use by "stack ghci" pkgFiles = GetPackageFiles $ \cabalfp -> debugBracket ("getPackageFiles" <+> pretty cabalfp) $ do let pkgDir = parent cabalfp distDir <- distDirFromDir pkgDir bc <- view buildConfigL cabalVer <- view cabalVersionL (componentModules,componentFiles,dataFiles',warnings) <- runRIO (GetPackageFileContext cabalfp distDir bc cabalVer) (packageDescModulesAndFiles pkg) setupFiles <- if buildType pkg == Custom then do let setupHsPath = pkgDir relFileSetupHs setupLhsPath = pkgDir relFileSetupLhs setupHsExists <- doesFileExist setupHsPath if setupHsExists then pure (S.singleton setupHsPath) else do setupLhsExists <- doesFileExist setupLhsPath if setupLhsExists then pure (S.singleton setupLhsPath) else pure S.empty else pure S.empty buildFiles <- liftM (S.insert cabalfp . S.union setupFiles) $ do let hpackPath = pkgDir relFileHpackPackageConfig hpackExists <- doesFileExist hpackPath pure $ if hpackExists then S.singleton hpackPath else S.empty pure (componentModules, componentFiles, buildFiles <> dataFiles', warnings) pkgId = package pkg name = pkgName pkgId (unknownTools, knownTools) = packageDescTools pkg deps = M.filterWithKey (const . not . isMe) (M.unionsWith (<>) [ asLibrary <$> packageDependencies packageConfig pkg -- We include all custom-setup deps - if present - in the -- package deps themselves. Stack always works with the -- invariant that there will be a single installed package -- relating to a package name, and this applies at the setup -- dependency level as well. , asLibrary <$> fromMaybe M.empty msetupDeps , knownTools ]) msetupDeps = fmap (M.fromList . map (depPkgName &&& depVerRange) . setupDepends) (setupBuildInfo pkg) asLibrary range = DepValue { dvVersionRange = range , dvType = AsLibrary } -- Is the package dependency mentioned here me: either the package -- name itself, or the name of one of the sub libraries isMe name' = name' == name || fromString (packageNameString name') `S.member` extraLibNames -- | Generate GHC options for the package's components, and a list of -- options which apply generally to the package, not one specific -- component. generatePkgDescOpts :: (HasEnvConfig env, MonadThrow m, MonadReader env m, MonadIO m) => InstallMap -> InstalledMap -> [PackageName] -- ^ Packages to omit from the "-package" / "-package-id" flags -> [PackageName] -- ^ Packages to add to the "-package" flags -> Path Abs File -> PackageDescription -> Map NamedComponent [DotCabalPath] -> m (Map NamedComponent BuildInfoOpts) generatePkgDescOpts installMap installedMap omitPkgs addPkgs cabalfp pkg componentPaths = do config <- view configL cabalVer <- view cabalVersionL distDir <- distDirFromDir cabalDir let generate namedComponent binfo = ( namedComponent , generateBuildInfoOpts BioInput { biInstallMap = installMap , biInstalledMap = installedMap , biCabalDir = cabalDir , biDistDir = distDir , biOmitPackages = omitPkgs , biAddPackages = addPkgs , biBuildInfo = binfo , biDotCabalPaths = fromMaybe [] (M.lookup namedComponent componentPaths) , biConfigLibDirs = configExtraLibDirs config , biConfigIncludeDirs = configExtraIncludeDirs config , biComponentName = namedComponent , biCabalVersion = cabalVer } ) pure ( M.fromList (concat [ maybe [] (pure . generate CLib . libBuildInfo) (library pkg) , mapMaybe (\sublib -> do let maybeLib = CInternalLib . T.pack . Cabal.unUnqualComponentName <$> (libraryNameString . libName) sublib flip generate (libBuildInfo sublib) <$> maybeLib ) (subLibraries pkg) , fmap (\exe -> generate (CExe (T.pack (Cabal.unUnqualComponentName (exeName exe)))) (buildInfo exe)) (executables pkg) , fmap (\bench -> generate (CBench (T.pack (Cabal.unUnqualComponentName (benchmarkName bench)))) (benchmarkBuildInfo bench)) (benchmarks pkg) , fmap (\test -> generate (CTest (T.pack (Cabal.unUnqualComponentName (testName test)))) (testBuildInfo test)) (testSuites pkg)])) where cabalDir = parent cabalfp -- | Input to 'generateBuildInfoOpts' data BioInput = BioInput { biInstallMap :: !InstallMap , biInstalledMap :: !InstalledMap , biCabalDir :: !(Path Abs Dir) , biDistDir :: !(Path Abs Dir) , biOmitPackages :: ![PackageName] , biAddPackages :: ![PackageName] , biBuildInfo :: !BuildInfo , biDotCabalPaths :: ![DotCabalPath] , biConfigLibDirs :: ![FilePath] , biConfigIncludeDirs :: ![FilePath] , biComponentName :: !NamedComponent , biCabalVersion :: !Version } -- | Generate GHC options for the target. Since Cabal also figures out -- these options, currently this is only used for invoking GHCI (via -- stack ghci). generateBuildInfoOpts :: BioInput -> BuildInfoOpts generateBuildInfoOpts BioInput {..} = BuildInfoOpts { bioOpts = ghcOpts ++ fmap ("-optP" <>) (cppOptions biBuildInfo) -- NOTE for future changes: Due to this use of nubOrd (and other uses -- downstream), these generated options must not rely on multiple -- argument sequences. For example, ["--main-is", "Foo.hs", "--main- -- is", "Bar.hs"] would potentially break due to the duplicate -- "--main-is" being removed. -- -- See https://github.com/commercialhaskell/stack/issues/1255 , bioOneWordOpts = nubOrd $ concat [extOpts, srcOpts, includeOpts, libOpts, fworks, cObjectFiles] , bioPackageFlags = deps , bioCabalMacros = componentAutogen relFileCabalMacrosH } where cObjectFiles = mapMaybe (fmap toFilePath . makeObjectFilePathFromC biCabalDir biComponentName biDistDir) cfiles cfiles = mapMaybe dotCabalCFilePath biDotCabalPaths installVersion = snd -- Generates: -package=base -package=base16-bytestring-0.1.1.6 ... deps = concat [ case M.lookup name biInstalledMap of Just (_, Stack.Types.Package.Library _ident ipid _) -> ["-package-id=" <> ghcPkgIdString ipid] _ -> ["-package=" <> packageNameString name <> maybe "" -- This empty case applies to e.g. base. ((("-" <>) . versionString) . installVersion) (M.lookup name biInstallMap)] | name <- pkgs] pkgs = biAddPackages ++ [ name | Dependency name _ _ <- targetBuildDepends biBuildInfo -- TODO: cabal 3 introduced multiple public libraries in a single dependency , name `notElem` biOmitPackages] PerCompilerFlavor ghcOpts _ = options biBuildInfo extOpts = map (("-X" ++) . display) (usedExtensions biBuildInfo) srcOpts = map (("-i" <>) . toFilePathNoTrailingSep) (concat [ [ componentBuildDir biCabalVersion biComponentName biDistDir ] , [ biCabalDir | null (hsSourceDirs biBuildInfo) ] , mapMaybe (toIncludeDir . getSymbolicPath) (hsSourceDirs biBuildInfo) , [ componentAutogen ] , maybeToList (packageAutogenDir biCabalVersion biDistDir) , [ componentOutputDir biComponentName biDistDir ] ]) ++ [ "-stubdir=" ++ toFilePathNoTrailingSep (buildDir biDistDir) ] componentAutogen = componentAutogenDir biCabalVersion biComponentName biDistDir toIncludeDir "." = Just biCabalDir toIncludeDir relDir = concatAndCollapseAbsDir biCabalDir relDir includeOpts = map ("-I" <>) (biConfigIncludeDirs <> pkgIncludeOpts) pkgIncludeOpts = [ toFilePathNoTrailingSep absDir | dir <- includeDirs biBuildInfo , absDir <- handleDir dir ] libOpts = map ("-l" <>) (extraLibs biBuildInfo) <> map ("-L" <>) (biConfigLibDirs <> pkgLibDirs) pkgLibDirs = [ toFilePathNoTrailingSep absDir | dir <- extraLibDirs biBuildInfo , absDir <- handleDir dir ] handleDir dir = case (parseAbsDir dir, parseRelDir dir) of (Just ab, _ ) -> [ab] (_ , Just rel) -> [biCabalDir rel] (Nothing, Nothing ) -> [] fworks = map (\fwk -> "-framework=" <> fwk) (frameworks biBuildInfo) -- | Make the .o path from the .c file path for a component. Example: -- -- @ -- executable FOO -- c-sources: cbits/text_search.c -- @ -- -- Produces -- -- /build/FOO/FOO-tmp/cbits/text_search.o -- -- Example: -- -- λ> makeObjectFilePathFromC -- $(mkAbsDir "/Users/chris/Repos/hoogle") -- CLib -- $(mkAbsDir "/Users/chris/Repos/hoogle/.stack-work/Cabal-x.x.x/dist") -- $(mkAbsFile "/Users/chris/Repos/hoogle/cbits/text_search.c") -- Just "/Users/chris/Repos/hoogle/.stack-work/Cabal-x.x.x/dist/build/cbits/text_search.o" -- λ> makeObjectFilePathFromC -- $(mkAbsDir "/Users/chris/Repos/hoogle") -- (CExe "hoogle") -- $(mkAbsDir "/Users/chris/Repos/hoogle/.stack-work/Cabal-x.x.x/dist") -- $(mkAbsFile "/Users/chris/Repos/hoogle/cbits/text_search.c") -- Just "/Users/chris/Repos/hoogle/.stack-work/Cabal-x.x.x/dist/build/hoogle/hoogle-tmp/cbits/text_search.o" -- λ> makeObjectFilePathFromC :: MonadThrow m => Path Abs Dir -- ^ The cabal directory. -> NamedComponent -- ^ The name of the component. -> Path Abs Dir -- ^ Dist directory. -> Path Abs File -- ^ The path to the .c file. -> m (Path Abs File) -- ^ The path to the .o file for the component. makeObjectFilePathFromC cabalDir namedComponent distDir cFilePath = do relCFilePath <- stripProperPrefix cabalDir cFilePath relOFilePath <- parseRelFile (replaceExtension (toFilePath relCFilePath) "o") pure (componentOutputDir namedComponent distDir relOFilePath) -- | Get all dependencies of the package (buildable targets only). -- -- Note that for Cabal versions 1.22 and earlier, there is a bug where -- Cabal requires dependencies for non-buildable components to be -- present. We're going to use GHC version as a proxy for Cabal -- library version in this case for simplicity, so we'll check for GHC -- being 7.10 or earlier. This obviously makes our function a lot more -- fun to write... packageDependencies :: PackageConfig -> PackageDescription -> Map PackageName VersionRange packageDependencies pkgConfig pkg' = M.fromListWith intersectVersionRanges $ map (depPkgName &&& depVerRange) $ concatMap targetBuildDepends (allBuildInfo' pkg) ++ maybe [] setupDepends (setupBuildInfo pkg) where pkg | getGhcVersion (packageConfigCompilerVersion pkgConfig) >= mkVersion [8, 0] = pkg' -- Set all components to buildable. Only need to worry about -- library, exe, test, and bench, since others didn't exist in -- older Cabal versions | otherwise = pkg' { library = (\c -> c { libBuildInfo = go (libBuildInfo c) }) <$> library pkg' , executables = (\c -> c { buildInfo = go (buildInfo c) }) <$> executables pkg' , testSuites = if packageConfigEnableTests pkgConfig then (\c -> c { testBuildInfo = go (testBuildInfo c) }) <$> testSuites pkg' else testSuites pkg' , benchmarks = if packageConfigEnableBenchmarks pkgConfig then (\c -> c { benchmarkBuildInfo = go (benchmarkBuildInfo c) }) <$> benchmarks pkg' else benchmarks pkg' } go bi = bi { buildable = True } -- | Get all dependencies of the package (buildable targets only). -- -- This uses both the new 'buildToolDepends' and old 'buildTools' -- information. packageDescTools :: PackageDescription -> (Set ExeName, Map PackageName DepValue) packageDescTools pd = (S.fromList $ concat unknowns, M.fromListWith (<>) $ concat knowns) where (unknowns, knowns) = unzip $ map perBI $ allBuildInfo' pd perBI :: BuildInfo -> ([ExeName], [(PackageName, DepValue)]) perBI bi = (unknownTools, tools) where (unknownTools, knownTools) = partitionEithers $ map go1 (buildTools bi) tools = mapMaybe go2 (knownTools ++ buildToolDepends bi) -- This is similar to desugarBuildTool from Cabal, however it -- uses our own hard-coded map which drops tools shipped with -- GHC (like hsc2hs), and includes some tools from Stackage. go1 :: Cabal.LegacyExeDependency -> Either ExeName Cabal.ExeDependency go1 (Cabal.LegacyExeDependency name range) = case M.lookup name hardCodedMap of Just pkgName -> Right $ Cabal.ExeDependency pkgName (Cabal.mkUnqualComponentName name) range Nothing -> Left $ ExeName $ T.pack name go2 :: Cabal.ExeDependency -> Maybe (PackageName, DepValue) go2 (Cabal.ExeDependency pkg _name range) | pkg `S.member` preInstalledPackages = Nothing | otherwise = Just ( pkg , DepValue { dvVersionRange = range , dvType = AsBuildTool } ) -- | A hard-coded map for tool dependencies hardCodedMap :: Map String PackageName hardCodedMap = M.fromList [ ("alex", Distribution.Package.mkPackageName "alex") , ("happy", Distribution.Package.mkPackageName "happy") , ("cpphs", Distribution.Package.mkPackageName "cpphs") , ("greencard", Distribution.Package.mkPackageName "greencard") , ("c2hs", Distribution.Package.mkPackageName "c2hs") , ("hscolour", Distribution.Package.mkPackageName "hscolour") , ("hspec-discover", Distribution.Package.mkPackageName "hspec-discover") , ("hsx2hs", Distribution.Package.mkPackageName "hsx2hs") , ("gtk2hsC2hs", Distribution.Package.mkPackageName "gtk2hs-buildtools") , ("gtk2hsHookGenerator", Distribution.Package.mkPackageName "gtk2hs-buildtools") , ("gtk2hsTypeGen", Distribution.Package.mkPackageName "gtk2hs-buildtools") ] -- | Executable-only packages which come pre-installed with GHC and do -- not need to be built. Without this exception, we would either end -- up unnecessarily rebuilding these packages, or failing because the -- packages do not appear in the Stackage snapshot. preInstalledPackages :: Set PackageName preInstalledPackages = S.fromList [ mkPackageName "hsc2hs" , mkPackageName "haddock" ] -- | Variant of 'allBuildInfo' from Cabal that, like versions before -- 2.2, only includes buildable components. allBuildInfo' :: PackageDescription -> [BuildInfo] allBuildInfo' pkg_descr = [ bi | lib <- allLibraries pkg_descr , let bi = libBuildInfo lib , buildable bi ] ++ [ bi | flib <- foreignLibs pkg_descr , let bi = foreignLibBuildInfo flib , buildable bi ] ++ [ bi | exe <- executables pkg_descr , let bi = buildInfo exe , buildable bi ] ++ [ bi | tst <- testSuites pkg_descr , let bi = testBuildInfo tst , buildable bi ] ++ [ bi | tst <- benchmarks pkg_descr , let bi = benchmarkBuildInfo tst , buildable bi ] -- | A pair of package descriptions: one which modified the buildable -- values of test suites and benchmarks depending on whether they are -- enabled, and one which does not. -- -- Fields are intentionally lazy, we may only need one or the other -- value. -- -- MSS 2017-08-29: The very presence of this data type is terribly -- ugly, it represents the fact that the Cabal 2.0 upgrade did _not_ -- go well. Specifically, we used to have a field to indicate whether -- a component was enabled in addition to buildable, but that's gone -- now, and this is an ugly proxy. We should at some point clean up -- the mess of Package, LocalPackage, etc, and probably pull in the -- definition of PackageDescription from Cabal with our additionally -- needed metadata. But this is a good enough hack for the -- moment. Odds are, you're reading this in the year 2024 and thinking -- "wtf?" data PackageDescriptionPair = PackageDescriptionPair { pdpOrigBuildable :: PackageDescription , pdpModifiedBuildable :: PackageDescription } -- | Evaluates the conditions of a 'GenericPackageDescription', yielding -- a resolved 'PackageDescription'. resolvePackageDescription :: PackageConfig -> GenericPackageDescription -> PackageDescriptionPair resolvePackageDescription packageConfig (GenericPackageDescription desc _ defaultFlags mlib subLibs foreignLibs' exes tests benches) = PackageDescriptionPair { pdpOrigBuildable = go False , pdpModifiedBuildable = go True } where go modBuildable = desc {library = fmap (resolveConditions rc updateLibDeps) mlib ,subLibraries = map (\(n, v) -> (resolveConditions rc updateLibDeps v){libName=LSubLibName n}) subLibs ,foreignLibs = map (\(n, v) -> (resolveConditions rc updateForeignLibDeps v){foreignLibName=n}) foreignLibs' ,executables = map (\(n, v) -> (resolveConditions rc updateExeDeps v){exeName=n}) exes ,testSuites = map (\(n,v) -> (resolveConditions rc (updateTestDeps modBuildable) v){testName=n}) tests ,benchmarks = map (\(n,v) -> (resolveConditions rc (updateBenchmarkDeps modBuildable) v){benchmarkName=n}) benches} flags = M.union (packageConfigFlags packageConfig) (flagMap defaultFlags) rc = mkResolveConditions (packageConfigCompilerVersion packageConfig) (packageConfigPlatform packageConfig) flags updateLibDeps lib deps = lib {libBuildInfo = (libBuildInfo lib) {targetBuildDepends = deps}} updateForeignLibDeps lib deps = lib {foreignLibBuildInfo = (foreignLibBuildInfo lib) {targetBuildDepends = deps}} updateExeDeps exe deps = exe {buildInfo = (buildInfo exe) {targetBuildDepends = deps}} -- Note that, prior to moving to Cabal 2.0, we would set -- testEnabled/benchmarkEnabled here. These fields no longer -- exist, so we modify buildable instead here. The only -- wrinkle in the Cabal 2.0 story is -- https://github.com/haskell/cabal/issues/1725, where older -- versions of Cabal (which may be used for actually building -- code) don't properly exclude build-depends for -- non-buildable components. Testing indicates that everything -- is working fine, and that this comment can be completely -- ignored. I'm leaving the comment anyway in case something -- breaks and you, poor reader, are investigating. updateTestDeps modBuildable test deps = let bi = testBuildInfo test bi' = bi { targetBuildDepends = deps , buildable = buildable bi && (if modBuildable then packageConfigEnableTests packageConfig else True) } in test { testBuildInfo = bi' } updateBenchmarkDeps modBuildable benchmark deps = let bi = benchmarkBuildInfo benchmark bi' = bi { targetBuildDepends = deps , buildable = buildable bi && (if modBuildable then packageConfigEnableBenchmarks packageConfig else True) } in benchmark { benchmarkBuildInfo = bi' } -- | Make a map from a list of flag specifications. -- -- What is @flagManual@ for? flagMap :: [PackageFlag] -> Map FlagName Bool flagMap = M.fromList . map pair where pair :: PackageFlag -> (FlagName, Bool) pair = flagName &&& flagDefault data ResolveConditions = ResolveConditions { rcFlags :: Map FlagName Bool , rcCompilerVersion :: ActualCompiler , rcOS :: OS , rcArch :: Arch } -- | Generic a @ResolveConditions@ using sensible defaults. mkResolveConditions :: ActualCompiler -- ^ Compiler version -> Platform -- ^ installation target platform -> Map FlagName Bool -- ^ enabled flags -> ResolveConditions mkResolveConditions compilerVersion (Platform arch os) flags = ResolveConditions { rcFlags = flags , rcCompilerVersion = compilerVersion , rcOS = os , rcArch = arch } -- | Resolve the condition tree for the library. resolveConditions :: (Semigroup target,Monoid target,Show target) => ResolveConditions -> (target -> cs -> target) -> CondTree ConfVar cs target -> target resolveConditions rc addDeps (CondNode lib deps cs) = basic <> children where basic = addDeps lib deps children = mconcat (map apply cs) where apply (Cabal.CondBranch cond node mcs) = if condSatisfied cond then resolveConditions rc addDeps node else maybe mempty (resolveConditions rc addDeps) mcs condSatisfied c = case c of Var v -> varSatisfied v Lit b -> b CNot c' -> not (condSatisfied c') COr cx cy -> condSatisfied cx || condSatisfied cy CAnd cx cy -> condSatisfied cx && condSatisfied cy varSatisfied v = case v of OS os -> os == rcOS rc Arch arch -> arch == rcArch rc PackageFlag flag -> fromMaybe False $ M.lookup flag (rcFlags rc) -- NOTE: ^^^^^ This should never happen, as all flags -- which are used must be declared. Defaulting to -- False. Impl flavor range -> case (flavor, rcCompilerVersion rc) of (GHC, ACGhc vghc) -> vghc `withinRange` range _ -> False -- | Path for the package's build log. buildLogPath :: (MonadReader env m, HasBuildConfig env, MonadThrow m) => Package -> Maybe String -> m (Path Abs File) buildLogPath package' msuffix = do env <- ask let stack = getProjectWorkDir env fp <- parseRelFile $ concat $ packageIdentifierString (packageIdentifier package') : maybe id (\suffix -> ("-" :) . (suffix :)) msuffix [".log"] pure $ stack relDirLogs fp {- FIXME -- | Create a 'ProjectPackage' from a directory containing a package. mkProjectPackage :: forall env. (HasPantryConfig env, HasLogFunc env, HasProcessContext env) => PrintWarnings -> ResolvedPath Dir -> RIO env ProjectPackage mkProjectPackage printWarnings dir = do (gpd, name, cabalfp) <- loadCabalFilePath (resolvedAbsolute dir) pure ProjectPackage { ppCabalFP = cabalfp , ppGPD' = gpd printWarnings , ppResolvedDir = dir , ppName = name } -- | Create a 'DepPackage' from a 'PackageLocation' mkDepPackage :: forall env. (HasPantryConfig env, HasLogFunc env, HasProcessContext env) => PackageLocation -> RIO env DepPackage mkDepPackage pl = do (name, gpdio) <- case pl of PLMutable dir -> do (gpdio, name, _cabalfp) <- loadCabalFilePath (resolvedAbsolute dir) pure (name, gpdio NoPrintWarnings) PLImmutable pli -> do PackageIdentifier name _ <- getPackageLocationIdent pli run <- askRunInIO pure (name, run $ loadCabalFileImmutable pli) pure DepPackage { dpGPD' = gpdio , dpLocation = pl , dpName = name } -} -- | Force a package to be treated as a custom build type, see -- applyForceCustomBuild :: Version -- ^ global Cabal version -> Package -> Package applyForceCustomBuild cabalVersion package | forceCustomBuild = package { packageBuildType = Custom , packageDeps = M.insertWith (<>) "Cabal" (DepValue cabalVersionRange AsLibrary) $ packageDeps package , packageSetupDeps = Just $ M.fromList [ ("Cabal", cabalVersionRange) , ("base", anyVersion) ] } | otherwise = package where cabalVersionRange = orLaterVersion $ mkVersion $ cabalSpecToVersionDigits $ packageCabalSpec package forceCustomBuild = packageBuildType package == Simple && not (cabalVersion `withinRange` cabalVersionRange) stack-2.9.3.1/src/Stack/PackageDump.hs0000644000000000000000000003037014445022466015542 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} module Stack.PackageDump ( Line , eachSection , eachPair , DumpPackage (..) , conduitDumpPackage , ghcPkgDump , ghcPkgDescribe , sinkMatching , pruneDeps ) where import Data.Attoparsec.Args import Data.Attoparsec.Text as P import Data.Conduit import qualified Data.Conduit.List as CL import qualified Data.Conduit.Text as CT import qualified Data.Map as Map import qualified Data.Set as Set import qualified Distribution.Text as C import Path.Extra ( toFilePathNoTrailingSep ) import RIO.Process hiding ( readProcess ) import qualified RIO.Text as T import Stack.GhcPkg import Stack.Prelude import Stack.Types.Config ( HasCompiler (..), GhcPkgExe (..), DumpPackage (..) ) import Stack.Types.GhcPkgId -- | Type representing exceptions thrown by functions exported by the -- "Stack.PackageDump" module. data PackageDumpException = MissingSingleField Text (Map Text [Line]) | Couldn'tParseField Text [Line] deriving (Show, Typeable) instance Exception PackageDumpException where displayException (MissingSingleField name values) = unlines $ concat [ "Error: [S-4257]\n" , "Expected single value for field name " , show name , " when parsing ghc-pkg dump output:" ] : map (\(k, v) -> " " ++ show (k, v)) (Map.toList values) displayException (Couldn'tParseField name ls) = concat [ "Error: [S-2016]\n" , "Couldn't parse the field " , show name , " from lines: " , show ls , "." ] -- | Call ghc-pkg dump with appropriate flags and stream to the given @Sink@, for a single database ghcPkgDump :: (HasProcessContext env, HasLogFunc env) => GhcPkgExe -> [Path Abs Dir] -- ^ if empty, use global -> ConduitM Text Void (RIO env) a -> RIO env a ghcPkgDump pkgexe = ghcPkgCmdArgs pkgexe ["dump"] -- | Call ghc-pkg describe with appropriate flags and stream to the given @Sink@, for a single database ghcPkgDescribe :: (HasProcessContext env, HasLogFunc env, HasCompiler env) => GhcPkgExe -> PackageName -> [Path Abs Dir] -- ^ if empty, use global -> ConduitM Text Void (RIO env) a -> RIO env a ghcPkgDescribe pkgexe pkgName' = ghcPkgCmdArgs pkgexe ["describe", "--simple-output", packageNameString pkgName'] -- | Call ghc-pkg and stream to the given @Sink@, for a single database ghcPkgCmdArgs :: (HasProcessContext env, HasLogFunc env) => GhcPkgExe -> [String] -> [Path Abs Dir] -- ^ if empty, use global -> ConduitM Text Void (RIO env) a -> RIO env a ghcPkgCmdArgs pkgexe@(GhcPkgExe pkgPath) cmd mpkgDbs sink = do case reverse mpkgDbs of (pkgDb:_) -> createDatabase pkgexe pkgDb -- TODO maybe use some retry logic instead? _ -> pure () -- https://github.com/haskell/process/issues/251 snd <$> sinkProcessStderrStdout (toFilePath pkgPath) args CL.sinkNull sink' where args = concat [ case mpkgDbs of [] -> ["--global", "--no-user-package-db"] _ -> ["--user", "--no-user-package-db"] ++ concatMap (\pkgDb -> ["--package-db", toFilePathNoTrailingSep pkgDb]) mpkgDbs , cmd , ["--expand-pkgroot"] ] sink' = CT.decodeUtf8 .| sink -- | Prune a list of possible packages down to those whose dependencies are met. -- -- * id uniquely identifies an item -- -- * There can be multiple items per name pruneDeps :: (Ord name, Ord id) => (id -> name) -- ^ extract the name from an id -> (item -> id) -- ^ the id of an item -> (item -> [id]) -- ^ get the dependencies of an item -> (item -> item -> item) -- ^ choose the desired of two possible items -> [item] -- ^ input items -> Map name item pruneDeps getName getId getDepends chooseBest = Map.fromList . fmap (getName . getId &&& id) . loop Set.empty Set.empty [] where loop foundIds usedNames foundItems dps = case partitionEithers $ map depsMet dps of ([], _) -> foundItems (s', dps') -> let foundIds' = Map.fromListWith chooseBest s' foundIds'' = Set.fromList $ map getId $ Map.elems foundIds' usedNames' = Map.keysSet foundIds' foundItems' = Map.elems foundIds' in loop (Set.union foundIds foundIds'') (Set.union usedNames usedNames') (foundItems ++ foundItems') (catMaybes dps') where depsMet dp | name `Set.member` usedNames = Right Nothing | all (`Set.member` foundIds) (getDepends dp) = Left (name, dp) | otherwise = Right $ Just dp where id' = getId dp name = getName id' -- | Find the package IDs matching the given constraints with all dependencies installed. -- Packages not mentioned in the provided @Map@ are allowed to be present too. sinkMatching :: Monad m => Map PackageName Version -- ^ allowed versions -> ConduitM DumpPackage o m (Map PackageName DumpPackage) sinkMatching allowed = Map.fromList . map (pkgName . dpPackageIdent &&& id) . Map.elems . pruneDeps id dpGhcPkgId dpDepends const -- Could consider a better comparison in the future <$> (CL.filter (isAllowed . dpPackageIdent) .| CL.consume) where isAllowed (PackageIdentifier name version) = case Map.lookup name allowed of Just version' | version /= version' -> False _ -> True -- | Convert a stream of bytes into a stream of @DumpPackage@s conduitDumpPackage :: MonadThrow m => ConduitM Text DumpPackage m () conduitDumpPackage = (.| CL.catMaybes) $ eachSection $ do pairs <- eachPair (\k -> (k, ) <$> CL.consume) .| CL.consume let m = Map.fromList pairs let parseS k = case Map.lookup k m of Just [v] -> pure v _ -> throwM $ MissingSingleField k m -- Can't fail: if not found, same as an empty list. See: -- https://github.com/commercialhaskell/stack/issues/182 parseM k = Map.findWithDefault [] k m parseDepend :: MonadThrow m => Text -> m (Maybe GhcPkgId) parseDepend "builtin_rts" = pure Nothing parseDepend bs = liftM Just $ parseGhcPkgId bs' where (bs', _builtinRts) = case stripSuffixText " builtin_rts" bs of Nothing -> case stripPrefixText "builtin_rts " bs of Nothing -> (bs, False) Just x -> (x, True) Just x -> (x, True) case Map.lookup "id" m of Just ["builtin_rts"] -> pure Nothing _ -> do name <- parseS "name" >>= parsePackageNameThrowing . T.unpack version <- parseS "version" >>= parseVersionThrowing . T.unpack ghcPkgId <- parseS "id" >>= parseGhcPkgId -- if a package has no modules, these won't exist let libDirKey = "library-dirs" libraries = parseM "hs-libraries" exposedModules = parseM "exposed-modules" exposed = parseM "exposed" license = case parseM "license" of [licenseText] -> C.simpleParse (T.unpack licenseText) _ -> Nothing depends <- mapMaybeM parseDepend $ concatMap T.words $ parseM "depends" -- Handle sublibs by recording the name of the parent library -- If name of parent library is missing, this is not a sublib. let mkParentLib n = PackageIdentifier n version parentLib = mkParentLib <$> (parseS "package-name" >>= parsePackageNameThrowing . T.unpack) let parseQuoted key = case mapM (P.parseOnly (argsParser NoEscaping)) val of Left{} -> throwM (Couldn'tParseField key val) Right dirs -> pure (concat dirs) where val = parseM key libDirPaths <- parseQuoted libDirKey haddockInterfaces <- parseQuoted "haddock-interfaces" haddockHtml <- parseQuoted "haddock-html" pure $ Just DumpPackage { dpGhcPkgId = ghcPkgId , dpPackageIdent = PackageIdentifier name version , dpParentLibIdent = parentLib , dpLicense = license , dpLibDirs = libDirPaths , dpLibraries = T.words $ T.unwords libraries , dpHasExposedModules = not (null libraries || null exposedModules) -- Strip trailing commas from ghc package exposed-modules (looks buggy to me...). -- Then try to parse the module names. , dpExposedModules = Set.fromList $ mapMaybe (C.simpleParse . T.unpack . T.dropSuffix ",") $ T.words $ T.unwords exposedModules , dpDepends = depends , dpHaddockInterfaces = haddockInterfaces , dpHaddockHtml = listToMaybe haddockHtml , dpIsExposed = exposed == ["True"] } stripPrefixText :: Text -> Text -> Maybe Text stripPrefixText x y | x `T.isPrefixOf` y = Just $ T.drop (T.length x) y | otherwise = Nothing stripSuffixText :: Text -> Text -> Maybe Text stripSuffixText x y | x `T.isSuffixOf` y = Just $ T.take (T.length y - T.length x) y | otherwise = Nothing -- | A single line of input, not including line endings type Line = Text -- | Apply the given Sink to each section of output, broken by a single line containing --- eachSection :: Monad m => ConduitM Line Void m a -> ConduitM Text a m () eachSection inner = CL.map (T.filter (/= '\r')) .| CT.lines .| start where peekText = await >>= maybe (pure Nothing) (\bs -> if T.null bs then peekText else leftover bs >> pure (Just bs)) start = peekText >>= maybe (pure ()) (const go) go = do x <- toConsumer $ takeWhileC (/= "---") .| inner yield x CL.drop 1 start -- | Grab each key/value pair eachPair :: Monad m => (Text -> ConduitM Line Void m a) -> ConduitM Line a m () eachPair inner = start where start = await >>= maybe (pure ()) start' start' bs1 = toConsumer (valSrc .| inner key) >>= yield >> start where (key, bs2) = T.break (== ':') bs1 (spaces, bs3) = T.span (== ' ') $ T.drop 1 bs2 ind = T.length key + 1 + T.length spaces valSrc | T.null bs3 = noIndent | otherwise = yield bs3 >> loopIndent ind noIndent = do mx <- await case mx of Nothing -> pure () Just bs -> do let (spaces, val) = T.span (== ' ') bs if T.length spaces == 0 then leftover val else do yield val loopIndent (T.length spaces) loopIndent i = loop where loop = await >>= maybe (pure ()) go go bs | T.length spaces == i && T.all (== ' ') spaces = yield val >> loop | otherwise = leftover bs where (spaces, val) = T.splitAt i bs -- | General purpose utility takeWhileC :: Monad m => (a -> Bool) -> ConduitM a a m () takeWhileC f = loop where loop = await >>= maybe (pure ()) go go x | f x = yield x >> loop | otherwise = leftover x stack-2.9.3.1/src/Stack/Path.hs0000644000000000000000000002370014445022466014254 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -- | Handy path information. module Stack.Path ( path , pathParser ) where import Data.List ( intercalate ) import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Options.Applicative as OA import Path ( (), parent ) import Path.Extra ( toFilePathNoTrailingSep ) import RIO.Process ( HasProcessContext (..), exeSearchPathL ) import Stack.Constants import Stack.Constants.Config import Stack.GhcPkg as GhcPkg import Stack.Prelude import Stack.Runners import Stack.Types.Config import qualified System.FilePath as FP -- | Print out useful path information in a human-readable format (and -- support others later). path :: [Text] -> RIO Runner () path keys = do let deprecated = filter ((`elem` keys) . fst) deprecatedPathKeys forM_ deprecated $ \(oldOption, newOption) -> logWarn $ "\n" <> "'--" <> display oldOption <> "' will be removed in a future release.\n" <> "Please use '--" <> display newOption <> "' instead.\n" <> "\n" let -- filter the chosen paths in flags (keys), -- or show all of them if no specific paths chosen. goodPaths = filter ( \(_, key, _) -> (null keys && key /= T.pack deprecatedStackRootOptionName) || elem key keys ) paths singlePath = length goodPaths == 1 toEither (_, k, UseHaddocks p) = Left (k, p) toEither (_, k, WithoutHaddocks p) = Right (k, p) (with, without) = partitionEithers $ map toEither goodPaths runHaddock True $ printKeys with singlePath runHaddock False $ printKeys without singlePath printKeys :: HasEnvConfig env => [(Text, PathInfo -> Text)] -> Bool -> RIO env () printKeys extractors single = do pathInfo <- fillPathInfo liftIO $ forM_ extractors $ \(key, extractPath) -> do let prefix = if single then "" else key <> ": " T.putStrLn $ prefix <> extractPath pathInfo runHaddock :: Bool -> RIO EnvConfig () -> RIO Runner () runHaddock x action = local modifyConfig $ withConfig YesReexec $ withDefaultEnvConfig action where modifyConfig = set (globalOptsL.globalOptsBuildOptsMonoidL.buildOptsMonoidHaddockL) (Just x) fillPathInfo :: HasEnvConfig env => RIO env PathInfo fillPathInfo = do -- We must use a BuildConfig from an EnvConfig to ensure that it contains the -- full environment info including GHC paths etc. piBuildConfig <- view $ envConfigL.buildConfigL -- This is the modified 'bin-path', -- including the local GHC or MSYS if not configured to operate on -- global GHC. -- It was set up in 'withBuildConfigAndLock -> withBuildConfigExt -> setupEnv'. -- So it's not the *minimal* override path. piSnapDb <- packageDatabaseDeps piLocalDb <- packageDatabaseLocal piExtraDbs <- packageDatabaseExtra piGlobalDb <- view $ compilerPathsL.to cpGlobalDB piSnapRoot <- installationRootDeps piLocalRoot <- installationRootLocal piToolsDir <- bindirCompilerTools piHoogleRoot <- hoogleRoot piDistDir <- distRelativeDir piHpcDir <- hpcReportDir piCompiler <- getCompilerPath pure PathInfo {..} pathParser :: OA.Parser [Text] pathParser = mapMaybeA ( \(desc,name,_) -> OA.flag Nothing (Just name) ( OA.long (T.unpack name) <> OA.help desc ) ) paths -- | Passed to all the path printers as a source of info. data PathInfo = PathInfo { piBuildConfig :: !BuildConfig , piSnapDb :: !(Path Abs Dir) , piLocalDb :: !(Path Abs Dir) , piGlobalDb :: !(Path Abs Dir) , piSnapRoot :: !(Path Abs Dir) , piLocalRoot :: !(Path Abs Dir) , piToolsDir :: !(Path Abs Dir) , piHoogleRoot :: !(Path Abs Dir) , piDistDir :: Path Rel Dir , piHpcDir :: !(Path Abs Dir) , piExtraDbs :: ![Path Abs Dir] , piCompiler :: !(Path Abs File) } instance HasPlatform PathInfo instance HasLogFunc PathInfo where logFuncL = configL.logFuncL instance HasRunner PathInfo where runnerL = configL.runnerL instance HasStylesUpdate PathInfo where stylesUpdateL = runnerL.stylesUpdateL instance HasTerm PathInfo where useColorL = runnerL.useColorL termWidthL = runnerL.termWidthL instance HasGHCVariant PathInfo instance HasConfig PathInfo instance HasPantryConfig PathInfo where pantryConfigL = configL.pantryConfigL instance HasProcessContext PathInfo where processContextL = configL.processContextL instance HasBuildConfig PathInfo where buildConfigL = lens piBuildConfig (\x y -> x { piBuildConfig = y }) . buildConfigL data UseHaddocks a = UseHaddocks a | WithoutHaddocks a -- | The paths of interest to a user. The first tuple string is used -- for a description that the optparse flag uses, and the second -- string as a machine-readable key and also for @--foo@ flags. The user -- can choose a specific path to list like @--stack-root@. But -- really it's mainly for the documentation aspect. -- -- When printing output we generate @PathInfo@ and pass it to the -- function to generate an appropriate string. Trailing slashes are -- removed, see #506 paths :: [(String, Text, UseHaddocks (PathInfo -> Text))] paths = [ ( "Global Stack root directory" , T.pack stackRootOptionName , WithoutHaddocks $ view (stackRootL.to toFilePathNoTrailingSep.to T.pack)) , ( "Global Stack configuration file" , T.pack stackGlobalConfigOptionName , WithoutHaddocks $ view (stackGlobalConfigL.to toFilePath.to T.pack)) , ( "Project root (derived from stack.yaml file)" , "project-root" , WithoutHaddocks $ view (projectRootL.to toFilePathNoTrailingSep.to T.pack)) , ( "Configuration location (where the stack.yaml file is)" , "config-location" , WithoutHaddocks $ view (stackYamlL.to toFilePath.to T.pack)) , ( "PATH environment variable" , "bin-path" , WithoutHaddocks $ T.pack . intercalate [FP.searchPathSeparator] . view exeSearchPathL) , ( "Install location for GHC and other core tools (see 'stack ls tools' command)" , "programs" , WithoutHaddocks $ view (configL.to configLocalPrograms.to toFilePathNoTrailingSep.to T.pack)) , ( "Compiler binary (e.g. ghc)" , "compiler-exe" , WithoutHaddocks $ T.pack . toFilePath . piCompiler ) , ( "Directory containing the compiler binary (e.g. ghc)" , "compiler-bin" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . parent . piCompiler ) , ( "Directory containing binaries specific to a particular compiler (e.g. intero)" , "compiler-tools-bin" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piToolsDir ) , ( "Directory where Stack installs executables (e.g. ~/.local/bin (Unix-like OSs) or %APPDATA%\\local\\bin (Windows))" , "local-bin" , WithoutHaddocks $ view $ configL.to configLocalBin.to toFilePathNoTrailingSep.to T.pack) , ( "Extra include directories" , "extra-include-dirs" , WithoutHaddocks $ T.intercalate ", " . map T.pack . configExtraIncludeDirs . view configL ) , ( "Extra library directories" , "extra-library-dirs" , WithoutHaddocks $ T.intercalate ", " . map T.pack . configExtraLibDirs . view configL ) , ( "Snapshot package database" , "snapshot-pkg-db" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piSnapDb ) , ( "Local project package database" , "local-pkg-db" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piLocalDb ) , ( "Global package database" , "global-pkg-db" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piGlobalDb ) , ( "GHC_PACKAGE_PATH environment variable" , "ghc-package-path" , WithoutHaddocks $ \pi' -> mkGhcPackagePath True (piLocalDb pi') (piSnapDb pi') (piExtraDbs pi') (piGlobalDb pi') ) , ( "Snapshot installation root" , "snapshot-install-root" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piSnapRoot ) , ( "Local project installation root" , "local-install-root" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piLocalRoot ) , ( "Snapshot documentation root" , "snapshot-doc-root" , UseHaddocks $ \pi' -> T.pack (toFilePathNoTrailingSep (piSnapRoot pi' docDirSuffix)) ) , ( "Local project documentation root" , "local-doc-root" , UseHaddocks $ \pi' -> T.pack (toFilePathNoTrailingSep (piLocalRoot pi' docDirSuffix)) ) , ( "Local project documentation root" , "local-hoogle-root" , UseHaddocks $ T.pack . toFilePathNoTrailingSep . piHoogleRoot) , ( "Dist work directory, relative to package directory" , "dist-dir" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piDistDir ) , ( "Where HPC reports and tix files are stored" , "local-hpc-root" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . piHpcDir ) , ( "DEPRECATED: Use '--local-bin' instead" , "local-bin-path" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . configLocalBin . view configL ) , ( "DEPRECATED: Use '--programs' instead" , "ghc-paths" , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . configLocalPrograms . view configL ) , ( "DEPRECATED: Use '--" <> stackRootOptionName <> "' instead" , T.pack deprecatedStackRootOptionName , WithoutHaddocks $ T.pack . toFilePathNoTrailingSep . view stackRootL ) ] deprecatedPathKeys :: [(Text, Text)] deprecatedPathKeys = [ (T.pack deprecatedStackRootOptionName, T.pack stackRootOptionName) , ("ghc-paths", "programs") , ("local-bin-path", "local-bin") ] stack-2.9.3.1/src/Stack/Prelude.hs0000644000000000000000000002734014445022466014764 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Stack.Prelude ( withSystemTempDir , withKeepSystemTempDir , sinkProcessStderrStdout , sinkProcessStdout , logProcessStderrStdout , readProcessNull , withProcessContext , stripCR , prompt , promptPassword , promptBool , stackProgName , stackProgName' , FirstTrue (..) , fromFirstTrue , defaultFirstTrue , FirstFalse (..) , fromFirstFalse , defaultFirstFalse , writeBinaryFileAtomic , bugReport , bugPrettyReport , blankLine , module X -- * Re-exports from the rio-pretty print package , HasStylesUpdate (..) , HasTerm (..) , Pretty (..) , PrettyException (..) , PrettyRawSnapshotLocation (..) , StyleDoc , Style (..) , StyleSpec , StylesUpdate (..) , (<+>) , align , bulletedList , debugBracket , defaultStyles , encloseSep , fillSep , flow , hang , hcat , hsep , indent , line , logLevelToStyle , mkNarrativeList , parens , parseStylesUpdateFromString , prettyDebugL , prettyError , prettyErrorL , prettyInfo , prettyInfoL , prettyInfoS , prettyNote , prettyWarn , prettyWarnL , prettyWarnS , punctuate , sep , softbreak , softline , string , style , vsep ) where import Data.Monoid as X ( Any (..), Endo (..), First (..), Sum (..) ) import Data.Conduit as X ( ConduitM, runConduit, (.|) ) import qualified Data.Conduit.Binary as CB import qualified Data.Conduit.List as CL import Data.Conduit.Process.Typed ( byteStringInput, createSource, withLoggedProcess_ ) import qualified Data.Text.IO as T import Pantry as X hiding ( Package (..), loadSnapshot ) import Path as X ( Abs, Dir, File, Path, Rel, toFilePath ) import qualified Path.IO import RIO as X import RIO.File as X hiding ( writeBinaryFileAtomic ) import RIO.PrettyPrint ( HasStylesUpdate (..), HasTerm (..), Pretty (..), Style (..) , StyleDoc, (<+>), align, bulletedList, debugBracket , encloseSep, fillSep, flow, hang, hcat, hsep, indent, line , logLevelToStyle, mkNarrativeList, parens, prettyDebugL , prettyError, prettyErrorL, prettyInfo, prettyInfoL , prettyInfoS, prettyNote, prettyWarn, prettyWarnL , prettyWarnS, punctuate, sep, softbreak, softline, string , style, stylesUpdateL, useColorL, vsep ) import RIO.PrettyPrint.DefaultStyles (defaultStyles) import RIO.PrettyPrint.PrettyException ( PrettyException (..) ) import RIO.PrettyPrint.StylesUpdate ( StylesUpdate (..), parseStylesUpdateFromString ) import RIO.PrettyPrint.Types ( StyleSpec ) import RIO.Process ( HasProcessContext (..), ProcessConfig, ProcessContext , closed, getStderr, getStdout, proc, readProcess_, setStderr , setStdin, setStdout, waitExitCode, withProcessWait_ , workingDirL ) import qualified RIO.Text as T import System.IO.Echo ( withoutInputEcho ) -- | Path version withSystemTempDir :: MonadUnliftIO m => String -> (Path Abs Dir -> m a) -> m a withSystemTempDir str inner = withRunInIO $ \run -> Path.IO.withSystemTempDir str $ run . inner -- | Like `withSystemTempDir`, but the temporary directory is not deleted. withKeepSystemTempDir :: MonadUnliftIO m => String -> (Path Abs Dir -> m a) -> m a withKeepSystemTempDir str inner = withRunInIO $ \run -> do path <- Path.IO.getTempDir dir <- Path.IO.createTempDir path str run $ inner dir -- | Consume the stdout and stderr of a process feeding strict 'ByteString's to -- the consumers. -- -- Throws a 'ReadProcessException' if unsuccessful in launching, or -- 'ExitCodeException' if the process itself fails. sinkProcessStderrStdout :: forall e o env. (HasProcessContext env, HasLogFunc env, HasCallStack) => String -- ^ Command -> [String] -- ^ Command line arguments -> ConduitM ByteString Void (RIO env) e -- ^ Sink for stderr -> ConduitM ByteString Void (RIO env) o -- ^ Sink for stdout -> RIO env (e,o) sinkProcessStderrStdout name args sinkStderr sinkStdout = proc name args $ \pc0 -> do let pc = setStdout createSource $ setStderr createSource -- Don't use closed, since that can break ./configure scripts -- See https://github.com/commercialhaskell/stack/pull/4722 $ setStdin (byteStringInput "") pc0 withProcessWait_ pc $ \p -> (runConduit (getStderr p .| sinkStderr) `concurrently` runConduit (getStdout p .| sinkStdout)) <* waitExitCode p -- | Consume the stdout of a process feeding strict 'ByteString's to a consumer. -- If the process fails, spits out stdout and stderr as error log -- level. Should not be used for long-running processes or ones with -- lots of output; for that use 'sinkProcessStderrStdout'. -- -- Throws a 'ReadProcessException' if unsuccessful. sinkProcessStdout :: (HasProcessContext env, HasLogFunc env, HasCallStack) => String -- ^ Command -> [String] -- ^ Command line arguments -> ConduitM ByteString Void (RIO env) a -- ^ Sink for stdout -> RIO env a sinkProcessStdout name args sinkStdout = proc name args $ \pc -> withLoggedProcess_ (setStdin closed pc) $ \p -> runConcurrently $ Concurrently (runConduit $ getStderr p .| CL.sinkNull) *> Concurrently (runConduit $ getStdout p .| sinkStdout) logProcessStderrStdout :: (HasCallStack, HasProcessContext env, HasLogFunc env) => ProcessConfig stdin stdoutIgnored stderrIgnored -> RIO env () logProcessStderrStdout pc = withLoggedProcess_ pc $ \p -> let logLines = CB.lines .| CL.mapM_ (logInfo . displayBytesUtf8) in runConcurrently $ Concurrently (runConduit $ getStdout p .| logLines) *> Concurrently (runConduit $ getStderr p .| logLines) -- | Read from the process, ignoring any output. -- -- Throws a 'ReadProcessException' exception if the process fails. readProcessNull :: (HasProcessContext env, HasLogFunc env, HasCallStack) => String -- ^ Command -> [String] -- ^ Command line arguments -> RIO env () readProcessNull name args = -- We want the output to appear in any exceptions, so we capture and drop it void $ proc name args readProcess_ -- | Use the new 'ProcessContext', but retain the working directory -- from the parent environment. withProcessContext :: HasProcessContext env => ProcessContext -> RIO env a -> RIO env a withProcessContext pcNew inner = do pcOld <- view processContextL let pcNew' = set workingDirL (view workingDirL pcOld) pcNew local (set processContextL pcNew') inner -- | Remove a trailing carriage pure if present stripCR :: Text -> Text stripCR = T.dropSuffix "\r" -- | Prompt the user by sending text to stdout, and taking a line of -- input from stdin. prompt :: MonadIO m => Text -> m Text prompt txt = liftIO $ do T.putStr txt hFlush stdout T.getLine -- | Prompt the user by sending text to stdout, and collecting a line -- of input from stdin. While taking input from stdin, input echoing is -- disabled, to hide passwords. -- -- Based on code from cabal-install, Distribution.Client.Upload promptPassword :: MonadIO m => Text -> m Text promptPassword txt = liftIO $ do T.putStr txt hFlush stdout -- Save/restore the terminal echoing status (no echoing for entering -- the password). password <- withoutInputEcho T.getLine -- Since the user's newline is not echoed, one needs to be inserted. T.putStrLn "" pure password -- | Prompt the user by sending text to stdout, and collecting a line of -- input from stdin. If something other than "y" or "n" is entered, then -- print a message indicating that "y" or "n" is expected, and ask -- again. promptBool :: MonadIO m => Text -> m Bool promptBool txt = liftIO $ do input <- prompt txt case input of "y" -> pure True "n" -> pure False _ -> do T.putStrLn "Please press either 'y' or 'n', and then enter." promptBool txt -- | Name of the 'stack' program. -- -- NOTE: Should be defined in "Stack.Constants", but not doing so due to the -- GHC stage restrictions. stackProgName :: String stackProgName = "stack" stackProgName' :: Text stackProgName' = T.pack stackProgName -- | Like @First Bool@, but the default is @True@. newtype FirstTrue = FirstTrue { getFirstTrue :: Maybe Bool } deriving (Show, Eq, Ord) instance Semigroup FirstTrue where FirstTrue (Just x) <> _ = FirstTrue (Just x) FirstTrue Nothing <> x = x instance Monoid FirstTrue where mempty = FirstTrue Nothing mappend = (<>) -- | Get the 'Bool', defaulting to 'True' fromFirstTrue :: FirstTrue -> Bool fromFirstTrue = fromMaybe True . getFirstTrue -- | Helper for filling in default values defaultFirstTrue :: (a -> FirstTrue) -> Bool defaultFirstTrue _ = True -- | Like @First Bool@, but the default is @False@. newtype FirstFalse = FirstFalse { getFirstFalse :: Maybe Bool } deriving (Show, Eq, Ord) instance Semigroup FirstFalse where FirstFalse (Just x) <> _ = FirstFalse (Just x) FirstFalse Nothing <> x = x instance Monoid FirstFalse where mempty = FirstFalse Nothing mappend = (<>) -- | Get the 'Bool', defaulting to 'False' fromFirstFalse :: FirstFalse -> Bool fromFirstFalse = fromMaybe False . getFirstFalse -- | Helper for filling in default values defaultFirstFalse :: (a -> FirstFalse) -> Bool defaultFirstFalse _ = False -- | Write a @Builder@ to a file and atomically rename. writeBinaryFileAtomic :: MonadIO m => Path absrel File -> Builder -> m () writeBinaryFileAtomic fp builder = liftIO $ withBinaryFileAtomic (toFilePath fp) WriteMode (`hPutBuilder` builder) newtype PrettyRawSnapshotLocation = PrettyRawSnapshotLocation RawSnapshotLocation instance Pretty PrettyRawSnapshotLocation where pretty (PrettyRawSnapshotLocation (RSLCompiler compiler)) = fromString $ T.unpack $ utf8BuilderToText $ display compiler pretty (PrettyRawSnapshotLocation (RSLUrl url Nothing)) = style Url (fromString $ T.unpack url) pretty (PrettyRawSnapshotLocation (RSLUrl url (Just blob))) = fillSep [ style Url (fromString $ T.unpack url) , parens $ fromString $ T.unpack $ utf8BuilderToText $ display blob ] pretty (PrettyRawSnapshotLocation (RSLFilePath resolved)) = style File (fromString $ show $ resolvedRelative resolved) pretty (PrettyRawSnapshotLocation (RSLSynonym syn)) = fromString $ show syn -- | Report a bug in Stack. bugReport :: String -> String -> String bugReport code msg = "Error: " ++ code ++ "\n" ++ bugDeclaration ++ " " ++ msg ++ " " ++ bugRequest -- | Report a pretty bug in Stack. bugPrettyReport :: String -> StyleDoc -> StyleDoc bugPrettyReport code msg = "Error:" <+> fromString code <> line <> flow bugDeclaration <+> msg <+> flow bugRequest -- | Bug declaration message. bugDeclaration :: String bugDeclaration = "The impossible happened!" -- | Bug report message. bugRequest :: String bugRequest = "Please report this bug at Stack's repository." -- | A \'pretty\' blank line. blankLine :: StyleDoc blankLine = line <> line stack-2.9.3.1/src/Stack/Runners.hs0000644000000000000000000002007114445022466015012 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} -- | Utilities for running stack commands. -- -- Instead of using Has-style classes below, the type signatures use -- concrete environments to try and avoid accidentally rerunning -- configuration parsing. For example, we want @withConfig $ -- withConfig $ ...@ to fail. module Stack.Runners ( withBuildConfig , withEnvConfig , withDefaultEnvConfig , withConfig , withGlobalProject , withRunnerGlobal , ShouldReexec (..) ) where import RIO.Process ( mkDefaultProcessContext ) import RIO.Time ( addUTCTime, getCurrentTime ) import Stack.Build.Target ( NeedTargets (..) ) import Stack.Config import Stack.Constants import Stack.DefaultColorWhen ( defaultColorWhen ) import qualified Stack.Docker as Docker import qualified Stack.Nix as Nix import Stack.Prelude import Stack.Setup import Stack.Storage.User ( upgradeChecksSince, logUpgradeCheck ) import Stack.Types.Config import Stack.Types.Docker ( dockerEnable ) import Stack.Types.Nix ( nixEnable ) import Stack.Types.Version ( stackMinorVersion, minorVersion ) import System.Console.ANSI ( hSupportsANSIWithoutEmulation ) import System.Terminal ( getTerminalWidth ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Runners" module. data RunnersException = CommandInvalid | DockerAndNixInvalid | NixWithinDockerInvalid | DockerWithinNixInvalid deriving (Show, Typeable) instance Exception RunnersException where displayException CommandInvalid = "Error: [S-7144]\n" ++ "Cannot use this command with options which override the stack.yaml \ \location." displayException DockerAndNixInvalid = "Error: [S-8314]\n" ++ "Cannot use both Docker and Nix at the same time." displayException NixWithinDockerInvalid = "Error: [S-8641]\n" ++ "Cannot use Nix from within a Docker container." displayException DockerWithinNixInvalid = "Error: [S-5107]\n" ++ "Cannot use Docker from within a Nix shell." -- | Ensure that no project settings are used when running 'withConfig'. withGlobalProject :: RIO Runner a -> RIO Runner a withGlobalProject inner = do oldSYL <- view stackYamlLocL case oldSYL of SYLDefault -> local (set stackYamlLocL SYLGlobalProject) inner _ -> throwIO CommandInvalid -- | Helper for 'withEnvConfig' which passes in some default arguments: -- -- * No targets are requested -- -- * Default command line build options are assumed withDefaultEnvConfig :: RIO EnvConfig a -> RIO Config a withDefaultEnvConfig = withEnvConfig AllowNoTargets defaultBuildOptsCLI -- | Upgrade a 'Config' environment to an 'EnvConfig' environment by -- performing further parsing of project-specific configuration (like -- 'withBuildConfig') and then setting up a build environment -- toolchain. This is intended to be run inside a call to -- 'withConfig'. withEnvConfig :: NeedTargets -> BuildOptsCLI -> RIO EnvConfig a -- ^ Action that uses the build config. If Docker is enabled for builds, -- this will be run in a Docker container. -> RIO Config a withEnvConfig needTargets boptsCLI inner = withBuildConfig $ do envConfig <- setupEnv needTargets boptsCLI Nothing logDebug "Starting to execute command inside EnvConfig" runRIO envConfig inner -- | If the settings justify it, should we reexec inside Docker or Nix? data ShouldReexec = YesReexec | NoReexec -- | Load the configuration. Convenience function used -- throughout this module. withConfig :: ShouldReexec -> RIO Config a -> RIO Runner a withConfig shouldReexec inner = loadConfig $ \config -> do -- If we have been relaunched in a Docker container, perform in-container initialization -- (switch UID, etc.). We do this after first loading the configuration since it must -- happen ASAP but needs a configuration. view (globalOptsL.to globalDockerEntrypoint) >>= traverse_ (Docker.entrypoint config) runRIO config $ do -- Catching all exceptions here, since we don't want this -- check to ever cause Stack to stop working shouldUpgradeCheck `catchAny` \e -> logError $ "Error: [S-7353]\n" <> "Error when running shouldUpgradeCheck: " <> displayShow e case shouldReexec of YesReexec -> reexec inner NoReexec -> inner -- | Perform a Docker or Nix reexec, if warranted. Otherwise run the -- inner action. reexec :: RIO Config a -> RIO Config a reexec inner = do nixEnable' <- asks $ nixEnable . configNix dockerEnable' <- asks $ dockerEnable . configDocker case (nixEnable', dockerEnable') of (True, True) -> throwIO DockerAndNixInvalid (False, False) -> inner -- Want to use Nix (True, False) -> do whenM getInContainer $ throwIO NixWithinDockerInvalid isReexec <- view reExecL if isReexec then inner else Nix.runShellAndExit -- Want to use Docker (False, True) -> do whenM getInNixShell $ throwIO DockerWithinNixInvalid inContainer <- getInContainer if inContainer then do isReexec <- view reExecL if isReexec then inner else throwIO Docker.OnlyOnHostException else Docker.runContainerAndExit -- | Use the 'GlobalOpts' to create a 'Runner' and run the provided -- action. withRunnerGlobal :: GlobalOpts -> RIO Runner a -> IO a withRunnerGlobal go inner = do colorWhen <- maybe defaultColorWhen pure $ getFirst $ configMonoidColorWhen $ globalConfigMonoid go useColor <- case colorWhen of ColorNever -> pure False ColorAlways -> pure True ColorAuto -> fromMaybe True <$> hSupportsANSIWithoutEmulation stderr termWidth <- clipWidth <$> maybe (fromMaybe defaultTerminalWidth <$> getTerminalWidth) pure (globalTermWidth go) menv <- mkDefaultProcessContext let update = globalStylesUpdate go withNewLogFunc go useColor update $ \logFunc -> runRIO Runner { runnerGlobalOpts = go , runnerUseColor = useColor , runnerLogFunc = logFunc , runnerTermWidth = termWidth , runnerProcessContext = menv } inner where clipWidth w | w < minTerminalWidth = minTerminalWidth | w > maxTerminalWidth = maxTerminalWidth | otherwise = w -- | Check if we should recommend upgrading Stack and, if so, recommend it. shouldUpgradeCheck :: RIO Config () shouldUpgradeCheck = do config <- ask when (configRecommendUpgrade config) $ do now <- getCurrentTime let yesterday = addUTCTime (-24 * 60 * 60) now checks <- upgradeChecksSince yesterday when (checks == 0) $ do mversion <- getLatestHackageVersion NoRequireHackageIndex "stack" UsePreferredVersions case mversion of -- Compare the minor version so we avoid patch-level, Hackage-only releases. -- See: https://github.com/commercialhaskell/stack/pull/4729#pullrequestreview-227176315 Just (PackageIdentifierRevision _ version _) | minorVersion version > stackMinorVersion -> do logWarn "<<<<<<<<<<<<<<<<<<" logWarn $ "You are currently using Stack version " <> fromString (versionString stackVersion) <> ", but version " <> fromString (versionString version) <> " is available" logWarn "You can try to upgrade by running 'stack upgrade'" logWarn $ "Tired of seeing this? Add 'recommend-stack-upgrade: false' to " <> fromString (toFilePath (configUserConfigPath config)) logWarn ">>>>>>>>>>>>>>>>>>" logWarn "" logWarn "" _ -> pure () logUpgradeCheck now stack-2.9.3.1/src/Stack/Script.hs0000644000000000000000000004015414445022466014626 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Stack.Script ( scriptCmd ) where import Data.ByteString.Builder ( toLazyByteString ) import qualified Data.ByteString.Char8 as S8 import qualified Data.Conduit.List as CL import Data.List.Split ( splitWhen ) import qualified Data.Map.Strict as Map import qualified Data.Set as Set import Distribution.Compiler ( CompilerFlavor (..) ) import Distribution.ModuleName ( ModuleName ) import qualified Distribution.PackageDescription as PD import qualified Distribution.Types.CondTree as C import Distribution.Types.ModuleReexport ( moduleReexportName ) import Distribution.Types.PackageName ( mkPackageName ) import Distribution.Types.VersionRange ( withinRange ) import Distribution.System ( Platform (..) ) import qualified Pantry.SHA256 as SHA256 import Path ( parent ) import Path.IO ( getModificationTime, resolveFile' ) import qualified RIO.Directory as Dir import RIO.Process ( exec, proc, readProcessStdout_, withWorkingDir ) import qualified RIO.Text as T import qualified Stack.Build import Stack.Build.Installed import Stack.Constants ( osIsWindows ) import Stack.PackageDump import Stack.Prelude import Stack.Options.ScriptParser import Stack.Runners import Stack.Setup ( withNewLocalBuildTargets ) import Stack.SourceMap ( getCompilerInfo, immutableLocSha ) import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.SourceMap import System.FilePath ( dropExtension, replaceExtension ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Script" module. data ScriptException = MutableDependenciesForScript [PackageName] | AmbiguousModuleName ModuleName [PackageName] | ArgumentsWithNoRunInvalid | NoRunWithoutCompilationInvalid deriving (Show, Typeable) instance Exception ScriptException where displayException (MutableDependenciesForScript names) = unlines $ "Error: [S-4994]" : "No mutable packages are allowed in the 'script' command. Mutable \ \packages found:" : map (\name -> "- " ++ packageNameString name) names displayException (AmbiguousModuleName mname pkgs) = unlines $ "Error: [S-1691]" : ( "Module " ++ moduleNameString mname ++ " appears in multiple packages: " ) : [ unwords $ map packageNameString pkgs ] displayException ArgumentsWithNoRunInvalid = "Error: [S-5067]\n" ++ "'--no-run' incompatible with arguments." displayException NoRunWithoutCompilationInvalid = "Error: [S-9469]\n" ++ "'--no-run' requires either '--compile' or '--optimize'." -- | Run a Stack Script scriptCmd :: ScriptOpts -> RIO Runner () scriptCmd opts = do -- Some warnings in case the user somehow tries to set a -- stack.yaml location. Note that in this functions we use -- logError instead of logWarn because, when using the -- interpreter mode, only error messages are shown. See: -- https://github.com/commercialhaskell/stack/issues/3007 view (globalOptsL.to globalStackYaml) >>= \case SYLOverride fp -> logError $ "Ignoring override stack.yaml file for script command: " <> fromString (toFilePath fp) SYLGlobalProject -> logError "Ignoring SYLGlobalProject for script command" SYLDefault -> pure () SYLNoProject _ -> assert False (pure ()) file <- resolveFile' $ soFile opts isNoRunCompile <- fromFirstFalse . configMonoidNoRunCompile <$> view (globalOptsL.to globalConfigMonoid) let scriptDir = parent file modifyGO go = go { globalConfigMonoid = (globalConfigMonoid go) { configMonoidInstallGHC = FirstTrue $ Just True } , globalStackYaml = SYLNoProject $ soScriptExtraDeps opts } (shouldRun, shouldCompile) = if isNoRunCompile then (NoRun, SECompile) else (soShouldRun opts, soCompile opts) case shouldRun of YesRun -> pure () NoRun -> do unless (null $ soArgs opts) $ throwIO ArgumentsWithNoRunInvalid case shouldCompile of SEInterpret -> throwIO NoRunWithoutCompilationInvalid SECompile -> pure () SEOptimize -> pure () -- Optimization: if we're compiling, and the executable is newer -- than the source file, run it immediately. local (over globalOptsL modifyGO) $ case shouldCompile of SEInterpret -> longWay shouldRun shouldCompile file scriptDir SECompile -> shortCut shouldRun shouldCompile file scriptDir SEOptimize -> shortCut shouldRun shouldCompile file scriptDir where runCompiled shouldRun file = do let exeName = toExeName $ toFilePath file case shouldRun of YesRun -> exec exeName (soArgs opts) NoRun -> logInfo $ "Compilation finished, executable available at " <> fromString exeName shortCut shouldRun shouldCompile file scriptDir = handleIO (const $ longWay shouldRun shouldCompile file scriptDir) $ do srcMod <- getModificationTime file exeMod <- Dir.getModificationTime $ toExeName $ toFilePath file if srcMod < exeMod then runCompiled shouldRun file else longWay shouldRun shouldCompile file scriptDir longWay shouldRun shouldCompile file scriptDir = withConfig YesReexec $ withDefaultEnvConfig $ do config <- view configL menv <- liftIO $ configProcessContextSettings config defaultEnvSettings withProcessContext menv $ do colorFlag <- appropriateGhcColorFlag targetsSet <- case soPackages opts of [] -> do -- Using the import parser getPackagesFromImports (soFile opts) packages -> do let targets = concatMap wordsComma packages targets' <- mapM parsePackageNameThrowing targets pure $ Set.fromList targets' unless (Set.null targetsSet) $ do -- Optimization: use the relatively cheap ghc-pkg list -- --simple-output to check which packages are installed -- already. If all needed packages are available, we can -- skip the (rather expensive) build call below. GhcPkgExe pkg <- view $ compilerPathsL.to cpPkg -- https://github.com/haskell/process/issues/251 bss <- snd <$> sinkProcessStderrStdout (toFilePath pkg) ["list", "--simple-output"] CL.sinkNull CL.consume -- FIXME use the package info from envConfigPackages, or is that crazy? let installed = Set.fromList $ map toPackageName $ words $ S8.unpack $ S8.concat bss if Set.null $ Set.difference (Set.map packageNameString targetsSet) installed then logDebug "All packages already installed" else do logDebug "Missing packages, performing installation" let targets = map (T.pack . packageNameString) $ Set.toList targetsSet withNewLocalBuildTargets targets $ Stack.Build.build Nothing let ghcArgs = concat [ ["-i", "-i" ++ toFilePath scriptDir] , ["-hide-all-packages"] , maybeToList colorFlag , map (\x -> "-package" ++ x) $ Set.toList $ Set.insert "base" $ Set.map packageNameString targetsSet , case shouldCompile of SEInterpret -> [] SECompile -> [] SEOptimize -> ["-O2"] , soGhcOptions opts ] case shouldCompile of SEInterpret -> do interpret <- view $ compilerPathsL.to cpInterpreter exec (toFilePath interpret) (ghcArgs ++ toFilePath file : soArgs opts) _ -> do -- Use readProcessStdout_ so that (1) if GHC does send any output -- to stdout, we capture it and stop it from being sent to our -- stdout, which could break scripts, and (2) if there's an -- exception, the standard output we did capture will be reported -- to the user. compilerExeName <- view $ compilerPathsL.to cpCompiler.to toFilePath withWorkingDir (toFilePath scriptDir) $ proc compilerExeName (ghcArgs ++ [toFilePath file]) (void . readProcessStdout_) runCompiled shouldRun file toPackageName = reverse . drop 1 . dropWhile (/= '-') . reverse -- Like words, but splits on both commas and spaces wordsComma = splitWhen (\c -> c == ' ' || c == ',') toExeName fp = if osIsWindows then replaceExtension fp "exe" else dropExtension fp getPackagesFromImports :: FilePath -- ^ script filename -> RIO EnvConfig (Set PackageName) getPackagesFromImports scriptFP = do (pns, mns) <- liftIO $ parseImports <$> S8.readFile scriptFP if Set.null mns then pure pns else Set.union pns <$> getPackagesFromModuleNames mns getPackagesFromModuleNames :: Set ModuleName -> RIO EnvConfig (Set PackageName) getPackagesFromModuleNames mns = do hash <- hashSnapshot withSnapshotCache hash mapSnapshotPackageModules $ \getModulePackages -> do pns <- forM (Set.toList mns) $ \mn -> do pkgs <- getModulePackages mn case pkgs of [] -> pure Set.empty [pn] -> pure $ Set.singleton pn _ -> throwM $ AmbiguousModuleName mn pkgs pure $ Set.unions pns `Set.difference` blacklist hashSnapshot :: RIO EnvConfig SnapshotCacheHash hashSnapshot = do sourceMap <- view $ envConfigL . to envConfigSourceMap compilerInfo <- getCompilerInfo let eitherPliHash (pn, dep) | PLImmutable pli <- dpLocation dep = Right $ immutableLocSha pli | otherwise = Left pn deps = Map.toList (smDeps sourceMap) case partitionEithers (map eitherPliHash deps) of ([], pliHashes) -> do let hashedContent = mconcat $ compilerInfo : pliHashes pure $ SnapshotCacheHash (SHA256.hashLazyBytes $ toLazyByteString hashedContent) (mutables, _) -> throwM $ MutableDependenciesForScript mutables mapSnapshotPackageModules :: RIO EnvConfig (Map PackageName (Set ModuleName)) mapSnapshotPackageModules = do sourceMap <- view $ envConfigL . to envConfigSourceMap installMap <- toInstallMap sourceMap (_installedMap, globalDumpPkgs, snapshotDumpPkgs, _localDumpPkgs) <- getInstalled installMap let globals = dumpedPackageModules (smGlobal sourceMap) globalDumpPkgs notHidden = Map.filter (not . dpHidden) notHiddenDeps = notHidden $ smDeps sourceMap installedDeps = dumpedPackageModules notHiddenDeps snapshotDumpPkgs dumpPkgs = Set.fromList $ map (pkgName . dpPackageIdent) snapshotDumpPkgs notInstalledDeps = Map.withoutKeys notHiddenDeps dumpPkgs otherDeps <- for notInstalledDeps $ \dep -> do gpd <- liftIO $ cpGPD (dpCommon dep) Set.fromList <$> allExposedModules gpd -- source map construction process should guarantee unique package names -- in these maps pure $ globals <> installedDeps <> otherDeps dumpedPackageModules :: Map PackageName a -> [DumpPackage] -> Map PackageName (Set ModuleName) dumpedPackageModules pkgs dumpPkgs = let pnames = Map.keysSet pkgs `Set.difference` blacklist in Map.fromList [ (pn, dpExposedModules) | DumpPackage {..} <- dumpPkgs , let PackageIdentifier pn _ = dpPackageIdent , pn `Set.member` pnames ] allExposedModules :: PD.GenericPackageDescription -> RIO EnvConfig [ModuleName] allExposedModules gpd = do Platform curArch curOs <- view platformL curCompiler <- view actualCompilerVersionL let checkCond (PD.OS os) = pure $ os == curOs checkCond (PD.Arch arch) = pure $ arch == curArch checkCond (PD.Impl compiler range) = case curCompiler of ACGhc version -> pure $ compiler == GHC && version `withinRange` range ACGhcGit {} -> pure $ compiler == GHC -- currently we don't do flag checking here checkCond other = Left other mlibrary = snd . C.simplifyCondTree checkCond <$> PD.condLibrary gpd pure $ case mlibrary of Just lib -> PD.exposedModules lib ++ map moduleReexportName (PD.reexportedModules lib) Nothing -> mempty -- | The Stackage project introduced the concept of hidden packages, -- to deal with conflicting module names. However, this is a -- relatively recent addition (at time of writing). See: -- http://www.snoyman.com/blog/2017/01/conflicting-module-names. To -- kick this thing off a bit better, we're included a blacklist of -- packages that should never be auto-parsed in. blacklist :: Set PackageName blacklist = Set.fromList [ mkPackageName "async-dejafu" , mkPackageName "monads-tf" , mkPackageName "crypto-api" , mkPackageName "fay-base" , mkPackageName "hashmap" , mkPackageName "hxt-unicode" , mkPackageName "hledger-web" , mkPackageName "plot-gtk3" , mkPackageName "gtk3" , mkPackageName "regex-pcre-builtin" , mkPackageName "regex-compat-tdfa" , mkPackageName "log" , mkPackageName "zip" , mkPackageName "monad-extras" , mkPackageName "control-monad-free" , mkPackageName "prompt" , mkPackageName "kawhi" , mkPackageName "language-c" , mkPackageName "gl" , mkPackageName "svg-tree" , mkPackageName "Glob" , mkPackageName "nanospec" , mkPackageName "HTF" , mkPackageName "courier" , mkPackageName "newtype-generics" , mkPackageName "objective" , mkPackageName "binary-ieee754" , mkPackageName "rerebase" , mkPackageName "cipher-aes" , mkPackageName "cipher-blowfish" , mkPackageName "cipher-camellia" , mkPackageName "cipher-des" , mkPackageName "cipher-rc4" , mkPackageName "crypto-cipher-types" , mkPackageName "crypto-numbers" , mkPackageName "crypto-pubkey" , mkPackageName "crypto-random" , mkPackageName "cryptohash" , mkPackageName "cryptohash-conduit" , mkPackageName "cryptohash-md5" , mkPackageName "cryptohash-sha1" , mkPackageName "cryptohash-sha256" ] parseImports :: ByteString -> (Set PackageName, Set ModuleName) parseImports = fold . mapMaybe (parseLine . stripCR') . S8.lines where -- Remove any carriage pure character present at the end, to -- support Windows-style line endings (CRLF) stripCR' bs | S8.null bs = bs | S8.last bs == '\r' = S8.init bs | otherwise = bs stripPrefix x y | x `S8.isPrefixOf` y = Just $ S8.drop (S8.length x) y | otherwise = Nothing parseLine bs0 = do bs1 <- stripPrefix "import " bs0 let bs2 = S8.dropWhile (== ' ') bs1 bs3 = fromMaybe bs2 $ stripPrefix "qualified " bs2 case stripPrefix "\"" bs3 of Just bs4 -> do pn <- parsePackageNameThrowing $ S8.unpack $ S8.takeWhile (/= '"') bs4 Just (Set.singleton pn, Set.empty) Nothing -> Just ( Set.empty , Set.singleton $ fromString $ T.unpack $ decodeUtf8With lenientDecode $ S8.takeWhile (\c -> c /= ' ' && c /= '(') bs3 ) stack-2.9.3.1/src/Stack/SDist.hs0000644000000000000000000006206114445022466014411 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TypeFamilies #-} -- Create a source distribution tarball module Stack.SDist ( getSDistTarball , checkSDistTarball , checkSDistTarball' , SDistOpts (..) ) where import qualified Codec.Archive.Tar as Tar import qualified Codec.Archive.Tar.Entry as Tar import qualified Codec.Compression.GZip as GZip import Control.Applicative import Control.Concurrent.Execute ( ActionContext (..), Concurrency (..) ) import qualified Data.ByteString as S import qualified Data.ByteString.Char8 as S8 import qualified Data.ByteString.Lazy as L import Data.Char ( toLower ) import Data.Data ( cast ) import qualified Data.List as List import qualified Data.List.NonEmpty as NE import qualified Data.Map.Strict as Map import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.Text.Encoding.Error as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Encoding as TLE import Data.Time.Clock.POSIX import Distribution.Package ( Dependency (..) ) import qualified Distribution.PackageDescription as Cabal import qualified Distribution.PackageDescription.Check as Check import qualified Distribution.PackageDescription.Parsec as Cabal import Distribution.PackageDescription.PrettyPrint ( showGenericPackageDescription ) import Distribution.Version ( simplifyVersionRange, orLaterVersion, earlierVersion , hasUpperBound, hasLowerBound ) import Path import Path.IO hiding ( getModificationTime, getPermissions, withSystemTempDir ) import Stack.Build ( mkBaseConfigOpts, build, buildLocalTargets ) import Stack.Build.Execute import Stack.Build.Installed import Stack.Build.Source ( projectLocalPackages ) import Stack.Package import Stack.Prelude hiding ( Display (..) ) import Stack.SourceMap import Stack.Types.Build import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.Package import Stack.Types.SourceMap import Stack.Types.Version import System.Directory ( getModificationTime, getPermissions ) import qualified System.FilePath as FP -- | Type representing exceptions thrown by functions exported by the -- "Stack.SDist" module. data SDistException = CheckException (NonEmpty Check.PackageCheck) | CabalFilePathsInconsistentBug (Path Abs File) (Path Abs File) | ToTarPathException String deriving (Show, Typeable) instance Exception SDistException where displayException (CheckException xs) = unlines $ [ "Error: [S-6439]" , "Package check reported the following errors:" ] <> fmap show (NE.toList xs) displayException (CabalFilePathsInconsistentBug cabalfp cabalfp') = concat [ "Error: [S-9595]\n" , "The impossible happened! Two Cabal file paths are inconsistent: " , show (cabalfp, cabalfp') ] displayException (ToTarPathException e) = "Error: [S-7875\n" ++ e data SDistOpts = SDistOpts { sdoptsDirsToWorkWith :: [String] -- ^ Directories to package , sdoptsPvpBounds :: Maybe PvpBounds -- ^ PVP Bounds overrides , sdoptsIgnoreCheck :: Bool -- ^ Whether to ignore check of the package for common errors , sdoptsBuildTarball :: Bool -- ^ Whether to build the tarball , sdoptsTarPath :: Maybe FilePath -- ^ Where to copy the tarball } -- | Given the path to a local package, creates its source -- distribution tarball. -- -- While this yields a 'FilePath', the name of the tarball, this -- tarball is not written to the disk and instead yielded as a lazy -- bytestring. getSDistTarball :: HasEnvConfig env => Maybe PvpBounds -- ^ Override Config value -> Path Abs Dir -- ^ Path to local package -> RIO env (FilePath, L.ByteString, Maybe (PackageIdentifier, L.ByteString)) -- ^ Filename, tarball contents, and option Cabal file revision to upload getSDistTarball mpvpBounds pkgDir = do config <- view configL let PvpBounds pvpBounds asRevision = fromMaybe (configPvpBounds config) mpvpBounds tweakCabal = pvpBounds /= PvpBoundsNone pkgFp = toFilePath pkgDir lp <- readLocalPackage pkgDir forM_ (packageSetupDeps (lpPackage lp)) $ \customSetupDeps -> case NE.nonEmpty (map (T.pack . packageNameString) (Map.keys customSetupDeps)) of Just nonEmptyDepTargets -> do eres <- buildLocalTargets nonEmptyDepTargets case eres of Left err -> logError $ "Error: [S-8399]\n" <> "Error building custom-setup dependencies: " <> displayShow err Right _ -> pure () Nothing -> logWarn "unexpected empty custom-setup dependencies" sourceMap <- view $ envConfigL.to envConfigSourceMap installMap <- toInstallMap sourceMap (installedMap, _globalDumpPkgs, _snapshotDumpPkgs, _localDumpPkgs) <- getInstalled installMap let deps = Map.fromList [ (pid, ghcPkgId) | (_, Library pid ghcPkgId _) <- Map.elems installedMap] logInfo $ "Getting file list for " <> fromString pkgFp (fileList, cabalfp) <- getSDistFileList lp deps logInfo $ "Building sdist tarball for " <> fromString pkgFp files <- normalizeTarballPaths (map (T.unpack . stripCR . T.pack) (lines fileList)) -- We're going to loop below and eventually find the cabal -- file. When we do, we'll upload this reference, if the -- mpvpBounds value indicates that we should be uploading a cabal -- file revision. cabalFileRevisionRef <- liftIO (newIORef Nothing) -- NOTE: Could make this use lazy I/O to only read files as needed -- for upload (both GZip.compress and Tar.write are lazy). -- However, it seems less error prone and more predictable to read -- everything in at once, so that's what we're doing for now: let tarPath isDir fp = case Tar.toTarPath isDir (forceUtf8Enc (pkgId FP. fp)) of Left e -> throwIO $ ToTarPathException e Right tp -> pure tp -- convert a String of proper characters to a String of bytes -- in UTF8 encoding masquerading as characters. This is -- necessary for tricking the tar package into proper -- character encoding. forceUtf8Enc = S8.unpack . T.encodeUtf8 . T.pack packWith f isDir fp = liftIO $ f (pkgFp FP. fp) =<< tarPath isDir fp packDir = packWith Tar.packDirectoryEntry True packFile fp -- This is a Cabal file, we're going to tweak it, but only -- tweak it as a revision. | tweakCabal && isCabalFp fp && asRevision = do lbsIdent <- getCabalLbs pvpBounds (Just 1) cabalfp sourceMap liftIO (writeIORef cabalFileRevisionRef (Just lbsIdent)) packWith packFileEntry False fp -- Same, except we'll include the Cabal file in the -- original tarball upload. | tweakCabal && isCabalFp fp = do (_ident, lbs) <- getCabalLbs pvpBounds Nothing cabalfp sourceMap currTime <- liftIO getPOSIXTime -- Seconds from UNIX epoch tp <- liftIO $ tarPath False fp pure $ (Tar.fileEntry tp lbs) { Tar.entryTime = floor currTime } | otherwise = packWith packFileEntry False fp isCabalFp fp = toFilePath pkgDir FP. fp == toFilePath cabalfp tarName = pkgId FP.<.> "tar.gz" pkgId = packageIdentifierString (packageIdentifier (lpPackage lp)) dirEntries <- mapM packDir (dirsFromFiles files) fileEntries <- mapM packFile files mcabalFileRevision <- liftIO (readIORef cabalFileRevisionRef) pure (tarName, GZip.compress (Tar.write (dirEntries ++ fileEntries)), mcabalFileRevision) -- | Get the PVP bounds-enabled version of the given Cabal file getCabalLbs :: HasEnvConfig env => PvpBoundsType -> Maybe Int -- ^ optional revision -> Path Abs File -- ^ Cabal file -> SourceMap -> RIO env (PackageIdentifier, L.ByteString) getCabalLbs pvpBounds mrev cabalfp sourceMap = do (gpdio, _name, cabalfp') <- loadCabalFilePath (Just stackProgName') (parent cabalfp) gpd <- liftIO $ gpdio NoPrintWarnings unless (cabalfp == cabalfp') $ throwIO $ CabalFilePathsInconsistentBug cabalfp cabalfp' installMap <- toInstallMap sourceMap (installedMap, _, _, _) <- getInstalled installMap let internalPackages = Set.fromList $ gpdPackageName gpd : map (Cabal.unqualComponentNameToPackageName . fst) (Cabal.condSubLibraries gpd) gpd' = gtraverseT (addBounds internalPackages installMap installedMap) gpd gpd'' = case mrev of Nothing -> gpd' Just rev -> gpd' { Cabal.packageDescription = (Cabal.packageDescription gpd') { Cabal.customFieldsPD = (("x-revision", show rev):) $ filter (\(x, _) -> map toLower x /= "x-revision") $ Cabal.customFieldsPD $ Cabal.packageDescription gpd' } } ident = Cabal.package $ Cabal.packageDescription gpd'' -- Sanity rendering and reparsing the input, to ensure there are no -- cabal bugs, since there have been bugs here before, and currently -- are at the time of writing: -- -- https://github.com/haskell/cabal/issues/1202 -- https://github.com/haskell/cabal/issues/2353 -- https://github.com/haskell/cabal/issues/4863 (current issue) let roundtripErrs = [ flow "Bug detected in Cabal library. ((parse . render . parse) === \ \id) does not hold for the Cabal file at" <+> pretty cabalfp , "" ] (_warnings, eres) = Cabal.runParseResult $ Cabal.parseGenericPackageDescription $ T.encodeUtf8 $ T.pack $ showGenericPackageDescription gpd case eres of Right roundtripped | roundtripped == gpd -> pure () | otherwise -> do prettyWarn $ vsep $ roundtripErrs ++ [ "This seems to be fixed in development versions of Cabal, but \ \at time of writing, the fix is not in any released versions." , "" , "Please see this GitHub issue for status:" <+> style Url "https://github.com/commercialhaskell/stack/issues/3549" , "" , fillSep [ flow "If the issue is closed as resolved, then you may be \ \able to fix this by upgrading to a newer version of \ \Stack via" , style Shell "stack upgrade" , flow "for latest stable version or" , style Shell "stack upgrade --git" , flow "for the latest development version." ] , "" , fillSep [ flow "If the issue is fixed, but updating doesn't solve the \ \problem, please check if there are similar open \ \issues, and if not, report a new issue to the Stack \ \issue tracker, at" , style Url "https://github.com/commercialhaskell/stack/issues/new" ] , "" , flow "If the issue is not fixed, feel free to leave a comment \ \on it indicating that you would like it to be fixed." , "" ] Left (_version, errs) -> do prettyWarn $ vsep $ roundtripErrs ++ [ flow "In particular, parsing the rendered Cabal file is yielding a \ \parse error. Please check if there are already issues \ \tracking this, and if not, please report new issues to the \ \Stack and Cabal issue trackers, via" , bulletedList [ style Url "https://github.com/commercialhaskell/stack/issues/new" , style Url "https://github.com/haskell/cabal/issues/new" ] , flow $ "The parse error is: " ++ unlines (map show (toList errs)) , "" ] pure ( ident , TLE.encodeUtf8 $ TL.pack $ showGenericPackageDescription gpd'' ) where addBounds :: Set PackageName -> InstallMap -> InstalledMap -> Dependency -> Dependency addBounds internalPackages installMap installedMap dep@(Dependency name range s) = if name `Set.member` internalPackages then dep else case foundVersion of Nothing -> dep Just version -> Dependency name (simplifyVersionRange $ (if toAddUpper && not (hasUpperBound range) then addUpper version else id) $ (if toAddLower && not (hasLowerBound range) then addLower version else id) range) s where foundVersion = case Map.lookup name installMap of Just (_, version) -> Just version Nothing -> case Map.lookup name installedMap of Just (_, installed) -> Just (installedVersion installed) Nothing -> Nothing addUpper version = intersectVersionRanges (earlierVersion $ nextMajorVersion version) addLower version = intersectVersionRanges (orLaterVersion version) (toAddLower, toAddUpper) = case pvpBounds of PvpBoundsNone -> (False, False) PvpBoundsUpper -> (False, True) PvpBoundsLower -> (True, False) PvpBoundsBoth -> (True, True) -- | Traverse a data type. gtraverseT :: (Data a,Typeable b) => (Typeable b => b -> b) -> a -> a gtraverseT f = gmapT (\x -> case cast x of Nothing -> gtraverseT f x Just b -> fromMaybe x (cast (f b))) -- | Read in a 'LocalPackage' config. This makes some default decisions -- about 'LocalPackage' fields that might not be appropriate for other -- use-cases. readLocalPackage :: HasEnvConfig env => Path Abs Dir -> RIO env LocalPackage readLocalPackage pkgDir = do config <- getDefaultPackageConfig (gpdio, _, cabalfp) <- loadCabalFilePath (Just stackProgName') pkgDir gpd <- liftIO $ gpdio YesPrintWarnings let package = resolvePackage config gpd pure LocalPackage { lpPackage = package , lpWanted = False -- HACK: makes it so that sdist output goes to a log instead of a file. , lpCabalFile = cabalfp -- NOTE: these aren't the 'correct values, but aren't used in -- the usage of this function in this module. , lpTestBench = Nothing , lpBuildHaddocks = False , lpForceDirty = False , lpDirtyFiles = pure Nothing , lpNewBuildCaches = pure Map.empty , lpComponentFiles = pure Map.empty , lpComponents = Set.empty , lpUnbuildable = Set.empty } -- | Returns a newline-separate list of paths, and the absolute path to the -- Cabal file. getSDistFileList :: HasEnvConfig env => LocalPackage -> Map PackageIdentifier GhcPkgId -> RIO env (String, Path Abs File) getSDistFileList lp deps = withSystemTempDir (stackProgName <> "-sdist") $ \tmpdir -> do let bopts = defaultBuildOpts let boptsCli = defaultBuildOptsCLI baseConfigOpts <- mkBaseConfigOpts boptsCli locals <- projectLocalPackages withExecuteEnv bopts boptsCli baseConfigOpts locals [] [] [] Nothing -- provide empty list of globals. This is a hack around custom Setup.hs files $ \ee -> withSingleContext ac ee task deps (Just "sdist") $ \_package cabalfp _pkgDir cabal _announce _outputType -> do let outFile = toFilePath tmpdir FP. "source-files-list" cabal CloseOnException KeepTHLoading ["sdist", "--list-sources", outFile] contents <- liftIO (S.readFile outFile) pure (T.unpack $ T.decodeUtf8With T.lenientDecode contents, cabalfp) where package = lpPackage lp ac = ActionContext Set.empty [] ConcurrencyAllowed task = Task { taskProvides = PackageIdentifier (packageName package) (packageVersion package) , taskType = TTLocalMutable lp , taskConfigOpts = TaskConfigOpts { tcoMissing = Set.empty , tcoOpts = \_ -> ConfigureOpts [] [] } , taskBuildHaddock = False , taskPresent = Map.empty , taskAllInOne = True , taskCachePkgSrc = CacheSrcLocal (toFilePath (parent $ lpCabalFile lp)) , taskAnyMissing = True , taskBuildTypeConfig = False } normalizeTarballPaths :: HasRunner env => [FilePath] -> RIO env [FilePath] normalizeTarballPaths fps = do -- TODO: consider whether erroring out is better - otherwise the -- user might upload an incomplete tar? unless (null outsideDir) $ logWarn $ "Warning: These files are outside of the package directory, and will be omitted from the tarball: " <> displayShow outsideDir pure (nubOrd files) where (outsideDir, files) = partitionEithers (map pathToEither fps) pathToEither fp = maybe (Left fp) Right (normalizePath fp) normalizePath :: FilePath -> Maybe FilePath normalizePath = fmap FP.joinPath . go . FP.splitDirectories . FP.normalise where go [] = Just [] go ("..":_) = Nothing go (_:"..":xs) = go xs go (x:xs) = (x :) <$> go xs dirsFromFiles :: [FilePath] -> [FilePath] dirsFromFiles dirs = Set.toAscList (Set.delete "." results) where results = foldl' (\s -> go s . FP.takeDirectory) Set.empty dirs go s x | Set.member x s = s | otherwise = go (Set.insert x s) (FP.takeDirectory x) -- | Check package in given tarball. This will log all warnings -- and will throw an exception in case of critical errors. -- -- Note that we temporarily decompress the archive to analyze it. checkSDistTarball :: HasEnvConfig env => SDistOpts -- ^ The configuration of what to check -> Path Abs File -- ^ Absolute path to tarball -> RIO env () checkSDistTarball opts tarball = withTempTarGzContents tarball $ \pkgDir' -> do pkgDir <- (pkgDir' ) `liftM` (parseRelDir . FP.takeBaseName . FP.takeBaseName . toFilePath $ tarball) -- ^ drop ".tar" ^ drop ".gz" when (sdoptsBuildTarball opts) (buildExtractedTarball ResolvedPath { resolvedRelative = RelFilePath "this-is-not-used" -- ugly hack , resolvedAbsolute = pkgDir }) unless (sdoptsIgnoreCheck opts) (checkPackageInExtractedTarball pkgDir) checkPackageInExtractedTarball :: HasEnvConfig env => Path Abs Dir -- ^ Absolute path to tarball -> RIO env () checkPackageInExtractedTarball pkgDir = do (gpdio, name, _cabalfp) <- loadCabalFilePath (Just stackProgName') pkgDir gpd <- liftIO $ gpdio YesPrintWarnings config <- getDefaultPackageConfig let PackageDescriptionPair pkgDesc _ = resolvePackageDescription config gpd logInfo $ "Checking package '" <> fromString (packageNameString name) <> "' for common mistakes" let pkgChecks = -- MSS 2017-12-12: Try out a few different variants of -- pkgDesc to try and provoke an error or warning. I don't -- know why, but when using `Just pkgDesc`, it appears that -- Cabal does not detect that `^>=` is used with -- `cabal-version: 1.24` or earlier. It seems like pkgDesc -- (the one we create) does not populate the `buildDepends` -- field, whereas flattenPackageDescription from Cabal -- does. In any event, using `Nothing` seems more logical -- for this check anyway, and the fallback to `Just pkgDesc` -- is just a crazy sanity check. case Check.checkPackage gpd Nothing of [] -> Check.checkPackage gpd (Just pkgDesc) x -> x fileChecks <- liftIO $ Check.checkPackageFiles minBound pkgDesc (toFilePath pkgDir) let checks = pkgChecks ++ fileChecks (errors, warnings) = let criticalIssue (Check.PackageBuildImpossible _) = True criticalIssue (Check.PackageDistInexcusable _) = True criticalIssue _ = False in List.partition criticalIssue checks unless (null warnings) $ logWarn $ "Package check reported the following warnings:\n" <> mconcat (List.intersperse "\n" . fmap displayShow $ warnings) case NE.nonEmpty errors of Nothing -> pure () Just ne -> throwM $ CheckException ne buildExtractedTarball :: HasEnvConfig env => ResolvedPath Dir -> RIO env () buildExtractedTarball pkgDir = do envConfig <- view envConfigL localPackageToBuild <- readLocalPackage $ resolvedAbsolute pkgDir -- We remove the path based on the name of the package let isPathToRemove path = do localPackage <- readLocalPackage path pure $ packageName (lpPackage localPackage) == packageName (lpPackage localPackageToBuild) pathsToKeep <- fmap Map.fromList $ flip filterM (Map.toList (smwProject (bcSMWanted (envConfigBuildConfig envConfig)))) $ fmap not . isPathToRemove . resolvedAbsolute . ppResolvedDir . snd pp <- mkProjectPackage YesPrintWarnings pkgDir False let adjustEnvForBuild env = let updatedEnvConfig = envConfig { envConfigSourceMap = updatePackagesInSourceMap (envConfigSourceMap envConfig) , envConfigBuildConfig = updateBuildConfig (envConfigBuildConfig envConfig) } updateBuildConfig bc = bc { bcConfig = (bcConfig bc) { configBuild = defaultBuildOpts { boptsTests = True } } } in set envConfigL updatedEnvConfig env updatePackagesInSourceMap sm = sm {smProject = Map.insert (cpName $ ppCommon pp) pp pathsToKeep} local adjustEnvForBuild $ build Nothing -- | Version of 'checkSDistTarball' that first saves lazy bytestring to -- temporary directory and then calls 'checkSDistTarball' on it. checkSDistTarball' :: HasEnvConfig env => SDistOpts -> String -- ^ Tarball name -> L.ByteString -- ^ Tarball contents as a byte string -> RIO env () checkSDistTarball' opts name bytes = withSystemTempDir "stack" $ \tpath -> do npath <- (tpath ) `liftM` parseRelFile name liftIO $ L.writeFile (toFilePath npath) bytes checkSDistTarball opts npath withTempTarGzContents :: Path Abs File -- ^ Location of tarball -> (Path Abs Dir -> RIO env a) -- ^ Perform actions given dir with tarball contents -> RIO env a withTempTarGzContents apath f = withSystemTempDir "stack" $ \tpath -> do archive <- liftIO $ L.readFile (toFilePath apath) liftIO . Tar.unpack (toFilePath tpath) . Tar.read . GZip.decompress $ archive f tpath -------------------------------------------------------------------------------- -- Copy+modified from the tar package to avoid issues with lazy IO ( see -- https://github.com/commercialhaskell/stack/issues/1344 ) packFileEntry :: FilePath -- ^ Full path to find the file on the local disk -> Tar.TarPath -- ^ Path to use for the tar Entry in the archive -> IO Tar.Entry packFileEntry filepath tarpath = do mtime <- getModTime filepath perms <- getPermissions filepath content <- S.readFile filepath let size = fromIntegral (S.length content) pure (Tar.simpleEntry tarpath (Tar.NormalFile (L.fromStrict content) size)) { Tar.entryPermissions = if executable perms then Tar.executableFilePermissions else Tar.ordinaryFilePermissions, Tar.entryTime = mtime } getModTime :: FilePath -> IO Tar.EpochTime getModTime path = do t <- getModificationTime path pure . floor . utcTimeToPOSIXSeconds $ t getDefaultPackageConfig :: (MonadIO m, MonadReader env m, HasEnvConfig env) => m PackageConfig getDefaultPackageConfig = do platform <- view platformL compilerVersion <- view actualCompilerVersionL pure PackageConfig { packageConfigEnableTests = False , packageConfigEnableBenchmarks = False , packageConfigFlags = mempty , packageConfigGhcOptions = [] , packageConfigCabalConfigOpts = [] , packageConfigCompilerVersion = compilerVersion , packageConfigPlatform = platform } stack-2.9.3.1/src/Stack/Setup.hs0000644000000000000000000031463114445022466014466 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ViewPatterns #-} module Stack.Setup ( setupEnv , ensureCompilerAndMsys , ensureDockerStackExe , SetupOpts (..) , defaultSetupInfoYaml , withNewLocalBuildTargets -- * Stack binary download , StackReleaseInfo , getDownloadVersion , stackVersion , preferredPlatforms , downloadStackReleaseInfo , downloadStackExe ) where import qualified Codec.Archive.Tar as Tar import Conduit ( ConduitT, await, concatMapMC, filterCE, foldMC, yield ) import Control.Applicative ( empty ) import Crypto.Hash ( SHA1 (..), SHA256 (..) ) import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.ByteString as S import qualified Data.ByteString.Lazy as LBS import qualified Data.Conduit.Binary as CB import Data.Conduit.Lazy ( lazyConsume ) import qualified Data.Conduit.List as CL import Data.Conduit.Process.Typed ( createSource ) import Data.Conduit.Zlib ( ungzip ) import Data.List.Split ( splitOn ) import qualified Data.Map as Map import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Encoding as T import qualified Data.Text.Lazy.Encoding as TL import qualified Data.Text.Encoding.Error as T import qualified Data.Yaml as Yaml import Distribution.System ( Arch (..), OS, Platform (..) ) import qualified Distribution.System as Cabal import Distribution.Text ( simpleParse ) import Distribution.Types.PackageName ( mkPackageName ) import Distribution.Version ( mkVersion ) import Network.HTTP.Client ( redirectCount ) import Network.HTTP.StackClient ( CheckHexDigest (..), HashCheck (..), getResponseBody , getResponseStatusCode, httpLbs, httpJSON , mkDownloadRequest, parseRequest, parseUrlThrow , setGitHubHeaders, setHashChecks, setLengthCheck , verifiedDownloadWithProgress, withResponse , setRequestMethod ) import Network.HTTP.Simple ( getResponseHeader ) import Pantry.Internal.AesonExtended ( Value (..), WithJSONWarnings (..), logJSONWarnings ) import Path ( (), dirname, filename, parent, parseAbsDir, parseAbsFile , parseRelDir, parseRelFile, toFilePath ) import Path.CheckInstall ( warnInstallSearchPathIssues ) import Path.Extended ( fileExtension ) import Path.Extra ( toFilePathNoTrailingSep ) import Path.IO hiding ( findExecutable, withSystemTempDir ) import RIO.List ( headMaybe, intercalate, intersperse, isPrefixOf , maximumByMaybe, sort, sortBy, stripPrefix ) import RIO.Process ( EnvVars, HasProcessContext (..), ProcessContext , augmentPath, augmentPathMap, doesExecutableExist, envVarsL , exeSearchPathL, getStdout, mkProcessContext, modifyEnvVars , proc, readProcess_, readProcessStdout, runProcess , runProcess_, setStdout, waitExitCode, withModifyEnvVars , withProcessWait, withWorkingDir, workingDirL ) import Stack.Build.Haddock ( shouldHaddockDeps ) import Stack.Build.Source ( hashSourceMapData, loadSourceMap ) import Stack.Build.Target ( NeedTargets (..), parseTargets ) import Stack.Constants import Stack.Constants.Config ( distRelativeDir ) import Stack.GhcPkg ( createDatabase, getGlobalDB, ghcPkgPathEnvVar , mkGhcPackagePath ) import Stack.Prelude import Stack.SourceMap import Stack.Setup.Installed ( Tool (..), extraDirs, filterTools, getCompilerVersion , installDir, listInstalled, markInstalled, tempInstallDir , toolString, unmarkInstalled ) import Stack.Storage.User ( loadCompilerPaths, saveCompilerPaths ) import Stack.Types.Build import Stack.Types.Compiler import Stack.Types.CompilerBuild import Stack.Types.Config import Stack.Types.Docker import Stack.Types.SourceMap import Stack.Types.Version import qualified System.Directory as D import System.Environment ( getExecutablePath, lookupEnv ) import System.IO.Error ( isPermissionError ) import System.FilePath ( searchPathSeparator ) import qualified System.FilePath as FP import System.Permissions ( setFileExecutable ) import System.Uname ( getRelease ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Setup" module data SetupException = UnsupportedSetupCombo OS Arch | MissingDependencies [String] | UnknownCompilerVersion (Set.Set Text) WantedCompiler (Set.Set ActualCompiler) | UnknownOSKey Text | GHCSanityCheckCompileFailed SomeException (Path Abs File) | WantedMustBeGHC | RequireCustomGHCVariant | ProblemWhileDecompressing (Path Abs File) | SetupInfoMissingSevenz | DockerStackExeNotFound Version Text | UnsupportedSetupConfiguration | InvalidGhcAt (Path Abs File) SomeException | MSYS2NotFound Text | UnwantedCompilerVersion | UnwantedArchitecture | SandboxedCompilerNotFound | CompilerNotFound [String] | GHCInfoNotValidUTF8 UnicodeException | GHCInfoNotListOfPairs | GHCInfoMissingGlobalPackageDB | GHCInfoMissingTargetPlatform | GHCInfoTargetPlatformInvalid String | CabalNotFound (Path Abs File) | HadrianScriptNotFound | URLInvalid String | UnknownArchiveExtension String | Unsupported7z | TarballInvalid String | TarballFileInvalid String (Path Abs File) | UnknownArchiveStructure (Path Abs File) | StackReleaseInfoNotFound String | StackBinaryArchiveNotFound [String] | WorkingDirectoryInvalidBug | HadrianBindistNotFound | DownloadAndInstallCompilerError | StackBinaryArchiveZipUnsupportedBug | StackBinaryArchiveUnsupported Text | StackBinaryNotInArchive String Text | FileTypeInArchiveInvalid Tar.Entry Text | BinaryUpgradeOnOSUnsupported Cabal.OS | BinaryUpgradeOnArchUnsupported Cabal.Arch | ExistingMSYS2NotDeleted (Path Abs Dir) IOException deriving (Show, Typeable) instance Exception SetupException where displayException (UnsupportedSetupCombo os arch) = concat [ "Error: [S-1852]\n" , "I don't know how to install GHC for " , show (os, arch) , ", please install manually" ] displayException (MissingDependencies tools) = concat [ "Error: [S-2126]\n" , "The following executables are missing and must be installed: " , intercalate ", " tools ] displayException (UnknownCompilerVersion oskeys wanted known) = concat [ "Error: [S-9443]\n" , "No setup information found for " , T.unpack $ utf8BuilderToText $ display wanted , " on your platform.\nThis probably means a GHC bindist has not yet been added for OS key '" , T.unpack (T.intercalate "', '" (sort $ Set.toList oskeys)) , "'.\nSupported versions: " , T.unpack (T.intercalate ", " (map compilerVersionText (sort $ Set.toList known))) ] displayException (UnknownOSKey oskey) = concat [ "Error: [S-6810]\n" , "Unable to find installation URLs for OS key: " , T.unpack oskey ] displayException (GHCSanityCheckCompileFailed e ghc) = concat [ "Error: [S-5159]\n" , "The GHC located at " , toFilePath ghc , " failed to compile a sanity check. Please see:\n\n" , " http://docs.haskellstack.org/en/stable/install_and_upgrade/\n\n" , "for more information. Exception was:\n" , displayException e ] displayException WantedMustBeGHC = "Error: [S-9030]\n" ++ "The wanted compiler must be GHC." displayException RequireCustomGHCVariant = "Error: [S-8948]\n" ++ "A custom '--ghc-variant' must be specified to use '--ghc-bindist'." displayException (ProblemWhileDecompressing archive) = concat [ "Error: [S-2905]\n" , "Problem while decompressing " , toFilePath archive ] displayException SetupInfoMissingSevenz = "Error: [S-9561]\n" ++ "SetupInfo missing Sevenz EXE/DLL." displayException (DockerStackExeNotFound stackVersion' osKey) = concat [ "Error: [S-1457]\n" , stackProgName , "-" , versionString stackVersion' , " executable not found for " , T.unpack osKey , "\nUse the '" , T.unpack dockerStackExeArgName , "' option to specify a location."] displayException UnsupportedSetupConfiguration = "Error: [S-7748]\n" ++ "Stack does not know how to install GHC on your system \ \configuration, please install manually." displayException (InvalidGhcAt compiler e) = concat [ "Error: [S-2476]\n" , "Found an invalid compiler at " , show (toFilePath compiler) , ": " , displayException e ] displayException (MSYS2NotFound osKey) = concat [ "Error: [S-5308]\n" , "MSYS2 not found for " , T.unpack osKey ] displayException UnwantedCompilerVersion = "Error: [S-5127]\n" ++ "Not the compiler version we want." displayException UnwantedArchitecture = "Error: [S-1540]\n" ++ "Not the architecture we want." displayException SandboxedCompilerNotFound = "Error: [S-9953]\n" ++ "Could not find sandboxed compiler." displayException (CompilerNotFound toTry) = concat [ "Error: [S-4764]\n" , "Could not find any of: " , show toTry ] displayException (GHCInfoNotValidUTF8 e) = concat [ "Error: [S-8668]\n" , "GHC info is not valid UTF-8: " , displayException e ] displayException GHCInfoNotListOfPairs = "Error: [S-4878]\n" ++ "GHC info does not parse as a list of pairs." displayException GHCInfoMissingGlobalPackageDB = "Error: [S-2965]\n" ++ "Key 'Global Package DB' not found in GHC info." displayException GHCInfoMissingTargetPlatform = "Error: [S-5219]\n" ++ "Key 'Target platform' not found in GHC info." displayException (GHCInfoTargetPlatformInvalid targetPlatform) = concat [ "Error: [S-8299]\n" , "Invalid target platform in GHC info: " , targetPlatform ] displayException (CabalNotFound compiler) = concat [ "Error: [S-2574]\n" , "Cabal library not found in global package database for " , toFilePath compiler ] displayException HadrianScriptNotFound = "Error: [S-1128]\n" ++ "No Hadrian build script found." displayException (URLInvalid url) = concat [ "Error: [S-1906]\n" , "`url` must be either an HTTP URL or a file path: " , url ] displayException (UnknownArchiveExtension url) = concat [ "Error: [S-1648]\n" , "Unknown extension for url: " , url ] displayException Unsupported7z = "Error: [S-4509]\n" ++ "Don't know how to deal with .7z files on non-Windows." displayException (TarballInvalid name) = concat [ "Error: [S-3158]\n" , name , " must be a tarball file." ] displayException (TarballFileInvalid name archiveFile) = concat [ "Error: [S-5252]\n" , "Invalid " , name , " filename: " , show archiveFile ] displayException (UnknownArchiveStructure archiveFile) = concat [ "Error: [S-1827]\n" , "Expected a single directory within unpacked " , toFilePath archiveFile ] displayException (StackReleaseInfoNotFound url) = concat [ "Error: [S-9476]\n" , "Could not get release information for Stack from: " , url ] displayException (StackBinaryArchiveNotFound platforms) = concat [ "Error: [S-4461]\n" , "Unable to find binary Stack archive for platforms: " , unwords platforms ] displayException WorkingDirectoryInvalidBug = bugReport "[S-2076]" "Invalid working directory." displayException HadrianBindistNotFound = "Error: [S-6617]\n" ++ "Can't find Hadrian-generated binary distribution." displayException DownloadAndInstallCompilerError = "Error: [S-7227]\n" ++ "'downloadAndInstallCompiler' should not be reached with ghc-git." displayException StackBinaryArchiveZipUnsupportedBug = bugReport "[S-3967]" "FIXME: Handle zip files." displayException (StackBinaryArchiveUnsupported archiveURL) = concat [ "Error: [S-6636]\n" , "Unknown archive format for Stack archive: " , T.unpack archiveURL ] displayException (StackBinaryNotInArchive exeName url) = concat [ "Error: [S-7871]\n" , "Stack executable " , exeName , " not found in archive from " , T.unpack url ] displayException (FileTypeInArchiveInvalid e url) = concat [ "Error: [S-5046]\n" , "Invalid file type for tar entry named " , Tar.entryPath e , " downloaded from " , T.unpack url ] displayException (BinaryUpgradeOnOSUnsupported os) = concat [ "Error: [S-4132]\n" , "Binary upgrade not yet supported on OS: " , show os ] displayException (BinaryUpgradeOnArchUnsupported arch) = concat [ "Error: [S-3249]\n" , "Binary upgrade not yet supported on arch: " , show arch ] displayException (ExistingMSYS2NotDeleted destDir e) = concat [ "Error: [S-4230]\n" , "Could not delete existing MSYS2 directory: " , toFilePath destDir , "\n" , displayException e ] -- | Type representing \'pretty\' exceptions thrown by functions exported by the -- "Stack.Setup" module data SetupPrettyException = GHCInstallFailed SomeException String String [String] (Path Abs Dir) (Path Abs Dir) (Path Abs Dir) deriving (Show, Typeable) instance Pretty SetupPrettyException where pretty (GHCInstallFailed ex step cmd args wd tempDir destDir) = "[S-7441]" <> line <> string (displayException ex) <> line <> hang 2 ( flow "Error encountered while" <+> fromString step <+> flow "GHC with" <> line <> style Shell (fromString (unwords (cmd : args))) <> line -- TODO: Figure out how to insert \ in the appropriate spots -- hang 2 (shellColor (fillSep (fromString cmd : map fromString args))) <> line <> <> flow "run in" <+> pretty wd ) <> blankLine <> flow "The following directories may now contain files, but won't be \ \used by Stack:" <> line <> " -" <+> pretty tempDir <> line <> " -" <+> pretty destDir <> blankLine <> flow "For more information consider rerunning with --verbose flag" <> line instance Exception SetupPrettyException -- | Type representing exceptions thrown by 'performPathChecking' data PerformPathCheckingException = ProcessExited ExitCode String [String] deriving (Show, Typeable) instance Exception PerformPathCheckingException where displayException (ProcessExited ec cmd args) = concat [ "Error: [S-1991]\n" , "Process exited with " , displayException ec , ": " , unwords (cmd:args) ] -- | Default location of the stack-setup.yaml file defaultSetupInfoYaml :: String defaultSetupInfoYaml = "https://raw.githubusercontent.com/commercialhaskell/stackage-content/master/stack/stack-setup-2.yaml" data SetupOpts = SetupOpts { soptsInstallIfMissing :: !Bool , soptsUseSystem :: !Bool -- ^ Should we use a system compiler installation, if available? , soptsWantedCompiler :: !WantedCompiler , soptsCompilerCheck :: !VersionCheck , soptsStackYaml :: !(Maybe (Path Abs File)) -- ^ If we got the desired GHC version from that file , soptsForceReinstall :: !Bool , soptsSanityCheck :: !Bool -- ^ Run a sanity check on the selected GHC , soptsSkipGhcCheck :: !Bool -- ^ Don't check for a compatible GHC version/architecture , soptsSkipMsys :: !Bool -- ^ Do not use a custom msys installation on Windows , soptsResolveMissingGHC :: !(Maybe Text) -- ^ Message shown to user for how to resolve the missing GHC , soptsGHCBindistURL :: !(Maybe String) -- ^ Alternate GHC binary distribution (requires custom GHCVariant) } deriving Show -- | Modify the environment variables (like PATH) appropriately, possibly doing installation too setupEnv :: NeedTargets -> BuildOptsCLI -> Maybe Text -- ^ Message to give user when necessary GHC is not available -> RIO BuildConfig EnvConfig setupEnv needTargets boptsCLI mResolveMissingGHC = do config <- view configL bc <- view buildConfigL let stackYaml = bcStackYaml bc platform <- view platformL wcVersion <- view wantedCompilerVersionL wanted <- view wantedCompilerVersionL actual <- either throwIO pure $ wantedToActual wanted let wc = actual^.whichCompilerL let sopts = SetupOpts { soptsInstallIfMissing = configInstallGHC config , soptsUseSystem = configSystemGHC config , soptsWantedCompiler = wcVersion , soptsCompilerCheck = configCompilerCheck config , soptsStackYaml = Just stackYaml , soptsForceReinstall = False , soptsSanityCheck = False , soptsSkipGhcCheck = configSkipGHCCheck config , soptsSkipMsys = configSkipMsys config , soptsResolveMissingGHC = mResolveMissingGHC , soptsGHCBindistURL = Nothing } (compilerPaths, ghcBin) <- ensureCompilerAndMsys sopts let compilerVer = cpCompilerVersion compilerPaths -- Modify the initial environment to include the GHC path, if a local GHC -- is being used menv0 <- view processContextL env <- either throwM (pure . removeHaskellEnvVars) $ augmentPathMap (map toFilePath $ edBins ghcBin) (view envVarsL menv0) menv <- mkProcessContext env logDebug "Resolving package entries" (sourceMap, sourceMapHash) <- runWithGHC menv compilerPaths $ do smActual <- actualFromGhc (bcSMWanted bc) compilerVer let actualPkgs = Map.keysSet (smaDeps smActual) <> Map.keysSet (smaProject smActual) prunedActual = smActual { smaGlobal = pruneGlobals (smaGlobal smActual) actualPkgs } haddockDeps = shouldHaddockDeps (configBuild config) targets <- parseTargets needTargets haddockDeps boptsCLI prunedActual sourceMap <- loadSourceMap targets boptsCLI smActual sourceMapHash <- hashSourceMapData boptsCLI sourceMap pure (sourceMap, sourceMapHash) let envConfig0 = EnvConfig { envConfigBuildConfig = bc , envConfigBuildOptsCLI = boptsCLI , envConfigSourceMap = sourceMap , envConfigSourceMapHash = sourceMapHash , envConfigCompilerPaths = compilerPaths } -- extra installation bin directories mkDirs <- runRIO envConfig0 extraBinDirs let mpath = Map.lookup "PATH" env depsPath <- either throwM pure $ augmentPath (toFilePath <$> mkDirs False) mpath localsPath <- either throwM pure $ augmentPath (toFilePath <$> mkDirs True) mpath deps <- runRIO envConfig0 packageDatabaseDeps runWithGHC menv compilerPaths $ createDatabase (cpPkg compilerPaths) deps localdb <- runRIO envConfig0 packageDatabaseLocal runWithGHC menv compilerPaths $ createDatabase (cpPkg compilerPaths) localdb extras <- runReaderT packageDatabaseExtra envConfig0 let mkGPP locals = mkGhcPackagePath locals localdb deps extras $ cpGlobalDB compilerPaths distDir <- runReaderT distRelativeDir envConfig0 >>= canonicalizePath executablePath <- liftIO getExecutablePath utf8EnvVars <- withProcessContext menv $ getUtf8EnvVars compilerVer mGhcRtsEnvVar <- liftIO $ lookupEnv "GHCRTS" envRef <- liftIO $ newIORef Map.empty let getProcessContext' es = do m <- readIORef envRef case Map.lookup es m of Just eo -> pure eo Nothing -> do eo <- mkProcessContext $ Map.insert "PATH" (if esIncludeLocals es then localsPath else depsPath) $ (if esIncludeGhcPackagePath es then Map.insert (ghcPkgPathEnvVar wc) (mkGPP (esIncludeLocals es)) else id) $ (if esStackExe es then Map.insert "STACK_EXE" (T.pack executablePath) else id) $ (if esLocaleUtf8 es then Map.union utf8EnvVars else id) $ case (soptsSkipMsys sopts, platform) of (False, Platform Cabal.I386 Cabal.Windows) -> Map.insert "MSYSTEM" "MINGW32" (False, Platform Cabal.X86_64 Cabal.Windows) -> Map.insert "MSYSTEM" "MINGW64" _ -> id -- See https://github.com/commercialhaskell/stack/issues/3444 $ case (esKeepGhcRts es, mGhcRtsEnvVar) of (True, Just ghcRts) -> Map.insert "GHCRTS" (T.pack ghcRts) _ -> id -- For reasoning and duplication, see: -- https://github.com/commercialhaskell/stack/issues/70 $ Map.insert "HASKELL_PACKAGE_SANDBOX" (T.pack $ toFilePathNoTrailingSep deps) $ Map.insert "HASKELL_PACKAGE_SANDBOXES" (T.pack $ if esIncludeLocals es then intercalate [searchPathSeparator] [ toFilePathNoTrailingSep localdb , toFilePathNoTrailingSep deps , "" ] else intercalate [searchPathSeparator] [ toFilePathNoTrailingSep deps , "" ]) $ Map.insert "HASKELL_DIST_DIR" (T.pack $ toFilePathNoTrailingSep distDir) -- Make sure that any .ghc.environment files -- are ignored, since we're setting up our -- own package databases. See -- https://github.com/commercialhaskell/stack/issues/4706 $ (case cpCompilerVersion compilerPaths of ACGhc version | version >= mkVersion [8, 4, 4] -> Map.insert "GHC_ENVIRONMENT" "-" _ -> id) env () <- atomicModifyIORef envRef $ \m' -> (Map.insert es eo m', ()) pure eo envOverride <- liftIO $ getProcessContext' minimalEnvSettings pure EnvConfig { envConfigBuildConfig = bc { bcConfig = addIncludeLib ghcBin $ set processContextL envOverride (view configL bc) { configProcessContextSettings = getProcessContext' } } , envConfigBuildOptsCLI = boptsCLI , envConfigSourceMap = sourceMap , envConfigSourceMapHash = sourceMapHash , envConfigCompilerPaths = compilerPaths } -- | A modified env which we know has an installed compiler on the PATH. data WithGHC env = WithGHC !CompilerPaths !env insideL :: Lens' (WithGHC env) env insideL = lens (\(WithGHC _ x) -> x) (\(WithGHC cp _) -> WithGHC cp) instance HasLogFunc env => HasLogFunc (WithGHC env) where logFuncL = insideL.logFuncL instance HasRunner env => HasRunner (WithGHC env) where runnerL = insideL.runnerL instance HasProcessContext env => HasProcessContext (WithGHC env) where processContextL = insideL.processContextL instance HasStylesUpdate env => HasStylesUpdate (WithGHC env) where stylesUpdateL = insideL.stylesUpdateL instance HasTerm env => HasTerm (WithGHC env) where useColorL = insideL.useColorL termWidthL = insideL.termWidthL instance HasPantryConfig env => HasPantryConfig (WithGHC env) where pantryConfigL = insideL.pantryConfigL instance HasConfig env => HasPlatform (WithGHC env) instance HasConfig env => HasGHCVariant (WithGHC env) instance HasConfig env => HasConfig (WithGHC env) where configL = insideL.configL instance HasBuildConfig env => HasBuildConfig (WithGHC env) where buildConfigL = insideL.buildConfigL instance HasCompiler (WithGHC env) where compilerPathsL = to (\(WithGHC cp _) -> cp) -- | Set up a modified environment which includes the modified PATH -- that GHC can be found on. This is needed for looking up global -- package information and ghc fingerprint (result from 'ghc --info'). runWithGHC :: HasConfig env => ProcessContext -> CompilerPaths -> RIO (WithGHC env) a -> RIO env a runWithGHC pc cp inner = do env <- ask let envg = WithGHC cp $ set envOverrideSettingsL (\_ -> pure pc) $ set processContextL pc env runRIO envg inner -- | special helper for GHCJS which needs an updated source map -- only project dependencies should get included otherwise source map hash will -- get changed and EnvConfig will become inconsistent rebuildEnv :: EnvConfig -> NeedTargets -> Bool -> BuildOptsCLI -> RIO env EnvConfig rebuildEnv envConfig needTargets haddockDeps boptsCLI = do let bc = envConfigBuildConfig envConfig cp = envConfigCompilerPaths envConfig compilerVer = smCompiler $ envConfigSourceMap envConfig runRIO (WithGHC cp bc) $ do smActual <- actualFromGhc (bcSMWanted bc) compilerVer let actualPkgs = Map.keysSet (smaDeps smActual) <> Map.keysSet (smaProject smActual) prunedActual = smActual { smaGlobal = pruneGlobals (smaGlobal smActual) actualPkgs } targets <- parseTargets needTargets haddockDeps boptsCLI prunedActual sourceMap <- loadSourceMap targets boptsCLI smActual pure $ envConfig {envConfigSourceMap = sourceMap, envConfigBuildOptsCLI = boptsCLI} -- | Some commands (script, ghci and exec) set targets dynamically -- see also the note about only local targets for rebuildEnv withNewLocalBuildTargets :: HasEnvConfig env => [Text] -> RIO env a -> RIO env a withNewLocalBuildTargets targets f = do envConfig <- view $ envConfigL haddockDeps <- view $ configL.to configBuild.to shouldHaddockDeps let boptsCLI = envConfigBuildOptsCLI envConfig envConfig' <- rebuildEnv envConfig NeedTargets haddockDeps $ boptsCLI {boptsCLITargets = targets} local (set envConfigL envConfig') f -- | Add the include and lib paths to the given Config addIncludeLib :: ExtraDirs -> Config -> Config addIncludeLib (ExtraDirs _bins includes libs) config = config { configExtraIncludeDirs = configExtraIncludeDirs config ++ map toFilePathNoTrailingSep includes , configExtraLibDirs = configExtraLibDirs config ++ map toFilePathNoTrailingSep libs } -- | Ensure both the compiler and the msys toolchain are installed and -- provide the PATHs to add if necessary ensureCompilerAndMsys :: (HasBuildConfig env, HasGHCVariant env) => SetupOpts -> RIO env (CompilerPaths, ExtraDirs) ensureCompilerAndMsys sopts = do getSetupInfo' <- memoizeRef getSetupInfo mmsys2Tool <- ensureMsys sopts getSetupInfo' msysPaths <- maybe (pure Nothing) (fmap Just . extraDirs) mmsys2Tool actual <- either throwIO pure $ wantedToActual $ soptsWantedCompiler sopts didWarn <- warnUnsupportedCompiler $ getGhcVersion actual (cp, ghcPaths) <- ensureCompiler sopts getSetupInfo' warnUnsupportedCompilerCabal cp didWarn let paths = maybe ghcPaths (ghcPaths <>) msysPaths pure (cp, paths) -- | See warnUnsupportedCompiler :: HasLogFunc env => Version -> RIO env Bool warnUnsupportedCompiler ghcVersion = do if | ghcVersion < mkVersion [7, 8] -> do logWarn $ "Stack will almost certainly fail with GHC below version 7.8, requested " <> fromString (versionString ghcVersion) logWarn "Valiantly attempting to run anyway, but I know this is doomed" logWarn "For more information, see: https://github.com/commercialhaskell/stack/issues/648" logWarn "" pure True | ghcVersion >= mkVersion [9, 5] -> do logWarn $ "Stack has not been tested with GHC versions above 9.4, and using " <> fromString (versionString ghcVersion) <> ", this may fail" pure True | otherwise -> do logDebug "Asking for a supported GHC version" pure False -- | See warnUnsupportedCompilerCabal :: HasLogFunc env => CompilerPaths -> Bool -- ^ already warned about GHC? -> RIO env () warnUnsupportedCompilerCabal cp didWarn = do unless didWarn $ void $ warnUnsupportedCompiler $ getGhcVersion $ cpCompilerVersion cp let cabalVersion = cpCabalVersion cp if | cabalVersion < mkVersion [1, 19, 2] -> do logWarn $ "Stack no longer supports Cabal versions below 1.19.2," logWarn $ "but version " <> fromString (versionString cabalVersion) <> " was found." logWarn "This invocation will most likely fail." logWarn "To fix this, either use an older version of Stack or a newer resolver" logWarn "Acceptable resolvers: lts-3.0/nightly-2015-05-05 or later" | cabalVersion >= mkVersion [3, 9] -> logWarn $ "Stack has not been tested with Cabal versions above 3.8, but version " <> fromString (versionString cabalVersion) <> " was found, this may fail" | otherwise -> pure () -- | Ensure that the msys toolchain is installed if necessary and -- provide the PATHs to add if necessary ensureMsys :: HasBuildConfig env => SetupOpts -> Memoized SetupInfo -> RIO env (Maybe Tool) ensureMsys sopts getSetupInfo' = do platform <- view platformL localPrograms <- view $ configL.to configLocalPrograms installed <- listInstalled localPrograms case platform of Platform _ Cabal.Windows | not (soptsSkipMsys sopts) -> case getInstalledTool installed (mkPackageName "msys2") (const True) of Just tool -> pure (Just tool) Nothing | soptsInstallIfMissing sopts -> do si <- runMemoized getSetupInfo' osKey <- getOSKey platform config <- view configL VersionedDownloadInfo version info <- case Map.lookup osKey $ siMsys2 si of Just x -> pure x Nothing -> throwIO $ MSYS2NotFound osKey let tool = Tool (PackageIdentifier (mkPackageName "msys2") version) Just <$> downloadAndInstallTool (configLocalPrograms config) info tool (installMsys2Windows si) | otherwise -> do logWarn "Continuing despite missing tool: msys2" pure Nothing _ -> pure Nothing installGhcBindist :: HasBuildConfig env => SetupOpts -> Memoized SetupInfo -> [Tool] -> RIO env (Tool, CompilerBuild) installGhcBindist sopts getSetupInfo' installed = do Platform expectedArch _ <- view platformL let wanted = soptsWantedCompiler sopts isWanted = isWantedCompiler (soptsCompilerCheck sopts) (soptsWantedCompiler sopts) config <- view configL ghcVariant <- view ghcVariantL wc <- either throwIO (pure . whichCompiler) $ wantedToActual wanted possibleCompilers <- case wc of Ghc -> do ghcBuilds <- getGhcBuilds forM ghcBuilds $ \ghcBuild -> do ghcPkgName <- parsePackageNameThrowing ("ghc" ++ ghcVariantSuffix ghcVariant ++ compilerBuildSuffix ghcBuild) pure (getInstalledTool installed ghcPkgName (isWanted . ACGhc), ghcBuild) let existingCompilers = concatMap (\(installedCompiler, compilerBuild) -> case (installedCompiler, soptsForceReinstall sopts) of (Just tool, False) -> [(tool, compilerBuild)] _ -> []) possibleCompilers logDebug $ "Found already installed GHC builds: " <> mconcat (intersperse ", " (map (fromString . compilerBuildName . snd) existingCompilers)) case existingCompilers of (tool, build_):_ -> pure (tool, build_) [] | soptsInstallIfMissing sopts -> do si <- runMemoized getSetupInfo' downloadAndInstallPossibleCompilers (map snd possibleCompilers) si (soptsWantedCompiler sopts) (soptsCompilerCheck sopts) (soptsGHCBindistURL sopts) | otherwise -> do let suggestion = fromMaybe (mconcat [ "To install the correct GHC into " , T.pack (toFilePath (configLocalPrograms config)) , ", try running 'stack setup' or use the '--install-ghc' flag." , " To use your system GHC installation, run \ \'stack config set system-ghc --global true', \ \or use the '--system-ghc' flag." ]) (soptsResolveMissingGHC sopts) throwM $ CompilerVersionMismatch Nothing -- FIXME ((\(x, y, _) -> (x, y)) <$> msystem) (soptsWantedCompiler sopts, expectedArch) ghcVariant (case possibleCompilers of [] -> CompilerBuildStandard (_, compilerBuild):_ -> compilerBuild) (soptsCompilerCheck sopts) (soptsStackYaml sopts) suggestion -- | Ensure compiler is installed, without worrying about msys ensureCompiler :: forall env. (HasConfig env, HasBuildConfig env, HasGHCVariant env) => SetupOpts -> Memoized SetupInfo -> RIO env (CompilerPaths, ExtraDirs) ensureCompiler sopts getSetupInfo' = do let wanted = soptsWantedCompiler sopts wc <- either throwIO (pure . whichCompiler) $ wantedToActual wanted hook <- ghcInstallHook hookIsExecutable <- handleIO (\_ -> pure False) $ if osIsWindows then doesFileExist hook -- can't really detect executable on windows, only file extension else executable <$> getPermissions hook Platform expectedArch _ <- view platformL let canUseCompiler cp | soptsSkipGhcCheck sopts = pure cp | not $ isWanted $ cpCompilerVersion cp = throwIO UnwantedCompilerVersion | cpArch cp /= expectedArch = throwIO UnwantedArchitecture | otherwise = pure cp isWanted = isWantedCompiler (soptsCompilerCheck sopts) (soptsWantedCompiler sopts) let checkCompiler :: Path Abs File -> RIO env (Maybe CompilerPaths) checkCompiler compiler = do eres <- tryAny $ pathsFromCompiler wc CompilerBuildStandard False compiler >>= canUseCompiler case eres of Left e -> do logDebug $ "Not using compiler at " <> displayShow (toFilePath compiler) <> ": " <> displayShow e pure Nothing Right cp -> pure $ Just cp mcp <- if | soptsUseSystem sopts -> do logDebug "Getting system compiler version" runConduit $ sourceSystemCompilers wanted .| concatMapMC checkCompiler .| await | hookIsExecutable -> do -- if the hook fails, we fall through to stacks sandboxed installation hookGHC <- runGHCInstallHook sopts hook maybe (pure Nothing) checkCompiler hookGHC | otherwise -> pure Nothing case mcp of Nothing -> ensureSandboxedCompiler sopts getSetupInfo' Just cp -> do let paths = ExtraDirs { edBins = [parent $ cpCompiler cp], edInclude = [], edLib = [] } pure (cp, paths) -- | Runs @STACK_ROOT\/hooks\/ghc-install.sh@. -- -- Reads and possibly validates the output of the process as the GHC -- binary and returns it. runGHCInstallHook :: HasBuildConfig env => SetupOpts -> Path Abs File -> RIO env (Maybe (Path Abs File)) runGHCInstallHook sopts hook = do logDebug "Getting hook installed compiler version" let wanted = soptsWantedCompiler sopts menv0 <- view processContextL menv <- mkProcessContext (Map.union (wantedCompilerToEnv wanted) $ removeHaskellEnvVars (view envVarsL menv0)) (exit, out) <- withProcessContext menv $ proc "sh" [toFilePath hook] readProcessStdout case exit of ExitSuccess -> do let ghcPath = stripNewline . TL.unpack . TL.decodeUtf8With T.lenientDecode $ out case parseAbsFile ghcPath of Just compiler -> do when (soptsSanityCheck sopts) $ sanityCheck compiler logDebug ("Using GHC compiler at: " <> fromString (toFilePath compiler)) pure (Just compiler) Nothing -> do logWarn ("Path to GHC binary is not a valid path: " <> fromString ghcPath) pure Nothing ExitFailure i -> do logWarn ("GHC install hook exited with code: " <> fromString (show i)) pure Nothing where wantedCompilerToEnv :: WantedCompiler -> EnvVars wantedCompilerToEnv (WCGhc ver) = Map.fromList [("HOOK_GHC_TYPE", "bindist") ,("HOOK_GHC_VERSION", T.pack (versionString ver)) ] wantedCompilerToEnv (WCGhcGit commit flavor) = Map.fromList [("HOOK_GHC_TYPE", "git") ,("HOOK_GHC_COMMIT", commit) ,("HOOK_GHC_FLAVOR", flavor) ,("HOOK_GHC_FLAVOUR", flavor) ] wantedCompilerToEnv (WCGhcjs ghcjs_ver ghc_ver) = Map.fromList [("HOOK_GHC_TYPE", "ghcjs") ,("HOOK_GHC_VERSION", T.pack (versionString ghc_ver)) ,("HOOK_GHCJS_VERSION", T.pack (versionString ghcjs_ver)) ] newlines :: [Char] newlines = ['\n', '\r'] stripNewline :: String -> String stripNewline str = filter (flip notElem newlines) str ensureSandboxedCompiler :: HasBuildConfig env => SetupOpts -> Memoized SetupInfo -> RIO env (CompilerPaths, ExtraDirs) ensureSandboxedCompiler sopts getSetupInfo' = do let wanted = soptsWantedCompiler sopts -- List installed tools config <- view configL let localPrograms = configLocalPrograms config installed <- listInstalled localPrograms logDebug $ "Installed tools: \n - " <> mconcat (intersperse "\n - " (map (fromString . toolString) installed)) (compilerTool, compilerBuild) <- case soptsWantedCompiler sopts of -- shall we build GHC from source? WCGhcGit commitId flavour -> buildGhcFromSource getSetupInfo' installed (configCompilerRepository config) commitId flavour _ -> installGhcBindist sopts getSetupInfo' installed paths <- extraDirs compilerTool wc <- either throwIO (pure . whichCompiler) $ wantedToActual wanted menv0 <- view processContextL m <- either throwM pure $ augmentPathMap (toFilePath <$> edBins paths) (view envVarsL menv0) menv <- mkProcessContext (removeHaskellEnvVars m) names <- case wanted of WCGhc version -> pure ["ghc-" ++ versionString version, "ghc"] WCGhcGit{} -> pure ["ghc"] WCGhcjs{} -> throwIO GhcjsNotSupported -- Previously, we used findExecutable to locate these executables. This was -- actually somewhat sloppy, as it could discover executables outside of the -- sandbox. This led to a specific issue on Windows with GHC 9.0.1. See -- https://gitlab.haskell.org/ghc/ghc/-/issues/20074. Instead, now, we look -- on the paths specified only. let loop [] = do logError $ "Looked for sandboxed compiler named one of: " <> displayShow names logError $ "Could not find it on the paths " <> displayShow (edBins paths) throwIO SandboxedCompilerNotFound loop (x:xs) = do res <- liftIO $ D.findExecutablesInDirectories (map toFilePath (edBins paths)) x case res of [] -> loop xs compiler:rest -> do unless (null rest) $ do logWarn "Found multiple candidate compilers:" for_ res $ \y -> logWarn $ "- " <> fromString y logWarn $ "This usually indicates a failed installation. Trying anyway with " <> fromString compiler parseAbsFile compiler compiler <- withProcessContext menv $ do compiler <- loop names -- Run this here to ensure that the sanity check uses the modified -- environment, otherwise we may infect GHC_PACKAGE_PATH and break sanity -- checks. when (soptsSanityCheck sopts) $ sanityCheck compiler pure compiler cp <- pathsFromCompiler wc compilerBuild True compiler pure (cp, paths) pathsFromCompiler :: forall env. HasConfig env => WhichCompiler -> CompilerBuild -> Bool -> Path Abs File -- ^ executable filepath -> RIO env CompilerPaths pathsFromCompiler wc compilerBuild isSandboxed compiler = withCache $ handleAny onErr $ do let dir = toFilePath $ parent compiler suffixNoVersion | osIsWindows = ".exe" | otherwise = "" msuffixWithVersion = do let prefix = case wc of Ghc -> "ghc-" fmap ("-" ++) $ stripPrefix prefix $ toFilePath $ filename compiler suffixes = maybe id (:) msuffixWithVersion [suffixNoVersion] findHelper :: (WhichCompiler -> [String]) -> RIO env (Path Abs File) findHelper getNames = do let toTry = [dir ++ name ++ suffix | suffix <- suffixes, name <- getNames wc] loop [] = throwIO $ CompilerNotFound toTry loop (guessedPath':rest) = do guessedPath <- parseAbsFile guessedPath' exists <- doesFileExist guessedPath if exists then pure guessedPath else loop rest logDebug $ "Looking for executable(s): " <> displayShow toTry loop toTry pkg <- fmap GhcPkgExe $ findHelper $ \case Ghc -> ["ghc-pkg"] menv0 <- view processContextL menv <- mkProcessContext (removeHaskellEnvVars (view envVarsL menv0)) interpreter <- findHelper $ \case Ghc -> ["runghc"] haddock <- findHelper $ \case Ghc -> ["haddock", "haddock-ghc"] infobs <- proc (toFilePath compiler) ["--info"] $ fmap (toStrictBytes . fst) . readProcess_ infotext <- case decodeUtf8' infobs of Left e -> throwIO $ GHCInfoNotValidUTF8 e Right info -> pure info infoPairs :: [(String, String)] <- case readMaybe $ T.unpack infotext of Nothing -> throwIO GHCInfoNotListOfPairs Just infoPairs -> pure infoPairs let infoMap = Map.fromList infoPairs eglobaldb <- tryAny $ case Map.lookup "Global Package DB" infoMap of Nothing -> throwIO GHCInfoMissingGlobalPackageDB Just db -> parseAbsDir db arch <- case Map.lookup "Target platform" infoMap of Nothing -> throwIO GHCInfoMissingTargetPlatform Just targetPlatform -> case simpleParse $ takeWhile (/= '-') targetPlatform of Nothing -> throwIO $ GHCInfoTargetPlatformInvalid targetPlatform Just arch -> pure arch compilerVer <- case wc of Ghc -> case Map.lookup "Project version" infoMap of Nothing -> do logWarn "Key 'Project version' not found in GHC info" getCompilerVersion wc compiler Just versionString' -> ACGhc <$> parseVersionThrowing versionString' globaldb <- case eglobaldb of Left e -> do logWarn "Parsing global DB from GHC info failed" logWarn $ displayShow e logWarn "Asking ghc-pkg directly" withProcessContext menv $ getGlobalDB pkg Right x -> pure x globalDump <- withProcessContext menv $ globalsFromDump pkg cabalPkgVer <- case Map.lookup cabalPackageName globalDump of Nothing -> throwIO $ CabalNotFound compiler Just dp -> pure $ pkgVersion $ dpPackageIdent dp pure CompilerPaths { cpBuild = compilerBuild , cpArch = arch , cpSandboxed = isSandboxed , cpCompilerVersion = compilerVer , cpCompiler = compiler , cpPkg = pkg , cpInterpreter = interpreter , cpHaddock = haddock , cpCabalVersion = cabalPkgVer , cpGlobalDB = globaldb , cpGhcInfo = infobs , cpGlobalDump = globalDump } where onErr = throwIO . InvalidGhcAt compiler withCache inner = do eres <- tryAny $ loadCompilerPaths compiler compilerBuild isSandboxed mres <- case eres of Left e -> do logWarn $ "Trouble loading CompilerPaths cache: " <> displayShow e pure Nothing Right x -> pure x case mres of Just cp -> cp <$ logDebug "Loaded compiler information from cache" Nothing -> do cp <- inner saveCompilerPaths cp `catchAny` \e -> logWarn ("Unable to save CompilerPaths cache: " <> displayShow e) pure cp buildGhcFromSource :: forall env. ( HasTerm env , HasProcessContext env , HasBuildConfig env ) => Memoized SetupInfo -> [Tool] -> CompilerRepository -> Text -> Text -> RIO env (Tool, CompilerBuild) buildGhcFromSource getSetupInfo' installed (CompilerRepository url) commitId flavour = do config <- view configL let compilerTool = ToolGhcGit commitId flavour -- detect when the correct GHC is already installed if compilerTool `elem` installed then pure (compilerTool,CompilerBuildStandard) else do -- clone the repository and execute the given commands withRepo (SimpleRepo url commitId RepoGit) $ do -- withRepo is guaranteed to set workingDirL, so let's get it mcwd <- traverse parseAbsDir =<< view workingDirL cwd <- maybe (throwIO WorkingDirectoryInvalidBug) pure mcwd threads <- view $ configL.to configJobs let hadrianArgs = fmap T.unpack [ "-c" -- run ./boot and ./configure , "-j" <> tshow threads -- parallel build , "--flavour=" <> flavour -- selected flavour , "binary-dist" ] hadrianScripts | osIsWindows = hadrianScriptsWindows | otherwise = hadrianScriptsPosix foundHadrianPaths <- filterM doesFileExist $ (cwd ) <$> hadrianScripts hadrianPath <- maybe (throwIO HadrianScriptNotFound) pure $ listToMaybe foundHadrianPaths logSticky $ "Building GHC from source with `" <> display flavour <> "` flavour. It can take a long time (more than one hour)..." -- We need to provide an absolute path to the script since -- the process package only sets working directory _after_ -- discovering the executable proc (toFilePath hadrianPath) hadrianArgs runProcess_ -- find the bindist and install it bindistPath <- parseRelDir "_build/bindist" (_,files) <- listDir (cwd bindistPath) let isBindist p = do extension <- fileExtension (filename p) pure $ "ghc-" `isPrefixOf` (toFilePath (filename p)) && extension == ".xz" mbindist <- filterM isBindist files case mbindist of [bindist] -> do let bindist' = T.pack (toFilePath bindist) dlinfo = DownloadInfo { downloadInfoUrl = bindist' -- we can specify a filepath instead of a URL , downloadInfoContentLength = Nothing , downloadInfoSha1 = Nothing , downloadInfoSha256 = Nothing } ghcdlinfo = GHCDownloadInfo mempty mempty dlinfo installer | osIsWindows = installGHCWindows | otherwise = installGHCPosix ghcdlinfo si <- runMemoized getSetupInfo' _ <- downloadAndInstallTool (configLocalPrograms config) dlinfo compilerTool (installer si) pure (compilerTool, CompilerBuildStandard) _ -> do forM_ files (logDebug . fromString . (" - " ++) . toFilePath) throwIO HadrianBindistNotFound -- | Determine which GHC builds to use depending on which shared libraries are available -- on the system. getGhcBuilds :: HasConfig env => RIO env [CompilerBuild] getGhcBuilds = do config <- view configL case configGHCBuild config of Just ghcBuild -> pure [ghcBuild] Nothing -> determineGhcBuild where determineGhcBuild = do -- TODO: a more reliable, flexible, and data driven approach would be to actually download small -- "test" executables (from setup-info) that link to the same gmp/tinfo versions -- that GHC does (i.e. built in same environment as the GHC bindist). The algorithm would go -- something like this: -- -- check for previous 'uname -a'/`ldconfig -p` plus compiler version/variant in cache -- if cached, then use that as suffix -- otherwise: -- download setup-info -- go through all with right prefix for os/version/variant -- first try "standard" (no extra suffix), then the rest -- download "compatibility check" exe if not already downloaded -- try running it -- if successful, then choose that -- cache compiler suffix with the uname -a and ldconfig -p output hash plus compiler version -- -- Of course, could also try to make a static GHC bindist instead of all this rigamarole. platform <- view platformL case platform of Platform _ Cabal.Linux -> do -- Some systems don't have ldconfig in the PATH, so make sure to look in /sbin and /usr/sbin as well let sbinEnv m = Map.insert "PATH" ("/sbin:/usr/sbin" <> maybe "" (":" <>) (Map.lookup "PATH" m)) m eldconfigOut <- withModifyEnvVars sbinEnv $ proc "ldconfig" ["-p"] $ tryAny . fmap fst . readProcess_ let firstWords = case eldconfigOut of Right ldconfigOut -> mapMaybe (listToMaybe . T.words) $ T.lines $ T.decodeUtf8With T.lenientDecode $ LBS.toStrict ldconfigOut Left _ -> [] checkLib lib | libT `elem` firstWords = do logDebug ("Found shared library " <> libD <> " in 'ldconfig -p' output") pure True | osIsWindows = -- Cannot parse /usr/lib on Windows pure False | otherwise = do -- This is a workaround for the fact that libtinfo.so.x doesn't appear in -- the 'ldconfig -p' output on Arch or Slackware even when it exists. -- There doesn't seem to be an easy way to get the true list of directories -- to scan for shared libs, but this works for our particular cases. matches <- filterM (doesFileExist .( lib)) usrLibDirs case matches of [] -> logDebug ("Did not find shared library " <> libD) >> pure False (path:_) -> logDebug ("Found shared library " <> libD <> " in " <> fromString (Path.toFilePath path)) >> pure True where libT = T.pack (toFilePath lib) libD = fromString (toFilePath lib) hastinfo5 <- checkLib relFileLibtinfoSo5 hastinfo6 <- checkLib relFileLibtinfoSo6 hasncurses6 <- checkLib relFileLibncurseswSo6 hasgmp5 <- checkLib relFileLibgmpSo10 hasgmp4 <- checkLib relFileLibgmpSo3 let libComponents = concat [ [["tinfo6"] | hastinfo6 && hasgmp5] , [[] | hastinfo5 && hasgmp5] , [["ncurses6"] | hasncurses6 && hasgmp5 ] , [["gmp4"] | hasgmp4 ] ] useBuilds $ map (\c -> case c of [] -> CompilerBuildStandard _ -> CompilerBuildSpecialized (intercalate "-" c)) libComponents Platform _ Cabal.FreeBSD -> do let getMajorVer = readMaybe <=< headMaybe . (splitOn ".") majorVer <- getMajorVer <$> sysRelease if majorVer >= Just (12 :: Int) then useBuilds [CompilerBuildSpecialized "ino64"] else useBuilds [CompilerBuildStandard] Platform _ Cabal.OpenBSD -> do releaseStr <- mungeRelease <$> sysRelease useBuilds [CompilerBuildSpecialized releaseStr] _ -> useBuilds [CompilerBuildStandard] useBuilds builds = do logDebug $ "Potential GHC builds: " <> mconcat (intersperse ", " (map (fromString . compilerBuildName) builds)) pure builds -- | Encode an OpenBSD version (like "6.1") into a valid argument for -- CompilerBuildSpecialized, so "maj6-min1". Later version numbers are prefixed -- with "r". -- The result r must be such that "ghc-" ++ r is a valid package name, -- as recognized by parsePackageNameFromString. mungeRelease :: String -> String mungeRelease = intercalate "-" . prefixMaj . splitOn "." where prefixFst pfx k (rev : revs) = (pfx ++ rev) : k revs prefixFst _ _ [] = [] prefixMaj = prefixFst "maj" prefixMin prefixMin = prefixFst "min" (map ('r':)) sysRelease :: HasLogFunc env => RIO env String sysRelease = handleIO (\e -> do logWarn $ "Could not query OS version: " <> displayShow e pure "") (liftIO getRelease) -- | Ensure Docker container-compatible 'stack' executable is downloaded ensureDockerStackExe :: HasConfig env => Platform -> RIO env (Path Abs File) ensureDockerStackExe containerPlatform = do config <- view configL containerPlatformDir <- runReaderT platformOnlyRelDir (containerPlatform,PlatformVariantNone) let programsPath = configLocalProgramsBase config containerPlatformDir tool = Tool (PackageIdentifier (mkPackageName "stack") stackVersion) stackExeDir <- installDir programsPath tool let stackExePath = stackExeDir relFileStack stackExeExists <- doesFileExist stackExePath unless stackExeExists $ do logInfo $ "Downloading Docker-compatible " <> fromString stackProgName <> " executable" sri <- downloadStackReleaseInfo Nothing Nothing (Just (versionString stackMinorVersion)) platforms <- runReaderT preferredPlatforms (containerPlatform, PlatformVariantNone) downloadStackExe platforms sri stackExeDir False (const $ pure ()) pure stackExePath -- | Get all executables on the path that might match the wanted compiler sourceSystemCompilers :: (HasProcessContext env, HasLogFunc env) => WantedCompiler -> ConduitT i (Path Abs File) (RIO env) () sourceSystemCompilers wanted = do searchPath <- view exeSearchPathL names <- case wanted of WCGhc version -> pure [ "ghc-" ++ versionString version , "ghc" ] WCGhcjs{} -> throwIO GhcjsNotSupported WCGhcGit{} -> pure [] -- only use sandboxed versions for_ names $ \name -> for_ searchPath $ \dir -> do fp <- resolveFile' $ addExe $ dir FP. name exists <- doesFileExist fp when exists $ yield fp where addExe | osIsWindows = (++ ".exe") | otherwise = id -- | Download the most recent SetupInfo getSetupInfo :: HasConfig env => RIO env SetupInfo getSetupInfo = do config <- view configL let inlineSetupInfo = configSetupInfoInline config locations' = configSetupInfoLocations config locations = if null locations' then [defaultSetupInfoYaml] else locations' resolvedSetupInfos <- mapM loadSetupInfo locations pure (inlineSetupInfo <> mconcat resolvedSetupInfos) where loadSetupInfo urlOrFile = do bs <- case parseUrlThrow urlOrFile of Just req -> liftM (LBS.toStrict . getResponseBody) $ httpLbs req Nothing -> liftIO $ S.readFile urlOrFile WithJSONWarnings si warnings <- either throwM pure (Yaml.decodeEither' bs) when (urlOrFile /= defaultSetupInfoYaml) $ logJSONWarnings urlOrFile warnings pure si getInstalledTool :: [Tool] -- ^ already installed -> PackageName -- ^ package to find -> (Version -> Bool) -- ^ which versions are acceptable -> Maybe Tool getInstalledTool installed name goodVersion = Tool <$> maximumByMaybe (comparing pkgVersion) (filterTools name goodVersion installed) downloadAndInstallTool :: (HasTerm env, HasBuildConfig env) => Path Abs Dir -> DownloadInfo -> Tool -> (Path Abs File -> ArchiveType -> Path Abs Dir -> Path Abs Dir -> RIO env ()) -> RIO env Tool downloadAndInstallTool programsDir downloadInfo tool installer = do ensureDir programsDir (file, at) <- downloadFromInfo programsDir downloadInfo tool dir <- installDir programsDir tool tempDir <- tempInstallDir programsDir tool liftIO $ ignoringAbsence (removeDirRecur tempDir) ensureDir tempDir unmarkInstalled programsDir tool installer file at tempDir dir markInstalled programsDir tool liftIO $ ignoringAbsence (removeDirRecur tempDir) pure tool downloadAndInstallCompiler :: (HasBuildConfig env, HasGHCVariant env) => CompilerBuild -> SetupInfo -> WantedCompiler -> VersionCheck -> Maybe String -> RIO env Tool downloadAndInstallCompiler ghcBuild si wanted@(WCGhc version) versionCheck mbindistURL = do ghcVariant <- view ghcVariantL (selectedVersion, downloadInfo) <- case mbindistURL of Just bindistURL -> do case ghcVariant of GHCCustom _ -> pure () _ -> throwM RequireCustomGHCVariant pure (version, GHCDownloadInfo mempty mempty DownloadInfo { downloadInfoUrl = T.pack bindistURL , downloadInfoContentLength = Nothing , downloadInfoSha1 = Nothing , downloadInfoSha256 = Nothing }) _ -> do ghcKey <- getGhcKey ghcBuild case Map.lookup ghcKey $ siGHCs si of Nothing -> throwM $ UnknownOSKey ghcKey Just pairs_ -> getWantedCompilerInfo ghcKey versionCheck wanted ACGhc pairs_ config <- view configL let installer = case configPlatform config of Platform _ Cabal.Windows -> installGHCWindows _ -> installGHCPosix downloadInfo logInfo $ "Preparing to install GHC" <> (case ghcVariant of GHCStandard -> "" v -> " (" <> fromString (ghcVariantName v) <> ")") <> (case ghcBuild of CompilerBuildStandard -> "" b -> " (" <> fromString (compilerBuildName b) <> ")") <> " to an isolated location." logInfo "This will not interfere with any system-level installation." ghcPkgName <- parsePackageNameThrowing ("ghc" ++ ghcVariantSuffix ghcVariant ++ compilerBuildSuffix ghcBuild) let tool = Tool $ PackageIdentifier ghcPkgName selectedVersion downloadAndInstallTool (configLocalPrograms config) (gdiDownloadInfo downloadInfo) tool (installer si) downloadAndInstallCompiler _ _ WCGhcjs{} _ _ = throwIO GhcjsNotSupported downloadAndInstallCompiler _ _ WCGhcGit{} _ _ = throwIO DownloadAndInstallCompilerError getWantedCompilerInfo :: (Ord k, MonadThrow m) => Text -> VersionCheck -> WantedCompiler -> (k -> ActualCompiler) -> Map k a -> m (k, a) getWantedCompilerInfo key versionCheck wanted toCV pairs_ = case mpair of Just pair -> pure pair Nothing -> throwM $ UnknownCompilerVersion (Set.singleton key) wanted (Set.fromList $ map toCV (Map.keys pairs_)) where mpair = listToMaybe $ sortBy (flip (comparing fst)) $ filter (isWantedCompiler versionCheck wanted . toCV . fst) (Map.toList pairs_) -- | Download and install the first available compiler build. downloadAndInstallPossibleCompilers :: (HasGHCVariant env, HasBuildConfig env) => [CompilerBuild] -> SetupInfo -> WantedCompiler -> VersionCheck -> Maybe String -> RIO env (Tool, CompilerBuild) downloadAndInstallPossibleCompilers possibleCompilers si wanted versionCheck mbindistURL = go possibleCompilers Nothing where -- This will stop as soon as one of the builds doesn't throw an @UnknownOSKey@ or -- @UnknownCompilerVersion@ exception (so it will only try subsequent builds if one is nonexistent, -- not if the download or install fails for some other reason). -- The @Unknown*@ exceptions thrown by each attempt are combined into a single exception -- (if only @UnknownOSKey@ is thrown, then the first of those is rethrown, but if any -- @UnknownCompilerVersion@s are thrown then the attempted OS keys and available versions -- are unioned). go [] Nothing = throwM UnsupportedSetupConfiguration go [] (Just e) = throwM e go (b:bs) e = do logDebug $ "Trying to setup GHC build: " <> fromString (compilerBuildName b) er <- try $ downloadAndInstallCompiler b si wanted versionCheck mbindistURL case er of Left e'@(UnknownCompilerVersion ks' w' vs') -> case e of Nothing -> go bs (Just e') Just (UnknownOSKey k) -> go bs $ Just $ UnknownCompilerVersion (Set.insert k ks') w' vs' Just (UnknownCompilerVersion ks _ vs) -> go bs $ Just $ UnknownCompilerVersion (Set.union ks' ks) w' (Set.union vs' vs) Just x -> throwM x Left e'@(UnknownOSKey k') -> case e of Nothing -> go bs (Just e') Just (UnknownOSKey _) -> go bs e Just (UnknownCompilerVersion ks w vs) -> go bs $ Just $ UnknownCompilerVersion (Set.insert k' ks) w vs Just x -> throwM x Left e' -> throwM e' Right r -> pure (r, b) getGhcKey :: (MonadReader env m, HasPlatform env, HasGHCVariant env, MonadThrow m) => CompilerBuild -> m Text getGhcKey ghcBuild = do ghcVariant <- view ghcVariantL platform <- view platformL osKey <- getOSKey platform pure $ osKey <> T.pack (ghcVariantSuffix ghcVariant) <> T.pack (compilerBuildSuffix ghcBuild) getOSKey :: (MonadThrow m) => Platform -> m Text getOSKey platform = case platform of Platform I386 Cabal.Linux -> pure "linux32" Platform X86_64 Cabal.Linux -> pure "linux64" Platform I386 Cabal.OSX -> pure "macosx" Platform X86_64 Cabal.OSX -> pure "macosx" Platform I386 Cabal.FreeBSD -> pure "freebsd32" Platform X86_64 Cabal.FreeBSD -> pure "freebsd64" Platform I386 Cabal.OpenBSD -> pure "openbsd32" Platform X86_64 Cabal.OpenBSD -> pure "openbsd64" Platform I386 Cabal.Windows -> pure "windows32" Platform X86_64 Cabal.Windows -> pure "windows64" Platform Arm Cabal.Linux -> pure "linux-armv7" Platform AArch64 Cabal.Linux -> pure "linux-aarch64" Platform Sparc Cabal.Linux -> pure "linux-sparc" Platform AArch64 Cabal.OSX -> pure "macosx-aarch64" Platform AArch64 Cabal.FreeBSD -> pure "freebsd-aarch64" Platform arch os -> throwM $ UnsupportedSetupCombo os arch downloadOrUseLocal :: (HasTerm env, HasBuildConfig env) => Text -> DownloadInfo -> Path Abs File -> RIO env (Path Abs File) downloadOrUseLocal downloadLabel downloadInfo destination = case url of (parseUrlThrow -> Just _) -> do ensureDir (parent destination) chattyDownload downloadLabel downloadInfo destination pure destination (parseAbsFile -> Just path) -> do warnOnIgnoredChecks pure path (parseRelFile -> Just path) -> do warnOnIgnoredChecks root <- view projectRootL pure (root path) _ -> throwIO $ URLInvalid url where url = T.unpack $ downloadInfoUrl downloadInfo warnOnIgnoredChecks = do let DownloadInfo{downloadInfoContentLength=contentLength, downloadInfoSha1=sha1, downloadInfoSha256=sha256} = downloadInfo when (isJust contentLength) $ logWarn "`content-length` is not checked and should not be specified when `url` is a file path" when (isJust sha1) $ logWarn "`sha1` is not checked and should not be specified when `url` is a file path" when (isJust sha256) $ logWarn "`sha256` is not checked and should not be specified when `url` is a file path" downloadFromInfo :: (HasTerm env, HasBuildConfig env) => Path Abs Dir -> DownloadInfo -> Tool -> RIO env (Path Abs File, ArchiveType) downloadFromInfo programsDir downloadInfo tool = do archiveType <- case extension of ".tar.xz" -> pure TarXz ".tar.bz2" -> pure TarBz2 ".tar.gz" -> pure TarGz ".7z.exe" -> pure SevenZ _ -> throwIO $ UnknownArchiveExtension url relativeFile <- parseRelFile $ toolString tool ++ extension let destinationPath = programsDir relativeFile localPath <- downloadOrUseLocal (T.pack (toolString tool)) downloadInfo destinationPath pure (localPath, archiveType) where url = T.unpack $ downloadInfoUrl downloadInfo extension = loop url where loop fp | ext `elem` [".tar", ".bz2", ".xz", ".exe", ".7z", ".gz"] = loop fp' ++ ext | otherwise = "" where (fp', ext) = FP.splitExtension fp data ArchiveType = TarBz2 | TarXz | TarGz | SevenZ installGHCPosix :: HasConfig env => GHCDownloadInfo -> SetupInfo -> Path Abs File -> ArchiveType -> Path Abs Dir -> Path Abs Dir -> RIO env () installGHCPosix downloadInfo _ archiveFile archiveType tempDir destDir = do platform <- view platformL menv0 <- view processContextL menv <- mkProcessContext (removeHaskellEnvVars (view envVarsL menv0)) logDebug $ "menv = " <> displayShow (view envVarsL menv) (zipTool', compOpt) <- case archiveType of TarXz -> pure ("xz", 'J') TarBz2 -> pure ("bzip2", 'j') TarGz -> pure ("gzip", 'z') SevenZ -> throwIO Unsupported7z -- Slight hack: OpenBSD's tar doesn't support xz. -- https://github.com/commercialhaskell/stack/issues/2283#issuecomment-237980986 let tarDep = case (platform, archiveType) of (Platform _ Cabal.OpenBSD, TarXz) -> checkDependency "gtar" _ -> checkDependency "tar" (zipTool, makeTool, tarTool) <- checkDependencies $ (,,) <$> checkDependency zipTool' <*> (checkDependency "gmake" <|> checkDependency "make") <*> tarDep logDebug $ "ziptool: " <> fromString zipTool logDebug $ "make: " <> fromString makeTool logDebug $ "tar: " <> fromString tarTool let runStep step wd env cmd args = do menv' <- modifyEnvVars menv (Map.union env) let logLines lvl = CB.lines .| CL.mapM_ (lvl . displayBytesUtf8) logStdout = logLines logDebug logStderr = logLines logError void $ withWorkingDir (toFilePath wd) $ withProcessContext menv' $ sinkProcessStderrStdout cmd args logStderr logStdout `catchAny` \ex -> throwIO $ PrettyException (GHCInstallFailed ex step cmd args wd tempDir destDir) logSticky $ "Unpacking GHC into " <> fromString (toFilePath tempDir) <> " ..." logDebug $ "Unpacking " <> fromString (toFilePath archiveFile) runStep "unpacking" tempDir mempty tarTool [compOpt : "xf", toFilePath archiveFile] dir <- expectSingleUnpackedDir archiveFile tempDir mOverrideGccPath <- view $ configL.to configOverrideGccPath -- The make application uses the CC environment variable to configure the -- program for compiling C programs let mGccEnv = let gccEnvFromPath p = Map.singleton "CC" $ T.pack (toFilePath p) in gccEnvFromPath <$> mOverrideGccPath -- Data.Map.union provides a left-biased union, so mGccEnv will prevail let ghcConfigureEnv = fromMaybe Map.empty mGccEnv `Map.union` gdiConfigureEnv downloadInfo logSticky "Configuring GHC ..." runStep "configuring" dir ghcConfigureEnv (toFilePath $ dir relFileConfigure) (("--prefix=" ++ toFilePath destDir) : map T.unpack (gdiConfigureOpts downloadInfo)) logSticky "Installing GHC ..." runStep "installing" dir mempty makeTool ["install"] logStickyDone $ "Installed GHC." logDebug $ "GHC installed to " <> fromString (toFilePath destDir) -- | Check if given processes appear to be present, throwing an exception if -- missing. checkDependencies :: CheckDependency env a -> RIO env a checkDependencies (CheckDependency f) = f >>= either (throwIO . MissingDependencies) pure checkDependency :: HasProcessContext env => String -> CheckDependency env String checkDependency tool = CheckDependency $ do exists <- doesExecutableExist tool pure $ if exists then Right tool else Left [tool] newtype CheckDependency env a = CheckDependency (RIO env (Either [String] a)) deriving Functor instance Applicative (CheckDependency env) where pure x = CheckDependency $ pure (Right x) CheckDependency f <*> CheckDependency x = CheckDependency $ do f' <- f x' <- x pure $ case (f', x') of (Left e1, Left e2) -> Left $ e1 ++ e2 (Left e, Right _) -> Left e (Right _, Left e) -> Left e (Right f'', Right x'') -> Right $ f'' x'' instance Alternative (CheckDependency env) where empty = CheckDependency $ pure $ Left [] CheckDependency x <|> CheckDependency y = CheckDependency $ do res1 <- x case res1 of Left _ -> y Right x' -> pure $ Right x' installGHCWindows :: HasBuildConfig env => SetupInfo -> Path Abs File -> ArchiveType -> Path Abs Dir -> Path Abs Dir -> RIO env () installGHCWindows si archiveFile archiveType _tempDir destDir = do withUnpackedTarball7z "GHC" si archiveFile archiveType destDir logInfo $ "GHC installed to " <> fromString (toFilePath destDir) installMsys2Windows :: HasBuildConfig env => SetupInfo -> Path Abs File -> ArchiveType -> Path Abs Dir -> Path Abs Dir -> RIO env () installMsys2Windows si archiveFile archiveType _tempDir destDir = do exists <- liftIO $ D.doesDirectoryExist $ toFilePath destDir when exists $ liftIO (D.removeDirectoryRecursive $ toFilePath destDir) `catchIO` \e -> do throwM $ ExistingMSYS2NotDeleted destDir e withUnpackedTarball7z "MSYS2" si archiveFile archiveType destDir -- I couldn't find this officially documented anywhere, but you need to run -- the MSYS shell once in order to initialize some pacman stuff. Once that -- run happens, you can just run commands as usual. menv0 <- view processContextL newEnv0 <- modifyEnvVars menv0 $ Map.insert "MSYSTEM" "MSYS" newEnv <- either throwM pure $ augmentPathMap [toFilePath $ destDir relDirUsr relDirBin] (view envVarsL newEnv0) menv <- mkProcessContext newEnv withWorkingDir (toFilePath destDir) $ withProcessContext menv $ proc "sh" ["--login", "-c", "true"] runProcess_ -- No longer installing git, it's unreliable -- (https://github.com/commercialhaskell/stack/issues/1046) and the -- MSYS2-installed version has bad CRLF defaults. -- -- Install git. We could install other useful things in the future too. -- runCmd (Cmd (Just destDir) "pacman" menv ["-Sy", "--noconfirm", "git"]) Nothing -- | Unpack a compressed tarball using 7zip. Expects a single directory in -- the unpacked results, which is renamed to the destination directory. withUnpackedTarball7z :: HasBuildConfig env => String -- ^ Name of tool, used in error messages -> SetupInfo -> Path Abs File -- ^ Path to archive file -> ArchiveType -> Path Abs Dir -- ^ Destination directory. -> RIO env () withUnpackedTarball7z name si archiveFile archiveType destDir = do suffix <- case archiveType of TarXz -> pure ".xz" TarBz2 -> pure ".bz2" TarGz -> pure ".gz" _ -> throwIO $ TarballInvalid name tarFile <- case T.stripSuffix suffix $ T.pack $ toFilePath (filename archiveFile) of Nothing -> throwIO $ TarballFileInvalid name archiveFile Just x -> parseRelFile $ T.unpack x run7z <- setup7z si let tmpName = toFilePathNoTrailingSep (dirname destDir) ++ "-tmp" ensureDir (parent destDir) withRunInIO $ \run -> withTempDir (parent destDir) tmpName $ \tmpDir -> run $ do liftIO $ ignoringAbsence (removeDirRecur destDir) run7z tmpDir archiveFile run7z tmpDir (tmpDir tarFile) absSrcDir <- expectSingleUnpackedDir archiveFile tmpDir renameDir absSrcDir destDir expectSingleUnpackedDir :: (MonadIO m, MonadThrow m) => Path Abs File -> Path Abs Dir -> m (Path Abs Dir) expectSingleUnpackedDir archiveFile destDir = do contents <- listDir destDir case contents of ([dir], _ ) -> pure dir _ -> throwIO $ UnknownArchiveStructure archiveFile -- | Download 7z as necessary, and get a function for unpacking things. -- -- Returned function takes an unpack directory and archive. setup7z :: (HasBuildConfig env, MonadIO m) => SetupInfo -> RIO env (Path Abs Dir -> Path Abs File -> m ()) setup7z si = do dir <- view $ configL.to configLocalPrograms ensureDir dir let exeDestination = dir relFile7zexe dllDestination = dir relFile7zdll case (siSevenzDll si, siSevenzExe si) of (Just sevenzDll, Just sevenzExe) -> do _ <- downloadOrUseLocal "7z.dll" sevenzDll dllDestination exePath <- downloadOrUseLocal "7z.exe" sevenzExe exeDestination withRunInIO $ \run -> pure $ \outdir archive -> liftIO $ run $ do let cmd = toFilePath exePath args = [ "x" , "-o" ++ toFilePath outdir , "-y" , toFilePath archive ] let archiveDisplay = fromString $ FP.takeFileName $ toFilePath archive isExtract = FP.takeExtension (toFilePath archive) == ".tar" logInfo $ (if isExtract then "Extracting " else "Decompressing ") <> archiveDisplay <> "..." ec <- proc cmd args $ \pc -> if isExtract then withProcessWait (setStdout createSource pc) $ \p -> do total <- runConduit $ getStdout p .| filterCE (== 10) -- newline characters .| foldMC (\count bs -> do let count' = count + S.length bs logSticky $ "Extracted " <> display count' <> " files" pure count' ) 0 logStickyDone $ "Extracted total of " <> display total <> " files from " <> archiveDisplay waitExitCode p else runProcess pc when (ec /= ExitSuccess) $ liftIO $ throwM (ProblemWhileDecompressing archive) _ -> throwM SetupInfoMissingSevenz chattyDownload :: HasTerm env => Text -- ^ label -> DownloadInfo -- ^ URL, content-length, sha1, and sha256 -> Path Abs File -- ^ destination -> RIO env () chattyDownload label downloadInfo path = do let url = downloadInfoUrl downloadInfo req <- parseUrlThrow $ T.unpack url logSticky $ "Preparing to download " <> display label <> " ..." logDebug $ "Downloading from " <> display url <> " to " <> fromString (toFilePath path) <> " ..." hashChecks <- fmap catMaybes $ forM [ ("sha1", HashCheck SHA1, downloadInfoSha1) , ("sha256", HashCheck SHA256, downloadInfoSha256) ] $ \(name, constr, getter) -> case getter downloadInfo of Just bs -> do logDebug $ "Will check against " <> name <> " hash: " <> displayBytesUtf8 bs pure $ Just $ constr $ CheckHexDigestByteString bs Nothing -> pure Nothing when (null hashChecks) $ logWarn $ "No sha1 or sha256 found in metadata," <> " download hash won't be checked." let dReq = setHashChecks hashChecks $ setLengthCheck mtotalSize $ mkDownloadRequest req x <- verifiedDownloadWithProgress dReq path label mtotalSize if x then logStickyDone ("Downloaded " <> display label <> ".") else logStickyDone "Already downloaded." where mtotalSize = downloadInfoContentLength downloadInfo -- | Perform a basic sanity check of GHC sanityCheck :: (HasProcessContext env, HasLogFunc env) => Path Abs File -> RIO env () sanityCheck ghc = withSystemTempDir "stack-sanity-check" $ \dir -> do let fp = toFilePath $ dir relFileMainHs liftIO $ S.writeFile fp $ T.encodeUtf8 $ T.pack $ unlines [ "import Distribution.Simple" -- ensure Cabal library is present , "main = putStrLn \"Hello World\"" ] logDebug $ "Performing a sanity check on: " <> fromString (toFilePath ghc) eres <- withWorkingDir (toFilePath dir) $ proc (toFilePath ghc) [ fp , "-no-user-package-db" ] $ try . readProcess_ case eres of Left e -> throwIO $ GHCSanityCheckCompileFailed e ghc Right _ -> pure () -- TODO check that the output of running the command is correct -- Remove potentially confusing environment variables removeHaskellEnvVars :: Map Text Text -> Map Text Text removeHaskellEnvVars = Map.delete "GHC_PACKAGE_PATH" . Map.delete "GHC_ENVIRONMENT" . Map.delete "HASKELL_PACKAGE_SANDBOX" . Map.delete "HASKELL_PACKAGE_SANDBOXES" . Map.delete "HASKELL_DIST_DIR" . -- https://github.com/commercialhaskell/stack/issues/1460 Map.delete "DESTDIR" . -- https://github.com/commercialhaskell/stack/issues/3444 Map.delete "GHCRTS" -- | Get map of environment variables to set to change the GHC's encoding to UTF-8 getUtf8EnvVars :: (HasProcessContext env, HasPlatform env, HasLogFunc env) => ActualCompiler -> RIO env (Map Text Text) getUtf8EnvVars compilerVer = if getGhcVersion compilerVer >= mkVersion [7, 10, 3] -- GHC_CHARENC supported by GHC >=7.10.3 then pure $ Map.singleton "GHC_CHARENC" "UTF-8" else legacyLocale where legacyLocale = do menv <- view processContextL Platform _ os <- view platformL if os == Cabal.Windows then -- On Windows, locale is controlled by the code page, so we don't set any environment -- variables. pure Map.empty else do let checkedVars = map checkVar (Map.toList $ view envVarsL menv) -- List of environment variables that will need to be updated to set UTF-8 (because -- they currently do not specify UTF-8). needChangeVars = concatMap fst checkedVars -- Set of locale-related environment variables that have already have a value. existingVarNames = Set.unions (map snd checkedVars) -- True if a locale is already specified by one of the "global" locale variables. hasAnyExisting = any (`Set.member` existingVarNames) ["LANG", "LANGUAGE", "LC_ALL"] if null needChangeVars && hasAnyExisting then -- If no variables need changes and at least one "global" variable is set, no -- changes to environment need to be made. pure Map.empty else do -- Get a list of known locales by running @locale -a@. elocales <- tryAny $ fmap fst $ proc "locale" ["-a"] readProcess_ let -- Filter the list to only include locales with UTF-8 encoding. utf8Locales = case elocales of Left _ -> [] Right locales -> filter isUtf8Locale (T.lines $ T.decodeUtf8With T.lenientDecode $ LBS.toStrict locales) mfallback = getFallbackLocale utf8Locales when (isNothing mfallback) (logWarn "Warning: unable to set locale to UTF-8 encoding; GHC may fail with 'invalid character'") let -- Get the new values of variables to adjust. changes = Map.unions $ map (adjustedVarValue menv utf8Locales mfallback) needChangeVars -- Get the values of variables to add. adds | hasAnyExisting = -- If we already have a "global" variable, then nothing needs -- to be added. Map.empty | otherwise = -- If we don't already have a "global" variable, then set LANG to the -- fallback. case mfallback of Nothing -> Map.empty Just fallback -> Map.singleton "LANG" fallback pure (Map.union changes adds) -- Determines whether an environment variable is locale-related and, if so, whether it needs to -- be adjusted. checkVar :: (Text, Text) -> ([Text], Set Text) checkVar (k,v) = if k `elem` ["LANG", "LANGUAGE"] || "LC_" `T.isPrefixOf` k then if isUtf8Locale v then ([], Set.singleton k) else ([k], Set.singleton k) else ([], Set.empty) -- Adjusted value of an existing locale variable. Looks for valid UTF-8 encodings with -- same language /and/ territory, then with same language, and finally the first UTF-8 locale -- returned by @locale -a@. adjustedVarValue :: ProcessContext -> [Text] -> Maybe Text -> Text -> Map Text Text adjustedVarValue menv utf8Locales mfallback k = case Map.lookup k (view envVarsL menv) of Nothing -> Map.empty Just v -> case concatMap (matchingLocales utf8Locales) [ T.takeWhile (/= '.') v <> "." , T.takeWhile (/= '_') v <> "_"] of (v':_) -> Map.singleton k v' [] -> case mfallback of Just fallback -> Map.singleton k fallback Nothing -> Map.empty -- Determine the fallback locale, by looking for any UTF-8 locale prefixed with the list in -- @fallbackPrefixes@, and if not found, picking the first UTF-8 encoding returned by @locale -- -a@. getFallbackLocale :: [Text] -> Maybe Text getFallbackLocale utf8Locales = case concatMap (matchingLocales utf8Locales) fallbackPrefixes of (v:_) -> Just v [] -> case utf8Locales of [] -> Nothing (v:_) -> Just v -- Filter the list of locales for any with the given prefixes (case-insensitive). matchingLocales :: [Text] -> Text -> [Text] matchingLocales utf8Locales prefix = filter (\v -> T.toLower prefix `T.isPrefixOf` T.toLower v) utf8Locales -- Does the locale have one of the encodings in @utf8Suffixes@ (case-insensitive)? isUtf8Locale locale = any (\ v -> T.toLower v `T.isSuffixOf` T.toLower locale) utf8Suffixes -- Prefixes of fallback locales (case-insensitive) fallbackPrefixes = ["C.", "en_US.", "en_"] -- Suffixes of UTF-8 locales (case-insensitive) utf8Suffixes = [".UTF-8", ".utf8"] -- Binary Stack upgrades -- | Information on a binary release of Stack data StackReleaseInfo = SRIGitHub !Value -- ^ Metadata downloaded from GitHub releases about available binaries. | SRIHaskellStackOrg !HaskellStackOrg -- ^ Information on the latest available binary for the current platforms. data HaskellStackOrg = HaskellStackOrg { hsoUrl :: !Text , hsoVersion :: !Version } deriving Show downloadStackReleaseInfo :: (HasPlatform env, HasLogFunc env) => Maybe String -- GitHub org -> Maybe String -- GitHub repo -> Maybe String -- ^ optional version -> RIO env StackReleaseInfo downloadStackReleaseInfo Nothing Nothing Nothing = do platform <- view platformL -- Fallback list of URLs to try for upgrading. let urls0 = case platform of Platform X86_64 Cabal.Linux -> [ "https://get.haskellstack.org/upgrade/linux-x86_64-static.tar.gz" , "https://get.haskellstack.org/upgrade/linux-x86_64.tar.gz" ] Platform X86_64 Cabal.OSX -> [ "https://get.haskellstack.org/upgrade/osx-x86_64.tar.gz" ] Platform X86_64 Cabal.Windows -> [ "https://get.haskellstack.org/upgrade/windows-x86_64.tar.gz" ] _ -> [] -- Helper function: extract the version from a GitHub releases URL. let extractVersion loc = do version0 <- case reverse $ splitOn "/" $ T.unpack loc of _final:version0:_ -> Right version0 _ -> Left $ "Insufficient pieces in location: " ++ show loc version1 <- maybe (Left "no leading v on version") Right $ stripPrefix "v" version0 maybe (Left $ "Invalid version: " ++ show version1) Right $ parseVersion version1 -- Try out different URLs. If we've exhausted all of them, fall back to GitHub. loop [] = do logDebug "Could not get binary from haskellstack.org, trying GitHub" downloadStackReleaseInfoGitHub Nothing Nothing Nothing -- Try the next URL loop (url:urls) = do -- Make a HEAD request without any redirects req <- setRequestMethod "HEAD" <$> parseRequest (T.unpack url) res <- httpLbs req { redirectCount = 0 } -- Look for a redirect. We're looking for a standard GitHub releases -- URL where we can extract version information from. case getResponseHeader "location" res of [] -> logDebug "No location header found, continuing" *> loop urls -- Exactly one location header. [locBS] -> case decodeUtf8' locBS of Left e -> logDebug ("Invalid UTF8: " <> displayShow (locBS, e)) *> loop urls Right loc -> case extractVersion loc of Left s -> logDebug ("No version found: " <> displayShow (url, loc, s)) *> loop (loc:urls) -- We found a valid URL, let's use it! Right version -> do let hso = HaskellStackOrg { hsoUrl = loc , hsoVersion = version } logDebug $ "Downloading from haskellstack.org: " <> displayShow hso pure $ SRIHaskellStackOrg hso locs -> logDebug ("Multiple location headers found: " <> displayShow locs) *> loop urls loop urls0 downloadStackReleaseInfo morg mrepo mver = downloadStackReleaseInfoGitHub morg mrepo mver -- | Same as above, but always uses GitHub downloadStackReleaseInfoGitHub :: (MonadIO m, MonadThrow m) => Maybe String -- GitHub org -> Maybe String -- GitHub repo -> Maybe String -- ^ optional version -> m StackReleaseInfo downloadStackReleaseInfoGitHub morg mrepo mver = liftIO $ do let org = fromMaybe "commercialhaskell" morg repo = fromMaybe "stack" mrepo let url = concat [ "https://api.github.com/repos/" , org , "/" , repo , "/releases/" , case mver of Nothing -> "latest" Just ver -> "tags/v" ++ ver ] req <- parseRequest url res <- httpJSON $ setGitHubHeaders req let code = getResponseStatusCode res if code >= 200 && code < 300 then pure $ SRIGitHub $ getResponseBody res else throwIO $ StackReleaseInfoNotFound url preferredPlatforms :: (MonadReader env m, HasPlatform env, MonadThrow m) => m [(Bool, String)] preferredPlatforms = do Platform arch' os' <- view platformL (isWindows, os) <- case os' of Cabal.Linux -> pure (False, "linux") Cabal.Windows -> pure (True, "windows") Cabal.OSX -> pure (False, "osx") Cabal.FreeBSD -> pure (False, "freebsd") _ -> throwM $ BinaryUpgradeOnOSUnsupported os' arch <- case arch' of I386 -> pure "i386" X86_64 -> pure "x86_64" Arm -> pure "arm" _ -> throwM $ BinaryUpgradeOnArchUnsupported arch' hasgmp4 <- pure False -- FIXME import relevant code from Stack.Setup? checkLib $(mkRelFile "libgmp.so.3") let suffixes | hasgmp4 = ["-static", "-gmp4", ""] | otherwise = ["-static", ""] pure $ map (\suffix -> (isWindows, concat [os, "-", arch, suffix])) suffixes downloadStackExe :: HasConfig env => [(Bool, String)] -- ^ acceptable platforms -> StackReleaseInfo -> Path Abs Dir -- ^ destination directory -> Bool -- ^ perform PATH-aware checking, see #3232 -> (Path Abs File -> IO ()) -- ^ test the temp exe before renaming -> RIO env () downloadStackExe platforms0 archiveInfo destDir checkPath testExe = do (isWindows, archiveURL) <- let loop [] = throwIO $ StackBinaryArchiveNotFound (map snd platforms0) loop ((isWindows, p'):ps) = do let p = T.pack p' logInfo $ "Querying for archive location for platform: " <> fromString p' case findArchive archiveInfo p of Just x -> pure (isWindows, x) Nothing -> loop ps in loop platforms0 let (destFile, tmpFile) | isWindows = ( destDir relFileStackDotExe , destDir relFileStackDotTmpDotExe ) | otherwise = ( destDir relFileStack , destDir relFileStackDotTmp ) logInfo $ "Downloading from: " <> display archiveURL liftIO $ do case () of () | ".tar.gz" `T.isSuffixOf` archiveURL -> handleTarball tmpFile isWindows archiveURL | ".zip" `T.isSuffixOf` archiveURL -> throwIO StackBinaryArchiveZipUnsupportedBug | otherwise -> throwIO $ StackBinaryArchiveUnsupported archiveURL logInfo "Download complete, testing executable" platform <- view platformL -- We need to call getExecutablePath before we overwrite the -- currently running binary: after that, Linux will append -- (deleted) to the filename. currExe <- liftIO getExecutablePath liftIO $ do setFileExecutable (toFilePath tmpFile) testExe tmpFile case platform of Platform _ Cabal.Windows | FP.equalFilePath (toFilePath destFile) currExe -> do old <- parseAbsFile (toFilePath destFile ++ ".old") renameFile destFile old renameFile tmpFile destFile _ -> renameFile tmpFile destFile destDir' <- liftIO . D.canonicalizePath . toFilePath $ destDir warnInstallSearchPathIssues destDir' ["stack"] logInfo $ "New Stack executable available at " <> fromString (toFilePath destFile) when checkPath $ performPathChecking destFile currExe `catchAny` (logError . displayShow) where findArchive (SRIGitHub val) pattern = do Object top <- pure val Array assets <- KeyMap.lookup "assets" top getFirst $ fold $ fmap (First . findMatch pattern') assets where pattern' = mconcat ["-", pattern, "."] findMatch pattern'' (Object o) = do String name <- KeyMap.lookup "name" o guard $ not $ ".asc" `T.isSuffixOf` name guard $ pattern'' `T.isInfixOf` name String url <- KeyMap.lookup "browser_download_url" o Just url findMatch _ _ = Nothing findArchive (SRIHaskellStackOrg hso) _ = pure $ hsoUrl hso handleTarball :: Path Abs File -> Bool -> T.Text -> IO () handleTarball tmpFile isWindows url = do req <- fmap setGitHubHeaders $ parseUrlThrow $ T.unpack url withResponse req $ \res -> do entries <- fmap (Tar.read . LBS.fromChunks) $ lazyConsume $ getResponseBody res .| ungzip let loop Tar.Done = throwIO $ StackBinaryNotInArchive exeName url loop (Tar.Fail e) = throwM e loop (Tar.Next e es) = case FP.splitPath (Tar.entryPath e) of -- Ignore the first component, see: https://github.com/commercialhaskell/stack/issues/5288 [_ignored, name] | name == exeName -> do case Tar.entryContent e of Tar.NormalFile lbs _ -> do ensureDir destDir LBS.writeFile (toFilePath tmpFile) lbs _ -> throwIO $ FileTypeInArchiveInvalid e url _ -> loop es loop entries where exeName | isWindows = "stack.exe" | otherwise = "stack" -- | Ensure that the Stack executable download is in the same location -- as the currently running executable. See: -- https://github.com/commercialhaskell/stack/issues/3232 performPathChecking :: HasConfig env => Path Abs File -- ^ location of the newly downloaded file -> String -- ^ currently running executable -> RIO env () performPathChecking newFile executablePath = do executablePath' <- parseAbsFile executablePath unless (toFilePath newFile == executablePath) $ do logInfo $ "Also copying Stack executable to " <> fromString executablePath tmpFile <- parseAbsFile $ executablePath ++ ".tmp" eres <- tryIO $ do liftIO $ copyFile newFile tmpFile setFileExecutable (toFilePath tmpFile) liftIO $ renameFile tmpFile executablePath' logInfo "Stack executable copied successfully!" case eres of Right () -> pure () Left e | isPermissionError e -> do logWarn $ "Permission error when trying to copy: " <> displayShow e logWarn "Should I try to perform the file copy using sudo? This may fail" toSudo <- promptBool "Try using sudo? (y/n) " when toSudo $ do let run cmd args = do ec <- proc cmd args runProcess when (ec /= ExitSuccess) $ throwIO $ ProcessExited ec cmd args commands = [ ("sudo", [ "cp" , toFilePath newFile , toFilePath tmpFile ]) , ("sudo", [ "mv" , toFilePath tmpFile , executablePath ]) ] logInfo "Going to run the following commands:" logInfo "" forM_ commands $ \(cmd, args) -> logInfo $ "- " <> mconcat (intersperse " " (fromString <$> (cmd:args))) mapM_ (uncurry run) commands logInfo "" logInfo "sudo file copy worked!" | otherwise -> throwM e getDownloadVersion :: StackReleaseInfo -> Maybe Version getDownloadVersion (SRIGitHub val) = do Object o <- Just val String rawName <- KeyMap.lookup "name" o -- drop the "v" at the beginning of the name parseVersion $ T.unpack (T.drop 1 rawName) getDownloadVersion (SRIHaskellStackOrg hso) = Just $ hsoVersion hso stack-2.9.3.1/src/Stack/Setup/Installed.hs0000644000000000000000000001616314445022466016404 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} module Stack.Setup.Installed ( getCompilerVersion , markInstalled , unmarkInstalled , listInstalled , Tool (..) , toolString , toolNameString , parseToolText , filterTools , extraDirs , installDir , tempInstallDir ) where import qualified Data.ByteString.Char8 as S8 import qualified Data.ByteString.Lazy as BL import Data.Char ( isDigit ) import qualified Data.List as L import qualified Data.Text as T import qualified Data.Text.Encoding as T import Distribution.System ( Platform (..) ) import qualified Distribution.System as Cabal import Path import Path.IO import RIO.Process import Stack.Constants import Stack.Prelude import Stack.Types.Compiler import Stack.Types.Config data Tool = Tool PackageIdentifier -- ^ e.g. ghc-7.8.4, msys2-20150512 | ToolGhcGit !Text !Text -- ^ e.g. ghc-git-COMMIT_ID-FLAVOUR deriving (Eq) -- | 'Tool' values are ordered by name (being @ghc-git@, for @ToolGhcGit _ _@) -- alphabetically and then by version (later versions are ordered before -- earlier versions, where applicable). instance Ord Tool where compare (Tool pkgId1) (Tool pkgId2) = if pkgName1 == pkgName2 then compare pkgVersion2 pkgVersion1 -- Later versions ordered first else compare pkgName1 pkgName2 where PackageIdentifier pkgName1 pkgVersion1 = pkgId1 PackageIdentifier pkgName2 pkgVersion2 = pkgId2 compare (Tool pkgId) (ToolGhcGit _ _) = compare (pkgName pkgId) "ghc-git" compare (ToolGhcGit _ _) (Tool pkgId) = compare "ghc-git" (pkgName pkgId) compare (ToolGhcGit c1 f1) (ToolGhcGit c2 f2) = if f1 == f2 then compare c1 c2 else compare f1 f2 toolString :: Tool -> String toolString (Tool ident) = packageIdentifierString ident toolString (ToolGhcGit commit flavour) = "ghc-git-" ++ T.unpack commit ++ "-" ++ T.unpack flavour toolNameString :: Tool -> String toolNameString (Tool ident) = packageNameString $ pkgName ident toolNameString ToolGhcGit{} = "ghc-git" parseToolText :: Text -> Maybe Tool parseToolText (parseWantedCompiler -> Right WCGhcjs{}) = Nothing parseToolText (parseWantedCompiler -> Right (WCGhcGit c f)) = Just (ToolGhcGit c f) parseToolText (parsePackageIdentifier . T.unpack -> Just pkgId) = Just (Tool pkgId) parseToolText _ = Nothing markInstalled :: (MonadIO m, MonadThrow m) => Path Abs Dir -> Tool -> m () markInstalled programsPath tool = do fpRel <- parseRelFile $ toolString tool ++ ".installed" writeBinaryFileAtomic (programsPath fpRel) "installed" unmarkInstalled :: MonadIO m => Path Abs Dir -> Tool -> m () unmarkInstalled programsPath tool = liftIO $ do fpRel <- parseRelFile $ toolString tool ++ ".installed" ignoringAbsence (removeFile $ programsPath fpRel) listInstalled :: (MonadIO m, MonadThrow m) => Path Abs Dir -> m [Tool] listInstalled programsPath = do doesDirExist programsPath >>= \case False -> pure [] True -> do (_, files) <- listDir programsPath pure $ mapMaybe toTool files where toTool fp = do x <- T.stripSuffix ".installed" $ T.pack $ toFilePath $ filename fp parseToolText x filterTools :: PackageName -- ^ package to find -> (Version -> Bool) -- ^ which versions are acceptable -> [Tool] -- ^ tools to filter -> [PackageIdentifier] filterTools name goodVersion installed = [ pkgId | Tool pkgId <- installed , pkgName pkgId == name , goodVersion (pkgVersion pkgId) ] getCompilerVersion :: (HasProcessContext env, HasLogFunc env) => WhichCompiler -> Path Abs File -- ^ executable -> RIO env ActualCompiler getCompilerVersion wc exe = do case wc of Ghc -> do logDebug "Asking GHC for its version" bs <- fst <$> proc (toFilePath exe) ["--numeric-version"] readProcess_ let (_, ghcVersion) = versionFromEnd $ BL.toStrict bs x <- ACGhc <$> parseVersionThrowing (T.unpack $ T.decodeUtf8 ghcVersion) logDebug $ "GHC version is: " <> display x pure x where versionFromEnd = S8.spanEnd isValid . fst . S8.breakEnd isValid isValid c = c == '.' || isDigit c -- | Binary directories for the given installed package extraDirs :: HasConfig env => Tool -> RIO env ExtraDirs extraDirs tool = do config <- view configL dir <- installDir (configLocalPrograms config) tool case (configPlatform config, toolNameString tool) of (Platform _ Cabal.Windows, isGHC -> True) -> pure mempty { edBins = [ dir relDirBin , dir relDirMingw relDirBin ] } (Platform Cabal.I386 Cabal.Windows, "msys2") -> pure mempty { edBins = [ dir relDirMingw32 relDirBin , dir relDirUsr relDirBin , dir relDirUsr relDirLocal relDirBin ] , edInclude = [ dir relDirMingw32 relDirInclude ] , edLib = [ dir relDirMingw32 relDirLib , dir relDirMingw32 relDirBin ] } (Platform Cabal.X86_64 Cabal.Windows, "msys2") -> pure mempty { edBins = [ dir relDirMingw64 relDirBin , dir relDirUsr relDirBin , dir relDirUsr relDirLocal relDirBin ] , edInclude = [ dir relDirMingw64 relDirInclude ] , edLib = [ dir relDirMingw64 relDirLib , dir relDirMingw64 relDirBin ] } (_, isGHC -> True) -> pure mempty { edBins = [ dir relDirBin ] } (Platform _ x, toolName) -> do logWarn $ "binDirs: unexpected OS/tool combo: " <> displayShow (x, toolName) pure mempty where isGHC n = "ghc" == n || "ghc-" `L.isPrefixOf` n installDir :: (MonadReader env m, MonadThrow m) => Path Abs Dir -> Tool -> m (Path Abs Dir) installDir programsDir tool = do relativeDir <- parseRelDir $ toolString tool pure $ programsDir relativeDir tempInstallDir :: (MonadReader env m, MonadThrow m) => Path Abs Dir -> Tool -> m (Path Abs Dir) tempInstallDir programsDir tool = do relativeDir <- parseRelDir $ toolString tool ++ ".temp" pure $ programsDir relativeDir stack-2.9.3.1/src/Stack/SetupCmd.hs0000644000000000000000000000725514445022466015113 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -- | Install GHC/GHCJS and Cabal. module Stack.SetupCmd ( setup , setupParser , SetupCmdOpts (..) ) where import Control.Applicative import qualified Data.Text as T import qualified Options.Applicative as OA import qualified Options.Applicative.Builder.Extra as OA import qualified Options.Applicative.Types as OA import Path import Stack.Prelude import Stack.Setup import Stack.Types.Config import Stack.Types.Version data SetupCmdOpts = SetupCmdOpts { scoCompilerVersion :: !(Maybe WantedCompiler) , scoForceReinstall :: !Bool , scoGHCBindistURL :: !(Maybe String) , scoGHCJSBootOpts :: ![String] , scoGHCJSBootClean :: !Bool } setupParser :: OA.Parser SetupCmdOpts setupParser = SetupCmdOpts <$> OA.optional (OA.argument readVersion (OA.metavar "GHC_VERSION" <> OA.help ("Version of GHC to install, e.g. 7.10.2. " ++ "The default is to install the version implied by the resolver."))) <*> OA.boolFlags False "reinstall" "reinstalling GHC, even if available (incompatible with --system-ghc)" OA.idm <*> OA.optional (OA.strOption (OA.long "ghc-bindist" <> OA.metavar "URL" <> OA.help "Alternate GHC binary distribution (requires custom --ghc-variant)")) <*> OA.many (OA.strOption (OA.long "ghcjs-boot-options" <> OA.metavar "GHCJS_BOOT" <> OA.help "Additional ghcjs-boot options")) <*> OA.boolFlags True "ghcjs-boot-clean" "Control if ghcjs-boot should have --clean option present" OA.idm where readVersion = do s <- OA.readerAsk case parseWantedCompiler ("ghc-" <> T.pack s) of Left _ -> case parseWantedCompiler (T.pack s) of Left _ -> OA.readerError $ "Invalid version: " ++ s Right x -> pure x Right x -> pure x setup :: (HasBuildConfig env, HasGHCVariant env) => SetupCmdOpts -> WantedCompiler -> VersionCheck -> Maybe (Path Abs File) -> RIO env () setup SetupCmdOpts{..} wantedCompiler compilerCheck mstack = do Config{..} <- view configL sandboxedGhc <- cpSandboxed . fst <$> ensureCompilerAndMsys SetupOpts { soptsInstallIfMissing = True , soptsUseSystem = configSystemGHC && not scoForceReinstall , soptsWantedCompiler = wantedCompiler , soptsCompilerCheck = compilerCheck , soptsStackYaml = mstack , soptsForceReinstall = scoForceReinstall , soptsSanityCheck = True , soptsSkipGhcCheck = False , soptsSkipMsys = configSkipMsys , soptsResolveMissingGHC = Nothing , soptsGHCBindistURL = scoGHCBindistURL } let compiler = case wantedCompiler of WCGhc _ -> "GHC" WCGhcGit{} -> "GHC (built from source)" WCGhcjs {} -> "GHCJS" if sandboxedGhc then logInfo $ "Stack will use a sandboxed " <> compiler <> " it installed." else logInfo $ "Stack will use the " <> compiler <> " on your PATH." logInfo "For more information on paths, see 'stack path' and 'stack exec env'." logInfo $ "To use this " <> compiler <> " and packages outside of a project, consider using:" logInfo "'stack ghc', 'stack ghci', 'stack runghc', or 'stack exec'." stack-2.9.3.1/src/Stack/SourceMap.hs0000644000000000000000000002276614445022466015271 0ustar0000000000000000{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} module Stack.SourceMap ( mkProjectPackage , snapToDepPackage , additionalDepPackage , loadVersion , getPLIVersion , loadGlobalHints , DumpedGlobalPackage , actualFromGhc , actualFromHints , checkFlagsUsedThrowing , globalCondCheck , pruneGlobals , globalsFromHints , getCompilerInfo , immutableLocSha , loadProjectSnapshotCandidate , SnapshotCandidate , globalsFromDump ) where import Data.ByteString.Builder ( byteString ) import qualified Data.Conduit.List as CL import qualified Distribution.PackageDescription as PD import Distribution.System ( Platform (..) ) import qualified Pantry.SHA256 as SHA256 import qualified RIO.Map as Map import RIO.Process import qualified RIO.Set as Set import Stack.PackageDump import Stack.Prelude import Stack.Types.Build import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.SourceMap -- | Create a 'ProjectPackage' from a directory containing a package. mkProjectPackage :: forall env. (HasPantryConfig env, HasLogFunc env, HasProcessContext env) => PrintWarnings -> ResolvedPath Dir -> Bool -> RIO env ProjectPackage mkProjectPackage printWarnings dir buildHaddocks = do (gpd, name, cabalfp) <- loadCabalFilePath (Just stackProgName') (resolvedAbsolute dir) pure ProjectPackage { ppCabalFP = cabalfp , ppResolvedDir = dir , ppCommon = CommonPackage { cpGPD = gpd printWarnings , cpName = name , cpFlags = mempty , cpGhcOptions = mempty , cpCabalConfigOpts = mempty , cpHaddocks = buildHaddocks } } -- | Create a 'DepPackage' from a 'PackageLocation', from some additional -- to a snapshot setting (extra-deps or command line) additionalDepPackage :: forall env. (HasPantryConfig env, HasLogFunc env, HasProcessContext env) => Bool -> PackageLocation -> RIO env DepPackage additionalDepPackage buildHaddocks pl = do (name, gpdio) <- case pl of PLMutable dir -> do (gpdio, name, _cabalfp) <- loadCabalFilePath (Just stackProgName') (resolvedAbsolute dir) pure (name, gpdio NoPrintWarnings) PLImmutable pli -> do let PackageIdentifier name _ = packageLocationIdent pli run <- askRunInIO pure (name, run $ loadCabalFileImmutable pli) pure DepPackage { dpLocation = pl , dpHidden = False , dpFromSnapshot = NotFromSnapshot , dpCommon = CommonPackage { cpGPD = gpdio , cpName = name , cpFlags = mempty , cpGhcOptions = mempty , cpCabalConfigOpts = mempty , cpHaddocks = buildHaddocks } } snapToDepPackage :: forall env. (HasPantryConfig env, HasLogFunc env, HasProcessContext env) => Bool -> PackageName -> SnapshotPackage -> RIO env DepPackage snapToDepPackage buildHaddocks name SnapshotPackage{..} = do run <- askRunInIO pure DepPackage { dpLocation = PLImmutable spLocation , dpHidden = spHidden , dpFromSnapshot = FromSnapshot , dpCommon = CommonPackage { cpGPD = run $ loadCabalFileImmutable spLocation , cpName = name , cpFlags = spFlags , cpGhcOptions = spGhcOptions , cpCabalConfigOpts = [] -- No spCabalConfigOpts, not present in snapshots , cpHaddocks = buildHaddocks } } loadVersion :: MonadIO m => CommonPackage -> m Version loadVersion common = do gpd <- liftIO $ cpGPD common pure (pkgVersion $ PD.package $ PD.packageDescription gpd) getPLIVersion :: PackageLocationImmutable -> Version getPLIVersion (PLIHackage (PackageIdentifier _ v) _ _) = v getPLIVersion (PLIArchive _ pm) = pkgVersion $ pmIdent pm getPLIVersion (PLIRepo _ pm) = pkgVersion $ pmIdent pm globalsFromDump :: (HasLogFunc env, HasProcessContext env) => GhcPkgExe -> RIO env (Map PackageName DumpedGlobalPackage) globalsFromDump pkgexe = do let pkgConduit = conduitDumpPackage .| CL.foldMap (\dp -> Map.singleton (dpGhcPkgId dp) dp) toGlobals ds = Map.fromList $ map (pkgName . dpPackageIdent &&& id) $ Map.elems ds toGlobals <$> ghcPkgDump pkgexe [] pkgConduit globalsFromHints :: HasConfig env => WantedCompiler -> RIO env (Map PackageName Version) globalsFromHints compiler = do mglobalHints <- loadGlobalHints compiler case mglobalHints of Just hints -> pure hints Nothing -> do logWarn $ "Unable to load global hints for " <> display compiler pure mempty type DumpedGlobalPackage = DumpPackage actualFromGhc :: (HasConfig env, HasCompiler env) => SMWanted -> ActualCompiler -> RIO env (SMActual DumpedGlobalPackage) actualFromGhc smw ac = do globals <- view $ compilerPathsL.to cpGlobalDump pure SMActual { smaCompiler = ac , smaProject = smwProject smw , smaDeps = smwDeps smw , smaGlobal = globals } actualFromHints :: (HasConfig env) => SMWanted -> ActualCompiler -> RIO env (SMActual GlobalPackageVersion) actualFromHints smw ac = do globals <- globalsFromHints (actualToWanted ac) pure SMActual { smaCompiler = ac , smaProject = smwProject smw , smaDeps = smwDeps smw , smaGlobal = Map.map GlobalPackageVersion globals } -- | Simple cond check for boot packages - checks only OS and Arch globalCondCheck :: (HasConfig env) => RIO env (PD.ConfVar -> Either PD.ConfVar Bool) globalCondCheck = do Platform arch os <- view platformL let condCheck (PD.OS os') = pure $ os' == os condCheck (PD.Arch arch') = pure $ arch' == arch condCheck c = Left c pure condCheck checkFlagsUsedThrowing :: (MonadIO m, MonadThrow m) => Map PackageName (Map FlagName Bool) -> FlagSource -> Map PackageName ProjectPackage -> Map PackageName DepPackage -> m () checkFlagsUsedThrowing packageFlags source prjPackages deps = do unusedFlags <- forMaybeM (Map.toList packageFlags) $ \(pname, flags) -> getUnusedPackageFlags (pname, flags) source prjPackages deps unless (null unusedFlags) $ throwM $ InvalidFlagSpecification $ Set.fromList unusedFlags getUnusedPackageFlags :: MonadIO m => (PackageName, Map FlagName Bool) -> FlagSource -> Map PackageName ProjectPackage -> Map PackageName DepPackage -> m (Maybe UnusedFlags) getUnusedPackageFlags (name, userFlags) source prj deps = let maybeCommon = fmap ppCommon (Map.lookup name prj) <|> fmap dpCommon (Map.lookup name deps) in case maybeCommon of -- Package is not available as project or dependency Nothing -> pure $ Just $ UFNoPackage source name -- Package exists, let's check if the flags are defined Just common -> do gpd <- liftIO $ cpGPD common let pname = pkgName $ PD.package $ PD.packageDescription gpd pkgFlags = Set.fromList $ map PD.flagName $ PD.genPackageFlags gpd unused = Map.keysSet $ Map.withoutKeys userFlags pkgFlags if Set.null unused -- All flags are defined, nothing to do then pure Nothing -- Error about the undefined flags else pure $ Just $ UFFlagsNotDefined source pname pkgFlags unused pruneGlobals :: Map PackageName DumpedGlobalPackage -> Set PackageName -> Map PackageName GlobalPackage pruneGlobals globals deps = let (prunedGlobals, keptGlobals) = partitionReplacedDependencies globals (pkgName . dpPackageIdent) dpGhcPkgId dpDepends deps in Map.map (GlobalPackage . pkgVersion . dpPackageIdent) keptGlobals <> Map.map ReplacedGlobalPackage prunedGlobals getCompilerInfo :: (HasConfig env, HasCompiler env) => RIO env Builder getCompilerInfo = view $ compilerPathsL.to (byteString . cpGhcInfo) immutableLocSha :: PackageLocationImmutable -> Builder immutableLocSha = byteString . treeKeyToBs . locationTreeKey where locationTreeKey (PLIHackage _ _ tk) = tk locationTreeKey (PLIArchive _ pm) = pmTreeKey pm locationTreeKey (PLIRepo _ pm) = pmTreeKey pm treeKeyToBs (TreeKey (BlobKey sha _)) = SHA256.toHexBytes sha type SnapshotCandidate env = [ResolvedPath Dir] -> RIO env (SMActual GlobalPackageVersion) loadProjectSnapshotCandidate :: (HasConfig env) => RawSnapshotLocation -> PrintWarnings -> Bool -> RIO env (SnapshotCandidate env) loadProjectSnapshotCandidate loc printWarnings buildHaddocks = do debugRSL <- view rslInLogL (snapshot, _, _) <- loadAndCompleteSnapshotRaw' debugRSL loc Map.empty Map.empty deps <- Map.traverseWithKey (snapToDepPackage False) (snapshotPackages snapshot) let wc = snapshotCompiler snapshot globals <- Map.map GlobalPackageVersion <$> globalsFromHints wc pure $ \projectPackages -> do prjPkgs <- fmap Map.fromList . for projectPackages $ \resolved -> do pp <- mkProjectPackage printWarnings resolved buildHaddocks pure (cpName $ ppCommon pp, pp) compiler <- either throwIO pure $ wantedToActual $ snapshotCompiler snapshot pure SMActual { smaCompiler = compiler , smaProject = prjPkgs , smaDeps = Map.difference deps prjPkgs , smaGlobal = globals } stack-2.9.3.1/src/Stack/Storage/Project.hs0000644000000000000000000002044214445022466016372 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -Wno-unused-top-binds -Wno-identities #-} -- | Work with SQLite database used for caches across a single project. module Stack.Storage.Project ( initProjectStorage , ConfigCacheKey , configCacheKey , loadConfigCache , saveConfigCache , deactiveConfigCache ) where import qualified Data.ByteString as S import qualified Data.Set as Set import Database.Persist.Sqlite import Database.Persist.TH import qualified Pantry.Internal as SQLite import Path import Stack.Prelude import Stack.Storage.Util ( handleMigrationException, updateList, updateSet ) import Stack.Types.Build import Stack.Types.Cache import Stack.Types.Config ( HasBuildConfig, ProjectStorage (..), bcProjectStorage , buildConfigL ) import Stack.Types.GhcPkgId share [ mkPersist sqlSettings , mkMigrate "migrateAll" ] [persistLowerCase| ConfigCacheParent sql="config_cache" directory FilePath "default=(hex(randomblob(16)))" type ConfigCacheType pkgSrc CachePkgSrc active Bool pathEnvVar Text haddock Bool default=0 UniqueConfigCacheParent directory type sql="unique_config_cache" deriving Show ConfigCacheDirOption parent ConfigCacheParentId sql="config_cache_id" OnDeleteCascade index Int value String sql="option" UniqueConfigCacheDirOption parent index deriving Show ConfigCacheNoDirOption parent ConfigCacheParentId sql="config_cache_id" OnDeleteCascade index Int value String sql="option" UniqueConfigCacheNoDirOption parent index deriving Show ConfigCacheDep parent ConfigCacheParentId sql="config_cache_id" OnDeleteCascade value GhcPkgId sql="ghc_pkg_id" UniqueConfigCacheDep parent value deriving Show ConfigCacheComponent parent ConfigCacheParentId sql="config_cache_id" OnDeleteCascade value S.ByteString sql="component" UniqueConfigCacheComponent parent value deriving Show |] -- | Initialize the database. initProjectStorage :: HasLogFunc env => Path Abs File -- ^ storage file -> (ProjectStorage -> RIO env a) -> RIO env a initProjectStorage fp f = handleMigrationException $ SQLite.initStorage "Stack" migrateAll fp $ f . ProjectStorage -- | Run an action in a database transaction withProjectStorage :: (HasBuildConfig env, HasLogFunc env) => ReaderT SqlBackend (RIO env) a -> RIO env a withProjectStorage inner = do storage <- view (buildConfigL . to bcProjectStorage . to unProjectStorage) SQLite.withStorage_ storage inner -- | Key used to retrieve configuration or flag cache type ConfigCacheKey = Unique ConfigCacheParent -- | Build key used to retrieve configuration or flag cache configCacheKey :: Path Abs Dir -> ConfigCacheType -> ConfigCacheKey configCacheKey dir = UniqueConfigCacheParent (toFilePath dir) -- | Internal helper to read the 'ConfigCache' readConfigCache :: (HasBuildConfig env, HasLogFunc env) => Entity ConfigCacheParent -> ReaderT SqlBackend (RIO env) ConfigCache readConfigCache (Entity parentId ConfigCacheParent {..}) = do let configCachePkgSrc = configCacheParentPkgSrc coDirs <- map (configCacheDirOptionValue . entityVal) <$> selectList [ConfigCacheDirOptionParent ==. parentId] [Asc ConfigCacheDirOptionIndex] coNoDirs <- map (configCacheNoDirOptionValue . entityVal) <$> selectList [ConfigCacheNoDirOptionParent ==. parentId] [Asc ConfigCacheNoDirOptionIndex] let configCacheOpts = ConfigureOpts {..} configCacheDeps <- Set.fromList . map (configCacheDepValue . entityVal) <$> selectList [ConfigCacheDepParent ==. parentId] [] configCacheComponents <- Set.fromList . map (configCacheComponentValue . entityVal) <$> selectList [ConfigCacheComponentParent ==. parentId] [] let configCachePathEnvVar = configCacheParentPathEnvVar let configCacheHaddock = configCacheParentHaddock pure ConfigCache {..} -- | Load 'ConfigCache' from the database. loadConfigCache :: (HasBuildConfig env, HasLogFunc env) => ConfigCacheKey -> RIO env (Maybe ConfigCache) loadConfigCache key = withProjectStorage $ do mparent <- getBy key case mparent of Nothing -> pure Nothing Just parentEntity@(Entity _ ConfigCacheParent {..}) | configCacheParentActive -> Just <$> readConfigCache parentEntity | otherwise -> pure Nothing -- | Insert or update 'ConfigCache' to the database. saveConfigCache :: (HasBuildConfig env, HasLogFunc env) => ConfigCacheKey -> ConfigCache -> RIO env () saveConfigCache key@(UniqueConfigCacheParent dir type_) new = withProjectStorage $ do mparent <- getBy key (parentId, mold) <- case mparent of Nothing -> (, Nothing) <$> insert ConfigCacheParent { configCacheParentDirectory = dir , configCacheParentType = type_ , configCacheParentPkgSrc = configCachePkgSrc new , configCacheParentActive = True , configCacheParentPathEnvVar = configCachePathEnvVar new , configCacheParentHaddock = configCacheHaddock new } Just parentEntity@(Entity parentId _) -> do old <- readConfigCache parentEntity update parentId [ ConfigCacheParentPkgSrc =. configCachePkgSrc new , ConfigCacheParentActive =. True , ConfigCacheParentPathEnvVar =. configCachePathEnvVar new ] pure (parentId, Just old) updateList ConfigCacheDirOption ConfigCacheDirOptionParent parentId ConfigCacheDirOptionIndex (maybe [] (coDirs . configCacheOpts) mold) (coDirs $ configCacheOpts new) updateList ConfigCacheNoDirOption ConfigCacheNoDirOptionParent parentId ConfigCacheNoDirOptionIndex (maybe [] (coNoDirs . configCacheOpts) mold) (coNoDirs $ configCacheOpts new) updateSet ConfigCacheDep ConfigCacheDepParent parentId ConfigCacheDepValue (maybe Set.empty configCacheDeps mold) (configCacheDeps new) updateSet ConfigCacheComponent ConfigCacheComponentParent parentId ConfigCacheComponentValue (maybe Set.empty configCacheComponents mold) (configCacheComponents new) -- | Mark 'ConfigCache' as inactive in the database. -- We use a flag instead of deleting the records since, in most cases, the same -- cache will be written again within in a few seconds (after -- `cabal configure`), so this avoids unnecessary database churn. deactiveConfigCache :: HasBuildConfig env => ConfigCacheKey -> RIO env () deactiveConfigCache (UniqueConfigCacheParent dir type_) = withProjectStorage $ updateWhere [ConfigCacheParentDirectory ==. dir, ConfigCacheParentType ==. type_] [ConfigCacheParentActive =. False] stack-2.9.3.1/src/Stack/Storage/User.hs0000644000000000000000000003502414445022466015704 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -Wno-unused-top-binds -Wno-identities #-} -- | Work with SQLite database used for caches across an entire user account. module Stack.Storage.User ( initUserStorage , PrecompiledCacheKey , precompiledCacheKey , loadPrecompiledCache , savePrecompiledCache , loadDockerImageExeCache , saveDockerImageExeCache , loadCompilerPaths , saveCompilerPaths , upgradeChecksSince , logUpgradeCheck ) where import qualified Data.Set as Set import qualified Data.Text as T import Data.Time.Clock ( UTCTime ) import Database.Persist.Sqlite import Database.Persist.TH import Distribution.Text ( simpleParse, display ) import Foreign.C.Types ( CTime (..) ) import qualified Pantry.Internal as SQLite import Path import Path.IO ( resolveFile', resolveDir' ) import qualified RIO.FilePath as FP import Stack.Prelude hiding ( MigrationFailure ) import Stack.Storage.Util ( handleMigrationException, updateSet ) import Stack.Types.Build import Stack.Types.Cache import Stack.Types.Compiler import Stack.Types.CompilerBuild ( CompilerBuild ) import Stack.Types.Config ( CompilerPaths (..), GhcPkgExe (..), HasConfig , UserStorage (..), configL, configUserStorage ) import System.Posix.Types ( COff (..) ) import System.PosixCompat.Files ( fileSize, getFileStatus, modificationTime ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Storage.User" module. data StorageUserException = CompilerFileMetadataMismatch | GlobalPackageCacheFileMetadataMismatch | GlobalDumpParseFailure | CompilerCacheArchitectureInvalid Text deriving (Show, Typeable) instance Exception StorageUserException where displayException CompilerFileMetadataMismatch = "Error: [S-8196]\n" ++ "Compiler file metadata mismatch, ignoring cache." displayException GlobalPackageCacheFileMetadataMismatch = "Error: [S-5378]\n" ++ "Global package cache file metadata mismatch, ignoring cache." displayException GlobalDumpParseFailure = "Error: [S-2673]\n" ++ "Global dump did not parse correctly." displayException (CompilerCacheArchitectureInvalid compilerCacheArch) = concat [ "Error: [S-8441]\n" , "Invalid arch: " , show compilerCacheArch ] share [ mkPersist sqlSettings , mkMigrate "migrateAll" ] [persistLowerCase| PrecompiledCacheParent sql="precompiled_cache" platformGhcDir FilePath "default=(hex(randomblob(16)))" compiler Text cabalVersion Text packageKey Text optionsHash ByteString haddock Bool default=0 library FilePath Maybe UniquePrecompiledCacheParent platformGhcDir compiler cabalVersion packageKey optionsHash haddock sql="unique_precompiled_cache" deriving Show PrecompiledCacheSubLib parent PrecompiledCacheParentId sql="precompiled_cache_id" OnDeleteCascade value FilePath sql="sub_lib" UniquePrecompiledCacheSubLib parent value deriving Show PrecompiledCacheExe parent PrecompiledCacheParentId sql="precompiled_cache_id" OnDeleteCaseCascade value FilePath sql="exe" UniquePrecompiledCacheExe parent value deriving Show DockerImageExeCache imageHash Text exePath FilePath exeTimestamp UTCTime compatible Bool DockerImageExeCacheUnique imageHash exePath exeTimestamp deriving Show CompilerCache actualVersion ActualCompiler arch Text -- Include ghc executable size and modified time for sanity checking entries ghcPath FilePath ghcSize Int64 ghcModified Int64 ghcPkgPath FilePath runghcPath FilePath haddockPath FilePath cabalVersion Text globalDb FilePath globalDbCacheSize Int64 globalDbCacheModified Int64 info ByteString -- This is the ugliest part of this table, simply storing a Show/Read version of the -- data. We could do a better job with normalized data and proper table structure. -- However, recomputing this value in the future if the data representation changes -- is very cheap, so we'll take the easy way out for now. globalDump Text UniqueCompilerInfo ghcPath -- Last time certain actions were performed LastPerformed action Action timestamp UTCTime UniqueAction action |] -- | Initialize the database. initUserStorage :: HasLogFunc env => Path Abs File -- ^ storage file -> (UserStorage -> RIO env a) -> RIO env a initUserStorage fp f = handleMigrationException $ SQLite.initStorage "Stack" migrateAll fp $ f . UserStorage -- | Run an action in a database transaction withUserStorage :: (HasConfig env, HasLogFunc env) => ReaderT SqlBackend (RIO env) a -> RIO env a withUserStorage inner = do storage <- view (configL . to configUserStorage . to unUserStorage) SQLite.withStorage_ storage inner -- | Key used to retrieve the precompiled cache type PrecompiledCacheKey = Unique PrecompiledCacheParent -- | Build key used to retrieve the precompiled cache precompiledCacheKey :: Path Rel Dir -> ActualCompiler -> Version -> Text -> ByteString -> Bool -> PrecompiledCacheKey precompiledCacheKey platformGhcDir compiler cabalVersion = UniquePrecompiledCacheParent (toFilePath platformGhcDir) (compilerVersionText compiler) (T.pack $ versionString cabalVersion) -- | Internal helper to read the 'PrecompiledCache' from the database readPrecompiledCache :: (HasConfig env, HasLogFunc env) => PrecompiledCacheKey -> ReaderT SqlBackend (RIO env) (Maybe ( PrecompiledCacheParentId , PrecompiledCache Rel)) readPrecompiledCache key = do mparent <- getBy key forM mparent $ \(Entity parentId PrecompiledCacheParent {..}) -> do pcLibrary <- mapM parseRelFile precompiledCacheParentLibrary pcSubLibs <- mapM (parseRelFile . precompiledCacheSubLibValue . entityVal) =<< selectList [PrecompiledCacheSubLibParent ==. parentId] [] pcExes <- mapM (parseRelFile . precompiledCacheExeValue . entityVal) =<< selectList [PrecompiledCacheExeParent ==. parentId] [] pure (parentId, PrecompiledCache {..}) -- | Load 'PrecompiledCache' from the database. loadPrecompiledCache :: (HasConfig env, HasLogFunc env) => PrecompiledCacheKey -> RIO env (Maybe (PrecompiledCache Rel)) loadPrecompiledCache key = withUserStorage $ fmap snd <$> readPrecompiledCache key -- | Insert or update 'PrecompiledCache' to the database. savePrecompiledCache :: (HasConfig env, HasLogFunc env) => PrecompiledCacheKey -> PrecompiledCache Rel -> RIO env () savePrecompiledCache key@(UniquePrecompiledCacheParent precompiledCacheParentPlatformGhcDir precompiledCacheParentCompiler precompiledCacheParentCabalVersion precompiledCacheParentPackageKey precompiledCacheParentOptionsHash precompiledCacheParentHaddock) new = withUserStorage $ do let precompiledCacheParentLibrary = fmap toFilePath (pcLibrary new) mIdOld <- readPrecompiledCache key (parentId, mold) <- case mIdOld of Nothing -> (, Nothing) <$> insert PrecompiledCacheParent {..} Just (parentId, old) -> do update parentId [ PrecompiledCacheParentLibrary =. precompiledCacheParentLibrary ] pure (parentId, Just old) updateSet PrecompiledCacheSubLib PrecompiledCacheSubLibParent parentId PrecompiledCacheSubLibValue (maybe Set.empty (toFilePathSet . pcSubLibs) mold) (toFilePathSet $ pcSubLibs new) updateSet PrecompiledCacheExe PrecompiledCacheExeParent parentId PrecompiledCacheExeValue (maybe Set.empty (toFilePathSet . pcExes) mold) (toFilePathSet $ pcExes new) where toFilePathSet = Set.fromList . map toFilePath -- | Get the record of whether an executable is compatible with a Docker image loadDockerImageExeCache :: (HasConfig env, HasLogFunc env) => Text -> Path Abs File -> UTCTime -> RIO env (Maybe Bool) loadDockerImageExeCache imageId exePath exeTimestamp = withUserStorage $ fmap (dockerImageExeCacheCompatible . entityVal) <$> getBy (DockerImageExeCacheUnique imageId (toFilePath exePath) exeTimestamp) -- | Sets the record of whether an executable is compatible with a Docker image saveDockerImageExeCache :: (HasConfig env, HasLogFunc env) => Text -> Path Abs File -> UTCTime -> Bool -> RIO env () saveDockerImageExeCache imageId exePath exeTimestamp compatible = void $ withUserStorage $ upsert (DockerImageExeCache imageId (toFilePath exePath) exeTimestamp compatible) [] -- | Type-restricted version of 'fromIntegral' to ensure we're making -- the value bigger, not smaller. sizeToInt64 :: COff -> Int64 sizeToInt64 (COff i) = fromIntegral i -- fromIntegral added for 32-bit systems -- | Type-restricted version of 'fromIntegral' to ensure we're making -- the value bigger, not smaller. timeToInt64 :: CTime -> Int64 timeToInt64 (CTime i) = fromIntegral i -- fromIntegral added for 32-bit systems -- | Load compiler information, if available, and confirm that the -- referenced files are unchanged. May throw exceptions! loadCompilerPaths :: HasConfig env => Path Abs File -- ^ compiler executable -> CompilerBuild -> Bool -- ^ sandboxed? -> RIO env (Maybe CompilerPaths) loadCompilerPaths compiler build sandboxed = do mres <- withUserStorage $ getBy $ UniqueCompilerInfo $ toFilePath compiler for mres $ \(Entity _ CompilerCache {..}) -> do compilerStatus <- liftIO $ getFileStatus $ toFilePath compiler when (compilerCacheGhcSize /= sizeToInt64 (fileSize compilerStatus) || compilerCacheGhcModified /= timeToInt64 (modificationTime compilerStatus)) (throwIO CompilerFileMetadataMismatch) globalDbStatus <- liftIO $ getFileStatus $ compilerCacheGlobalDb FP. "package.cache" when (compilerCacheGlobalDbCacheSize /= sizeToInt64 (fileSize globalDbStatus) || compilerCacheGlobalDbCacheModified /= timeToInt64 (modificationTime globalDbStatus)) (throwIO GlobalPackageCacheFileMetadataMismatch) -- We could use parseAbsFile instead of resolveFile' below to -- bypass some system calls, at the cost of some really wonky -- error messages in case someone screws up their GHC installation pkgexe <- resolveFile' compilerCacheGhcPkgPath runghc <- resolveFile' compilerCacheRunghcPath haddock <- resolveFile' compilerCacheHaddockPath globaldb <- resolveDir' compilerCacheGlobalDb cabalVersion <- parseVersionThrowing $ T.unpack compilerCacheCabalVersion globalDump <- case readMaybe $ T.unpack compilerCacheGlobalDump of Nothing -> throwIO GlobalDumpParseFailure Just globalDump -> pure globalDump arch <- case simpleParse $ T.unpack compilerCacheArch of Nothing -> throwIO $ CompilerCacheArchitectureInvalid compilerCacheArch Just arch -> pure arch pure CompilerPaths { cpCompiler = compiler , cpCompilerVersion = compilerCacheActualVersion , cpArch = arch , cpBuild = build , cpPkg = GhcPkgExe pkgexe , cpInterpreter = runghc , cpHaddock = haddock , cpSandboxed = sandboxed , cpCabalVersion = cabalVersion , cpGlobalDB = globaldb , cpGhcInfo = compilerCacheInfo , cpGlobalDump = globalDump } -- | Save compiler information. May throw exceptions! saveCompilerPaths :: HasConfig env => CompilerPaths -> RIO env () saveCompilerPaths CompilerPaths {..} = withUserStorage $ do deleteBy $ UniqueCompilerInfo $ toFilePath cpCompiler compilerStatus <- liftIO $ getFileStatus $ toFilePath cpCompiler globalDbStatus <- liftIO $ getFileStatus $ toFilePath $ cpGlobalDB $(mkRelFile "package.cache") let GhcPkgExe pkgexe = cpPkg insert_ CompilerCache { compilerCacheActualVersion = cpCompilerVersion , compilerCacheGhcPath = toFilePath cpCompiler , compilerCacheGhcSize = sizeToInt64 $ fileSize compilerStatus , compilerCacheGhcModified = timeToInt64 $ modificationTime compilerStatus , compilerCacheGhcPkgPath = toFilePath pkgexe , compilerCacheRunghcPath = toFilePath cpInterpreter , compilerCacheHaddockPath = toFilePath cpHaddock , compilerCacheCabalVersion = T.pack $ versionString cpCabalVersion , compilerCacheGlobalDb = toFilePath cpGlobalDB , compilerCacheGlobalDbCacheSize = sizeToInt64 $ fileSize globalDbStatus , compilerCacheGlobalDbCacheModified = timeToInt64 $ modificationTime globalDbStatus , compilerCacheInfo = cpGhcInfo , compilerCacheGlobalDump = tshow cpGlobalDump , compilerCacheArch = T.pack $ Distribution.Text.display cpArch } -- | How many upgrade checks have occurred since the given timestamp? upgradeChecksSince :: HasConfig env => UTCTime -> RIO env Int upgradeChecksSince since = withUserStorage $ count [ LastPerformedAction ==. UpgradeCheck , LastPerformedTimestamp >=. since ] -- | Log in the database that an upgrade check occurred at the given time. logUpgradeCheck :: HasConfig env => UTCTime -> RIO env () logUpgradeCheck time = withUserStorage $ void $ upsert (LastPerformed UpgradeCheck time) [LastPerformedTimestamp =. time] stack-2.9.3.1/src/Stack/Storage/Util.hs0000644000000000000000000000575614445106224015707 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE CPP #-} -- | Utils for the other Stack.Storage modules module Stack.Storage.Util ( handleMigrationException , updateList , updateSet ) where import qualified Data.Set as Set import Database.Persist import Stack.Prelude import Stack.Types.Storage ( StoragePrettyException (..) ) -- | Efficiently update a set of values stored in a database table updateSet :: ( PersistEntityBackend record ~ BaseBackend backend , PersistField parentid , PersistField value , Ord value , PersistEntity record , MonadIO m , PersistQueryWrite backend #if MIN_VERSION_persistent(2,14,0) , SafeToInsert record #endif ) => (parentid -> value -> record) -> EntityField record parentid -> parentid -> EntityField record value -> Set value -> Set value -> ReaderT backend m () updateSet recordCons parentFieldCons parentId valueFieldCons old new = when (old /= new) $ do deleteWhere [ parentFieldCons ==. parentId , valueFieldCons <-. Set.toList (Set.difference old new) ] insertMany_ $ map (recordCons parentId) $ Set.toList (Set.difference new old) -- | Efficiently update a list of values stored in a database table. updateList :: ( PersistEntityBackend record ~ BaseBackend backend , PersistField parentid , Ord value , PersistEntity record , MonadIO m , PersistQueryWrite backend #if MIN_VERSION_persistent(2,14,0) , SafeToInsert record #endif ) => (parentid -> Int -> value -> record) -> EntityField record parentid -> parentid -> EntityField record Int -> [value] -> [value] -> ReaderT backend m () updateList recordCons parentFieldCons parentId indexFieldCons old new = when (old /= new) $ do let oldSet = Set.fromList (zip [0 ..] old) newSet = Set.fromList (zip [0 ..] new) deleteWhere [ parentFieldCons ==. parentId , indexFieldCons <-. map fst (Set.toList $ Set.difference oldSet newSet) ] insertMany_ $ map (uncurry $ recordCons parentId) $ Set.toList (Set.difference newSet oldSet) handleMigrationException :: HasLogFunc env => RIO env a -> RIO env a handleMigrationException inner = do eres <- try inner either ( \e -> case e :: PantryException of MigrationFailure desc fp ex -> throwIO $ PrettyException $ StorageMigrationFailure desc fp ex _ -> throwIO e ) pure eres stack-2.9.3.1/src/Stack/Types/Build.hs0000644000000000000000000013521514445022466015530 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} -- | Build-specific types. module Stack.Types.Build ( BuildException (..) , BuildPrettyException (..) , ConstructPlanException (..) , BadDependency (..) , ParentMap , FlagSource (..) , UnusedFlags (..) , InstallLocation (..) , Installed (..) , psVersion , Task (..) , taskIsTarget , taskLocation , taskTargetIsMutable , LocalPackage (..) , BaseConfigOpts (..) , Plan (..) , TestOpts (..) , BenchmarkOpts (..) , FileWatchOpts (..) , BuildOpts (..) , BuildSubset (..) , defaultBuildOpts , TaskType (..) , IsMutable (..) , installLocationIsMutable , TaskConfigOpts (..) , BuildCache (..) , ConfigCache (..) , configureOpts , CachePkgSrc (..) , toCachePkgSrc , isStackOpt , wantedLocalPackages , FileCacheInfo (..) , ConfigureOpts (..) , PrecompiledCache (..) ) where import Data.Aeson ( ToJSON, FromJSON ) import qualified Data.ByteString as S import Data.Char ( isSpace ) import Data.List as L import qualified Data.Map as Map import qualified Data.Map.Strict as M import Data.Monoid.Map ( MonoidMap (..) ) import qualified Data.Set as Set import qualified Data.Text as T import Database.Persist.Sql ( PersistField (..), PersistFieldSql (..) , PersistValue (PersistText), SqlType (SqlString) ) import Distribution.PackageDescription ( TestSuiteInterface, mkPackageName ) import Distribution.System ( Arch ) import qualified Distribution.Text as C import qualified Distribution.Version as C import Path ( parseRelDir, (), parent ) import Path.Extra ( toFilePathNoTrailingSep ) import RIO.Process ( showProcessArgDebug ) import Stack.Constants import Stack.Prelude import Stack.Types.Compiler import Stack.Types.CompilerBuild import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.Version import System.FilePath ( pathSeparator ) -- | Type representing exceptions thrown by functions exported by modules with -- names beginning @Stack.Build@. data BuildException = Couldn'tFindPkgId PackageName | CompilerVersionMismatch (Maybe (ActualCompiler, Arch)) -- found (WantedCompiler, Arch) -- expected GHCVariant -- expected CompilerBuild -- expected VersionCheck (Maybe (Path Abs File)) -- Path to the stack.yaml file Text -- recommended resolution | Couldn'tParseTargets [Text] | UnknownTargets (Set PackageName) -- no known version (Map PackageName Version) -- not in snapshot, here's the most recent version in the index (Path Abs File) -- stack.yaml | TestSuiteFailure PackageIdentifier (Map Text (Maybe ExitCode)) (Maybe (Path Abs File)) S.ByteString | TestSuiteTypeUnsupported TestSuiteInterface | LocalPackageDoesn'tMatchTarget PackageName Version -- local version Version -- version specified on command line | NoSetupHsFound (Path Abs Dir) | InvalidFlagSpecification (Set UnusedFlags) | InvalidGhcOptionsSpecification [PackageName] | TargetParseException [Text] | SomeTargetsNotBuildable [(PackageName, NamedComponent)] | TestSuiteExeMissing Bool String String String | CabalCopyFailed Bool String | LocalPackagesPresent [PackageIdentifier] | CouldNotLockDistDir !(Path Abs File) | TaskCycleBug PackageIdentifier | PackageIdMissingBug PackageIdentifier | AllInOneBuildBug | MulipleResultsBug PackageName [DumpPackage] | TemplateHaskellNotFoundBug | HaddockIndexNotFound | ShowBuildErrorBug deriving (Show, Typeable) instance Exception BuildException where displayException (Couldn'tFindPkgId name) = bugReport "[S-7178]" $ concat [ "After installing " , packageNameString name ,", the package id couldn't be found (via ghc-pkg describe " , packageNameString name , ")." ] displayException (CompilerVersionMismatch mactual (expected, eArch) ghcVariant ghcBuild check mstack resolution) = concat [ "Error: [S-6362]\n" , case mactual of Nothing -> "No compiler found, expected " Just (actual, arch) -> concat [ "Compiler version mismatched, found " , compilerVersionString actual , " (" , C.display arch , ")" , ", but expected " ] , case check of MatchMinor -> "minor version match with " MatchExact -> "exact version " NewerMinor -> "minor version match or newer with " , T.unpack $ utf8BuilderToText $ display expected , " (" , C.display eArch , ghcVariantSuffix ghcVariant , compilerBuildSuffix ghcBuild , ") (based on " , case mstack of Nothing -> "command line arguments" Just stack -> "resolver setting in " ++ toFilePath stack , ").\n" , T.unpack resolution ] displayException (Couldn'tParseTargets targets) = unlines $ "Error: [S-3127]" : "The following targets could not be parsed as package names or \ \directories:" : map T.unpack targets displayException (UnknownTargets noKnown notInSnapshot stackYaml) = unlines $ "Error: [S-2154]" : (noKnown' ++ notInSnapshot') where noKnown' | Set.null noKnown = [] | otherwise = pure $ "The following target packages were not found: " ++ intercalate ", " (map packageNameString $ Set.toList noKnown) ++ "\nSee https://docs.haskellstack.org/en/stable/build_command/#target-syntax for details." notInSnapshot' | Map.null notInSnapshot = [] | otherwise = "The following packages are not in your snapshot, but exist" : "in your package index. Recommended action: add them to your" : ("extra-deps in " ++ toFilePath stackYaml) : "(Note: these are the most recent versions," : "but there's no guarantee that they'll build together)." : "" : map (\(name, version') -> "- " ++ packageIdentifierString (PackageIdentifier name version')) (Map.toList notInSnapshot) displayException (TestSuiteFailure ident codes mlogFile bs) = unlines $ "Error: [S-1995]" : concat [ ["Test suite failure for package " ++ packageIdentifierString ident] , flip map (Map.toList codes) $ \(name, mcode) -> concat [ " " , T.unpack name , ": " , case mcode of Nothing -> " executable not found" Just ec -> " exited with: " ++ displayException ec ] , pure $ case mlogFile of Nothing -> "Logs printed to console" -- TODO Should we load up the full error output and print it here? Just logFile -> "Full log available at " ++ toFilePath logFile , if S.null bs then [] else ["", "", doubleIndent $ T.unpack $ decodeUtf8With lenientDecode bs] ] where indent' = dropWhileEnd isSpace . unlines . fmap (\l -> " " ++ l) . lines doubleIndent = indent' . indent' displayException (TestSuiteTypeUnsupported interface) = concat [ "Error: [S-3819]\n" , "Unsupported test suite type: " , show interface ] -- Suppressing duplicate output displayException (LocalPackageDoesn'tMatchTarget name localV requestedV) = concat [ "Error: [S-5797]\n" , "Version for local package " , packageNameString name , " is " , versionString localV , ", but you asked for " , versionString requestedV , " on the command line" ] displayException (NoSetupHsFound dir) = concat [ "Error: [S-3118]\n" , "No Setup.hs or Setup.lhs file found in " , toFilePath dir ] displayException (InvalidFlagSpecification unused) = unlines $ "Error: [S-8664]" : "Invalid flag specification:" : map go (Set.toList unused) where showFlagSrc :: FlagSource -> String showFlagSrc FSCommandLine = " (specified on command line)" showFlagSrc FSStackYaml = " (specified in stack.yaml)" go :: UnusedFlags -> String go (UFNoPackage src name) = concat [ "- Package '" , packageNameString name , "' not found" , showFlagSrc src ] go (UFFlagsNotDefined src pname pkgFlags flags) = concat [ "- Package '" , name , "' does not define the following flags" , showFlagSrc src , ":\n" , intercalate "\n" (map (\flag -> " " ++ flagNameString flag) (Set.toList flags)) , "\n- Flags defined by package '" ++ name ++ "':\n" , intercalate "\n" (map (\flag -> " " ++ name ++ ":" ++ flagNameString flag) (Set.toList pkgFlags)) ] where name = packageNameString pname go (UFSnapshot name) = concat [ "- Attempted to set flag on snapshot package " , packageNameString name , ", please add to extra-deps" ] displayException (InvalidGhcOptionsSpecification unused) = unlines $ "Error: [S-4925]" : "Invalid GHC options specification:" : map showGhcOptionSrc unused where showGhcOptionSrc name = concat [ "- Package '" , packageNameString name , "' not found" ] displayException (TargetParseException [err]) = concat [ "Error: [S-8506]\n" , "Error parsing targets: " , T.unpack err ] displayException (TargetParseException errs) = unlines $ "Error [S-8506]" : "The following errors occurred while parsing the build targets:" : map (("- " ++) . T.unpack) errs displayException (SomeTargetsNotBuildable xs) = unlines [ "Error: [S-7086]" , "The following components have 'buildable: False' set in the Cabal \ \configuration, and so cannot be targets:" , " " <> T.unpack (renderPkgComponents xs) , "To resolve this, either provide flags such that these components \ \are buildable, or only specify buildable targets." ] displayException (TestSuiteExeMissing isSimpleBuildType exeName pkgName' testName) = missingExeError "[S-7987]" isSimpleBuildType $ concat [ "Test suite executable \"" , exeName , " not found for " , pkgName' , ":test:" , testName ] displayException (CabalCopyFailed isSimpleBuildType innerMsg) = missingExeError "[S-8027]" isSimpleBuildType $ concat [ "'cabal copy' failed. Error message:\n" , innerMsg , "\n" ] displayException (LocalPackagesPresent locals) = unlines $ "Error: [S-5510]" : "Local packages are not allowed when using the 'script' command. \ \Packages found:" : map (\ident -> "- " ++ packageIdentifierString ident) locals displayException (CouldNotLockDistDir lockFile) = unlines [ "Error: [S-7168]" , "Locking the dist directory failed, try to lock file:" , " " ++ toFilePath lockFile , "Maybe you're running another copy of Stack?" ] displayException (TaskCycleBug pid) = bugReport "[S-7868]" $ "Error: The impossible happened! Unexpected task cycle for " ++ packageNameString (pkgName pid) displayException (PackageIdMissingBug ident) = bugReport "[S-8923]" $ "The impossible happened! singleBuild: missing package ID missing: " ++ show ident displayException AllInOneBuildBug = bugReport "[S-7371]" "Cannot have an all-in-one build that also has a final build step." displayException (MulipleResultsBug name dps) = bugReport "[S-6739]" "singleBuild: multiple results when describing installed package " ++ show (name, dps) displayException TemplateHaskellNotFoundBug = bugReport "[S-3121]" "template-haskell is a wired-in GHC boot library but it wasn't found." displayException HaddockIndexNotFound = "Error: [S-6901]\n" ++ "No local or snapshot doc index found to open." displayException ShowBuildErrorBug = bugReport "[S-5452]" "Unexpected case in showBuildError." data BuildPrettyException = ConstructPlanFailed [ConstructPlanException] (Path Abs File) (Path Abs Dir) ParentMap (Set PackageName) (Map PackageName [PackageName]) | ExecutionFailure [SomeException] | CabalExitedUnsuccessfully ExitCode PackageIdentifier (Path Abs File) -- cabal Executable [String] -- cabal arguments (Maybe (Path Abs File)) -- logfiles location [Text] -- log contents | SetupHsBuildFailure ExitCode (Maybe PackageIdentifier) -- which package's custom setup, is simple setup if Nothing (Path Abs File) -- ghc Executable [String] -- ghc arguments (Maybe (Path Abs File)) -- logfiles location [Text] -- log contents deriving (Show, Typeable) instance Pretty BuildPrettyException where pretty ( ConstructPlanFailed errs stackYaml stackRoot parents wanted prunedGlobalDeps ) = "[S-4804]" <> line <> flow "Stack failed to construct a build plan." <> blankLine <> pprintExceptions errs stackYaml stackRoot parents wanted prunedGlobalDeps pretty (ExecutionFailure es) = "[S-7282]" <> line <> flow "Stack failed to execute the build plan." <> blankLine <> flow "While executing the build plan, Stack encountered the \ \following errors:" <> blankLine <> hcat (L.intersperse blankLine (map ppExceptions es)) where ppExceptions :: SomeException -> StyleDoc ppExceptions e = case fromException e of Just (PrettyException e') -> pretty e' Nothing -> (string . show) e pretty (CabalExitedUnsuccessfully exitCode taskProvides' execName fullArgs logFiles bss) = showBuildError "[S-7011]" False exitCode (Just taskProvides') execName fullArgs logFiles bss pretty (SetupHsBuildFailure exitCode mtaskProvides execName fullArgs logFiles bss) = showBuildError "[S-6374]" True exitCode mtaskProvides execName fullArgs logFiles bss instance Exception BuildPrettyException pprintExceptions :: [ConstructPlanException] -> Path Abs File -> Path Abs Dir -> ParentMap -> Set PackageName -> Map PackageName [PackageName] -> StyleDoc pprintExceptions exceptions stackYaml stackRoot parentMap wanted' prunedGlobalDeps = mconcat $ [ flow "While constructing the build plan, Stack encountered the \ \following errors:" , blankLine , mconcat (L.intersperse blankLine (mapMaybe pprintException exceptions')) ] ++ if L.null recommendations then [] else [ blankLine , flow "Some different approaches to resolving this:" , blankLine ] ++ recommendations where exceptions' = {- should we dedupe these somehow? nubOrd -} exceptions recommendations = if not onlyHasDependencyMismatches then [] else [ " *" <+> align ( flow "Set 'allow-newer: true' in " <+> pretty (defaultUserConfigPath stackRoot) <+> "to ignore all version constraints and build anyway." ) , blankLine ] ++ addExtraDepsRecommendations addExtraDepsRecommendations | Map.null extras = [] | (Just _) <- Map.lookup (mkPackageName "base") extras = [ " *" <+> align (flow "Build requires unattainable version of base. Since base is a part of GHC, you most likely need to use a different GHC version with the matching base.") , line ] | otherwise = [ " *" <+> align (style Recommendation (flow "Recommended action:") <+> flow "try adding the following to your extra-deps in" <+> pretty stackYaml <> ":") , blankLine , vsep (map pprintExtra (Map.toList extras)) , line ] extras = Map.unions $ map getExtras exceptions' getExtras DependencyCycleDetected{} = Map.empty getExtras UnknownPackage{} = Map.empty getExtras (DependencyPlanFailures _ m) = Map.unions $ map go $ Map.toList m where -- TODO: Likely a good idea to distinguish these to the user. In particular, for DependencyMismatch go (name, (_range, Just (version,cabalHash), NotInBuildPlan)) = Map.singleton name (version,cabalHash) go (name, (_range, Just (version,cabalHash), DependencyMismatch{})) = Map.singleton name (version, cabalHash) go _ = Map.empty pprintExtra (name, (version, BlobKey cabalHash cabalSize)) = let cfInfo = CFIHash cabalHash (Just cabalSize) packageIdRev = PackageIdentifierRevision name version cfInfo in fromString ("- " ++ T.unpack (utf8BuilderToText (display packageIdRev))) allNotInBuildPlan = Set.fromList $ concatMap toNotInBuildPlan exceptions' toNotInBuildPlan (DependencyPlanFailures _ pDeps) = map fst $ filter (\(_, (_, _, badDep)) -> badDep == NotInBuildPlan) $ Map.toList pDeps toNotInBuildPlan _ = [] -- This checks if 'allow-newer: true' could resolve all issues. onlyHasDependencyMismatches = all go exceptions' where go DependencyCycleDetected{} = False go UnknownPackage{} = False go (DependencyPlanFailures _ m) = all (\(_, _, depErr) -> isMismatch depErr) (M.elems m) isMismatch DependencyMismatch{} = True isMismatch Couldn'tResolveItsDependencies{} = True isMismatch _ = False pprintException (DependencyCycleDetected pNames) = Just $ flow "Dependency cycle detected in packages:" <> line <> indent 4 (encloseSep "[" "]" "," (map (style Error . fromString . packageNameString) pNames)) pprintException (DependencyPlanFailures pkg pDeps) = case mapMaybe pprintDep (Map.toList pDeps) of [] -> Nothing depErrors -> Just $ flow "In the dependencies for" <+> pkgIdent <> pprintFlags (packageFlags pkg) <> ":" <> line <> indent 4 (vsep depErrors) <> case getShortestDepsPath parentMap wanted' (packageName pkg) of Nothing -> line <> flow "needed for unknown reason - stack invariant violated." Just [] -> line <> flow "needed since" <+> pkgName' <+> flow "is a build target." Just (target:path) -> line <> flow "needed due to" <+> encloseSep "" "" " -> " pathElems where pathElems = [style Target . fromString . packageIdentifierString $ target] ++ map (fromString . packageIdentifierString) path ++ [pkgIdent] where pkgName' = style Current . fromString . packageNameString $ packageName pkg pkgIdent = style Current . fromString . packageIdentifierString $ packageIdentifier pkg -- Skip these when they are redundant with 'NotInBuildPlan' info. pprintException (UnknownPackage name) | name `Set.member` allNotInBuildPlan = Nothing | name `Set.member` wiredInPackages = Just $ flow "Can't build a package with same name as a wired-in-package:" <+> (style Current . fromString . packageNameString $ name) | Just pruned <- Map.lookup name prunedGlobalDeps = let prunedDeps = map (style Current . fromString . packageNameString) pruned in Just $ flow "Can't use GHC boot package" <+> (style Current . fromString . packageNameString $ name) <+> flow "when it has an overridden dependency (issue #4510);" <+> flow "you need to add the following as explicit dependencies to the project:" <+> line <+> encloseSep "" "" ", " prunedDeps | otherwise = Just $ flow "Unknown package:" <+> (style Current . fromString . packageNameString $ name) pprintFlags flags | Map.null flags = "" | otherwise = parens $ sep $ map pprintFlag $ Map.toList flags pprintFlag (name, True) = "+" <> fromString (flagNameString name) pprintFlag (name, False) = "-" <> fromString (flagNameString name) pprintDep (name, (range, mlatestApplicable, badDep)) = case badDep of NotInBuildPlan | name `elem` fold prunedGlobalDeps -> Just $ style Error (fromString $ packageNameString name) <+> align ((if range == C.anyVersion then flow "needed" else flow "must match" <+> goodRange) <> "," <> softline <> flow "but this GHC boot package has been pruned (issue #4510);" <+> flow "you need to add the package explicitly to extra-deps" <+> latestApplicable Nothing) | otherwise -> Just $ style Error (fromString $ packageNameString name) <+> align ((if range == C.anyVersion then flow "needed" else flow "must match" <+> goodRange) <> "," <> softline <> flow "but the Stack configuration has no specified version" <+> latestApplicable Nothing) -- TODO: For local packages, suggest editing constraints DependencyMismatch version -> Just $ (style Error . fromString . packageIdentifierString) (PackageIdentifier name version) <+> align (flow "from Stack configuration does not match" <+> goodRange <+> latestApplicable (Just version)) -- I think the main useful info is these explain why missing -- packages are needed. Instead lets give the user the shortest -- path from a target to the package. Couldn'tResolveItsDependencies _version -> Nothing HasNoLibrary -> Just $ style Error (fromString $ packageNameString name) <+> align (flow "is a library dependency, but the package provides no library") BDDependencyCycleDetected names -> Just $ style Error (fromString $ packageNameString name) <+> align (flow $ "dependency cycle detected: " ++ L.intercalate ", " (map packageNameString names)) where goodRange = style Good (fromString (C.display range)) latestApplicable mversion = case mlatestApplicable of Nothing | isNothing mversion -> flow "(no package with that name found, perhaps there \ \is a typo in a package's build-depends or an \ \omission from the stack.yaml packages list?)" | otherwise -> "" Just (laVer, _) | Just laVer == mversion -> flow "(latest matching version is specified)" | otherwise -> fillSep [ flow "(latest matching version is" , style Good (fromString $ versionString laVer) <> ")" ] -- | Get the shortest reason for the package to be in the build plan. In -- other words, trace the parent dependencies back to a 'wanted' -- package. getShortestDepsPath :: ParentMap -> Set PackageName -> PackageName -> Maybe [PackageIdentifier] getShortestDepsPath (MonoidMap parentsMap) wanted' name = if Set.member name wanted' then Just [] else case M.lookup name parentsMap of Nothing -> Nothing Just (_, parents) -> Just $ findShortest 256 paths0 where paths0 = M.fromList $ map (\(ident, _) -> (pkgName ident, startDepsPath ident)) parents where -- The 'paths' map is a map from PackageName to the shortest path -- found to get there. It is the frontier of our breadth-first -- search of dependencies. findShortest :: Int -> Map PackageName DepsPath -> [PackageIdentifier] findShortest fuel _ | fuel <= 0 = [PackageIdentifier (mkPackageName "stack-ran-out-of-jet-fuel") (C.mkVersion [0])] findShortest _ paths | M.null paths = [] findShortest fuel paths = case targets of [] -> findShortest (fuel - 1) $ M.fromListWith chooseBest $ concatMap extendPath recurses _ -> let (DepsPath _ _ path) = L.minimum (map snd targets) in path where (targets, recurses) = L.partition (\(n, _) -> n `Set.member` wanted') (M.toList paths) chooseBest :: DepsPath -> DepsPath -> DepsPath chooseBest x y = max x y -- Extend a path to all its parents. extendPath :: (PackageName, DepsPath) -> [(PackageName, DepsPath)] extendPath (n, dp) = case M.lookup n parentsMap of Nothing -> [] Just (_, parents) -> map (\(pkgId, _) -> (pkgName pkgId, extendDepsPath pkgId dp)) parents startDepsPath :: PackageIdentifier -> DepsPath startDepsPath ident = DepsPath { dpLength = 1 , dpNameLength = length (packageNameString (pkgName ident)) , dpPath = [ident] } extendDepsPath :: PackageIdentifier -> DepsPath -> DepsPath extendDepsPath ident dp = DepsPath { dpLength = dpLength dp + 1 , dpNameLength = dpNameLength dp + length (packageNameString (pkgName ident)) , dpPath = [ident] } data ConstructPlanException = DependencyCycleDetected [PackageName] | DependencyPlanFailures Package (Map PackageName (VersionRange, LatestApplicableVersion, BadDependency)) | UnknownPackage PackageName -- TODO perhaps this constructor will be removed, and BadDependency will handle it all -- ^ Recommend adding to extra-deps, give a helpful version number? deriving (Typeable, Eq, Show) -- | The latest applicable version and it's latest Cabal file revision. -- For display purposes only, Nothing if package not found type LatestApplicableVersion = Maybe (Version, BlobKey) -- | Reason why a dependency was not used data BadDependency = NotInBuildPlan | Couldn'tResolveItsDependencies Version | DependencyMismatch Version | HasNoLibrary -- ^ See description of 'DepType' | BDDependencyCycleDetected ![PackageName] deriving (Typeable, Eq, Ord, Show) type ParentMap = MonoidMap PackageName (First Version, [(PackageIdentifier, VersionRange)]) data DepsPath = DepsPath { dpLength :: Int -- ^ Length of dpPath , dpNameLength :: Int -- ^ Length of package names combined , dpPath :: [PackageIdentifier] -- ^ A path where the packages later -- in the list depend on those that -- come earlier } deriving (Eq, Ord, Show) data FlagSource = FSCommandLine | FSStackYaml deriving (Show, Eq, Ord) data UnusedFlags = UFNoPackage FlagSource PackageName | UFFlagsNotDefined FlagSource PackageName (Set FlagName) -- defined in package (Set FlagName) -- not defined | UFSnapshot PackageName deriving (Show, Eq, Ord) missingExeError :: String -> Bool -> String -> String missingExeError errorCode isSimpleBuildType msg = unlines $ "Error: " <> errorCode : msg : "Possible causes of this issue:" : map ("* " <>) possibleCauses where possibleCauses = "No module named \"Main\". The 'main-is' source file should usually \ \have a header indicating that it's a 'Main' module." : "A Cabal file that refers to nonexistent other files (e.g. a \ \license-file that doesn't exist). Running 'cabal check' may point \ \out these issues." : if isSimpleBuildType then [] else ["The Setup.hs file is changing the installation target dir."] showBuildError :: String -> Bool -> ExitCode -> Maybe PackageIdentifier -> Path Abs File -> [String] -> Maybe (Path Abs File) -> [Text] -> StyleDoc showBuildError errorCode isBuildingSetup exitCode mtaskProvides execName fullArgs logFiles bss = let fullCmd = unwords $ dropQuotes (toFilePath execName) : map (T.unpack . showProcessArgDebug) fullArgs logLocations = maybe mempty (\fp -> line <> flow "Logs have been written to:" <+> style File (pretty fp)) logFiles in fromString errorCode <> line <> flow "While building" <+> ( case (isBuildingSetup, mtaskProvides) of (False, Nothing) -> impureThrow ShowBuildErrorBug (False, Just taskProvides') -> "package" <+> style Target (fromString $ dropQuotes (packageIdentifierString taskProvides')) (True, Nothing) -> "simple" <+> style File "Setup.hs" (True, Just taskProvides') -> "custom" <+> style File "Setup.hs" <+> flow "for package" <+> style Target (fromString $ dropQuotes (packageIdentifierString taskProvides')) ) <+> flow "(scroll up to its section to see the error) using:" <> line <> style Shell (fromString fullCmd) <> line <> flow "Process exited with code:" <+> (fromString . show) exitCode <+> ( if exitCode == ExitFailure (-9) then flow "(THIS MAY INDICATE OUT OF MEMORY)" else mempty ) <> logLocations <> if null bss then mempty else blankLine <> string (removeTrailingSpaces (map T.unpack bss)) where removeTrailingSpaces = dropWhileEnd isSpace . unlines dropQuotes = filter ('\"' /=) ---------------------------------------------- -- | Package dependency oracle. newtype PkgDepsOracle = PkgDeps PackageName deriving (Show,Typeable,Eq,NFData) -- | Stored on disk to know whether the files have changed. newtype BuildCache = BuildCache { buildCacheTimes :: Map FilePath FileCacheInfo -- ^ Modification times of files. } deriving (Generic, Eq, Show, Typeable, ToJSON, FromJSON) instance NFData BuildCache -- | Stored on disk to know whether the flags have changed. data ConfigCache = ConfigCache { configCacheOpts :: !ConfigureOpts -- ^ All options used for this package. , configCacheDeps :: !(Set GhcPkgId) -- ^ The GhcPkgIds of all of the dependencies. Since Cabal doesn't take -- the complete GhcPkgId (only a PackageIdentifier) in the configure -- options, just using the previous value is insufficient to know if -- dependencies have changed. , configCacheComponents :: !(Set S.ByteString) -- ^ The components to be built. It's a bit of a hack to include this in -- here, as it's not a configure option (just a build option), but this -- is a convenient way to force compilation when the components change. , configCacheHaddock :: !Bool -- ^ Are haddocks to be built? , configCachePkgSrc :: !CachePkgSrc , configCachePathEnvVar :: !Text -- ^ Value of the PATH env var, see } deriving (Generic, Eq, Show, Data, Typeable) instance NFData ConfigCache data CachePkgSrc = CacheSrcUpstream | CacheSrcLocal FilePath deriving (Generic, Eq, Read, Show, Data, Typeable) instance NFData CachePkgSrc instance PersistField CachePkgSrc where toPersistValue CacheSrcUpstream = PersistText "upstream" toPersistValue (CacheSrcLocal fp) = PersistText ("local:" <> T.pack fp) fromPersistValue (PersistText t) = do if t == "upstream" then Right CacheSrcUpstream else case T.stripPrefix "local:" t of Just fp -> Right $ CacheSrcLocal (T.unpack fp) Nothing -> Left $ "Unexpected CachePkgSrc value: " <> t fromPersistValue _ = Left "Unexpected CachePkgSrc type" instance PersistFieldSql CachePkgSrc where sqlType _ = SqlString toCachePkgSrc :: PackageSource -> CachePkgSrc toCachePkgSrc (PSFilePath lp) = CacheSrcLocal (toFilePath (parent (lpCabalFile lp))) toCachePkgSrc PSRemote{} = CacheSrcUpstream -- | A task to perform when building data Task = Task { taskProvides :: !PackageIdentifier -- FIXME turn this into a function on taskType? -- ^ the package/version to be built , taskType :: !TaskType -- ^ the task type, telling us how to build this , taskConfigOpts :: !TaskConfigOpts , taskBuildHaddock :: !Bool , taskPresent :: !(Map PackageIdentifier GhcPkgId) -- ^ GhcPkgIds of already-installed dependencies , taskAllInOne :: !Bool -- ^ indicates that the package can be built in one step , taskCachePkgSrc :: !CachePkgSrc , taskAnyMissing :: !Bool -- ^ Were any of the dependencies missing? The reason this is -- necessary is... hairy. And as you may expect, a bug in -- Cabal. See: -- . The -- problem is that Cabal may end up generating the same package ID -- for a dependency, even if the ABI has changed. As a result, -- without this field, Stack would think that a reconfigure is -- unnecessary, when in fact we _do_ need to reconfigure. The -- details here suck. We really need proper hashes for package -- identifiers. , taskBuildTypeConfig :: !Bool -- ^ Is the build type of this package Configure. Check out -- ensureConfigureScript in Stack.Build.Execute for the motivation } deriving Show -- | Given the IDs of any missing packages, produce the configure options data TaskConfigOpts = TaskConfigOpts { tcoMissing :: !(Set PackageIdentifier) -- ^ Dependencies for which we don't yet have an GhcPkgId , tcoOpts :: !(Map PackageIdentifier GhcPkgId -> ConfigureOpts) -- ^ Produce the list of options given the missing @GhcPkgId@s } instance Show TaskConfigOpts where show (TaskConfigOpts missing f) = concat [ "Missing: " , show missing , ". Without those: " , show $ f Map.empty ] -- | The type of a task, either building local code or something from the -- package index (upstream) data TaskType = TTLocalMutable LocalPackage | TTRemotePackage IsMutable Package PackageLocationImmutable deriving Show data IsMutable = Mutable | Immutable deriving (Eq, Show) instance Semigroup IsMutable where Mutable <> _ = Mutable _ <> Mutable = Mutable Immutable <> Immutable = Immutable instance Monoid IsMutable where mempty = Immutable mappend = (<>) taskIsTarget :: Task -> Bool taskIsTarget t = case taskType t of TTLocalMutable lp -> lpWanted lp _ -> False taskLocation :: Task -> InstallLocation taskLocation task = case taskType task of TTLocalMutable _ -> Local TTRemotePackage Mutable _ _ -> Local TTRemotePackage Immutable _ _ -> Snap taskTargetIsMutable :: Task -> IsMutable taskTargetIsMutable task = case taskType task of TTLocalMutable _ -> Mutable TTRemotePackage mutable _ _ -> mutable installLocationIsMutable :: InstallLocation -> IsMutable installLocationIsMutable Snap = Immutable installLocationIsMutable Local = Mutable -- | A complete plan of what needs to be built and how to do it data Plan = Plan { planTasks :: !(Map PackageName Task) , planFinals :: !(Map PackageName Task) -- ^ Final actions to be taken (test, benchmark, etc) , planUnregisterLocal :: !(Map GhcPkgId (PackageIdentifier, Text)) -- ^ Text is reason we're unregistering, for display only , planInstallExes :: !(Map Text InstallLocation) -- ^ Executables that should be installed after successful building } deriving Show -- | Basic information used to calculate what the configure options are data BaseConfigOpts = BaseConfigOpts { bcoSnapDB :: !(Path Abs Dir) , bcoLocalDB :: !(Path Abs Dir) , bcoSnapInstallRoot :: !(Path Abs Dir) , bcoLocalInstallRoot :: !(Path Abs Dir) , bcoBuildOpts :: !BuildOpts , bcoBuildOptsCLI :: !BuildOptsCLI , bcoExtraDBs :: ![Path Abs Dir] } deriving Show -- | Render a @BaseConfigOpts@ to an actual list of options configureOpts :: EnvConfig -> BaseConfigOpts -> Map PackageIdentifier GhcPkgId -- ^ dependencies -> Bool -- ^ local non-extra-dep? -> IsMutable -> Package -> ConfigureOpts configureOpts econfig bco deps isLocal isMutable package = ConfigureOpts { coDirs = configureOptsDirs bco isMutable package , coNoDirs = configureOptsNoDir econfig bco deps isLocal package } -- options set by stack isStackOpt :: Text -> Bool isStackOpt t = any (`T.isPrefixOf` t) [ "--dependency=" , "--constraint=" , "--package-db=" , "--libdir=" , "--bindir=" , "--datadir=" , "--libexecdir=" , "--sysconfdir" , "--docdir=" , "--htmldir=" , "--haddockdir=" , "--enable-tests" , "--enable-benchmarks" , "--exact-configuration" -- Treat these as causing dirtiness, to resolve -- https://github.com/commercialhaskell/stack/issues/2984 -- -- , "--enable-library-profiling" -- , "--enable-executable-profiling" -- , "--enable-profiling" ] || t == "--user" configureOptsDirs :: BaseConfigOpts -> IsMutable -> Package -> [String] configureOptsDirs bco isMutable package = concat [ ["--user", "--package-db=clear", "--package-db=global"] , map (("--package-db=" ++) . toFilePathNoTrailingSep) $ case isMutable of Immutable -> bcoExtraDBs bco ++ [bcoSnapDB bco] Mutable -> bcoExtraDBs bco ++ [bcoSnapDB bco] ++ [bcoLocalDB bco] , [ "--libdir=" ++ toFilePathNoTrailingSep (installRoot relDirLib) , "--bindir=" ++ toFilePathNoTrailingSep (installRoot bindirSuffix) , "--datadir=" ++ toFilePathNoTrailingSep (installRoot relDirShare) , "--libexecdir=" ++ toFilePathNoTrailingSep (installRoot relDirLibexec) , "--sysconfdir=" ++ toFilePathNoTrailingSep (installRoot relDirEtc) , "--docdir=" ++ toFilePathNoTrailingSep docDir , "--htmldir=" ++ toFilePathNoTrailingSep docDir , "--haddockdir=" ++ toFilePathNoTrailingSep docDir] ] where installRoot = case isMutable of Immutable -> bcoSnapInstallRoot bco Mutable -> bcoLocalInstallRoot bco docDir = case pkgVerDir of Nothing -> installRoot docDirSuffix Just dir -> installRoot docDirSuffix dir pkgVerDir = parseRelDir (packageIdentifierString (PackageIdentifier (packageName package) (packageVersion package)) ++ [pathSeparator]) -- | Same as 'configureOpts', but does not include directory path options configureOptsNoDir :: EnvConfig -> BaseConfigOpts -> Map PackageIdentifier GhcPkgId -- ^ dependencies -> Bool -- ^ is this a local, non-extra-dep? -> Package -> [String] configureOptsNoDir econfig bco deps isLocal package = concat [ depOptions , ["--enable-library-profiling" | boptsLibProfile bopts || boptsExeProfile bopts] -- Cabal < 1.21.1 does not support --enable-profiling, use --enable-executable-profiling instead , let profFlag = "--enable-" <> concat ["executable-" | not newerCabal] <> "profiling" in [ profFlag | boptsExeProfile bopts && isLocal] , ["--enable-split-objs" | boptsSplitObjs bopts] , ["--disable-library-stripping" | not $ boptsLibStrip bopts || boptsExeStrip bopts] , ["--disable-executable-stripping" | not (boptsExeStrip bopts) && isLocal] , map (\(name,enabled) -> "-f" <> (if enabled then "" else "-") <> flagNameString name) (Map.toList flags) , map T.unpack $ packageCabalConfigOpts package , processGhcOptions (packageGhcOptions package) , map ("--extra-include-dirs=" ++) (configExtraIncludeDirs config) , map ("--extra-lib-dirs=" ++) (configExtraLibDirs config) , maybe [] (\customGcc -> ["--with-gcc=" ++ toFilePath customGcc]) (configOverrideGccPath config) , ["--exact-configuration"] , ["--ghc-option=-fhide-source-paths" | hideSourcePaths cv] ] where -- This function parses the GHC options that are providing in the -- stack.yaml file. In order to handle RTS arguments correctly, we need -- to provide the RTS arguments as a single argument. processGhcOptions :: [Text] -> [String] processGhcOptions args = let (preRtsArgs, mid) = break ("+RTS" ==) args (rtsArgs, end) = break ("-RTS" ==) mid fullRtsArgs = case rtsArgs of [] -> -- This means that we didn't have any RTS args - no -- `+RTS` - and therefore no need for a `-RTS`. [] _ -> -- In this case, we have some RTS args. `break` -- puts the `"-RTS"` string in the `snd` list, so -- we want to append it on the end of `rtsArgs` -- here. -- -- We're not checking that `-RTS` is the first -- element of `end`. This is because the GHC RTS -- allows you to omit a trailing -RTS if that's the -- last of the arguments. This permits a GHC -- options in stack.yaml that matches what you -- might pass directly to GHC. [T.unwords $ rtsArgs ++ ["-RTS"]] -- We drop the first element from `end`, because it is always -- either `"-RTS"` (and we don't want that as a separate -- argument) or the list is empty (and `drop _ [] = []`). postRtsArgs = drop 1 end newArgs = concat [preRtsArgs, fullRtsArgs, postRtsArgs] in concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) newArgs wc = view (actualCompilerVersionL.to whichCompiler) econfig cv = view (actualCompilerVersionL.to getGhcVersion) econfig hideSourcePaths ghcVersion = ghcVersion >= C.mkVersion [8, 2] && configHideSourcePaths config config = view configL econfig bopts = bcoBuildOpts bco newerCabal = view cabalVersionL econfig >= C.mkVersion [1, 22] -- Unioning atop defaults is needed so that all flags are specified -- with --exact-configuration. flags = packageFlags package `Map.union` packageDefaultFlags package depOptions = map (uncurry toDepOption) $ Map.toList deps where toDepOption = if newerCabal then toDepOption1_22 else toDepOption1_18 toDepOption1_22 (PackageIdentifier name _) gid = concat [ "--dependency=" , packageNameString name , "=" , ghcPkgIdString gid ] toDepOption1_18 ident _gid = concat [ "--constraint=" , packageNameString name , "==" , versionString version' ] where PackageIdentifier name version' = ident -- | Get set of wanted package names from locals. wantedLocalPackages :: [LocalPackage] -> Set PackageName wantedLocalPackages = Set.fromList . map (packageName . lpPackage) . filter lpWanted -- | Configure options to be sent to Setup.hs configure data ConfigureOpts = ConfigureOpts { coDirs :: ![String] -- ^ Options related to various paths. We separate these out since they do -- not have an impact on the contents of the compiled binary for checking -- if we can use an existing precompiled cache. , coNoDirs :: ![String] } deriving (Show, Eq, Generic, Data, Typeable) instance NFData ConfigureOpts -- | Information on a compiled package: the library conf file (if relevant), -- the sublibraries (if present) and all of the executable paths. data PrecompiledCache base = PrecompiledCache { pcLibrary :: !(Maybe (Path base File)) -- ^ .conf file inside the package database , pcSubLibs :: ![Path base File] -- ^ .conf file inside the package database, for each of the sublibraries , pcExes :: ![Path base File] -- ^ Full paths to executables } deriving (Show, Eq, Generic, Typeable) instance NFData (PrecompiledCache Abs) instance NFData (PrecompiledCache Rel) stack-2.9.3.1/src/Stack/Types/CompilerBuild.hs0000644000000000000000000000257114445022466017221 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Types.CompilerBuild ( CompilerBuild (..) , compilerBuildName , compilerBuildSuffix , parseCompilerBuild ) where import Stack.Prelude import Pantry.Internal.AesonExtended ( FromJSON, parseJSON, withText ) import Data.Text as T data CompilerBuild = CompilerBuildStandard | CompilerBuildSpecialized String deriving (Show) instance FromJSON CompilerBuild where -- Strange structuring is to give consistent error messages parseJSON = withText "CompilerBuild" (either (fail . show) pure . parseCompilerBuild . T.unpack) -- | Descriptive name for compiler build compilerBuildName :: CompilerBuild -> String compilerBuildName CompilerBuildStandard = "standard" compilerBuildName (CompilerBuildSpecialized s) = s -- | Suffix to use for filenames/directories constructed with compiler build compilerBuildSuffix :: CompilerBuild -> String compilerBuildSuffix CompilerBuildStandard = "" compilerBuildSuffix (CompilerBuildSpecialized s) = '-' : s -- | Parse compiler build from a String. parseCompilerBuild :: (MonadThrow m) => String -> m CompilerBuild parseCompilerBuild "" = pure CompilerBuildStandard parseCompilerBuild "standard" = pure CompilerBuildStandard parseCompilerBuild name = pure (CompilerBuildSpecialized name) stack-2.9.3.1/src/Stack/Types/Compiler.hs0000644000000000000000000001123214445022466016233 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} module Stack.Types.Compiler ( ActualCompiler (..) , WhichCompiler (..) , CompilerRepository (..) , CompilerException (..) , defaultCompilerRepository , getGhcVersion , whichCompiler , compilerVersionText , compilerVersionString , isWantedCompiler , wantedToActual , actualToWanted , parseActualCompiler ) where import Data.Aeson import Database.Persist import Database.Persist.Sql import qualified Data.Text as T import Stack.Prelude import Stack.Types.Version import Distribution.Version ( mkVersion ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Types.Compiler" module. data CompilerException = GhcjsNotSupported | PantryException PantryException deriving (Show, Typeable) instance Exception CompilerException where displayException GhcjsNotSupported = "Error: [S-7903]\n" ++ "GHCJS is no longer supported by Stack." displayException (PantryException p) = "Error: [S-7972]\n" ++ displayException p -- | Variety of compiler to use. data WhichCompiler = Ghc deriving (Show, Eq, Ord) -- | Specifies a compiler and its version number(s). -- -- Note that despite having this datatype, Stack isn't in a hurry to -- support compilers other than GHC. data ActualCompiler = ACGhc !Version | ACGhcGit !Text !Text deriving (Generic, Show, Eq, Ord, Data, Typeable) instance NFData ActualCompiler instance Display ActualCompiler where display (ACGhc x) = display (WCGhc x) display (ACGhcGit x y) = display (WCGhcGit x y) instance ToJSON ActualCompiler where toJSON = toJSON . compilerVersionText instance FromJSON ActualCompiler where parseJSON (String t) = either (const $ fail "Failed to parse compiler version") pure (parseActualCompiler t) parseJSON _ = fail "Invalid CompilerVersion, must be String" instance FromJSONKey ActualCompiler where fromJSONKey = FromJSONKeyTextParser $ \k -> case parseActualCompiler k of Left _ -> fail $ "Failed to parse CompilerVersion " ++ T.unpack k Right parsed -> pure parsed instance PersistField ActualCompiler where toPersistValue = toPersistValue . compilerVersionText fromPersistValue = (mapLeft tshow . parseActualCompiler) <=< fromPersistValue instance PersistFieldSql ActualCompiler where sqlType _ = SqlString wantedToActual :: WantedCompiler -> Either CompilerException ActualCompiler wantedToActual (WCGhc x) = Right $ ACGhc x wantedToActual (WCGhcjs _ _) = Left GhcjsNotSupported wantedToActual (WCGhcGit x y) = Right $ ACGhcGit x y actualToWanted :: ActualCompiler -> WantedCompiler actualToWanted (ACGhc x) = WCGhc x actualToWanted (ACGhcGit x y) = WCGhcGit x y parseActualCompiler :: T.Text -> Either CompilerException ActualCompiler parseActualCompiler = either (Left . PantryException) wantedToActual . parseWantedCompiler compilerVersionText :: ActualCompiler -> T.Text compilerVersionText = utf8BuilderToText . display compilerVersionString :: ActualCompiler -> String compilerVersionString = T.unpack . compilerVersionText whichCompiler :: ActualCompiler -> WhichCompiler whichCompiler ACGhc{} = Ghc whichCompiler ACGhcGit{} = Ghc isWantedCompiler :: VersionCheck -> WantedCompiler -> ActualCompiler -> Bool isWantedCompiler check (WCGhc wanted) (ACGhc actual) = checkVersion check wanted actual isWantedCompiler _check (WCGhcGit wCommit wFlavour) (ACGhcGit aCommit aFlavour) = wCommit == aCommit && wFlavour == aFlavour isWantedCompiler _ _ _ = False getGhcVersion :: ActualCompiler -> Version getGhcVersion (ACGhc v) = v getGhcVersion (ACGhcGit _ _) = -- We can't return the actual version without running the installed ghc. -- For now we assume that users of ghc-git use it with a recent commit so we -- return a version far in the future. This disables our hacks for older -- versions and passes version checking when we use newer features. mkVersion [999,0,0] -- | Repository containing the compiler sources newtype CompilerRepository = CompilerRepository Text deriving (Show) instance FromJSON CompilerRepository where parseJSON = withText "CompilerRepository" (pure . CompilerRepository) defaultCompilerRepository :: CompilerRepository defaultCompilerRepository = CompilerRepository "https://gitlab.haskell.org/ghc/ghc.git" stack-2.9.3.1/src/Stack/Types/Config.hs0000644000000000000000000026350714445022466015704 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ViewPatterns #-} -- | The Config type. module Stack.Types.Config ( -- * Main configuration types and classes -- ** HasPlatform & HasStackRoot HasPlatform (..) , PlatformVariant (..) -- ** Runner , HasRunner (..) , Runner (..) , ColorWhen (..) , terminalL , reExecL -- ** Config & HasConfig , Config (..) , HasConfig (..) , askLatestSnapshotUrl , configProjectRoot -- ** BuildConfig & HasBuildConfig , BuildConfig (..) , ProjectPackage (..) , DepPackage (..) , ppRoot , ppVersion , ppComponents , ppGPD , stackYamlL , projectRootL , HasBuildConfig (..) -- ** Storage databases , UserStorage (..) , ProjectStorage (..) -- ** GHCVariant & HasGHCVariant , GHCVariant (..) , ghcVariantName , ghcVariantSuffix , parseGHCVariant , HasGHCVariant (..) , snapshotsDir -- ** EnvConfig & HasEnvConfig , EnvConfig (..) , HasSourceMap (..) , HasEnvConfig (..) , getCompilerPath -- * Details -- ** ApplyGhcOptions , ApplyGhcOptions (..) -- ** AllowNewerDeps , AllowNewerDeps (..) -- ** CabalConfigKey , CabalConfigKey (..) -- ** ConfigException , HpackExecutable (..) , ConfigException (..) , ConfigPrettyException (..) , ParseAbsolutePathException (..) , packageIndicesWarning -- ** ConfigMonoid , ConfigMonoid (..) , configMonoidInstallGHCName , configMonoidSystemGHCName , parseConfigMonoid -- ** DumpLogs , DumpLogs (..) -- ** EnvSettings , EnvSettings (..) , minimalEnvSettings , defaultEnvSettings , plainEnvSettings -- ** GlobalOpts & GlobalOptsMonoid , GlobalOpts (..) , GlobalOptsMonoid (..) , rslInLogL , StackYamlLoc (..) , stackYamlLocL , LockFileBehavior (..) , readLockFileBehavior , lockFileBehaviorL , defaultLogLevel -- ** Project & ProjectAndConfigMonoid , Project (..) , ProjectConfig (..) , Curator (..) , ProjectAndConfigMonoid (..) , parseProjectAndConfigMonoid -- ** PvpBounds , PvpBounds (..) , PvpBoundsType (..) , parsePvpBounds -- ** ColorWhen , readColorWhen -- ** Styles , readStyles -- ** SCM , SCM(..) -- * Paths , bindirSuffix , GlobalInfoSource (..) , getProjectWorkDir , docDirSuffix , extraBinDirs , hpcReportDir , installationRootDeps , installationRootLocal , bindirCompilerTools , hoogleRoot , hoogleDatabasePath , packageDatabaseDeps , packageDatabaseExtra , packageDatabaseLocal , platformOnlyRelDir , platformGhcRelDir , platformGhcVerOnlyRelDir , useShaPathOnWindows , shaPath , shaPathForBytes , workDirL , ghcInstallHook -- * Command-related types , AddCommand -- ** Eval , EvalOpts (..) -- ** Exec , ExecOpts (..) , SpecialExecCmd (..) , ExecOptsExtra (..) -- ** Setup , DownloadInfo (..) , VersionedDownloadInfo (..) , GHCDownloadInfo (..) , SetupInfo (..) -- ** Docker entrypoint , DockerEntrypoint (..) , DockerUser (..) , module X -- * Lens helpers , wantedCompilerVersionL , actualCompilerVersionL , HasCompiler (..) , DumpPackage (..) , CompilerPaths (..) , GhcPkgExe (..) , getGhcPkgExe , cpWhich , ExtraDirs (..) , buildOptsL , globalOptsL , buildOptsInstallExesL , buildOptsMonoidHaddockL , buildOptsMonoidTestsL , buildOptsMonoidBenchmarksL , buildOptsMonoidInstallExesL , buildOptsHaddockL , globalOptsBuildOptsMonoidL , stackRootL , stackGlobalConfigL , cabalVersionL , whichCompilerL , envOverrideSettingsL , shouldForceGhcColorFlag , appropriateGhcColorFlag -- * Helper logging functions , prettyStackDevL -- * Lens reexport , view , to ) where import Control.Monad.Writer ( Writer, tell ) import Control.Monad.Trans.Except ( ExceptT ) import Crypto.Hash ( hashWith, SHA1 (..) ) import Pantry.Internal.AesonExtended ( ToJSON, toJSON, FromJSON, FromJSONKey (..), parseJSON , withText, object, (.=), (..:), (...:), (..:?), (..!=) , Value(Bool), withObjectWarnings, WarningParser, Object , jsonSubWarnings, jsonSubWarningsT, jsonSubWarningsTT , WithJSONWarnings (..) , FromJSONKeyFunction (FromJSONKeyTextParser) ) import Data.Attoparsec.Args ( parseArgs, EscapingMode (Escaping) ) import qualified Data.ByteArray.Encoding as Mem ( convertToBase, Base(Base16) ) import qualified Data.ByteString.Char8 as S8 import Data.Coerce ( coerce ) import Data.List ( stripPrefix ) import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Map as Map import qualified Data.Map.Strict as M import qualified Data.Monoid as Monoid import Data.Monoid.Map ( MonoidMap (..) ) import qualified Data.Set as Set import qualified Data.Text as T import Data.Yaml ( ParseException ) import qualified Data.Yaml as Yaml import qualified Distribution.License as C import Distribution.ModuleName ( ModuleName ) import Distribution.PackageDescription ( GenericPackageDescription ) import qualified Distribution.PackageDescription as C import Distribution.System ( Platform, Arch ) import qualified Distribution.Text import Distribution.Version ( anyVersion, mkVersion ) import Generics.Deriving.Monoid ( memptydefault, mappenddefault ) import Lens.Micro import Options.Applicative ( ReadM ) import qualified Options.Applicative as OA import qualified Options.Applicative.Types as OA import Pantry.Internal ( Storage ) import Path import qualified RIO.List as List import Stack.Constants import Stack.Prelude import Stack.Types.Compiler import Stack.Types.CompilerBuild import Stack.Types.Docker import Stack.Types.GhcPkgId import Stack.Types.NamedComponent import Stack.Types.Nix import Stack.Types.Resolver import Stack.Types.SourceMap import Stack.Types.TemplateName import Stack.Types.Version ( IntersectingVersionRange (..), VersionCheck (..) , VersionRange, stackVersion, versionRangeText ) import qualified System.FilePath as FilePath import System.PosixCompat.Types ( UserID, GroupID, FileMode ) import RIO.Process ( ProcessContext, HasProcessContext (..) ) import Casa.Client ( CasaRepoPrefix ) -- Re-exports import Stack.Types.Config.Build as X -- | Type representing exceptions thrown by functions exported by the -- "Stack.Config" module. data ConfigException = ParseCustomSnapshotException Text ParseException | NoProjectConfigFound (Path Abs Dir) (Maybe Text) | UnexpectedArchiveContents [Path Abs Dir] [Path Abs File] | UnableToExtractArchive Text (Path Abs File) | BadStackVersionException VersionRange | NoSuchDirectory FilePath | ParseGHCVariantException String | BadStackRoot (Path Abs Dir) | Won'tCreateStackRootInDirectoryOwnedByDifferentUser (Path Abs Dir) (Path Abs Dir) -- ^ @$STACK_ROOT@, parent dir | UserDoesn'tOwnDirectory (Path Abs Dir) | ManualGHCVariantSettingsAreIncompatibleWithSystemGHC | NixRequiresSystemGhc | NoResolverWhenUsingNoProject | DuplicateLocalPackageNames ![(PackageName, [PackageLocation])] | NoLTSWithMajorVersion Int | NoLTSFound | MultiplePackageIndices [PackageIndexConfig] deriving (Show, Typeable) instance Exception ConfigException where displayException (ParseCustomSnapshotException url exception) = concat [ "Error: [S-8981]\n" , "Could not parse '" , T.unpack url , "':\n" , Yaml.prettyPrintParseException exception , "\nSee https://docs.haskellstack.org/en/stable/custom_snapshot/" ] displayException (NoProjectConfigFound dir mcmd) = concat [ "Error: [S-2206]\n" , "Unable to find a stack.yaml file in the current directory (" , toFilePath dir , ") or its ancestors" , case mcmd of Nothing -> "" Just cmd -> "\nRecommended action: stack " ++ T.unpack cmd ] displayException (UnexpectedArchiveContents dirs files) = concat [ "Error: [S-4964]\n" , "When unpacking an archive specified in your stack.yaml file, " , "did not find expected contents. Expected: a single directory. Found: " , show ( map (toFilePath . dirname) dirs , map (toFilePath . filename) files ) ] displayException (UnableToExtractArchive url file) = concat [ "Error: [S-2040]\n" , "Archive extraction failed. Tarballs and zip archives are supported, \ \couldn't handle the following URL, " , T.unpack url , " downloaded to the file " , toFilePath $ filename file ] displayException (BadStackVersionException requiredRange) = concat [ "Error: [S-1641]\n" , "The version of Stack you are using (" , show stackVersion , ") is outside the required\n" ,"version range specified in stack.yaml (" , T.unpack (versionRangeText requiredRange) , ").\n" , "You can upgrade Stack by running:\n\n" , "stack upgrade" ] displayException (NoSuchDirectory dir) = concat [ "Error: [S-8773]\n" , "No directory could be located matching the supplied path: " , dir ] displayException (ParseGHCVariantException v) = concat [ "Error: [S-3938]\n" , "Invalid ghc-variant value: " , v ] displayException (BadStackRoot stackRoot) = concat [ "Error: [S-8530]\n" , "Invalid Stack root: '" , toFilePath stackRoot , "'. Please provide a valid absolute path." ] displayException (Won'tCreateStackRootInDirectoryOwnedByDifferentUser envStackRoot parentDir) = concat [ "Error: [S-7613]\n" , "Preventing creation of Stack root '" , toFilePath envStackRoot , "'. Parent directory '" , toFilePath parentDir , "' is owned by someone else." ] displayException (UserDoesn'tOwnDirectory dir) = concat [ "Error: [S-8707]\n" , "You are not the owner of '" , toFilePath dir , "'. Aborting to protect file permissions." , "\nRetry with '--" , T.unpack configMonoidAllowDifferentUserName , "' to disable this precaution." ] displayException ManualGHCVariantSettingsAreIncompatibleWithSystemGHC = T.unpack $ T.concat [ "Error: [S-3605]\n" , "Stack can only control the " , configMonoidGHCVariantName , " of its own GHC installations. Please use '--no-" , configMonoidSystemGHCName , "'." ] displayException NixRequiresSystemGhc = T.unpack $ T.concat [ "Error: [S-6816]\n" , "Stack's Nix integration is incompatible with '--no-system-ghc'. " , "Please use '--" , configMonoidSystemGHCName , "' or disable the Nix integration." ] displayException NoResolverWhenUsingNoProject = "Error: [S-5027]\n" ++ "When using the script command, you must provide a resolver argument" displayException (DuplicateLocalPackageNames pairs) = concat $ "Error: [S-5470]\n" : "The same package name is used in multiple local packages\n" : map go pairs where go (name, dirs) = unlines $ "" : (packageNameString name ++ " used in:") : map goLoc dirs goLoc loc = "- " ++ show loc displayException (NoLTSWithMajorVersion n) = concat [ "Error: [S-3803]\n" , "No LTS release found with major version " , show n , "." ] displayException NoLTSFound = "Error: [S-5472]\n" ++ "No LTS releases found." displayException (MultiplePackageIndices pics) = concat [ "Error: [S-3251]\n" , "When using the 'package-indices' key to override the default " , "package index, you must provide exactly one value, received: " , show pics , "\n" , packageIndicesWarning ] -- | Type representing \'pretty\' exceptions thrown by functions exported by the -- "Stack.Config" module. data ConfigPrettyException = ParseConfigFileException !(Path Abs File) !ParseException | NoMatchingSnapshot !(NonEmpty SnapName) | ResolverMismatch !RawSnapshotLocation String | ResolverPartial !RawSnapshotLocation !String deriving (Show, Typeable) instance Pretty ConfigPrettyException where pretty (ParseConfigFileException configFile exception) = "[S-6602]" <> line <> fillSep [ flow "Stack could not load and parse" , style File (pretty configFile) , flow "as a YAML configuraton file." ] <> blankLine <> flow "While loading and parsing, Stack encountered the following \ \error:" <> blankLine <> string (Yaml.prettyPrintParseException exception) <> blankLine <> fillSep [ flow "For help about the content of Stack's YAML configuration \ \files, see (for the most recent release of Stack)" , style Url "http://docs.haskellstack.org/en/stable/yaml_configuration/" <> "." ] pretty (NoMatchingSnapshot names) = "[S-1833]" <> line <> flow "None of the following snapshots provides a compiler matching \ \your package(s):" <> line <> bulletedList (map (fromString . show) (NonEmpty.toList names)) <> blankLine <> resolveOptions pretty (ResolverMismatch resolver errDesc) = "[S-6395]" <> line <> fillSep [ "Snapshot" , style Url (pretty $ PrettyRawSnapshotLocation resolver) , flow "does not have a matching compiler to build some or all of \ \your package(s)." ] <> blankLine <> indent 4 (string errDesc) <> line <> resolveOptions pretty (ResolverPartial resolver errDesc) = "[S-2422]" <> line <> fillSep [ "Snapshot" , style Url (pretty $ PrettyRawSnapshotLocation resolver) , flow "does not have all the packages to match your requirements." ] <> blankLine <> indent 4 (string errDesc) <> line <> resolveOptions instance Exception ConfigPrettyException data ParseAbsolutePathException = ParseAbsolutePathException String String deriving (Show, Typeable) instance Exception ParseAbsolutePathException where displayException (ParseAbsolutePathException envVar dir) = concat [ "Error: [S-9437]\n" , "Failed to parse " , envVar , " environment variable (expected absolute directory): " , dir ] -- | The base environment that almost everything in Stack runs in, -- based off of parsing command line options in 'GlobalOpts'. Provides -- logging and process execution. data Runner = Runner { runnerGlobalOpts :: !GlobalOpts , runnerUseColor :: !Bool , runnerLogFunc :: !LogFunc , runnerTermWidth :: !Int , runnerProcessContext :: !ProcessContext } data ColorWhen = ColorNever | ColorAlways | ColorAuto deriving (Eq, Show, Generic) instance FromJSON ColorWhen where parseJSON v = do s <- parseJSON v case s of "never" -> pure ColorNever "always" -> pure ColorAlways "auto" -> pure ColorAuto _ -> fail ("Unknown color use: " <> s <> ". Expected values of " <> "option are 'never', 'always', or 'auto'.") -- | The top-level Stackage configuration. data Config = Config {configWorkDir :: !(Path Rel Dir) -- ^ this allows to override .stack-work directory ,configUserConfigPath :: !(Path Abs File) -- ^ Path to user configuration file (usually ~/.stack/config.yaml) ,configBuild :: !BuildOpts -- ^ Build configuration ,configDocker :: !DockerOpts -- ^ Docker configuration ,configNix :: !NixOpts -- ^ Execution environment (e.g nix-shell) configuration ,configProcessContextSettings :: !(EnvSettings -> IO ProcessContext) -- ^ Environment variables to be passed to external tools ,configLocalProgramsBase :: !(Path Abs Dir) -- ^ Non-platform-specific path containing local installations ,configLocalPrograms :: !(Path Abs Dir) -- ^ Path containing local installations (mainly GHC) ,configHideTHLoading :: !Bool -- ^ Hide the Template Haskell "Loading package ..." messages from the -- console ,configPrefixTimestamps :: !Bool -- ^ Prefix build output with timestamps for each line. ,configPlatform :: !Platform -- ^ The platform we're building for, used in many directory names ,configPlatformVariant :: !PlatformVariant -- ^ Variant of the platform, also used in directory names ,configGHCVariant :: !(Maybe GHCVariant) -- ^ The variant of GHC requested by the user. ,configGHCBuild :: !(Maybe CompilerBuild) -- ^ Override build of the compiler distribution (e.g. standard, gmp4, tinfo6) ,configLatestSnapshot :: !Text -- ^ URL of a JSON file providing the latest LTS and Nightly snapshots. ,configSystemGHC :: !Bool -- ^ Should we use the system-installed GHC (on the PATH) if -- available? Can be overridden by command line options. ,configInstallGHC :: !Bool -- ^ Should we automatically install GHC if missing or the wrong -- version is available? Can be overridden by command line options. ,configSkipGHCCheck :: !Bool -- ^ Don't bother checking the GHC version or architecture. ,configSkipMsys :: !Bool -- ^ On Windows: don't use a sandboxed MSYS ,configCompilerCheck :: !VersionCheck -- ^ Specifies which versions of the compiler are acceptable. ,configCompilerRepository :: !CompilerRepository -- ^ Specifies the repository containing the compiler sources ,configLocalBin :: !(Path Abs Dir) -- ^ Directory we should install executables into ,configRequireStackVersion :: !VersionRange -- ^ Require a version of Stack within this range. ,configJobs :: !Int -- ^ How many concurrent jobs to run, defaults to number of capabilities ,configOverrideGccPath :: !(Maybe (Path Abs File)) -- ^ Optional gcc override path ,configExtraIncludeDirs :: ![FilePath] -- ^ --extra-include-dirs arguments ,configExtraLibDirs :: ![FilePath] -- ^ --extra-lib-dirs arguments ,configCustomPreprocessorExts :: ![Text] -- ^ List of custom preprocessors to complete the hard coded ones ,configConcurrentTests :: !Bool -- ^ Run test suites concurrently ,configTemplateParams :: !(Map Text Text) -- ^ Parameters for templates. ,configScmInit :: !(Maybe SCM) -- ^ Initialize SCM (e.g. git) when creating new projects. ,configGhcOptionsByName :: !(Map PackageName [Text]) -- ^ Additional GHC options to apply to specific packages. ,configGhcOptionsByCat :: !(Map ApplyGhcOptions [Text]) -- ^ Additional GHC options to apply to categories of packages ,configCabalConfigOpts :: !(Map CabalConfigKey [Text]) -- ^ Additional options to be passed to ./Setup.hs configure ,configSetupInfoLocations :: ![String] -- ^ URLs or paths to stack-setup.yaml files, for finding tools. -- If none present, the default setup-info is used. ,configSetupInfoInline :: !SetupInfo -- ^ Additional SetupInfo to use to find tools. ,configPvpBounds :: !PvpBounds -- ^ How PVP upper bounds should be added to packages ,configModifyCodePage :: !Bool -- ^ Force the code page to UTF-8 on Windows ,configRebuildGhcOptions :: !Bool -- ^ Rebuild on GHC options changes ,configApplyGhcOptions :: !ApplyGhcOptions -- ^ Which packages to ghc-options on the command line apply to? ,configAllowNewer :: !Bool -- ^ Ignore version ranges in .cabal files. Funny naming chosen to -- match cabal. ,configAllowNewerDeps :: !(Maybe [PackageName]) -- ^ Ignore dependency upper and lower bounds only for specified -- packages. No effect unless allow-newer is enabled. ,configDefaultTemplate :: !(Maybe TemplateName) -- ^ The default template to use when none is specified. -- (If Nothing, the 'default' default template is used.) ,configAllowDifferentUser :: !Bool -- ^ Allow users other than the Stack root owner to use the Stack -- installation. ,configDumpLogs :: !DumpLogs -- ^ Dump logs of local non-dependencies when doing a build. ,configProject :: !(ProjectConfig (Project, Path Abs File)) -- ^ Project information and stack.yaml file location ,configAllowLocals :: !Bool -- ^ Are we allowed to build local packages? The script -- command disallows this. ,configSaveHackageCreds :: !Bool -- ^ Should we save Hackage credentials to a file? ,configHackageBaseUrl :: !Text -- ^ Hackage base URL used when uploading packages ,configRunner :: !Runner ,configPantryConfig :: !PantryConfig ,configStackRoot :: !(Path Abs Dir) ,configResolver :: !(Maybe AbstractResolver) -- ^ Any resolver override from the command line ,configUserStorage :: !UserStorage -- ^ Database connection pool for user Stack database ,configHideSourcePaths :: !Bool -- ^ Enable GHC hiding source paths? ,configRecommendUpgrade :: !Bool -- ^ Recommend a Stack upgrade? ,configNoRunCompile :: !Bool -- ^ Use --no-run and --compile options when using `stack script` ,configStackDeveloperMode :: !Bool -- ^ Turn on Stack developer mode for additional messages? } -- | A bit of type safety to ensure we're talking to the right database. newtype UserStorage = UserStorage { unUserStorage :: Storage } -- | A bit of type safety to ensure we're talking to the right database. newtype ProjectStorage = ProjectStorage { unProjectStorage :: Storage } -- | The project root directory, if in a project. configProjectRoot :: Config -> Maybe (Path Abs Dir) configProjectRoot c = case configProject c of PCProject (_, fp) -> Just $ parent fp PCGlobalProject -> Nothing PCNoProject _deps -> Nothing -- | Which packages do configure opts apply to? data CabalConfigKey = CCKTargets -- ^ See AGOTargets | CCKLocals -- ^ See AGOLocals | CCKEverything -- ^ See AGOEverything | CCKPackage !PackageName -- ^ A specific package deriving (Show, Read, Eq, Ord) instance FromJSON CabalConfigKey where parseJSON = withText "CabalConfigKey" parseCabalConfigKey instance FromJSONKey CabalConfigKey where fromJSONKey = FromJSONKeyTextParser parseCabalConfigKey parseCabalConfigKey :: (Monad m, MonadFail m) => Text -> m CabalConfigKey parseCabalConfigKey "$targets" = pure CCKTargets parseCabalConfigKey "$locals" = pure CCKLocals parseCabalConfigKey "$everything" = pure CCKEverything parseCabalConfigKey name = case parsePackageName $ T.unpack name of Nothing -> fail $ "Invalid CabalConfigKey: " ++ show name Just x -> pure $ CCKPackage x -- | Which packages do ghc-options on the command line apply to? data ApplyGhcOptions = AGOTargets -- ^ all local targets | AGOLocals -- ^ all local packages, even non-targets | AGOEverything -- ^ every package deriving (Show, Read, Eq, Ord, Enum, Bounded) instance FromJSON ApplyGhcOptions where parseJSON = withText "ApplyGhcOptions" $ \t -> case t of "targets" -> pure AGOTargets "locals" -> pure AGOLocals "everything" -> pure AGOEverything _ -> fail $ "Invalid ApplyGhcOptions: " ++ show t newtype AllowNewerDeps = AllowNewerDeps [PackageName] deriving (Show, Read, Eq, Ord, Generic) instance Semigroup AllowNewerDeps where (<>) = mappenddefault instance Monoid AllowNewerDeps where mappend = (<>) mempty = memptydefault instance FromJSON AllowNewerDeps where parseJSON = fmap (AllowNewerDeps . fmap C.mkPackageName) . parseJSON -- | Which build log files to dump data DumpLogs = DumpNoLogs -- ^ don't dump any logfiles | DumpWarningLogs -- ^ dump logfiles containing warnings | DumpAllLogs -- ^ dump all logfiles deriving (Show, Read, Eq, Ord, Enum, Bounded) instance FromJSON DumpLogs where parseJSON (Bool True) = pure DumpAllLogs parseJSON (Bool False) = pure DumpNoLogs parseJSON v = withText "DumpLogs" (\t -> if | t == "none" -> pure DumpNoLogs | t == "warning" -> pure DumpWarningLogs | t == "all" -> pure DumpAllLogs | otherwise -> fail ("Invalid DumpLogs: " ++ show t)) v -- | Controls which version of the environment is used data EnvSettings = EnvSettings { esIncludeLocals :: !Bool -- ^ include local project bin directory, GHC_PACKAGE_PATH, etc , esIncludeGhcPackagePath :: !Bool -- ^ include the GHC_PACKAGE_PATH variable , esStackExe :: !Bool -- ^ set the STACK_EXE variable to the current executable name , esLocaleUtf8 :: !Bool -- ^ set the locale to C.UTF-8 , esKeepGhcRts :: !Bool -- ^ if True, keep GHCRTS variable in environment } deriving (Show, Eq, Ord) type AddCommand = ExceptT (RIO Runner ()) (Writer (OA.Mod OA.CommandFields (RIO Runner (), GlobalOptsMonoid))) () data ExecOpts = ExecOpts { eoCmd :: !SpecialExecCmd , eoArgs :: ![String] , eoExtra :: !ExecOptsExtra } deriving (Show) data SpecialExecCmd = ExecCmd String | ExecRun | ExecGhc | ExecRunGhc deriving (Show, Eq) data ExecOptsExtra = ExecOptsExtra { eoEnvSettings :: !EnvSettings , eoPackages :: ![String] , eoRtsOptions :: ![String] , eoCwd :: !(Maybe FilePath) } deriving (Show) data EvalOpts = EvalOpts { evalArg :: !String , evalExtra :: !ExecOptsExtra } deriving (Show) -- | Parsed global command-line options. data GlobalOpts = GlobalOpts { globalReExecVersion :: !(Maybe String) -- ^ Expected re-exec in container version , globalDockerEntrypoint :: !(Maybe DockerEntrypoint) -- ^ Data used when Stack is acting as a Docker entrypoint (internal use only) , globalLogLevel :: !LogLevel -- ^ Log level , globalTimeInLog :: !Bool -- ^ Whether to include timings in logs. , globalRSLInLog :: !Bool -- ^ Whether to include raw snapshot layer (RSL) in logs. , globalConfigMonoid :: !ConfigMonoid -- ^ Config monoid, for passing into 'loadConfig' , globalResolver :: !(Maybe AbstractResolver) -- ^ Resolver override , globalCompiler :: !(Maybe WantedCompiler) -- ^ Compiler override , globalTerminal :: !Bool -- ^ We're in a terminal? , globalStylesUpdate :: !StylesUpdate -- ^ SGR (Ansi) codes for styles , globalTermWidth :: !(Maybe Int) -- ^ Terminal width override , globalStackYaml :: !StackYamlLoc -- ^ Override project stack.yaml , globalLockFileBehavior :: !LockFileBehavior } deriving (Show) rslInLogL :: HasRunner env => SimpleGetter env Bool rslInLogL = globalOptsL.to globalRSLInLog -- | Location for the project's stack.yaml file. data StackYamlLoc = SYLDefault -- ^ Use the standard parent-directory-checking logic | SYLOverride !(Path Abs File) -- ^ Use a specific stack.yaml file provided | SYLNoProject ![PackageIdentifierRevision] -- ^ Do not load up a project, just user configuration. Include -- the given extra dependencies with the resolver. | SYLGlobalProject -- ^ Do not look for a project configuration, and use the implicit global. deriving Show stackYamlLocL :: HasRunner env => Lens' env StackYamlLoc stackYamlLocL = globalOptsL.lens globalStackYaml (\x y -> x { globalStackYaml = y }) -- | How to interact with lock files data LockFileBehavior = LFBReadWrite -- ^ Read and write lock files | LFBReadOnly -- ^ Read lock files, but do not write them | LFBIgnore -- ^ Entirely ignore lock files | LFBErrorOnWrite -- ^ Error out on trying to write a lock file. This can be used to -- ensure that lock files in a repository already ensure -- reproducible builds. deriving (Show, Enum, Bounded) lockFileBehaviorL :: HasRunner env => SimpleGetter env LockFileBehavior lockFileBehaviorL = globalOptsL.to globalLockFileBehavior -- | Parser for 'LockFileBehavior' readLockFileBehavior :: ReadM LockFileBehavior readLockFileBehavior = do s <- OA.readerAsk case Map.lookup s m of Just x -> pure x Nothing -> OA.readerError $ "Invalid lock file behavior, valid options: " ++ List.intercalate ", " (Map.keys m) where m = Map.fromList $ map (\x -> (render x, x)) [minBound..maxBound] render LFBReadWrite = "read-write" render LFBReadOnly = "read-only" render LFBIgnore = "ignore" render LFBErrorOnWrite = "error-on-write" -- | Project configuration information. Not every run of Stack has a -- true local project; see constructors below. data ProjectConfig a = PCProject a -- ^ Normal run: we want a project, and have one. This comes from -- either 'SYLDefault' or 'SYLOverride'. | PCGlobalProject -- ^ No project was found when using 'SYLDefault'. Instead, use -- the implicit global. | PCNoProject ![PackageIdentifierRevision] -- ^ Use a no project run. This comes from 'SYLNoProject'. -- | Parsed global command-line options monoid. data GlobalOptsMonoid = GlobalOptsMonoid { globalMonoidReExecVersion :: !(First String) -- ^ Expected re-exec in container version , globalMonoidDockerEntrypoint :: !(First DockerEntrypoint) -- ^ Data used when Stack is acting as a Docker entrypoint (internal use only) , globalMonoidLogLevel :: !(First LogLevel) -- ^ Log level , globalMonoidTimeInLog :: !FirstTrue -- ^ Whether to include timings in logs. , globalMonoidRSLInLog :: !FirstFalse -- ^ Whether to include raw snapshot layer (RSL) in logs. , globalMonoidConfigMonoid :: !ConfigMonoid -- ^ Config monoid, for passing into 'loadConfig' , globalMonoidResolver :: !(First (Unresolved AbstractResolver)) -- ^ Resolver override , globalMonoidResolverRoot :: !(First FilePath) -- ^ root directory for resolver relative path , globalMonoidCompiler :: !(First WantedCompiler) -- ^ Compiler override , globalMonoidTerminal :: !(First Bool) -- ^ We're in a terminal? , globalMonoidStyles :: !StylesUpdate -- ^ Stack's output styles , globalMonoidTermWidth :: !(First Int) -- ^ Terminal width override , globalMonoidStackYaml :: !(First FilePath) -- ^ Override project stack.yaml , globalMonoidLockFileBehavior :: !(First LockFileBehavior) -- ^ See 'globalLockFileBehavior' } deriving Generic instance Semigroup GlobalOptsMonoid where (<>) = mappenddefault instance Monoid GlobalOptsMonoid where mempty = memptydefault mappend = (<>) -- | Default logging level should be something useful but not crazy. defaultLogLevel :: LogLevel defaultLogLevel = LevelInfo readColorWhen :: ReadM ColorWhen readColorWhen = do s <- OA.readerAsk case s of "never" -> pure ColorNever "always" -> pure ColorAlways "auto" -> pure ColorAuto _ -> OA.readerError "Expected values of color option are 'never', 'always', or 'auto'." readStyles :: ReadM StylesUpdate readStyles = parseStylesUpdateFromString <$> OA.readerAsk -- | A superset of 'Config' adding information on how to build code. The reason -- for this breakdown is because we will need some of the information from -- 'Config' in order to determine the values here. -- -- These are the components which know nothing about local configuration. data BuildConfig = BuildConfig { bcConfig :: !Config , bcSMWanted :: !SMWanted , bcExtraPackageDBs :: ![Path Abs Dir] -- ^ Extra package databases , bcStackYaml :: !(Path Abs File) -- ^ Location of the stack.yaml file. -- -- Note: if the STACK_YAML environment variable is used, this may be -- different from projectRootL "stack.yaml" if a different file -- name is used. , bcProjectStorage :: !ProjectStorage -- ^ Database connection pool for project Stack database , bcCurator :: !(Maybe Curator) } stackYamlL :: HasBuildConfig env => Lens' env (Path Abs File) stackYamlL = buildConfigL.lens bcStackYaml (\x y -> x { bcStackYaml = y }) -- | Directory containing the project's stack.yaml file projectRootL :: HasBuildConfig env => Getting r env (Path Abs Dir) projectRootL = stackYamlL.to parent -- | Configuration after the environment has been setup. data EnvConfig = EnvConfig {envConfigBuildConfig :: !BuildConfig ,envConfigBuildOptsCLI :: !BuildOptsCLI ,envConfigSourceMap :: !SourceMap ,envConfigSourceMapHash :: !SourceMapHash ,envConfigCompilerPaths :: !CompilerPaths } ppGPD :: MonadIO m => ProjectPackage -> m GenericPackageDescription ppGPD = liftIO . cpGPD . ppCommon -- | Root directory for the given 'ProjectPackage' ppRoot :: ProjectPackage -> Path Abs Dir ppRoot = parent . ppCabalFP -- | All components available in the given 'ProjectPackage' ppComponents :: MonadIO m => ProjectPackage -> m (Set NamedComponent) ppComponents pp = do gpd <- ppGPD pp pure $ Set.fromList $ concat [ maybe [] (const [CLib]) (C.condLibrary gpd) , go CExe (fst <$> C.condExecutables gpd) , go CTest (fst <$> C.condTestSuites gpd) , go CBench (fst <$> C.condBenchmarks gpd) ] where go :: (T.Text -> NamedComponent) -> [C.UnqualComponentName] -> [NamedComponent] go wrapper = map (wrapper . T.pack . C.unUnqualComponentName) -- | Version for the given 'ProjectPackage ppVersion :: MonadIO m => ProjectPackage -> m Version ppVersion = fmap gpdVersion . ppGPD -- | A project is a collection of packages. We can have multiple stack.yaml -- files, but only one of them may contain project information. data Project = Project { projectUserMsg :: !(Maybe String) -- ^ A warning message to display to the user when the auto generated -- config may have issues. , projectPackages :: ![RelFilePath] -- ^ Packages which are actually part of the project (as opposed -- to dependencies). , projectDependencies :: ![RawPackageLocation] -- ^ Dependencies defined within the stack.yaml file, to be -- applied on top of the snapshot. , projectFlags :: !(Map PackageName (Map FlagName Bool)) -- ^ Flags to be applied on top of the snapshot flags. , projectResolver :: !RawSnapshotLocation -- ^ How we resolve which @Snapshot@ to use , projectCompiler :: !(Maybe WantedCompiler) -- ^ Override the compiler in 'projectResolver' , projectExtraPackageDBs :: ![FilePath] , projectCurator :: !(Maybe Curator) -- ^ Extra configuration intended exclusively for usage by the -- curator tool. In other words, this is /not/ part of the -- documented and exposed Stack API. SUBJECT TO CHANGE. , projectDropPackages :: !(Set PackageName) -- ^ Packages to drop from the 'projectResolver'. } deriving Show instance ToJSON Project where -- Expanding the constructor fully to ensure we don't miss any fields. toJSON (Project userMsg packages extraDeps flags resolver mcompiler extraPackageDBs mcurator drops) = object $ concat [ maybe [] (\cv -> ["compiler" .= cv]) mcompiler , maybe [] (\msg -> ["user-message" .= msg]) userMsg , if null extraPackageDBs then [] else ["extra-package-dbs" .= extraPackageDBs] , if null extraDeps then [] else ["extra-deps" .= extraDeps] , if Map.null flags then [] else ["flags" .= fmap toCabalStringMap (toCabalStringMap flags)] , ["packages" .= packages] , ["resolver" .= resolver] , maybe [] (\c -> ["curator" .= c]) mcurator , if Set.null drops then [] else ["drop-packages" .= Set.map CabalString drops] ] -- | Extra configuration intended exclusively for usage by the -- curator tool. In other words, this is /not/ part of the -- documented and exposed Stack API. SUBJECT TO CHANGE. data Curator = Curator { curatorSkipTest :: !(Set PackageName) , curatorExpectTestFailure :: !(Set PackageName) , curatorSkipBenchmark :: !(Set PackageName) , curatorExpectBenchmarkFailure :: !(Set PackageName) , curatorSkipHaddock :: !(Set PackageName) , curatorExpectHaddockFailure :: !(Set PackageName) } deriving Show instance ToJSON Curator where toJSON c = object [ "skip-test" .= Set.map CabalString (curatorSkipTest c) , "expect-test-failure" .= Set.map CabalString (curatorExpectTestFailure c) , "skip-bench" .= Set.map CabalString (curatorSkipBenchmark c) , "expect-benchmark-failure" .= Set.map CabalString (curatorExpectTestFailure c) , "skip-haddock" .= Set.map CabalString (curatorSkipHaddock c) , "expect-test-failure" .= Set.map CabalString (curatorExpectHaddockFailure c) ] instance FromJSON (WithJSONWarnings Curator) where parseJSON = withObjectWarnings "Curator" $ \o -> Curator <$> fmap (Set.map unCabalString) (o ..:? "skip-test" ..!= mempty) <*> fmap (Set.map unCabalString) (o ..:? "expect-test-failure" ..!= mempty) <*> fmap (Set.map unCabalString) (o ..:? "skip-bench" ..!= mempty) <*> fmap (Set.map unCabalString) (o ..:? "expect-benchmark-failure" ..!= mempty) <*> fmap (Set.map unCabalString) (o ..:? "skip-haddock" ..!= mempty) <*> fmap (Set.map unCabalString) (o ..:? "expect-haddock-failure" ..!= mempty) -- An uninterpreted representation of configuration options. -- Configurations may be "cascaded" using mappend (left-biased). data ConfigMonoid = ConfigMonoid { configMonoidStackRoot :: !(First (Path Abs Dir)) -- ^ See: 'clStackRoot' , configMonoidWorkDir :: !(First (Path Rel Dir)) -- ^ See: 'configWorkDir'. , configMonoidBuildOpts :: !BuildOptsMonoid -- ^ build options. , configMonoidDockerOpts :: !DockerOptsMonoid -- ^ Docker options. , configMonoidNixOpts :: !NixOptsMonoid -- ^ Options for the execution environment (nix-shell or container) , configMonoidConnectionCount :: !(First Int) -- ^ See: 'configConnectionCount' , configMonoidHideTHLoading :: !FirstTrue -- ^ See: 'configHideTHLoading' , configMonoidPrefixTimestamps :: !(First Bool) -- ^ See: 'configPrefixTimestamps' , configMonoidLatestSnapshot :: !(First Text) -- ^ See: 'configLatestSnapshot' , configMonoidPackageIndex :: !(First PackageIndexConfig) -- ^ See: 'withPantryConfig' , configMonoidPackageIndices :: !(First [PackageIndexConfig]) -- ^ Deprecated in favour of package-index , configMonoidSystemGHC :: !(First Bool) -- ^ See: 'configSystemGHC' ,configMonoidInstallGHC :: !FirstTrue -- ^ See: 'configInstallGHC' ,configMonoidSkipGHCCheck :: !FirstFalse -- ^ See: 'configSkipGHCCheck' ,configMonoidSkipMsys :: !FirstFalse -- ^ See: 'configSkipMsys' ,configMonoidCompilerCheck :: !(First VersionCheck) -- ^ See: 'configCompilerCheck' ,configMonoidCompilerRepository :: !(First CompilerRepository) -- ^ See: 'configCompilerRepository' ,configMonoidRequireStackVersion :: !IntersectingVersionRange -- ^ See: 'configRequireStackVersion' ,configMonoidArch :: !(First String) -- ^ Used for overriding the platform ,configMonoidGHCVariant :: !(First GHCVariant) -- ^ Used for overriding the platform ,configMonoidGHCBuild :: !(First CompilerBuild) -- ^ Used for overriding the GHC build ,configMonoidJobs :: !(First Int) -- ^ See: 'configJobs' ,configMonoidExtraIncludeDirs :: ![FilePath] -- ^ See: 'configExtraIncludeDirs' ,configMonoidExtraLibDirs :: ![FilePath] -- ^ See: 'configExtraLibDirs' ,configMonoidCustomPreprocessorExts :: ![Text] -- ^ See: 'configCustomPreprocessorExts' , configMonoidOverrideGccPath :: !(First (Path Abs File)) -- ^ Allow users to override the path to gcc ,configMonoidOverrideHpack :: !(First FilePath) -- ^ Use Hpack executable (overrides bundled Hpack) ,configMonoidConcurrentTests :: !(First Bool) -- ^ See: 'configConcurrentTests' ,configMonoidLocalBinPath :: !(First FilePath) -- ^ Used to override the binary installation dir ,configMonoidTemplateParameters :: !(Map Text Text) -- ^ Template parameters. ,configMonoidScmInit :: !(First SCM) -- ^ Initialize SCM (e.g. git init) when making new projects? ,configMonoidGhcOptionsByName :: !(MonoidMap PackageName (Monoid.Dual [Text])) -- ^ See 'configGhcOptionsByName'. Uses 'Monoid.Dual' so that -- options from the configs on the right come first, so that they -- can be overridden. ,configMonoidGhcOptionsByCat :: !(MonoidMap ApplyGhcOptions (Monoid.Dual [Text])) -- ^ See 'configGhcOptionsAll'. Uses 'Monoid.Dual' so that options -- from the configs on the right come first, so that they can be -- overridden. ,configMonoidCabalConfigOpts :: !(MonoidMap CabalConfigKey (Monoid.Dual [Text])) -- ^ See 'configCabalConfigOpts'. ,configMonoidExtraPath :: ![Path Abs Dir] -- ^ Additional paths to search for executables in ,configMonoidSetupInfoLocations :: ![String] -- ^ See 'configSetupInfoLocations' ,configMonoidSetupInfoInline :: !SetupInfo -- ^ See 'configSetupInfoInline' ,configMonoidLocalProgramsBase :: !(First (Path Abs Dir)) -- ^ Override the default local programs dir, where e.g. GHC is installed. ,configMonoidPvpBounds :: !(First PvpBounds) -- ^ See 'configPvpBounds' ,configMonoidModifyCodePage :: !FirstTrue -- ^ See 'configModifyCodePage' ,configMonoidRebuildGhcOptions :: !FirstFalse -- ^ See 'configMonoidRebuildGhcOptions' ,configMonoidApplyGhcOptions :: !(First ApplyGhcOptions) -- ^ See 'configApplyGhcOptions' ,configMonoidAllowNewer :: !(First Bool) -- ^ See 'configMonoidAllowNewer' ,configMonoidAllowNewerDeps :: !(Maybe AllowNewerDeps) -- ^ See 'configMonoidAllowNewerDeps' ,configMonoidDefaultTemplate :: !(First TemplateName) -- ^ The default template to use when none is specified. -- (If Nothing, the 'default' default template is used.) , configMonoidAllowDifferentUser :: !(First Bool) -- ^ Allow users other than the Stack root owner to use the Stack -- installation. , configMonoidDumpLogs :: !(First DumpLogs) -- ^ See 'configDumpLogs' , configMonoidSaveHackageCreds :: !(First Bool) -- ^ See 'configSaveHackageCreds' , configMonoidHackageBaseUrl :: !(First Text) -- ^ See 'configHackageBaseUrl' , configMonoidColorWhen :: !(First ColorWhen) -- ^ When to use 'ANSI' colors , configMonoidStyles :: !StylesUpdate , configMonoidHideSourcePaths :: !FirstTrue -- ^ See 'configHideSourcePaths' , configMonoidRecommendUpgrade :: !FirstTrue -- ^ See 'configRecommendUpgrade' , configMonoidCasaRepoPrefix :: !(First CasaRepoPrefix) , configMonoidSnapshotLocation :: !(First Text) -- ^ Custom location of LTS/Nightly snapshots , configMonoidNoRunCompile :: !FirstFalse -- ^ See: 'configNoRunCompile' , configMonoidStackDeveloperMode :: !(First Bool) -- ^ See 'configStackDeveloperMode' } deriving (Show, Generic) instance Semigroup ConfigMonoid where (<>) = mappenddefault instance Monoid ConfigMonoid where mempty = memptydefault mappend = (<>) parseConfigMonoid :: Path Abs Dir -> Value -> Yaml.Parser (WithJSONWarnings ConfigMonoid) parseConfigMonoid = withObjectWarnings "ConfigMonoid" . parseConfigMonoidObject -- | Parse a partial configuration. Used both to parse both a standalone config -- file and a project file, so that a sub-parser is not required, which would interfere with -- warnings for missing fields. parseConfigMonoidObject :: Path Abs Dir -> Object -> WarningParser ConfigMonoid parseConfigMonoidObject rootDir obj = do -- Parsing 'stackRoot' from 'stackRoot'/config.yaml would be nonsensical let configMonoidStackRoot = First Nothing configMonoidWorkDir <- First <$> obj ..:? configMonoidWorkDirName configMonoidBuildOpts <- jsonSubWarnings (obj ..:? configMonoidBuildOptsName ..!= mempty) configMonoidDockerOpts <- jsonSubWarnings (obj ..:? configMonoidDockerOptsName ..!= mempty) configMonoidNixOpts <- jsonSubWarnings (obj ..:? configMonoidNixOptsName ..!= mempty) configMonoidConnectionCount <- First <$> obj ..:? configMonoidConnectionCountName configMonoidHideTHLoading <- FirstTrue <$> obj ..:? configMonoidHideTHLoadingName configMonoidPrefixTimestamps <- First <$> obj ..:? configMonoidPrefixTimestampsName murls :: Maybe Value <- obj ..:? configMonoidUrlsName configMonoidLatestSnapshot <- case murls of Nothing -> pure $ First Nothing Just urls -> jsonSubWarnings $ lift $ withObjectWarnings "urls" (\o -> First <$> o ..:? "latest-snapshot" :: WarningParser (First Text)) urls configMonoidPackageIndex <- First <$> jsonSubWarningsT (obj ..:? configMonoidPackageIndexName) configMonoidPackageIndices <- First <$> jsonSubWarningsTT (obj ..:? configMonoidPackageIndicesName) configMonoidSystemGHC <- First <$> obj ..:? configMonoidSystemGHCName configMonoidInstallGHC <- FirstTrue <$> obj ..:? configMonoidInstallGHCName configMonoidSkipGHCCheck <- FirstFalse <$> obj ..:? configMonoidSkipGHCCheckName configMonoidSkipMsys <- FirstFalse <$> obj ..:? configMonoidSkipMsysName configMonoidRequireStackVersion <- IntersectingVersionRange . unVersionRangeJSON <$> ( obj ..:? configMonoidRequireStackVersionName ..!= VersionRangeJSON anyVersion) configMonoidArch <- First <$> obj ..:? configMonoidArchName configMonoidGHCVariant <- First <$> obj ..:? configMonoidGHCVariantName configMonoidGHCBuild <- First <$> obj ..:? configMonoidGHCBuildName configMonoidJobs <- First <$> obj ..:? configMonoidJobsName configMonoidExtraIncludeDirs <- map (toFilePath rootDir FilePath.) <$> obj ..:? configMonoidExtraIncludeDirsName ..!= [] configMonoidExtraLibDirs <- map (toFilePath rootDir FilePath.) <$> obj ..:? configMonoidExtraLibDirsName ..!= [] configMonoidCustomPreprocessorExts <- obj ..:? configMonoidCustomPreprocessorExtsName ..!= [] configMonoidOverrideGccPath <- First <$> obj ..:? configMonoidOverrideGccPathName configMonoidOverrideHpack <- First <$> obj ..:? configMonoidOverrideHpackName configMonoidConcurrentTests <- First <$> obj ..:? configMonoidConcurrentTestsName configMonoidLocalBinPath <- First <$> obj ..:? configMonoidLocalBinPathName templates <- obj ..:? "templates" (configMonoidScmInit,configMonoidTemplateParameters) <- case templates of Nothing -> pure (First Nothing,M.empty) Just tobj -> do scmInit <- tobj ..:? configMonoidScmInitName params <- tobj ..:? configMonoidTemplateParametersName pure (First scmInit,fromMaybe M.empty params) configMonoidCompilerCheck <- First <$> obj ..:? configMonoidCompilerCheckName configMonoidCompilerRepository <- First <$> (obj ..:? configMonoidCompilerRepositoryName) options <- Map.map unGhcOptions <$> obj ..:? configMonoidGhcOptionsName ..!= mempty optionsEverything <- case (Map.lookup GOKOldEverything options, Map.lookup GOKEverything options) of (Just _, Just _) -> fail "Cannot specify both `*` and `$everything` GHC options" (Nothing, Just x) -> pure x (Just x, Nothing) -> do tell "The `*` ghc-options key is not recommended. Consider using $locals, or if really needed, $everything" pure x (Nothing, Nothing) -> pure [] let configMonoidGhcOptionsByCat = coerce $ Map.fromList [ (AGOEverything, optionsEverything) , (AGOLocals, Map.findWithDefault [] GOKLocals options) , (AGOTargets, Map.findWithDefault [] GOKTargets options) ] configMonoidGhcOptionsByName = coerce $ Map.fromList [(name, opts) | (GOKPackage name, opts) <- Map.toList options] configMonoidCabalConfigOpts' <- obj ..:? "configure-options" ..!= mempty let configMonoidCabalConfigOpts = coerce (configMonoidCabalConfigOpts' :: Map CabalConfigKey [Text]) configMonoidExtraPath <- obj ..:? configMonoidExtraPathName ..!= [] configMonoidSetupInfoLocations <- obj ..:? configMonoidSetupInfoLocationsName ..!= [] configMonoidSetupInfoInline <- jsonSubWarningsT (obj ..:? configMonoidSetupInfoInlineName) ..!= mempty configMonoidLocalProgramsBase <- First <$> obj ..:? configMonoidLocalProgramsBaseName configMonoidPvpBounds <- First <$> obj ..:? configMonoidPvpBoundsName configMonoidModifyCodePage <- FirstTrue <$> obj ..:? configMonoidModifyCodePageName configMonoidRebuildGhcOptions <- FirstFalse <$> obj ..:? configMonoidRebuildGhcOptionsName configMonoidApplyGhcOptions <- First <$> obj ..:? configMonoidApplyGhcOptionsName configMonoidAllowNewer <- First <$> obj ..:? configMonoidAllowNewerName configMonoidAllowNewerDeps <- obj ..:? configMonoidAllowNewerDepsName configMonoidDefaultTemplate <- First <$> obj ..:? configMonoidDefaultTemplateName configMonoidAllowDifferentUser <- First <$> obj ..:? configMonoidAllowDifferentUserName configMonoidDumpLogs <- First <$> obj ..:? configMonoidDumpLogsName configMonoidSaveHackageCreds <- First <$> obj ..:? configMonoidSaveHackageCredsName configMonoidHackageBaseUrl <- First <$> obj ..:? configMonoidHackageBaseUrlName configMonoidColorWhenUS <- obj ..:? configMonoidColorWhenUSName configMonoidColorWhenGB <- obj ..:? configMonoidColorWhenGBName let configMonoidColorWhen = First $ configMonoidColorWhenUS <|> configMonoidColorWhenGB configMonoidStylesUS <- obj ..:? configMonoidStylesUSName configMonoidStylesGB <- obj ..:? configMonoidStylesGBName let configMonoidStyles = fromMaybe mempty $ configMonoidStylesUS <|> configMonoidStylesGB configMonoidHideSourcePaths <- FirstTrue <$> obj ..:? configMonoidHideSourcePathsName configMonoidRecommendUpgrade <- FirstTrue <$> obj ..:? configMonoidRecommendUpgradeName configMonoidCasaRepoPrefix <- First <$> obj ..:? configMonoidCasaRepoPrefixName configMonoidSnapshotLocation <- First <$> obj ..:? configMonoidSnapshotLocationName configMonoidNoRunCompile <- FirstFalse <$> obj ..:? configMonoidNoRunCompileName configMonoidStackDeveloperMode <- First <$> obj ..:? configMonoidStackDeveloperModeName pure ConfigMonoid {..} configMonoidWorkDirName :: Text configMonoidWorkDirName = "work-dir" configMonoidBuildOptsName :: Text configMonoidBuildOptsName = "build" configMonoidDockerOptsName :: Text configMonoidDockerOptsName = "docker" configMonoidNixOptsName :: Text configMonoidNixOptsName = "nix" configMonoidConnectionCountName :: Text configMonoidConnectionCountName = "connection-count" configMonoidHideTHLoadingName :: Text configMonoidHideTHLoadingName = "hide-th-loading" configMonoidPrefixTimestampsName :: Text configMonoidPrefixTimestampsName = "build-output-timestamps" configMonoidUrlsName :: Text configMonoidUrlsName = "urls" configMonoidPackageIndexName :: Text configMonoidPackageIndexName = "package-index" -- Deprecated in favour of package-index configMonoidPackageIndicesName :: Text configMonoidPackageIndicesName = "package-indices" configMonoidSystemGHCName :: Text configMonoidSystemGHCName = "system-ghc" configMonoidInstallGHCName :: Text configMonoidInstallGHCName = "install-ghc" configMonoidSkipGHCCheckName :: Text configMonoidSkipGHCCheckName = "skip-ghc-check" configMonoidSkipMsysName :: Text configMonoidSkipMsysName = "skip-msys" configMonoidRequireStackVersionName :: Text configMonoidRequireStackVersionName = "require-stack-version" configMonoidArchName :: Text configMonoidArchName = "arch" configMonoidGHCVariantName :: Text configMonoidGHCVariantName = "ghc-variant" configMonoidGHCBuildName :: Text configMonoidGHCBuildName = "ghc-build" configMonoidJobsName :: Text configMonoidJobsName = "jobs" configMonoidExtraIncludeDirsName :: Text configMonoidExtraIncludeDirsName = "extra-include-dirs" configMonoidExtraLibDirsName :: Text configMonoidExtraLibDirsName = "extra-lib-dirs" configMonoidCustomPreprocessorExtsName :: Text configMonoidCustomPreprocessorExtsName = "custom-preprocessor-extensions" configMonoidOverrideGccPathName :: Text configMonoidOverrideGccPathName = "with-gcc" configMonoidOverrideHpackName :: Text configMonoidOverrideHpackName = "with-hpack" configMonoidConcurrentTestsName :: Text configMonoidConcurrentTestsName = "concurrent-tests" configMonoidLocalBinPathName :: Text configMonoidLocalBinPathName = "local-bin-path" configMonoidScmInitName :: Text configMonoidScmInitName = "scm-init" configMonoidTemplateParametersName :: Text configMonoidTemplateParametersName = "params" configMonoidCompilerCheckName :: Text configMonoidCompilerCheckName = "compiler-check" configMonoidCompilerRepositoryName :: Text configMonoidCompilerRepositoryName = "compiler-repository" configMonoidGhcOptionsName :: Text configMonoidGhcOptionsName = "ghc-options" configMonoidExtraPathName :: Text configMonoidExtraPathName = "extra-path" configMonoidSetupInfoLocationsName :: Text configMonoidSetupInfoLocationsName = "setup-info-locations" configMonoidSetupInfoInlineName :: Text configMonoidSetupInfoInlineName = "setup-info" configMonoidLocalProgramsBaseName :: Text configMonoidLocalProgramsBaseName = "local-programs-path" configMonoidPvpBoundsName :: Text configMonoidPvpBoundsName = "pvp-bounds" configMonoidModifyCodePageName :: Text configMonoidModifyCodePageName = "modify-code-page" configMonoidRebuildGhcOptionsName :: Text configMonoidRebuildGhcOptionsName = "rebuild-ghc-options" configMonoidApplyGhcOptionsName :: Text configMonoidApplyGhcOptionsName = "apply-ghc-options" configMonoidAllowNewerName :: Text configMonoidAllowNewerName = "allow-newer" configMonoidAllowNewerDepsName :: Text configMonoidAllowNewerDepsName = "allow-newer-deps" configMonoidDefaultTemplateName :: Text configMonoidDefaultTemplateName = "default-template" configMonoidAllowDifferentUserName :: Text configMonoidAllowDifferentUserName = "allow-different-user" configMonoidDumpLogsName :: Text configMonoidDumpLogsName = "dump-logs" configMonoidSaveHackageCredsName :: Text configMonoidSaveHackageCredsName = "save-hackage-creds" configMonoidHackageBaseUrlName :: Text configMonoidHackageBaseUrlName = "hackage-base-url" configMonoidColorWhenUSName :: Text configMonoidColorWhenUSName = "color" configMonoidColorWhenGBName :: Text configMonoidColorWhenGBName = "colour" configMonoidStylesUSName :: Text configMonoidStylesUSName = "stack-colors" configMonoidStylesGBName :: Text configMonoidStylesGBName = "stack-colours" configMonoidHideSourcePathsName :: Text configMonoidHideSourcePathsName = "hide-source-paths" configMonoidRecommendUpgradeName :: Text configMonoidRecommendUpgradeName = "recommend-stack-upgrade" configMonoidCasaRepoPrefixName :: Text configMonoidCasaRepoPrefixName = "casa-repo-prefix" configMonoidSnapshotLocationName :: Text configMonoidSnapshotLocationName = "snapshot-location-base" configMonoidNoRunCompileName :: Text configMonoidNoRunCompileName = "script-no-run-compile" configMonoidStackDeveloperModeName :: Text configMonoidStackDeveloperModeName = "stack-developer-mode" packageIndicesWarning :: String packageIndicesWarning = "The 'package-indices' key is deprecated in favour of 'package-index'." resolveOptions :: StyleDoc resolveOptions = flow "This may be resolved by:" <> line <> bulletedList [ fillSep [ "Using" , style Shell "--omit-packages" , "to exclude mismatching package(s)." ] , fillSep [ "Using" , style Shell "--resolver" , "to specify a matching snapshot/resolver." ] ] -- | Get the URL to request the information on the latest snapshots askLatestSnapshotUrl :: (MonadReader env m, HasConfig env) => m Text askLatestSnapshotUrl = view $ configL.to configLatestSnapshot -- | @".stack-work"@ workDirL :: HasConfig env => Lens' env (Path Rel Dir) workDirL = configL.lens configWorkDir (\x y -> x { configWorkDir = y }) -- | @STACK_ROOT\/hooks\/@ hooksDir :: HasConfig env => RIO env (Path Abs Dir) hooksDir = do sr <- view $ configL.to configStackRoot pure (sr [reldir|hooks|]) -- | @STACK_ROOT\/hooks\/ghc-install.sh@ ghcInstallHook :: HasConfig env => RIO env (Path Abs File) ghcInstallHook = do hd <- hooksDir pure (hd [relfile|ghc-install.sh|]) -- | Per-project work dir getProjectWorkDir :: (HasBuildConfig env, MonadReader env m) => m (Path Abs Dir) getProjectWorkDir = do root <- view projectRootL workDir <- view workDirL pure (root workDir) -- | Relative directory for the platform identifier platformOnlyRelDir :: (MonadReader env m, HasPlatform env, MonadThrow m) => m (Path Rel Dir) platformOnlyRelDir = do platform <- view platformL platformVariant <- view platformVariantL parseRelDir (Distribution.Text.display platform ++ platformVariantSuffix platformVariant) -- | Directory containing snapshots snapshotsDir :: (MonadReader env m, HasEnvConfig env, MonadThrow m) => m (Path Abs Dir) snapshotsDir = do root <- view stackRootL platform <- platformGhcRelDir pure $ root relDirSnapshots platform -- | Installation root for dependencies installationRootDeps :: (HasEnvConfig env) => RIO env (Path Abs Dir) installationRootDeps = do root <- view stackRootL -- TODO: also useShaPathOnWindows here, once #1173 is resolved. psc <- platformSnapAndCompilerRel pure $ root relDirSnapshots psc -- | Installation root for locals installationRootLocal :: (HasEnvConfig env) => RIO env (Path Abs Dir) installationRootLocal = do workDir <- getProjectWorkDir psc <- useShaPathOnWindows =<< platformSnapAndCompilerRel pure $ workDir relDirInstall 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 <- view actualCompilerVersionL compiler <- parseRelDir $ compilerVersionString compilerVersion pure $ view stackRootL config relDirCompilerTools platform compiler bindirSuffix -- | Hoogle directory. hoogleRoot :: (HasEnvConfig env) => RIO env (Path Abs Dir) hoogleRoot = do workDir <- getProjectWorkDir psc <- useShaPathOnWindows =<< platformSnapAndCompilerRel pure $ workDir relDirHoogle psc -- | Get the hoogle database path. hoogleDatabasePath :: (HasEnvConfig env) => RIO env (Path Abs File) hoogleDatabasePath = do dir <- hoogleRoot pure (dir relFileDatabaseHoo) -- | Path for platform followed by snapshot name followed by compiler -- name. platformSnapAndCompilerRel :: (HasEnvConfig env) => RIO env (Path Rel Dir) platformSnapAndCompilerRel = do platform <- platformGhcRelDir smh <- view $ envConfigL.to envConfigSourceMapHash name <- smRelDir smh ghc <- compilerVersionDir useShaPathOnWindows (platform name ghc) -- | Relative directory for the platform and GHC identifier platformGhcRelDir :: (MonadReader env m, HasEnvConfig env, MonadThrow m) => m (Path Rel Dir) platformGhcRelDir = do cp <- view compilerPathsL let cbSuffix = compilerBuildSuffix $ cpBuild cp verOnly <- platformGhcVerOnlyRelDirStr parseRelDir (mconcat [ verOnly, cbSuffix ]) -- | Relative directory for the platform and GHC identifier without GHC bindist build platformGhcVerOnlyRelDir :: (MonadReader env m, HasPlatform env, HasGHCVariant env, MonadThrow m) => m (Path Rel Dir) platformGhcVerOnlyRelDir = parseRelDir =<< platformGhcVerOnlyRelDirStr -- | Relative directory for the platform and GHC identifier without GHC bindist build -- (before parsing into a Path) platformGhcVerOnlyRelDirStr :: (MonadReader env m, HasPlatform env, HasGHCVariant env) => m FilePath platformGhcVerOnlyRelDirStr = do platform <- view platformL platformVariant <- view platformVariantL ghcVariant <- view ghcVariantL pure $ mconcat [ Distribution.Text.display platform , platformVariantSuffix platformVariant , ghcVariantSuffix ghcVariant ] -- | This is an attempt to shorten Stack paths on Windows to decrease our -- chances of hitting 260 symbol path limit. The idea is to calculate -- SHA1 hash of the path used on other architectures, encode with base -- 16 and take first 8 symbols of it. useShaPathOnWindows :: MonadThrow m => Path Rel Dir -> m (Path Rel Dir) useShaPathOnWindows | osIsWindows = shaPath | otherwise = pure shaPath :: (IsPath Rel t, MonadThrow m) => Path Rel t -> m (Path Rel t) shaPath = shaPathForBytes . encodeUtf8 . T.pack . toFilePath shaPathForBytes :: (IsPath Rel t, MonadThrow m) => ByteString -> m (Path Rel t) shaPathForBytes = parsePath . S8.unpack . S8.take 8 . Mem.convertToBase Mem.Base16 . hashWith SHA1 -- TODO: Move something like this into the path package. Consider -- subsuming path-io's 'AnyPath'? class IsPath b t where parsePath :: MonadThrow m => FilePath -> m (Path b t) instance IsPath Abs Dir where parsePath = parseAbsDir instance IsPath Rel Dir where parsePath = parseRelDir instance IsPath Abs File where parsePath = parseAbsFile instance IsPath Rel File where parsePath = parseRelFile compilerVersionDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env) => m (Path Rel Dir) compilerVersionDir = do compilerVersion <- view actualCompilerVersionL parseRelDir $ case compilerVersion of ACGhc version -> versionString version ACGhcGit {} -> compilerVersionString compilerVersion -- | Package database for installing dependencies into packageDatabaseDeps :: (HasEnvConfig env) => RIO env (Path Abs Dir) packageDatabaseDeps = do root <- installationRootDeps pure $ root relDirPkgdb -- | Package database for installing local packages into packageDatabaseLocal :: (HasEnvConfig env) => RIO env (Path Abs Dir) packageDatabaseLocal = do root <- installationRootLocal pure $ root relDirPkgdb -- | Extra package databases packageDatabaseExtra :: (MonadReader env m, HasEnvConfig env) => m [Path Abs Dir] packageDatabaseExtra = view $ buildConfigL.to bcExtraPackageDBs -- | Where do we get information on global packages for loading up a -- 'LoadedSnapshot'? data GlobalInfoSource = GISSnapshotHints -- ^ Accept the hints in the snapshot definition | GISCompiler ActualCompiler -- ^ Look up the actual information in the installed compiler -- | Where HPC reports and tix files get stored. hpcReportDir :: (HasEnvConfig env) => RIO env (Path Abs Dir) hpcReportDir = do root <- installationRootLocal pure $ root relDirHpc -- | Get the extra bin directories (for the PATH). Puts more local first -- -- Bool indicates whether or not to include the locals extraBinDirs :: (HasEnvConfig env) => RIO env (Bool -> [Path Abs Dir]) extraBinDirs = do deps <- installationRootDeps local' <- installationRootLocal tools <- bindirCompilerTools pure $ \locals -> if locals then [local' bindirSuffix, deps bindirSuffix, tools] else [deps bindirSuffix, tools] minimalEnvSettings :: EnvSettings minimalEnvSettings = EnvSettings { esIncludeLocals = False , esIncludeGhcPackagePath = False , esStackExe = False , esLocaleUtf8 = False , esKeepGhcRts = False } -- | Default @EnvSettings@ which includes locals and GHC_PACKAGE_PATH. -- -- Note that this also passes through the GHCRTS environment variable. -- See https://github.com/commercialhaskell/stack/issues/3444 defaultEnvSettings :: EnvSettings defaultEnvSettings = EnvSettings { esIncludeLocals = True , esIncludeGhcPackagePath = True , esStackExe = True , esLocaleUtf8 = False , esKeepGhcRts = True } -- | Environment settings which do not embellish the environment -- -- Note that this also passes through the GHCRTS environment variable. -- See https://github.com/commercialhaskell/stack/issues/3444 plainEnvSettings :: EnvSettings plainEnvSettings = EnvSettings { esIncludeLocals = False , esIncludeGhcPackagePath = False , esStackExe = False , esLocaleUtf8 = False , esKeepGhcRts = True } -- | Get the path for the given compiler ignoring any local binaries. -- -- https://github.com/commercialhaskell/stack/issues/1052 getCompilerPath :: HasCompiler env => RIO env (Path Abs File) getCompilerPath = view $ compilerPathsL.to cpCompiler data ProjectAndConfigMonoid = ProjectAndConfigMonoid !Project !ConfigMonoid parseProjectAndConfigMonoid :: Path Abs Dir -> Value -> Yaml.Parser (WithJSONWarnings (IO ProjectAndConfigMonoid)) parseProjectAndConfigMonoid rootDir = withObjectWarnings "ProjectAndConfigMonoid" $ \o -> do packages <- o ..:? "packages" ..!= [RelFilePath "."] deps <- jsonSubWarningsTT (o ..:? "extra-deps") ..!= [] flags' <- o ..:? "flags" ..!= mempty let flags = unCabalStringMap <$> unCabalStringMap (flags' :: Map (CabalString PackageName) (Map (CabalString FlagName) Bool)) resolver <- jsonSubWarnings $ o ...: ["snapshot", "resolver"] mcompiler <- o ..:? "compiler" msg <- o ..:? "user-message" config <- parseConfigMonoidObject rootDir o extraPackageDBs <- o ..:? "extra-package-dbs" ..!= [] mcurator <- jsonSubWarningsT (o ..:? "curator") drops <- o ..:? "drop-packages" ..!= mempty pure $ do deps' <- mapM (resolvePaths (Just rootDir)) deps resolver' <- resolvePaths (Just rootDir) resolver let project = Project { projectUserMsg = msg , projectResolver = resolver' , projectCompiler = mcompiler -- FIXME make sure resolver' isn't SLCompiler , projectExtraPackageDBs = extraPackageDBs , projectPackages = packages , projectDependencies = concatMap toList (deps' :: [NonEmpty RawPackageLocation]) , projectFlags = flags , projectCurator = mcurator , projectDropPackages = Set.map unCabalString drops } pure $ ProjectAndConfigMonoid project config -- | A software control system. data SCM = Git deriving (Show) instance FromJSON SCM where parseJSON v = do s <- parseJSON v case s of "git" -> pure Git _ -> fail ("Unknown or unsupported SCM: " <> s) instance ToJSON SCM where toJSON Git = toJSON ("git" :: Text) -- | A variant of the platform, used to differentiate Docker builds from host data PlatformVariant = PlatformVariantNone | PlatformVariant String -- | Render a platform variant to a String suffix. platformVariantSuffix :: PlatformVariant -> String platformVariantSuffix PlatformVariantNone = "" platformVariantSuffix (PlatformVariant v) = "-" ++ v -- | Specialized variant of GHC (e.g. libgmp4 or integer-simple) data GHCVariant = GHCStandard -- ^ Standard bindist | GHCIntegerSimple -- ^ Bindist that uses integer-simple | GHCNativeBignum -- ^ Bindist that uses the Haskell-native big-integer backend | GHCCustom String -- ^ Other bindists deriving (Show) instance FromJSON GHCVariant where -- Strange structuring is to give consistent error messages parseJSON = withText "GHCVariant" (either (fail . show) pure . parseGHCVariant . T.unpack) -- | Render a GHC variant to a String. ghcVariantName :: GHCVariant -> String ghcVariantName GHCStandard = "standard" ghcVariantName GHCIntegerSimple = "integersimple" ghcVariantName GHCNativeBignum = "int-native" ghcVariantName (GHCCustom name) = "custom-" ++ name -- | Render a GHC variant to a String suffix. ghcVariantSuffix :: GHCVariant -> String ghcVariantSuffix GHCStandard = "" ghcVariantSuffix v = "-" ++ ghcVariantName v -- | Parse GHC variant from a String. parseGHCVariant :: (MonadThrow m) => String -> m GHCVariant parseGHCVariant s = case stripPrefix "custom-" s of Just name -> pure (GHCCustom name) Nothing | s == "" -> pure GHCStandard | s == "standard" -> pure GHCStandard | s == "integersimple" -> pure GHCIntegerSimple | s == "int-native" -> pure GHCNativeBignum | otherwise -> pure (GHCCustom s) -- | Build of the compiler distribution (e.g. standard, gmp4, tinfo6) -- | Information for a file to download. data DownloadInfo = DownloadInfo { downloadInfoUrl :: Text -- ^ URL or absolute file path , downloadInfoContentLength :: Maybe Int , downloadInfoSha1 :: Maybe ByteString , downloadInfoSha256 :: Maybe ByteString } deriving (Show) instance FromJSON (WithJSONWarnings DownloadInfo) where parseJSON = withObjectWarnings "DownloadInfo" parseDownloadInfoFromObject -- | Parse JSON in existing object for 'DownloadInfo' parseDownloadInfoFromObject :: Object -> WarningParser DownloadInfo parseDownloadInfoFromObject o = do url <- o ..: "url" contentLength <- o ..:? "content-length" sha1TextMay <- o ..:? "sha1" sha256TextMay <- o ..:? "sha256" pure DownloadInfo { downloadInfoUrl = url , downloadInfoContentLength = contentLength , downloadInfoSha1 = fmap encodeUtf8 sha1TextMay , downloadInfoSha256 = fmap encodeUtf8 sha256TextMay } data VersionedDownloadInfo = VersionedDownloadInfo { vdiVersion :: Version , vdiDownloadInfo :: DownloadInfo } deriving Show instance FromJSON (WithJSONWarnings VersionedDownloadInfo) where parseJSON = withObjectWarnings "VersionedDownloadInfo" $ \o -> do CabalString version <- o ..: "version" downloadInfo <- parseDownloadInfoFromObject o pure VersionedDownloadInfo { vdiVersion = version , vdiDownloadInfo = downloadInfo } data GHCDownloadInfo = GHCDownloadInfo { gdiConfigureOpts :: [Text] , gdiConfigureEnv :: Map Text Text , gdiDownloadInfo :: DownloadInfo } deriving Show instance FromJSON (WithJSONWarnings GHCDownloadInfo) where parseJSON = withObjectWarnings "GHCDownloadInfo" $ \o -> do configureOpts <- o ..:? "configure-opts" ..!= mempty configureEnv <- o ..:? "configure-env" ..!= mempty downloadInfo <- parseDownloadInfoFromObject o pure GHCDownloadInfo { gdiConfigureOpts = configureOpts , gdiConfigureEnv = configureEnv , gdiDownloadInfo = downloadInfo } data SetupInfo = SetupInfo { siSevenzExe :: Maybe DownloadInfo , siSevenzDll :: Maybe DownloadInfo , siMsys2 :: Map Text VersionedDownloadInfo , siGHCs :: Map Text (Map Version GHCDownloadInfo) , siStack :: Map Text (Map Version DownloadInfo) } deriving Show instance FromJSON (WithJSONWarnings SetupInfo) where parseJSON = withObjectWarnings "SetupInfo" $ \o -> do siSevenzExe <- jsonSubWarningsT (o ..:? "sevenzexe-info") siSevenzDll <- jsonSubWarningsT (o ..:? "sevenzdll-info") siMsys2 <- jsonSubWarningsT (o ..:? "msys2" ..!= mempty) (fmap unCabalStringMap -> siGHCs) <- jsonSubWarningsTT (o ..:? "ghc" ..!= mempty) (fmap unCabalStringMap -> siStack) <- jsonSubWarningsTT (o ..:? "stack" ..!= mempty) pure SetupInfo {..} -- | For the @siGHCs@ field maps are deeply merged. -- For all fields the values from the first @SetupInfo@ win. instance Semigroup SetupInfo where l <> r = SetupInfo { siSevenzExe = siSevenzExe l <|> siSevenzExe r , siSevenzDll = siSevenzDll l <|> siSevenzDll r , siMsys2 = siMsys2 l <> siMsys2 r , siGHCs = Map.unionWith (<>) (siGHCs l) (siGHCs r) , siStack = Map.unionWith (<>) (siStack l) (siStack r) } instance Monoid SetupInfo where mempty = SetupInfo { siSevenzExe = Nothing , siSevenzDll = Nothing , siMsys2 = Map.empty , siGHCs = Map.empty , siStack = Map.empty } mappend = (<>) -- | How PVP bounds should be added to .cabal files data PvpBoundsType = PvpBoundsNone | PvpBoundsUpper | PvpBoundsLower | PvpBoundsBoth deriving (Show, Read, Eq, Typeable, Ord, Enum, Bounded) data PvpBounds = PvpBounds { pbType :: !PvpBoundsType , pbAsRevision :: !Bool } deriving (Show, Read, Eq, Typeable, Ord) pvpBoundsText :: PvpBoundsType -> Text pvpBoundsText PvpBoundsNone = "none" pvpBoundsText PvpBoundsUpper = "upper" pvpBoundsText PvpBoundsLower = "lower" pvpBoundsText PvpBoundsBoth = "both" parsePvpBounds :: Text -> Either String PvpBounds parsePvpBounds t = maybe err Right $ do (t', asRevision) <- case T.break (== '-') t of (x, "") -> Just (x, False) (x, "-revision") -> Just (x, True) _ -> Nothing x <- Map.lookup t' m Just PvpBounds { pbType = x , pbAsRevision = asRevision } where m = Map.fromList $ map (pvpBoundsText &&& id) [minBound..maxBound] err = Left $ "Invalid PVP bounds: " ++ T.unpack t instance ToJSON PvpBounds where toJSON (PvpBounds typ asRevision) = toJSON (pvpBoundsText typ <> (if asRevision then "-revision" else "")) instance FromJSON PvpBounds where parseJSON = withText "PvpBounds" (either fail pure . parsePvpBounds) -- | Data passed into Docker container for the Docker entrypoint's use newtype DockerEntrypoint = DockerEntrypoint { deUser :: Maybe DockerUser -- ^ UID/GID/etc of host user, if we wish to perform UID/GID switch in container } deriving (Read,Show) -- | Docker host user info data DockerUser = DockerUser { duUid :: UserID -- ^ uid , duGid :: GroupID -- ^ gid , duGroups :: [GroupID] -- ^ Supplemental groups , duUmask :: FileMode -- ^ File creation mask } } deriving (Read,Show) data GhcOptionKey = GOKOldEverything | GOKEverything | GOKLocals | GOKTargets | GOKPackage !PackageName deriving (Eq, Ord) instance FromJSONKey GhcOptionKey where fromJSONKey = FromJSONKeyTextParser $ \t -> case t of "*" -> pure GOKOldEverything "$everything" -> pure GOKEverything "$locals" -> pure GOKLocals "$targets" -> pure GOKTargets _ -> case parsePackageName $ T.unpack t of Nothing -> fail $ "Invalid package name: " ++ show t Just x -> pure $ GOKPackage x fromJSONKeyList = FromJSONKeyTextParser $ \_ -> fail "GhcOptionKey.fromJSONKeyList" newtype GhcOptions = GhcOptions { unGhcOptions :: [Text] } instance FromJSON GhcOptions where parseJSON = withText "GhcOptions" $ \t -> case parseArgs Escaping t of Left e -> fail e Right opts -> pure $ GhcOptions $ map T.pack opts ----------------------------------- -- Lens classes ----------------------------------- -- | Class for environment values which have a Platform class HasPlatform env where platformL :: Lens' env Platform default platformL :: HasConfig env => Lens' env Platform platformL = configL.platformL {-# INLINE platformL #-} platformVariantL :: Lens' env PlatformVariant default platformVariantL :: HasConfig env => Lens' env PlatformVariant platformVariantL = configL.platformVariantL {-# INLINE platformVariantL #-} -- | Class for environment values which have a GHCVariant class HasGHCVariant env where ghcVariantL :: SimpleGetter env GHCVariant default ghcVariantL :: HasConfig env => SimpleGetter env GHCVariant ghcVariantL = configL.ghcVariantL {-# INLINE ghcVariantL #-} -- | Class for environment values which have a 'Runner'. class (HasProcessContext env, HasLogFunc env) => HasRunner env where runnerL :: Lens' env Runner instance HasLogFunc Runner where logFuncL = lens runnerLogFunc (\x y -> x { runnerLogFunc = y }) instance HasProcessContext Runner where processContextL = lens runnerProcessContext (\x y -> x { runnerProcessContext = y }) instance HasRunner Runner where runnerL = id instance HasStylesUpdate Runner where stylesUpdateL = globalOptsL. lens globalStylesUpdate (\x y -> x { globalStylesUpdate = y }) instance HasTerm Runner where useColorL = lens runnerUseColor (\x y -> x { runnerUseColor = y }) termWidthL = lens runnerTermWidth (\x y -> x { runnerTermWidth = y }) globalOptsL :: HasRunner env => Lens' env GlobalOpts globalOptsL = runnerL.lens runnerGlobalOpts (\x y -> x { runnerGlobalOpts = y }) -- | Class for environment values that can provide a 'Config'. class ( HasPlatform env, HasGHCVariant env, HasProcessContext env, HasPantryConfig env, HasTerm env, HasRunner env) => HasConfig env where configL :: Lens' env Config default configL :: HasBuildConfig env => Lens' env Config configL = buildConfigL.lens bcConfig (\x y -> x { bcConfig = y }) {-# INLINE configL #-} class HasConfig env => HasBuildConfig env where buildConfigL :: Lens' env BuildConfig default buildConfigL :: HasEnvConfig env => Lens' env BuildConfig buildConfigL = envConfigL.lens envConfigBuildConfig (\x y -> x { envConfigBuildConfig = y }) class (HasBuildConfig env, HasSourceMap env, HasCompiler env) => HasEnvConfig env where envConfigL :: Lens' env EnvConfig ----------------------------------- -- Lens instances ----------------------------------- instance HasPlatform (Platform,PlatformVariant) where platformL = _1 platformVariantL = _2 instance HasPlatform Config where platformL = lens configPlatform (\x y -> x { configPlatform = y }) platformVariantL = lens configPlatformVariant (\x y -> x { configPlatformVariant = y }) instance HasPlatform BuildConfig instance HasPlatform EnvConfig instance HasGHCVariant GHCVariant where ghcVariantL = id {-# INLINE ghcVariantL #-} instance HasGHCVariant Config where ghcVariantL = to $ fromMaybe GHCStandard . configGHCVariant instance HasGHCVariant BuildConfig instance HasGHCVariant EnvConfig instance HasProcessContext Config where processContextL = runnerL.processContextL instance HasProcessContext BuildConfig where processContextL = configL.processContextL instance HasProcessContext EnvConfig where processContextL = configL.processContextL instance HasPantryConfig Config where pantryConfigL = lens configPantryConfig (\x y -> x { configPantryConfig = y }) instance HasPantryConfig BuildConfig where pantryConfigL = configL.pantryConfigL instance HasPantryConfig EnvConfig where pantryConfigL = configL.pantryConfigL instance HasConfig Config where configL = id {-# INLINE configL #-} instance HasConfig BuildConfig where configL = lens bcConfig (\x y -> x { bcConfig = y }) instance HasConfig EnvConfig instance HasBuildConfig BuildConfig where buildConfigL = id {-# INLINE buildConfigL #-} instance HasBuildConfig EnvConfig instance HasCompiler EnvConfig where compilerPathsL = to envConfigCompilerPaths instance HasEnvConfig EnvConfig where envConfigL = id {-# INLINE envConfigL #-} instance HasRunner Config where runnerL = lens configRunner (\x y -> x { configRunner = y }) instance HasRunner BuildConfig where runnerL = configL.runnerL instance HasRunner EnvConfig where runnerL = configL.runnerL instance HasLogFunc Config where logFuncL = runnerL.logFuncL instance HasLogFunc BuildConfig where logFuncL = runnerL.logFuncL instance HasLogFunc EnvConfig where logFuncL = runnerL.logFuncL instance HasStylesUpdate Config where stylesUpdateL = runnerL.stylesUpdateL instance HasStylesUpdate BuildConfig where stylesUpdateL = runnerL.stylesUpdateL instance HasStylesUpdate EnvConfig where stylesUpdateL = runnerL.stylesUpdateL instance HasTerm Config where useColorL = runnerL.useColorL termWidthL = runnerL.termWidthL instance HasTerm BuildConfig where useColorL = runnerL.useColorL termWidthL = runnerL.termWidthL instance HasTerm EnvConfig where useColorL = runnerL.useColorL termWidthL = runnerL.termWidthL ----------------------------------- -- Helper lenses ----------------------------------- stackRootL :: HasConfig s => Lens' s (Path Abs Dir) stackRootL = configL.lens configStackRoot (\x y -> x { configStackRoot = y }) stackGlobalConfigL :: HasConfig s => Lens' s (Path Abs File) stackGlobalConfigL = configL.lens configUserConfigPath (\x y -> x { configUserConfigPath = y }) -- | The compiler specified by the @SnapshotDef@. This may be -- different from the actual compiler used! wantedCompilerVersionL :: HasBuildConfig s => Getting r s WantedCompiler wantedCompilerVersionL = buildConfigL.to (smwCompiler . bcSMWanted) -- | Location of the ghc-pkg executable newtype GhcPkgExe = GhcPkgExe (Path Abs File) deriving Show -- | Get the 'GhcPkgExe' from a 'HasCompiler' environment getGhcPkgExe :: HasCompiler env => RIO env GhcPkgExe getGhcPkgExe = view $ compilerPathsL.to cpPkg -- | Dump information for a single package data DumpPackage = DumpPackage { dpGhcPkgId :: !GhcPkgId , dpPackageIdent :: !PackageIdentifier , dpParentLibIdent :: !(Maybe PackageIdentifier) , dpLicense :: !(Maybe C.License) , dpLibDirs :: ![FilePath] , dpLibraries :: ![Text] , dpHasExposedModules :: !Bool , dpExposedModules :: !(Set ModuleName) , dpDepends :: ![GhcPkgId] , dpHaddockInterfaces :: ![FilePath] , dpHaddockHtml :: !(Maybe FilePath) , dpIsExposed :: !Bool } deriving (Show, Read, Eq) -- | Paths on the filesystem for the compiler we're using data CompilerPaths = CompilerPaths { cpCompilerVersion :: !ActualCompiler , cpArch :: !Arch , cpBuild :: !CompilerBuild , cpCompiler :: !(Path Abs File) -- | ghc-pkg or equivalent , cpPkg :: !GhcPkgExe -- | runghc , cpInterpreter :: !(Path Abs File) -- | haddock, in 'IO' to allow deferring the lookup , cpHaddock :: !(Path Abs File) -- | Is this a Stack-sandboxed installation? , cpSandboxed :: !Bool , cpCabalVersion :: !Version -- ^ This is the version of Cabal that Stack will use to compile Setup.hs files -- in the build process. -- -- Note that this is not necessarily the same version as the one that Stack -- depends on as a library and which is displayed when running -- @stack ls dependencies | grep Cabal@ in the Stack project. , cpGlobalDB :: !(Path Abs Dir) -- ^ Global package database , cpGhcInfo :: !ByteString -- ^ Output of @ghc --info@ , cpGlobalDump :: !(Map PackageName DumpPackage) } deriving Show cpWhich :: (MonadReader env m, HasCompiler env) => m WhichCompiler cpWhich = view $ compilerPathsL.to (whichCompiler.cpCompilerVersion) data ExtraDirs = ExtraDirs { edBins :: ![Path Abs Dir] , edInclude :: ![Path Abs Dir] , edLib :: ![Path Abs Dir] } deriving (Show, Generic) instance Semigroup ExtraDirs where (<>) = mappenddefault instance Monoid ExtraDirs where mempty = memptydefault mappend = (<>) -- | An environment which ensures that the given compiler is available -- on the PATH class HasCompiler env where compilerPathsL :: SimpleGetter env CompilerPaths instance HasCompiler CompilerPaths where compilerPathsL = id class HasSourceMap env where sourceMapL :: Lens' env SourceMap instance HasSourceMap EnvConfig where sourceMapL = lens envConfigSourceMap (\x y -> x { envConfigSourceMap = y }) -- | The version of the compiler which will actually be used. May be -- different than that specified in the 'SnapshotDef' and returned -- by 'wantedCompilerVersionL'. actualCompilerVersionL :: HasSourceMap env => SimpleGetter env ActualCompiler actualCompilerVersionL = sourceMapL.to smCompiler buildOptsL :: HasConfig s => Lens' s BuildOpts buildOptsL = configL.lens configBuild (\x y -> x { configBuild = y }) buildOptsMonoidHaddockL :: Lens' BuildOptsMonoid (Maybe Bool) buildOptsMonoidHaddockL = lens (getFirstFalse . buildMonoidHaddock) (\buildMonoid t -> buildMonoid {buildMonoidHaddock = FirstFalse t}) buildOptsMonoidTestsL :: Lens' BuildOptsMonoid (Maybe Bool) buildOptsMonoidTestsL = lens (getFirstFalse . buildMonoidTests) (\buildMonoid t -> buildMonoid {buildMonoidTests = FirstFalse t}) buildOptsMonoidBenchmarksL :: Lens' BuildOptsMonoid (Maybe Bool) buildOptsMonoidBenchmarksL = lens (getFirstFalse . buildMonoidBenchmarks) (\buildMonoid t -> buildMonoid {buildMonoidBenchmarks = FirstFalse t}) buildOptsMonoidInstallExesL :: Lens' BuildOptsMonoid (Maybe Bool) buildOptsMonoidInstallExesL = lens (getFirstFalse . buildMonoidInstallExes) (\buildMonoid t -> buildMonoid {buildMonoidInstallExes = FirstFalse t}) buildOptsInstallExesL :: Lens' BuildOpts Bool buildOptsInstallExesL = lens boptsInstallExes (\bopts t -> bopts {boptsInstallExes = t}) buildOptsHaddockL :: Lens' BuildOpts Bool buildOptsHaddockL = lens boptsHaddock (\bopts t -> bopts {boptsHaddock = t}) globalOptsBuildOptsMonoidL :: Lens' GlobalOpts BuildOptsMonoid globalOptsBuildOptsMonoidL = lens globalConfigMonoid (\x y -> x { globalConfigMonoid = y }) . lens configMonoidBuildOpts (\x y -> x { configMonoidBuildOpts = y }) cabalVersionL :: HasCompiler env => SimpleGetter env Version cabalVersionL = compilerPathsL.to cpCabalVersion whichCompilerL :: Getting r ActualCompiler WhichCompiler whichCompilerL = to whichCompiler envOverrideSettingsL :: HasConfig env => Lens' env (EnvSettings -> IO ProcessContext) envOverrideSettingsL = configL.lens configProcessContextSettings (\x y -> x { configProcessContextSettings = y }) shouldForceGhcColorFlag :: (HasRunner env, HasEnvConfig env) => RIO env Bool shouldForceGhcColorFlag = do canDoColor <- (>= mkVersion [8, 2, 1]) . getGhcVersion <$> view actualCompilerVersionL shouldDoColor <- view useColorL pure $ canDoColor && shouldDoColor appropriateGhcColorFlag :: (HasRunner env, HasEnvConfig env) => RIO env (Maybe String) appropriateGhcColorFlag = f <$> shouldForceGhcColorFlag where f True = Just ghcColorForceFlag f False = Nothing -- | See 'globalTerminal' terminalL :: HasRunner env => Lens' env Bool terminalL = globalOptsL.lens globalTerminal (\x y -> x { globalTerminal = y }) -- | See 'globalReExecVersion' reExecL :: HasRunner env => SimpleGetter env Bool reExecL = globalOptsL.to (isJust . globalReExecVersion) -- | In dev mode, print as a warning, otherwise as debug prettyStackDevL :: HasConfig env => [StyleDoc] -> RIO env () prettyStackDevL docs = do config <- view configL if configStackDeveloperMode config then prettyWarnL docs else prettyDebugL docs stack-2.9.3.1/src/Stack/Types/Config/Build.hs0000644000000000000000000004733014445022466016735 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -- | Configuration options for building. module Stack.Types.Config.Build ( BuildOpts (..) , BuildCommand (..) , defaultBuildOpts , defaultBuildOptsCLI , BuildOptsCLI (..) , BuildOptsMonoid (..) , TestOpts (..) , defaultTestOpts , TestOptsMonoid (..) , HaddockOpts (..) , defaultHaddockOpts , HaddockOptsMonoid (..) , BenchmarkOpts (..) , defaultBenchmarkOpts , BenchmarkOptsMonoid (..) , FileWatchOpts (..) , BuildSubset (..) , ApplyCLIFlag (..) , boptsCLIFlagsByName , CabalVerbosity (..) , toFirstCabalVerbosity ) where import qualified Data.Map.Strict as Map import qualified Data.Text as T import Distribution.Parsec ( Parsec (..), simpleParsec ) import Distribution.Verbosity ( Verbosity, normal, verbose ) import Generics.Deriving.Monoid ( memptydefault, mappenddefault ) import Pantry.Internal.AesonExtended import Stack.Prelude -- | Build options that is interpreted by the build command. -- This is built up from BuildOptsCLI and BuildOptsMonoid data BuildOpts = BuildOpts {boptsLibProfile :: !Bool ,boptsExeProfile :: !Bool ,boptsLibStrip :: !Bool ,boptsExeStrip :: !Bool ,boptsHaddock :: !Bool -- ^ Build haddocks? ,boptsHaddockOpts :: !HaddockOpts -- ^ Options to pass to haddock ,boptsOpenHaddocks :: !Bool -- ^ Open haddocks in the browser? ,boptsHaddockDeps :: !(Maybe Bool) -- ^ Build haddocks for dependencies? ,boptsHaddockInternal :: !Bool -- ^ Build haddocks for all symbols and packages, like @cabal haddock --internal@ ,boptsHaddockHyperlinkSource :: !Bool -- ^ Build hyperlinked source if possible. Fallback to -- @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 ,boptsKeepGoing :: !(Maybe Bool) -- ^ Keep building/running after failure ,boptsKeepTmpFiles :: !Bool -- ^ Keep intermediate files and build directories ,boptsForceDirty :: !Bool -- ^ Force treating all local packages as having dirty files ,boptsTests :: !Bool -- ^ Turn on tests for local targets ,boptsTestOpts :: !TestOpts -- ^ Additional test arguments ,boptsBenchmarks :: !Bool -- ^ Turn on benchmarks for local targets ,boptsBenchmarkOpts :: !BenchmarkOpts -- ^ Additional test arguments -- ^ Commands (with arguments) to run after a successful build -- ^ Only perform the configure step when building ,boptsReconfigure :: !Bool -- ^ Perform the configure step even if already configured ,boptsCabalVerbose :: !CabalVerbosity -- ^ Ask Cabal to be verbose in its builds ,boptsSplitObjs :: !Bool -- ^ Whether to enable split-objs. ,boptsSkipComponents :: ![Text] -- ^ Which components to skip when building ,boptsInterleavedOutput :: !Bool -- ^ Should we use the interleaved GHC output when building -- multiple packages? ,boptsDdumpDir :: !(Maybe Text) } deriving (Show) defaultBuildOpts :: BuildOpts defaultBuildOpts = BuildOpts { boptsLibProfile = defaultFirstFalse buildMonoidLibProfile , boptsExeProfile = defaultFirstFalse buildMonoidExeProfile , boptsLibStrip = defaultFirstTrue buildMonoidLibStrip , boptsExeStrip = defaultFirstTrue buildMonoidExeStrip , boptsHaddock = False , boptsHaddockOpts = defaultHaddockOpts , boptsOpenHaddocks = defaultFirstFalse buildMonoidOpenHaddocks , boptsHaddockDeps = Nothing , boptsHaddockInternal = defaultFirstFalse buildMonoidHaddockInternal , boptsHaddockHyperlinkSource = defaultFirstTrue buildMonoidHaddockHyperlinkSource , boptsInstallExes = defaultFirstFalse buildMonoidInstallExes , boptsInstallCompilerTool = defaultFirstFalse buildMonoidInstallCompilerTool , boptsPreFetch = defaultFirstFalse buildMonoidPreFetch , boptsKeepGoing = Nothing , boptsKeepTmpFiles = defaultFirstFalse buildMonoidKeepTmpFiles , boptsForceDirty = defaultFirstFalse buildMonoidForceDirty , boptsTests = defaultFirstFalse buildMonoidTests , boptsTestOpts = defaultTestOpts , boptsBenchmarks = defaultFirstFalse buildMonoidBenchmarks , boptsBenchmarkOpts = defaultBenchmarkOpts , boptsReconfigure = defaultFirstFalse buildMonoidReconfigure , boptsCabalVerbose = CabalVerbosity normal , boptsSplitObjs = defaultFirstFalse buildMonoidSplitObjs , boptsSkipComponents = [] , boptsInterleavedOutput = defaultFirstTrue buildMonoidInterleavedOutput , boptsDdumpDir = Nothing } defaultBuildOptsCLI ::BuildOptsCLI defaultBuildOptsCLI = BuildOptsCLI { boptsCLITargets = [] , boptsCLIDryrun = False , boptsCLIFlags = Map.empty , boptsCLIGhcOptions = [] , boptsCLIBuildSubset = BSAll , boptsCLIFileWatch = NoFileWatch , boptsCLIWatchAll = False , boptsCLIExec = [] , boptsCLIOnlyConfigure = False , boptsCLICommand = Build , boptsCLIInitialBuildSteps = False } -- | How to apply a CLI flag data ApplyCLIFlag = ACFAllProjectPackages -- ^ Apply to all project packages which have such a flag name available. | ACFByName !PackageName -- ^ Apply to the specified package only. deriving (Show, Eq, Ord) -- | Only flags set via 'ACFByName' boptsCLIFlagsByName :: BuildOptsCLI -> Map PackageName (Map FlagName Bool) boptsCLIFlagsByName = Map.fromList . mapMaybe go . Map.toList . boptsCLIFlags where go (ACFAllProjectPackages, _) = Nothing go (ACFByName name, flags) = Just (name, flags) -- | Build options that may only be specified from the CLI data BuildOptsCLI = BuildOptsCLI { boptsCLITargets :: ![Text] , boptsCLIDryrun :: !Bool , boptsCLIGhcOptions :: ![Text] , boptsCLIFlags :: !(Map ApplyCLIFlag (Map FlagName Bool)) , boptsCLIBuildSubset :: !BuildSubset , boptsCLIFileWatch :: !FileWatchOpts , boptsCLIWatchAll :: !Bool , boptsCLIExec :: ![(String, [String])] , boptsCLIOnlyConfigure :: !Bool , boptsCLICommand :: !BuildCommand , boptsCLIInitialBuildSteps :: !Bool } deriving Show -- | Command sum type for conditional arguments. data BuildCommand = Build | Test | Haddock | Bench | Install deriving (Eq, Show) -- | Build options that may be specified in the stack.yaml or from the CLI data BuildOptsMonoid = BuildOptsMonoid { buildMonoidTrace :: !Any , buildMonoidProfile :: !Any , buildMonoidNoStrip :: !Any , buildMonoidLibProfile :: !FirstFalse , buildMonoidExeProfile :: !FirstFalse , buildMonoidLibStrip :: !FirstTrue , buildMonoidExeStrip :: !FirstTrue , buildMonoidHaddock :: !FirstFalse , buildMonoidHaddockOpts :: !HaddockOptsMonoid , buildMonoidOpenHaddocks :: !FirstFalse , buildMonoidHaddockDeps :: !(First Bool) , buildMonoidHaddockInternal :: !FirstFalse , buildMonoidHaddockHyperlinkSource :: !FirstTrue , buildMonoidInstallExes :: !FirstFalse , buildMonoidInstallCompilerTool :: !FirstFalse , buildMonoidPreFetch :: !FirstFalse , buildMonoidKeepGoing :: !(First Bool) , buildMonoidKeepTmpFiles :: !FirstFalse , buildMonoidForceDirty :: !FirstFalse , buildMonoidTests :: !FirstFalse , buildMonoidTestOpts :: !TestOptsMonoid , buildMonoidBenchmarks :: !FirstFalse , buildMonoidBenchmarkOpts :: !BenchmarkOptsMonoid , buildMonoidReconfigure :: !FirstFalse , buildMonoidCabalVerbose :: !(First CabalVerbosity) , buildMonoidSplitObjs :: !FirstFalse , buildMonoidSkipComponents :: ![Text] , buildMonoidInterleavedOutput :: !FirstTrue , buildMonoidDdumpDir :: !(First Text) } deriving (Show, Generic) instance FromJSON (WithJSONWarnings BuildOptsMonoid) where parseJSON = withObjectWarnings "BuildOptsMonoid" (\o -> do let buildMonoidTrace = Any False buildMonoidProfile = Any False buildMonoidNoStrip = Any False buildMonoidLibProfile <- FirstFalse <$> o ..:? buildMonoidLibProfileArgName buildMonoidExeProfile <-FirstFalse <$> o ..:? buildMonoidExeProfileArgName buildMonoidLibStrip <- FirstTrue <$> o ..:? buildMonoidLibStripArgName buildMonoidExeStrip <-FirstTrue <$> o ..:? buildMonoidExeStripArgName buildMonoidHaddock <- FirstFalse <$> o ..:? buildMonoidHaddockArgName buildMonoidHaddockOpts <- jsonSubWarnings (o ..:? buildMonoidHaddockOptsArgName ..!= mempty) buildMonoidOpenHaddocks <- FirstFalse <$> o ..:? buildMonoidOpenHaddocksArgName buildMonoidHaddockDeps <- First <$> o ..:? buildMonoidHaddockDepsArgName buildMonoidHaddockInternal <- FirstFalse <$> o ..:? buildMonoidHaddockInternalArgName buildMonoidHaddockHyperlinkSource <- FirstTrue <$> o ..:? buildMonoidHaddockHyperlinkSourceArgName buildMonoidInstallExes <- FirstFalse <$> o ..:? buildMonoidInstallExesArgName buildMonoidInstallCompilerTool <- FirstFalse <$> o ..:? buildMonoidInstallCompilerToolArgName buildMonoidPreFetch <- FirstFalse <$> o ..:? buildMonoidPreFetchArgName buildMonoidKeepGoing <- First <$> o ..:? buildMonoidKeepGoingArgName buildMonoidKeepTmpFiles <- FirstFalse <$> o ..:? buildMonoidKeepTmpFilesArgName buildMonoidForceDirty <- FirstFalse <$> o ..:? buildMonoidForceDirtyArgName buildMonoidTests <- FirstFalse <$> o ..:? buildMonoidTestsArgName buildMonoidTestOpts <- jsonSubWarnings (o ..:? buildMonoidTestOptsArgName ..!= mempty) buildMonoidBenchmarks <- FirstFalse <$> o ..:? buildMonoidBenchmarksArgName buildMonoidBenchmarkOpts <- jsonSubWarnings (o ..:? buildMonoidBenchmarkOptsArgName ..!= mempty) buildMonoidReconfigure <- FirstFalse <$> o ..:? buildMonoidReconfigureArgName cabalVerbosity <- First <$> o ..:? buildMonoidCabalVerbosityArgName cabalVerbose <- FirstFalse <$> o ..:? buildMonoidCabalVerboseArgName let buildMonoidCabalVerbose = cabalVerbosity <> toFirstCabalVerbosity cabalVerbose buildMonoidSplitObjs <- FirstFalse <$> o ..:? buildMonoidSplitObjsName buildMonoidSkipComponents <- o ..:? buildMonoidSkipComponentsName ..!= mempty buildMonoidInterleavedOutput <- FirstTrue <$> o ..:? buildMonoidInterleavedOutputName buildMonoidDdumpDir <- o ..:? buildMonoidDdumpDirName ..!= mempty pure BuildOptsMonoid{..}) buildMonoidLibProfileArgName :: Text buildMonoidLibProfileArgName = "library-profiling" buildMonoidExeProfileArgName :: Text buildMonoidExeProfileArgName = "executable-profiling" buildMonoidLibStripArgName :: Text buildMonoidLibStripArgName = "library-stripping" buildMonoidExeStripArgName :: Text buildMonoidExeStripArgName = "executable-stripping" buildMonoidHaddockArgName :: Text buildMonoidHaddockArgName = "haddock" buildMonoidHaddockOptsArgName :: Text buildMonoidHaddockOptsArgName = "haddock-arguments" buildMonoidOpenHaddocksArgName :: Text buildMonoidOpenHaddocksArgName = "open-haddocks" buildMonoidHaddockDepsArgName :: Text buildMonoidHaddockDepsArgName = "haddock-deps" buildMonoidHaddockInternalArgName :: Text buildMonoidHaddockInternalArgName = "haddock-internal" buildMonoidHaddockHyperlinkSourceArgName :: Text buildMonoidHaddockHyperlinkSourceArgName = "haddock-hyperlink-source" buildMonoidInstallExesArgName :: Text buildMonoidInstallExesArgName = "copy-bins" buildMonoidInstallCompilerToolArgName :: Text buildMonoidInstallCompilerToolArgName = "copy-compiler-tool" buildMonoidPreFetchArgName :: Text buildMonoidPreFetchArgName = "prefetch" buildMonoidKeepGoingArgName :: Text buildMonoidKeepGoingArgName = "keep-going" buildMonoidKeepTmpFilesArgName :: Text buildMonoidKeepTmpFilesArgName = "keep-tmp-files" buildMonoidForceDirtyArgName :: Text buildMonoidForceDirtyArgName = "force-dirty" buildMonoidTestsArgName :: Text buildMonoidTestsArgName = "test" buildMonoidTestOptsArgName :: Text buildMonoidTestOptsArgName = "test-arguments" buildMonoidBenchmarksArgName :: Text buildMonoidBenchmarksArgName = "bench" buildMonoidBenchmarkOptsArgName :: Text buildMonoidBenchmarkOptsArgName = "benchmark-opts" buildMonoidReconfigureArgName :: Text buildMonoidReconfigureArgName = "reconfigure" buildMonoidCabalVerbosityArgName :: Text buildMonoidCabalVerbosityArgName = "cabal-verbosity" buildMonoidCabalVerboseArgName :: Text buildMonoidCabalVerboseArgName = "cabal-verbose" buildMonoidSplitObjsName :: Text buildMonoidSplitObjsName = "split-objs" buildMonoidSkipComponentsName :: Text buildMonoidSkipComponentsName = "skip-components" buildMonoidInterleavedOutputName :: Text buildMonoidInterleavedOutputName = "interleaved-output" buildMonoidDdumpDirName :: Text buildMonoidDdumpDirName = "ddump-dir" instance Semigroup BuildOptsMonoid where (<>) = mappenddefault instance Monoid BuildOptsMonoid where mempty = memptydefault mappend = (<>) -- | Which subset of packages to build data BuildSubset = BSAll | BSOnlySnapshot -- ^ Only install packages in the snapshot database, skipping -- packages intended for the local database. | BSOnlyDependencies | BSOnlyLocals -- ^ Refuse to build anything in the snapshot database, see -- https://github.com/commercialhaskell/stack/issues/5272 deriving (Show, Eq) -- | Options for the 'FinalAction' 'DoTests' data TestOpts = TestOpts {toRerunTests :: !Bool -- ^ Whether successful tests will be run gain ,toAdditionalArgs :: ![String] -- ^ Arguments passed to the test program ,toCoverage :: !Bool -- ^ Generate a code coverage report ,toDisableRun :: !Bool -- ^ Disable running of tests ,toMaximumTimeSeconds :: !(Maybe Int) -- ^ test suite timeout in seconds ,toAllowStdin :: !Bool -- ^ Whether to allow standard input } deriving (Eq,Show) defaultTestOpts :: TestOpts defaultTestOpts = TestOpts { toRerunTests = defaultFirstTrue toMonoidRerunTests , toAdditionalArgs = [] , toCoverage = defaultFirstFalse toMonoidCoverage , toDisableRun = defaultFirstFalse toMonoidDisableRun , toMaximumTimeSeconds = Nothing , toAllowStdin = defaultFirstTrue toMonoidAllowStdin } data TestOptsMonoid = TestOptsMonoid { toMonoidRerunTests :: !FirstTrue , toMonoidAdditionalArgs :: ![String] , toMonoidCoverage :: !FirstFalse , toMonoidDisableRun :: !FirstFalse , toMonoidMaximumTimeSeconds :: !(First (Maybe Int)) , toMonoidAllowStdin :: !FirstTrue } deriving (Show, Generic) instance FromJSON (WithJSONWarnings TestOptsMonoid) where parseJSON = withObjectWarnings "TestOptsMonoid" (\o -> do toMonoidRerunTests <- FirstTrue <$> o ..:? toMonoidRerunTestsArgName toMonoidAdditionalArgs <- o ..:? toMonoidAdditionalArgsName ..!= [] toMonoidCoverage <- FirstFalse <$> o ..:? toMonoidCoverageArgName toMonoidDisableRun <- FirstFalse <$> o ..:? toMonoidDisableRunArgName toMonoidMaximumTimeSeconds <- First <$> o ..:? toMonoidMaximumTimeSecondsArgName toMonoidAllowStdin <- FirstTrue <$> o ..:? toMonoidTestsAllowStdinName pure TestOptsMonoid{..}) toMonoidRerunTestsArgName :: Text toMonoidRerunTestsArgName = "rerun-tests" toMonoidAdditionalArgsName :: Text toMonoidAdditionalArgsName = "additional-args" toMonoidCoverageArgName :: Text toMonoidCoverageArgName = "coverage" toMonoidDisableRunArgName :: Text toMonoidDisableRunArgName = "no-run-tests" toMonoidMaximumTimeSecondsArgName :: Text toMonoidMaximumTimeSecondsArgName = "test-suite-timeout" toMonoidTestsAllowStdinName :: Text toMonoidTestsAllowStdinName = "tests-allow-stdin" instance Semigroup TestOptsMonoid where (<>) = mappenddefault instance Monoid TestOptsMonoid where mempty = memptydefault mappend = (<>) -- | Haddock Options newtype HaddockOpts = HaddockOpts { hoAdditionalArgs :: [String] -- ^ Arguments passed to haddock program } deriving (Eq,Show) newtype HaddockOptsMonoid = HaddockOptsMonoid {hoMonoidAdditionalArgs :: [String] } deriving (Show, Generic) defaultHaddockOpts :: HaddockOpts defaultHaddockOpts = HaddockOpts {hoAdditionalArgs = []} instance FromJSON (WithJSONWarnings HaddockOptsMonoid) where parseJSON = withObjectWarnings "HaddockOptsMonoid" (\o -> do hoMonoidAdditionalArgs <- o ..:? hoMonoidAdditionalArgsName ..!= [] pure HaddockOptsMonoid{..}) instance Semigroup HaddockOptsMonoid where (<>) = mappenddefault instance Monoid HaddockOptsMonoid where mempty = memptydefault mappend = (<>) hoMonoidAdditionalArgsName :: Text hoMonoidAdditionalArgsName = "haddock-args" -- | Options for the 'FinalAction' 'DoBenchmarks' data BenchmarkOpts = BenchmarkOpts { beoAdditionalArgs :: !(Maybe String) -- ^ Arguments passed to the benchmark program , beoDisableRun :: !Bool -- ^ Disable running of benchmarks } deriving (Eq,Show) defaultBenchmarkOpts :: BenchmarkOpts defaultBenchmarkOpts = BenchmarkOpts { beoAdditionalArgs = Nothing , beoDisableRun = False } data BenchmarkOptsMonoid = BenchmarkOptsMonoid { beoMonoidAdditionalArgs :: !(First String) , beoMonoidDisableRun :: !(First Bool) } deriving (Show, Generic) instance FromJSON (WithJSONWarnings BenchmarkOptsMonoid) where parseJSON = withObjectWarnings "BenchmarkOptsMonoid" (\o -> do beoMonoidAdditionalArgs <- First <$> o ..:? beoMonoidAdditionalArgsArgName beoMonoidDisableRun <- First <$> o ..:? beoMonoidDisableRunArgName pure BenchmarkOptsMonoid{..}) beoMonoidAdditionalArgsArgName :: Text beoMonoidAdditionalArgsArgName = "benchmark-arguments" beoMonoidDisableRunArgName :: Text beoMonoidDisableRunArgName = "no-run-benchmarks" instance Semigroup BenchmarkOptsMonoid where (<>) = mappenddefault instance Monoid BenchmarkOptsMonoid where mempty = memptydefault mappend = (<>) data FileWatchOpts = NoFileWatch | FileWatch | FileWatchPoll deriving (Show,Eq) newtype CabalVerbosity = CabalVerbosity Verbosity deriving (Eq, Show) toFirstCabalVerbosity :: FirstFalse -> First CabalVerbosity toFirstCabalVerbosity vf = First $ getFirstFalse vf <&> \p -> if p then verboseLevel else normalLevel where verboseLevel = CabalVerbosity verbose normalLevel = CabalVerbosity normal instance FromJSON CabalVerbosity where parseJSON = withText "CabalVerbosity" $ \t -> let s = T.unpack t errMsg = fail $ "Unrecognised Cabal verbosity: " ++ s in maybe errMsg pure (simpleParsec s) instance Parsec CabalVerbosity where parsec = CabalVerbosity <$> parsec stack-2.9.3.1/src/Stack/Types/Docker.hs0000644000000000000000000004603414445022466015700 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -- | Docker types. module Stack.Types.Docker ( DockerException (..) , DockerMonoidRepoOrImage (..) , DockerOpts (..) , DockerOptsMonoid (..) , DockerStackExe (..) , Mount (..) , VersionRangeJSON (..) , dockerAutoPullArgName , dockerCmdName , dockerContainerNameArgName , dockerContainerPlatform , dockerDetachArgName , dockerEnableArgName , dockerEntrypointArgName , dockerEnvArgName , dockerHelpOptName , dockerImageArgName , dockerMountArgName , dockerMountModeArgName , dockerNetworkArgName , dockerPersistArgName , dockerPullCmdName , dockerRegistryLoginArgName , dockerRegistryPasswordArgName , dockerRegistryUsernameArgName , dockerRepoArgName , dockerRequireDockerVersionArgName , dockerRunArgsArgName , dockerSetUserArgName , dockerStackExeArgName , dockerStackExeDownloadVal , dockerStackExeHostVal , dockerStackExeImageVal , parseDockerStackExe , reExecArgName ) where import Data.List ( intercalate ) import qualified Data.Text as T import Distribution.System ( Platform (..), OS (..), Arch (..) ) import Distribution.Text ( simpleParse, display ) import Distribution.Version ( anyVersion ) import Generics.Deriving.Monoid ( mappenddefault, memptydefault ) import Pantry.Internal.AesonExtended import Path import Stack.Prelude hiding ( Display (..) ) import Stack.Types.Version import Text.Read ( Read (..) ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Docker" module. data DockerException = DockerMustBeEnabledException -- ^ Docker must be enabled to use the command. | OnlyOnHostException -- ^ Command must be run on host OS (not in a container). | InspectFailedException String -- ^ @docker inspect@ failed. | NotPulledException String -- ^ Image does not exist. | InvalidImagesOutputException String -- ^ Invalid output from @docker images@. | InvalidPSOutputException String -- ^ Invalid output from @docker ps@. | InvalidInspectOutputException String -- ^ Invalid output from @docker inspect@. | PullFailedException String -- ^ Could not pull a Docker image. | DockerTooOldException Version Version -- ^ Installed version of @docker@ below minimum version. | DockerVersionProhibitedException [Version] Version -- ^ Installed version of @docker@ is prohibited. | BadDockerVersionException VersionRange Version -- ^ Installed version of @docker@ is out of range specified in config file. | InvalidVersionOutputException -- ^ Invalid output from @docker --version@. | HostStackTooOldException Version (Maybe Version) -- ^ Version of @stack@ on host is too old for version in image. | ContainerStackTooOldException Version Version -- ^ Version of @stack@ in container/image is too old for version on host. | CannotDetermineProjectRootException -- ^ Can't determine the project root (where to put docker sandbox). | DockerNotInstalledException -- ^ @docker --version@ failed. | UnsupportedStackExeHostPlatformException -- ^ Using host stack-exe on unsupported platform. | DockerStackExeParseException String -- ^ @stack-exe@ option fails to parse. deriving (Show, Typeable) instance Exception DockerException where displayException DockerMustBeEnabledException = "Error: [S-3223]\n" ++ "Docker must be enabled in your configuration file to use this \ \command." displayException OnlyOnHostException = "Error: [S-9779]\n" ++ "This command must be run on host OS (not in a Docker container)." displayException (InspectFailedException image) = concat [ "Error: [S-9105]\n" , "'docker inspect' failed for image after pull: " , image , "." ] displayException (NotPulledException image) = concat [ "Error: [S-6626]\n" , "The Docker image referenced by your configuration file" , " has not\nbeen downloaded:\n " , image , "\n\nRun '" , unwords [stackProgName, dockerCmdName, dockerPullCmdName] , "' to download it, then try again." ] displayException (InvalidImagesOutputException l) = concat [ "Error: [S-5841]\n" , "Invalid 'docker images' output line: '" , l , "'." ] displayException (InvalidPSOutputException l) = concat [ "Error: [S-9608]\n" , "Invalid 'docker ps' output line: '" , l ,"'." ] displayException (InvalidInspectOutputException msg) = concat [ "Error: [S-2240]\n" , "Invalid 'docker inspect' output: " , msg , "." ] displayException (PullFailedException image) = concat [ "Error: [S-6092]\n" , "Could not pull Docker image:\n " , image , "\nThere may not be an image on the registry for your resolver's LTS \ \version in\n" , "your configuration file." ] displayException (DockerTooOldException minVersion haveVersion) = concat [ "Error: [S-6281]\n" , "Minimum docker version '" , versionString minVersion , "' is required by " , stackProgName , " (you have '" , versionString haveVersion , "')." ] displayException (DockerVersionProhibitedException prohibitedVersions haveVersion) = concat [ "Error: [S-8252]\n" , "These Docker versions are incompatible with " , stackProgName , " (you have '" , versionString haveVersion , "'): " , intercalate ", " (map versionString prohibitedVersions) , "." ] displayException (BadDockerVersionException requiredRange haveVersion) = concat [ "Error: [S-6170]\n" , "The version of 'docker' you are using (" , show haveVersion , ") is outside the required\n" , "version range specified in stack.yaml (" , T.unpack (versionRangeText requiredRange) , ")." ] displayException InvalidVersionOutputException = "Error: [S-5827]\n" ++ "Cannot get Docker version (invalid 'docker --version' output)." displayException (HostStackTooOldException minVersion (Just hostVersion)) = concat [ "Error: [S-7112]\n" , "The host's version of '" , stackProgName , "' is too old for this Docker image.\nVersion " , versionString minVersion , " is required; you have " , versionString hostVersion , "." ] displayException (HostStackTooOldException minVersion Nothing) = concat [ "Error: [S-7112]\n" , "The host's version of '" , stackProgName , "' is too old.\nVersion " , versionString minVersion , " is required." ] displayException (ContainerStackTooOldException requiredVersion containerVersion) = concat [ "Error: [S-5832]\n" , "The Docker container's version of '" , stackProgName , "' is too old.\nVersion " , versionString requiredVersion , " is required; the container has " , versionString containerVersion , "." ] displayException CannotDetermineProjectRootException = "Error: [S-4078]\n" ++ "Cannot determine project root directory for Docker sandbox." displayException DockerNotInstalledException = "Error: [S-7058]\n" ++ "Cannot find 'docker' in PATH. Is Docker installed?" displayException UnsupportedStackExeHostPlatformException = concat [ "Error: [S-6894]\n" , "Using host's " , stackProgName , " executable in Docker container is only supported on " , display dockerContainerPlatform , " platform." ] displayException (DockerStackExeParseException s) = concat [ "Error: [S-1512]\n" , "Failed to parse " , show s , ". Expected " , show dockerStackExeDownloadVal , ", " , show dockerStackExeHostVal , ", " , show dockerStackExeImageVal , " or absolute path to executable." ] -- | Docker configuration. data DockerOpts = DockerOpts { dockerEnable :: !Bool -- ^ Is using Docker enabled? , dockerImage :: !(Either SomeException String) -- ^ Exact Docker image tag or ID. Overrides docker-repo-*/tag. , dockerRegistryLogin :: !Bool -- ^ Does registry require login for pulls? , dockerRegistryUsername :: !(Maybe String) -- ^ Optional username for Docker registry. , dockerRegistryPassword :: !(Maybe String) -- ^ Optional password for Docker registry. , dockerAutoPull :: !Bool -- ^ Automatically pull new images. , dockerDetach :: !Bool -- ^ Whether to run a detached container , dockerPersist :: !Bool -- ^ Create a persistent container (don't remove it when finished). Implied by -- `dockerDetach`. , dockerContainerName :: !(Maybe String) -- ^ Container name to use, only makes sense from command-line with `dockerPersist` -- or `dockerDetach`. , dockerNetwork :: !(Maybe String) -- ^ The network docker uses. , dockerRunArgs :: ![String] -- ^ Arguments to pass directly to @docker run@. , dockerMount :: ![Mount] -- ^ Volumes to mount in the container. , dockerMountMode :: !(Maybe String) -- ^ Volume mount mode , dockerEnv :: ![String] -- ^ Environment variables to set in the container. , dockerStackExe :: !(Maybe DockerStackExe) -- ^ Location of container-compatible Stack executable , dockerSetUser :: !(Maybe Bool) -- ^ Set in-container user to match host's , dockerRequireDockerVersion :: !VersionRange -- ^ Require a version of Docker within this range. } deriving (Show) -- | An uninterpreted representation of docker options. -- Configurations may be "cascaded" using mappend (left-biased). data DockerOptsMonoid = DockerOptsMonoid { dockerMonoidDefaultEnable :: !Any -- ^ Should Docker be defaulted to enabled (does @docker:@ section exist in the config)? , dockerMonoidEnable :: !(First Bool) -- ^ Is using Docker enabled? , dockerMonoidRepoOrImage :: !(First DockerMonoidRepoOrImage) -- ^ Docker repository name (e.g. @fpco/stack-build@ or @fpco/stack-full:lts-2.8@) , dockerMonoidRegistryLogin :: !(First Bool) -- ^ Does registry require login for pulls? , dockerMonoidRegistryUsername :: !(First String) -- ^ Optional username for Docker registry. , dockerMonoidRegistryPassword :: !(First String) -- ^ Optional password for Docker registry. , dockerMonoidAutoPull :: !FirstTrue -- ^ Automatically pull new images. , dockerMonoidDetach :: !FirstFalse -- ^ Whether to run a detached container , dockerMonoidPersist :: !FirstFalse -- ^ Create a persistent container (don't remove it when finished). Implied by -- `dockerDetach`. , dockerMonoidContainerName :: !(First String) -- ^ Container name to use, only makes sense from command-line with `dockerPersist` -- or `dockerDetach`. , dockerMonoidNetwork :: !(First String) -- ^ See: 'dockerNetwork' , dockerMonoidRunArgs :: ![String] -- ^ Arguments to pass directly to @docker run@ , dockerMonoidMount :: ![Mount] -- ^ Volumes to mount in the container , dockerMonoidMountMode :: !(First String) -- ^ Volume mount mode , dockerMonoidEnv :: ![String] -- ^ Environment variables to set in the container , dockerMonoidStackExe :: !(First DockerStackExe) -- ^ Location of container-compatible Stack executable , dockerMonoidSetUser :: !(First Bool) -- ^ Set in-container user to match host's , dockerMonoidRequireDockerVersion :: !IntersectingVersionRange -- ^ See: 'dockerRequireDockerVersion' } deriving (Show, Generic) -- | Decode uninterpreted docker options from JSON/YAML. instance FromJSON (WithJSONWarnings DockerOptsMonoid) where parseJSON = withObjectWarnings "DockerOptsMonoid" (\o -> do let dockerMonoidDefaultEnable = Any True dockerMonoidEnable <- First <$> o ..:? dockerEnableArgName dockerMonoidRepoOrImage <- First <$> ( (Just . DockerMonoidImage <$> o ..: dockerImageArgName) <|> (Just . DockerMonoidRepo <$> o ..: dockerRepoArgName) <|> pure Nothing ) dockerMonoidRegistryLogin <- First <$> o ..:? dockerRegistryLoginArgName dockerMonoidRegistryUsername <- First <$> o ..:? dockerRegistryUsernameArgName dockerMonoidRegistryPassword <- First <$> o ..:? dockerRegistryPasswordArgName dockerMonoidAutoPull <- FirstTrue <$> o ..:? dockerAutoPullArgName dockerMonoidDetach <- FirstFalse <$> o ..:? dockerDetachArgName dockerMonoidPersist <- FirstFalse <$> o ..:? dockerPersistArgName dockerMonoidContainerName <- First <$> o ..:? dockerContainerNameArgName dockerMonoidNetwork <- First <$> o ..:? dockerNetworkArgName dockerMonoidRunArgs <- o ..:? dockerRunArgsArgName ..!= [] dockerMonoidMount <- o ..:? dockerMountArgName ..!= [] dockerMonoidMountMode <- First <$> o ..:? dockerMountModeArgName dockerMonoidEnv <- o ..:? dockerEnvArgName ..!= [] dockerMonoidStackExe <- First <$> o ..:? dockerStackExeArgName dockerMonoidSetUser <- First <$> o ..:? dockerSetUserArgName dockerMonoidRequireDockerVersion <- IntersectingVersionRange . unVersionRangeJSON <$> ( o ..:? dockerRequireDockerVersionArgName ..!= VersionRangeJSON anyVersion ) pure DockerOptsMonoid{..}) -- | Left-biased combine Docker options instance Semigroup DockerOptsMonoid where (<>) = mappenddefault -- | Left-biased combine Docker options instance Monoid DockerOptsMonoid where mempty = memptydefault mappend = (<>) -- | Where to get the `stack` executable to run in Docker containers data DockerStackExe = DockerStackExeDownload -- ^ Download from official bindist | DockerStackExeHost -- ^ Host's `stack` (linux-x86_64 only) | DockerStackExeImage -- ^ Docker image's `stack` (versions must match) | DockerStackExePath (Path Abs File) -- ^ Executable at given path deriving (Show) instance FromJSON DockerStackExe where parseJSON a = do s <- parseJSON a case parseDockerStackExe s of Right dse -> pure dse Left e -> fail (displayException e) -- | Parse 'DockerStackExe'. parseDockerStackExe :: (MonadThrow m) => String -> m DockerStackExe parseDockerStackExe t | t == dockerStackExeDownloadVal = pure DockerStackExeDownload | t == dockerStackExeHostVal = pure DockerStackExeHost | t == dockerStackExeImageVal = pure DockerStackExeImage | otherwise = case parseAbsFile t of Just p -> pure (DockerStackExePath p) Nothing -> throwM (DockerStackExeParseException t) -- | Docker volume mount. data Mount = Mount String String -- | For optparse-applicative. instance Read Mount where readsPrec _ s = case break (== ':') s of (a,':':b) -> [(Mount a b,"")] (a,[]) -> [(Mount a a,"")] _ -> fail "Invalid value for Docker mount (expect '/host/path:/container/path')" -- | Show instance. instance Show Mount where show (Mount a b) = if a == b then a else concat [a,":",b] -- | For YAML. instance FromJSON Mount where parseJSON v = do s <- parseJSON v case readMaybe s of Nothing -> fail $ "Mount read failed: " ++ s Just x -> pure x -- | Options for Docker repository or image. data DockerMonoidRepoOrImage = DockerMonoidRepo String | DockerMonoidImage String deriving (Show) -- | Newtype for non-orphan FromJSON instance. newtype VersionRangeJSON = VersionRangeJSON { unVersionRangeJSON :: VersionRange } -- | Parse VersionRange. instance FromJSON VersionRangeJSON where parseJSON = withText "VersionRange" (\s -> maybe (fail ("Invalid cabal-style VersionRange: " ++ T.unpack s)) (pure . VersionRangeJSON) (Distribution.Text.simpleParse (T.unpack s))) -- | Docker enable argument name. dockerEnableArgName :: Text dockerEnableArgName = "enable" -- | Docker repo arg argument name. dockerRepoArgName :: Text dockerRepoArgName = "repo" -- | Docker image argument name. dockerImageArgName :: Text dockerImageArgName = "image" -- | Docker registry login argument name. dockerRegistryLoginArgName :: Text dockerRegistryLoginArgName = "registry-login" -- | Docker registry username argument name. dockerRegistryUsernameArgName :: Text dockerRegistryUsernameArgName = "registry-username" -- | Docker registry password argument name. dockerRegistryPasswordArgName :: Text dockerRegistryPasswordArgName = "registry-password" -- | Docker auto-pull argument name. dockerAutoPullArgName :: Text dockerAutoPullArgName = "auto-pull" -- | Docker detach argument name. dockerDetachArgName :: Text dockerDetachArgName = "detach" -- | Docker run args argument name. dockerRunArgsArgName :: Text dockerRunArgsArgName = "run-args" -- | Docker mount argument name. dockerMountArgName :: Text dockerMountArgName = "mount" -- | Docker mount mode argument name. dockerMountModeArgName :: Text dockerMountModeArgName = "mount-mode" -- | Docker environment variable argument name. dockerEnvArgName :: Text dockerEnvArgName = "env" -- | Docker container name argument name. dockerContainerNameArgName :: Text dockerContainerNameArgName = "container-name" -- -- | Docker container name argument name. dockerNetworkArgName :: Text dockerNetworkArgName = "network" -- | Docker persist argument name. dockerPersistArgName :: Text dockerPersistArgName = "persist" -- | Docker Stack executable argument name. dockerStackExeArgName :: Text dockerStackExeArgName = "stack-exe" -- | Value for @--docker-stack-exe=download@ dockerStackExeDownloadVal :: String dockerStackExeDownloadVal = "download" -- | Value for @--docker-stack-exe=host@ dockerStackExeHostVal :: String dockerStackExeHostVal = "host" -- | Value for @--docker-stack-exe=image@ dockerStackExeImageVal :: String dockerStackExeImageVal = "image" -- | Docker @set-user@ argument name dockerSetUserArgName :: Text dockerSetUserArgName = "set-user" -- | Docker @require-version@ argument name dockerRequireDockerVersionArgName :: Text dockerRequireDockerVersionArgName = "require-docker-version" -- | Argument name used to pass docker entrypoint data (only used internally) dockerEntrypointArgName :: String dockerEntrypointArgName = "internal-docker-entrypoint" -- | Command-line argument for "docker" dockerCmdName :: String dockerCmdName = "docker" dockerHelpOptName :: String dockerHelpOptName = dockerCmdName ++ "-help" -- | Command-line argument for @docker pull@. dockerPullCmdName :: String dockerPullCmdName = "pull" -- | Command-line option for @--internal-re-exec-version@. reExecArgName :: String reExecArgName = "internal-re-exec-version" -- | Platform that Docker containers run dockerContainerPlatform :: Platform dockerContainerPlatform = Platform X86_64 Linux stack-2.9.3.1/src/Stack/Types/GhcPkgId.hs0000644000000000000000000000430214445022466016101 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} -- | A ghc-pkg id. module Stack.Types.GhcPkgId ( GhcPkgId , unGhcPkgId , ghcPkgIdParser , parseGhcPkgId , ghcPkgIdString ) where import Stack.Prelude import Pantry.Internal.AesonExtended import Data.Attoparsec.Text import qualified Data.Text as T import Database.Persist.Sql ( PersistField, PersistFieldSql ) import Prelude ( Read (..) ) -- | A parse fail. newtype GhcPkgIdParseFail = GhcPkgIdParseFail Text deriving (Show, Typeable) instance Exception GhcPkgIdParseFail where displayException (GhcPkgIdParseFail bs) = concat [ "Error: [S-5359]\n" , "Invalid package ID: " , show bs ] -- | A ghc-pkg package identifier. newtype GhcPkgId = GhcPkgId Text deriving (Eq,Ord,Data,Typeable,Generic,PersistField,PersistFieldSql) instance Hashable GhcPkgId instance NFData GhcPkgId instance Show GhcPkgId where show = show . ghcPkgIdString instance Read GhcPkgId where readsPrec i = map (first (GhcPkgId . T.pack)) . readsPrec i instance FromJSON GhcPkgId where parseJSON = withText "GhcPkgId" $ \t -> case parseGhcPkgId t of Left e -> fail $ show (e, t) Right x -> pure x instance ToJSON GhcPkgId where toJSON g = toJSON (ghcPkgIdString g) -- | Convenient way to parse a package name from a 'Text'. parseGhcPkgId :: MonadThrow m => Text -> m GhcPkgId parseGhcPkgId x = go x where go = either (const (throwM (GhcPkgIdParseFail x))) pure . parseOnly (ghcPkgIdParser <* endOfInput) -- | A parser for a package-version-hash pair. ghcPkgIdParser :: Parser GhcPkgId ghcPkgIdParser = let elements = "_.-" :: String in GhcPkgId . T.pack <$> many1 (choice [digit, letter, satisfy (`elem` elements)]) -- | Get a string representation of GHC package id. ghcPkgIdString :: GhcPkgId -> String ghcPkgIdString (GhcPkgId x) = T.unpack x -- | Get a text value of GHC package id unGhcPkgId :: GhcPkgId -> Text unGhcPkgId (GhcPkgId v) = v stack-2.9.3.1/src/Stack/Types/NamedComponent.hs0000644000000000000000000000466314445022466017402 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Types.NamedComponent ( NamedComponent (..) , renderComponent , renderPkgComponents , renderPkgComponent , exeComponents , testComponents , benchComponents , internalLibComponents , isCLib , isCInternalLib , isCExe , isCTest , isCBench ) where import qualified Data.Set as Set import qualified Data.Text as T import Pantry import Stack.Prelude -- | A single, fully resolved component of a package data NamedComponent = CLib | CInternalLib !Text | CExe !Text | CTest !Text | CBench !Text deriving (Show, Eq, Ord) renderComponent :: NamedComponent -> Text renderComponent CLib = "lib" renderComponent (CInternalLib x) = "internal-lib:" <> x renderComponent (CExe x) = "exe:" <> x renderComponent (CTest x) = "test:" <> x renderComponent (CBench x) = "bench:" <> x renderPkgComponents :: [(PackageName, NamedComponent)] -> Text renderPkgComponents = T.intercalate " " . map renderPkgComponent renderPkgComponent :: (PackageName, NamedComponent) -> Text renderPkgComponent (pkg, comp) = fromString (packageNameString pkg) <> ":" <> renderComponent comp exeComponents :: Set NamedComponent -> Set Text exeComponents = Set.fromList . mapMaybe mExeName . Set.toList where mExeName (CExe name) = Just name mExeName _ = Nothing testComponents :: Set NamedComponent -> Set Text testComponents = Set.fromList . mapMaybe mTestName . Set.toList where mTestName (CTest name) = Just name mTestName _ = Nothing benchComponents :: Set NamedComponent -> Set Text benchComponents = Set.fromList . mapMaybe mBenchName . Set.toList where mBenchName (CBench name) = Just name mBenchName _ = Nothing internalLibComponents :: Set NamedComponent -> Set Text internalLibComponents = Set.fromList . mapMaybe mInternalName . Set.toList where mInternalName (CInternalLib name) = Just name mInternalName _ = Nothing isCLib :: NamedComponent -> Bool isCLib CLib{} = True isCLib _ = False isCInternalLib :: NamedComponent -> Bool isCInternalLib CInternalLib{} = True isCInternalLib _ = False isCExe :: NamedComponent -> Bool isCExe CExe{} = True isCExe _ = False isCTest :: NamedComponent -> Bool isCTest CTest{} = True isCTest _ = False isCBench :: NamedComponent -> Bool isCBench CBench{} = True isCBench _ = False stack-2.9.3.1/src/Stack/Types/Nix.hs0000644000000000000000000000743214445022466015226 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} -- | Nix types. module Stack.Types.Nix ( NixOpts (..) , NixOptsMonoid (..) , nixAddGCRootsArgName , nixEnableArgName , nixInitFileArgName , nixPackagesArgName , nixPathArgName , nixPureShellArgName , nixShellOptsArgName ) where import Generics.Deriving.Monoid ( mappenddefault, memptydefault ) import Pantry.Internal.AesonExtended import Stack.Prelude -- | Nix configuration. Parameterize by resolver type to avoid cyclic -- dependency. data NixOpts = NixOpts { nixEnable :: !Bool , nixPureShell :: !Bool , nixPackages :: ![Text] -- ^ The system packages to be installed in the environment before it runs , nixInitFile :: !(Maybe FilePath) -- ^ The path of a file containing preconfiguration of the environment (e.g shell.nix) , nixShellOptions :: ![Text] -- ^ Options to be given to the nix-shell command line , nixAddGCRoots :: !Bool -- ^ Should we register gc roots so running nix-collect-garbage doesn't remove nix dependencies } deriving (Show) -- | An uninterpreted representation of nix options. -- Configurations may be "cascaded" using mappend (left-biased). data NixOptsMonoid = NixOptsMonoid { nixMonoidEnable :: !(First Bool) -- ^ Is using nix-shell enabled? , nixMonoidPureShell :: !(First Bool) -- ^ Should the nix-shell be pure , nixMonoidPackages :: !(First [Text]) -- ^ System packages to use (given to nix-shell) , nixMonoidInitFile :: !(First FilePath) -- ^ The path of a file containing preconfiguration of the environment (e.g shell.nix) , nixMonoidShellOptions :: !(First [Text]) -- ^ Options to be given to the nix-shell command line , nixMonoidPath :: !(First [Text]) -- ^ Override parts of NIX_PATH (notably 'nixpkgs') , nixMonoidAddGCRoots :: !FirstFalse -- ^ Should we register gc roots so running nix-collect-garbage doesn't remove nix dependencies } deriving (Eq, Generic, Show) -- | Decode uninterpreted nix options from JSON/YAML. instance FromJSON (WithJSONWarnings NixOptsMonoid) where parseJSON = withObjectWarnings "NixOptsMonoid" ( \o -> do nixMonoidEnable <- First <$> o ..:? nixEnableArgName nixMonoidPureShell <- First <$> o ..:? nixPureShellArgName nixMonoidPackages <- First <$> o ..:? nixPackagesArgName nixMonoidInitFile <- First <$> o ..:? nixInitFileArgName nixMonoidShellOptions <- First <$> o ..:? nixShellOptsArgName nixMonoidPath <- First <$> o ..:? nixPathArgName nixMonoidAddGCRoots <- FirstFalse <$> o ..:? nixAddGCRootsArgName pure NixOptsMonoid{..} ) -- | Left-biased combine Nix options instance Semigroup NixOptsMonoid where (<>) = mappenddefault -- | Left-biased combine Nix options instance Monoid NixOptsMonoid where mempty = memptydefault mappend = (<>) -- | Nix enable argument name. nixEnableArgName :: Text nixEnableArgName = "enable" -- | Nix run in pure shell argument name. nixPureShellArgName :: Text nixPureShellArgName = "pure" -- | Nix packages (build inputs) argument name. nixPackagesArgName :: Text nixPackagesArgName = "packages" -- | shell.nix file path argument name. nixInitFileArgName :: Text nixInitFileArgName = "shell-file" -- | Extra options for the nix-shell command argument name. nixShellOptsArgName :: Text nixShellOptsArgName = "nix-shell-options" -- | NIX_PATH override argument name nixPathArgName :: Text nixPathArgName = "path" -- | Add GC roots arg name nixAddGCRootsArgName :: Text nixAddGCRootsArgName = "add-gc-roots" stack-2.9.3.1/src/Stack/Types/Package.hs0000644000000000000000000004000114445022466016010 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} module Stack.Types.Package ( BuildInfoOpts (..) , ExeName (..) , FileCacheInfo (..) , GetPackageOpts (..) , InstallLocation (..) , InstallMap , Installed (..) , InstalledPackageLocation (..) , InstalledMap , LocalPackage (..) , MemoizedWith (..) , Package (..) , PackageConfig (..) , PackageException (..) , PackageLibraries (..) , PackageSource (..) , dotCabalCFilePath , dotCabalGetPath , dotCabalMain , dotCabalMainPath , dotCabalModule , dotCabalModulePath , installedPackageIdentifier , installedVersion , lpFiles , lpFilesForComponents , memoizeRefWith , packageDefinedFlags , packageIdent , packageIdentifier , psVersion , runMemoizedWith ) where import Stack.Prelude import qualified RIO.Text as T import Data.Aeson ( ToJSON (..), FromJSON (..), (.=), (.:), object, withObject ) import qualified Data.Map as M import qualified Data.Set as Set import Distribution.CabalSpecVersion import Distribution.Parsec ( PError (..), PWarning (..), showPos ) import qualified Distribution.SPDX.License as SPDX import Distribution.License ( License ) import Distribution.ModuleName ( ModuleName ) import Distribution.PackageDescription ( TestSuiteInterface, BuildType ) import Distribution.System ( Platform (..) ) import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.GhcPkgId import Stack.Types.NamedComponent import Stack.Types.SourceMap import Stack.Types.Version import Stack.Types.Dependency ( DepValue ) import Stack.Types.PackageFile ( GetPackageFiles (..), DotCabalDescriptor (..) , DotCabalPath (..) ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Package" module. data PackageException = PackageInvalidCabalFile !(Either PackageIdentifierRevision (Path Abs File)) !(Maybe Version) ![PError] ![PWarning] | MismatchedCabalIdentifier !PackageIdentifierRevision !PackageIdentifier | CabalFileNameParseFail FilePath | CabalFileNameInvalidPackageName FilePath | ComponentNotParsedBug deriving (Show, Typeable) instance Exception PackageException where displayException (PackageInvalidCabalFile loc _mversion errs warnings) = concat [ "Error: [S-8072]\n" , "Unable to parse Cabal file " , case loc of Left pir -> "for " ++ T.unpack (utf8BuilderToText (display pir)) Right fp -> toFilePath fp {- Not actually needed, the errors will indicate if a newer version exists. Also, it seems that this is set to Just the version even if we support it. , case mversion of Nothing -> "" Just version -> "\nRequires newer Cabal file parser version: " ++ versionString version -} , "\n\n" , unlines $ map (\(PError pos msg) -> concat [ "- " , showPos pos , ": " , msg ]) errs , unlines $ map (\(PWarning _ pos msg) -> concat [ "- " , showPos pos , ": " , msg ]) warnings ] displayException (MismatchedCabalIdentifier pir ident) = concat [ "Error: [S-5394]\n" , "Mismatched package identifier." , "\nFound: " , packageIdentifierString ident , "\nExpected: " , T.unpack $ utf8BuilderToText $ display pir ] displayException (CabalFileNameParseFail fp) = concat [ "Error: [S-2203]\n" , "Invalid file path for Cabal file, must have a .cabal extension: " , fp ] displayException (CabalFileNameInvalidPackageName fp) = concat [ "Error: [S-8854]\n" , "Cabal file names must use valid package names followed by a .cabal \ \extension, the following is invalid: " , fp ] displayException ComponentNotParsedBug = bugReport "[S-4623]" "Component names should always parse as directory names." -- | Libraries in a package. Since Cabal 2.0, internal libraries are a -- thing. data PackageLibraries = NoLibraries | HasLibraries !(Set Text) -- ^ the foreign library names, sub libraries get built automatically without explicit component name passing deriving (Show,Typeable) -- | Name of an executable. newtype ExeName = ExeName { unExeName :: Text } deriving (Show, Eq, Ord, Hashable, IsString, Generic, NFData, Data, Typeable) -- | Some package info. data Package = Package {packageName :: !PackageName -- ^ Name of the package. ,packageVersion :: !Version -- ^ Version of the package ,packageLicense :: !(Either SPDX.License License) -- ^ The license the package was released under. ,packageFiles :: !GetPackageFiles -- ^ Get all files of the package. ,packageDeps :: !(Map PackageName DepValue) -- ^ Packages that the package depends on, both as libraries and build tools. ,packageUnknownTools :: !(Set ExeName) -- ^ Build tools specified in the legacy manner (build-tools:) that failed the hard-coded lookup. ,packageAllDeps :: !(Set PackageName) -- ^ Original dependencies (not sieved). ,packageGhcOptions :: ![Text] -- ^ Ghc options used on package. ,packageCabalConfigOpts :: ![Text] -- ^ Additional options passed to ./Setup.hs configure ,packageFlags :: !(Map FlagName Bool) -- ^ Flags used on package. ,packageDefaultFlags :: !(Map FlagName Bool) -- ^ Defaults for unspecified flags. ,packageLibraries :: !PackageLibraries -- ^ does the package have a buildable library stanza? ,packageInternalLibraries :: !(Set Text) -- ^ names of internal libraries ,packageTests :: !(Map Text TestSuiteInterface) -- ^ names and interfaces of test suites ,packageBenchmarks :: !(Set Text) -- ^ names of benchmarks ,packageExes :: !(Set Text) -- ^ names of executables ,packageOpts :: !GetPackageOpts -- ^ Args to pass to GHC. ,packageHasExposedModules :: !Bool -- ^ Does the package have exposed modules? ,packageBuildType :: !BuildType -- ^ Package build-type. ,packageSetupDeps :: !(Maybe (Map PackageName VersionRange)) -- ^ If present: custom-setup dependencies ,packageCabalSpec :: !CabalSpecVersion -- ^ Cabal spec range } deriving (Show,Typeable) packageIdent :: Package -> PackageIdentifier packageIdent p = PackageIdentifier (packageName p) (packageVersion p) packageIdentifier :: Package -> PackageIdentifier packageIdentifier pkg = PackageIdentifier (packageName pkg) (packageVersion pkg) packageDefinedFlags :: Package -> Set FlagName packageDefinedFlags = M.keysSet . packageDefaultFlags type InstallMap = Map PackageName (InstallLocation, Version) -- | Files that the package depends on, relative to package directory. -- Argument is the location of the Cabal file newtype GetPackageOpts = GetPackageOpts { getPackageOpts :: forall env. HasEnvConfig env => InstallMap -> InstalledMap -> [PackageName] -> [PackageName] -> Path Abs File -> RIO env (Map NamedComponent (Map ModuleName (Path Abs File)) ,Map NamedComponent [DotCabalPath] ,Map NamedComponent BuildInfoOpts) } instance Show GetPackageOpts where show _ = "" -- | GHC options based on cabal information and ghc-options. data BuildInfoOpts = BuildInfoOpts { bioOpts :: [String] , bioOneWordOpts :: [String] , bioPackageFlags :: [String] -- ^ These options can safely have 'nubOrd' applied to them, as -- there are no multi-word options (see -- https://github.com/commercialhaskell/stack/issues/1255) , bioCabalMacros :: Path Abs File } deriving Show -- | Package build configuration data PackageConfig = PackageConfig {packageConfigEnableTests :: !Bool -- ^ Are tests enabled? ,packageConfigEnableBenchmarks :: !Bool -- ^ Are benchmarks enabled? ,packageConfigFlags :: !(Map FlagName Bool) -- ^ Configured flags. ,packageConfigGhcOptions :: ![Text] -- ^ Configured ghc options. ,packageConfigCabalConfigOpts :: ![Text] -- ^ ./Setup.hs configure options ,packageConfigCompilerVersion :: ActualCompiler -- ^ GHC version ,packageConfigPlatform :: !Platform -- ^ host platform } deriving (Show,Typeable) -- | Compares the package name. instance Ord Package where compare = on compare packageName -- | Compares the package name. instance Eq Package where (==) = on (==) packageName -- | Where the package's source is located: local directory or package index data PackageSource = PSFilePath LocalPackage -- ^ Package which exist on the filesystem | PSRemote PackageLocationImmutable Version FromSnapshot CommonPackage -- ^ Package which is downloaded remotely. instance Show PackageSource where show (PSFilePath lp) = concat ["PSFilePath (", show lp, ")"] show (PSRemote pli v fromSnapshot _) = concat [ "PSRemote" , "(", show pli, ")" , "(", show v, ")" , show fromSnapshot , "" ] psVersion :: PackageSource -> Version psVersion (PSFilePath lp) = packageVersion $ lpPackage lp psVersion (PSRemote _ v _ _) = v -- | Information on a locally available package of source code data LocalPackage = LocalPackage { lpPackage :: !Package -- ^ The @Package@ info itself, after resolution with package flags, -- with tests and benchmarks disabled , lpComponents :: !(Set NamedComponent) -- ^ Components to build, not including the library component. , lpUnbuildable :: !(Set NamedComponent) -- ^ Components explicitly requested for build, that are marked -- "buildable: false". , lpWanted :: !Bool -- FIXME Should completely drop this "wanted" terminology, it's unclear -- ^ Whether this package is wanted as a target. , lpTestBench :: !(Maybe Package) -- ^ This stores the 'Package' with tests and benchmarks enabled, if -- either is asked for by the user. , lpCabalFile :: !(Path Abs File) -- ^ The Cabal file , lpBuildHaddocks :: !Bool , lpForceDirty :: !Bool , lpDirtyFiles :: !(MemoizedWith EnvConfig (Maybe (Set FilePath))) -- ^ Nothing == not dirty, Just == dirty. Note that the Set may be empty if -- we forced the build to treat packages as dirty. Also, the Set may not -- include all modified files. , lpNewBuildCaches :: !(MemoizedWith EnvConfig (Map NamedComponent (Map FilePath FileCacheInfo))) -- ^ current state of the files , lpComponentFiles :: !(MemoizedWith EnvConfig (Map NamedComponent (Set (Path Abs File)))) -- ^ all files used by this package } deriving Show newtype MemoizedWith env a = MemoizedWith { unMemoizedWith :: RIO env a } deriving (Functor, Applicative, Monad) memoizeRefWith :: MonadIO m => RIO env a -> m (MemoizedWith env a) memoizeRefWith action = do ref <- newIORef Nothing pure $ MemoizedWith $ do mres <- readIORef ref res <- case mres of Just res -> pure res Nothing -> do res <- tryAny action writeIORef ref $ Just res pure res either throwIO pure res runMemoizedWith :: (HasEnvConfig env, MonadReader env m, MonadIO m) => MemoizedWith EnvConfig a -> m a runMemoizedWith (MemoizedWith action) = do envConfig <- view envConfigL runRIO envConfig action instance Show (MemoizedWith env a) where show _ = "<>" lpFiles :: HasEnvConfig env => LocalPackage -> RIO env (Set.Set (Path Abs File)) lpFiles = runMemoizedWith . fmap (Set.unions . M.elems) . lpComponentFiles lpFilesForComponents :: HasEnvConfig env => Set NamedComponent -> LocalPackage -> RIO env (Set.Set (Path Abs File)) lpFilesForComponents components lp = runMemoizedWith $ do componentFiles <- lpComponentFiles lp pure $ mconcat (M.elems (M.restrictKeys componentFiles components)) -- | A location to install a package into, either snapshot or local data InstallLocation = Snap | Local deriving (Show, Eq) instance Semigroup InstallLocation where Local <> _ = Local _ <> Local = Local Snap <> Snap = Snap instance Monoid InstallLocation where mempty = Snap mappend = (<>) data InstalledPackageLocation = InstalledTo InstallLocation | ExtraGlobal deriving (Show, Eq) newtype FileCacheInfo = FileCacheInfo { fciHash :: SHA256 } deriving (Generic, Show, Eq, Typeable) instance NFData FileCacheInfo -- Provided for storing the BuildCache values in a file. But maybe -- JSON/YAML isn't the right choice here, worth considering. instance ToJSON FileCacheInfo where toJSON (FileCacheInfo hash') = object [ "hash" .= hash' ] instance FromJSON FileCacheInfo where parseJSON = withObject "FileCacheInfo" $ \o -> FileCacheInfo <$> o .: "hash" -- | Maybe get the module name from the .cabal descriptor. dotCabalModule :: DotCabalDescriptor -> Maybe ModuleName dotCabalModule (DotCabalModule m) = Just m dotCabalModule _ = Nothing -- | Maybe get the main name from the .cabal descriptor. dotCabalMain :: DotCabalDescriptor -> Maybe FilePath dotCabalMain (DotCabalMain m) = Just m dotCabalMain _ = Nothing -- | Get the module path. dotCabalModulePath :: DotCabalPath -> Maybe (Path Abs File) dotCabalModulePath (DotCabalModulePath fp) = Just fp dotCabalModulePath _ = Nothing -- | Get the main path. dotCabalMainPath :: DotCabalPath -> Maybe (Path Abs File) dotCabalMainPath (DotCabalMainPath fp) = Just fp dotCabalMainPath _ = Nothing -- | Get the c file path. dotCabalCFilePath :: DotCabalPath -> Maybe (Path Abs File) dotCabalCFilePath (DotCabalCFilePath fp) = Just fp dotCabalCFilePath _ = Nothing -- | Get the path. dotCabalGetPath :: DotCabalPath -> Path Abs File dotCabalGetPath dcp = case dcp of DotCabalModulePath fp -> fp DotCabalMainPath fp -> fp DotCabalFilePath fp -> fp DotCabalCFilePath fp -> fp type InstalledMap = Map PackageName (InstallLocation, Installed) data Installed = Library PackageIdentifier GhcPkgId (Maybe (Either SPDX.License License)) | Executable PackageIdentifier deriving (Show, Eq) installedPackageIdentifier :: Installed -> PackageIdentifier installedPackageIdentifier (Library pid _ _) = pid installedPackageIdentifier (Executable pid) = pid -- | Get the installed Version. installedVersion :: Installed -> Version installedVersion i = let PackageIdentifier _ version = installedPackageIdentifier i in version stack-2.9.3.1/src/Stack/Types/PackageName.hs0000644000000000000000000000171214445022466016617 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleInstances #-} -- | Names for packages. module Stack.Types.PackageName ( packageNameArgument ) where import Stack.Prelude import qualified Options.Applicative as O -- | An argument which accepts a template name of the format -- @foo.hsfiles@. packageNameArgument :: O.Mod O.ArgumentFields PackageName -> O.Parser PackageName packageNameArgument = O.argument (do s <- O.str either O.readerError pure (p s)) where p s = case parsePackageName s of Just x -> Right x Nothing -> Left $ unlines [ "Expected valid package name, but got: " ++ s , "Package names consist of one or more alphanumeric words separated by hyphens." , "To avoid ambiguity with version numbers, each of these words must contain at least one letter." ] stack-2.9.3.1/src/Stack/Types/Resolver.hs0000644000000000000000000000776014445022466016275 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} module Stack.Types.Resolver ( AbstractResolver (..) , readAbstractResolver , Snapshots (..) ) where import qualified Data.Aeson.Key as Key import qualified Data.Aeson.KeyMap as KeyMap import qualified Data.IntMap.Strict as IntMap import qualified Data.Text as T import Data.Text.Read ( decimal ) import Data.Time ( Day ) import Options.Applicative ( ReadM ) import qualified Options.Applicative.Types as OA import Pantry.Internal.AesonExtended ( FromJSON, parseJSON, withObject, (.:), withText ) import Stack.Prelude -- | Type representing exceptions thrown by functions exported by the -- "Stack.Types.Resolver" module. data TypesResolverException = ParseResolverException !Text | FilepathInDownloadedSnapshot !Text deriving (Show, Typeable) instance Exception TypesResolverException where displayException (ParseResolverException t) = concat [ "Error: [S-8787]\n" , "Invalid resolver value: " , T.unpack t , ". Possible valid values include lts-2.12, nightly-YYYY-MM-DD, \ \ghc-7.10.2, and ghcjs-0.1.0_ghc-7.10.2. See \ \https://www.stackage.org/snapshots for a complete list." ] displayException (FilepathInDownloadedSnapshot url) = unlines [ "Error: [S-4865]" , "Downloaded snapshot specified a 'resolver: { location: filepath }' " , "field, but filepaths are not allowed in downloaded snapshots.\n" , "Filepath specified: " ++ T.unpack url ] -- | Either an actual resolver value, or an abstract description of one (e.g., -- latest nightly). data AbstractResolver = ARLatestNightly | ARLatestLTS | ARLatestLTSMajor !Int | ARResolver !RawSnapshotLocation | ARGlobal instance Show AbstractResolver where show = T.unpack . utf8BuilderToText . display instance Display AbstractResolver where display ARLatestNightly = "nightly" display ARLatestLTS = "lts" display (ARLatestLTSMajor x) = "lts-" <> display x display (ARResolver usl) = display usl display ARGlobal = "global" readAbstractResolver :: ReadM (Unresolved AbstractResolver) readAbstractResolver = do s <- OA.readerAsk case s of "global" -> pure $ pure ARGlobal "nightly" -> pure $ pure ARLatestNightly "lts" -> pure $ pure ARLatestLTS 'l':'t':'s':'-':x | Right (x', "") <- decimal $ T.pack x -> pure $ pure $ ARLatestLTSMajor x' _ -> pure $ ARResolver <$> parseRawSnapshotLocation (T.pack s) -- | Most recent Nightly and newest LTS version per major release. data Snapshots = Snapshots { snapshotsNightly :: !Day , snapshotsLts :: !(IntMap Int) } deriving Show instance FromJSON Snapshots where parseJSON = withObject "Snapshots" $ \o -> Snapshots <$> (o .: "nightly" >>= parseNightly) <*> fmap IntMap.unions (mapM (parseLTS . snd) $ filter (isLTS . Key.toText . fst) $ KeyMap.toList o) where parseNightly t = case parseSnapName t of Left e -> fail $ displayException e Right (LTS _ _) -> fail "Unexpected LTS value" Right (Nightly d) -> pure d isLTS = ("lts-" `T.isPrefixOf`) parseLTS = withText "LTS" $ \t -> case parseSnapName t of Left e -> fail $ displayException e Right (LTS x y) -> pure $ IntMap.singleton x y Right (Nightly _) -> fail "Unexpected nightly value" stack-2.9.3.1/src/Stack/Types/SourceMap.hs0000644000000000000000000001345114445022466016364 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} -- | A sourcemap maps a package name to how it should be built, -- including source code, flags, options, etc. This module contains -- various stages of source map construction. See the -- @build_overview.md@ doc for details on these stages. module Stack.Types.SourceMap ( -- * Different source map types SMWanted (..) , SMActual (..) , Target (..) , PackageType (..) , SMTargets (..) , SourceMap (..) -- * Helper types , FromSnapshot (..) , DepPackage (..) , ProjectPackage (..) , CommonPackage (..) , GlobalPackageVersion (..) , GlobalPackage (..) , isReplacedGlobal , SourceMapHash (..) , smRelDir ) where import qualified Data.Text as T import Distribution.PackageDescription ( GenericPackageDescription ) import qualified Pantry.SHA256 as SHA256 import Path import Stack.Prelude import Stack.Types.Compiler import Stack.Types.NamedComponent -- | Common settings for both dependency and project package. data CommonPackage = CommonPackage { cpGPD :: !(IO GenericPackageDescription) , cpName :: !PackageName , cpFlags :: !(Map FlagName Bool) -- ^ overrides default flags , cpGhcOptions :: ![Text] -- also lets us know if we're doing profiling , cpCabalConfigOpts :: ![Text] , cpHaddocks :: !Bool } -- | Flag showing if package comes from a snapshot -- needed to ignore dependency bounds between such packages data FromSnapshot = FromSnapshot | NotFromSnapshot deriving (Show) -- | A view of a dependency package, specified in stack.yaml data DepPackage = DepPackage { dpCommon :: !CommonPackage , dpLocation :: !PackageLocation , dpHidden :: !Bool -- ^ Should the package be hidden after registering? -- Affects the script interpreter's module name import parser. , dpFromSnapshot :: !FromSnapshot -- ^ Needed to ignore bounds between snapshot packages -- See https://github.com/commercialhaskell/stackage/issues/3185 } -- | A view of a project package needed for resolving components data ProjectPackage = ProjectPackage { ppCommon :: !CommonPackage , ppCabalFP :: !(Path Abs File) , ppResolvedDir :: !(ResolvedPath Dir) } -- | A view of a package installed in the global package database also -- could include marker for a replaced global package (could be replaced -- because of a replaced dependency) data GlobalPackage = GlobalPackage !Version | ReplacedGlobalPackage ![PackageName] deriving Eq isReplacedGlobal :: GlobalPackage -> Bool isReplacedGlobal (ReplacedGlobalPackage _) = True isReplacedGlobal (GlobalPackage _) = False -- | A source map with information on the wanted (but not actual) -- compiler. This is derived by parsing the @stack.yaml@ file for -- @packages@, @extra-deps@, their configuration (e.g., flags and -- options), and parsing the snapshot it refers to. It does not -- include global packages or any information from the command line. -- -- Invariant: a @PackageName@ appears in either 'smwProject' or -- 'smwDeps', but not both. data SMWanted = SMWanted { smwCompiler :: !WantedCompiler , smwProject :: !(Map PackageName ProjectPackage) , smwDeps :: !(Map PackageName DepPackage) , smwSnapshotLocation :: !RawSnapshotLocation -- ^ Where this snapshot is loaded from. } -- | Adds in actual compiler information to 'SMWanted', in particular -- the contents of the global package database. -- -- Invariant: a @PackageName@ appears in only one of the @Map@s. data SMActual global = SMActual { smaCompiler :: !ActualCompiler , smaProject :: !(Map PackageName ProjectPackage) , smaDeps :: !(Map PackageName DepPackage) , smaGlobal :: !(Map PackageName global) } newtype GlobalPackageVersion = GlobalPackageVersion Version -- | How a package is intended to be built data Target = TargetAll !PackageType -- ^ Build all of the default components. | TargetComps !(Set NamedComponent) -- ^ Only build specific components data PackageType = PTProject | PTDependency deriving (Eq, Show) -- | Builds on an 'SMActual' by resolving the targets specified on the -- command line, potentially adding in new dependency packages in the -- process. data SMTargets = SMTargets { smtTargets :: !(Map PackageName Target) , smtDeps :: !(Map PackageName DepPackage) } -- | The final source map, taking an 'SMTargets' and applying all -- command line flags and GHC options. data SourceMap = SourceMap { smTargets :: !SMTargets -- ^ Doesn't need to be included in the hash, does not affect the -- source map. , smCompiler :: !ActualCompiler -- ^ Need to hash the compiler version _and_ its installation -- path. Ideally there would be some kind of output from GHC -- telling us some unique ID for the compiler itself. , smProject :: !(Map PackageName ProjectPackage) -- ^ Doesn't need to be included in hash, doesn't affect any of -- the packages that get stored in the snapshot database. , smDeps :: !(Map PackageName DepPackage) -- ^ Need to hash all of the immutable dependencies, can ignore -- the mutable dependencies. , smGlobal :: !(Map PackageName GlobalPackage) -- ^ Doesn't actually need to be hashed, implicitly captured by -- smCompiler. Can be broken if someone installs new global -- packages. We can document that as not supported, _or_ we could -- actually include all of this in the hash and make Stack more -- resilient. } -- | A unique hash for the immutable portions of a 'SourceMap'. newtype SourceMapHash = SourceMapHash SHA256 -- | Returns relative directory name with source map's hash smRelDir :: (MonadThrow m) => SourceMapHash -> m (Path Rel Dir) smRelDir (SourceMapHash smh) = parseRelDir $ T.unpack $ SHA256.toHexText smh stack-2.9.3.1/src/Stack/Types/TemplateName.hs0000644000000000000000000001336014445022466017041 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} -- | Template name handling. module Stack.Types.TemplateName ( TemplateName , RepoTemplatePath (..) , RepoService (..) , TemplatePath (..) , templateName , templatePath , parseTemplateNameFromString , parseRepoPathWithService , templateNameArgument , templateParamArgument , defaultTemplateName ) where import Data.Aeson ( FromJSON (..), withText ) import qualified Data.Text as T import Network.HTTP.StackClient ( parseRequest ) import qualified Options.Applicative as O import Path import Stack.Prelude -- | Type representing exceptions thrown by functions exported by the -- "Stack.Types.TemplateName" module. newtype TypeTemplateNameException = DefaultTemplateNameNotParsedBug String deriving (Show, Typeable) instance Exception TypeTemplateNameException where displayException (DefaultTemplateNameNotParsedBug s) = bugReport "[S-7410]" $ "The impossible happened! Cannot parse default template name: " ++ s -- | A template name. data TemplateName = TemplateName !Text !TemplatePath deriving (Ord,Eq,Show) data TemplatePath = AbsPath (Path Abs File) -- ^ an absolute path on the filesystem | RelPath String (Path Rel File) -- ^ a relative path on the filesystem, or relative to -- the template repository. To avoid path separator conversion -- on Windows, the raw command-line parameter passed is also -- given as the first field (possibly with @.hsfiles@ appended). | UrlPath String -- ^ a full URL | RepoPath RepoTemplatePath deriving (Eq, Ord, Show) -- | Details for how to access a template from a remote repo. data RepoTemplatePath = RepoTemplatePath { rtpService :: RepoService , rtpUser :: Text , rtpTemplate :: Text } deriving (Eq, Ord, Show) -- | Services from which templates can be retrieved from a repository. data RepoService = GitHub | GitLab | Bitbucket deriving (Eq, Ord, Show) instance FromJSON TemplateName where parseJSON = withText "TemplateName" $ either fail pure . parseTemplateNameFromString . T.unpack -- | An argument which accepts a template name of the format -- @foo.hsfiles@ or @foo@, ultimately normalized to @foo@. templateNameArgument :: O.Mod O.ArgumentFields TemplateName -> O.Parser TemplateName templateNameArgument = O.argument (do s <- O.str either O.readerError pure (parseTemplateNameFromString s)) -- | An argument which accepts a @key:value@ pair for specifying parameters. templateParamArgument :: O.Mod O.OptionFields (Text,Text) -> O.Parser (Text,Text) templateParamArgument = O.option (do s <- O.str either O.readerError pure (parsePair s)) where parsePair :: String -> Either String (Text, Text) parsePair s = case break (==':') s of (key,':':value@(_:_)) -> Right (T.pack key, T.pack value) _ -> Left ("Expected key:value format for argument: " <> s) -- | Parse a template name from a string. parseTemplateNameFromString :: String -> Either String TemplateName parseTemplateNameFromString fname = case T.stripSuffix ".hsfiles" (T.pack fname) of Nothing -> parseValidFile (T.pack fname) (fname <> ".hsfiles") fname Just prefix -> parseValidFile prefix fname fname where parseValidFile prefix hsf orig = maybe (Left expected) Right $ asum (validParses prefix hsf orig) validParses prefix hsf orig = -- NOTE: order is important [ TemplateName prefix . RepoPath <$> parseRepoPath hsf , TemplateName (T.pack orig) . UrlPath <$> (parseRequest orig *> Just orig) , TemplateName prefix . AbsPath <$> parseAbsFile hsf , TemplateName prefix . RelPath hsf <$> parseRelFile hsf ] expected = "Expected a template like: foo or foo.hsfiles or\ \ https://example.com/foo.hsfiles or github:user/foo" -- | The default template name you can use if you don't have one. defaultTemplateName :: TemplateName defaultTemplateName = case parseTemplateNameFromString "new-template" of Left s -> impureThrow $ DefaultTemplateNameNotParsedBug s Right x -> x -- | Get a text representation of the template name. templateName :: TemplateName -> Text templateName (TemplateName prefix _) = prefix -- | Get the path of the template. templatePath :: TemplateName -> TemplatePath templatePath (TemplateName _ fp) = fp defaultRepoUserForService :: RepoService -> Maybe Text defaultRepoUserForService GitHub = Just "commercialhaskell" defaultRepoUserForService _ = Nothing -- | Parses a template path of the form @github:user/template@. parseRepoPath :: String -> Maybe RepoTemplatePath parseRepoPath s = case T.splitOn ":" (T.pack s) of ["github" , rest] -> parseRepoPathWithService GitHub rest ["gitlab" , rest] -> parseRepoPathWithService GitLab rest ["bitbucket" , rest] -> parseRepoPathWithService Bitbucket rest _ -> Nothing -- | Parses a template path of the form @user/template@, given a service parseRepoPathWithService :: RepoService -> Text -> Maybe RepoTemplatePath parseRepoPathWithService service path = case T.splitOn "/" path of [user, name] -> Just $ RepoTemplatePath service user name [name] -> do repoUser <- defaultRepoUserForService service Just $ RepoTemplatePath service repoUser name _ -> Nothing stack-2.9.3.1/src/Stack/Types/Version.hs0000644000000000000000000001125314445022466016111 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} -- | Versions for packages. module Stack.Types.Version ( Cabal.VersionRange -- TODO in the future should have a newtype wrapper , IntersectingVersionRange (..) , VersionCheck (..) , versionRangeText , Cabal.withinRange , Stack.Types.Version.intersectVersionRanges , toMajorVersion , latestApplicableVersion , checkVersion , nextMajorVersion , minorVersion , stackVersion , showStackVersion , stackMajorVersion , stackMinorVersion ) where import Data.List ( find ) import qualified Data.Set as Set import qualified Data.Text as T import Data.Version ( showVersion ) import Distribution.Pretty ( pretty ) import qualified Distribution.Version as Cabal import Pantry.Internal.AesonExtended ( FromJSON (..), ToJSON (..), Value (..), withText ) import qualified Paths_stack as Meta import Stack.Prelude hiding ( Vector, pretty ) import Text.PrettyPrint ( render ) newtype IntersectingVersionRange = IntersectingVersionRange { getIntersectingVersionRange :: Cabal.VersionRange } deriving Show instance Semigroup IntersectingVersionRange where IntersectingVersionRange l <> IntersectingVersionRange r = IntersectingVersionRange (l `Cabal.intersectVersionRanges` r) instance Monoid IntersectingVersionRange where mempty = IntersectingVersionRange Cabal.anyVersion mappend = (<>) -- | Display a version range versionRangeText :: Cabal.VersionRange -> Text versionRangeText = T.pack . render . pretty -- | A modified intersection which also simplifies, for better display. intersectVersionRanges :: Cabal.VersionRange -> Cabal.VersionRange -> Cabal.VersionRange intersectVersionRanges x y = Cabal.simplifyVersionRange $ Cabal.intersectVersionRanges x y -- | Returns the first two components, defaulting to 0 if not present toMajorVersion :: Version -> Version toMajorVersion v = case Cabal.versionNumbers v of [] -> Cabal.mkVersion [0, 0] [a] -> Cabal.mkVersion [a, 0] a:b:_ -> Cabal.mkVersion [a, b] -- | Given a version range and a set of versions, find the latest version from -- the set that is within the range. latestApplicableVersion :: Cabal.VersionRange -> Set Version -> Maybe Version latestApplicableVersion r = find (`Cabal.withinRange` r) . Set.toDescList -- | Get the next major version number for the given version nextMajorVersion :: Version -> Version nextMajorVersion v = case Cabal.versionNumbers v of [] -> Cabal.mkVersion [0, 1] [a] -> Cabal.mkVersion [a, 1] a:b:_ -> Cabal.mkVersion [a, b + 1] data VersionCheck = MatchMinor | MatchExact | NewerMinor deriving (Eq, Ord, Show) instance ToJSON VersionCheck where toJSON MatchMinor = String "match-minor" toJSON MatchExact = String "match-exact" toJSON NewerMinor = String "newer-minor" instance FromJSON VersionCheck where parseJSON = withText expected $ \t -> case t of "match-minor" -> pure MatchMinor "match-exact" -> pure MatchExact "newer-minor" -> pure NewerMinor _ -> fail ("Expected " ++ expected ++ ", but got " ++ show t) where expected = "VersionCheck value (match-minor, match-exact, or newer-minor)" checkVersion :: VersionCheck -> Version -> Version -> Bool checkVersion check (Cabal.versionNumbers -> wanted) (Cabal.versionNumbers -> actual) = case check of MatchMinor -> and (take 3 matching) MatchExact -> length wanted == length actual && and matching NewerMinor -> and (take 2 matching) && newerMinor where matching = zipWith (==) wanted actual getMinor (_a:_b:c:_) = Just c getMinor _ = Nothing newerMinor = case (getMinor wanted, getMinor actual) of (Nothing, _) -> True (Just _, Nothing) -> False (Just w, Just a) -> a >= w -- | Get minor version (excludes any patchlevel) minorVersion :: Version -> Version minorVersion = Cabal.mkVersion . take 3 . Cabal.versionNumbers -- | Current Stack version stackVersion :: Version stackVersion = Cabal.mkVersion' Meta.version -- | Current Stack version in the same format as yielded by -- 'Data.Version.showVersion'. showStackVersion :: String showStackVersion = showVersion Meta.version -- | Current Stack minor version (excludes patchlevel) stackMinorVersion :: Version stackMinorVersion = minorVersion stackVersion -- | Current Stack major version. Returns the first two components, defaulting -- to 0 if not present stackMajorVersion :: Version stackMajorVersion = toMajorVersion stackVersion stack-2.9.3.1/src/Stack/Unpack.hs0000644000000000000000000001132214445022466014576 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Stack.Unpack ( unpackPackages ) where import Path ( (), parseRelDir ) import Path.IO ( doesDirExist ) import RIO.List ( intercalate ) import qualified RIO.Map as Map import RIO.Process ( HasProcessContext ) import qualified RIO.Set as Set import qualified RIO.Text as T import Stack.Prelude -- | Type representing exceptions thrown by functions exported by the -- "Stack.Unpack" module. data UnpackException = UnpackDirectoryAlreadyExists (Set (Path Abs Dir)) | CouldNotParsePackageSelectors [String] deriving (Show, Typeable) instance Exception UnpackException where displayException (UnpackDirectoryAlreadyExists dirs) = unlines $ "Error: [S-3515]" : "Unable to unpack due to already present directories:" : map ((" " ++) . toFilePath) (Set.toList dirs) displayException (CouldNotParsePackageSelectors strs) = unlines $ "Error: [S-2628]" : "The following package selectors are not valid package names or \ \identifiers:" : map ("- " ++) strs -- | Intended to work for the command line command. unpackPackages :: forall env. (HasPantryConfig env, HasLogFunc env, HasProcessContext env) => Maybe RawSnapshot -- ^ when looking up by name, take from this build plan -> Path Abs Dir -- ^ destination -> [String] -- ^ names or identifiers -> RIO env () unpackPackages mSnapshot dest input = do let (errs1, (names, pirs1)) = fmap partitionEithers $ partitionEithers $ map parse input locs1 <- forM pirs1 $ \pir -> do loc <- fmap cplComplete $ completePackageLocation $ RPLIHackage pir Nothing pure (loc, packageLocationIdent loc) (errs2, locs2) <- partitionEithers <$> traverse toLoc names case errs1 ++ errs2 of [] -> pure () errs -> throwM $ CouldNotParsePackageSelectors errs locs <- Map.fromList <$> mapM (\(pir, ident) -> do suffix <- parseRelDir $ packageIdentifierString ident pure (pir, dest suffix) ) (locs1 ++ locs2) alreadyUnpacked <- filterM doesDirExist $ Map.elems locs unless (null alreadyUnpacked) $ throwM $ UnpackDirectoryAlreadyExists $ Set.fromList alreadyUnpacked forM_ (Map.toList locs) $ \(loc, dest') -> do unpackPackageLocation dest' loc logInfo $ "Unpacked " <> display loc <> " to " <> fromString (toFilePath dest') where toLoc | Just snapshot <- mSnapshot = toLocSnapshot snapshot | otherwise = toLocNoSnapshot toLocNoSnapshot :: PackageName -> RIO env (Either String (PackageLocationImmutable, PackageIdentifier)) toLocNoSnapshot name = do mloc1 <- getLatestHackageLocation YesRequireHackageIndex name UsePreferredVersions mloc <- case mloc1 of Just _ -> pure mloc1 Nothing -> do updated <- updateHackageIndex $ Just $ "Could not find package " <> fromString (packageNameString name) <> ", updating" case updated of UpdateOccurred -> getLatestHackageLocation YesRequireHackageIndex name UsePreferredVersions NoUpdateOccurred -> pure Nothing case mloc of Nothing -> do candidates <- getHackageTypoCorrections name pure $ Left $ concat [ "Could not find package " , packageNameString name , " on Hackage" , if null candidates then "" else ". Perhaps you meant: " ++ intercalate ", " (map packageNameString candidates) ] Just loc -> pure $ Right (loc, packageLocationIdent loc) toLocSnapshot :: RawSnapshot -> PackageName -> RIO env (Either String (PackageLocationImmutable, PackageIdentifier)) toLocSnapshot snapshot name = case Map.lookup name (rsPackages snapshot) of Nothing -> pure $ Left $ "Package does not appear in snapshot: " ++ packageNameString name Just sp -> do loc <- cplComplete <$> completePackageLocation (rspLocation sp) pure $ Right (loc, packageLocationIdent loc) -- Possible future enhancement: parse names as name + version range parse s = case parsePackageName (T.unpack t) of Just x -> Right $ Left x Nothing -> case parsePackageIdentifierRevision t of Right x -> Right $ Right x Left _ -> Left $ "Could not parse as package name or identifier: " ++ s where t = T.pack s stack-2.9.3.1/src/Stack/Upgrade.hs0000644000000000000000000002622114445022466014750 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Upgrade ( upgrade , UpgradeOpts , upgradeOpts ) where import qualified Data.Text as T import Options.Applicative import Path import RIO.Process import Stack.Build import Stack.Build.Target ( NeedTargets (..) ) import Stack.Constants import Stack.Prelude hiding ( force, Display (..) ) import Stack.Runners import Stack.Setup import Stack.Types.Config import System.Console.ANSI ( hSupportsANSIWithoutEmulation ) import System.Process ( rawSystem, readProcess ) -- | Type representing exceptions thrown by functions exported by the -- "Stack.Upgrade" module. data UpgradeException = NeitherBinaryOrSourceSpecified | ExecutableFailure | CommitsNotFound String String | StackInPackageIndexNotFound | VersionWithNoRevision deriving (Show, Typeable) instance Exception UpgradeException where displayException NeitherBinaryOrSourceSpecified = "Error: [S-3642]\n" ++ "You must allow either binary or source upgrade paths." displayException ExecutableFailure = "Error: [S-8716]\n" ++ "Non-success exit code from running newly downloaded executable." displayException (CommitsNotFound branch repo) = concat [ "Error: [S-7114]\n" , "No commits found for branch " , branch , " on repo " , repo ] displayException StackInPackageIndexNotFound = "Error: [S-9668]\n" ++ "No Stack version found in package indices." displayException VersionWithNoRevision = "Error: [S-6648]\n" ++ "Latest version with no revision." upgradeOpts :: Parser UpgradeOpts upgradeOpts = UpgradeOpts <$> (sourceOnly <|> optional binaryOpts) <*> (binaryOnly <|> optional sourceOpts) where binaryOnly = flag' Nothing (long "binary-only" <> help "Do not use a source upgrade path") sourceOnly = flag' Nothing (long "source-only" <> help "Do not use a binary upgrade path") binaryOpts = BinaryOpts <$> optional (strOption ( long "binary-platform" <> help "Platform type for archive to download" <> showDefault)) <*> switch (long "force-download" <> help "Download the latest available Stack executable") <*> optional (strOption (long "binary-version" <> help "Download a specific Stack version")) <*> optional (strOption (long "github-org" <> help "GitHub organization name")) <*> optional (strOption (long "github-repo" <> help "GitHub repository name")) sourceOpts = SourceOpts <$> ((\fromGit repo branch -> if fromGit then Just (repo, branch) else Nothing) <$> switch ( long "git" <> help "Clone from Git instead of downloading from Hackage (more dangerous)" ) <*> strOption ( long "git-repo" <> help "Clone from specified git repository" <> value "https://github.com/commercialhaskell/stack" <> showDefault ) <*> strOption ( long "git-branch" <> help "Clone from this git branch" <> value "master" <> showDefault )) data BinaryOpts = BinaryOpts { _boPlatform :: !(Maybe String) , _boForce :: !Bool -- ^ force a download, even if the downloaded version is older -- than what we are , _boVersion :: !(Maybe String) -- ^ specific version to download , _boGitHubOrg :: !(Maybe String) , _boGitHubRepo :: !(Maybe String) } deriving Show newtype SourceOpts = SourceOpts (Maybe (String, String)) -- repo and branch deriving Show data UpgradeOpts = UpgradeOpts { _uoBinary :: !(Maybe BinaryOpts) , _uoSource :: !(Maybe SourceOpts) } deriving Show upgrade :: Maybe String -- ^ git hash at time of building, if known -> UpgradeOpts -> RIO Runner () upgrade builtHash (UpgradeOpts mbo mso) = case (mbo, mso) of -- FIXME It would be far nicer to capture this case in the -- options parser itself so we get better error messages, but -- I can't think of a way to make it happen. (Nothing, Nothing) -> throwIO NeitherBinaryOrSourceSpecified (Just bo, Nothing) -> binary bo (Nothing, Just so) -> source so -- See #2977 - if --git or --git-repo is specified, do source upgrade. (_, Just so@(SourceOpts (Just _))) -> source so (Just bo, Just so) -> binary bo `catchAny` \e -> do prettyWarnL [ flow "Exception occurred when trying to perform binary upgrade:" , fromString . show $ e , line <> flow "Falling back to source upgrade" ] source so where binary bo = binaryUpgrade bo source so = sourceUpgrade builtHash so binaryUpgrade :: BinaryOpts -> RIO Runner () binaryUpgrade (BinaryOpts mplatform force' mver morg mrepo) = withConfig NoReexec $ do platforms0 <- case mplatform of Nothing -> preferredPlatforms Just p -> pure [("windows" `T.isInfixOf` T.pack p, p)] archiveInfo <- downloadStackReleaseInfo morg mrepo mver let mdownloadVersion = getDownloadVersion archiveInfo force = case mver of Nothing -> force' Just _ -> True -- specifying a version implies we're forcing things isNewer <- case mdownloadVersion of Nothing -> do prettyErrorL $ flow "Unable to determine upstream version from GitHub metadata" : [ line <> flow "Rerun with --force-download to force an upgrade" | not force] pure False Just downloadVersion -> do prettyInfoL [ flow "Current Stack version:" , fromString (versionString stackVersion) <> "," , flow "available download version:" , fromString (versionString downloadVersion) ] pure $ downloadVersion > stackVersion toUpgrade <- case (force, isNewer) of (False, False) -> do prettyInfoS "Skipping binary upgrade, you are already running the most recent version" pure False (True, False) -> do prettyInfoS "Forcing binary upgrade" pure True (_, True) -> do prettyInfoS "Newer version detected, downloading" pure True when toUpgrade $ do config <- view configL downloadStackExe platforms0 archiveInfo (configLocalBin config) True $ \tmpFile -> do -- Sanity check! ec <- rawSystem (toFilePath tmpFile) ["--version"] unless (ec == ExitSuccess) (throwIO ExecutableFailure) sourceUpgrade :: Maybe String -> SourceOpts -> RIO Runner () sourceUpgrade builtHash (SourceOpts gitRepo) = withSystemTempDir "stack-upgrade" $ \tmp -> do mdir <- case gitRepo of Just (repo, branch) -> do remote <- liftIO $ System.Process.readProcess "git" ["ls-remote", repo, branch] [] latestCommit <- case words remote of [] -> throwIO $ CommitsNotFound branch repo x:_ -> pure x when (isNothing builtHash) $ prettyWarnS $ "Information about the commit this version of Stack was " <> "built from is not available due to how it was built. " <> "Will continue by assuming an upgrade is needed " <> "because we have no information to the contrary." if builtHash == Just latestCommit then do prettyInfoS "Already up-to-date, no upgrade required" pure Nothing else do prettyInfoS "Cloning stack" -- NOTE: "--recursive" was added after v1.0.0 (and before the -- next release). This means that we can't use submodules in -- the Stack repo until we're comfortable with "stack upgrade -- --git" not working for earlier versions. let args = [ "clone", repo , "stack", "--depth", "1", "--recursive", "--branch", branch] withWorkingDir (toFilePath tmp) $ proc "git" args runProcess_ -- On Windows 10, an upstream issue with the `git clone` command -- means that command clears, but does not then restore, the -- ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for native terminals. -- The following hack re-enables the lost ANSI-capability. when osIsWindows $ void $ liftIO $ hSupportsANSIWithoutEmulation stdout pure $ Just $ tmp relDirStackProgName -- We need to access the Pantry database to find out about the -- latest Stack available on Hackage. We first use a standard -- Config to do this, and once we have the source load up the -- stack.yaml from inside that source. Nothing -> withConfig NoReexec $ do void $ updateHackageIndex $ Just "Updating index to make sure we find the latest Stack version" mversion <- getLatestHackageVersion YesRequireHackageIndex "stack" UsePreferredVersions (PackageIdentifierRevision _ version _) <- case mversion of Nothing -> throwIO StackInPackageIndexNotFound Just version -> pure version if version <= stackVersion then do prettyInfoS "Already at latest version, no upgrade required" pure Nothing else do suffix <- parseRelDir $ "stack-" ++ versionString version let dir = tmp suffix mrev <- getLatestHackageRevision YesRequireHackageIndex "stack" version case mrev of Nothing -> throwIO VersionWithNoRevision Just (_rev, cfKey, treeKey) -> do let ident = PackageIdentifier "stack" version unpackPackageLocation dir $ PLIHackage ident cfKey treeKey pure $ Just dir let modifyGO dir go = go { globalResolver = Nothing -- always use the resolver settings in the stack.yaml file , globalStackYaml = SYLOverride $ dir stackDotYaml } boptsCLI = defaultBuildOptsCLI { boptsCLITargets = ["stack"] } forM_ mdir $ \dir -> local (over globalOptsL (modifyGO dir)) $ withConfig NoReexec $ withEnvConfig AllowNoTargets boptsCLI $ local (set (buildOptsL.buildOptsInstallExesL) True) $ build Nothing stack-2.9.3.1/src/Stack/Upload.hs0000644000000000000000000002611314445022466014605 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} -- | Provide ability to upload tarballs to Hackage. module Stack.Upload ( -- * Upload upload , uploadBytes , uploadRevision -- * Credentials , HackageCreds , HackageAuth (..) , HackageKey (..) , loadAuth , writeFilePrivate -- * Internal , maybeGetHackageKey ) where import Conduit ( mapOutput, sinkList ) import Data.Aeson ( FromJSON (..), ToJSON (..), decode', toEncoding , fromEncoding, object, withObject, (.:), (.=) ) import Data.ByteString.Builder ( lazyByteString ) import qualified Data.ByteString.Char8 as S import qualified Data.ByteString.Lazy as L import qualified Data.Conduit.Binary as CB import qualified Data.Text as T import Network.HTTP.StackClient ( Request, RequestBody (RequestBodyLBS), Response , withResponse, httpNoBody, getGlobalManager , getResponseStatusCode, getResponseBody, setRequestHeader , parseRequest, formDataBody, partFileRequestBody, partBS , partLBS, applyDigestAuth, displayDigestAuthException ) import Stack.Options.UploadParser import Stack.Prelude import Stack.Types.Config import System.Directory ( createDirectoryIfMissing, removeFile, renameFile ) import System.Environment ( lookupEnv ) import System.FilePath ( (), takeFileName, takeDirectory ) import System.PosixCompat.Files ( setFileMode ) -- | Type representing \'pretty\' exceptions thrown by functions exported by the -- "Stack.Upload" module. data UploadPrettyException = AuthenticationFailure | ArchiveUploadFailure Int [String] String deriving (Show, Typeable) instance Pretty UploadPrettyException where pretty AuthenticationFailure = "[S-2256]" <> line <> flow "authentification failure" <> line <> flow "Authentication failure uploading to server" pretty (ArchiveUploadFailure code res tarName) = "[S-6108]" <> line <> flow "unhandled status code:" <+> fromString (show code) <> line <> flow "Upload failed on" <+> style File (fromString tarName) <> line <> vsep (map string res) instance Exception UploadPrettyException newtype HackageKey = HackageKey Text deriving (Eq, Show) -- | Username and password to log into Hackage. -- -- Since 0.1.0.0 data HackageCreds = HackageCreds { hcUsername :: !Text , hcPassword :: !Text , hcCredsFile :: !FilePath } deriving (Eq, Show) data HackageAuth = HAKey HackageKey | HACreds HackageCreds deriving (Eq, Show) instance ToJSON HackageCreds where toJSON (HackageCreds u p _) = object [ "username" .= u , "password" .= p ] instance FromJSON (FilePath -> HackageCreds) where parseJSON = withObject "HackageCreds" $ \o -> HackageCreds <$> o .: "username" <*> o .: "password" withEnvVariable :: Text -> IO Text -> IO Text withEnvVariable varName fromPrompt = lookupEnv (T.unpack varName) >>= maybe fromPrompt (pure . T.pack) maybeGetHackageKey :: RIO m (Maybe HackageKey) maybeGetHackageKey = liftIO $ fmap (HackageKey . T.pack) <$> lookupEnv "HACKAGE_KEY" loadAuth :: HasLogFunc m => Config -> RIO m HackageAuth loadAuth config = do maybeHackageKey <- maybeGetHackageKey case maybeHackageKey of Just key -> do logInfo "HACKAGE_KEY found in env, using that for credentials." pure $ HAKey key Nothing -> HACreds <$> loadUserAndPassword config -- | Load Hackage credentials, either from a save file or the command -- line. -- -- Since 0.1.0.0 loadUserAndPassword :: HasLogFunc m => Config -> RIO m HackageCreds loadUserAndPassword config = do fp <- liftIO $ credsFile config elbs <- liftIO $ tryIO $ L.readFile fp case either (const Nothing) Just elbs >>= \lbs -> (lbs, ) <$> decode' lbs of Nothing -> fromPrompt fp Just (lbs, mkCreds) -> do -- Ensure privacy, for cleaning up old versions of Stack that -- didn't do this writeFilePrivate fp $ lazyByteString lbs unless (configSaveHackageCreds config) $ do logWarn "WARNING: You've set save-hackage-creds to false" logWarn "However, credentials were found at:" logWarn $ " " <> fromString fp pure $ mkCreds fp where fromPrompt :: HasLogFunc m => FilePath -> RIO m HackageCreds fromPrompt fp = do username <- liftIO $ withEnvVariable "HACKAGE_USERNAME" (prompt "Hackage username: ") password <- liftIO $ withEnvVariable "HACKAGE_PASSWORD" (promptPassword "Hackage password: ") let hc = HackageCreds { hcUsername = username , hcPassword = password , hcCredsFile = fp } when (configSaveHackageCreds config) $ do shouldSave <- promptBool $ T.pack $ "Save hackage credentials to file at " ++ fp ++ " [y/n]? " logInfo "NOTE: Avoid this prompt in the future by using: save-hackage-creds: false" when shouldSave $ do writeFilePrivate fp $ fromEncoding $ toEncoding hc logInfo "Saved!" hFlush stdout pure hc -- | Write contents to a file which is always private. -- -- For history of this function, see: -- -- * https://github.com/commercialhaskell/stack/issues/2159#issuecomment-477948928 -- -- * https://github.com/commercialhaskell/stack/pull/4665 writeFilePrivate :: MonadIO m => FilePath -> Builder -> m () writeFilePrivate fp builder = liftIO $ withTempFile (takeDirectory fp) (takeFileName fp) $ \fpTmp h -> do -- Temp file is created such that only current user can read and write it. -- See docs for openTempFile: https://www.stackage.org/haddock/lts-13.14/base-4.12.0.0/System-IO.html#v:openTempFile -- Write to the file and close the handle. hPutBuilder h builder hClose h -- Make sure the destination file, if present, is writeable void $ tryIO $ setFileMode fp 0o600 -- And atomically move renameFile fpTmp fp credsFile :: Config -> IO FilePath credsFile config = do let dir = toFilePath (view stackRootL config) "upload" createDirectoryIfMissing True dir pure $ dir "credentials.json" addAPIKey :: HackageKey -> Request -> Request addAPIKey (HackageKey key) req = setRequestHeader "Authorization" [fromString $ "X-ApiKey" ++ " " ++ T.unpack key] req applyAuth :: HasLogFunc m => HackageAuth -> Request -> RIO m Request applyAuth haAuth req0 = do case haAuth of HAKey key -> pure (addAPIKey key req0) HACreds creds -> applyCreds creds req0 applyCreds :: HasLogFunc m => HackageCreds -> Request -> RIO m Request applyCreds creds req0 = do manager <- liftIO getGlobalManager ereq <- liftIO $ applyDigestAuth (encodeUtf8 $ hcUsername creds) (encodeUtf8 $ hcPassword creds) req0 manager case ereq of Left e -> do logWarn "WARNING: No HTTP digest prompt found, this will probably fail" case fromException e of Just e' -> logWarn $ fromString $ displayDigestAuthException e' Nothing -> logWarn $ fromString $ displayException e pure req0 Right req -> pure req -- | Upload a single tarball with the given @Uploader@. Instead of -- sending a file like 'upload', this sends a lazy bytestring. -- -- Since 0.1.2.1 uploadBytes :: HasLogFunc m => String -- ^ Hackage base URL -> HackageAuth -> String -- ^ tar file name -> UploadVariant -> L.ByteString -- ^ tar file contents -> RIO m () uploadBytes baseUrl auth tarName uploadVariant bytes = do let req1 = setRequestHeader "Accept" ["text/plain"] (fromString $ baseUrl <> "packages/" <> case uploadVariant of Publishing -> "" Candidate -> "candidates/" ) formData = [partFileRequestBody "package" tarName (RequestBodyLBS bytes)] req2 <- liftIO $ formDataBody formData req1 req3 <- applyAuth auth req2 logInfo $ "Uploading " <> fromString tarName <> "... " hFlush stdout withRunInIO $ \runInIO -> withResponse req3 (runInIO . inner) where inner :: HasLogFunc m => Response (ConduitM () S.ByteString IO ()) -> RIO m () inner res = case getResponseStatusCode res of 200 -> logInfo "done!" 401 -> do case auth of HACreds creds -> handleIO (const $ pure ()) (liftIO $ removeFile (hcCredsFile creds)) _ -> pure () throwIO $ PrettyException AuthenticationFailure 403 -> do logError "Error: [S-2804]" logError "forbidden upload" logError "Usually means: you've already uploaded this package/version combination" logError "Ignoring error and continuing, full message from Hackage below:\n" liftIO $ printBody res 503 -> do logError "Error: [S-4444]" logError "service unavailable" logError "This error some times gets sent even though the upload succeeded" logError "Check on Hackage to see if your package is present" liftIO $ printBody res code -> do let resBody = mapOutput show (getResponseBody res) resBody' <- liftIO $ runConduit $ resBody .| sinkList throwIO $ PrettyException (ArchiveUploadFailure code resBody' tarName) printBody :: Response (ConduitM () S.ByteString IO ()) -> IO () printBody res = runConduit $ getResponseBody res .| CB.sinkHandle stdout -- | Upload a single tarball with the given @Uploader@. -- -- Since 0.1.0.0 upload :: HasLogFunc m => String -- ^ Hackage base URL -> HackageAuth -> FilePath -> UploadVariant -> RIO m () upload baseUrl auth fp uploadVariant = uploadBytes baseUrl auth (takeFileName fp) uploadVariant =<< liftIO (L.readFile fp) uploadRevision :: HasLogFunc m => String -- ^ Hackage base URL -> HackageAuth -> PackageIdentifier -> L.ByteString -> RIO m () uploadRevision baseUrl auth ident@(PackageIdentifier name _) cabalFile = do req0 <- parseRequest $ concat [ baseUrl , "package/" , packageIdentifierString ident , "/" , packageNameString name , ".cabal/edit" ] req1 <- formDataBody [ partLBS "cabalfile" cabalFile , partBS "publish" "on" ] req0 req2 <- applyAuth auth req1 void $ httpNoBody req2 stack-2.9.3.1/src/windows/System/Info/ShortPathName.hs0000644000000000000000000000016214445022466020676 0ustar0000000000000000module System.Info.ShortPathName ( getShortPathName ) where import System.Win32.Info (getShortPathName) stack-2.9.3.1/src/unix/System/Info/ShortPathName.hs0000644000000000000000000000041514445022466020170 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module System.Info.ShortPathName ( getShortPathName ) where import RIO.FilePath (FilePath) import RIO.Prelude (pure) import RIO.Prelude.Types (IO) getShortPathName :: FilePath -> IO FilePath getShortPathName = pure stack-2.9.3.1/src/windows/System/Permissions.hs0000644000000000000000000000051514445022466017603 0ustar0000000000000000module System.Permissions ( setScriptPerms , osIsWindows , setFileExecutable ) where -- | True if using Windows OS. osIsWindows :: Bool osIsWindows = True setScriptPerms :: Monad m => FilePath -> m () setScriptPerms _ = pure () setFileExecutable :: Monad m => FilePath -> m () setFileExecutable _ = pure () stack-2.9.3.1/src/unix/System/Permissions.hs0000644000000000000000000000125414445022466017075 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module System.Permissions ( setScriptPerms , osIsWindows , setFileExecutable ) where import qualified System.Posix.Files as Posix import RIO -- | True if using Windows OS. osIsWindows :: Bool osIsWindows = False setScriptPerms :: MonadIO m => FilePath -> m () setScriptPerms fp = do liftIO $ Posix.setFileMode fp $ Posix.ownerReadMode `Posix.unionFileModes` Posix.ownerWriteMode `Posix.unionFileModes` Posix.groupReadMode `Posix.unionFileModes` Posix.otherReadMode setFileExecutable :: MonadIO m => FilePath -> m () setFileExecutable fp = liftIO $ Posix.setFileMode fp 0o755 stack-2.9.3.1/src/System/Process/Pager.hs0000644000000000000000000000514414445022466016255 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Run external pagers (@$PAGER@, @less@, @more@). module System.Process.Pager ( pageWriter , pageText , PagerException (..) ) where import Control.Monad.Trans.Maybe ( MaybeT (runMaybeT, MaybeT) ) import qualified Data.Text.IO as T import Stack.Prelude import System.Directory ( findExecutable ) import System.Environment ( lookupEnv ) import System.Process ( createProcess, cmdspec, shell, proc, waitForProcess , CmdSpec (ShellCommand, RawCommand) , StdStream (CreatePipe) , CreateProcess (std_in, close_fds, delegate_ctlc) ) -- | Type representing exceptions thrown by functions exported by the -- "System.Process.Pager" module. data PagerException = PagerExitFailure CmdSpec Int deriving (Show, Typeable) instance Exception PagerException where displayException (PagerExitFailure cmd n) = let getStr (ShellCommand c) = c getStr (RawCommand exePath _) = exePath in concat [ "Error: [S-9392]\n" , "Pager (`" , getStr cmd , "') exited with non-zero status: " , show n ] -- | Run pager, providing a function that writes to the pager's input. pageWriter :: (Handle -> IO ()) -> IO () pageWriter writer = do mpager <- runMaybeT $ cmdspecFromEnvVar <|> cmdspecFromExeName "less" <|> cmdspecFromExeName "more" case mpager of Just pager -> do (Just h,_,_,procHandle) <- createProcess pager { std_in = CreatePipe , close_fds = True , delegate_ctlc = True } (_ :: Either IOException ()) <- try (do writer h hClose h) exit <- waitForProcess procHandle case exit of ExitSuccess -> pure () ExitFailure n -> throwIO (PagerExitFailure (cmdspec pager) n) pure () Nothing -> writer stdout where cmdspecFromEnvVar = shell <$> MaybeT (lookupEnv "PAGER") cmdspecFromExeName = fmap (\path -> proc path []) . MaybeT . findExecutable -- | Run pager to display a 'Text' pageText :: Text -> IO () pageText = pageWriter . flip T.hPutStr stack-2.9.3.1/src/windows/System/Terminal.hs0000644000000000000000000001067214445022466017050 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE OverloadedStrings #-} module System.Terminal ( fixCodePage , getTerminalWidth , hIsTerminalDeviceOrMinTTY ) where import Distribution.Types.Version (mkVersion) import Foreign.Ptr import Foreign.Storable import Foreign.Marshal.Alloc import Stack.Prelude import System.IO hiding (hIsTerminalDevice) import System.Process import System.Win32 (isMinTTYHandle, withHandleToHANDLE) import System.Win32.Console (setConsoleCP, setConsoleOutputCP, getConsoleCP, getConsoleOutputCP) import RIO.Partial (read) type HANDLE = Ptr () data CONSOLE_SCREEN_BUFFER_INFO sizeCONSOLE_SCREEN_BUFFER_INFO :: Int sizeCONSOLE_SCREEN_BUFFER_INFO = 22 posCONSOLE_SCREEN_BUFFER_INFO_srWindow :: Int posCONSOLE_SCREEN_BUFFER_INFO_srWindow = 10 -- 4 x Word16 Left,Top,Right,Bottom c_STD_OUTPUT_HANDLE :: Int c_STD_OUTPUT_HANDLE = -11 foreign import ccall unsafe "windows.h GetConsoleScreenBufferInfo" c_GetConsoleScreenBufferInfo :: HANDLE -> Ptr CONSOLE_SCREEN_BUFFER_INFO -> IO Bool foreign import ccall unsafe "windows.h GetStdHandle" c_GetStdHandle :: Int -> IO HANDLE getTerminalWidth :: IO (Maybe Int) getTerminalWidth = do hdl <- c_GetStdHandle c_STD_OUTPUT_HANDLE allocaBytes sizeCONSOLE_SCREEN_BUFFER_INFO $ \p -> do b <- c_GetConsoleScreenBufferInfo hdl p if not b then do -- This could happen on Cygwin or MSYS let stty = (shell "stty size") { std_in = UseHandle stdin , std_out = CreatePipe , std_err = CreatePipe } (_, mbStdout, _, rStty) <- createProcess stty exStty <- waitForProcess rStty case exStty of ExitFailure _ -> pure Nothing ExitSuccess -> maybe (pure Nothing) (\hSize -> do sizeStr <- hGetContents hSize case map read $ words sizeStr :: [Int] of [_r, c] -> pure $ Just c _ -> pure Nothing ) mbStdout else do [left,_top,right,_bottom] <- forM [0..3] $ \i -> do v <- peekByteOff p ((i*2) + posCONSOLE_SCREEN_BUFFER_INFO_srWindow) pure $ fromIntegral (v :: Word16) pure $ Just (1+right-left) -- | Set the code page for this process as necessary. Only applies to Windows. -- See: https://github.com/commercialhaskell/stack/issues/738 fixCodePage :: HasLogFunc env => Bool -- ^ modify code page? -> Version -- ^ GHC version -> RIO env a -> RIO env a fixCodePage mcp ghcVersion inner = do if mcp && ghcVersion < mkVersion [7, 10, 3] then fixCodePage' -- GHC >=7.10.3 doesn't need this code page hack. else inner where fixCodePage' = do origCPI <- liftIO getConsoleCP origCPO <- liftIO getConsoleOutputCP let setInput = origCPI /= expected setOutput = origCPO /= expected fixInput | setInput = bracket_ (liftIO $ do setConsoleCP expected) (liftIO $ setConsoleCP origCPI) | otherwise = id fixOutput | setOutput = bracket_ (liftIO $ do setConsoleOutputCP expected) (liftIO $ setConsoleOutputCP origCPO) | otherwise = id case (setInput, setOutput) of (False, False) -> pure () (True, True) -> warn "" (True, False) -> warn " input" (False, True) -> warn " output" fixInput $ fixOutput inner expected = 65001 -- UTF-8 warn typ = logInfo $ "Setting" <> typ <> " codepage to UTF-8 (65001) to ensure correct output from GHC" -- | hIsTerminaDevice does not recognise handles to mintty terminals as terminal -- devices, but isMinTTYHandle does. hIsTerminalDeviceOrMinTTY :: MonadIO m => Handle -> m Bool hIsTerminalDeviceOrMinTTY h = do isTD <- hIsTerminalDevice h if isTD then pure True else liftIO $ withHandleToHANDLE h isMinTTYHandle stack-2.9.3.1/src/unix/System/Terminal.hsc0000644000000000000000000000271114445022466016477 0ustar0000000000000000{-# LANGUAGE CApiFFI #-} {-# LANGUAGE ForeignFunctionInterface #-} module System.Terminal ( fixCodePage , getTerminalWidth , hIsTerminalDeviceOrMinTTY ) where import Foreign import Foreign.C.Types import RIO (MonadIO, Handle, hIsTerminalDevice) #include #include newtype WindowWidth = WindowWidth CUShort deriving (Eq, Ord, Show) instance Storable WindowWidth where sizeOf _ = (#size struct winsize) alignment _ = (#alignment struct winsize) peek p = WindowWidth <$> (#peek struct winsize, ws_col) p poke p (WindowWidth w) = do (#poke struct winsize, ws_col) p w -- `ioctl` is variadic, so `capi` is needed, see: -- https://www.haskell.org/ghc/blog/20210709-capi-usage.html foreign import capi "sys/ioctl.h ioctl" ioctl :: CInt -> CInt -> Ptr WindowWidth -> IO CInt getTerminalWidth :: IO (Maybe Int) getTerminalWidth = alloca $ \p -> do errno <- ioctl (#const STDOUT_FILENO) (#const TIOCGWINSZ) p if errno < 0 then return Nothing else do WindowWidth w <- peek p return . Just . fromIntegral $ w fixCodePage :: x -> y -> a -> a fixCodePage _ _ = id -- | hIsTerminaDevice does not recognise handles to mintty terminals as terminal -- devices, but isMinTTYHandle does. hIsTerminalDeviceOrMinTTY :: MonadIO m => Handle -> m Bool hIsTerminalDeviceOrMinTTY = hIsTerminalDevice stack-2.9.3.1/src/Path/Extended.hs0000644000000000000000000000104514445022466014745 0ustar0000000000000000module Path.Extended ( fileExtension , addExtension , replaceExtension ) where import Control.Monad.Catch import qualified Path import Path (Path, File) fileExtension :: MonadThrow m => Path b File -> m String fileExtension = Path.fileExtension addExtension :: MonadThrow m => String -> Path b File -> m (Path b File) addExtension = Path.addExtension replaceExtension :: MonadThrow m => String -> Path b File -> m (Path b File) replaceExtension ext = Path.replaceExtension ('.' : ext) stack-2.9.3.1/src/Stack/ComponentFile.hs0000644000000000000000000005075214445022466016131 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} -- | A module which exports all component-level file-gathering logic. It also -- includes utility functions for handling paths and directories. module Stack.ComponentFile ( resolveOrWarn , libraryFiles , executableFiles , testFiles , benchmarkFiles , componentOutputDir , componentBuildDir , packageAutogenDir , buildDir , componentAutogenDir ) where import Control.Exception ( throw ) import Data.List ( find, isPrefixOf ) import qualified Data.Map.Strict as M import qualified Data.Set as S import qualified Data.Text as T import Distribution.ModuleName ( ModuleName ) import qualified Distribution.ModuleName as Cabal import Distribution.Package hiding ( Module, Package, PackageIdentifier, packageName , packageVersion ) import Distribution.PackageDescription hiding ( FlagName ) import Distribution.Text ( display ) import Distribution.Utils.Path ( getSymbolicPath ) import Distribution.Version ( mkVersion ) import qualified HiFileParser as Iface import Path as FL hiding ( replaceExtension ) import Path.Extra import Path.IO hiding ( findFiles ) import Stack.Constants import Stack.Prelude hiding ( Display (..) ) import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.Package import Stack.Types.PackageFile ( GetPackageFileContext (..), DotCabalDescriptor (..) , DotCabalPath (..), PackageWarning (..) ) import qualified System.Directory as D ( doesFileExist ) import qualified System.FilePath as FilePath -- | Get all files referenced by the benchmark. benchmarkFiles :: NamedComponent -> Benchmark -> RIO GetPackageFileContext (Map ModuleName (Path Abs File), [DotCabalPath], [PackageWarning]) benchmarkFiles component bench = do resolveComponentFiles component build names where names = bnames <> exposed exposed = case benchmarkInterface bench of BenchmarkExeV10 _ fp -> [DotCabalMain fp] BenchmarkUnsupported _ -> [] bnames = map DotCabalModule (otherModules build) build = benchmarkBuildInfo bench -- | Get all files referenced by the test. testFiles :: NamedComponent -> TestSuite -> RIO GetPackageFileContext (Map ModuleName (Path Abs File), [DotCabalPath], [PackageWarning]) testFiles component test = do resolveComponentFiles component build names where names = bnames <> exposed exposed = case testInterface test of TestSuiteExeV10 _ fp -> [DotCabalMain fp] TestSuiteLibV09 _ mn -> [DotCabalModule mn] TestSuiteUnsupported _ -> [] bnames = map DotCabalModule (otherModules build) build = testBuildInfo test -- | Get all files referenced by the executable. executableFiles :: NamedComponent -> Executable -> RIO GetPackageFileContext (Map ModuleName (Path Abs File), [DotCabalPath], [PackageWarning]) executableFiles component exe = do resolveComponentFiles component build names where build = buildInfo exe names = map DotCabalModule (otherModules build) ++ [DotCabalMain (modulePath exe)] -- | Get all files referenced by the library. libraryFiles :: NamedComponent -> Library -> RIO GetPackageFileContext (Map ModuleName (Path Abs File), [DotCabalPath], [PackageWarning]) libraryFiles component lib = do resolveComponentFiles component build names where build = libBuildInfo lib names = bnames ++ exposed exposed = map DotCabalModule (exposedModules lib) bnames = map DotCabalModule (otherModules build) -- | Get all files referenced by the component. resolveComponentFiles :: NamedComponent -> BuildInfo -> [DotCabalDescriptor] -> RIO GetPackageFileContext (Map ModuleName (Path Abs File), [DotCabalPath], [PackageWarning]) resolveComponentFiles component build names = do dirs <- mapMaybeM (resolveDirOrWarn . getSymbolicPath) (hsSourceDirs build) dir <- asks (parent . ctxFile) agdirs <- autogenDirs (modules,files,warnings) <- resolveFilesAndDeps component ((if null dirs then [dir] else dirs) ++ agdirs) names cfiles <- buildOtherSources build pure (modules, files <> cfiles, warnings) where autogenDirs = do cabalVer <- asks ctxCabalVer distDir <- asks ctxDistDir let compDir = componentAutogenDir cabalVer component distDir pkgDir = maybeToList $ packageAutogenDir cabalVer distDir filterM doesDirExist $ compDir : pkgDir -- | Try to resolve the list of base names in the given directory by -- looking for unique instances of base names applied with the given -- extensions, plus find any of their module and TemplateHaskell -- dependencies. resolveFilesAndDeps :: NamedComponent -- ^ Package component name -> [Path Abs Dir] -- ^ Directories to look in. -> [DotCabalDescriptor] -- ^ Base names. -> RIO GetPackageFileContext (Map ModuleName (Path Abs File),[DotCabalPath],[PackageWarning]) resolveFilesAndDeps component dirs names0 = do (dotCabalPaths, foundModules, missingModules) <- loop names0 S.empty warnings <- liftM2 (++) (warnUnlisted foundModules) (warnMissing missingModules) pure (foundModules, dotCabalPaths, warnings) where loop [] _ = pure ([], M.empty, []) loop names doneModules0 = do resolved <- resolveFiles dirs names let foundFiles = mapMaybe snd resolved foundModules = mapMaybe toResolvedModule resolved missingModules = mapMaybe toMissingModule resolved pairs <- mapM (getDependencies component dirs) foundFiles let doneModules = S.union doneModules0 (S.fromList (mapMaybe dotCabalModule names)) moduleDeps = S.unions (map fst pairs) thDepFiles = concatMap snd pairs modulesRemaining = S.difference moduleDeps doneModules -- Ignore missing modules discovered as dependencies - they may -- have been deleted. (resolvedFiles, resolvedModules, _) <- loop (map DotCabalModule (S.toList modulesRemaining)) doneModules pure ( nubOrd $ foundFiles <> map DotCabalFilePath thDepFiles <> resolvedFiles , M.union (M.fromList foundModules) resolvedModules , missingModules ) warnUnlisted foundModules = do let unlistedModules = foundModules `M.difference` M.fromList (mapMaybe (fmap (, ()) . dotCabalModule) names0) pure $ if M.null unlistedModules then [] else [ UnlistedModulesWarning component (map fst (M.toList unlistedModules)) ] warnMissing _missingModules = do pure [] -- TODO: bring this back - see -- https://github.com/commercialhaskell/stack/issues/2649 {- cabalfp <- asks ctxFile pure $ if null missingModules then [] else [ MissingModulesWarning cabalfp component missingModules] -} -- TODO: In usages of toResolvedModule / toMissingModule, some sort -- of map + partition would probably be better. toResolvedModule :: (DotCabalDescriptor, Maybe DotCabalPath) -> Maybe (ModuleName, Path Abs File) toResolvedModule (DotCabalModule mn, Just (DotCabalModulePath fp)) = Just (mn, fp) toResolvedModule _ = Nothing toMissingModule :: (DotCabalDescriptor, Maybe DotCabalPath) -> Maybe ModuleName toMissingModule (DotCabalModule mn, Nothing) = Just mn toMissingModule _ = Nothing -- | Get the dependencies of a Haskell module file. getDependencies :: NamedComponent -> [Path Abs Dir] -> DotCabalPath -> RIO GetPackageFileContext (Set ModuleName, [Path Abs File]) getDependencies component dirs dotCabalPath = case dotCabalPath of DotCabalModulePath resolvedFile -> readResolvedHi resolvedFile DotCabalMainPath resolvedFile -> readResolvedHi resolvedFile DotCabalFilePath{} -> pure (S.empty, []) DotCabalCFilePath{} -> pure (S.empty, []) where readResolvedHi resolvedFile = do dumpHIDir <- componentOutputDir component <$> asks ctxDistDir dir <- asks (parent . ctxFile) let sourceDir = fromMaybe dir $ find (`isProperPrefixOf` resolvedFile) dirs stripSourceDir d = stripProperPrefix d resolvedFile case stripSourceDir sourceDir of Nothing -> pure (S.empty, []) Just fileRel -> do let hiPath = FilePath.replaceExtension (toFilePath (dumpHIDir fileRel)) ".hi" dumpHIExists <- liftIO $ D.doesFileExist hiPath if dumpHIExists then parseHI hiPath else pure (S.empty, []) -- | Parse a .hi file into a set of modules and files. parseHI :: FilePath -> RIO GetPackageFileContext (Set ModuleName, [Path Abs File]) parseHI hiPath = do dir <- asks (parent . ctxFile) result <- liftIO $ catchAnyDeep (Iface.fromFile hiPath) (\e -> pure (Left (displayException e))) case result of Left msg -> do prettyStackDevL [ flow "Failed to decode module interface:" , style File $ fromString hiPath , flow "Decoding failure:" , style Error $ fromString msg ] pure (S.empty, []) Right iface -> do let moduleNames = fmap (fromString . T.unpack . decodeUtf8Lenient . fst) . Iface.unList . Iface.dmods . Iface.deps resolveFileDependency file = do resolved <- liftIO (forgivingAbsence (resolveFile dir file)) >>= rejectMissingFile when (isNothing resolved) $ prettyWarnL [ flow "Dependent file listed in:" , style File $ fromString hiPath , flow "does not exist:" , style File $ fromString file ] pure resolved resolveUsages = traverse (resolveFileDependency . Iface.unUsage) . Iface.unList . Iface.usage resolvedUsages <- catMaybes <$> resolveUsages iface pure (S.fromList $ moduleNames iface, resolvedUsages) -- | The directory where generated files are put like .o or .hs (from .x files). componentOutputDir :: NamedComponent -> Path Abs Dir -> Path Abs Dir componentOutputDir namedComponent distDir = case namedComponent of CLib -> buildDir distDir CInternalLib name -> makeTmp name CExe name -> makeTmp name CTest name -> makeTmp name CBench name -> makeTmp name where makeTmp name = buildDir distDir componentNameToDir (name <> "/" <> name <> "-tmp") -- | Try to resolve the list of base names in the given directory by -- looking for unique instances of base names applied with the given -- extensions. resolveFiles :: [Path Abs Dir] -- ^ Directories to look in. -> [DotCabalDescriptor] -- ^ Base names. -> RIO GetPackageFileContext [(DotCabalDescriptor, Maybe DotCabalPath)] resolveFiles dirs names = forM names (\name -> liftM (name, ) (findCandidate dirs name)) -- | Find a candidate for the given module-or-filename from the list -- of directories and given extensions. findCandidate :: [Path Abs Dir] -> DotCabalDescriptor -> RIO GetPackageFileContext (Maybe DotCabalPath) findCandidate dirs name = do pkg <- asks ctxFile >>= parsePackageNameFromFilePath customPreprocessorExts <- view $ configL . to configCustomPreprocessorExts let haskellPreprocessorExts = haskellDefaultPreprocessorExts ++ customPreprocessorExts candidates <- liftIO $ makeNameCandidates haskellPreprocessorExts case candidates of [candidate] -> pure (Just (cons candidate)) [] -> do case name of DotCabalModule mn | display mn /= paths_pkg pkg -> logPossibilities dirs mn _ -> pure () pure Nothing (candidate:rest) -> do warnMultiple name candidate rest pure (Just (cons candidate)) where cons = case name of DotCabalModule{} -> DotCabalModulePath DotCabalMain{} -> DotCabalMainPath DotCabalFile{} -> DotCabalFilePath DotCabalCFile{} -> DotCabalCFilePath paths_pkg pkg = "Paths_" ++ packageNameString pkg makeNameCandidates haskellPreprocessorExts = liftM (nubOrd . concat) (mapM (makeDirCandidates haskellPreprocessorExts) dirs) makeDirCandidates :: [Text] -> Path Abs Dir -> IO [Path Abs File] makeDirCandidates haskellPreprocessorExts dir = case name of DotCabalMain fp -> resolveCandidate dir fp DotCabalFile fp -> resolveCandidate dir fp DotCabalCFile fp -> resolveCandidate dir fp DotCabalModule mn -> do let perExt ext = resolveCandidate dir (Cabal.toFilePath mn ++ "." ++ T.unpack ext) withHaskellExts <- mapM perExt haskellFileExts withPPExts <- mapM perExt haskellPreprocessorExts pure $ case (concat withHaskellExts, concat withPPExts) of -- If we have exactly 1 Haskell extension and exactly -- 1 preprocessor extension, assume the former file is -- generated from the latter -- -- See https://github.com/commercialhaskell/stack/issues/4076 ([_], [y]) -> [y] -- Otherwise, return everything (xs, ys) -> xs ++ ys resolveCandidate dir = fmap maybeToList . resolveDirFile dir -- | Log that we couldn't find a candidate, but there are -- possibilities for custom preprocessor extensions. -- -- For example: .erb for a Ruby file might exist in one of the -- directories. logPossibilities :: HasTerm env => [Path Abs Dir] -> ModuleName -> RIO env () logPossibilities dirs mn = do possibilities <- liftM concat (makePossibilities mn) unless (null possibilities) $ prettyWarnL [ flow "Unable to find a known candidate for the Cabal entry" , (style Module . fromString $ display mn) <> "," , flow "but did find:" , line <> bulletedList (map pretty possibilities) , flow "If you are using a custom preprocessor for this module" , flow "with its own file extension, consider adding the extension" , flow "to the 'custom-preprocessor-extensions' field in stack.yaml." ] where makePossibilities name = mapM ( \dir -> do (_,files) <- listDir dir pure ( map filename ( filter (isPrefixOf (display name) . toFilePath . filename) files ) ) ) dirs -- | Get all C sources and extra source files in a build. buildOtherSources :: BuildInfo -> RIO GetPackageFileContext [DotCabalPath] buildOtherSources build = do cwd <- liftIO getCurrentDir dir <- asks (parent . ctxFile) file <- asks ctxFile let resolveDirFiles files toCabalPath = forMaybeM files $ \fp -> do result <- resolveDirFile dir fp case result of Nothing -> do warnMissingFile "File" cwd fp file pure Nothing Just p -> pure $ Just (toCabalPath p) csources <- resolveDirFiles (cSources build) DotCabalCFilePath jsources <- resolveDirFiles (targetJsSources build) DotCabalFilePath pure (csources <> jsources) -- | Get the target's JS sources. targetJsSources :: BuildInfo -> [FilePath] targetJsSources = jsSources -- | Resolve file as a child of a specified directory, symlinks -- don't get followed. resolveDirFile :: (MonadIO m, MonadThrow m) => Path Abs Dir -> FilePath.FilePath -> m (Maybe (Path Abs File)) resolveDirFile x y = do -- The standard canonicalizePath does not work for this case p <- parseCollapsedAbsFile (toFilePath x FilePath. y) exists <- doesFileExist p pure $ if exists then Just p else Nothing -- | Warn the user that multiple candidates are available for an -- entry, but that we picked one anyway and continued. warnMultiple :: DotCabalDescriptor -> Path b t -> [Path b t] -> RIO GetPackageFileContext () warnMultiple name candidate rest = -- TODO: figure out how to style 'name' and the dispOne stuff prettyWarnL [ flow "There were multiple candidates for the Cabal entry" , fromString . showName $ name , line <> bulletedList (map dispOne (candidate:rest)) , line <> flow "picking:" , dispOne candidate ] where showName (DotCabalModule name') = display name' showName (DotCabalMain fp) = fp showName (DotCabalFile fp) = fp showName (DotCabalCFile fp) = fp dispOne = fromString . toFilePath -- TODO: figure out why dispOne can't be just `display` -- (remove the .hlint.yaml exception if it can be) -- | Parse a package name from a file path. parsePackageNameFromFilePath :: MonadThrow m => Path a File -> m PackageName parsePackageNameFromFilePath fp = do base <- clean $ toFilePath $ filename fp case parsePackageName base of Nothing -> throwM $ CabalFileNameInvalidPackageName $ toFilePath fp Just x -> pure x where clean = liftM reverse . strip . reverse strip ('l':'a':'b':'a':'c':'.':xs) = pure xs strip _ = throwM (CabalFileNameParseFail (toFilePath fp)) -- | Resolve the directory, if it can't be resolved, warn for the user -- (purely to be helpful). resolveDirOrWarn :: FilePath.FilePath -> RIO GetPackageFileContext (Maybe (Path Abs Dir)) resolveDirOrWarn = resolveOrWarn "Directory" f where f p x = liftIO (forgivingAbsence (resolveDir p x)) >>= rejectMissingDir -- | Make the global autogen dir if Cabal version is new enough. packageAutogenDir :: Version -> Path Abs Dir -> Maybe (Path Abs Dir) packageAutogenDir cabalVer distDir | cabalVer < mkVersion [2, 0] = Nothing | otherwise = Just $ buildDir distDir relDirGlobalAutogen -- | Make the autogen dir. componentAutogenDir :: Version -> NamedComponent -> Path Abs Dir -> Path Abs Dir componentAutogenDir cabalVer component distDir = componentBuildDir cabalVer component distDir relDirAutogen -- | Make the build dir. Note that Cabal >= 2.0 uses the -- 'componentBuildDir' above for some things. buildDir :: Path Abs Dir -> Path Abs Dir buildDir distDir = distDir relDirBuild -- NOTE: don't export this, only use it for valid paths based on -- component names. componentNameToDir :: Text -> Path Rel Dir componentNameToDir name = fromMaybe (throw ComponentNotParsedBug) (parseRelDir (T.unpack name)) -- | See 'Distribution.Simple.LocalBuildInfo.componentBuildDir' componentBuildDir :: Version -> NamedComponent -> Path Abs Dir -> Path Abs Dir componentBuildDir cabalVer component distDir | cabalVer < mkVersion [2, 0] = buildDir distDir | otherwise = case component of CLib -> buildDir distDir CInternalLib name -> buildDir distDir componentNameToDir name CExe name -> buildDir distDir componentNameToDir name CTest name -> buildDir distDir componentNameToDir name CBench name -> buildDir distDir componentNameToDir name -- Internal helper to define resolveFileOrWarn and resolveDirOrWarn resolveOrWarn :: Text -> (Path Abs Dir -> String -> RIO GetPackageFileContext (Maybe a)) -> FilePath.FilePath -> RIO GetPackageFileContext (Maybe a) resolveOrWarn subject resolver path = do cwd <- liftIO getCurrentDir file <- asks ctxFile dir <- asks (parent . ctxFile) result <- resolver dir path when (isNothing result) $ warnMissingFile subject cwd path file pure result warnMissingFile :: Text -> Path Abs Dir -> FilePath -> Path Abs File -> RIO GetPackageFileContext () warnMissingFile subject cwd path fromFile = prettyWarnL [ fromString . T.unpack $ subject -- TODO: needs style? , flow "listed in" , maybe (pretty fromFile) pretty (stripProperPrefix cwd fromFile) , flow "file does not exist:" , style Dir . fromString $ path ] stack-2.9.3.1/src/Stack/PackageFile.hs0000644000000000000000000001176314445022466015521 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -- | A module which exports all package-level file-gathering logic. module Stack.PackageFile ( packageDescModulesAndFiles ) where import qualified Data.Map.Strict as M import qualified Data.Set as S import qualified Data.Text as T import Distribution.CabalSpecVersion ( CabalSpecVersion ) import Distribution.ModuleName ( ModuleName ) import Distribution.PackageDescription hiding ( FlagName ) import Distribution.Simple.Glob ( matchDirFileGlob ) import qualified Distribution.Types.UnqualComponentName as Cabal import Path as FL hiding ( replaceExtension ) import Path.Extra import Path.IO hiding ( findFiles ) import Stack.ComponentFile import Stack.Prelude hiding ( Display (..) ) import Stack.Types.NamedComponent import Stack.Types.PackageFile ( DotCabalPath (..), GetPackageFileContext (..) , PackageWarning (..) ) import qualified System.FilePath as FilePath import System.IO.Error ( isUserError ) -- | Resolve the file, if it can't be resolved, warn for the user -- (purely to be helpful). resolveFileOrWarn :: FilePath.FilePath -> RIO GetPackageFileContext (Maybe (Path Abs File)) resolveFileOrWarn = resolveOrWarn "File" f where f p x = liftIO (forgivingAbsence (resolveFile p x)) >>= rejectMissingFile -- | Get all files referenced by the package. packageDescModulesAndFiles :: PackageDescription -> RIO GetPackageFileContext ( Map NamedComponent (Map ModuleName (Path Abs File)) , Map NamedComponent [DotCabalPath] , Set (Path Abs File) , [PackageWarning] ) packageDescModulesAndFiles pkg = do (libraryMods, libDotCabalFiles, libWarnings) <- maybe (pure (M.empty, M.empty, [])) (asModuleAndFileMap libComponent libraryFiles) (library pkg) (subLibrariesMods, subLibDotCabalFiles, subLibWarnings) <- liftM foldTuples ( mapM (asModuleAndFileMap internalLibComponent libraryFiles) (subLibraries pkg) ) (executableMods, exeDotCabalFiles, exeWarnings) <- liftM foldTuples ( mapM (asModuleAndFileMap exeComponent executableFiles) (executables pkg) ) (testMods, testDotCabalFiles, testWarnings) <- liftM foldTuples (mapM (asModuleAndFileMap testComponent testFiles) (testSuites pkg)) (benchModules, benchDotCabalPaths, benchWarnings) <- liftM foldTuples ( mapM (asModuleAndFileMap benchComponent benchmarkFiles) (benchmarks pkg) ) dfiles <- resolveGlobFiles (specVersion pkg) ( extraSrcFiles pkg ++ map (dataDir pkg FilePath.) (dataFiles pkg) ) let modules = libraryMods <> subLibrariesMods <> executableMods <> testMods <> benchModules files = libDotCabalFiles <> subLibDotCabalFiles <> exeDotCabalFiles <> testDotCabalFiles <> benchDotCabalPaths warnings = libWarnings <> subLibWarnings <> exeWarnings <> testWarnings <> benchWarnings pure (modules, files, dfiles, warnings) where libComponent = const CLib internalLibComponent = CInternalLib . T.pack . maybe "" Cabal.unUnqualComponentName . libraryNameString . libName exeComponent = CExe . T.pack . Cabal.unUnqualComponentName . exeName testComponent = CTest . T.pack . Cabal.unUnqualComponentName . testName benchComponent = CBench . T.pack . Cabal.unUnqualComponentName . benchmarkName asModuleAndFileMap label f lib = do (a, b, c) <- f (label lib) lib pure (M.singleton (label lib) a, M.singleton (label lib) b, c) foldTuples = foldl' (<>) (M.empty, M.empty, []) -- | Resolve globbing of files (e.g. data files) to absolute paths. resolveGlobFiles :: CabalSpecVersion -- ^ Cabal file version -> [String] -> RIO GetPackageFileContext (Set (Path Abs File)) resolveGlobFiles cabalFileVersion = liftM (S.fromList . catMaybes . concat) . mapM resolve where resolve name = if '*' `elem` name then explode name else liftM pure (resolveFileOrWarn name) explode name = do dir <- asks (parent . ctxFile) names <- matchDirFileGlob' (FL.toFilePath dir) name mapM resolveFileOrWarn names matchDirFileGlob' dir glob = catch (liftIO (matchDirFileGlob minBound cabalFileVersion dir glob)) ( \(e :: IOException) -> if isUserError e then do prettyWarnL [ flow "Wildcard does not match any files:" , style File $ fromString glob , line <> flow "in directory:" , style Dir $ fromString dir ] pure [] else throwIO e ) stack-2.9.3.1/src/Stack/Types/Cache.hs0000644000000000000000000000376114445022466015474 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Types.Cache ( ConfigCacheType (..) , Action (..) ) where import qualified Data.Text as T import Database.Persist.Sql import Stack.Prelude import Stack.Types.GhcPkgId -- | Type of config cache data ConfigCacheType = ConfigCacheTypeConfig | ConfigCacheTypeFlagLibrary GhcPkgId | ConfigCacheTypeFlagExecutable PackageIdentifier deriving (Eq, Show) instance PersistField ConfigCacheType where toPersistValue ConfigCacheTypeConfig = PersistText "config" toPersistValue (ConfigCacheTypeFlagLibrary v) = PersistText $ "lib:" <> unGhcPkgId v toPersistValue (ConfigCacheTypeFlagExecutable v) = PersistText $ "exe:" <> T.pack (packageIdentifierString v) fromPersistValue (PersistText t) = fromMaybe (Left $ "Unexpected ConfigCacheType value: " <> t) $ config <|> fmap lib (T.stripPrefix "lib:" t) <|> fmap exe (T.stripPrefix "exe:" t) where config | t == "config" = Just (Right ConfigCacheTypeConfig) | otherwise = Nothing lib v = do ghcPkgId <- mapLeft tshow (parseGhcPkgId v) Right $ ConfigCacheTypeFlagLibrary ghcPkgId exe v = do pkgId <- maybe (Left $ "Unexpected ConfigCacheType value: " <> t) Right $ parsePackageIdentifier (T.unpack v) Right $ ConfigCacheTypeFlagExecutable pkgId fromPersistValue _ = Left "Unexpected ConfigCacheType type" instance PersistFieldSql ConfigCacheType where sqlType _ = SqlString data Action = UpgradeCheck deriving (Show, Eq, Ord) instance PersistField Action where toPersistValue UpgradeCheck = PersistInt64 1 fromPersistValue (PersistInt64 1) = Right UpgradeCheck fromPersistValue x = Left $ T.pack $ "Invalid Action: " ++ show x instance PersistFieldSql Action where sqlType _ = SqlInt64 stack-2.9.3.1/src/Stack/Types/Dependency.hs0000644000000000000000000000202314445022466016535 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Types.Dependency ( DepValue (..) , DepType (..) ) where import Distribution.Types.VersionRange ( VersionRange ) import Stack.Prelude import Stack.Types.Version ( intersectVersionRanges ) -- | The value for a map from dependency name. This contains both the -- version range and the type of dependency, and provides a semigroup -- instance. data DepValue = DepValue { dvVersionRange :: !VersionRange , dvType :: !DepType } deriving (Show, Typeable) instance Semigroup DepValue where DepValue a x <> DepValue b y = DepValue (intersectVersionRanges a b) (x <> y) -- | Is this package being used as a library, or just as a build tool? -- If the former, we need to ensure that a library actually -- exists. See -- data DepType = AsLibrary | AsBuildTool deriving (Show, Eq) instance Semigroup DepType where AsLibrary <> _ = AsLibrary AsBuildTool <> x = x stack-2.9.3.1/src/Stack/Types/PackageFile.hs0000644000000000000000000000731514445022466016623 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} -- | The facility for retrieving all files from the main Stack -- 'Stack.Types.Package' type. This was moved into its own module to allow -- component-level file-gathering without circular dependency at the Package -- level. module Stack.Types.PackageFile ( GetPackageFileContext (..) , DotCabalPath (..) , DotCabalDescriptor (..) , GetPackageFiles (..) , PackageWarning (..) ) where import Distribution.ModuleName ( ModuleName ) import RIO.Process ( HasProcessContext (processContextL) ) import Stack.Prelude import Stack.Types.Config ( BuildConfig, HasBuildConfig (..), HasConfig (..) , HasEnvConfig, HasGHCVariant, HasPlatform, HasRunner (..) ) import Stack.Types.NamedComponent ( NamedComponent ) data GetPackageFileContext = GetPackageFileContext { ctxFile :: !(Path Abs File) , ctxDistDir :: !(Path Abs Dir) , ctxBuildConfig :: !BuildConfig , ctxCabalVer :: !Version } instance HasPlatform GetPackageFileContext instance HasGHCVariant GetPackageFileContext instance HasLogFunc GetPackageFileContext where logFuncL = configL.logFuncL instance HasRunner GetPackageFileContext where runnerL = configL.runnerL instance HasStylesUpdate GetPackageFileContext where stylesUpdateL = runnerL.stylesUpdateL instance HasTerm GetPackageFileContext where useColorL = runnerL.useColorL termWidthL = runnerL.termWidthL instance HasConfig GetPackageFileContext instance HasPantryConfig GetPackageFileContext where pantryConfigL = configL.pantryConfigL instance HasProcessContext GetPackageFileContext where processContextL = configL.processContextL instance HasBuildConfig GetPackageFileContext where buildConfigL = lens ctxBuildConfig (\x y -> x { ctxBuildConfig = y }) -- | A path resolved from the Cabal file, which is either main-is or -- an exposed/internal/referenced module. data DotCabalPath = DotCabalModulePath !(Path Abs File) | DotCabalMainPath !(Path Abs File) | DotCabalFilePath !(Path Abs File) | DotCabalCFilePath !(Path Abs File) deriving (Eq, Ord, Show) -- | A descriptor from a Cabal file indicating one of the following: -- -- exposed-modules: Foo -- other-modules: Foo -- or -- main-is: Foo.hs -- data DotCabalDescriptor = DotCabalModule !ModuleName | DotCabalMain !FilePath | DotCabalFile !FilePath | DotCabalCFile !FilePath deriving (Eq, Ord, Show) -- | Files that the package depends on, relative to package directory. -- Argument is the location of the Cabal file newtype GetPackageFiles = GetPackageFiles { getPackageFiles :: forall env. HasEnvConfig env => Path Abs File -> RIO env ( Map NamedComponent (Map ModuleName (Path Abs File)) , Map NamedComponent [DotCabalPath] , Set (Path Abs File) , [PackageWarning] ) } instance Show GetPackageFiles where show _ = "" -- | Warning generated when reading a package data PackageWarning = UnlistedModulesWarning NamedComponent [ModuleName] -- ^ Modules found that are not listed in Cabal file -- TODO: bring this back - see -- https://github.com/commercialhaskell/stack/issues/2649 {- | MissingModulesWarning (Path Abs File) (Maybe String) [ModuleName] -- ^ Modules not found in file system, which are listed in Cabal file -} stack-2.9.3.1/src/Stack/Types/Storage.hs0000644000000000000000000000360214445022466016067 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} -- | Types used by @Stack.Storage@ modules. module Stack.Types.Storage ( StoragePrettyException (..) ) where import Data.Text import Stack.Prelude -- | Type representing \'pretty\' exceptions thrown by functions exported by -- modules beginning @Stack.Storage@. data StoragePrettyException = StorageMigrationFailure !Text !(Path Abs File) !SomeException deriving (Show, Typeable) instance Pretty StoragePrettyException where pretty (StorageMigrationFailure desc fp ex) = "[S-8835]" <> line <> flow "Stack could not migrate the the database" <+> style File (fromString $ show desc) <+> flow "located at" <+> style Dir (pretty fp) <> "." <> blankLine <> flow "While migrating the database, Stack encountered the error:" <> blankLine <> string exMsg <> blankLine <> flow "Please report this as an issue at" <+> style Url "https://github.com/commercialhaskell/stack/issues" <> "." <> blankLine -- See https://github.com/commercialhaskell/stack/issues/5851 <> if exMsg == winIOGHCRTSMsg then flow "This error can be caused by a bug that arises if GHC's \ \'--io-manager=native' RTS option is set using the GHCRTS \ \environment variable. As a workaround try setting the option \ \in the project's Cabal file, Stack's YAML configuration file \ \or at the command line." else flow "As a workaround you may delete the database. This \ \will cause the database to be recreated." where exMsg = displayException ex winIOGHCRTSMsg = "\\\\.\\NUL: hDuplicateTo: illegal operation (handles are incompatible)" instance Exception StoragePrettyException stack-2.9.3.1/src/windows/System/Posix/User.hs0000644000000000000000000000265414445111644017313 0ustar0000000000000000-- | The module of this name differs as between Windows and non-Windows builds. -- This is the Windows version. Non-Windows builds rely on the unix package, -- which exposes a module of the same name. module System.Posix.User ( getEffectiveUserID , getEffectiveGroupID , getGroups , getUserEntryForName , homeDirectory , setGroupID , setUserID ) where import System.IO.Error ( illegalOperationErrorType, mkIOError ) import System.PosixCompat.Types ( GroupID, UserID ) unsupported :: String -> IO a unsupported f = ioError $ mkIOError illegalOperationErrorType x Nothing Nothing where x = "System.Posix.User." ++ f ++ ": not supported on Windows." getEffectiveUserID :: IO UserID getEffectiveUserID = unsupported "getEffectiveUserID" getEffectiveGroupID :: IO GroupID getEffectiveGroupID = unsupported "getEffectiveGroupID" getGroups :: IO [GroupID] getGroups = return [] getUserEntryForName :: String -> IO UserEntry getUserEntryForName _ = unsupported "getUserEntryForName" setGroupID :: GroupID -> IO () setGroupID _ = return () setUserID :: UserID -> IO () setUserID _ = return () data UserEntry = UserEntry { userName :: String , userPassword :: String , userID :: UserID , userGroupID :: GroupID , userGecos :: String , homeDirectory :: String , userShell :: String } deriving (Eq, Read, Show) stack-2.9.3.1/src/windows/System/Uname.hs0000644000000000000000000000020514445022466016331 0ustar0000000000000000module System.Uname ( getRelease ) where getRelease :: IO String getRelease = error "getRelease not supported on Windows" stack-2.9.3.1/src/unix/System/Uname.hsc0000644000000000000000000000215514445022466015773 0ustar0000000000000000module System.Uname ( getRelease ) where #include import Foreign import Foreign.C getRelease :: IO String getRelease = do alloca $ \ ptr -> do throwErrnoIfMinus1_ "uname" $ uname ptr peekCString $ release ptr -- | @'uname' name@ stores nul-terminated strings of information -- identifying the current system info to the structure referenced -- by name. -- -- > import Foreign.C -- > import Foreign.Marshal -- > -- > sysName :: IO String -- > sysName = alloca $ \ ptr -> -- > do throwErrnoIfMinus1_ "uname" $ uname ptr -- > peekCString $ sysname ptr -- foreign import ccall unsafe "haskell_uname" uname :: Ptr Utsname -> IO CInt data Utsname instance Storable Utsname where sizeOf = const #size struct utsname alignment = const #alignment struct utsname poke = error "Storable Utsname: peek: unsupported operation" peek = error "Storable Utsname: poke: unsupported operation" release :: Ptr Utsname -> CString release = (#ptr struct utsname, release) stack-2.9.3.1/src/unix/cbits/uname.c0000644000000000000000000000014414331513215015303 0ustar0000000000000000#include int haskell_uname(struct utsname *name) { return uname(name); } stack-2.9.3.1/test/integration/IntegrationSpec.hs0000644000000000000000000002135614445022466020131 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} import Conduit import Data.List (stripPrefix) import Options.Generic import RIO import RIO.Char (toLower) import RIO.Directory hiding (findExecutable) import RIO.FilePath import RIO.List (isInfixOf, partition) import qualified RIO.Map as Map import RIO.Process import qualified RIO.Set as Set import qualified RIO.Text as T import System.Environment (lookupEnv, getExecutablePath) import System.Info (os) import System.PosixCompat.Files -- This code does not use a test framework so that we get direct -- control of how the output is displayed. main :: IO () main = runSimpleApp $ do logInfo "Initiating Stack integration test running" options <- getRecord "Stack integration tests" results <- runApp options $ do logInfo "Running with the following environment" proc "env" [] runProcess_ tests <- asks appTestDirs let count = Set.size tests loop !idx rest !accum = case rest of [] -> pure accum next:rest' -> do logInfo $ "Running integration test " <> display idx <> "/" <> display count <> ": " <> fromString (takeFileName next) res <- test next loop (idx + 1) rest' (res <> accum) loop (1 :: Int) (Set.toList tests) mempty let (successes, failures) = partition ((== ExitSuccess) . snd) $ Map.toList results unless (null successes) $ do logInfo "Successful tests:" for_ successes $ \(x, _) -> logInfo $ "- " <> display x logInfo "" if null failures then logInfo "No failures!" else do logInfo "Failed tests:" for_ failures $ \(x, ec) -> logInfo $ "- " <> display x <> " - " <> displayShow ec exitFailure data Options = Options { optSpeed :: Maybe Speed , optMatch :: Maybe String } deriving Generic instance ParseRecord Options where parseRecord = parseRecordWithModifiers modifiers where optName = map toLower . drop 3 modifiers = defaultModifiers { fieldNameModifier = optName , shortNameModifier = firstLetter . optName } data Speed = Fast | Normal | Superslow deriving (Read, Generic) instance ParseField Speed exeExt :: String exeExt = if isWindows then ".exe" else "" isWindows :: Bool isWindows = os == "mingw32" runApp :: Options -> RIO App a -> RIO SimpleApp a runApp options inner = do let speed = fromMaybe Normal $ optSpeed options simpleApp <- ask runghc <- findExecutable "runghc" >>= either throwIO pure srcDir <- canonicalizePath "" testsRoot <- canonicalizePath $ srcDir "test/integration" libdir <- canonicalizePath $ testsRoot "lib" myPath <- liftIO getExecutablePath stack <- canonicalizePath $ takeDirectory myPath "stack" ++ exeExt logInfo $ "Using Stack located at " <> fromString stack proc stack ["--version"] runProcess_ logInfo $ "Using runghc located at " <> fromString runghc proc runghc ["--version"] runProcess_ let matchTest = case optMatch options of Nothing -> const True Just str -> (str `isInfixOf`) testDirs <- runConduitRes $ sourceDirectory (testsRoot "tests") .| filterMC (liftIO . hasTest) .| filterC matchTest .| foldMapC Set.singleton let modifyEnvCommon = Map.insert "SRC_DIR" (fromString srcDir) . Map.insert "STACK_EXE" (fromString stack) . Map.delete "GHC_PACKAGE_PATH" . Map.insert "STACK_TEST_SPEED" (case speed of Superslow -> "SUPERSLOW" _ -> "NORMAL") . Map.fromList . map (first T.toUpper) . Map.toList case speed of Fast -> do let app = App { appSimpleApp = simpleApp , appRunghc = runghc , appLibDir = libdir , appSetupHome = id , appTestDirs = testDirs } runRIO app $ withModifyEnvVars modifyEnvCommon inner _ -> do morigStackRoot <- liftIO $ lookupEnv "STACK_ROOT" origStackRoot <- case morigStackRoot of Nothing -> getAppUserDataDirectory "stack" Just x -> pure x logInfo "Initializing/updating the original Pantry store" proc stack ["update"] runProcess_ pantryRoot <- canonicalizePath $ origStackRoot "pantry" let modifyEnv = Map.insert "PANTRY_ROOT" (fromString pantryRoot) . modifyEnvCommon app = App { appSimpleApp = simpleApp , appRunghc = runghc , appLibDir = libdir , appSetupHome = \inner' -> withSystemTempDirectory "home" $ \newHome -> do let newStackRoot = newHome ".stack" createDirectoryIfMissing True newStackRoot let modifyEnv' = Map.insert "HOME" (fromString newHome) . Map.insert "APPDATA" (fromString newHome) . Map.insert "STACK_ROOT" (fromString newStackRoot) writeFileBinary (newStackRoot "config.yaml") "system-ghc: true\ninstall-ghc: false\n" withModifyEnvVars modifyEnv' inner' , appTestDirs = testDirs } runRIO app $ withModifyEnvVars modifyEnv inner hasTest :: FilePath -> IO Bool hasTest dir = doesFileExist $ dir "Main.hs" data App = App { appRunghc :: !FilePath , appLibDir :: !FilePath , appSetupHome :: !(forall a. RIO App a -> RIO App a) , appSimpleApp :: !SimpleApp , appTestDirs :: !(Set FilePath) } simpleAppL :: Lens' App SimpleApp simpleAppL = lens appSimpleApp (\x y -> x { appSimpleApp = y }) instance HasLogFunc App where logFuncL = simpleAppL.logFuncL instance HasProcessContext App where processContextL = simpleAppL.processContextL -- | Call 'appSetupHome' on the inner action withHome :: RIO App a -> RIO App a withHome inner = do app <- ask appSetupHome app inner test :: FilePath -- ^ test dir -> RIO App (Map Text ExitCode) test testDir = withDir $ \dir -> withHome $ do runghc <- asks appRunghc libDir <- asks appLibDir let mainFile = testDir "Main.hs" copyTree (testDir "files") dir withSystemTempFile (name <.> "log") $ \logfp logh -> do ec <- withWorkingDir dir $ withModifyEnvVars (Map.insert "TEST_DIR" $ fromString testDir) $ proc runghc [ "-clear-package-db" , "-global-package-db" , "-i" ++ libDir , mainFile ] $ runProcess . setStdin closed . setStdout (useHandleOpen logh) . setStderr (useHandleOpen logh) hClose logh case ec of ExitSuccess -> logInfo "Success!" _ -> do logError "Failure, dumping log\n\n" withSourceFile logfp $ \src -> runConduit $ src .| stderrC logError $ "\n\nEnd of log for " <> fromString name pure $ Map.singleton (fromString name) ec where name = takeFileName testDir withDir = withSystemTempDirectory ("stack-integration-" ++ name) copyTree :: MonadIO m => FilePath -> FilePath -> m () copyTree src dst = liftIO $ runResourceT (sourceDirectoryDeep False src `connect` mapM_C go) `catch` \(_ :: IOException) -> pure () where go srcfp = liftIO $ do Just suffix <- pure $ stripPrefix src srcfp let dstfp = dst stripHeadSeparator suffix createDirectoryIfMissing True $ takeDirectory dstfp -- copying yaml files so lock files won't get created in -- the source directory if takeFileName srcfp /= "package.yaml" && (takeExtensions srcfp == ".yaml" || takeExtensions srcfp == ".yml") then copyFile srcfp dstfp else createSymbolicLink srcfp dstfp `catch` \(_ :: IOException) -> copyFile srcfp dstfp -- for Windows stripHeadSeparator :: FilePath -> FilePath stripHeadSeparator [] = [] stripHeadSeparator fp@(x:xs) = if isPathSeparator x then xs else fp stack-2.9.3.1/test/integration/lib/StackTest.hs0000644000000000000000000002574214445022466017511 0ustar0000000000000000{-# LANGUAGE ScopedTypeVariables #-} module StackTest where import Control.Monad import Control.Monad.IO.Class import Control.Monad.Trans.Reader import Control.Concurrent import Control.Exception import Data.Maybe (fromMaybe) import System.Environment import System.Directory import System.IO import System.IO.Error import System.Process import System.Exit import System.Info (arch, os) import GHC.Stack (HasCallStack) run' :: HasCallStack => FilePath -> [String] -> IO ExitCode run' cmd args = do logInfo $ "Running: " ++ cmd ++ " " ++ unwords (map showProcessArgDebug args) (Nothing, Nothing, Nothing, ph) <- createProcess (proc cmd args) waitForProcess ph run :: HasCallStack => FilePath -> [String] -> IO () run cmd args = do ec <- run' cmd args unless (ec == ExitSuccess) $ error $ "Exited with exit code: " ++ displayException ec runShell :: HasCallStack => String -> IO () runShell cmd = do logInfo $ "Running: " ++ cmd (Nothing, Nothing, Nothing, ph) <- createProcess (shell cmd) ec <- waitForProcess ph unless (ec == ExitSuccess) $ error $ "Exited with exit code: " ++ displayException ec runWithCwd :: HasCallStack => FilePath -> String -> [String] -> IO String runWithCwd cwdPath cmd args = do logInfo $ "Running: " ++ cmd let cp = proc cmd args (ec, stdoutStr, _) <- readCreateProcessWithExitCode (cp { cwd = Just cwdPath }) "" unless (ec == ExitSuccess) $ error $ "Exited with exit code: " ++ displayException ec pure stdoutStr stackExe :: IO String stackExe = getEnv "STACK_EXE" stackSrc :: IO String stackSrc = getEnv "SRC_DIR" testDir :: IO String testDir = getEnv "TEST_DIR" stack' :: HasCallStack => [String] -> IO ExitCode stack' args = do stackEnv <- stackExe run' stackEnv args stack :: HasCallStack => [String] -> IO () stack args = do ec <- stack' args unless (ec == ExitSuccess) $ error $ "Exited with exit code: " ++ displayException ec -- Temporary workaround for Windows to ignore exceptions arising out -- of Windows when we do stack clean. More info here: https://github.com/commercialhaskell/stack/issues/4936 stackCleanFull :: HasCallStack => IO () stackCleanFull = stackIgnoreException ["clean", "--full"] -- Temporary workaround for Windows to ignore exceptions arising out -- of Windows when we do stack clean. More info here: https://github.com/commercialhaskell/stack/issues/4936 stackIgnoreException :: HasCallStack => [String] -> IO () stackIgnoreException args = if isWindows then void (stack' args) `catch` (\(_e :: IOException) -> pure ()) else stack args stackErr :: HasCallStack => [String] -> IO () stackErr args = do ec <- stack' args when (ec == ExitSuccess) $ error "stack was supposed to fail, but didn't" type Repl = ReaderT ReplConnection IO data ReplConnection = ReplConnection { replStdin :: Handle , replStdout :: Handle } nextPrompt :: Repl () nextPrompt = do (ReplConnection _ inputHandle) <- ask c <- liftIO $ hGetChar inputHandle if c == '>' then do _ <- liftIO $ hGetChar inputHandle pure () else nextPrompt replCommand :: String -> Repl () replCommand cmd = do (ReplConnection input _) <- ask liftIO $ hPutStrLn input cmd replGetLine :: Repl String replGetLine = ask >>= liftIO . hGetLine . replStdout replGetChar :: Repl Char replGetChar = ask >>= liftIO . hGetChar . replStdout runRepl :: HasCallStack => FilePath -> [String] -> ReaderT ReplConnection IO () -> IO ExitCode runRepl cmd args actions = do logInfo $ "Running: " ++ cmd ++ " " ++ unwords (map showProcessArgDebug args) (Just rStdin, Just rStdout, Just rStderr, ph) <- createProcess (proc cmd args) { std_in = CreatePipe , std_out = CreatePipe , std_err = CreatePipe } hSetBuffering rStdin NoBuffering hSetBuffering rStdout NoBuffering hSetBuffering rStderr NoBuffering tempDir <- if isWindows then fromMaybe "" <$> lookupEnv "TEMP" else pure "/tmp" let tempFP = tempDir ++ "/stderr" _ <- forkIO $ withFile tempFP WriteMode $ \err -> do hSetBuffering err NoBuffering forever $ catch (hGetChar rStderr >>= hPutChar err) $ \e -> unless (isEOFError e) $ throw e runReaderT (nextPrompt >> actions) (ReplConnection rStdin rStdout) waitForProcess ph repl :: HasCallStack => [String] -> Repl () -> IO () repl args action = do stackExe' <- stackExe ec <- runRepl stackExe' ("repl":args) action unless (ec == ExitSuccess) $ pure () -- TODO: Understand why the exit code is 1 despite running GHCi tests -- successfully. -- else error $ "Exited with exit code: " ++ show ec stackStderr :: HasCallStack => [String] -> IO (ExitCode, String) stackStderr args = do stackExe' <- stackExe logInfo $ "Running: " ++ stackExe' ++ " " ++ unwords (map showProcessArgDebug args) (ec, _, err) <- readProcessWithExitCode stackExe' args "" hPutStr stderr err pure (ec, err) -- | Run stack with arguments and apply a check to the resulting -- stderr output if the process succeeded. stackCheckStderr :: HasCallStack => [String] -> (String -> IO ()) -> IO () stackCheckStderr args check = do (ec, err) <- stackStderr args if ec /= ExitSuccess then error $ "Exited with exit code: " ++ displayException ec else check err -- | Same as 'stackCheckStderr', but ensures that the Stack process -- fails. stackErrStderr :: HasCallStack => [String] -> (String -> IO ()) -> IO () stackErrStderr args check = do (ec, err) <- stackStderr args if ec == ExitSuccess then error "Stack process succeeded, but it shouldn't" else check err runEx :: HasCallStack => FilePath -> String -> IO (ExitCode, String, String) runEx cmd args = runEx' cmd $ words args runEx' :: HasCallStack => FilePath -> [String] -> IO (ExitCode, String, String) runEx' cmd args = do logInfo $ "Running: " ++ cmd ++ " " ++ unwords (map showProcessArgDebug args) (ec, out, err) <- readProcessWithExitCode cmd args "" putStr out hPutStr stderr err pure (ec, out, err) -- | Run stack with arguments and apply a check to the resulting -- stdout output if the process succeeded. -- -- Take care with newlines; if the output includes a newline character that -- should not be there, use 'Data.List.Extra.trimEnd' to remove it. stackCheckStdout :: HasCallStack => [String] -> (String -> IO ()) -> IO () stackCheckStdout args check = do stackExe' <- stackExe (ec, out, _) <- runEx' stackExe' args if ec /= ExitSuccess then error $ "Exited with exit code: " ++ displayException ec else check out doesNotExist :: HasCallStack => FilePath -> IO () doesNotExist fp = do logInfo $ "doesNotExist " ++ fp exists <- doesFileOrDirExist fp case exists of (Right msg) -> error msg (Left _) -> pure () doesExist :: HasCallStack => FilePath -> IO () doesExist fp = do logInfo $ "doesExist " ++ fp exists <- doesFileOrDirExist fp case exists of (Right _) -> pure () (Left _) -> error "No file or directory exists" doesFileOrDirExist :: HasCallStack => FilePath -> IO (Either () String) doesFileOrDirExist fp = do isFile <- doesFileExist fp if isFile then pure (Right ("File exists: " ++ fp)) else do isDir <- doesDirectoryExist fp if isDir then pure (Right ("Directory exists: " ++ fp)) else pure (Left ()) copy :: HasCallStack => FilePath -> FilePath -> IO () copy src dest = do logInfo ("Copy " ++ show src ++ " to " ++ show dest) System.Directory.copyFile src dest fileContentsMatch :: HasCallStack => FilePath -> FilePath -> IO () fileContentsMatch f1 f2 = do doesExist f1 doesExist f2 f1Contents <- readFile f1 f2Contents <- readFile f2 unless (f1Contents == f2Contents) $ error ("contents do not match for " ++ show f1 ++ " " ++ show f2) logInfo :: String -> IO () logInfo = hPutStrLn stderr -- TODO: use Stack's process running utilities? (better logging) -- for now just copy+modifying this one from System.Process.Log -- | Show a process arg including speechmarks when necessary. Just for -- debugging purposes, not functionally important. showProcessArgDebug :: String -> String showProcessArgDebug x | any special x = show x | otherwise = x where special '"' = True special ' ' = True special _ = False -- | Extension of executables exeExt :: String exeExt = if isWindows then ".exe" else "" -- | Is the OS Windows? isWindows :: Bool isWindows = os == "mingw32" isLinux :: Bool isLinux = os == "linux" -- | Is the OS Alpine Linux? getIsAlpine :: IO Bool getIsAlpine = doesFileExist "/etc/alpine-release" -- | Is the architecture ARM? isARM :: Bool isARM = arch == "arm" -- | Is the OS Mac OS X? isMacOSX :: Bool isMacOSX = os == "darwin" -- | To avoid problems with GHC version mismatch when a new LTS major -- version is released, pass this argument to @stack@ when running in -- a global context. The LTS major version here should match that of -- the main @stack.yaml@. -- defaultResolverArg :: String defaultResolverArg = "--resolver=nightly-2022-11-14" -- | Remove a file and ignore any warnings about missing files. removeFileIgnore :: HasCallStack => FilePath -> IO () removeFileIgnore fp = removeFile fp `catch` \e -> if isDoesNotExistError e then pure () else throwIO e -- | Remove a directory and ignore any warnings about missing files. removeDirIgnore :: HasCallStack => FilePath -> IO () removeDirIgnore fp = removeDirectoryRecursive fp `catch` \e -> if isDoesNotExistError e then pure () else throwIO e -- | Changes to the specified working directory. withCwd :: HasCallStack => FilePath -> IO () -> IO () withCwd dir action = do currentDirectory <- getCurrentDirectory let enterDir = setCurrentDirectory dir exitDir = setCurrentDirectory currentDirectory bracket_ enterDir exitDir action -- | Changes working directory to Stack source directory. withSourceDirectory :: HasCallStack => IO () -> IO () withSourceDirectory action = do dir <- stackSrc withCwd dir action -- | Mark a test as superslow, only to be run when explicitly requested. superslow :: HasCallStack => IO () -> IO () superslow inner = do mres <- lookupEnv "STACK_TEST_SPEED" case mres of Just "NORMAL" -> logInfo "Skipping superslow test" Just "SUPERSLOW" -> do logInfo "Running superslow test, hold on to your butts" inner Nothing -> do logInfo "No STACK_TEST_SPEED specified. Executing superslow test, hold on to your butts" inner Just x -> error $ "Invalid value for STACK_TEST_SPEED env var: " ++ show x stack-2.9.3.1/src/main/Main.hs0000644000000000000000000012106714445022466014130 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -- | Main Stack tool entry point. module Main (main) where import BuildInfo import Conduit ( runConduitRes, sourceLazy, sinkFileCautious ) import Data.Attoparsec.Args ( EscapingMode (Escaping), parseArgs ) import Data.Attoparsec.Interpreter ( getInterpreterArgs ) import qualified Data.List as L import qualified Data.Map.Strict as Map import qualified Data.Set as Set import qualified Data.Text as T import RIO.Process import GHC.IO.Encoding ( mkTextEncoding, textEncodingName ) import Options.Applicative ( Parser, ParserFailure, ParserHelp, ParserResult (..), flag , handleParseResult, help, helpError, idm, long, metavar , overFailure, renderFailure, strArgument, switch ) import Options.Applicative.Help ( errorHelp, stringChunk, vcatChunks ) import Options.Applicative.Builder.Extra ( boolFlags, execExtraHelp, extraHelpOption, textOption ) import Options.Applicative.Complicated ( addCommand, addSubCommands, complicatedOptions ) import Pantry ( loadSnapshot ) import Path import Path.IO import Stack.Build import Stack.Build.Target ( NeedTargets (..) ) import Stack.Clean ( CleanCommand (..), CleanOpts (..), clean ) import Stack.Config import Stack.ConfigCmd as ConfigCmd import Stack.Constants import Stack.Constants.Config import Stack.Coverage import qualified Stack.Docker as Docker import Stack.Dot import Stack.GhcPkg ( findGhcPkgField ) import qualified Stack.Nix as Nix import Stack.FileWatch import Stack.Ghci import Stack.Hoogle import Stack.List import Stack.Ls import qualified Stack.IDE as IDE import Stack.Init import Stack.New import Stack.Options.BuildParser import Stack.Options.CleanParser import Stack.Options.DockerParser import Stack.Options.DotParser import Stack.Options.ExecParser import Stack.Options.GhciParser import Stack.Options.GlobalParser import Stack.Options.HpcReportParser import Stack.Options.NewParser import Stack.Options.NixParser import Stack.Options.ScriptParser import Stack.Options.SDistParser import Stack.Options.UploadParser import Stack.Options.Utils import qualified Stack.Path import Stack.Prelude hiding (Display (..)) import Stack.Runners import Stack.Script import Stack.SDist ( SDistOpts (..), checkSDistTarball, checkSDistTarball' , getSDistTarball ) import Stack.Setup ( withNewLocalBuildTargets ) import Stack.SetupCmd import Stack.Types.Version ( VersionCheck (..), checkVersion, showStackVersion , stackVersion ) import Stack.Types.Config import Stack.Types.NamedComponent import Stack.Types.SourceMap import Stack.Unpack import Stack.Upgrade import qualified Stack.Upload as Upload import qualified System.Directory as D import System.Environment ( getArgs, getProgName, withArgs ) import System.FilePath ( isValid, pathSeparator, takeDirectory ) import qualified System.FilePath as FP import System.IO ( hGetEncoding, hPutStrLn, hSetEncoding ) import System.Terminal ( hIsTerminalDeviceOrMinTTY ) -- | Type representing exceptions thrown by functions in the "Main" module. data MainException = InvalidReExecVersion String String | InvalidPathForExec FilePath deriving (Show, Typeable) instance Exception MainException where displayException (InvalidReExecVersion expected actual) = concat [ "Error: [S-2186]\n" , "When re-executing '" , stackProgName , "' in a container, the incorrect version was found\nExpected: " , expected , "; found: " , actual ] displayException (InvalidPathForExec path) = concat [ "Error: [S-1541]\n" , "Got an invalid '--cwd' argument for 'stack exec' (" , path , ")." ] -- | Type representing \'pretty\' exceptions thrown by functions in the "Main" -- module. data MainPrettyException = GHCProfOptionInvalid | ResolverOptionInvalid | PackageIdNotFoundBug !String | ExecutableToRunNotFound deriving (Show, Typeable) instance Pretty MainPrettyException where pretty GHCProfOptionInvalid = "[S-8100]" <> line <> flow "When building with Stack, you should not use GHC's '-prof' \ \option. Instead, please use Stack's '--library-profiling' and \ \'--executable-profiling' flags. See:" <+> style Url "https://github.com/commercialhaskell/stack/issues/1015" <> "." pretty ResolverOptionInvalid = "[S-8761]" <> line <> flow "The '--resolver' option cannot be used with Stack's 'upgrade' \ \command." pretty (PackageIdNotFoundBug name) = bugPrettyReport "[S-8251]" $ "Could not find the package id of the package" <+> style Target (fromString name) <> "." pretty ExecutableToRunNotFound = "[S-2483]" <> line <> flow "No executables found." instance Exception MainPrettyException main :: IO () main = do -- Line buffer the output by default, particularly for non-terminal runs. -- See https://github.com/commercialhaskell/stack/pull/360 hSetBuffering stdout LineBuffering hSetBuffering stdin LineBuffering hSetBuffering stderr LineBuffering hSetTranslit stdout hSetTranslit stderr args <- getArgs progName <- getProgName isTerminal <- hIsTerminalDeviceOrMinTTY stdout -- On Windows, where applicable, defaultColorWhen has the side effect of -- enabling ANSI for ANSI-capable native (ConHost) terminals, if not already -- ANSI-enabled. execExtraHelp args Docker.dockerHelpOptName (dockerOptsParser False) ("Only showing --" ++ Docker.dockerCmdName ++ "* options.") execExtraHelp args Nix.nixHelpOptName (nixOptsParser False) ("Only showing --" ++ Nix.nixCmdName ++ "* options.") currentDir <- D.getCurrentDirectory eGlobalRun <- try $ commandLineHandler currentDir progName False case eGlobalRun of Left (exitCode :: ExitCode) -> throwIO exitCode Right (globalMonoid, run) -> do global <- globalOptsFromMonoid isTerminal globalMonoid when (globalLogLevel global == LevelDebug) $ hPutStrLn stderr versionString' case globalReExecVersion global of Just expectVersion -> do expectVersion' <- parseVersionThrowing expectVersion unless (checkVersion MatchMinor expectVersion' stackVersion) $ throwIO $ InvalidReExecVersion expectVersion showStackVersion _ -> pure () withRunnerGlobal global $ run `catches` [ Handler handleExitCode , Handler handlePrettyException , Handler handleSomeException ] -- | Change the character encoding of the given Handle to transliterate on -- unsupported characters instead of throwing an exception hSetTranslit :: Handle -> IO () hSetTranslit h = do menc <- hGetEncoding h case fmap textEncodingName menc of Just name | '/' `notElem` name -> do enc' <- mkTextEncoding $ name ++ "//TRANSLIT" hSetEncoding h enc' _ -> pure () -- | Handle ExitCode exceptions. handleExitCode :: ExitCode -> RIO Runner a handleExitCode = exitWith -- | Handle PrettyException exceptions. handlePrettyException :: PrettyException -> RIO Runner a handlePrettyException e = do -- The code below loads the entire Stack configuration, when all that is -- needed are the Stack colours. A tailored approach may be better. result <- tryAny $ withConfig NoReexec $ prettyError $ pretty e case result of -- Falls back to the command line's Stack colours if there is any error in -- loading the entire Stack configuration. Left _ -> prettyError $ pretty e Right _ -> pure () exitFailure -- | Handle SomeException exceptions. This special handler stops "stack: " from -- being printed before the exception. handleSomeException :: SomeException -> RIO Runner a handleSomeException (SomeException e) = do logError $ fromString $ displayException e exitFailure -- Vertically combine only the error component of the first argument with the -- error component of the second. vcatErrorHelp :: ParserHelp -> ParserHelp -> ParserHelp vcatErrorHelp h1 h2 = h2 { helpError = vcatChunks [helpError h2, helpError h1] } commandLineHandler :: FilePath -> String -> Bool -> IO (GlobalOptsMonoid, RIO Runner ()) commandLineHandler currentDir progName isInterpreter = complicatedOptions stackVersion (Just versionString') hpackVersion "stack - The Haskell Tool Stack" "" "Stack's documentation is available at https://docs.haskellstack.org/. \ \Command 'stack COMMAND --help' for help about a Stack command. Stack also \ \supports the Haskell Error Index at https://errors.haskell.org/." (globalOpts OuterGlobalOpts) (Just failureCallback) addCommands where failureCallback f args = case L.stripPrefix "Invalid argument" (fst (renderFailure f "")) of Just _ -> if isInterpreter then parseResultHandler args f else secondaryCommandHandler args f >>= interpreterHandler currentDir args Nothing -> parseResultHandler args f parseResultHandler args f = if isInterpreter then do let hlp = errorHelp $ stringChunk (unwords ["Error executing interpreter command:" , progName , unwords args]) handleParseResult (overFailure (vcatErrorHelp hlp) (Failure f)) else handleParseResult (Failure f) addCommands = do unless isInterpreter $ do addBuildCommand' "build" "Build the package(s) in this directory/configuration" buildCmd (buildOptsParser Build) addBuildCommand' "install" "Shortcut for 'build --copy-bins'" buildCmd (buildOptsParser Install) addCommand' "uninstall" "Show how to uninstall Stack. This command does not itself uninstall \ \Stack." uninstallCmd (pure ()) addBuildCommand' "test" "Shortcut for 'build --test'" buildCmd (buildOptsParser Test) addBuildCommand' "bench" "Shortcut for 'build --bench'" buildCmd (buildOptsParser Bench) addBuildCommand' "haddock" "Shortcut for 'build --haddock'" buildCmd (buildOptsParser Haddock) addCommand' "new" "Create a new project from a template. Run 'stack templates' to see \ \available templates. Will also initialise if there is no stack.yaml \ \file. Note: you can also specify a local file or a remote URL as a \ \template; or force an initialisation." newCmd newOptsParser addCommand' "templates" "Show how to find templates available for 'stack new'. 'stack new' \ \can accept a template from a remote repository (default: github), \ \local file or remote URL. Note: this downloads the help file." templatesCmd (pure ()) addCommand' "init" "Create Stack project configuration from Cabal or Hpack package \ \specifications" initCmd initOptsParser addCommand' "setup" "Get the appropriate GHC for your project" setupCmd setupParser addCommand' "path" "Print out handy path information" Stack.Path.path Stack.Path.pathParser addCommand' "ls" "List command. (Supports snapshots, dependencies, Stack's styles and \ \installed tools)" lsCmd lsParser addCommand' "unpack" "Unpack one or more packages locally" unpackCmd ( (,) <$> some (strArgument $ metavar "PACKAGE") <*> optional (textOption ( long "to" <> help "Optional path to unpack the package into (will \ \unpack into subdirectory)" )) ) addCommand' "update" "Update the package index" updateCmd (pure ()) addCommand'' "upgrade" "Upgrade Stack, installing to Stack's local-bin directory and, if \ \different and permitted, the directory of the current Stack \ \executable" upgradeCmd "Warning: if you use GHCup to install Stack, use only GHCup to \ \upgrade Stack." upgradeOpts addCommand' "upload" "Upload a package to Hackage" uploadCmd uploadOptsParser addCommand' "sdist" "Create source distribution tarballs" sdistCmd sdistOptsParser addCommand' "dot" "Visualize your project's dependency graph using Graphviz dot" dot (dotOptsParser False) -- Default for --external is False. addCommand' "ghc" "Run ghc" execCmd (execOptsParser $ Just ExecGhc) addCommand' "hoogle" "Run hoogle, the Haskell API search engine. Use the '-- ARGUMENT(S)' \ \syntax to pass Hoogle arguments, e.g. 'stack hoogle -- --count=20', \ \or 'stack hoogle -- server --local'." hoogleCmd ( (,,,) <$> many (strArgument ( metavar "-- ARGUMENT(S) (e.g. 'stack hoogle -- server --local')" )) <*> boolFlags True "setup" "If needed: install hoogle, build haddocks and \ \generate a hoogle database" idm <*> switch ( long "rebuild" <> help "Rebuild the hoogle database" ) <*> switch ( long "server" <> help "Start local Hoogle server" ) ) -- These are the only commands allowed in interpreter mode as well addCommand' "exec" "Execute a command. If the command is absent, the first of any \ \arguments is taken as the command." execCmd (execOptsParser Nothing) addCommand' "run" "Build and run an executable. Defaults to the first available \ \executable if none is provided as the first argument." execCmd (execOptsParser $ Just ExecRun) addGhciCommand' "ghci" "Run ghci in the context of package(s) (experimental)" ghciCmd ghciOptsParser addGhciCommand' "repl" "Run ghci in the context of package(s) (experimental) (alias for \ \'ghci')" ghciCmd ghciOptsParser addCommand' "runghc" "Run runghc" execCmd (execOptsParser $ Just ExecRunGhc) addCommand' "runhaskell" "Run runghc (alias for 'runghc')" execCmd (execOptsParser $ Just ExecRunGhc) addCommand "script" "Run a Stack Script" globalFooter scriptCmd ( \so gom -> gom { globalMonoidResolverRoot = First $ Just $ takeDirectory $ soFile so } ) (globalOpts OtherCmdGlobalOpts) scriptOptsParser unless isInterpreter $ do addCommand' "eval" "Evaluate some haskell code inline. Shortcut for 'stack exec ghc -- \ \-e CODE'" evalCmd (evalOptsParser "CODE") addCommand' "clean" "Delete build artefacts for the project packages." cleanCmd (cleanOptsParser Clean) addCommand' "purge" "Delete the project Stack working directories (.stack-work by \ \default). Shortcut for 'stack clean --full'" cleanCmd (cleanOptsParser Purge) addCommand' "query" "Query general build information (experimental)" queryCmd (many $ strArgument $ metavar "SELECTOR...") addCommand' "list" "List package id's in snapshot (experimental)" listCmd (many $ strArgument $ metavar "PACKAGE") addSubCommands' "ide" "IDE-specific commands" ( let outputFlag = flag IDE.OutputLogInfo IDE.OutputStdout ( long "stdout" <> help "Send output to stdout instead of the default, stderr" ) cabalFileFlag = flag IDE.ListPackageNames IDE.ListPackageCabalFiles ( long "cabal-files" <> help "Print paths to package cabal-files instead of \ \package names" ) in do addCommand' "packages" "List all available local loadable packages" idePackagesCmd ((,) <$> outputFlag <*> cabalFileFlag) addCommand' "targets" "List all available Stack targets" ideTargetsCmd outputFlag ) addSubCommands' Docker.dockerCmdName "Subcommands specific to Docker use" ( do addCommand' Docker.dockerPullCmdName "Pull latest version of Docker image from registry" dockerPullCmd (pure ()) addCommand' "reset" "Reset the Docker sandbox" dockerResetCmd ( switch ( long "keep-home" <> help "Do not delete sandbox's home directory" ) ) ) addSubCommands' ConfigCmd.cfgCmdName "Subcommands for accessing and modifying configuration values" ( do addCommand' ConfigCmd.cfgCmdSetName "Sets a key in YAML configuration file to value" (withConfig NoReexec . cfgCmdSet) configCmdSetParser addCommand' ConfigCmd.cfgCmdEnvName "Print environment variables for use in a shell" (withConfig YesReexec . withDefaultEnvConfig . cfgCmdEnv) configCmdEnvParser ) addSubCommands' "hpc" "Subcommands specific to Haskell Program Coverage" ( addCommand' "report" "Generate unified HPC coverage report from tix files and project \ \targets" hpcReportCmd hpcReportOptsParser ) where -- addCommand hiding global options addCommand' :: String -> String -> (a -> RIO Runner ()) -> Parser a -> AddCommand addCommand' cmd title constr = addCommand cmd title globalFooter constr (\_ gom -> gom) (globalOpts OtherCmdGlobalOpts) -- addCommand with custom footer hiding global options addCommand'' :: String -> String -> (a -> RIO Runner ()) -> String -> Parser a -> AddCommand addCommand'' cmd title constr cmdFooter = addCommand cmd title (globalFooter <> " " <> cmdFooter) constr (\_ gom -> gom) (globalOpts OtherCmdGlobalOpts) addSubCommands' :: String -> String -> AddCommand -> AddCommand addSubCommands' cmd title = addSubCommands cmd title globalFooter (globalOpts OtherCmdGlobalOpts) -- Additional helper that hides global options and shows build options addBuildCommand' :: String -> String -> (a -> RIO Runner ()) -> Parser a -> AddCommand addBuildCommand' cmd title constr = addCommand cmd title globalFooter constr (\_ gom -> gom) (globalOpts BuildCmdGlobalOpts) -- Additional helper that hides global options and shows some ghci options addGhciCommand' :: String -> String -> (a -> RIO Runner ()) -> Parser a -> AddCommand addGhciCommand' cmd title constr = addCommand cmd title globalFooter constr (\_ gom -> gom) (globalOpts GhciCmdGlobalOpts) globalOpts :: GlobalOptsContext -> Parser GlobalOptsMonoid globalOpts kind = extraHelpOption hide progName (Docker.dockerCmdName ++ "*") Docker.dockerHelpOptName <*> extraHelpOption hide progName (Nix.nixCmdName ++ "*") Nix.nixHelpOptName <*> globalOptsParser currentDir kind ( if isInterpreter -- Silent except when errors occur - see #2879 then Just LevelError else Nothing ) where hide = kind /= OuterGlobalOpts -- | fall-through to external executables in `git` style if they exist -- (i.e. `stack something` looks for `stack-something` before -- failing with "Invalid argument `something'") secondaryCommandHandler :: [String] -> ParserFailure ParserHelp -> IO (ParserFailure ParserHelp) secondaryCommandHandler args f = -- don't even try when the argument looks like a path or flag if elem pathSeparator cmd || "-" `L.isPrefixOf` L.head args then pure f else do mExternalExec <- D.findExecutable cmd case mExternalExec of Just ex -> withProcessContextNoLogging $ do -- TODO show the command in verbose mode -- hPutStrLn stderr $ unwords $ -- ["Running", "[" ++ ex, unwords (tail args) ++ "]"] _ <- exec ex (L.tail args) pure f Nothing -> pure $ fmap (vcatErrorHelp (noSuchCmd cmd)) f where -- FIXME this is broken when any options are specified before the command -- e.g. stack --verbosity silent cmd cmd = stackProgName ++ "-" ++ L.head args noSuchCmd name = errorHelp $ stringChunk ("Auxiliary command not found in path `" ++ name ++ "'") interpreterHandler :: Monoid t => FilePath -> [String] -> ParserFailure ParserHelp -> IO (GlobalOptsMonoid, (RIO Runner (), t)) interpreterHandler currentDir args f = do -- args can include top-level config such as --extra-lib-dirs=... (set by -- nix-shell) - we need to find the first argument which is a file, everything -- afterwards is an argument to the script, everything before is an argument -- to Stack (stackArgs, fileArgs) <- spanM (fmap not . D.doesFileExist) args case fileArgs of (file:fileArgs') -> runInterpreterCommand file stackArgs fileArgs' [] -> parseResultHandler (errorCombine (noSuchFile firstArg)) where firstArg = L.head args spanM _ [] = pure ([], []) spanM p xs@(x:xs') = do r <- p x if r then do (ys, zs) <- spanM p xs' pure (x:ys, zs) else pure ([], xs) -- if the first argument contains a path separator then it might be a file, -- or a Stack option referencing a file. In that case we only show the -- interpreter error message and exclude the command related error messages. errorCombine = if pathSeparator `elem` firstArg then overrideErrorHelp else vcatErrorHelp overrideErrorHelp h1 h2 = h2 { helpError = helpError h1 } parseResultHandler fn = handleParseResult (overFailure fn (Failure f)) noSuchFile name = errorHelp $ stringChunk ("File does not exist or is not a regular file `" ++ name ++ "'") runInterpreterCommand path stackArgs fileArgs = do progName <- getProgName iargs <- getInterpreterArgs path let parseCmdLine = commandLineHandler currentDir progName True -- Implicit file arguments are put before other arguments that -- occur after "--". See #3658 cmdArgs = stackArgs ++ case break (== "--") iargs of (beforeSep, []) -> beforeSep ++ ["--"] ++ [path] ++ fileArgs (beforeSep, optSep : afterSep) -> beforeSep ++ [optSep] ++ [path] ++ fileArgs ++ afterSep -- TODO show the command in verbose mode -- hPutStrLn stderr $ unwords $ -- ["Running", "[" ++ progName, unwords cmdArgs ++ "]"] (a,b) <- withArgs cmdArgs parseCmdLine pure (a,(b,mempty)) setupCmd :: SetupCmdOpts -> RIO Runner () setupCmd sco@SetupCmdOpts{..} = withConfig YesReexec $ do installGHC <- view $ configL.to configInstallGHC if installGHC then withBuildConfig $ do (wantedCompiler, compilerCheck, mstack) <- case scoCompilerVersion of Just v -> pure (v, MatchMinor, Nothing) Nothing -> (,,) <$> view wantedCompilerVersionL <*> view (configL.to configCompilerCheck) <*> (Just <$> view stackYamlL) setup sco wantedCompiler compilerCheck mstack else logWarn "The --no-install-ghc flag is inconsistent with 'stack setup'. \ \No action taken." cleanCmd :: CleanOpts -> RIO Runner () cleanCmd = withConfig NoReexec . clean -- | Helper for build and install commands buildCmd :: BuildOptsCLI -> RIO Runner () buildCmd opts = do when (any (("-prof" `elem`) . fromRight [] . parseArgs Escaping) (boptsCLIGhcOptions opts)) $ do throwIO $ PrettyException GHCProfOptionInvalid local (over globalOptsL modifyGO) $ case boptsCLIFileWatch opts of FileWatchPoll -> fileWatchPoll (inner . Just) FileWatch -> fileWatch (inner . Just) NoFileWatch -> inner Nothing where inner :: Maybe (Set (Path Abs File) -> IO ()) -> RIO Runner () inner setLocalFiles = withConfig YesReexec $ withEnvConfig NeedTargets opts $ Stack.Build.build setLocalFiles -- Read the build command from the CLI and enable it to run modifyGO = case boptsCLICommand opts of Test -> set (globalOptsBuildOptsMonoidL.buildOptsMonoidTestsL) (Just True) Haddock -> set (globalOptsBuildOptsMonoidL.buildOptsMonoidHaddockL) (Just True) Bench -> set (globalOptsBuildOptsMonoidL.buildOptsMonoidBenchmarksL) (Just True) Install -> set (globalOptsBuildOptsMonoidL.buildOptsMonoidInstallExesL) (Just True) Build -> id -- Default case is just Build -- | Display help for the uninstall command. uninstallCmd :: () -> RIO Runner () uninstallCmd () = withConfig NoReexec $ do stackRoot <- view stackRootL globalConfig <- view stackGlobalConfigL programsDir <- view $ configL.to configLocalProgramsBase localBinDir <- view $ configL.to configLocalBin let toStyleDoc = style Dir . fromString . toFilePath stackRoot' = toStyleDoc stackRoot globalConfig' = toStyleDoc globalConfig programsDir' = toStyleDoc programsDir localBinDir' = toStyleDoc localBinDir prettyInfo $ vsep [ flow "To uninstall Stack, it should be sufficient to delete:" , hang 4 $ fillSep [flow "(1) the directory containing Stack's tools", "(" <> softbreak <> programsDir' <> softbreak <> ");"] , hang 4 $ fillSep [flow "(2) the Stack root directory", "(" <> softbreak <> stackRoot' <> softbreak <> ");"] , hang 4 $ fillSep [flow "(3) if different, the directory containing ", flow "Stack's global YAML configuration file", "(" <> softbreak <> globalConfig' <> softbreak <> ");", "and"] , hang 4 $ fillSep [flow "(4) the 'stack' executable file (see the output", flow "of command", howToFindStack <> ",", flow "if Stack is on the PATH;", flow "Stack is often installed in", localBinDir' <> softbreak <> ")."] , fillSep [flow "You may also want to delete", style File ".stack-work", flow "directories in any Haskell projects that you have built."] ] where styleShell = style Shell howToFindStack | osIsWindows = styleShell "where.exe stack" | otherwise = styleShell "which stack" -- | Unpack packages to the filesystem unpackCmd :: ([String], Maybe Text) -> RIO Runner () unpackCmd (names, Nothing) = unpackCmd (names, Just ".") unpackCmd (names, Just dstPath) = withConfig NoReexec $ do mresolver <- view $ globalOptsL.to globalResolver mSnapshot <- forM mresolver $ \resolver -> do concrete <- makeConcreteResolver resolver loc <- completeSnapshotLocation concrete loadSnapshot loc dstPath' <- resolveDir' $ T.unpack dstPath unpackPackages mSnapshot dstPath' names -- | Update the package index updateCmd :: () -> RIO Runner () updateCmd () = withConfig NoReexec (void (updateHackageIndex Nothing)) upgradeCmd :: UpgradeOpts -> RIO Runner () upgradeCmd upgradeOpts' = do go <- view globalOptsL case globalResolver go of Just _ -> throwIO $ PrettyException ResolverOptionInvalid Nothing -> withGlobalProject $ upgrade maybeGitHash upgradeOpts' -- | Upload to Hackage uploadCmd :: UploadOpts -> RIO Runner () uploadCmd (UploadOpts (SDistOpts [] _ _ _ _) _) = do prettyErrorL [ flow "To upload the current package, please run" , style Shell "stack upload ." , flow "(with the period at the end)" ] liftIO exitFailure uploadCmd uploadOpts = do let partitionM _ [] = pure ([], []) partitionM f (x:xs) = do r <- f x (as, bs) <- partitionM f xs pure $ if r then (x:as, bs) else (as, x:bs) sdistOpts = uoptsSDistOpts uploadOpts (files, nonFiles) <- liftIO $ partitionM D.doesFileExist (sdoptsDirsToWorkWith sdistOpts) (dirs, invalid) <- liftIO $ partitionM D.doesDirectoryExist nonFiles withConfig YesReexec $ withDefaultEnvConfig $ do unless (null invalid) $ do let invalidList = bulletedList $ map (style File . fromString) invalid prettyErrorL [ style Shell "stack upload" , flow "expects a list of sdist tarballs or package directories." , flow "Can't find:" , line <> invalidList ] exitFailure when (null files && null dirs) $ do prettyErrorL [ style Shell "stack upload" , flow "expects a list of sdist tarballs or package directories, but none were specified." ] exitFailure config <- view configL let hackageUrl = T.unpack $ configHackageBaseUrl config uploadVariant = uoptsUploadVariant uploadOpts getCreds <- memoizeRef $ Upload.loadAuth config mapM_ (resolveFile' >=> checkSDistTarball sdistOpts) files forM_ files $ \file -> do tarFile <- resolveFile' file creds <- runMemoized getCreds Upload.upload hackageUrl creds (toFilePath tarFile) uploadVariant forM_ dirs $ \dir -> do pkgDir <- resolveDir' dir (tarName, tarBytes, mcabalRevision) <- getSDistTarball (sdoptsPvpBounds sdistOpts) pkgDir checkSDistTarball' sdistOpts tarName tarBytes creds <- runMemoized getCreds Upload.uploadBytes hackageUrl creds tarName uploadVariant tarBytes forM_ mcabalRevision $ uncurry $ Upload.uploadRevision hackageUrl creds sdistCmd :: SDistOpts -> RIO Runner () sdistCmd sdistOpts = withConfig YesReexec $ withDefaultEnvConfig $ do -- If no directories are specified, build all sdist tarballs. dirs' <- if null (sdoptsDirsToWorkWith sdistOpts) then do dirs <- view $ buildConfigL.to (map ppRoot . Map.elems . smwProject . bcSMWanted) when (null dirs) $ do stackYaml <- view stackYamlL prettyErrorL [ style Shell "stack sdist" , flow "expects a list of targets, and otherwise defaults to all of the project's packages." , flow "However, the configuration at" , pretty stackYaml , flow "contains no packages, so no sdist tarballs will be generated." ] exitFailure pure dirs else mapM resolveDir' (sdoptsDirsToWorkWith sdistOpts) forM_ dirs' $ \dir -> do (tarName, tarBytes, _mcabalRevision) <- getSDistTarball (sdoptsPvpBounds sdistOpts) dir distDir <- distDirFromDir dir tarPath <- (distDir ) <$> parseRelFile tarName ensureDir (parent tarPath) runConduitRes $ sourceLazy tarBytes .| sinkFileCautious (toFilePath tarPath) prettyInfoL [flow "Wrote sdist tarball to", pretty tarPath] checkSDistTarball sdistOpts tarPath forM_ (sdoptsTarPath sdistOpts) $ copyTarToTarPath tarPath tarName where copyTarToTarPath tarPath tarName targetDir = liftIO $ do let targetTarPath = targetDir FP. tarName D.createDirectoryIfMissing True $ FP.takeDirectory targetTarPath D.copyFile (toFilePath tarPath) targetTarPath -- | Execute a command. execCmd :: ExecOpts -> RIO Runner () execCmd ExecOpts {..} = withConfig YesReexec $ withEnvConfig AllowNoTargets boptsCLI $ do unless (null targets) $ Stack.Build.build Nothing config <- view configL menv <- liftIO $ configProcessContextSettings config eoEnvSettings withProcessContext menv $ do -- Add RTS options to arguments let argsWithRts args = if null eoRtsOptions then args :: [String] else args ++ ["+RTS"] ++ eoRtsOptions ++ ["-RTS"] (cmd, args) <- case (eoCmd, argsWithRts eoArgs) of (ExecCmd cmd, args) -> pure (cmd, args) (ExecRun, args) -> getRunCmd args (ExecGhc, args) -> getGhcCmd eoPackages args (ExecRunGhc, args) -> getRunGhcCmd eoPackages args runWithPath eoCwd $ exec cmd args where ExecOptsExtra {..} = eoExtra targets = concatMap words eoPackages boptsCLI = defaultBuildOptsCLI { boptsCLITargets = map T.pack targets } -- return the package-id of the first package in GHC_PACKAGE_PATH getPkgId name = do pkg <- getGhcPkgExe mId <- findGhcPkgField pkg [] name "id" case mId of Just i -> pure (L.head $ words (T.unpack i)) -- should never happen as we have already installed the packages _ -> throwIO $ PrettyException (PackageIdNotFoundBug name) getPkgOpts pkgs = map ("-package-id=" ++) <$> mapM getPkgId pkgs getRunCmd args = do packages <- view $ buildConfigL.to (smwProject . bcSMWanted) pkgComponents <- for (Map.elems packages) ppComponents let executables = filter isCExe $ concatMap Set.toList pkgComponents let (exe, args') = case args of [] -> (firstExe, args) x:xs -> case L.find (\y -> y == CExe (T.pack x)) executables of Nothing -> (firstExe, args) argExe -> (argExe, xs) where firstExe = listToMaybe executables case exe of Just (CExe exe') -> do withNewLocalBuildTargets [T.cons ':' exe'] $ Stack.Build.build Nothing pure (T.unpack exe', args') _ -> throwIO $ PrettyException ExecutableToRunNotFound getGhcCmd pkgs args = do pkgopts <- getPkgOpts pkgs compiler <- view $ compilerPathsL.to cpCompiler pure (toFilePath compiler, pkgopts ++ args) getRunGhcCmd pkgs args = do pkgopts <- getPkgOpts pkgs interpret <- view $ compilerPathsL.to cpInterpreter pure (toFilePath interpret, pkgopts ++ args) runWithPath :: Maybe FilePath -> RIO EnvConfig () -> RIO EnvConfig () runWithPath path callback = case path of Nothing -> callback Just p | not (isValid p) -> throwIO $ InvalidPathForExec p Just p -> withUnliftIO $ \ul -> D.withCurrentDirectory p $ unliftIO ul callback -- | Evaluate some haskell code inline. evalCmd :: EvalOpts -> RIO Runner () evalCmd EvalOpts {..} = execCmd execOpts where execOpts = ExecOpts { eoCmd = ExecGhc , eoArgs = ["-e", evalArg] , eoExtra = evalExtra } -- | Run GHCi in the context of a project. ghciCmd :: GhciOpts -> RIO Runner () ghciCmd ghciOpts = let boptsCLI = defaultBuildOptsCLI -- using only additional packages, targets then get overridden in `ghci` { boptsCLITargets = map T.pack (ghciAdditionalPackages ghciOpts) , boptsCLIInitialBuildSteps = True , boptsCLIFlags = ghciFlags ghciOpts , boptsCLIGhcOptions = map T.pack (ghciGhcOptions ghciOpts) } in withConfig YesReexec $ withEnvConfig AllowNoTargets boptsCLI $ do bopts <- view buildOptsL -- override env so running of tests and benchmarks is disabled let boptsLocal = bopts { boptsTestOpts = (boptsTestOpts bopts) { toDisableRun = True } , boptsBenchmarkOpts = (boptsBenchmarkOpts bopts) { beoDisableRun = True } } local (set buildOptsL boptsLocal) (ghci ghciOpts) -- | List packages in the project. idePackagesCmd :: (IDE.OutputStream, IDE.ListPackagesCmd) -> RIO Runner () idePackagesCmd = withConfig NoReexec . withBuildConfig . uncurry IDE.listPackages -- | List targets in the project. ideTargetsCmd :: IDE.OutputStream -> RIO Runner () ideTargetsCmd = withConfig NoReexec . withBuildConfig . IDE.listTargets -- | Pull the current Docker image. dockerPullCmd :: () -> RIO Runner () dockerPullCmd () = withConfig NoReexec $ Docker.preventInContainer Docker.pull -- | Reset the Docker sandbox. dockerResetCmd :: Bool -> RIO Runner () dockerResetCmd = withConfig NoReexec . Docker.preventInContainer . Docker.reset -- | Project initialization initCmd :: InitOpts -> RIO Runner () initCmd initOpts = do pwd <- getCurrentDir go <- view globalOptsL withGlobalProject $ withConfig YesReexec (initProject pwd initOpts (globalResolver go)) -- | Create a project directory structure and initialize the Stack config. newCmd :: (NewOpts, InitOpts) -> RIO Runner () newCmd (newOpts, initOpts) = withGlobalProject $ withConfig YesReexec $ do dir <- new newOpts (forceOverwrite initOpts) exists <- doesFileExist $ dir stackDotYaml when (forceOverwrite initOpts || not exists) $ do go <- view globalOptsL initProject dir initOpts (globalResolver go) -- | Display instructions for how to use templates templatesCmd :: () -> RIO Runner () templatesCmd () = withConfig NoReexec templatesHelp -- | Query build information queryCmd :: [String] -> RIO Runner () queryCmd selectors = withConfig YesReexec $ withDefaultEnvConfig $ queryBuildInfo $ map T.pack selectors -- | List packages listCmd :: [String] -> RIO Runner () listCmd names = withConfig NoReexec $ do mresolver <- view $ globalOptsL.to globalResolver mSnapshot <- forM mresolver $ \resolver -> do concrete <- makeConcreteResolver resolver loc <- completeSnapshotLocation concrete loadSnapshot loc listPackages mSnapshot names -- | generate a combined HPC report hpcReportCmd :: HpcReportOpts -> RIO Runner () hpcReportCmd hropts = do let (tixFiles, targetNames) = L.partition (".tix" `T.isSuffixOf`) (hroptsInputs hropts) boptsCLI = defaultBuildOptsCLI { boptsCLITargets = if hroptsAll hropts then [] else targetNames } withConfig YesReexec $ withEnvConfig AllowNoTargets boptsCLI $ generateHpcReportForTargets hropts tixFiles targetNames stack-2.9.3.1/src/main/BuildInfo.hs0000644000000000000000000000532014445022466015110 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} #ifdef USE_GIT_INFO {-# LANGUAGE TemplateHaskell #-} #endif -- Extracted from Main so that the Main module does not use CPP or TH, -- and therefore doesn't need to be recompiled as often. module BuildInfo ( versionString' , maybeGitHash , hpackVersion ) where #ifndef HIDE_DEP_VERSIONS import qualified Build_stack #endif #ifdef USE_GIT_INFO import Data.Version ( versionBranch ) #else import Data.Version ( showVersion, versionBranch ) #endif import Distribution.System ( buildArch ) import qualified Distribution.Text as Cabal ( display ) #ifdef USE_GIT_INFO import GitHash ( giCommitCount, giHash, tGitInfoCwdTry ) #endif #ifdef USE_GIT_INFO import Options.Applicative.Simple ( simpleVersion ) #endif import Stack.Prelude import qualified Paths_stack as Meta versionString' :: String #ifdef USE_GIT_INFO versionString' = concat $ concat [ [$(simpleVersion Meta.version)] -- Leave out number of commits for --depth=1 clone -- See https://github.com/commercialhaskell/stack/issues/792 , case giCommitCount <$> $$tGitInfoCwdTry of Left _ -> [] Right 1 -> [] Right count -> [" (", show count, " commits)"] , [afterVersion] ] #else versionString' = showStackVersion ++ afterVersion #endif where afterVersion = concat [ preReleaseString , ' ' : Cabal.display buildArch , depsString , warningString ] preReleaseString = case versionBranch Meta.version of (_:y:_) | even y -> " PRE-RELEASE" (_:_:z:_) | even z -> " RELEASE-CANDIDATE" _ -> "" #ifdef HIDE_DEP_VERSIONS depsString = " hpack-" ++ VERSION_hpack #else depsString = "\nCompiled with:\n" ++ unlines (map ("- " ++) Build_stack.deps) #endif #ifdef SUPPORTED_BUILD warningString = "" #else warningString = unlines [ "" , "Warning: this is an unsupported build that may use different versions of" , "dependencies and GHC than the officially released binaries, and therefore may" , "not behave identically. If you encounter problems, please try the latest" , "official build by running 'stack upgrade --force-download'." ] #endif -- | If USE_GIT_INFO is enabled, the Git hash in the build directory, otherwise Nothing. maybeGitHash :: Maybe String maybeGitHash = #ifdef USE_GIT_INFO (either (const Nothing) (Just . giHash) $$tGitInfoCwdTry) #else Nothing #endif -- | Hpack version we're compiled against hpackVersion :: String hpackVersion = VERSION_hpack stack-2.9.3.1/src/test/Spec.hs0000644000000000000000000000005514445022466014162 0ustar0000000000000000{-# OPTIONS_GHC -F -pgmF hspec-discover #-} stack-2.9.3.1/src/test/Stack/ArgsSpec.hs0000644000000000000000000001422014445022466016043 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} -- | Args parser test suite. module Stack.ArgsSpec where import Control.Monad import Data.Attoparsec.Args ( EscapingMode (..), parseArgsFromString ) import Data.Attoparsec.Interpreter ( interpreterArgsParser ) import qualified Data.Attoparsec.Text as P import Data.Text ( pack ) import Stack.Prelude import Test.Hspec import Prelude ( head ) -- | Test spec. spec :: Spec spec = do argsSpec interpreterArgsSpec argsSpec :: Spec argsSpec = forM_ argsInputOutput (\(input,output) -> it input (parseArgsFromString Escaping input == output)) -- | Fairly comprehensive checks. argsInputOutput :: [(String, Either String [String])] argsInputOutput = [ ("x", Right ["x"]) , ("x y z", Right ["x", "y", "z"]) , ("aaa bbb ccc", Right ["aaa", "bbb", "ccc"]) , (" aaa bbb ccc ", Right ["aaa", "bbb", "ccc"]) , ("aaa\"", Left "unterminated string: endOfInput") , ("\"", Left "unterminated string: endOfInput") , ("\"\"", Right [""]) , ("\"aaa", Left "unterminated string: endOfInput") , ("\"aaa\" bbb ccc \"ddd\"", Right ["aaa", "bbb", "ccc", "ddd"]) , ("\"aa\\\"a\" bbb ccc \"ddd\"", Right ["aa\"a", "bbb", "ccc", "ddd"]) , ("\"aa\\\"a\" bb\\b ccc \"ddd\"", Right ["aa\"a", "bb\\b", "ccc", "ddd"]) , ("\"\" \"\" c", Right ["","","c"])] interpreterArgsSpec :: Spec interpreterArgsSpec = describe "Script interpreter parser" $ do describe "Success cases" $ do describe "Line comments" $ do checkLines "" checkLines " --x" checkLines " --x --y" describe "Literate line comments" $ do checkLiterateLines "" checkLiterateLines " --x" checkLiterateLines " --x --y" describe "Block comments" $ do checkBlocks "" checkBlocks "\n" checkBlocks " --x" checkBlocks "\n--x" checkBlocks " --x --y" checkBlocks "\n--x\n--y" checkBlocks "\n\t--x\n\t--y" describe "Literate block comments" $ do checkLiterateBlocks "" "" checkLiterateBlocks "\n>" "" checkLiterateBlocks " --x" " --x" checkLiterateBlocks "\n>--x" "--x" checkLiterateBlocks " --x --y " "--x --y" checkLiterateBlocks "\n>--x\n>--y" "--x --y" checkLiterateBlocks "\n>\t--x\n>\t--y" "--x --y" describe "Failure cases" $ do checkFailures describe "Bare directives in literate files" $ do forM_ (interpreterGenValid lineComment []) $ testAndCheck (acceptFailure True) [] forM_ (interpreterGenValid blockComment []) $ testAndCheck (acceptFailure True) [] where parse isLiterate s = P.parseOnly (interpreterArgsParser isLiterate stackProgName) (pack s) acceptSuccess :: Bool -> String -> String -> Bool acceptSuccess isLiterate args s = case parse isLiterate s of Right x | words x == words args -> True _ -> False acceptFailure isLiterate _ s = case parse isLiterate s of Left _ -> True Right _ -> False testAndCheck checker out inp = it (show inp) $ checker out inp checkLines args = forM_ (interpreterGenValid lineComment args) (testAndCheck (acceptSuccess False) args) checkLiterateLines args = forM_ (interpreterGenValid literateLineComment args) (testAndCheck (acceptSuccess True) args) checkBlocks args = forM_ (interpreterGenValid blockComment args) (testAndCheck (acceptSuccess False) args) checkLiterateBlocks inp args = forM_ (interpreterGenValid literateBlockComment inp) (testAndCheck (acceptSuccess True) args) checkFailures = forM_ interpreterGenInvalid (testAndCheck (acceptFailure False) "unused") -- Generate a set of acceptable inputs for given format and args interpreterGenValid fmt args = shebang <++> newLine <++> fmt args interpreterGenInvalid :: [String] -- Generate a set of Invalid inputs interpreterGenInvalid = ["-stack\n"] -- random input -- just the shebang <|> shebang <++> ["\n"] -- invalid shebang <|> blockSpace <++> [head (interpreterGenValid lineComment args)] -- something between shebang and Stack comment <|> shebang <++> newLine <++> blockSpace <++> ([head (lineComment args)] <|> [head (blockComment args)]) -- unterminated block comment -- just chop the closing chars from a valid block comment <|> shebang <++> ["\n"] <++> let c = head (blockComment args) l = length c - 2 in [assert (drop l c == "-}") (take l c)] -- nested block comment <|> shebang <++> ["\n"] <++> [head (blockComment "--x {- nested -} --y")] where args = " --x --y" (<++>) = liftA2 (++) -- Generative grammar for the interpreter comments shebang = ["#!/usr/bin/env stack"] newLine = ["\n"] <|> ["\r\n"] -- A comment may be the last line or followed by something else postComment = [""] <|> newLine -- A command starts with zero or more whitespace followed by "stack" makeComment maker space args = let makePrefix s = (s <|> [""]) <++> [stackProgName] in (maker <$> (makePrefix space <++> [args])) <++> postComment lineSpace = [" "] <|> ["\t"] lineComment = makeComment makeLine lineSpace where makeLine s = "--" ++ s literateLineComment = makeComment ("> --" ++) lineSpace blockSpace = lineSpace <|> newLine blockComment = makeComment makeBlock blockSpace where makeBlock s = "{-" ++ s ++ "-}" literateBlockComment = makeComment (\s -> "> {-" ++ s ++ "-}") (lineSpace <|> map (++ ">") newLine) stack-2.9.3.1/src/test/Stack/Build/ExecuteSpec.hs0000644000000000000000000000031014445022466017603 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module Stack.Build.ExecuteSpec (main, spec) where import Stack.Prelude import Test.Hspec main :: IO () main = hspec spec spec :: Spec spec = pure () stack-2.9.3.1/src/test/Stack/Build/TargetSpec.hs0000644000000000000000000000227714445022466017445 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Build.TargetSpec (main, spec) where import qualified Data.Text as T import Distribution.Types.PackageName (mkPackageName) import Distribution.Version (mkVersion) import Stack.Build.Target import Stack.Prelude import Stack.Types.NamedComponent import Test.Hspec main :: IO () main = hspec spec spec :: Spec spec = do describe "parseRawTarget" $ do let test s e = it s $ parseRawTarget (T.pack s) `shouldBe` e test "foobar" $ Just $ RTPackage (mkPackageName "foobar") test "foobar-1.2.3" $ Just $ RTPackageIdentifier $ PackageIdentifier (mkPackageName "foobar") (mkVersion [1, 2, 3]) test "./foobar" Nothing test "foobar/" Nothing test "/foobar" Nothing test ":some-exe" $ Just $ RTComponent "some-exe" test "foobar:some-exe" $ Just $ RTPackageComponent (mkPackageName "foobar") $ UnresolvedComponent "some-exe" test "foobar:exe:some-exe" $ Just $ RTPackageComponent (mkPackageName "foobar") $ ResolvedComponent $ CExe "some-exe" stack-2.9.3.1/src/test/Stack/Config/DockerSpec.hs0000644000000000000000000000143114445022466017563 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.Config.DockerSpec (spec) where import Test.Hspec import Stack.Prelude import Stack.Types.Resolver import RIO.Time (fromGregorian) import Stack.Config.Docker (addDefaultTag) spec :: Spec spec = do describe "addDefaultTag" $ do it "succeeds fails no resolver" $ addDefaultTag "foo/bar" Nothing Nothing `shouldBe` Nothing it "succeeds on LTS" $ addDefaultTag "foo/bar" Nothing (Just $ ARResolver $ RSLSynonym $ LTS 1 2) `shouldBe` Just "foo/bar:lts-1.2" it "fails on nightly" $ addDefaultTag "foo/bar" Nothing (Just $ ARResolver $ RSLSynonym $ Nightly $ fromGregorian 2018 1 1) `shouldBe` Nothing stack-2.9.3.1/src/test/Stack/ConfigSpec.hs0000644000000000000000000002144014445022466016356 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Stack.ConfigSpec where import Control.Arrow import Distribution.Verbosity (verbose) import Pantry.Internal.AesonExtended import Data.Yaml import Pantry.Internal (pcHpackExecutable) import Path import Path.IO hiding (withSystemTempDir) import Stack.Config import Stack.Prelude import Stack.Runners import Stack.Types.Config import Stack.Options.GlobalParser (globalOptsFromMonoid) import System.Directory import System.Environment import System.IO (writeFile) import Test.Hspec sampleConfig :: String sampleConfig = "resolver: lts-19.22\n" ++ "packages: ['.']\n" buildOptsConfig :: String buildOptsConfig = "resolver: lts-19.22\n" ++ "packages: ['.']\n" ++ "build:\n" ++ " library-profiling: true\n" ++ " executable-profiling: true\n" ++ " haddock: true\n" ++ " haddock-deps: true\n" ++ " copy-bins: true\n" ++ " prefetch: true\n" ++ " force-dirty: true\n" ++ " keep-going: true\n" ++ " keep-tmp-files: true\n" ++ " test: true\n" ++ " test-arguments:\n" ++ " rerun-tests: true\n" ++ " additional-args: ['-fprof']\n" ++ " coverage: true\n" ++ " no-run-tests: true\n" ++ " bench: true\n" ++ " benchmark-opts:\n" ++ " benchmark-arguments: -O2\n" ++ " no-run-benchmarks: true\n" ++ " reconfigure: true\n" ++ " cabal-verbose: true\n" hpackConfig :: String hpackConfig = "resolver: lts-19.22\n" ++ "with-hpack: /usr/local/bin/hpack\n" ++ "packages: ['.']\n" resolverConfig :: String resolverConfig = "resolver: lts-19.22\n" ++ "packages: ['.']\n" snapshotConfig :: String snapshotConfig = "snapshot: lts-19.22\n" ++ "packages: ['.']\n" resolverSnapshotConfig :: String resolverSnapshotConfig = "resolver: lts-19.22\n" ++ "snapshot: lts-19.22\n" ++ "packages: ['.']\n" stackDotYaml :: Path Rel File stackDotYaml = either impureThrow id (parseRelFile "stack.yaml") setup :: IO () setup = unsetEnv "STACK_YAML" noException :: Selector SomeException noException = const False spec :: Spec spec = beforeAll setup $ do let logLevel = LevelOther "silent" -- TODO(danburton): not use inTempDir let inTempDir action = do currentDirectory <- getCurrentDirectory withSystemTempDirectory "Stack_ConfigSpec" $ \tempDir -> do let enterDir = setCurrentDirectory tempDir let exitDir = setCurrentDirectory currentDirectory bracket_ enterDir exitDir action -- TODO(danburton): a safer version of this? let withEnvVar name newValue action = do originalValue <- fromMaybe "" <$> lookupEnv name let setVar = setEnv name newValue let resetVar = setEnv name originalValue bracket_ setVar resetVar action describe "parseProjectAndConfigMonoid" $ do let loadProject' fp inner = do globalOpts <- globalOptsFromMonoid False mempty withRunnerGlobal globalOpts { globalLogLevel = logLevel } $ do iopc <- loadConfigYaml ( parseProjectAndConfigMonoid (parent fp) ) fp ProjectAndConfigMonoid project _ <- liftIO iopc liftIO $ inner project toAbsPath path = do parentDir <- getCurrentDirectory >>= parseAbsDir pure (parentDir path) loadProject config inner = do yamlAbs <- toAbsPath stackDotYaml writeFile (toFilePath yamlAbs) config loadProject' yamlAbs inner it "parses snapshot using 'resolver'" $ inTempDir $ do loadProject resolverConfig $ \Project{..} -> projectResolver `shouldBe` RSLSynonym (LTS 19 22) it "parses snapshot using 'snapshot'" $ inTempDir $ do loadProject snapshotConfig $ \Project{..} -> projectResolver `shouldBe` RSLSynonym (LTS 19 22) it "throws if both 'resolver' and 'snapshot' are present" $ inTempDir $ do loadProject resolverSnapshotConfig (const (pure ())) `shouldThrow` anyException describe "loadConfig" $ do let loadConfig' inner = do globalOpts <- globalOptsFromMonoid False mempty withRunnerGlobal globalOpts { globalLogLevel = logLevel } $ loadConfig inner -- TODO(danburton): make sure parent dirs also don't have config file it "works even if no config file exists" $ example $ loadConfig' $ const $ pure () it "works with a blank config file" $ inTempDir $ do writeFile (toFilePath stackDotYaml) "" -- TODO(danburton): more specific test for exception loadConfig' (const (pure ())) `shouldThrow` anyException let configOverrideHpack = pcHpackExecutable . view pantryConfigL it "parses config option with-hpack" $ inTempDir $ do writeFile (toFilePath stackDotYaml) hpackConfig loadConfig' $ \config -> liftIO $ configOverrideHpack config `shouldBe` HpackCommand "/usr/local/bin/hpack" it "parses config bundled Hpack" $ inTempDir $ do writeFile (toFilePath stackDotYaml) sampleConfig loadConfig' $ \config -> liftIO $ configOverrideHpack config `shouldBe` HpackBundled it "parses build config options" $ inTempDir $ do writeFile (toFilePath stackDotYaml) buildOptsConfig loadConfig' $ \config -> liftIO $ do let BuildOpts{..} = configBuild config boptsLibProfile `shouldBe` True boptsExeProfile `shouldBe` True boptsHaddock `shouldBe` True boptsHaddockDeps `shouldBe` Just True boptsInstallExes `shouldBe` True boptsPreFetch `shouldBe` True boptsKeepGoing `shouldBe` Just True boptsKeepTmpFiles `shouldBe` True boptsForceDirty `shouldBe` True boptsTests `shouldBe` True boptsTestOpts `shouldBe` TestOpts { toRerunTests = True , toAdditionalArgs = ["-fprof"] , toCoverage = True , toDisableRun = True , toMaximumTimeSeconds = Nothing , toAllowStdin = True } boptsBenchmarks `shouldBe` True boptsBenchmarkOpts `shouldBe` BenchmarkOpts { beoAdditionalArgs = Just "-O2" , beoDisableRun = True } boptsReconfigure `shouldBe` True boptsCabalVerbose `shouldBe` CabalVerbosity verbose it "finds the config file in a parent directory" $ inTempDir $ do writeFile "package.yaml" "name: foo" writeFile (toFilePath stackDotYaml) sampleConfig parentDir <- getCurrentDirectory >>= parseAbsDir let childDir = "child" createDirectory childDir setCurrentDirectory childDir loadConfig' $ \config -> liftIO $ do bc <- runRIO config $ withBuildConfig ask view projectRootL bc `shouldBe` parentDir it "respects the STACK_YAML env variable" $ inTempDir $ do withSystemTempDir "config-is-here" $ \dir -> do let stackYamlFp = toFilePath (dir stackDotYaml) writeFile stackYamlFp sampleConfig writeFile (toFilePath dir ++ "/package.yaml") "name: foo" withEnvVar "STACK_YAML" stackYamlFp $ loadConfig' $ \config -> liftIO $ do BuildConfig{..} <- runRIO config $ withBuildConfig ask bcStackYaml `shouldBe` dir stackDotYaml parent bcStackYaml `shouldBe` dir it "STACK_YAML can be relative" $ inTempDir $ do parentDir <- getCurrentDirectory >>= parseAbsDir let childRel = either impureThrow id (parseRelDir "child") yamlRel = childRel either impureThrow id (parseRelFile "some-other-name.config") yamlAbs = parentDir yamlRel packageYaml = childRel either impureThrow id (parseRelFile "package.yaml") createDirectoryIfMissing True $ toFilePath $ parent yamlAbs writeFile (toFilePath yamlAbs) "resolver: ghc-9.0" writeFile (toFilePath packageYaml) "name: foo" withEnvVar "STACK_YAML" (toFilePath yamlRel) $ loadConfig' $ \config -> liftIO $ do BuildConfig{..} <- runRIO config $ withBuildConfig ask bcStackYaml `shouldBe` yamlAbs describe "defaultConfigYaml" $ it "is parseable" $ \_ -> do curDir <- getCurrentDir let parsed :: Either String (Either String (WithJSONWarnings ConfigMonoid)) parsed = parseEither (parseConfigMonoid curDir) <$> left show (decodeEither' defaultConfigYaml) case parsed of Right (Right _) -> pure () :: IO () _ -> fail "Failed to parse default config yaml" stack-2.9.3.1/src/test/Stack/DotSpec.hs0000644000000000000000000001252414445022466015702 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} -- | Test suite for Stack.Dot module Stack.DotSpec where import Data.Functor.Identity import Data.List ((\\)) import qualified Data.Map as Map import qualified Data.Set as Set import Distribution.License (License (BSD3)) import qualified RIO.Text as T import Stack.Prelude hiding (pkgName) import Test.Hspec import Test.Hspec.QuickCheck (prop) import Test.QuickCheck (forAll,choose,Gen) import Stack.Dot dummyPayload :: DotPayload dummyPayload = DotPayload (parseVersion "0.0.0.0") (Just (Right BSD3)) Nothing spec :: Spec spec = do let graph = Map.mapKeys pkgName . fmap (\p -> (Set.map pkgName p, dummyPayload)) . Map.fromList $ [("one",Set.fromList ["base","free"]) ,("two",Set.fromList ["base","free","mtl","transformers","one"]) ] describe "Stack.Dot" $ do it "does nothing if depth is 0" $ resolveDependencies (Just 0) graph stubLoader `shouldBe` pure graph it "with depth 1, more dependencies are resolved" $ do let graph' = Map.insert (pkgName "cycle") (Set.singleton (pkgName "cycle"), dummyPayload) graph resultGraph = runIdentity (resolveDependencies (Just 0) graph stubLoader) resultGraph' = runIdentity (resolveDependencies (Just 1) graph' stubLoader) Map.size resultGraph < Map.size resultGraph' `shouldBe` True it "cycles are ignored" $ do let graph' = Map.insert (pkgName "cycle") (Set.singleton (pkgName "cycle"), dummyPayload) graph resultGraph = resolveDependencies Nothing graph stubLoader resultGraph' = resolveDependencies Nothing graph' stubLoader fmap Map.size resultGraph' `shouldBe` fmap ((+1) . Map.size) resultGraph let graphElem e = Set.member e . Set.unions . Map.elems prop "requested packages are pruned" $ do let resolvedGraph = runIdentity (resolveDependencies Nothing graph stubLoader) allPackages g = Map.keysSet g `Set.union` foldMap fst g forAll (sublistOf (Set.toList (allPackages resolvedGraph))) $ \toPrune -> let pruned = pruneGraph [pkgName "one", pkgName "two"] toPrune resolvedGraph in Set.null (allPackages pruned `Set.intersection` Set.fromList toPrune) prop "pruning removes orphans" $ do let resolvedGraph = runIdentity (resolveDependencies Nothing graph stubLoader) allPackages g = Map.keysSet g `Set.union` foldMap fst g orphans g = Map.filterWithKey (\k _ -> not (graphElem k g)) g forAll (sublistOf (Set.toList (allPackages resolvedGraph))) $ \toPrune -> let pruned = pruneGraph [pkgName "one", pkgName "two"] toPrune resolvedGraph in null (Map.keys (orphans (fmap fst pruned)) \\ [pkgName "one", pkgName "two"]) {- Helper functions below -} -- Backport from QuickCheck 2.8 to 2.7.6 sublistOf :: [a] -> Gen [a] sublistOf = filterM (\_ -> choose (False, True)) -- Unsafe internal helper to create a package name pkgName :: Text -> PackageName pkgName = fromMaybe failure . parsePackageName . T.unpack where failure = error "Internal error during package name creation in DotSpec.pkgName" -- Stub, simulates the function to load package dependencies stubLoader :: PackageName -> Identity (Set PackageName, DotPayload) stubLoader name = pure . (, dummyPayload) . Set.fromList . map pkgName $ case show name of "StateVar" -> ["stm","transformers"] "array" -> [] "bifunctors" -> ["semigroupoids","semigroups","tagged"] "binary" -> ["array","bytestring","containers"] "bytestring" -> ["deepseq","ghc-prim","integer-gmp"] "comonad" -> ["containers","contravariant","distributive" ,"semigroups","tagged","transformers","transformers-compat" ] "cont" -> ["StateVar","semigroups","transformers","transformers-compat","void"] "containers" -> ["array","deepseq","ghc-prim"] "deepseq" -> ["array"] "distributive" -> ["ghc-prim","tagged","transformers","transformers-compat"] "free" -> ["bifunctors","comonad","distributive","mtl" ,"prelude-extras","profunctors","semigroupoids" ,"semigroups","template-haskell","transformers" ] "ghc" -> [] "hashable" -> ["bytestring","ghc-prim","integer-gmp","text"] "integer" -> [] "mtl" -> ["transformers"] "nats" -> [] "one" -> ["free"] "prelude" -> [] "profunctors" -> ["comonad","distributive","semigroupoids","tagged","transformers"] "semigroupoids" -> ["comonad","containers","contravariant","distributive" ,"semigroups","transformers","transformers-compat" ] "semigroups" -> ["bytestring","containers","deepseq","hashable" ,"nats","text","unordered-containers" ] "stm" -> ["array"] "tagged" -> ["template-haskell"] "template" -> [] "text" -> ["array","binary","bytestring","deepseq","ghc-prim","integer-gmp"] "transformers" -> [] "two" -> ["free","mtl","one","transformers"] "unordered" -> ["deepseq","hashable"] "void" -> ["ghc-prim","hashable","semigroups"] _ -> [] stack-2.9.3.1/src/test/Stack/Ghci/PortableFakePaths.hs0000644000000000000000000000051014445022466020542 0ustar0000000000000000{-# LANGUAGE CPP #-} -- | Helpers for writing fake paths for test suite for the GhciScript DSL. -- This must be a separate module because it is used in Template Haskell splices. module Stack.Ghci.PortableFakePaths where defaultDrive :: FilePath #ifdef WINDOWS defaultDrive = "C:\\" #else defaultDrive = "/" #endif stack-2.9.3.1/src/test/Stack/Ghci/ScriptSpec.hs0000644000000000000000000000524614445022466017275 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE TemplateHaskell #-} -- | Test suite for the GhciScript DSL module Stack.Ghci.ScriptSpec where import qualified Data.Set as S import Distribution.ModuleName import Test.Hspec import qualified System.FilePath as FP import Stack.Ghci.PortableFakePaths import Stack.Prelude hiding (fromString) import Path import Path.Extra (pathToLazyByteString) import Stack.Ghci.Script spec :: Spec spec = do describe "GHCi" $ do describe "Script DSL" $ do describe "script" $ do it "should separate commands with a newline" $ do let dir = $(mkAbsDir $ defaultDrive FP. "src" FP. "package-a") script = cmdCdGhc dir <> cmdAdd [Left (fromString "Lib.A")] scriptToLazyByteString script `shouldBe` ":cd-ghc " <> pathToLazyByteString dir <> "\n:add Lib.A\n" describe ":add" $ do it "should not render empty add commands" $ do let script = cmdAdd S.empty scriptToLazyByteString script `shouldBe` "" it "should ensure that a space exists between each module in an add command" $ do let script = cmdAdd (S.fromList [Left (fromString "Lib.A"), Left (fromString "Lib.B")]) scriptToLazyByteString script `shouldBe` ":add Lib.A Lib.B\n" describe ":add (by file)" $ do it "should render a full file path" $ do let file = $(mkAbsFile $ defaultDrive FP. "Users" FP. "someone" FP. "src" FP. "project" FP. "package-a" FP. "src" FP. "Main.hs") script = cmdAdd (S.fromList [Right file]) scriptToLazyByteString script `shouldBe` ":add " <> pathToLazyByteString file <> "\n" describe ":cd-ghc" $ do it "should render a full absolute path" $ do let dir = $(mkAbsDir $ defaultDrive FP. "Users" FP. "someone" FP. "src" FP. "project" FP. "package-a") script = cmdCdGhc dir scriptToLazyByteString script `shouldBe` ":cd-ghc " <> pathToLazyByteString dir <> "\n" describe ":module" $ do it "should render empty module as ':module +'" $ do let script = cmdModule [] scriptToLazyByteString script `shouldBe` ":module +\n" it "should ensure that a space exists between each module in a module command" $ do let script = cmdModule [fromString "Lib.A", fromString "Lib.B"] scriptToLazyByteString script `shouldBe` ":module + Lib.A Lib.B\n" stack-2.9.3.1/src/test/Stack/GhciSpec.hs0000644000000000000000000002276514445022466016036 0ustar0000000000000000-- {-# LANGUAGE NoImplicitPrelude #-} -- {-# LANGUAGE QuasiQuotes #-} -- {-# LANGUAGE TemplateHaskell #-} -- | Test suite for GHCi like applications including both GHCi and Intero. module Stack.GhciSpec where import Test.Hspec spec :: Spec spec = pure () {- Commented out as part of the fix for https://github.com/commercialhaskell/stack/issues/3309 Not sure if maintaining this test is worth the effort. import qualified Data.ByteString.Lazy as LBS import qualified Data.Map as M import qualified Data.Set as S import qualified Data.Text as T import qualified Data.Text.Encoding as T import Distribution.License (License (BSD3)) import qualified Distribution.ModuleName as ModuleName import Distribution.PackageDescription (BuildType(..)) import Stack.Prelude import Stack.Types.Package import Stack.Types.PackageName import Stack.Types.Version import Test.Hspec import NeatInterpolation import Path import Path.Extra (pathToText) import qualified System.FilePath as FP import Stack.Ghci import Stack.Ghci.Script (scriptToLazyByteString) import Stack.Ghci.PortableFakePaths textToLazy :: Text -> LBS.ByteString textToLazy = LBS.fromStrict . T.encodeUtf8 -- | Matches two strings, after converting line-ends in the second to Unix ones -- (in a hacky way) and converting both to the same type. Workaround for -- https://github.com/nikita-volkov/neat-interpolation/issues/14. shouldBeLE :: LBS.ByteString -> Text -> Expectation shouldBeLE actual expected = shouldBe actual (textToLazy $ T.filter (/= '\r') expected) baseProjDir, projDirA, projDirB :: Path Abs Dir baseProjDir = $(mkAbsDir $ defaultDrive FP. "Users" FP. "someone" FP. "src") projDirA = baseProjDir either impureThrow id (parseRelDir "project-a") projDirB = baseProjDir either impureThrow id (parseRelDir "project-b") relFile :: Path Rel File relFile = either impureThrow id (parseRelFile $ "exe" FP. "Main.hs") absFile :: Path Abs File absFile = projDirA relFile projDirAT, projDirBT, relFileT, absFileT :: Text projDirAT = pathToText projDirA projDirBT = pathToText projDirB relFileT = pathToText relFile absFileT = pathToText absFile spec :: Spec spec = do describe "GHCi" $ do describe "Script rendering" $ do describe "should render GHCi scripts" $ do it "with one library package" $ do let res = scriptToLazyByteString $ renderScriptGhci packages_singlePackage Nothing [] res `shouldBeLE` ghciScript_projectWithLib it "with one main package" $ do let res = scriptToLazyByteString $ renderScriptGhci [] (Just absFile) [] res `shouldBeLE` ghciScript_projectWithMain it "with one library and main package" $ do let res = scriptToLazyByteString $ renderScriptGhci packages_singlePackage (Just absFile) [] res `shouldBeLE` ghciScript_projectWithLibAndMain it "with multiple library packages" $ do let res = scriptToLazyByteString $ renderScriptGhci packages_multiplePackages Nothing [] res `shouldBeLE` ghciScript_multipleProjectsWithLib describe "should render intero scripts" $ do it "with one library package" $ do let res = scriptToLazyByteString $ renderScriptIntero packages_singlePackage Nothing [] res `shouldBeLE` interoScript_projectWithLib it "with one main package" $ do let res = scriptToLazyByteString $ renderScriptIntero packages_singlePackage (Just absFile) [] res `shouldBeLE` interoScript_projectWithMain it "with one library and main package" $ do let res = scriptToLazyByteString $ renderScriptIntero packages_singlePackage (Just absFile) [] res `shouldBeLE` interoScript_projectWithLibAndMain it "with multiple library packages" $ do let res = scriptToLazyByteString $ renderScriptIntero packages_multiplePackages Nothing [] res `shouldBeLE` interoScript_multipleProjectsWithLib -- Expected Intero scripts interoScript_projectWithLib :: Text interoScript_projectWithLib = [text| :cd-ghc $projDirAT :add Lib.A :module + Lib.A |] interoScript_projectWithMain :: Text interoScript_projectWithMain = [text| :cd-ghc $projDirAT :add Lib.A :cd-ghc $projDirAT :add $absFileT :module + Lib.A |] interoScript_projectWithLibAndMain :: Text interoScript_projectWithLibAndMain = [text| :cd-ghc $projDirAT :add Lib.A :cd-ghc $projDirAT :add $absFileT :module + Lib.A |] interoScript_multipleProjectsWithLib :: Text interoScript_multipleProjectsWithLib = [text| :cd-ghc $projDirAT :add Lib.A :cd-ghc $projDirBT :add Lib.B :module + Lib.A Lib.B |] -- Expected GHCi Scripts ghciScript_projectWithLib :: Text ghciScript_projectWithLib = [text| :add Lib.A :module + Lib.A |] ghciScript_projectWithMain :: Text ghciScript_projectWithMain = [text| :add $absFileT :module + |] ghciScript_projectWithLibAndMain :: Text ghciScript_projectWithLibAndMain = [text| :add Lib.A :add $absFileT :module + Lib.A |] ghciScript_multipleProjectsWithLib :: Text ghciScript_multipleProjectsWithLib = [text| :add Lib.A :add Lib.B :module + Lib.A Lib.B |] -- Expected Legacy GHCi scripts ghciLegacyScript_projectWithMain :: Text ghciLegacyScript_projectWithMain = [text| :add :add $absFileT :module + |] ghciLegacyScript_projectWithLibAndMain :: Text ghciLegacyScript_projectWithLibAndMain = [text| :add Lib.A :add $absFileT :module + Lib.A |] ghciLegacyScript_multipleProjectsWithLib :: Text ghciLegacyScript_multipleProjectsWithLib = [text| :add Lib.A Lib.B :module + Lib.A Lib.B |] -- Sample GHCi load configs packages_singlePackage :: [GhciPkgInfo] packages_singlePackage = [ GhciPkgInfo { ghciPkgModules = S.fromList [ModuleName.fromString "Lib.A"] , ghciPkgDir = projDirA , ghciPkgName = $(mkPackageName "package-a") , ghciPkgOpts = [] , ghciPkgModFiles = S.empty , ghciPkgCFiles = S.empty , ghciPkgMainIs = M.empty , ghciPkgTargetFiles = Nothing , ghciPkgPackage = Package { packageName = $(mkPackageName "package-a") , packageVersion = $(mkVersion "0.1.0.0") , packageLicense = BSD3 , packageFiles = GetPackageFiles undefined , packageDeps = M.empty , packageTools = [] , packageAllDeps = S.empty , packageGhcOptions = [] , packageFlags = M.empty , packageDefaultFlags = M.empty , packageHasLibrary = True , packageTests = M.empty , packageBenchmarks = S.empty , packageExes = S.empty , packageOpts = GetPackageOpts undefined , packageHasExposedModules = True , packageBuildType = Just Simple , packageSetupDeps = Nothing } } ] packages_multiplePackages :: [GhciPkgInfo] packages_multiplePackages = [ GhciPkgInfo { ghciPkgModules = S.fromList [ModuleName.fromString "Lib.A"] , ghciPkgDir = projDirA , ghciPkgName = $(mkPackageName "package-a") , ghciPkgOpts = [] , ghciPkgModFiles = S.empty , ghciPkgCFiles = S.empty , ghciPkgMainIs = M.empty , ghciPkgTargetFiles = Nothing , ghciPkgPackage = Package { packageName = $(mkPackageName "package-a") , packageVersion = $(mkVersion "0.1.0.0") , packageLicense = BSD3 , packageFiles = GetPackageFiles undefined , packageDeps = M.empty , packageTools = [] , packageAllDeps = S.empty , packageGhcOptions = [] , packageFlags = M.empty , packageDefaultFlags = M.empty , packageHasLibrary = True , packageTests = M.empty , packageBenchmarks = S.empty , packageExes = S.empty , packageOpts = GetPackageOpts undefined , packageHasExposedModules = True , packageBuildType = Just Simple , packageSetupDeps = Nothing } } , GhciPkgInfo { ghciPkgModules = S.fromList [ModuleName.fromString "Lib.B"] , ghciPkgDir = projDirB , ghciPkgName = $(mkPackageName "package-b") , ghciPkgOpts = [] , ghciPkgModFiles = S.empty , ghciPkgCFiles = S.empty , ghciPkgMainIs = M.empty , ghciPkgTargetFiles = Nothing , ghciPkgPackage = Package { packageName = $(mkPackageName "package-b") , packageVersion = $(mkVersion "0.1.0.0") , packageLicense = BSD3 , packageFiles = GetPackageFiles undefined , packageDeps = M.empty , packageTools = [] , packageAllDeps = S.empty , packageGhcOptions = [] , packageFlags = M.empty , packageDefaultFlags = M.empty , packageHasLibrary = True , packageTests = M.empty , packageBenchmarks = S.empty , packageExes = S.empty , packageOpts = GetPackageOpts undefined , packageHasExposedModules = True , packageBuildType = Just Simple , packageSetupDeps = Nothing } } ] -} stack-2.9.3.1/src/test/Stack/LockSpec.hs0000644000000000000000000001350414445022466016043 0ustar0000000000000000{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Stack.LockSpec where import Pantry.Internal.AesonExtended ( WithJSONWarnings (..) ) import qualified Data.Yaml as Yaml import Distribution.Types.PackageName ( mkPackageName ) import Distribution.Types.Version ( mkVersion ) import Pantry import qualified Pantry.SHA256 as SHA256 import RIO import Stack.Lock import Test.Hspec import Text.RawString.QQ toBlobKey :: ByteString -> Word -> BlobKey toBlobKey string size = BlobKey (decodeSHA string) (FileSize size) decodeSHA :: ByteString -> SHA256 decodeSHA string = case SHA256.fromHexBytes string of Right csha -> csha Left err -> error $ "Failed decoding. Error: " <> displayException err decodeLocked :: ByteString -> IO Locked decodeLocked bs = do val <- Yaml.decodeThrow bs case Yaml.parseEither Yaml.parseJSON val of Left err -> throwIO $ Yaml.AesonException err Right (WithJSONWarnings res warnings) -> do unless (null warnings) $ throwIO $ Yaml.AesonException $ "Unexpected warnings: " ++ show warnings -- we just assume no file references resolvePaths Nothing res spec :: Spec spec = do it "parses lock file (empty with GHC resolver)" $ do let lockFile :: ByteString lockFile = [r|#some snapshots: - completed: compiler: ghc-8.6.5 original: compiler: ghc-8.6.5 packages: [] |] pkgImm <- lckPkgImmutableLocations <$> decodeLocked lockFile pkgImm `shouldBe` [] it "parses lock file (empty with LTS resolver)" $ do let lockFile :: ByteString lockFile = [r|#some snapshots: - completed: size: 527801 url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/11/22.yaml sha256: 7c8b1853da784bd7beb8728168bf4e879d8a2f6daf408ca0fa7933451864a96a original: lts-14.27 - completed: compiler: ghc-8.6.5 original: compiler: ghc-8.6.5 packages: [] |] pkgImm <- lckPkgImmutableLocations <$> decodeLocked lockFile pkgImm `shouldBe` [] it "parses lock file (LTS, wai + warp)" $ do let lockFile :: ByteString lockFile = [r|#some snapshots: - completed: size: 527801 url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/11/22.yaml sha256: 7c8b1853da784bd7beb8728168bf4e879d8a2f6daf408ca0fa7933451864a96a original: lts-14.27 - completed: compiler: ghc-8.6.5 original: compiler: ghc-8.6.5 packages: - original: subdir: wai git: https://github.com/yesodweb/wai.git commit: d11d63f1a6a92db8c637a8d33e7953ce6194a3e0 completed: subdir: wai name: wai version: 3.2.1.2 git: https://github.com/yesodweb/wai.git pantry-tree: size: 714 sha256: ecfd0b4b75f435a3f362394807b35e5ef0647b1a25005d44a3632c49db4833d2 commit: d11d63f1a6a92db8c637a8d33e7953ce6194a3e0 - original: subdir: warp git: https://github.com/yesodweb/wai.git commit: d11d63f1a6a92db8c637a8d33e7953ce6194a3e0 completed: subdir: warp name: warp version: 3.2.25 git: https://github.com/yesodweb/wai.git pantry-tree: size: 5103 sha256: f808e075811b002563d24c393ce115be826bb66a317d38da22c513ee42b7443a commit: d11d63f1a6a92db8c637a8d33e7953ce6194a3e0 |] pkgImm <- lckPkgImmutableLocations <$> decodeLocked lockFile let waiSubdirRepo subdir = Repo { repoType = RepoGit , repoUrl = "https://github.com/yesodweb/wai.git" , repoCommit = "d11d63f1a6a92db8c637a8d33e7953ce6194a3e0" , repoSubdir = subdir } emptyRPM = RawPackageMetadata { rpmName = Nothing , rpmVersion = Nothing , rpmTreeKey = Nothing } pkgImm `shouldBe` [ LockedLocation (RPLIRepo (waiSubdirRepo "wai") emptyRPM) (PLIRepo (waiSubdirRepo "wai") (PackageMetadata { pmIdent = PackageIdentifier { pkgName = mkPackageName "wai" , pkgVersion = mkVersion [3, 2, 1, 2] } , pmTreeKey = TreeKey (BlobKey (decodeSHA "ecfd0b4b75f435a3f362394807b35e5ef0647b1a25005d44a3632c49db4833d2") (FileSize 714)) })) , LockedLocation (RPLIRepo (waiSubdirRepo "warp") emptyRPM) (PLIRepo (waiSubdirRepo "warp") (PackageMetadata { pmIdent = PackageIdentifier { pkgName = mkPackageName "warp" , pkgVersion = mkVersion [3, 2, 25] } , pmTreeKey = TreeKey (BlobKey (decodeSHA "f808e075811b002563d24c393ce115be826bb66a317d38da22c513ee42b7443a") (FileSize 5103)) })) ] stack-2.9.3.1/src/test/Stack/NixSpec.hs0000644000000000000000000001067414445022466015716 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} module Stack.NixSpec where import Data.Maybe (fromJust) import Options.Applicative import Path import Prelude (writeFile) import Stack.Config import Stack.Config.Nix import Stack.Constants import Stack.Options.GlobalParser (globalOptsFromMonoid) import Stack.Options.NixParser import Stack.Prelude import Stack.Runners import Stack.Types.Config import Stack.Types.Nix import System.Directory import System.Environment import Test.Hspec sampleConfigNixEnabled :: String sampleConfigNixEnabled = "resolver: lts-19.22\n" ++ "packages: ['.']\n" ++ "system-ghc: true\n" ++ "nix:\n" ++ " enable: True\n" ++ " packages: [glpk]" sampleConfigNixDisabled :: String sampleConfigNixDisabled = "resolver: lts-19.22\n" ++ "packages: ['.']\n" ++ "nix:\n" ++ " enable: False" setup :: IO () setup = unsetEnv "STACK_YAML" spec :: Spec spec = beforeAll setup $ do let loadConfig' :: ConfigMonoid -> (Config -> IO ()) -> IO () loadConfig' cmdLineArgs inner = do globalOpts <- globalOptsFromMonoid False mempty { globalMonoidConfigMonoid = cmdLineArgs } withRunnerGlobal globalOpts { globalLogLevel = LevelOther "silent" } $ loadConfig (liftIO . inner) inTempDir test = do currentDirectory <- getCurrentDirectory withSystemTempDirectory "Stack_ConfigSpec" $ \tempDir -> do let enterDir = setCurrentDirectory tempDir exitDir = setCurrentDirectory currentDirectory bracket_ enterDir exitDir test withStackDotYaml config test = inTempDir $ do writeFile (toFilePath stackDotYaml) config test parseNixOpts cmdLineOpts = fromJust $ getParseResult $ execParserPure defaultPrefs (info (nixOptsParser False) mempty) cmdLineOpts parseOpts cmdLineOpts = mempty { configMonoidNixOpts = parseNixOpts cmdLineOpts } let trueOnNonWindows = not osIsWindows describe "nix disabled in config file" $ around_ (withStackDotYaml sampleConfigNixDisabled) $ do it "sees that the nix shell is not enabled" $ loadConfig' mempty $ \config -> nixEnable (configNix config) `shouldBe` False describe "--nix given on command line" $ it "sees that the nix shell is enabled" $ loadConfig' (parseOpts ["--nix"]) $ \config -> nixEnable (configNix config) `shouldBe` trueOnNonWindows describe "--nix-pure given on command line" $ it "sees that the nix shell is enabled" $ loadConfig' (parseOpts ["--nix-pure"]) $ \config -> nixEnable (configNix config) `shouldBe` trueOnNonWindows describe "--no-nix given on command line" $ it "sees that the nix shell is not enabled" $ loadConfig' (parseOpts ["--no-nix"]) $ \config -> nixEnable (configNix config) `shouldBe` False describe "--no-nix-pure given on command line" $ it "sees that the nix shell is not enabled" $ loadConfig' (parseOpts ["--no-nix-pure"]) $ \config -> nixEnable (configNix config) `shouldBe` False describe "nix enabled in config file" $ around_ (withStackDotYaml sampleConfigNixEnabled) $ do it "sees that the nix shell is enabled" $ loadConfig' mempty $ \config -> nixEnable (configNix config) `shouldBe` trueOnNonWindows describe "--no-nix given on command line" $ it "sees that the nix shell is not enabled" $ loadConfig' (parseOpts ["--no-nix"]) $ \config -> nixEnable (configNix config) `shouldBe` False describe "--nix-pure given on command line" $ it "sees that the nix shell is enabled" $ loadConfig' (parseOpts ["--nix-pure"]) $ \config -> nixEnable (configNix config) `shouldBe` trueOnNonWindows describe "--no-nix-pure given on command line" $ it "sees that the nix shell is enabled" $ loadConfig' (parseOpts ["--no-nix-pure"]) $ \config -> nixEnable (configNix config) `shouldBe` trueOnNonWindows it "sees that the only package asked for is glpk and asks for the correct GHC derivation" $ loadConfig' mempty $ \config -> do nixPackages (configNix config) `shouldBe` ["glpk"] v <- parseVersionThrowing "9.0.2" ghc <- either throwIO pure $ nixCompiler (WCGhc v) ghc `shouldBe` "haskell.compiler.ghc902" stack-2.9.3.1/src/test/Stack/PackageDumpSpec.hs0000644000000000000000000003024014445022466017330 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TupleSections #-} module Stack.PackageDumpSpec where import Conduit import qualified Data.Conduit.List as CL import Data.Conduit.Text ( decodeUtf8 ) import qualified Data.Map as Map import qualified Data.Set as Set import Distribution.License ( License (..) ) import Distribution.Types.PackageName ( mkPackageName ) import Distribution.Version ( mkVersion ) import Path ( parseAbsFile ) import Stack.PackageDump import Stack.Prelude import Stack.Types.Config import Stack.Types.GhcPkgId import RIO.Process import Test.Hspec import Test.Hspec.QuickCheck main :: IO () main = hspec spec spec :: Spec spec = do describe "eachSection" $ do let test name content expected = it name $ do actual <- runConduit $ yield content .| eachSection CL.consume .| CL.consume actual `shouldBe` expected test "unix line endings" "foo\nbar\n---\nbaz---\nbin\n---\n" [ ["foo", "bar"] , ["baz---", "bin"] ] test "windows line endings" "foo\r\nbar\r\n---\r\nbaz---\r\nbin\r\n---\r\n" [ ["foo", "bar"] , ["baz---", "bin"] ] it "eachPair" $ do let bss = [ "key1: val1" , "key2: val2a" , " val2b" , "key3:" , "key4:" , " val4a" , " val4b" ] sink k = fmap (k, ) CL.consume actual <- runConduit $ mapM_ yield bss .| eachPair sink .| CL.consume actual `shouldBe` [ ("key1", ["val1"]) , ("key2", ["val2a", "val2b"]) , ("key3", []) , ("key4", ["val4a", "val4b"]) ] describe "conduitDumpPackage" $ do it "ghc 7.8" $ do haskell2010:_ <- withSourceFile "test/package-dump/ghc-7.8.txt" $ \src -> runConduit $ src .| decodeUtf8 .| conduitDumpPackage .| CL.consume ghcPkgId <- parseGhcPkgId "haskell2010-1.1.2.0-05c8dd51009e08c6371c82972d40f55a" packageIdent <- maybe (fail "Not parsable package id") pure $ parsePackageIdentifier "haskell2010-1.1.2.0" depends <- mapM parseGhcPkgId [ "array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b" , "base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1" , "ghc-prim-0.3.1.0-a24f9c14c632d75b683d0f93283aea37" ] haskell2010 { dpExposedModules = mempty } `shouldBe` DumpPackage { dpGhcPkgId = ghcPkgId , dpPackageIdent = packageIdent , dpParentLibIdent = Nothing , dpLicense = Just BSD3 , dpLibDirs = ["/opt/ghc/7.8.4/lib/ghc-7.8.4/haskell2010-1.1.2.0"] , dpDepends = depends , dpLibraries = ["HShaskell2010-1.1.2.0"] , dpHasExposedModules = True , dpHaddockInterfaces = ["/opt/ghc/7.8.4/share/doc/ghc/html/libraries/haskell2010-1.1.2.0/haskell2010.haddock"] , dpHaddockHtml = Just "/opt/ghc/7.8.4/share/doc/ghc/html/libraries/haskell2010-1.1.2.0" , dpIsExposed = False , dpExposedModules = mempty } it "ghc 7.10" $ do haskell2010:_ <- withSourceFile "test/package-dump/ghc-7.10.txt" $ \src -> runConduit $ src .| decodeUtf8 .| conduitDumpPackage .| CL.consume ghcPkgId <- parseGhcPkgId "ghc-7.10.1-325809317787a897b7a97d646ceaa3a3" pkgIdent <- maybe (fail "Not parsable package id") pure $ parsePackageIdentifier "ghc-7.10.1" depends <- mapM parseGhcPkgId [ "array-0.5.1.0-e29cdbe82692341ebb7ce6e2798294f9" , "base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a" , "bin-package-db-0.0.0.0-708fc7d634a370b311371a5bcde40b62" , "bytestring-0.10.6.0-0909f8f31271f3d75749190bf2ee35db" , "containers-0.5.6.2-2114032c163425cc264e6e1169dc2f6d" , "directory-1.2.2.0-b4959b472d9eee380c6b32291ade29e0" , "filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6" , "hoopl-3.10.0.2-8c8dfc4c3140e5f7c982da224c3cb1f0" , "hpc-0.6.0.2-ac9064885aa8cb08a93314222939ead4" , "process-1.2.3.0-3b1e9bca6ac38225806ff7bbf3f845b1" , "template-haskell-2.10.0.0-e895139a0ffff267d412e3d0191ce93b" , "time-1.5.0.1-e17a9220d438435579d2914e90774246" , "transformers-0.4.2.0-c1a7bb855a176fe475d7b665301cd48f" , "unix-2.7.1.0-e5915eb989e568b732bc7286b0d0817f" ] haskell2010 { dpExposedModules = mempty } `shouldBe` DumpPackage { dpGhcPkgId = ghcPkgId , dpPackageIdent = pkgIdent , dpParentLibIdent = Nothing , dpLicense = Just BSD3 , dpLibDirs = ["/opt/ghc/7.10.1/lib/ghc-7.10.1/ghc_EMlWrQ42XY0BNVbSrKixqY"] , dpHaddockInterfaces = ["/opt/ghc/7.10.1/share/doc/ghc/html/libraries/ghc-7.10.1/ghc.haddock"] , dpHaddockHtml = Just "/opt/ghc/7.10.1/share/doc/ghc/html/libraries/ghc-7.10.1" , dpDepends = depends , dpLibraries = ["HSghc-7.10.1-EMlWrQ42XY0BNVbSrKixqY"] , dpHasExposedModules = True , dpIsExposed = False , dpExposedModules = mempty } it "ghc 7.8.4 (osx)" $ do hmatrix:_ <- withSourceFile "test/package-dump/ghc-7.8.4-osx.txt" $ \src -> runConduit $ src .| decodeUtf8 .| conduitDumpPackage .| CL.consume ghcPkgId <- parseGhcPkgId "hmatrix-0.16.1.5-12d5d21f26aa98774cdd8edbc343fbfe" pkgId <- maybe (fail "Not parsable package id") pure $ parsePackageIdentifier "hmatrix-0.16.1.5" depends <- mapM parseGhcPkgId [ "array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b" , "base-4.7.0.2-918c7ac27f65a87103264a9f51652d63" , "binary-0.7.1.0-108d06eea2ef05e517f9c1facf10f63c" , "bytestring-0.10.4.0-78bc8f2c724c765c78c004a84acf6cc3" , "deepseq-1.3.0.2-0ddc77716bd2515426e1ba39f6788a4f" , "random-1.1-822c19b7507b6ac1aaa4c66731e775ae" , "split-0.2.2-34cfb851cc3784e22bfae7a7bddda9c5" , "storable-complex-0.2.2-e962c368d58acc1f5b41d41edc93da72" , "vector-0.10.12.3-f4222db607fd5fdd7545d3e82419b307"] hmatrix `shouldBe` DumpPackage { dpGhcPkgId = ghcPkgId , dpPackageIdent = pkgId , dpParentLibIdent = Nothing , dpLicense = Just BSD3 , dpLibDirs = [ "/Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/lib/x86_64-osx-ghc-7.8.4/hmatrix-0.16.1.5" , "/opt/local/lib/" , "/usr/local/lib/" , "C:/Program Files/Example/"] , dpHaddockInterfaces = ["/Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/doc/html/hmatrix.haddock"] , dpHaddockHtml = Just "/Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/doc/html" , dpDepends = depends , dpLibraries = ["HShmatrix-0.16.1.5"] , dpHasExposedModules = True , dpIsExposed = True , dpExposedModules = Set.fromList ["Data.Packed","Data.Packed.Vector","Data.Packed.Matrix","Data.Packed.Foreign","Data.Packed.ST","Data.Packed.Development","Numeric.LinearAlgebra","Numeric.LinearAlgebra.LAPACK","Numeric.LinearAlgebra.Algorithms","Numeric.Container","Numeric.LinearAlgebra.Util","Numeric.LinearAlgebra.Devel","Numeric.LinearAlgebra.Data","Numeric.LinearAlgebra.HMatrix","Numeric.LinearAlgebra.Static"] } it "ghc HEAD" $ do ghcBoot:_ <- withSourceFile "test/package-dump/ghc-head.txt" $ \src -> runConduit $ src .| decodeUtf8 .| conduitDumpPackage .| CL.consume ghcPkgId <- parseGhcPkgId "ghc-boot-0.0.0.0" pkgId <- maybe (fail "Not parsable package id") pure $ parsePackageIdentifier "ghc-boot-0.0.0.0" depends <- mapM parseGhcPkgId [ "base-4.9.0.0" , "binary-0.7.5.0" , "bytestring-0.10.7.0" , "directory-1.2.5.0" , "filepath-1.4.1.0" ] ghcBoot `shouldBe` DumpPackage { dpGhcPkgId = ghcPkgId , dpPackageIdent = pkgId , dpParentLibIdent = Nothing , dpLicense = Just BSD3 , dpLibDirs = ["/opt/ghc/head/lib/ghc-7.11.20151213/ghc-boot-0.0.0.0"] , dpHaddockInterfaces = ["/opt/ghc/head/share/doc/ghc/html/libraries/ghc-boot-0.0.0.0/ghc-boot.haddock"] , dpHaddockHtml = Just "/opt/ghc/head/share/doc/ghc/html/libraries/ghc-boot-0.0.0.0" , dpDepends = depends , dpLibraries = ["HSghc-boot-0.0.0.0"] , dpHasExposedModules = True , dpIsExposed = True , dpExposedModules = Set.fromList ["GHC.Lexeme", "GHC.PackageDb"] } it "sinkMatching" $ runEnvNoLogging $ \pkgexe -> do m <- ghcPkgDump pkgexe [] $ conduitDumpPackage .| sinkMatching (Map.singleton (mkPackageName "transformers") (mkVersion [0, 0, 0, 0, 0, 0, 1])) case Map.lookup (mkPackageName "base") m of Nothing -> error "base not present" Just _ -> pure () liftIO $ do Map.lookup (mkPackageName "transformers") m `shouldBe` Nothing Map.lookup (mkPackageName "ghc") m `shouldBe` Nothing describe "pruneDeps" $ do it "sanity check" $ do let prunes = [ ((1, 'a'), []) , ((1, 'b'), []) , ((2, 'a'), [(1, 'b')]) , ((2, 'b'), [(1, 'a')]) , ((3, 'a'), [(1, 'c')]) , ((4, 'a'), [(2, 'a')]) ] actual = fst <$> pruneDeps fst fst snd bestPrune prunes actual `shouldBe` Map.fromList [ (1, (1, 'b')) , (2, (2, 'a')) , (4, (4, 'a')) ] prop "invariant holds" $ \prunes' -> -- Force uniqueness let prunes = Map.toList $ Map.fromList prunes' in checkDepsPresent prunes $ fst <$> pruneDeps fst fst snd bestPrune prunes type PruneCheck = ((Int, Char), [(Int, Char)]) bestPrune :: PruneCheck -> PruneCheck -> PruneCheck bestPrune x y | fst x > fst y = x | otherwise = y checkDepsPresent :: [PruneCheck] -> Map Int (Int, Char) -> Bool checkDepsPresent prunes selected = all hasDeps $ Set.toList allIds where depMap = Map.fromList prunes allIds = Set.fromList $ Map.elems selected hasDeps ident = case Map.lookup ident depMap of Nothing -> error "checkDepsPresent: missing in depMap" Just deps -> Set.null $ Set.difference (Set.fromList deps) allIds runEnvNoLogging :: (GhcPkgExe -> RIO LoggedProcessContext a) -> IO a runEnvNoLogging inner = do envVars <- view envVarsL <$> mkDefaultProcessContext menv <- mkProcessContext $ Map.delete "GHC_PACKAGE_PATH" envVars let find name = runRIO menv (findExecutable name) >>= either throwIO parseAbsFile pkg <- GhcPkgExe <$> find "ghc-pkg" runRIO (LoggedProcessContext menv mempty) (inner pkg) stack-2.9.3.1/src/test/Stack/Types/TemplateNameSpec.hs0000644000000000000000000000517214445022466020635 0ustar0000000000000000{-# LANGUAGE OverloadedStrings #-} module Stack.Types.TemplateNameSpec where import Stack.Types.TemplateName import Path.Internal import System.Info (os) import Test.Hspec spec :: Spec spec = describe "TemplateName" $ do describe "parseTemplateNameFromString" $ do let pathOf s = either error templatePath (parseTemplateNameFromString s) it "parses out the TemplatePath" $ do pathOf "github:user/name" `shouldBe` RepoPath (RepoTemplatePath GitHub "user" "name.hsfiles") pathOf "bitbucket:user/name" `shouldBe` RepoPath (RepoTemplatePath Bitbucket "user" "name.hsfiles") pathOf "gitlab:user/name" `shouldBe` RepoPath (RepoTemplatePath GitLab "user" "name.hsfiles") pathOf "http://www.com/file" `shouldBe` UrlPath "http://www.com/file" pathOf "https://www.com/file" `shouldBe` UrlPath "https://www.com/file" pathOf "name" `shouldBe` RelPath "name.hsfiles" (Path "name.hsfiles") pathOf "name.hsfile" `shouldBe` RelPath "name.hsfile.hsfiles" (Path "name.hsfile.hsfiles") pathOf "name.hsfiles" `shouldBe` RelPath "name.hsfiles" (Path "name.hsfiles") pathOf "" `shouldBe` RelPath ".hsfiles" (Path ".hsfiles") if os == "mingw32" then do pathOf "//home/file" `shouldBe` AbsPath (Path "\\\\home\\file.hsfiles") pathOf "/home/file" `shouldBe` RelPath "/home/file.hsfiles" (Path "\\home\\file.hsfiles") pathOf "/home/file.hsfiles" `shouldBe` RelPath "/home/file.hsfiles" (Path "\\home\\file.hsfiles") pathOf "c:\\home\\file" `shouldBe` AbsPath (Path "C:\\home\\file.hsfiles") pathOf "with/slash" `shouldBe` RelPath "with/slash.hsfiles" (Path "with\\slash.hsfiles") let colonAction = do pure $! pathOf "with:colon" colonAction `shouldThrow` anyErrorCall else do pathOf "//home/file" `shouldBe` AbsPath (Path "/home/file.hsfiles") pathOf "/home/file" `shouldBe` AbsPath (Path "/home/file.hsfiles") pathOf "/home/file.hsfiles" `shouldBe` AbsPath (Path "/home/file.hsfiles") pathOf "c:\\home\\file" `shouldBe` RelPath "c:\\home\\file.hsfiles" (Path "c:\\home\\file.hsfiles") pathOf "with/slash" `shouldBe` RelPath "with/slash.hsfiles" (Path "with/slash.hsfiles") pathOf "with:colon" `shouldBe` RelPath "with:colon.hsfiles" (Path "with:colon.hsfiles") stack-2.9.3.1/src/test/Stack/UploadSpec.hs0000644000000000000000000000243114445022466016374 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Stack.UploadSpec (spec) where import RIO import RIO.Directory import RIO.FilePath (()) import Stack.Upload import Test.Hspec import System.Permissions (osIsWindows) import System.PosixCompat.Files (getFileStatus, fileMode) import System.Environment (setEnv, unsetEnv) import Data.Bits ((.&.)) spec :: Spec spec = do it "writeFilePrivate" $ example $ withSystemTempDirectory "writeFilePrivate" $ \dir -> replicateM_ 2 $ do let fp = dir "filename" contents :: IsString s => s contents = "These are the contents" writeFilePrivate fp contents actual <- readFileBinary fp actual `shouldBe` contents perms <- getPermissions fp perms `shouldBe` setOwnerWritable True (setOwnerReadable True emptyPermissions) unless osIsWindows $ do status <- getFileStatus fp (fileMode status .&. 0o777) `shouldBe` 0o600 it "finds a HACKAGE_KEY env variable" $ do runRIO () maybeGetHackageKey `shouldReturn` Nothing withEnv "HACKAGE_KEY" "api_key" $ runRIO () maybeGetHackageKey `shouldReturn` Just (HackageKey "api_key") withEnv :: String -> String -> IO a -> IO a withEnv k v f = do setEnv k v f `finally` unsetEnv k stack-2.9.3.1/CONTRIBUTING.md0000644000000000000000000005202214445022466013420 0ustar0000000000000000# Contributors Guide Thank you for considering contributing to the maintenance or development of Stack, or otherwise supporting users of Stack! We hope that the following information will encourage and assist you. We start with some advice about Stack's goals and governance, and approach to supporting users. ## Stack's goals Stack's current goals are: * To provide easy to use tooling for Haskell development * To provide complete support for at least the following three development environments: Linux, macOS, and Windows * To address the needs of industrial users, open source maintainers, and other people * To focus on the 'curated package set' use case * To prioritize reproducible build plans The goals above are not set in stone. However, any major changes to them should involve significant public discussion and a public vote by the Stack maintainer team. ## Stack's governance People involved in maintaining or developing Stack with rights to make commits to the repository can be classified into two groups: 'committers' and 'maintainers'. ### Stack's committers We encourages a wide range of people to be granted rights to make commits to the repository. People are encouraged to take initiative to make non-controversial changes, such as documentation improvements, bug fixes, performance improvements, and feature enhancements. Maintainers should be included in discussions of controversial changes and tricky code changes. Our general approach is **"it's easier to ask forgiveness than permission"**. If there is ever a bad change, it can always be rolled back. ### Stack's maintainers Stack's maintainers are long-term contributors to the project. Michael Snoyman (@snoyberg) was the founder of Stack, and its initial maintainer - and he has added others. Michael's current interests and priorities mean that he is no longer actively involved in adding new features to Stack. Maintainers are recognized for their contributions including: * Direct code contribution * Review of pull requests * Interactions on the GitHub issue tracker * Documentation management * External support - for example, hosting or training The maintainer team make certain decisions when that is necessary, specifically: * How to proceed, if there is disagreement on how to do so on a specific topic * Whether to add or remove (see further below) a maintainer Generally, maintainers are only removed due to non-participation or actions unhealthy to the project. Removal due to non-participation is not a punishment, simply a recognition that maintainership is for active participants only. We hope that removal due to unhealthy actions will never be necessary, but would include protection for cases of: * Disruptive behavior in public channels related to Stack * Impairing the codebase through bad commits/merges Like committers, maintainers are broadly encouraged to make autonomous decisions. Each maintainer is empowered to make a unilateral decision. However, maintainers should favor getting consensus first if: * They are uncertain what is the best course of action * They anticipate that other maintainers or users of Stack will disagree on the decision ## Stack's support A large part of the general discussion around Stack is on support-related topics, and that is reflected in the current issue tracker content. Assistance in responding to such matters is greatly appreciated. While support-related matters can be posted here as an 'issue', we encourage the use of other forums, in particular [Haskell's Discourse](https://discourse.haskell.org/). We also recommend Haskell's Discourse for general discussions about Stack's current or desired features. Stack is also discussed on Reddit's [Haskell community](https://www.reddit.com/r/haskell/). We encourage use of those other forums because support-related discussions can clog up the issue tracker and make it more difficult to maintain the project. People needing support may also get a faster and fuller response on other forums. Additions to the issue tracker are better suited to concrete feature proposals, bug reports, and other code base discussions (for example, refactorings). ## Bug Reports Please [open an issue](https://github.com/commercialhaskell/stack/issues/new) and use the provided template to include all necessary details. The more detailed your report, the faster it can be resolved and will ensure it is resolved in the right way. Once your bug has been resolved, the responsible person will tag the issue as _Needs confirmation_ and assign the issue back to you. Once you have tested and confirmed that the issue is resolved, close the issue. If you are not a member of the project, you will be asked for confirmation and we will close it. ## Documentation Consistent with its goal of being easy to use, Stack aims to maintain a high quality of in-tool and online documentation. The in-tool documentation includes the output when the `--help` flag is specified and the content of Stack's warning and error messages. When drafting documentation it is helpful to have in mind the intended reader and what they are assumed to know, and not know, already. In that regard, documentation should aim to meet, at least, the needs of a person who is about to begin to study computing as an undergraduate but who has not previously coded using Haskell. That person may be familiar with one popular operating system but may not be familiar with others. The files which make up Stack's online documentation are located in the `doc` directory of the repository. They are formatted in the [Markdown syntax](https://daringfireball.net/projects/markdown/), with some extensions. Those files are rendered on [haskellstack.org](http://haskellstack.org) by [Read the Docs](https://readthedocs.org/) using [MkDocs](https://www.mkdocs.org/) and the [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) theme. The `stable` branch of the repository provides the 'stable' version of the online documentation. The `master` branch provides the 'latest' version of the documentation. The 'stable' version of the online documentation is intended to be applicable to the latest released version of Stack. If you would like to help with that documentation, please submit a [pull request](https://help.github.com/articles/using-pull-requests/) with your changes/additions based off the [stable branch](https://github.com/commercialhaskell/stack/tree/stable). The Markdown files are organised into the navigation menu (the table of contents) in the file `mkdocs.yml`, the configuration file for MkDocs. The description of a file in the menu can differ from the file's name. The navigation menu allows files to be organised in a hierarchy. Currently, up to three levels are used. The top level is: * **Welcome!:** The introduction to Stack. This page aims to be no longer than necessary but also to not assume much existing knowledge on the part of the reader. It provides a 'quick start' guide to getting and using Stack. * **How to get & use Stack:** This includes Stack's user's guide, answers to frequently asked questions, and more thorough explanations of aspects of Stack. The user's guide is divided into two parts. The first part is 'introductory', and has the style of a tutorial. The second part is 'advanced', and has more of a reference style. * **How Stack works (advanced):** Many users will not need to consult this advanced documentation. * **Stack's code (advanced):** Other information useful to people contributing to, or maintaining, Stack's code, documentation, and other files. * **Signing key:** How Stack's released executables are signed. * **Glossary:** A glossary of terms used throughout Stack's in-tool and online documentation. We aim to describe the same things in the same way in different places. * **Version history:** The log of changes to Stack between versions. The specific versions of the online documentation (eg `v: v2.9.1`) are generated from the content of files at the point in the repository's history specified by the corresponding release tag. Consequently, that content is fixed once released. If the names of Markdown files do not change between versions, then people can use the flyout on the online documentation to move between different versions of the same page. For that reason, the names of new Markdown files should be chosen with care and existing Markdown files should not be deleted or renamed without due consideration of the consequences. The Markdown syntax supported by MkDocs and the Material for MkDocs theme can differ from the GitHub Flavored Markdown ([GFM](https://github.github.com/gfm/)) supported for content on GitHub.com. Please refer to the [MkDocs documentation](https://www.mkdocs.org/user-guide/writing-your-docs/#writing-with-markdown) and the [Material for MkDocs reference](https://squidfunk.github.io/mkdocs-material/reference/) to ensure your pull request will achieve the desired rendering. The extensions to the basic Markdown syntax used are set out in `mkdocs.yml` and include: * admonitions * code blocks, with syntax highlighting provided by [Pygments](https://pygments.org/) * content tabs, which can be nested * icons and emojis The files in the `doc` directory of the repository include two symbolic links (symlinks), `ChangeLog.md` and `CONTRIBUTING.md`. Users of Git on Windows should be aware of its approach to symbolic links. See the [Git for Windows Wiki](https://github.com/git-for-windows/git/wiki/Symbolic-Links). If `git config --show-scope --show-origin core.symlinks` is `false` in a local repository on Windows, then the files will be checked out as small plain files that contain the link text See the [Git documentation](https://git-scm.com/docs/git-config#Documentation/git-config.txt-coresymlinks). ## Error messages Stack catches exceptions thrown by its dependencies or by Stack itself in `Main.main`. In addition to exceptions that halt Stack's execution, Stack logs certain other matters as 'errors'. To support the Haskell Foundation's [Haskell Error Index](https://errors.haskell.org/) initiative, all Stack error messages generated by Stack itself should have a unique initial line: ~~~text Error: [S-nnnn] ~~~ where `nnnn` is a four-digit number in the range 1000 to 9999. If you create a new Stack error, select a number using a random number generator (see, for example, [RANDOM.ORG](https://www.random.org/)) and check that number is not already in use in Stack's code. If it is, pick another until the number is unique. All exceptions generated by Stack itself are implemented using data constructors of closed sum types. Typically, there is one such type for each module that exports functions that throw exceptions. This type and the related `instance` definitions are usually located at the top of the relevant module. Stack supports two types of exceptions: 'pretty' exceptions that are instances of class `RIO.PrettyPrint.Pretty`, which provides `pretty :: e -> StyleDoc`, and thrown as expressions of type `RIO.PrettyPrint.PrettyException.PrettyException`; and other 'plain' exceptions that are simply instances of class `Control.Exception.Exception` and, hence, instances of class `Show`. These types and classes are re-exported by `Stack.Prelude`. Stack throws exceptions in parts of the code that should, in principle, be unreachable. The functions `Stack.Prelude.bugReport` and `Stack.Prelude.bugPrettyReport` are used to give the messages a consistent format. The names of the data constructors for those exceptions usually end in `Bug`. In a few cases, Stack may throw an exception in 'pure' code. The function `RIO.impureThrow :: Exception e => e -> a`, re-exported by `Stack.Prelude`, is used for that purpose. ## Code If you would like to contribute code to fix a bug, add a new feature, or otherwise improve `stack`, pull requests are most welcome. It's a good idea to [submit an issue](https://github.com/commercialhaskell/stack/issues/new) to discuss the change before plowing into writing code. If you'd like to help out but aren't sure what to work on, look for issues with the [awaiting pull request](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3A%22awaiting+pull+request%22) label. Issues that are suitable for newcomers to the codebase have the [newcomer friendly](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3A%22awaiting+pull+request%22+label%3a%22newcomer+friendly%22) label. Best to post a comment to the issue before you start work, in case anyone has already started. Please include a [ChangeLog](https://github.com/commercialhaskell/stack/blob/master/ChangeLog.md) entry and [documentation](https://github.com/commercialhaskell/stack/tree/master/doc/) updates with your pull request. ## Backwards Compatability The Stack executable does not need to, and does not, strive for the same broad compatibility with versions of GHC that a library package (such as `pantry`) would seek. Instead, Stack aims to define a well-known combination of dependencies on which its executable relies. That applies in particular to the `Cabal` package, where Stack aims to support one, and only one, version of `Cabal` with each release of its executable. At the time of writing (September 2022) that combination is defined by resolver `nightly-2022-11-14` (for GHC 9.2.4, and including `Cabal-3.6.3.0`) - see `stack.yaml`. ## Code Quality The Stack project uses [yamllint](https://github.com/adrienverge/yamllint) as a YAML file quality tool and [HLint](https://github.com/ndmitchell/hlint) as a code quality tool. ### Linting of YAML files The yamllint configuration extends the tools default and is set out in `.yamllint.yaml`. In particular, indentation is set at 2 spaces and `- ` in sequences is treated as part of the indentation. ### Linting of Haskell source code The HLint configurations is set out in `.hlint.yaml`. Stack contributors need not follow dogmatically the suggested HLint hints but are encouraged to debate their usefulness. If you find a HLint hint is not useful and detracts from readability of code, consider marking it in the [configuration file](https://github.com/commercialhaskell/stack/blob/master/.hlint.yaml) to be ignored. Please refer to the [HLint manual](https://github.com/ndmitchell/hlint#readme) for configuration syntax. Quoting [@mgsloan](https://github.com/commercialhaskell/stack/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Amgsloan): > We are optimizing for code clarity, not code concision or what HLint thinks. You can install HLint with Stack. You might want to install it in the global project in case you run into dependency conflicts. HLint can report hints in your favourite text editor. Refer to the HLint repository for more details. To install, command: ~~~text stack install hlint ~~~ Once installed, you can check your changes with command: ~~~text stack exec -- sh ./etc/scripts/hlint.sh ~~~ ## Testing The Stack code has both unit tests and integration tests. Integration tests can be found in the [test/integration](https://github.com/commercialhaskell/stack/tree/master/test/integration) folder and unit tests, in the [src/test](https://github.com/commercialhaskell/stack/tree/master/src/test) folder. Tests are written using the [Hspec](https://hspec.github.io/) framework. In order to run the full test suite, you can simply command: ~~~text stack test ~~~ The `--file-watch` is a very useful option to get quick feedback. However, running the entire test suite after each file change will slow you down. You'll need to specify which test suite (unit test or integration) and pass arguments to specify which module you'd specifically like to run to get quick feedback. A description of this follows below. ### Working with Unit Tests If you would like to run the unit tests on their own, you can command: ~~~text stack test stack:stack-test ~~~ Running an individual module works with a command like this: ~~~text stack test stack:stack-test --ta "-m " ~~~ Where `` is the name of the module without `Spec.hs`. You may also load tests into GHCi and run them with these command: ~~~text stack ghci stack:stack-test --only-main # GHCi starting up output ... > :main -m "" ~~~ Where again, `` is the name of the module without `Spec.hs`. ### Working with Integration Tests Running the integration tests is a little involved, you'll need to command: ~~~text stack build --flag stack:integration-tests stack --exec stack-integration-test ~~~ Running an individual module works with a command like this: ~~~text stack build --flag stack:integration-tests stack --exec "stack-integration-test -m " ~~~ Where `` is the name of the folder listed in the [test/integration/tests/](https://github.com/commercialhaskell/stack/tree/master/test/integration/tests) directory. You may also achieve this through GHCi with this command: ~~~text stack ghci stack:stack-integration-test # GHCi starting up output ... > :main -m "" ~~~ Where again, `` is the name of the folder listed in the [test/integration/tests/](https://github.com/commercialhaskell/stack/tree/master/test/integration/tests) directory. ## Continuous integration (CI) We use [GitHub Actions](https://docs.github.com/en/actions) to do CI on Stack. The configuration of the workflows is in the YAML files in `.github/workflows`. The current active workflows are: ### Linting - `lint.yml` This workflow will run if: * there is a pull request * commits are pushed to these branches: `master`, `stable` and `rc/**` The workflow has one job (`style`). It runs on `ubuntu` only and applies yamllint and Hlint. ### Test suite - `unit-tests.yml` This workflow will run if: * there is a pull request * commits are pushed to these branches: `master`, `stable` and `rc/**`. * requested The workflow has two jobs: `pedantic` and `unit-tests`. The `pedantic` job runs on `ubuntu` only and builds Stack with the `--pedantic` flag. The `unit-tests` job runs on a matrix of operating systems and Stack project-level YAML configuration files (`stack.yaml`). It builds and tests Stack with the following flags: `--haddock --no-haddock-deps`. Its approach to creating a cache depends on the operating system. Its 'Cache dependencies on Unix-like OS' step caches the Stack root on Unix-like operating systems. Its 'Cache dependencies on Windows' step caches the same information on Windows, but takes into account that a relevant directory is located outside of the Stack root. ### Integration-based - `integration-tests.yml` This workflow will run if: * there is a pull request * commits are pushed to these branches: `master`, `stable` and `rc/**` * any tag is created * requested The workflow has three jobs: `integration-tests`, `linux-arm64` and `github-release`. The `integration-tests` job runs on a matrix of operating systems (`ubuntu`, `windows` and `macos`) and makes use of the `release.hs` script at `etc/scripts`. Its approach to creating a cache is the same as for `unit-tests.yml`, described above. Its 'Install deps and run checks' step uses `release.hs check`. Its 'Build bindist' step uses `release.hs build`. Its 'Upload bindist' step uploads artifacts using the name of the runner's operating system (`Linux`, `Windows` or `macOS`) as the name for the artifacts. The `linux-arm64` job runs on a self-hosted runner for Linux and ARM64. It makes use of Docker and a Docker file at `etc/dockerfiles/arm64.Dockerfile`. Its 'Build bindist' step makes use of a compiled version of `release.hs` script at `etc/scripts` to command `release build`. Its 'Upload bindist' step uploads artifacts using `Linux-ARM64` as the name for the artifacts. The `github-release` job needs `integration-tests` and `linux-arm64`. It only takes effect if the trigger for the workflow was the creation of a tag. Its four steps `Download Linux/Windows/macOS/Linux-ARM64 artifact` download the named artifacts to path `_release`. Its step 'Hash and sign assets' makes use of a 'secret' environment variable `RELEASE_SIGNING_KEY` established by the owner of the Stack repository. The variable contains the private key for the GPG key with ID 0x575159689BEFB442. That key is imported into GPG and then used by GPG to create a detached signature for each file. ### Inactive - `stan.yml` Stan is a Haskell static analysis tool. As of 29 August 2022, it does not support GHC >= 9.0.1 and Stack is built with GHC >= 9.2.4. Consequently, this workflow does not run. Its intent is to apply Stan to Stack. ## Slack channel If you're making deep changes and real-time communication with the Stack team would be helpful, we have a `#stack-collaborators` Slack channel in the Haskell Foundation workspace. To join the workspace, follow this [link](https://haskell-foundation.slack.com/join/shared_invite/zt-z45o9x38-8L55P27r12YO0YeEufcO2w#/shared-invite/email). stack-2.9.3.1/ChangeLog.md0000644000000000000000000045337514445117331013354 0ustar0000000000000000# Changelog ## v2.9.3.1 - 2023-06-22 Hackage-only release of the `stack` package: * Supports building against snapshot Stackage LTS Haskell 21.0 (GHC 9.4.5), without extra deps. * Supports build with `persistent-2.14.5.0`, using CPP directives. * Supports build with `unix-compat-0.7`, by removing reliance on the module `System.PosixCompat.User` removed in that package. * Includes `cabal.project` and `cabal.config` files in the package. ## v2.9.3 - 2022-12-16 **Changes since v2.9.1:** Behavior changes: * In YAML configuration files, the `package-index` key is introduced which takes precedence over the existing `package-indices` key. The latter is deprecated. * In YAML configuration files, the `hackage-security` key of the `package-index` key or the `package-indices` item can be omitted, and the Hackage Security configuration for the item will default to that for the official Hackage server. See [#5870](https://github.com/commercialhaskell/stack/issues/5870). * Add the `stack config set package-index download-prefix` command to set the location of Stack's package index in YAML configuration files. * `stack setup` with the `--no-install-ghc` flag warns that the flag and the command are inconsistent and now takes no action. Previously the flag was silently ignored. * To support the Haskell Foundation's [Haskell Error Index](https://errors.haskell.org/) initiative, all Stack error messages generated by Stack itself begin with an unique code in the form `[S-nnnn]`, where `nnnn` is a four-digit number. * Test suite executables that seek input on the standard input channel (`stdin`) will not throw an exception. Previously, they would thow an exception, consistent with Cabal's 'exitcode-stdio-1.0' test suite interface specification. Pass the flag `--no-tests-allow-stdin` to `stack build` to enforce Cabal's specification. See [#5897](https://github.com/commercialhaskell/stack/issues/5897) Other enhancements: * Help documentation for `stack upgrade` warns that if GHCup is used to install Stack, only GHCup should be used to upgrade Stack. That is because GHCup uses an executable named `stack` to manage versions of Stack, that Stack will likely overwrite on upgrade. * Add `stack ls dependencies cabal` command, which lists dependencies in the format of exact Cabal constraints. * Add `STACK_XDG` environment variable to use the XDG Base Directory Specification for the Stack root and Stack's global YAML configuration file, if the Stack root location is not set on the command line or by using the `STACK_ROOT` environment variable. * Add `stack path --global-config`, to yield the full path of Stack's user-specific global YAML configuration file (`config.yaml`). * Add an experimental option, `allow-newer-deps`, which allows users to specify a subset of dependencies for which version bounds should be ignored (`allow-newer-deps: ['foo', 'bar']`). This field has no effect unless `allow-newer` is enabled. Bug fixes: * Fix ambiguous module name `Distribution.PackageDescription`, if compiling `StackSetupShim` with `Cabal-syntax-3.8.1.0` in package database. See [#5886](https://github.com/commercialhaskell/stack/pull/5886). * In YAML configuration files, if the `package-indices` key (or the `hackage-security` key of its item) is omitted, the expiration of timestamps is now ignored, as intended. See Pantry [#63](https://github.com/commercialhaskell/pantry/pull/63) ## v2.9.1 - 2022-09-19 **Changes since v2.7.5:** Release notes: * After an upgrade from an earlier version of Stack, on first use only, Stack 2.9.1 may warn that it had trouble loading the CompilerPaths cache. Behavior changes: * `stack build --coverage` will generate a unified coverage report, even if there is only one `*.tix` file, in case a package has tested the library of another package that has not tested its own library. See [#5713](https://github.com/commercialhaskell/stack/issues/5713) * `stack --verbose` no longer includes the lengthy raw snapshot layer (rsl) in the debug output by default. The new `stack --[no-]rsl-in-log` flag enables or disables the inclusion of the rsl in the debug output. Other enhancements: * Bump to Hpack 0.35.0. * On Windows, the installer now sets `DisplayVersion` in the registry, enabling tools like `winget` to properly read the version number. * Adds flag `--script-no-run-compile` (disabled by default) that uses the `--no-run` option with `stack script` (and forces the `--compile` option). This enables a command like `stack --script-no-run-compile Script.hs` to behave like `stack script --no-run --compile -- Script.hs` but without having to list all the `` in the Stack interpreter options comment in `Script.hs` on the command line. That may help test that scripts compile in CI (continuous integration). See [#5755](https://github.com/commercialhaskell/stack/issues/5755) * Fuller help is provided at the command line if a subcommand is missing (for example, `stack ls` now yields the equivalent of `stack ls --help`). See [#809](https://github.com/commercialhaskell/stack/issues/809) * Add build option `--cabal-verbosity=VERBOSITY` to specify the Cabal verbosity level (the option accepts Cabal's numerical and extended syntax). See [#1369](https://github.com/commercialhaskell/stack/issues/809) * Add the possibility of a `sh` script to customise fully GHC installation. See [#5585](https://github.com/commercialhaskell/stack/pull/5585) * `tools` subcommand added to `stack ls`, to list stack's installed tools. * `stack uninstall` shows how to uninstall Stack. * `--ghc-variant` accepts `int-native` as a variant. Bug fixes: * Fix `stack clean --full`, so that the files to be deleted are not in use. See [#5714](https://github.com/commercialhaskell/stack/issues/5714) * Fix an inconsistency in the pretty formatting of the output of `stack build --coverage` * Fix repeated warning about missing parameters when using `stack new` * Include `pantry-0.5.6`: Remove operational and mirror keys from bootstrap key set [#53](https://github.com/commercialhaskell/pantry/pull/53) * Pass any CPP options specified via `cpp-options:` in the Cabal file to GHCi using GHC's `-optP` flag. See [#5608](https://github.com/commercialhaskell/stack/pull/5608) * On Unix-like operating systems, respect the `with-gcc` option when installing GHC. See [#5609](https://github.com/commercialhaskell/stack/pull/5609) * Fixed logic in `get_isa()` in `get-stack.sh` to exclude systems that don't have x86 in their `uname -m` output. See [5792](https://github.com/commercialhaskell/stack/issues/5792). * Fixed output of `stack ls snapshots local` on Windows, to behave like that on Unix-like operating systems. * Fix non-deterministic test failures when executing a test suite for a multi-project repository with parallelism enabled. See [#5024](https://github.com/commercialhaskell/stack/issues/5024) ## v2.7.5 - 2022-03-06 **Changes since v2.7.3:** Behavior changes: * Cloning git repositories isn't per sub-directory anymore, see [#5411](https://github.com/commercialhaskell/stack/issues/5411) Other enhancements: * `stack setup` supports installing GHC for macOS aarch64 (M1) * `stack upload` supports authentication with a Hackage API key (via `HACKAGE_KEY` environment variable). Bug fixes: * Ensure that `extra-path` works for case-insensitive `PATH`s on Windows. See [rio#237](https://github.com/commercialhaskell/rio/pull/237) * Fix handling of overwritten `ghc` and `ghc-pkg` locations. [#5597](https://github.com/commercialhaskell/stack/pull/5597) * Fix failure to find package when a dependency is shared between projects. [#5680](https://github.com/commercialhaskell/stack/issues/5680) * `stack ghci` now uses package flags in `stack.yaml` [#5434](https://github.com/commercialhaskell/stack/issues/5434) ## v2.7.3 - 2021-07-20 **Changes since v2.7.1:** Other enhancements: * `stack upgrade` will download from `haskellstack.org` before trying `github.com`. See [#5288](https://github.com/commercialhaskell/stack/issues/5288) * `stack upgrade` makes less assumptions about archive format. See [#5288](https://github.com/commercialhaskell/stack/issues/5288) * Add a `--no-run` flag to the `script` command when compiling. Bug fixes: * GHC source builds work properly for recent GHC versions again. See [#5528](https://github.com/commercialhaskell/stack/issues/5528) * `stack setup` always looks for the unpacked directory name to support different tar file naming conventions. See [#5545](https://github.com/commercialhaskell/stack/issues/5545) * Bump `pantry` version for better OS support. See [pantry#33](https://github.com/commercialhaskell/pantry/issues/33) * When building the sanity check for a new GHC install, make sure to clear `GHC_PACKAGE_PATH`. * Specifying GHC RTS flags in the `stack.yaml` no longer fails with an error. [#5568](https://github.com/commercialhaskell/stack/pull/5568) * `stack setup` will look in sandboxed directories for executables, not relying on `findExecutables. See [GHC issue 20074](https://gitlab.haskell.org/ghc/ghc/-/issues/20074) * Track changes to `setup-config` properly to avoid reconfiguring on every change. See [#5578](https://github.com/commercialhaskell/stack/issues/5578) ## v2.7.1 - 2021-05-07 **Changes since v2.5.1.1:** Behavior changes: * `stack repl` now always warns about GHCi problems with loading multiple packages. It also sets now proper working directory when invoked with one package. See [#5421](https://github.com/commercialhaskell/stack/issues/5421) * `custom-setup` dependencies are now properly initialized for `stack dist`. This makes `explicit-setup-deps` no longer required and that option was removed. See [#4006](https://github.com/commercialhaskell/stack/issues/4006) Other enhancements: * Nix integration now passes `ghcVersion` (in addition to existing `ghc`) to `shell-file` as an identifier that can be looked up in a compiler attribute set. * Nix integration now allows Nix integration if the user is ready in nix-shell. This gets rid of "In Nix shell but reExecL is False" error. * `stack list` is a new command to list package versions in a snapshot. See [#5431](https://github.com/commercialhaskell/stack/pull/5431) * Consider GHC 9.0 a tested compiler and remove warnings. * `custom-preprocessor-extensions` is a new configuration option for allowing Stack to be aware of any custom preprocessors you have added to `Setup.hs`. See [#3491](https://github.com/commercialhaskell/stack/issues/3491) * Added `--candidate` flag to `upload` command to upload a package candidate rather than publishing the package. * Error output using `--no-interleaved-output` no longer prepends indenting whitespace. This allows emacs compilation-mode and vim quickfix to locate and track errors. See [#5523](https://github.com/commercialhaskell/stack/pull/5523) Bug fixes: * `stack new` now supports branches other than `master` as default for GitHub repositories. See [#5422](https://github.com/commercialhaskell/stack/issues/5422) * Ignore all errors from `hi-file-parser`. See [#5445](https://github.com/commercialhaskell/stack/issues/5445) and [#5486](https://github.com/commercialhaskell/stack/issues/5486). * Support basic auth in package-indices. See [#5509](https://github.com/commercialhaskell/stack/issues/5509). * Add support for parsing `.hi`. files from GHC 8.10 and 9.0. See [hi-file-parser#2](https://github.com/commercialhaskell/hi-file-parser/pull/2). ## v2.5.1.1 - 2020-12-09 Hackage-only release: * Support build with persistent-2.11.x and optparse-applicative-0.16.x ## v2.5.1 - 2020-10-15 **Changes since v2.3.3** Major changes: * Add the `snapshot-location-base` yaml configuration option, which allows to override the default location of snapshot configuration files. This option affects how snapshot synonyms (LTS/Nightly) are expanded to URLs by the `pantry` library. * `docker-network` configuration key added to override docker `--net` arg Behavior changes: * File watching now takes into account specified targets, old behavior could be restored using the new flag `--watch-all` [#5310](https://github.com/commercialhaskell/stack/issues/5310) Other enhancements: * `stack ls dependencies json` now includes fields `sha256` and `size` for dependencies of `type` `archive` in `location`. [#5280](https://github.com/commercialhaskell/stack/issues/5280) * Build failures now show a hint to scroll up to the corresponding section [#5279](https://github.com/commercialhaskell/stack/issues/5279) * Customisable output styles (see `stack --help` and the `--stack-colors` option, and `stack ls stack-colors --help`) now include `info`, `debug`, `other-level`, `secondary` and `highlight`, used with verbose output. Bug fixes: * Fix `stack test --coverage` when using Cabal 3 * `stack new` now generates PascalCase'd module name correctly. [#5376](https://github.com/commercialhaskell/stack/issues/5376) * Connection issues to Casa server no longer cause builds to failure. Casa acts only as an optimizing cache layer, not a critical piece of infrastructure. * Fix modified time busting caches by always calculating sha256 digest during the build process. [#5125](https://github.com/commercialhaskell/stack/issues/5125) ## v2.3.3 - 2020-08-06 **Changes since v2.3.1** Other enhancements: * Add the `stack-developer-mode` flag Bug fixes: * When using the `STACK_YAML` env var with Docker, make the path absolute. * Fix the problem of `stack repl foo:test:bar` failing without a project build before that. See [#5213](https://github.com/commercialhaskell/stack/issues/5213) * Fix `stack sdist` introducing unnecessary sublibrary syntax when using pvp-bounds. See [#5289](https://github.com/commercialhaskell/stack/issues/5289) ## v2.3.1 - 2020-04-29 Release notes: * We have reduced the number of platforms that we support with binary releases. The reason behind this is that we've been slowed down in our release process until now with issues trying to build binaries for less common platforms. In order to make sure we can address issues more quickly (like supporting new GHC versions), we're limiting support from the Stack team to: * Linux 64-bit (static) * macOS * Windows 64-bit If others want to provide additional binaries, we will definitely be happy for the support. But since our CI system is currently able to produce these three bindists only, that's what we will be providing with the next release. * Since we no longer have dynamically linked Linux binaries, we are removing removing the `-static` suffix from the static Linux binaries. If you have scripts to download the latest stable Linux binary, update them to use `linux-x86_64` instead of `linux-x86_64-static` (if you are already using the former, nothing needs to change). For this release, both are supported, but the next release will no longer have the `-static` variant. * We are also deprecating the download links at https://stackage.org/stack. See this page for the current installation instructions: https://docs.haskellstack.org/en/stable/install_and_upgrade/. * These are the canonical locations to download the latest stable binaries from, and will continue to be supported going forward: * Linux 64-bit (static): https://get.haskellstack.org/stable/linux-x86_64.tar.gz * macOS: https://get.haskellstack.org/stable/osx-x86_64.tar.gz * Windows 64-bit: https://get.haskellstack.org/stable/windows-x86_64.zip As always, binaries for specific versions are available from the GitHub releases: https://github.com/commercialhaskell/stack/releases. **Changes since v2.1.3.1** Major changes: * `setup-info-locations` yaml configuration now allows overwriting the default locations of `stack-setup-2.yaml`. [#5031](https://github.com/commercialhaskell/stack/pull/5031) [#2983](https://github.com/commercialhaskell/stack/issues/2983) [#2913](https://github.com/commercialhaskell/stack/issues/2913) * The `setup-info` configuration key now allows overwriting parts of the default `setup-info` * The `--setup-info-yaml` command line flag now may be used in all Stack commands such as `stack build`, and not only in `stack setup` * The `--setup-info-yaml` may specify multiple locations for `stack-setup.yaml` files. * The `stack upload` can read first reads environment Variable `$HACKAGE_USERNAME` and `$HACKAGE_PASSWORD` if they are missing only then asks for `username` or `password` * Fully remove GHCJS support. * Remove the `freeze` command. It has been replaced by lock files. Behavior changes: * Remove the deprecated `--stack-setup-yaml` command line argument in favor of `--setup-info-yaml`. See [#2647](https://github.com/commercialhaskell/stack/issues/2647) * We now recommend checking in generated Cabal files for repos. When generating lock files for extra-deps that only include `package.yaml` files, a deprecation warning will be generated. Also, those packages will no longer be included in the generated lock files. See [#5210](https://github.com/commercialhaskell/stack/issues/5210). Other enhancements: * Add `build-output-timestamps` flag in yaml. Setting it to true prefixes each build log output line with a timestamp. * Show warning about `local-programs-path` with spaces on windows when running scripts. See [#5013](https://github.com/commercialhaskell/stack/pull/5013) * Add `ls dependencies json` which will print dependencies as JSON. `ls dependencies --tree` is now `ls dependencies tree`. See [#4424](https://github.com/commercialhaskell/stack/pull/4424) * Remove warning for using Stack with GHC 8.8-8.10, and Cabal 3.0-3.2. * Allow relative paths in `--setup-info-yaml` and tool paths [#3394](https://github.com/commercialhaskell/stack/issues/3394) * Added the `--only-locals` flag. See [#5272](https://github.com/commercialhaskell/stack/issues/5272) Bug fixes: * Upgrade `pantry`: module mapping insertions into the database are now atomic. Previously, if you SIGTERMed at the wrong time while running a script, you could end up with an inconsistent database state. * `--resolver global` doesn't retrieve snapshots list from the internet because doesn't need it. See [#5103](https://github.com/commercialhaskell/stack/issues/5103) * Fix using relative links in haddocks output. See [#4971](https://github.com/commercialhaskell/stack/issues/4971). * Do not include generated Cabal file information in lock files. See [#5045](https://github.com/commercialhaskell/stack/issues/5045). * Use proper Hoogle executable path when installed automatically. See [#4905](https://github.com/commercialhaskell/stack/issues/4905) * Fix GHC version for batched package unregistration. See [#4951](https://github.com/commercialhaskell/stack/issues/4951) * Use Hoogle from the snapshot used and not the latest version. See [#4905](https://github.com/commercialhaskell/stack/issues/4905) * Resolve "'stty' is not recognized". See [#4901](https://github.com/commercialhaskell/stack/issues/4901) * Fix missing reconfigure check causing errors when a package gets used in multiple projects. See [#5147](https://github.com/commercialhaskell/stack/issues/5147) ## v2.1.3.1 - 2019-07-16 Hackage-only release: * Support persistent-template-2.7.x * Support rio-0.1.11.0 * Add `stack.yaml` back to hackage sdist, and add `snapshot.yaml` ## v2.1.3 - 2019-07-13 **Changes since v2.1.1** Behavior changes: * Disable WAL mode for SQLite3 databases, to improve compatibility with some platforms and filesystems. See [#4876](https://github.com/commercialhaskell/stack/issues/4876). * By default, do not perform expiry checks in Hackage Security. See [#4928](https://github.com/commercialhaskell/stack/issues/4928). Other enhancements: * Do not rerun expected test failures. This is mostly a change that will only affect the Stackage Curator use case, but there is now an additional message letting the user know when a previously-failed test case is being rerun. * Move configure information for local packages back to .stack-work to improve caching. See [#4893](https://github.com/commercialhaskell/stack/issues/4893). Bug fixes: * Fix to allow dependencies on specific versions of local git repositories. See [#4862](https://github.com/commercialhaskell/stack/pull/4862) * Allow Stack commands to be run in Nix mode without having a project file available. See [#4854](https://github.com/commercialhaskell/stack/issues/4864). * Removes dependency on gnu-tar for OSX and Linux environment. The `--force-local` option was required only for windows environment. * Properly wait for the `tar` subprocess to complete before returning, thereby avoiding a SIGTERM screwing up GHC installation. See [#4888](https://github.com/commercialhaskell/stack/issues/4888). * Use package complete locations from lock files when resolving dependencies in `extra-deps`. See [#4887](https://github.com/commercialhaskell/stack/issues/4887). * Set the `HASKELL_DIST_DIR` environment to a proper package dist directory so `doctest` is able to load modules autogenerated by Cabal. * Expose package library when running tests. * Fix support for non-ASCII module names. See [#4938](https://github.com/commercialhaskell/stack/issues/4938) Other changes: * Rename `pantry-tmp` package back to `pantry`, now that we have gained maintainership (which had been used by someone else for a candidate-only test that made it look like the name was free but prevented uploading a real package). ## v2.1.1.1 - 2019-06-14 Hackage-only release that removes `stack.yaml` from the sdist. This is because `stack.yaml` now defines a multi-package project, whereas Hackage works on the basis on individual packages (see [#4860](https://github.com/commercialhaskell/stack/issues/4860)) If building a `stack` executable for distribution, please download the source code from https://github.com/commercialhaskell/stack/releases/tag/v2.1.1 and build it using Stack itself in order to ensure identical behaviour to official binaries. This package on Hackage is provided for convenience and bootstrapping purposes. ## v2.1.1 - 2019-06-13 The Stack 2 release represents a series of significant changes to how Stack works internally. For the vast majority of cases, these changes are backwards compatible, in that existing projects will continue to build in the same way with Stack 2 as they did with Stack 1. The large version bump is due to the fundamental internal changes to cache handling, database storage (using SQLite in place of binary files), implicit snapshots (which greatly improve the precompiled cache), and moving to Pantry. We have also removed some less used features, as listed below. **Changes since v1.9.3** Major changes: * Switch over to pantry for managing packages. This is a major change to Stack's internals, and affects user-visible behavior in a few places. Some highlights: * Drop support for multiple package indices and legacy `00-index.tar` style indices. See [#4137](https://github.com/commercialhaskell/stack/issues/4137). * Support for archives and repos in the `packages` section has been removed. Instead, you must use `extra-deps` for such dependencies. `packages` now only supports local filepaths. * Add support for Git repositories containing (recursive) submodules. * Addition of new configuration options for specifying a "pantry tree" key, which provides more reproducibility around builds, and (in the future) will be used for more efficient package content downloads. You can also specify package name and version for more efficient config parsing. * __NOTE__ The new `stack freeze` command provides support for automatically generating this additional information. * Package contents and metadata are stored in an SQLite database in place of files on the filesystem. The `pantry` library can be used for interacting with these contents. * Internally, Stack has changed many datatypes, including moving to Cabal's definition of many data types. As a result of such changes, existing cache files will in general be invalidated, resulting in Stack needing to rebuild many previously cached builds in the new version. Sorry :(. * A new command, `stack freeze` has been added which outputs project and snapshot definitions with dependencies pinned to their exact versions. * The `ignore-revision-mismatch` setting is no longer needed, and has been removed. * Overriding GHC boot packages results in any other GHC boot packages depending on it being no longer available as a dependency, such packages need to be added explicitly when needed. See [#4510] (https://github.com/commercialhaskell/stack/issues/4510). * Cabal solver integration was not updated to support newer `cabal-install` versions so `stack solver` command was removed as well as a related option `--solver` from `stack new` and `stack init`. * Upgrade to Cabal 2.4 * Note that, in this process, the behavior of file globbing has been modified to match that of Cabal. In particular, this means that for Cabal spec versions less than 2.4, `*.txt` will match `foo.txt`, but not `foo.2.txt`. * Remove the `stack image` command. With the advent of Docker multistage builds, this functionality is no longer useful. For an example, please see [Building Haskell Apps with Docker](https://www.fpcomplete.com/blog/2017/12/building-haskell-apps-with-docker). * Support building GHC from source (experimental) * Stack now supports building and installing GHC from source. The built GHC is uniquely identified by a commit id and an Hadrian "flavour" (Hadrian is the newer GHC build system), hence `compiler` can be set to use a GHC built from source with `ghc-git-COMMIT-FLAVOUR` * `stack.yaml` now supports a `configure-options`, which are passed directly to the `configure` step in the Cabal build process. See [#1438](https://github.com/commercialhaskell/stack/issues/1438) * Remove support for building GHCJS itself. Future releases of Stack may remove GHCJS support entirely. * Support for lock files for pinning exact project dependency versions Behavior changes: * `stack.yaml` now supports `snapshot`: a synonym for `resolver`. See [#4256](https://github.com/commercialhaskell/stack/issues/4256) * `stack script` now passes `-i -idir` in to the `ghc` invocation. This makes it so that the script can import local modules, and fixes an issue where `.hs` files in the current directory could affect interpretation of the script. See [#4538](https://github.com/commercialhaskell/stack/pull/4538) * When using `stack script`, custom snapshot files will be resolved relative to the directory containing the script. * Remove the deprecated `--upgrade-cabal` flag to `stack setup`. * Support the `drop-packages` field in `stack.yaml` * Remove the GPG signing code during uploads. The GPG signatures have never been used yet, and there are no plans to implement signature verification. * Remove the `--plain` option for the `exec` family of commands * Always use the `--exact-configuration` Cabal configuration option when building (should mostly be a non-user-visible enhancement). * No longer supports Cabal versions older than `1.19.2`. This means projects using snapshots earlier than `lts-3.0` or `nightly-2015-05-05` will no longer build. * Remove the `stack docker cleanup` command. Docker itself now has [`docker image prune`](https://docs.docker.com/engine/reference/commandline/image_prune/) and [`docker container prune`](https://docs.docker.com/engine/reference/commandline/container_prune/), which you can use instead. * Interleaved output is now turned on by default, see [#4702](https://github.com/commercialhaskell/stack/issues/4702). In addition, the `packagename> ` prefix is no longer included in interleaved mode when only building a single target. * The `-fhide-source-paths` GHC option is now enabled by default and can be disabled via the `hide-source-paths` configuration option in `stack.yaml`. See [#3784](https://github.com/commercialhaskell/stack/issues/3784) * Stack will reconfigure a package if you modify your `PATH` environment variable. See [#3138](https://github.com/commercialhaskell/stack/issues/3138). * For GHC 8.4 and later, disable the "shadowed dependencies" workaround. This means that Stack will no longer have to force reconfigures as often. See [#3554](https://github.com/commercialhaskell/stack/issues/3554). * When building a package, Stack takes a lock on the dist directory in use to avoid multiple runs of Stack from trampling each others' files. See [#2730](https://github.com/commercialhaskell/stack/issues/2730). * Stack will check occasionally if there is a new version available and prompt the user to upgrade. This will not incur any additional network traffic, as it will piggy-back on the existing Hackage index updates. You can set `recommend-stack-upgrade: false` to bypass this. See [#1681](https://github.com/commercialhaskell/stack/issues/1681). * `stack list-dependencies` has been removed in favour of `stack ls dependencies`. * The new default for `--docker-auto-pull` is enabled. See [#3332](https://github.com/commercialhaskell/stack/issues/3332). Other enhancements: * Support MX Linux in get-stack.sh. Fixes [#4769](https://github.com/commercialhaskell/stack/issues/4769). * Defer loading up of files for local packages. This allows us to get plan construction errors much faster, and avoid some unnecessary work when only building a subset of packages. This is especially useful for the curator use case. * Existing global option `--color=WHEN` is now also available as a non-project-specific yaml configuration parameter `color:`. * Adopt the standard proposed at http://no-color.org/, that color should not be added by default if the `NO_COLOR` environment variable is present. * New command `stack ls stack-colors` lists the styles and the associated 'ANSI' control character sequences that Stack uses to color some of its output. See `stack ls stack-colors --help` for more information. * New global option `--stack-colors=STYLES`, also available as a non-project-specific yaml configuration parameter, allows a Stack user to redefine the default styles that Stack uses to color some of its output. See `stack --help` for more information. * British English spelling of 'color' (colour) accepted as an alias for `--color`, `--stack-colors`, `stack ls stack-colors` at the command line and for `color:` and `stack-colors:` in yaml configuration files. * New build option `--ddump-dir`. (See [#4225](https://github.com/commercialhaskell/stack/issues/4225)) * Stack parses and respects the `preferred-versions` information from Hackage for choosing latest version of a package in some cases, e.g. `stack unpack packagename`. * The components output in the `The main module to load is ambiguous` message now include package names so they can be more easily copy-pasted. * Git repos are shared across multiple projects. See [#3551](https://github.com/commercialhaskell/stack/issues/3551) * Use en_US.UTF-8 locale by default in pure Nix mode so programs won't crash because of Unicode in their output [#4095](https://github.com/commercialhaskell/stack/issues/4095) * Add `--tree` to `ls dependencies` to list dependencies as tree. [#4101](https://github.com/commercialhaskell/stack/issues/4101) * Add `--pedantic` to `ghci` to run with `-Wall` and `-Werror` [#4463](https://github.com/commercialhaskell/stack/issues/4463) * Add `--cabal-files` flag to `stack ide targets` command. * Add `--stdout` flag to all `stack ide` subcommands. * Use batches when unregistering packages with `ghc-pkg`. (See [#2662](https://github.com/commercialhaskell/stack/issues/2662)) * `get-stack` script now works on Windows CI machines of Appveyor, Travis and Azure Pipelines. See [#4535](https://github.com/commercialhaskell/stack/issues/4535)/ * Show snapshot being used when `stack ghci` is invoked outside of a project directory. See [#3651](https://github.com/commercialhaskell/stack/issues/3651) * The script interpreter now accepts a `--extra-dep` flag for adding packages not present in the snapshot. Currently, this only works with packages from Hackage, not Git repos or archives. * When using the script interpreter with `--optimize` or `--compile`, Stack will perform an optimization of checking whether a newer executable exists, making reruns significantly faster. There's a downside to this, however: if you have a multifile script, and change one of the dependency modules, Stack will not automatically detect and recompile. * `stack clean` will delete the entire `.stack-work/dist` directory, not just the relevant subdirectory for the current GHC version. See [#4480](https://github.com/commercialhaskell/stack/issues/4480). * Add `stack purge` as a shortcut for `stack clean --full`. See [#3863](https://github.com/commercialhaskell/stack/issues/3863). * Both `stack dot` and `stack ls dependencies` accept a `--global-hints` flag to bypass the need for an installed GHC. See [#4390](https://github.com/commercialhaskell/stack/issues/4390). * Add the `stack config env` command for getting shell script environment variables. See [#620](https://github.com/commercialhaskell/stack/issues/620). * Less verbose output from `stack setup` on Windows. See [#1212](https://github.com/commercialhaskell/stack/issues/1212). * Add an optional `ignore-expiry` flag to the `hackage-security` section of the `~/.stack/config.yaml`. It allows to disable timestamp expiration verification just like `cabal --ignore-expiry` does. The flag is not enabled by default so that the default functionality is not changed. * Include default values for most command line flags in the `--help` output. See [#893](https://github.com/commercialhaskell/stack/issues/893). * Set the `GHC_ENVIRONMENT` environment variable to specify dependency packages explicitly when running test. This is done to prevent ambiguous module name errors in `doctest` tests. * `get-stack` script now works on Windows CI machines of Appveyor, Travis and Azure Pipelines. See [#4535](https://github.com/commercialhaskell/stack/issues/4535) * Warn when a Docker image does not include a `PATH` environment variable. See [#2472](https://github.com/commercialhaskell/stack/issues/2742) * When using `system-ghc: true`, Stack will now find the appropriate GHC installation based on the version suffix, allowing you to more easily switch between various system-installed GHCs. See [#2433](https://github.com/commercialhaskell/stack/issues/2433). * `stack init` will now support create a `stack.yaml` file without any local packages. See [#2465](https://github.com/commercialhaskell/stack/issues/2465) * Store caches in SQLite database instead of files. * No longer use "global" Docker image database (`docker.db`). * User config files are respected for the script command. See [#3705](https://github.com/commercialhaskell/stack/issues/3705), [#3887](https://github.com/commercialhaskell/stack/issues/3887). * Set the `GHC_ENVIRONMENT` environment variable to `-` to tell GHC to ignore any such files when GHC is new enough (>= 8.4.4), otherwise simply unset the variable. This allows Stack to have control of package databases when running commands like `stack exec ghci`, even in the presence of implicit environment files created by `cabal new-build`. See [#4706](https://github.com/commercialhaskell/stack/issues/4706). * Use a database cache table to speed up discovery of installed GHCs * You can specify multiple `--test-arguments` options. See [#2226](https://github.com/commercialhaskell/stack/issues/2226) * Windows terminal width detection is now done. See [#3588](https://github.com/commercialhaskell/stack/issues/3588) * On Windows, informs users if the 'programs' path contains a space character and further warns users if that path does not have an alternative short ('8 dot 3') name, referencing the `local-programs-path` configuration option. See [#4726](https://github.com/commercialhaskell/stack/issues/4726) * Add `--docker-mount-mode` option to set the Docker volume mount mode for performance tuning on macOS. Bug fixes: * Ignore duplicate files for a single module when a Haskell module was generated from a preprocessor file. See [#4076](https://github.com/commercialhaskell/stack/issues/4076). * Only track down components in current directory if there are no hs-source-dirs found. This eliminates a number of false-positive warnings, similar to [#4076](https://github.com/commercialhaskell/stack/issues/4076). * Handle a change in GHC's hi-dump format around `addDependentFile`, which now includes a hash. See [yesodweb/yesod#1551](https://github.com/yesodweb/yesod/issues/1551) * Fix `subdirs` for git repos in `extra-deps` to match whole directory names. Also fixes for `subdirs: .`. See [#4292](https://github.com/commercialhaskell/stack/issues/4292) * Fix for git packages to update submodules to the correct state. See [#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`. * Support loading in GHCi definitions from symlinked C files. Without this patch, Stack will try to find object files in the directory pointed to by symlinks, while GCC will produce the object files in the original directory. See [#4402](https://github.com/commercialhaskell/stack/pull/4402) * Fix handling of GitHub and URL templates on Windows. See [#4394](https://github.com/commercialhaskell/stack/issues/4394) * Fix `--file-watch` not responding to file modifications when running inside docker on Mac. See [#4506](https://github.com/commercialhaskell/stack/issues/4506) * Using `--ghc-options` with `stack script --compile` now works. * Ensure the detailed-0.9 type tests work. See [#4453](https://github.com/commercialhaskell/stack/issues/4453). * Extra include and lib dirs are now order-dependent. See [#4527](https://github.com/commercialhaskell/stack/issues/4527). * Apply GHC options when building a `Setup.hs` file. See [#4526](https://github.com/commercialhaskell/stack/issues/4526). * Stack handles ABI changes in FreeBSD 12 by differentiating that version from previous. * Help text for the `templates` subcommand now reflects behaviour in Stack 1.9 — that it downloads and shows a help file, rather than listing available templates. * Fix detection of aarch64 platform (this broke when we upgraded to a newer Cabal version). * Docker: fix detecting and pulling missing images with `--docker-auto-pull`. See [#4598](https://github.com/commercialhaskell/stack/issues/4598) * Hackage credentials are not world-readable. See [#2159](https://github.com/commercialhaskell/stack/issues/2159). * Warnings are dumped from logs even when color is enabled. See [#2997](https://github.com/commercialhaskell/stack/issues/2997) * `stack init` will now work for Cabal files with sublibraries. See [#4408](https://github.com/commercialhaskell/stack/issues/4408) * When the Cabal spec version is newer than the global Cabal version, build against the snapshot's Cabal library. See [#4488](https://github.com/commercialhaskell/stack/issues/4488) * Docker: fix detection of expected subprocess failures. This fixes downloading a compatible `stack` executable when the host `stack` is not compatible with the Docker image (on Linux), and doesn't show an unnecessary extra error when the in-container re-exec'ed `stack` exits with failure. * The `stack ghci` command's `--ghc-options` flag now parses multiple options. See [#3315](https://github.com/commercialhaskell/stack/issues/3315). ## v1.9.3.1 - 2019-04-18 Hackage-only release with no user facing changes (added compatibility with `rio-0.1.9.2`). ## v1.9.3 - 2018-12-02 Bug fixes: * Stack can now be compiled again inside a directory that does not contain a `.git` directory. See [#4364](https://github.com/commercialhaskell/stack/issues/4364#issuecomment-431600841) * Handle a change in GHC's hi-dump format around `addDependentFile`, which now includes a hash. See [yesodweb/yesod#1551](https://github.com/yesodweb/yesod/issues/1551) * Allow variables to appear in template file names. ## v1.9.1.1 - 2018-11-14 Hackage-only release with no user facing changes. * Stack can now be compiled again inside a directory that does not contain a `.git` directory. See [#4364](https://github.com/commercialhaskell/stack/issues/4364#issuecomment-431600841) ## v1.9.1 - 2018-10-17 Release notes: * Statically linked Linux bindists are back again, thanks to [@nh2](https://github.com/nh2). * We will be deleting the Ubuntu, Debian, CentOS, Fedora, and Arch package repos from `download.fpcomplete.com` soon. These have been deprecated for over a year and have not received new releases, but were left in place for compatibility with older scripts. Major changes: * Upgrade to Cabal 2.4 * Note that, in this process, the behavior of file globbing has been modified to match that of Cabal. In particular, this means that for Cabal spec versions less than 2.4, `*.txt` will match `foo.txt`, but not `foo.2.txt`. * `GHCJS` support is being downgraded to 'experimental'. A warning notifying the user of the experimental status of `GHCJS` will be displayed. Behavior changes: * `ghc-options` from `stack.yaml` are now appended to `ghc-options` from `config.yaml`, whereas before they would be replaced. * `stack build` will now announce when sublibraries of a package are being build, in the same way executables, tests, benchmarks and libraries are announced * `stack sdist` will now announce the destination of the generated tarball, regardless of whether or not it passed the sanity checks * The `--upgrade-cabal` option to `stack setup` has been deprecated. This feature no longer works with GHC 8.2 and later. Furthermore, the reason for this flag originally being implemented was drastically lessened once Stack started using the snapshot's `Cabal` library for custom setups. See: [#4070](https://github.com/commercialhaskell/stack/issues/4070). * With the new namespaced template feature, `stack templates` is no longer able to meaningfully display a list of all templates available. Instead, the command will download and display a [help file](https://github.com/commercialhaskell/stack-templates/blob/master/STACK_HELP.md) with more information on how to discover templates. See: [#4039](https://github.com/commercialhaskell/stack/issues/4039) * Build tools are now handled in a similar way to `cabal-install`. In particular, for legacy `build-tools` fields, we use a hard-coded list of build tools in place of looking up build tool packages in a tool map. This both brings Stack's behavior closer into line with `cabal-install`, avoids some bugs, and opens up some possible optimizations/laziness. See: [#4125](https://github.com/commercialhaskell/stack/issues/4125). * Mustache templating is not applied to large files (over 50kb) to avoid performance degradation. See: [#4133](https://github.com/commercialhaskell/stack/issues/4133). * `stack upload` signs the package by default, as documented. `--no-signature` turns the signing off. [#3739](https://github.com/commercialhaskell/stack/issues/3739) * In case there is a network connectivity issue while trying to download a template, Stack will check whether that template had been downloaded before. In that case, the cached version will be used. See [#3850](https://github.com/commercialhaskell/stack/issues/3850). Other enhancements: * On Windows before Windows 10, --color=never is the default on terminals that can support ANSI color codes in output only by emulation * On Windows, recognise a 'mintty' (false) terminal as a terminal, by default * `stack build` issues a warning when `base` is explicitly listed in `extra-deps` of `stack.yaml` * `stack build` suggests trying another GHC version should the build plan end up requiring unattainable `base` version. * A new sub command `run` has been introduced to build and run a specified executable similar to `cabal run`. If no executable is provided as the first argument, it defaults to the first available executable in the project. * `stack build` missing dependency suggestions (on failure to construct a valid build plan because of missing deps) are now printed with their latest Cabal file revision hash. See [#4068](https://github.com/commercialhaskell/stack/pull/4068). * Added new `--tar-dir` option to `stack sdist`, that allows to copy the resulting tarball to the specified directory. * Introduced the `--interleaved-output` command line option and `build.interleaved-output` config value which causes multiple concurrent builds to dump to stderr at the same time with a `packagename> ` prefix. See [#3225](https://github.com/commercialhaskell/stack/issues/3225). * The default retry strategy has changed to exponential backoff. This should help with [#3510](https://github.com/commercialhaskell/stack/issues/3510). * `stack new` now allows template names of the form `username/foo` to download from a user other than `commercialstack` on GitHub, and can be prefixed with the service `github:`, `gitlab:`, or `bitbucket:`. See [#4039](https://github.com/commercialhaskell/stack/issues/4039) * Switch to `githash` to include some unmerged bugfixes in `gitrev` Suggestion to add `'allow-newer': true` now shows path to user config file where this flag should be put into [#3685](https://github.com/commercialhaskell/stack/issues/3685) * `stack ghci` now asks which main target to load before doing the build, rather than after * Bump to Hpack 0.29.0 * With GHC 8.4 and later, Haddock is given the `--quickjump` flag. * It is possible to specify the Hackage base URL to upload packages to, instead of the default of `https://hackage.haskell.org/`, by using `hackage-base-url` configuration option. * When using Nix, if a specific minor version of GHC is not requested, the latest minor version in the given major branch will be used automatically. Bug fixes: * `stack ghci` now does not invalidate `.o` files on repeated runs, meaning any modules compiled with `-fobject-code` will be cached between ghci runs. See [#4038](https://github.com/commercialhaskell/stack/pull/4038). * `~/.stack/config.yaml` and `stack.yaml` terminating by newline * The previous released caused a regression where some `stderr` from the `ghc-pkg` command showed up in the terminal. This output is now silenced. * A regression in recompilation checking introduced in v1.7.1 has been fixed. See [#4001](https://github.com/commercialhaskell/stack/issues/4001) * `stack ghci` on a package with internal libraries was erroneously looking for a wrong package corresponding to the internal library and failing to load any module. This has been fixed now and changes to the code in the library and the sublibrary are properly tracked. See [#3926](https://github.com/commercialhaskell/stack/issues/3926). * For packages with internal libraries not depended upon, `stack build` used to fail the build process since the internal library was not built but it was tried to be registered. This is now fixed by always building internal libraries. See [#3996](https://github.com/commercialhaskell/stack/issues/3996). * `--no-nix` was not respected under NixOS * Fix a regression which might use a lot of RAM. See [#4027](https://github.com/commercialhaskell/stack/issues/4027). * Order of commandline arguments does not matter anymore. See [#3959](https://github.com/commercialhaskell/stack/issues/3959) * When prompting users about saving their Hackage credentials on upload, flush to stdout before waiting for the response so the prompt actually displays. Also fixes a similar issue with ghci target selection prompt. * If `cabal` is not on PATH, running `stack solver` now prompts the user to run `stack install cabal-install` * `stack build` now succeeds in building packages which contain sublibraries which are dependencies of executables, tests or benchmarks but not of the main library. See [#3787](https://github.com/commercialhaskell/stack/issues/3787). * Sublibraries are now properly considered for coverage reports when the test suite depends on the internal library. Before, Stack was erroring when trying to generate the coverage report, see [#4105](https://github.com/commercialhaskell/stack/issues/4105). * Sublibraries are now added to the precompiled cache and recovered from there when the snapshot gets updated. Previously, updating the snapshot when there was a package with a sublibrary in the snapshot resulted in broken builds. This is now fixed, see [#4071](https://github.com/commercialhaskell/stack/issues/4071). * [#4114](https://github.com/commercialhaskell/stack/issues/4114) Stack pretty prints error messages with proper `error` logging level instead of `warning` now. This also fixes self-executing scripts not piping plan construction errors from runhaskell to terminal (issue [#3942](https://github.com/commercialhaskell/stack/issues/3942)). * Fix invalid "While building Setup.hs" when Cabal calls fail. See: [#3934](https://github.com/commercialhaskell/stack/issues/3934) * `stack upload` signs the package by default, as documented. `--no-signature` turns the signing off. [#3739](https://github.com/commercialhaskell/stack/issues/3739) ## v1.7.1 - 2018-04-27 Release notes: * aarch64 (64-bit ARM) bindists are now available for the first time. * Statically linked Linux bindists are no longer available, due to difficulty with GHC 8.2.2 on Alpine Linux. * 32-bit Linux GMP4 bindists for CentOS 6 are no longer available, since GHC 8.2.2 is no longer being built for that platform. Major changes: * Upgrade from Cabal 2.0 to Cabal 2.2 Behavior changes: * `stack setup` no longer uses different GHC configure options on Linux distributions that use GCC with PIE enabled by default. GHC detects this itself since ghc-8.0.2, and Stack's attempted workaround for older versions caused more problems than it solved. * `stack new` no longer initializes a project if the project template contains a `stack.yaml` file. Other enhancements: * A new sub command `ls` has been introduced to Stack to view local and remote snapshots present in the system. Use `stack ls snapshots --help` to get more details about it. * `list-dependencies` has been deprecated. The functionality has to accessed through the new `ls dependencies` interface. See [#3669](https://github.com/commercialhaskell/stack/issues/3669) for details. * Specify User-Agent HTTP request header on every HTTP request. See [#3628](https://github.com/commercialhaskell/stack/issues/3628) for details. * `stack setup` looks for GHC bindists and installations by any OS key that is compatible (rather than only checking a single one). This is relevant on Linux where different distributions may have different combinations of libtinfo 5/6, ncurses 5/6, and gmp 4/5, and will allow simplifying the setup-info metadata YAML for future GHC releases. * The build progress bar reports names of packages currently building. * `stack setup --verbose` causes verbose output of GHC configure process. See [#3716](https://github.com/commercialhaskell/stack/issues/3716) * Improve the error message when an `extra-dep` from a path or git reference can't be found. See [#3808](https://github.com/commercialhaskell/stack/pull/3808) * Nix integration is now disabled on windows even if explicitly enabled, since it isn't supported. See [#3600](https://github.com/commercialhaskell/stack/issues/3600) * `stack build` now supports a new flag `--keep-tmp-files` to retain intermediate files and directories for the purpose of debugging. It is best used with ghc's equivalent flag, i.e. `stack build --keep-tmp-files --ghc-options=-keep-tmp-files`. See [#3857](https://github.com/commercialhaskell/stack/issues/3857) * Improved error messages for snapshot parse exceptions * `stack unpack` now supports a `--to /target/directory` option to specify where to unpack the package into * `stack hoogle` now supports a new flag `--server` that launches local Hoogle server on port 8080. See [#2310](https://github.com/commercialhaskell/stack/issues/2310) Bug fixes: * The script interpreter's implicit file arguments are now passed before other arguments. See [#3658](https://github.com/commercialhaskell/stack/issues/3658). In particular, this makes it possible to pass `-- +RTS ... -RTS` to specify RTS arguments used when running the script. * Don't ignore the template `year` parameter in config files, and clarify the surrounding documentation. See [#2275](https://github.com/commercialhaskell/stack/issues/2275). * Benchmarks used to be run concurrently with other benchmarks and build steps. This is non-ideal because CPU usage of other processes may interfere with benchmarks. It also prevented benchmark output from being displayed by default. This is now fixed. See [#3663](https://github.com/commercialhaskell/stack/issues/3663). * `stack ghci` now allows loading multiple packages with the same module name, as long as they have the same filepath. See [#3776](https://github.com/commercialhaskell/stack/pull/3776). * `stack ghci` no longer always adds a dependency on `base`. It is now only added when there are no local targets. This allows it to be to load code that uses replacements for `base`. See [#3589](https://github.com/commercialhaskell/stack/issues/3589#issuecomment) * `stack ghci` now uses correct paths for autogen files with [#3791](https://github.com/commercialhaskell/stack/issues/3791) * When a package contained sublibraries, Stack was always recompiling the package. This has been fixed now, no recompilation is being done because of sublibraries. See [#3899](https://github.com/commercialhaskell/stack/issues/3899). * The `get-stack.sh` install script now matches manual instructions when it comes to Debian/Fedora/CentOS install dependencies. * Compile Cabal-simple with gmp when using Nix. See [#2944](https://github.com/commercialhaskell/stack/issues/2944) * `stack ghci` now replaces the Stack process with ghci. This improves signal handling behavior. In particular, handling of Ctrl-C. To make this possible, the generated files are now left behind after exit. The paths are based on hashing file contents, and it's stored in the system temporary directory, so this shouldn't result in too much garbage. See [#3821](https://github.com/commercialhaskell/stack/issues/3821). ## v1.6.5 - 2018-02-19 Bug fixes: * Some unnecessary rebuilds when no files were changed are now avoided, by having a separate build cache for each component of a package. See [#3732](https://github.com/commercialhaskell/stack/issues/3732). * Correct the behavior of promoting a package from snapshot to local package. This would get triggered when version bounds conflicted in a snapshot, which could be triggered via Hackage revisions for old packages. This also should allow custom snapshots to define conflicting versions of packages without issue. See [Stackage issue #3185](https://github.com/fpco/stackage/issues/3185). * When promoting packages from snapshot to local, we were occasionally discarding the actual package location content and instead defaulting to pulling the package from the index. We now correctly retain this information. Note that if you were affected by this bug, you will likely need to delete the binary build cache associated with the relevant custom snapshot. See [#3714](https://github.com/commercialhaskell/stack/issues/3714). * `--no-rerun-tests` has been fixed. Previously, after running a test we were forgetting to record the result, which meant that all tests always ran even if they had already passed before. See [#3770](https://github.com/commercialhaskell/stack/pull/3770). * Includes a patched version of `hackage-security` which fixes both some issues around asynchronous exception handling, and moves from directory locking to file locking, making the update mechanism resilient against SIGKILL and machine failure. See `hackage-security` issue [#187](https://github.com/haskell/hackage-security/issues/187) and Stack issue [#3073](https://github.com/commercialhaskell/stack/issues/3073). ## v1.6.3.1 - 2018-02-16 Hackage-only release with no user facing changes (updated to build with newer version of Hpack dependency). ## v1.6.3 - 2017-12-23 Enhancements: * In addition to supporting `.tar.gz` and `.zip` files as remote archives, plain `.tar` files are now accepted too. This will additionally help with cases where HTTP servers mistakenly set the transfer encoding to `gzip`. See [#3647](https://github.com/commercialhaskell/stack/issues/3647). * Links to docs.haskellstack.org ignore Stack version patchlevel. * Downloading Docker-compatible `stack` binary ignores Stack version patchlevel. Bug fixes: * For versions of Cabal before 1.24, ensure that the dependencies of non-buildable components are part of the build plan to work around an old Cabal bug. See [#3631](https://github.com/commercialhaskell/stack/issues/3631). * Run the Cabal file checking in the `sdist` command more reliably by allowing the Cabal library to flatten the `GenericPackageDescription` itself. ## v1.6.1.1 - 2017-12-20 Hackage-only release with no user facing changes (updated to build with newer dependency versions). ## v1.6.1 - 2017-12-07 Major changes: * Complete overhaul of how snapshots are defined, the `packages` and `extra-deps` fields, and a number of related items. For full details, please see the [writeup](https://www.fpcomplete.com/blog/2017/07/stacks-new-extensible-snapshots) on these changes. [PR #3249](https://github.com/commercialhaskell/stack/pull/3249), see the PR description for a number of related issues. * Upgraded to version 2.0 of the Cabal library. Behavior changes: * The `--install-ghc` flag is now on by default. For example, if you run `stack build` in a directory requiring a GHC that you do not currently have, Stack will automatically download and install that GHC. You can explicitly set `install-ghc: false` or pass the flag `--no-install-ghc` to regain the previous behavior. * `stack ghci` no longer loads modules grouped by package. This is always an improvement for plain ghci - it makes loading faster and less noisy. For intero, this has the side-effect that it will no longer load multiple packages that depend on TH loading relative paths. TH relative paths will still work when loading a single package into intero. See [#3309](https://github.com/commercialhaskell/stack/issues/3309) * Setting GHC options for a package via `ghc-options:` in your `stack.yaml` will promote it to a local package, providing for more consistency with flags and better reproducibility. See: [#849](https://github.com/commercialhaskell/stack/issues/849) * The `package-indices` setting with Hackage no longer works with the `00-index.tar.gz` tarball, but must use the `01-index.tar.gz` file to allow revised packages to be found. * Options passed via `--ghci-options` are now passed to the end of the invocation of ghci, instead of the middle. This allows using `+RTS` 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) * Stack will ask before saving hackage credentials to file. This new prompt can be avoided by using the `save-hackage-creds` setting. Please see [#2159](https://github.com/commercialhaskell/stack/issues/2159). * The `GHCRTS` environment variable will no longer be passed through to every program Stack runs. Instead, it will only be passed through commands like `exec`, `runghc`, `script`, `ghci`, etc. See [#3444](https://github.com/commercialhaskell/stack/issues/3444). * `ghc-options:` for specific packages will now come after the options specified for all packages / particular sets of packages. See [#3573](https://github.com/commercialhaskell/stack/issues/3573). * The `pvp-bounds` feature is no longer fully functional, due to some issues with the Cabal library's printer. See [#3550](https://github.com/commercialhaskell/stack/issues/3550). Other enhancements: * The `with-hpack` configuration option specifies an Hpack executable to use instead of the Hpack bundled with Stack. Please see [#3179](https://github.com/commercialhaskell/stack/issues/3179). * It's now possible to skip tests and benchmarks using `--skip` flag * `GitSHA1` is now `StaticSHA256` and is implemented using the `StaticSize 64 ByteString` for improved performance. See [#3006](https://github.com/commercialhaskell/stack/issues/3006) * Dependencies via HTTP(S) archives have been generalized to allow local file path archives, as well as to support setting a cryptographic hash (SHA256) of the contents for better reproducibility. * Allow specifying `--git-branch` when upgrading * When running `stack upgrade` from a file which is different from the default executable path (e.g., on POSIX systems, `~/.local/bin/stack`), it will now additionally copy the new executable over the currently running `stack` executable. If permission is denied (such as in `/usr/local/bin/stack`), the user will be prompted to try again using `sudo`. This is intended to assist with the user experience when the `PATH` environment variable has not been properly configured, see [#3232](https://github.com/commercialhaskell/stack/issues/3232). * `stack setup` for ghcjs will now install `alex` and `happy` if they are not present. See [#3109](https://github.com/commercialhaskell/stack/issues/3232). * Added `stack ghci --only-main` flag, to skip loading / importing all but main modules. See the ghci documentation page for further info. * Allow GHC's colored output to show through. GHC colors output starting with version 8.2.1, for older GHC this does nothing. Sometimes GHC's heuristics would work fine even before this change, for example in `stack ghci`, but this override's GHC's heuristics when they're broken by our collecting and processing GHC's output. * Extended the `ghc-options` field to support `$locals`, `$targets`, and `$everything`. See: [#3329](https://github.com/commercialhaskell/stack/issues/3329) * Better error message for case that `stack ghci` file targets are combined with invalid package targets. See: [#3342](https://github.com/commercialhaskell/stack/issues/3342) * For profiling now uses `-fprof-auto -fprof-cafs` instead of the deprecated `-auto-all -caf-all`. See: [#3360](https://github.com/commercialhaskell/stack/issues/3360) * Better descriptions are now available for `stack upgrade --help`. See: [#3070](https://github.com/commercialhaskell/stack/issues/3070) * When using Nix, nix-shell now depends always on gcc to prevent build errors when using the FFI. As ghc depends on gcc anyway, this doesn't increase the dependency footprint. * `--cwd DIR` can now be passed to `stack exec` in order to execute the program in a different directory. See: [#3264](https://github.com/commercialhaskell/stack/issues/3264) * Plan construction will detect if you add an executable-only package as a library dependency, resulting in much clearer error messages. See: [#2195](https://github.com/commercialhaskell/stack/issues/2195). * Addition of `--ghc-options` to `stack script` to pass options directly to GHC. See: [#3454](https://github.com/commercialhaskell/stack/issues/3454) * Add Hpack `package.yaml` to build Stack itself * Add `ignore-revision-mismatch` setting. See: [#3520](https://github.com/commercialhaskell/stack/issues/3520). * Log when each individual test suite finishes. See: [#3552](https://github.com/commercialhaskell/stack/issues/3552). * Avoid spurious rebuilds when using `--file-watch` by not watching files for executable, test and benchmark components that aren't a target. See: [#3483](https://github.com/commercialhaskell/stack/issues/3483). * Stack will now try to detect the width of the running terminal (only on POSIX for the moment) and use that to better display output messages. Work is ongoing, so some messages will not be optimal yet. The terminal width can be overridden with the new `--terminal-width` command-line option (this works even on non-POSIX). * Passing non local packages as targets to `stack ghci` will now cause them to be used as `-package` args along with package hiding. * Detect when user changed Cabal file instead of `package.yaml`. This was implemented upstream in Hpack. See [#3383](https://github.com/commercialhaskell/stack/issues/3383). * Automatically run `autoreconf -i` as necessary when a `configure` script is missing. See [#3534](https://github.com/commercialhaskell/stack/issues/3534) * GHC bindists can now be identified by their SHA256 checksum in addition to their SHA1 checksum, allowing for more security in download. * For filesystem setup-info paths, it's no longer assumed that the directory is writable, instead a temp dir is used. See [#3188](https://github.com/commercialhaskell/stack/issues/3188). Bug fixes: * `stack hoogle` correctly generates Hoogle databases. See: [#3362](https://github.com/commercialhaskell/stack/issues/3362) * `stack --docker-help` is now clearer about --docker implying system-ghc: true, rather than both --docker and --no-docker. * `stack haddock` now includes package names for all modules in the Haddock index page. See: [#2886](https://github.com/commercialhaskell/stack/issues/2886) * Fixed an issue where Stack wouldn't detect missing Docker images properly with newer Docker versions. [#3171](https://github.com/commercialhaskell/stack/pull/3171) * Previously, Cabal files with just test-suite could cause build to fail ([#2862](https://github.com/commercialhaskell/stack/issues/2862)) * If an invalid snapshot file has been detected (usually due to mismatched hashes), Stack will delete the downloaded file and recommend either retrying or filing an issue upstream. See [#3319](https://github.com/commercialhaskell/stack/issues/3319). * Modified the flag parser within Stack to match the behavior of Cabal's flag parser, which allows multiple sequential dashes. See [#3345](https://github.com/commercialhaskell/stack/issues/3345) * Now clears the hackage index cache if it is older than the downloaded index. Fixes potential issue if Stack was interrupted when updating index. See [#3033](https://github.com/commercialhaskell/stack/issues/3033) * The Stack install script now respects the `-d` option. See [#3366](https://github.com/commercialhaskell/stack/pull/3366). * `stack script` can now handle relative paths to source files. See [#3372](https://github.com/commercialhaskell/stack/issues/3372). * Fixes explanation of why a target is needed by the build plan, when the target is an extra dependency from the commandline. See [#3378](https://github.com/commercialhaskell/stack/issues/3378). * Previously, if you delete a yaml file from ~/.stack/build-plan, it would trust the etag and not re-download. Fixed in this version. * Invoking `stack --docker` in parallel now correctly locks the sqlite database. See [#3400](https://github.com/commercialhaskell/stack/issues/3400). * docs.haskellstack.org RTD documentation search is replaced by the mkdocs search. Please see [#3376](https://github.com/commercialhaskell/stack/issues/3376). * `stack clean` now works with nix. See [#3468](https://github.com/commercialhaskell/stack/issues/3376). * `stack build --only-dependencies` no longer builds local project packages that are depended on. See [#3476](https://github.com/commercialhaskell/stack/issues/3476). * Properly handle relative paths stored in the precompiled cache files. See [#3431](https://github.com/commercialhaskell/stack/issues/3431). * In some cases, Cabal does not realize that it needs to reconfigure, and must be told to do so automatically. This would manifest as a "shadowed dependency" error message. We now force a reconfigure whenever a dependency is built, even if the package ID remained the same. See [#2781](https://github.com/commercialhaskell/stack/issues/2781). * When `--pvp-bounds` is enabled for sdist or upload, internal dependencies could cause errors when uploaded to hackage. This is fixed, see [#3290](https://github.com/commercialhaskell/stack/issues/3290) * Fixes a bug where nonexistent hackage versions would cause Stack to suggest the same package name, without giving version info. See [#3562](https://github.com/commercialhaskell/stack/issues/3562) * Fixes a bug that has existed since 1.5.0, where `stack setup --upgrade-cabal` would say that Cabal is already the latest version, when it wasn't. * Ensure that an `extra-dep` from a local directory is not treated as a `$locals` for GHC options purposes. See [#3574](https://github.com/commercialhaskell/stack/issues/3574). * Building all executables only happens once instead of every time. See [#3229](https://github.com/commercialhaskell/stack/issues/3229) for more info. ## 1.5.1 - 2017-08-05 Bug fixes: * Stack eagerly tries to parse all Cabal files related to a snapshot. Starting with Stackage Nightly 2017-07-31, snapshots are using GHC 8.2.1, and the `ghc.cabal` file implicitly referenced uses the (not yet supported) Cabal 2.0 file format. Future releases of Stack will both be less eager about Cabal file parsing and support Cabal 2.0. This patch simply bypasses the error for invalid parsing. ## 1.5.0 - 2017-07-25 Behavior changes: * `stack profile` and `stack trace` now add their extra RTS arguments for benchmarks and tests to the beginning of the args, instead of the end. See [#2399](https://github.com/commercialhaskell/stack/issues/2399) * Support for Git-based indices has been removed. Other enhancements: * `stack setup` allow to control options passed to ghcjs-boot with `--ghcjs-boot-options` (one word at a time) and `--[no-]ghcjs-boot-clean` * `stack setup` now accepts a `--install-cabal VERSION` option which will install a specific version of the Cabal library globally. * Updates to store-0.4.1, which has improved performance and better error reporting for version tags. A side-effect of this is that all of stack's binary caches will be invalidated. * `stack solver` will now warn about unexpected `cabal-install` versions. See [#3044](https://github.com/commercialhaskell/stack/issues/3044) * Upstream packages unpacked to a temp dir are now deleted as soon as possible to avoid running out of space in `/tmp`. See [#3018](https://github.com/commercialhaskell/stack/issues/3018) * Add short synonyms for `test-arguments` and `benchmark-arguments` options. * Adds `STACK_WORK` environment variable, to specify work dir. See [#3063](https://github.com/commercialhaskell/stack/issues/3063) * Can now use relative paths for `extra-include-dirs` and `extra-lib-dirs`. See [#2830](https://github.com/commercialhaskell/stack/issues/2830) * Improved bash completion for many options, including `--ghc-options`, `--flag`, targets, and project executables for `exec`. * `--haddock-arguments` is actually used now when `haddock` is invoked during documentation generation. * `--[no-]haddock-hyperlink-source` flag added which allows toggling of sources being included in Haddock output. See [#3099](https://github.com/commercialhaskell/stack/issues/3099) * `stack ghci` will now skip building all local targets, even if they have downstream deps, as long as it's registered in the DB. * The `pvp-bounds` feature now supports adding `-revision` to the end of each value, e.g. `pvp-bounds: both-revision`. This means that, when uploading to Hackage, Stack will first upload your tarball with an unmodified Cabal file, and then upload a Cabal file revision with the PVP bounds added. This can be useful - especially combined with the [Stackage no-revisions feature](http://www.snoyman.com/blog/2017/04/stackages-no-revisions-field) - as a method to ensure PVP compliance without having to proactively fix bounds issues for Stackage maintenance. * Expose a `save-hackage-creds` configuration option * On GHC <= 7.8, filters out spurious linker warnings on windows See [#3127](https://github.com/commercialhaskell/stack/pull/3127) * Better error messages when creating or building packages which alias wired-in packages. See [#3172](https://github.com/commercialhaskell/stack/issues/3172). * MinGW bin folder now is searched for dynamic libraries. See [#3126](https://github.com/commercialhaskell/stack/issues/3126) * When using Nix, nix-shell now depends always on git to prevent runtime errors while fetching metadata * The `stack unpack` command now accepts a form where an explicit Hackage revision hash is specified, e.g. `stack unpack foo-1.2.3@gitsha1:deadbeef`. Note that this should be considered _experimental_, Stack will likely move towards a different hash format in the future. * Binary "stack upgrade" will now warn if the installed executable is not on the PATH or shadowed by another entry. * Allow running tests on tarball created by sdist and upload [#717](https://github.com/commercialhaskell/stack/issues/717). Bug fixes: * Fixes case where `stack build --profile` might not cause executables / tests / benchmarks to be rebuilt. See [#2984](https://github.com/commercialhaskell/stack/issues/2984) * `stack ghci file.hs` now loads the file even if it isn't part of your project. * `stack clean --full` now works when docker is enabled. See [#2010](https://github.com/commercialhaskell/stack/issues/2010) * Fixes an issue where cyclic deps can cause benchmarks or tests to be run before they are built. See [#2153](https://github.com/commercialhaskell/stack/issues/2153) * Fixes `stack build --file-watch` in cases where a directory is removed See [#1838](https://github.com/commercialhaskell/stack/issues/1838) * Fixes `stack dot` and `stack list-dependencies` to use info from the package database for wired-in-packages (ghc, base, etc). See [#3084](https://github.com/commercialhaskell/stack/issues/3084) * Fixes `stack --docker build` when user is part of libvirt/libvirtd groups on Ubuntu Yakkety (16.10). See [#3092](https://github.com/commercialhaskell/stack/issues/3092) * Switching a package between extra-dep and local package now forces rebuild (previously it wouldn't if versions were the same). See [#2147](https://github.com/commercialhaskell/stack/issues/2147) * `stack upload` no longer reveals your password when you type it on MinTTY-based Windows shells, such as Cygwin and MSYS2. See [#3142](https://github.com/commercialhaskell/stack/issues/3142) * `stack script`'s import parser will now properly parse files that have Windows-style line endings (CRLF) ## 1.4.0 - 2017-03-15 Release notes: * Docker images: [fpco/stack-full](https://hub.docker.com/r/fpco/stack-full/) and [fpco/stack-run](https://hub.docker.com/r/fpco/stack-run/) are no longer being built for LTS 8.0 and above. [fpco/stack-build](https://hub.docker.com/r/fpco/stack-build/) images continue to be built with a [simplified process](https://github.com/commercialhaskell/stack/tree/master/etc/dockerfiles/stack-build). [#624](https://github.com/commercialhaskell/stack/issues/624) Major changes: * A new command, `script`, has been added, intended to make the script interpreter workflow more reliable, easier to use, and more efficient. This command forces the user to provide a `--resolver` value, ignores all config files for more reproducible results, and optimizes the existing package check to make the common case of all packages already being present much faster. This mode does require that all packages be present in a snapshot, however. [#2805](https://github.com/commercialhaskell/stack/issues/2805) Behavior changes: * The default package metadata backend has been changed from Git to the 01-index.tar.gz file, from the hackage-security project. This is intended to address some download speed issues from GitHub for people in certain geographic regions. There is now full support for checking out specific Cabal file revisions from downloaded tarballs as well. If you manually specify a package index with only a Git URL, Git will still be used. See [#2780](https://github.com/commercialhaskell/stack/issues/2780) * When you provide the `--resolver` argument to the `stack unpack` command, any packages passed in by name only will be looked up in the given snapshot instead of taking the latest version. For example, `stack --resolver lts-7.14 unpack mtl` will get version 2.2.1 of `mtl`, regardless of the latest version available in the package indices. This will also force the same Cabal file revision to be used as is specified in the snapshot. Unpacking via a package identifier (e.g. `stack --resolver lts-7.14 unpack mtl-2.2.1`) will ignore any settings in the snapshot and take the most recent revision. For backwards compatibility with tools relying on the presence of a `00-index.tar`, Stack will copy the `01-index.tar` file to `00-index.tar`. Note, however, that these files are different; most importantly, 00-index contains only the newest revisions of Cabal files, while 01-index contains all versions. You may still need to update your tooling. * Passing `--(no-)nix-*` options now no longer implies `--nix`, except for `--nix-pure`, so that the user preference whether or not to use Nix is honored even in the presence of options that change the Nix behavior. Other enhancements: * Internal cleanup: configuration types are now based much more on lenses * `stack build` and related commands now allow the user to disable debug symbol stripping with new `--no-strip`, `--no-library-stripping`, and `--no-executable-shipping` flags, closing [#877](https://github.com/commercialhaskell/stack/issues/877). Also turned error message for missing targets more readable ([#2384](https://github.com/commercialhaskell/stack/issues/2384)) * `stack haddock` now shows index.html paths when documentation is already up to date. Resolved [#781](https://github.com/commercialhaskell/stack/issues/781) * Respects the `custom-setup` field introduced in Cabal 1.24. This supercedes any `explicit-setup-deps` settings in your `stack.yaml` and trusts the package's Cabal file to explicitly state all its dependencies. * If system package installation fails, `get-stack.sh` will fail as well. Also shows warning suggesting to run `apt-get update` or similar, depending on the OS. ([#2898](https://github.com/commercialhaskell/stack/issues/2898)) * When `stack ghci` is run with a config with no packages (e.g. global project), it will now look for source files in the current work dir. ([#2878](https://github.com/commercialhaskell/stack/issues/2878)) * Bump to Hpack 0.17.0 to allow `custom-setup` and `!include "..."` in `package.yaml`. * The script interpreter will now output error logging. In particular, this means it will output info about plan construction errors. ([#2879](https://github.com/commercialhaskell/stack/issues/2879)) * `stack ghci` now takes `--flag` and `--ghc-options` again (inadvertently removed in 1.3.0). ([#2986](https://github.com/commercialhaskell/stack/issues/2986)) * `stack exec` now takes `--rts-options` which passes the given arguments inside of `+RTS ... args .. -RTS` to the executable. This works around Stack itself consuming the RTS flags on Windows. ([#2640](https://github.com/commercialhaskell/stack/issues/2640)) * Upgraded `http-client-tls` version, which now offers support for the `socks5://` and `socks5h://` values in the `http_proxy` and `https_proxy` environment variables. Bug fixes: * Bump to Hpack 0.16.0 to avoid character encoding issues when reading and writing on non-UTF8 systems. * `stack ghci` will no longer ignore hsSourceDirs that contain `..`. ([#2895](https://github.com/commercialhaskell/stack/issues/2895)) * `stack list-dependencies --license` now works for wired-in-packages, like base. ([#2871](https://github.com/commercialhaskell/stack/issues/2871)) * `stack setup` now correctly indicates when it uses system ghc ([#2963](https://github.com/commercialhaskell/stack/issues/2963)) * Fix to `stack config set`, in 1.3.2 it always applied to the global project. ([#2709](https://github.com/commercialhaskell/stack/issues/2709)) * Previously, Cabal files without exe or lib would fail on the "copy" step. ([#2862](https://github.com/commercialhaskell/stack/issues/2862)) * `stack upgrade --git` now works properly. Workaround for affected versions (>= 1.3.0) is to instead run `stack upgrade --git --source-only`. ([#2977](https://github.com/commercialhaskell/stack/issues/2977)) * Added support for GHC 8's slightly different warning format for dumping warnings from logs. * Work around a bug in Cabal/GHC in which package IDs are not unique for different source code, leading to Stack not always rebuilding packages depending on local packages which have changed. ([#2904](https://github.com/commercialhaskell/stack/issues/2904)) ## 1.3.2 - 2016-12-27 Bug fixes: * `stack config set` can now be used without a compiler installed [#2852](https://github.com/commercialhaskell/stack/issues/2852). * `get-stack.sh` now installs correct binary on ARM for generic linux and raspbian, closing [#2856](https://github.com/commercialhaskell/stack/issues/2856). * Correct the testing of whether a package database exists by checking for the `package.cache` file itself instead of the containing directory. * Revert a change in the previous release which made it impossible to set local extra-dep packages as targets. This was overkill; we really only wanted to disable their test suites, which was already handled by a later patch. [#2849](https://github.com/commercialhaskell/stack/issues/2849) * `stack new` always treats templates as being UTF-8 encoding, ignoring locale settings on a local machine. See [Yesod mailing list discussion](https://groups.google.com/d/msg/yesodweb/ZyWLsJOtY0c/aejf9E7rCAAJ) ## 1.3.0 - 2016-12-12 Release notes: * For the _next_ Stack release after this one, we are planning changes to our Linux releases, including dropping our Ubuntu, Debian, CentOS, and Fedora package repositories and switching to statically linked binaries. See [#2534](https://github.com/commercialhaskell/stack/issues/2534). Note that upgrading without a package manager has gotten easier with new binary upgrade support in `stack upgrade` (see the Major Changes section below for more information). In addition, the get.haskellstack.org script no longer installs from Ubuntu, Debian, CentOS, or Fedora package repositories. Instead it places a generic binary in /usr/local/bin. Major changes: * Stack will now always use its own GHC installation, even when a suitable GHC installation is available on the PATH. To get the old behaviour, use the `--system-ghc` flag or run `stack config set system-ghc --global true`. Docker- and Nix-enabled projects continue to use the GHC installations in their environment by default. NB: Scripts that previously used Stack in combination with a system GHC installation should now include a `stack setup` line or use the `--install-ghc` flag. [#2221](https://github.com/commercialhaskell/stack/issues/2221) * `stack ghci` now defaults to skipping the build of target packages, because support has been added for invoking "initial build steps", which create autogen files and run preprocessors. The `--no-build` flag is now deprecated because it should no longer be necessary. See [#1364](https://github.com/commercialhaskell/stack/issues/1364) * Stack is now capable of doing binary upgrades instead of always recompiling a new version from source. Running `stack upgrade` will now default to downloading a binary version of Stack from the most recent release, if one is available. See `stack upgrade --help` for more options. [#1238](https://github.com/commercialhaskell/stack/issues/1238) Behavior changes: * Passing `--resolver X` with a Stack command which forces creation of a global project config, will pass resolver X into the initial config. See [#2579](https://github.com/commercialhaskell/stack/issues/2229). * Switch the "Run from outside project" messages to debug-level, to avoid spamming users in the normal case of non-project usage * If a remote package is specified (such as a Git repo) without an explicit `extra-dep` setting, a warning is given to the user to provide one explicitly. Other enhancements: * `stack haddock` now supports `--haddock-internal`. See [#2229](https://github.com/commercialhaskell/stack/issues/2229) * Add support for `system-ghc` and `install-ghc` fields to `stack config set` command. * Add `ghc-build` option to override autodetected GHC build to use (e.g. gmp4, tinfo6, nopie) on Linux. * `stack setup` detects systems where gcc enables PIE by default (such as Ubuntu 16.10 and Hardened Gentoo) and adjusts the GHC `configure` options accordingly. [#2542](https://github.com/commercialhaskell/stack/issues/2542) * Upload to Hackage with HTTP digest instead of HTTP basic. * Make `stack list-dependencies` understand all of the `stack dot` options too. * Add the ability for `stack list-dependencies` to list dependency licenses by passing the `--license` flag. * Dump logs that contain warnings for any local non-dependency packages [#2545](https://github.com/commercialhaskell/stack/issues/2545) * Add the `dump-logs` config option and `--dump-logs` command line option to get full build output on the console. [#426](https://github.com/commercialhaskell/stack/issues/426) * Add the `--open` option to "stack hpc report" command, causing the report to be opened in the browser. * The `stack config set` command now accepts a `--global` flag for suitable fields which causes it to modify the global user configuration (`~/.stack/config.yaml`) instead of the project configuration. [#2675](https://github.com/commercialhaskell/stack/pull/2675) * Information on the latest available snapshots is now downloaded from S3 instead of stackage.org, increasing reliability in case of stackage.org outages. [#2653](https://github.com/commercialhaskell/stack/pull/2653) * `stack dot` and `stack list-dependencies` now take targets and flags. [#1919](https://github.com/commercialhaskell/stack/issues/1919) * Deprecate `stack setup --stack-setup-yaml` for `--setup-info-yaml` based on discussion in [#2647](https://github.com/commercialhaskell/stack/issues/2647). * The `--main-is` flag for GHCI now implies the TARGET, fixing [#1845](https://github.com/commercialhaskell/stack/issues/1845). * `stack ghci` no longer takes all build options, as many weren't useful [#2199](https://github.com/commercialhaskell/stack/issues/2199) * `--no-time-in-log` option, to make verbose logs more diffable [#2727](https://github.com/commercialhaskell/stack/issues/2727) * `--color` option added to override auto-detection of ANSI support [#2725](https://github.com/commercialhaskell/stack/issues/2725) * Missing extra-deps are now warned about, adding a degree of typo detection [#1521](https://github.com/commercialhaskell/stack/issues/1521) * No longer warns about missing build-tools if they are on the PATH. [#2235](https://github.com/commercialhaskell/stack/issues/2235) * Replace enclosed-exceptions with safe-exceptions. [#2768](https://github.com/commercialhaskell/stack/issues/2768) * The install location for GHC and other programs can now be configured with the `local-programs-path` option in `config.yaml`. [#1644](https://github.com/commercialhaskell/stack/issues/1644) * Added option to add nix dependencies as nix GC roots * Proper pid 1 (init) process for `stack exec` with Docker * Dump build logs if they contain warnings. [#2545](https://github.com/commercialhaskell/stack/issues/2545) * Docker: redirect stdout of `docker pull` to stderr so that it will not interfere with output of other commands. * Nix & docker can be activated at the same time, in order to run Stack in a nix-shell in a container, preferably from an image already containing the nix dependencies in its /nix/store * Stack/nix: Dependencies can be added as nix GC roots, so they are not removed when running `nix-collect-garbage` Bug fixes: * Fixed a gnarly bug where programs and package tarballs sometimes have corrupted downloads. See [#2657](https://github.com/commercialhaskell/stack/issues/2568). * Add proper support for non-ASCII characters in file paths for the `sdist` command. See [#2549](https://github.com/commercialhaskell/stack/issues/2549) * Never treat `extra-dep` local packages as targets. This ensures things like test suites are not run for these packages, and that build output is not hidden due to their presence. * Fix a resource leak in `sinkProcessStderrStdout` which could affect much of the codebase, in particular copying precompiled packages. [#1979](https://github.com/commercialhaskell/stack/issues/1979) * Docker: ensure that interrupted extraction process does not cause corrupt file when downloading a Docker-compatible Stack executable [#2568](https://github.com/commercialhaskell/stack/issues/2568) * Fixed running `stack hpc report` on package targets. [#2664](https://github.com/commercialhaskell/stack/issues/2664) * Fix a long-standing performance regression where Stack would parse the `.dump-hi` files of the library components of local packages twice. [#2658](https://github.com/commercialhaskell/stack/pull/2658) * Fixed a regression in "stack ghci --no-load", where it would prompt for a main module to load. [#2603](https://github.com/commercialhaskell/stack/pull/2603) * Build Setup.hs files with the threaded RTS, mirroring the behavior of `cabal-install` and enabling more complex build systems in those files. * Fixed a bug in passing along `--ghc-options` to ghcjs. They were being provided as `--ghc-options` to Cabal, when it needs to be `--ghcjs-options`. [#2714](https://github.com/commercialhaskell/stack/issues/2714) * Launch Docker from the project root regardless of the working directory Stack is invoked from. This means paths relative to the project root (e.g. environment files) can be specified in `stack.yaml`'s docker `run-args`. * `stack setup --reinstall` now behaves as expected. [#2554](https://github.com/commercialhaskell/stack/issues/2554) ## 1.2.0 - 2016-09-16 Release notes: * On many Un*x systems, Stack can now be installed with a simple one-liner: wget -qO- https://get.haskellstack.org/ | sh * The fix for [#2175](https://github.com/commercialhaskell/stack/issues/2175) entails that Stack must perform a full clone of a large Git repo of Hackage meta-information. The total download size is about 200 MB. Please be aware of this when upgrading your Stack installation. * If you use Mac OS X, you may want to delay upgrading to macOS Sierra as there are reports of GHC panics when building some packages (including Stack itself). See [#2577](https://github.com/commercialhaskell/stack/issues/2577) * This version of Stack does not build on ARM or PowerPC systems (see [store#37](https://github.com/fpco/store/issues/37)). Please stay with version 1.1.2 for now on those architectures. This will be rectified soon! * We are now releasing a statically linked Stack binary for [64-bit Linux](https://get.haskellstack.org/stable/linux-x86_64-static.tar.gz). Please try it and let us know if you run into any trouble on your platform. * We are planning some changes to our Linux releases, including dropping our Ubuntu, Debian, CentOS, and Fedora package repositories and switching to statically linked binaries. We would value your feedback in [#2534](https://github.com/commercialhaskell/stack/issues/2534). Major changes: * Add `stack hoogle` command. [#55](https://github.com/commercialhaskell/stack/issues/55) * Support for absolute file path in `url` field of `setup-info` or `--ghc-bindist` * Add support for rendering GHCi scripts targeting different GHCi like applications [#2457](https://github.com/commercialhaskell/stack/pull/2457) Behavior changes: * Remove `stack ide start` and `stack ide load-targets` commands. [#2178](https://github.com/commercialhaskell/stack/issues/2178) * Support .buildinfo files in `stack ghci`. [#2242](https://github.com/commercialhaskell/stack/pull/2242) * Support -ferror-spans syntax in GHC error messages. * Avoid unpacking ghc to `/tmp` [#996](https://github.com/commercialhaskell/stack/issues/996) * The Linux `gmp4` GHC bindist is no longer considered a full-fledged GHC variant and can no longer be specified using the `ghc-variant` option, and instead is treated more like a slightly different platform. Other enhancements: * Use the `store` package for binary serialization of most caches. * Only require minor version match for Docker Stack exe. This way, we can make patch releases for version bounds and similar build issues without needing to upload new binaries for Docker. * Stack/Nix: Passes the right ghc derivation as an argument to the `shell.nix` when a custom `shell.nix` is used. See [#2243](https://github.com/commercialhaskell/stack/issues/2243) * Stack/Nix: Sets `LD_LIBRARY_PATH` so packages using C libs for Template Haskell can work (See _e.g._ [this HaskellR issue](https://github.com/tweag/HaskellR/issues/253)) * Parse CLI arguments and configuration files into less permissive types, improving error messages for bad inputs. [#2267](https://github.com/commercialhaskell/stack/issues/2267) * Add the ability to explicitly specify a gcc executable. [#593](https://github.com/commercialhaskell/stack/issues/593) * Nix: No longer uses LTS mirroring in nixpkgs. Gives to nix-shell a derivation like `haskell.compiler.ghc801` See [#2259](https://github.com/commercialhaskell/stack/issues/2259) * Perform some subprocesses during setup concurrently, slightly speeding up most commands. [#2346](https://github.com/commercialhaskell/stack/pull/2346) * `stack setup` no longer unpacks to the system temp dir on posix systems. [#996](https://github.com/commercialhaskell/stack/issues/996) * `stack setup` detects libtinfo6 and ncurses6 and can download alternate GHC bindists [#257](https://github.com/commercialhaskell/stack/issues/257) [#2302](https://github.com/commercialhaskell/stack/issues/2302). * `stack setup` detects Linux ARMv7 downloads appropriate GHC bindist [#2103](https://github.com/commercialhaskell/stack/issues/2103) * Custom `stack` binaries list dependency versions in output for `--version`. See [#2222](https://github.com/commercialhaskell/stack/issues/2222) and [#2450](https://github.com/commercialhaskell/stack/issues/2450). * Use a pretty printer to output dependency resolution errors. [#1912](https://github.com/commercialhaskell/stack/issues/1912) * Remove the `--os` flag [#2227](https://github.com/commercialhaskell/stack/issues/2227) * Add 'netbase' and 'ca-certificates' as dependency for .deb packages. [#2293](https://github.com/commercialhaskell/stack/issues/2293). * Add `stack ide targets` command. * Enhance debug logging with subprocess timings. * Pretty-print YAML parse errors [#2374](https://github.com/commercialhaskell/stack/issues/2374) * Clarify confusing `stack setup` output [#2314](https://github.com/commercialhaskell/stack/issues/2314) * Delete `Stack.Types` multimodule to improve build times [#2405](https://github.com/commercialhaskell/stack/issues/2405) * Remove spurious newlines in build logs [#2418](https://github.com/commercialhaskell/stack/issues/2418) * Interpreter: Provide a way to hide implicit packages [#1208](https://github.com/commercialhaskell/stack/issues/1208) * Check executability in exec lookup [#2489](https://github.com/commercialhaskell/stack/issues/2489) Bug fixes: * Fix Cabal warning about use of a deprecated Cabal flag [#2350](https://github.com/commercialhaskell/stack/issues/2350) * Support most executable extensions on Windows [#2225](https://github.com/commercialhaskell/stack/issues/2225) * Detect resolver change in `stack solver` [#2252](https://github.com/commercialhaskell/stack/issues/2252) * Fix a bug in docker image creation where the wrong base image was selected [#2376](https://github.com/commercialhaskell/stack/issues/2376) * Ignore special entries when unpacking tarballs [#2361](https://github.com/commercialhaskell/stack/issues/2361) * Fixes src directory pollution of `style.css` and `highlight.js` with GHC 8's haddock [#2429](https://github.com/commercialhaskell/stack/issues/2429) * Handle filepaths with spaces in `stack ghci` [#2266](https://github.com/commercialhaskell/stack/issues/2266) * Apply ghc-options to snapshot packages [#2289](https://github.com/commercialhaskell/stack/issues/2289) * `stack sdist`: Fix timestamp in tarball [#2394](https://github.com/commercialhaskell/stack/pull/2394) * Allow global Stack arguments with a script [#2316](https://github.com/commercialhaskell/stack/issues/2316) * Inconsistency between ToJSON and FromJSON instances of PackageLocation [#2412](https://github.com/commercialhaskell/stack/pull/2412) * Perform Unicode normalization on filepaths [#1810](https://github.com/commercialhaskell/stack/issues/1810) * Solver: always keep ghc wired-in as hard constraints [#2453](https://github.com/commercialhaskell/stack/issues/2453) * Support OpenBSD's tar where possible, require GNU tar for xz support [#2283](https://github.com/commercialhaskell/stack/issues/2283) * Fix using --coverage with Cabal-1.24 [#2424](https://github.com/commercialhaskell/stack/issues/2424) * When marking exe installed, remove old version [#2373](https://github.com/commercialhaskell/stack/issues/2373) * Stop truncating `all-cabal-hashes` git repo [#2175](https://github.com/commercialhaskell/stack/issues/2175) * Handle non-ASCII filenames on Windows [#2491](https://github.com/commercialhaskell/stack/issues/2491) * Avoid using multiple versions of a package in script interpreter by passing package-id to ghc/runghc [#1957](https://github.com/commercialhaskell/stack/issues/1957) * Only pre-load compiler version when using nix integration [#2459](https://github.com/commercialhaskell/stack/issues/2459) * Solver: parse Cabal errors also on Windows [#2502](https://github.com/commercialhaskell/stack/issues/2502) * Allow exec and ghci commands in interpreter mode. Scripts can now automatically open in the repl by using `exec ghci` instead of `runghc` in the shebang command. [#2510](https://github.com/commercialhaskell/stack/issues/2510) * Now consider a package to be dirty when an extra-source-file is changed. See [#2040](https://github.com/commercialhaskell/stack/issues/2040) ## 1.1.2 - 2016-05-20 Release notes: * Official FreeBSD binaries are [now available](http://docs.haskellstack.org/en/stable/install_and_upgrade/#freebsd) [#1253](https://github.com/commercialhaskell/stack/issues/1253). Major changes: * Extensible custom snapshots implemented. These allow you to define snapshots which extend other snapshots. See [#863](https://github.com/commercialhaskell/stack/issues/863). Local file custom snapshots can now be safely updated without changing their name. Remote custom snapshots should still be treated as immutable. Behavior changes: * `stack path --compiler` was added in the last release, to yield a path to the compiler. Unfortunately, `--compiler` is a global option that is useful to use with `stack path`. The same functionality is now provided by `stack path --compiler-exe`. See [#2123](https://github.com/commercialhaskell/stack/issues/2123) * For packages specified in terms of a git or hg repo, the hash used in the location has changed. This means that existing downloads from older stack versions won't be used. This is a side-effect of the fix to [#2133](https://github.com/commercialhaskell/stack/issues/2133) * `stack upgrade` no longer pays attention to local `stack.yaml` files, just the global config and CLI options. [#1392](https://github.com/commercialhaskell/stack/issues/1392) * `stack ghci` now uses `:add` instead of `:load`, making it potentially work better with user scripts. See [#1888](https://github.com/commercialhaskell/stack/issues/1888) Other enhancements: * Grab Cabal files via Git SHA to avoid regressions from Hackage revisions [#2070](https://github.com/commercialhaskell/stack/pull/2070) * Custom snapshots now support `ghc-options`. * Package git repos are now re-used rather than re-cloned. See [#1620](https://github.com/commercialhaskell/stack/issues/1620) * `DESTDIR` is filtered from environment when installing GHC. See [#1460](https://github.com/commercialhaskell/stack/issues/1460) * `stack haddock` now supports `--haddock-arguments`. See [#2144](https://github.com/commercialhaskell/stack/issues/2144) * Signing: warn if GPG_TTY is not set as per `man gpg-agent` Bug fixes: * Now ignore project config when doing `stack init` or `stack new`. See [#2110](https://github.com/commercialhaskell/stack/issues/2110) * Packages specified by git repo can now have submodules. See [#2133](https://github.com/commercialhaskell/stack/issues/2133) * Fix of hackage index fetch retry. See re-opening of [#1418](https://github.com/commercialhaskell/stack/issues/1418#issuecomment-217633843) * HPack now picks up changes to filesystem other than package.yaml. See [#2051](https://github.com/commercialhaskell/stack/issues/2051) * "stack solver" no longer suggests --omit-packages. See [#2031](https://github.com/commercialhaskell/stack/issues/2031) * Fixed an issue with building Cabal's Setup.hs. See [#1356](https://github.com/commercialhaskell/stack/issues/1356) * Package dirtiness now pays attention to deleted files. See [#1841](https://github.com/commercialhaskell/stack/issues/1841) * `stack ghci` now uses `extra-lib-dirs` and `extra-include-dirs`. See [#1656](https://github.com/commercialhaskell/stack/issues/1656) * Relative paths outside of source dir added via `qAddDependentFile` are now checked for dirtiness. See [#1982](https://github.com/commercialhaskell/stack/issues/1982) * Signing: always use `--with-fingerprints` ## 1.1.0 - 2016-05-04 Release notes: * Added Ubuntu 16.04 LTS (xenial) Apt repo. * No longer uploading new versions to Fedora 21 repo. Behavior changes: * Snapshot packages are no longer built with executable profiling. See [#1179](https://github.com/commercialhaskell/stack/issues/1179). * `stack init` now ignores symlinks when searching for Cabal files. It also now ignores any directory that begins with `.` (as well as `dist` dirs) - before it would only ignore `.git`, `.stack-work`, and `dist`. * The Stack executable is no longer built with `-rtsopts`. Before, when `-rtsopts` was enabled, Stack would process `+RTS` options even when intended for some other program, such as when used with `stack exec -- prog +RTS`. See [#2022](https://github.com/commercialhaskell/stack/issues/2022). * The `stack path --ghc-paths` option is deprecated and renamed to `--programs`. `--compiler` is added, which points directly at the compiler used in the current project. `--compiler-bin` points to the compiler's bin dir. * For consistency with the `$STACK_ROOT` environment variable, the `stack path --global-stack-root` flag and the `global-stack-root` field in the output of `stack path` are being deprecated and replaced with the `stack-root` flag and output field. Additionally, the Stack root can now be specified via the `--stack-root` command-line flag. See [#1148](https://github.com/commercialhaskell/stack/issues/1148). * `stack sig` GPG-related sub-commands were removed (folded into `upload` and `sdist`) * GPG signing of packages while uploading to Hackage is now the default. Use `upload --no-signature` if you would rather not contribute your package signature. If you don't yet have a GPG keyset, read this [blog post on GPG keys](https://fpcomplete.com/blog/2016/05/stack-security-gnupg-keys). We can add a `stack.yaml` config setting to disable signing if some people desire it. We hope that people will sign. Later we will be adding GPG signature verification options. * `stack build pkg-1.2.3` will now build even if the snapshot has a different package version - it is treated as an extra-dep. `stack build local-pkg-1.2.3` is an error even if the version number matches the local package [#2028](https://github.com/commercialhaskell/stack/issues/2028). * Having a `nix:` section no longer implies enabling nix build. This allows the user to globally configure whether nix is used (unless the project overrides the default explicitly). See [#1924](https://github.com/commercialhaskell/stack/issues/1924). * Remove deprecated valid-wanted field. * Docker: mount home directory in container [#1949](https://github.com/commercialhaskell/stack/issues/1949). * Deprecate `--local-bin-path` instead `--local-bin`. * `stack image`: allow absolute source paths for `add`. Other enhancements: * `stack haddock --open [PACKAGE]` opens the local haddocks in the browser. * Fix too much rebuilding when enabling/disabling profiling flags. * `stack build pkg-1.0` will now build `pkg-1.0` even if the snapshot specifies a different version (it introduces a temporary extra-dep) * Experimental support for `--split-objs` added [#1284](https://github.com/commercialhaskell/stack/issues/1284). * `git` packages with submodules are supported by passing the `--recursive` flag to `git clone`. * When using [Hpack](https://github.com/sol/hpack), only regenerate Cabal files when Hpack files change. * Hpack files can now be used in templates * `stack ghci` now runs ghci as a separate process [#1306](https://github.com/commercialhaskell/stack/issues/1306) * Retry when downloading snapshots and package indices * Many build options are configurable now in `stack.yaml`: ~~~yaml build: library-profiling: true executable-profiling: true haddock: true haddock-deps: true copy-bins: true prefetch: true force-dirty: true keep-going: true test: true test-arguments: rerun-tests: true additional-args: ['-fprof'] coverage: true no-run-tests: true bench: true benchmark-opts: benchmark-arguments: -O2 no-run-benchmarks: true reconfigure: true cabal-verbose: true ~~~ * A number of URLs are now configurable, useful for firewalls. See [#1794](https://github.com/commercialhaskell/stack/issues/1884). * Suggest causes when executables are missing. * Allow `--omit-packages` even without `--solver`. * Improve the generated `stack.yaml`. * Improve ghci results after :load Main module collision with main file path. * Only load the hackage index if necessary [#1883](https://github.com/commercialhaskell/stack/issues/1883), [#1892](https://github.com/commercialhaskell/stack/issues/1892). * init: allow local packages to be deps of deps [#1965](https://github.com/commercialhaskell/stack/issues/1965). * Always use full fingerprints from GPG [#1952](https://github.com/commercialhaskell/stack/issues/1952). * Default to using `gpg2` and fall back to `gpg` [#1976](https://github.com/commercialhaskell/stack/issues/1976). * Add a flag for --verbosity silent. * Add `haddock --open` flag [#1396](https://github.com/commercialhaskell/stack/issues/1396). Bug fixes: * Package tarballs would fail to unpack. [#1884](https://github.com/commercialhaskell/stack/issues/1884). * Fixed errant warnings about missing modules, after deleted and removed from Cabal file [#921](https://github.com/commercialhaskell/stack/issues/921) [#1805](https://github.com/commercialhaskell/stack/issues/1805). * Now considers a package to dirty when the Hpack file is changed [#1819](https://github.com/commercialhaskell/stack/issues/1819). * Nix: cancelling a Stack build now exits properly rather than dropping into a nix-shell [#1778](https://github.com/commercialhaskell/stack/issues/1778). * `allow-newer: true` now causes `--exact-configuration` to be passed to Cabal. See [#1579](https://github.com/commercialhaskell/stack/issues/1579). * `stack solver` no longer fails with `InvalidRelFile` for relative package paths including `..`. See [#1954](https://github.com/commercialhaskell/stack/issues/1954). * Ignore emacs lock files when finding Cabal files [#1897](https://github.com/commercialhaskell/stack/issues/1897). * Use lenient UTF-8 decode for build output [#1945](https://github.com/commercialhaskell/stack/issues/1945). * Clear index cache whenever index updated [#1962](https://github.com/commercialhaskell/stack/issues/1962). * Fix: Building a container image drops a .stack-work dir in the current working (sub)directory [#1975](https://github.com/commercialhaskell/stack/issues/1975). * Fix: Rebuilding when disabling profiling [#2023](https://github.com/commercialhaskell/stack/issues/2023). ## 1.0.4.3 - 2016-04-07 Bug fixes: * Don't delete contents of ~/.ssh when using `stack clean --full` with Docker enabled [#2000](https://github.com/commercialhaskell/stack/issues/2000) ## 1.0.4.2 - 2016-03-09 Build with `path-io-1.0.0`. There are no changes in behaviour from 1.0.4, so no binaries are released for this version. ## 1.0.4.1 - 2016-02-21 Fixes build with `aeson-0.11.0.0`. There are no changes in behaviour from 1.0.4, so no binaries are released for this version. ## 1.0.4 - 2016-02-20 Major changes: * Some notable changes in `stack init`: * Overall it should now be able to initialize almost all existing Cabal packages out of the box as long as the package itself is consistently defined. * Choose the best possible snapshot and add extra dependencies on top of a snapshot resolver rather than a compiler resolver - [#1583](https://github.com/commercialhaskell/stack/pull/1583) * Automatically omit a package (`--omit-packages`) when it is compiler incompatible or when there are packages with conflicting dependency requirements. See [#1674](https://github.com/commercialhaskell/stack/pull/1674). * Some more changes for a better user experience. Please refer to the doc guide for details. * Add support for Hpack, alternative package description format [#1679](https://github.com/commercialhaskell/stack/issues/1679) Other enhancements: * Docker: pass ~/.ssh and SSH auth socket into container, so that git repos work [#1358](https://github.com/commercialhaskell/stack/issues/1358). * Docker: strip suffix from docker --version. [#1653](https://github.com/commercialhaskell/stack/issues/1653) * Docker: pass USER and PWD environment variables into container. * On each run, Stack will test the Stack root directory (~/.stack), and the project and package work directories (.stack-work) for whether they are owned by the current user and abort if they are not. This precaution can be disabled with the `--allow-different-user` flag or `allow-different-user` option in the global config (~/.stack/config.yaml). [#471](https://github.com/commercialhaskell/stack/issues/471) * Added `stack clean --full` option for full working dir cleanup. * YAML config: support Zip archives. * Redownload build plan if parsing fails [#1702](https://github.com/commercialhaskell/stack/issues/1702). * Give mustache templates access to a 'year' tag [#1716](https://github.com/commercialhaskell/stack/pull/1716). * Have "stack ghci" warn about module name aliasing. * Add "stack ghci --load-local-deps". * Build Setup.hs with -rtsopts [#1687](https://github.com/commercialhaskell/stack/issues/1687). * `stack init` accepts a list of directories. * Add flag infos to DependencyPlanFailures (for better error output in case of flags) [#713](https://github.com/commercialhaskell/stack/issues/713) * `stack new --bare` complains for overwrites, and add `--force` option [#1597](https://github.com/commercialhaskell/stack/issues/1597). Bug fixes: * Previously, `stack ghci` would fail with `cannot satisfy -package-id` when the implicit build step changes the package key of some dependency. * Fix: Building with ghcjs: "ghc-pkg: Prelude.chr: bad argument: 2980338" [#1665](https://github.com/commercialhaskell/stack/issues/1665). * Fix running test / bench with `--profile` / `--trace`. * Fix: build progress counter is no longer visible [#1685](https://github.com/commercialhaskell/stack/issues/1685). * Use "-RTS" w/ profiling to allow extra args [#1772](https://github.com/commercialhaskell/stack/issues/1772). * Fix withUnpackedTarball7z to find name of srcDir after unpacking (fixes `stack setup` fails for ghcjs project on windows) [#1774](https://github.com/commercialhaskell/stack/issues/1774). * Add space before auto-generated bench opts (makes profiling options work uniformly for applications and benchmark suites) [#1771](https://github.com/commercialhaskell/stack/issues/1771). * Don't try to find plugin if it resembles flag. * Setup.hs changes cause package dirtiness [#1711](https://github.com/commercialhaskell/stack/issues/1711). * Send "stack templates" output to stdout [#1792](https://github.com/commercialhaskell/stack/issues/1792). ## 1.0.2 - 2016-01-18 Release notes: - Arch Linux: Stack has been adopted into the [official community repository](https://www.archlinux.org/packages/community/x86_64/stack/), so we will no longer be updating the AUR with new versions. See the [install/upgrade guide](http://docs.haskellstack.org/en/stable/install_and_upgrade/#arch-linux) for current download instructions. Major changes: - `stack init` and `solver` overhaul [#1583](https://github.com/commercialhaskell/stack/pull/1583) Other enhancements: - Disable locale/codepage hacks when GHC >=7.10.3 [#1552](https://github.com/commercialhaskell/stack/issues/1552) - Specify multiple images to build for `stack image container` [docs](http://docs.haskellstack.org/en/stable/yaml_configuration/#image) - Specify which executables to include in images for `stack image container` [docs](http://docs.haskellstack.org/en/stable/yaml_configuration/#image) - Docker: pass supplementary groups and umask into container - If git fetch fails wipe the directory and try again from scratch [#1418](https://github.com/commercialhaskell/stack/issues/1418) - Warn if newly installed executables won't be available on the PATH [#1362](https://github.com/commercialhaskell/stack/issues/1362) - `stack.yaml`: for `stack image container`, specify multiple images to generate, and which executables should be added to those images - GHCI: add interactive Main selection [#1068](https://github.com/commercialhaskell/stack/issues/1068) - Care less about the particular name of a GHCJS sdist folder [#1622](https://github.com/commercialhaskell/stack/issues/1622) - Unified Enable/disable help messaging [#1613](https://github.com/commercialhaskell/stack/issues/1613) Bug fixes: - Don't share precompiled packages between GHC/platform variants and Docker [#1551](https://github.com/commercialhaskell/stack/issues/1551) - Properly redownload corrupted downloads with the correct file size. [Mailing list discussion](https://groups.google.com/d/msg/haskell-stack/iVGDG5OHYxs/FjUrR5JsDQAJ) - Gracefully handle invalid paths in error/warning messages [#1561](https://github.com/commercialhaskell/stack/issues/1561) - Nix: select the correct GHC version corresponding to the snapshot even when an abstract resolver is passed via `--resolver` on the command-line. [#1641](https://github.com/commercialhaskell/stack/issues/1641) - Fix: Stack does not allow using an external package from ghci [#1557](https://github.com/commercialhaskell/stack/issues/1557) - Disable ambiguous global '--resolver' option for 'stack init' [#1531](https://github.com/commercialhaskell/stack/issues/1531) - Obey `--no-nix` flag - Fix: GHCJS Execute.hs: Non-exhaustive patterns in lambda [#1591](https://github.com/commercialhaskell/stack/issues/1591) - Send file-watch and sticky logger messages to stderr [#1302](https://github.com/commercialhaskell/stack/issues/1302) [#1635](https://github.com/commercialhaskell/stack/issues/1635) - Use globaldb path for querying Cabal version [#1647](https://github.com/commercialhaskell/stack/issues/1647) ## 1.0.0 - 2015-12-24 Release notes: * We're calling this version 1.0.0 in preparation for Stackage LTS 4. Note, however, that this does not mean the code's API will be stable as this is primarily an end-user tool. Enhancements: * Added flag `--profile` flag: passed with `stack build`, it will enable profiling, and for `--bench` and `--test` it will generate a profiling report by passing `+RTS -p` to the executable(s). Great for using like `stack build --bench --profile` (remember that enabling profile will slow down your benchmarks by >4x). Run `stack build --bench` again to disable the profiling and get proper speeds * Added flag `--trace` flag: just like `--profile`, it enables profiling, but instead of generating a report for `--bench` and `--test`, prints out a stack trace on exception. Great for using like `stack build --test --trace` * Nix: all options can be overridden on command line [#1483](https://github.com/commercialhaskell/stack/issues/1483) * Nix: build environments (shells) are now pure by default. * Make verbosity silent by default in script interpreter mode [#1472](https://github.com/commercialhaskell/stack/issues/1472) * Show a message when resetting git commit fails [#1453](https://github.com/commercialhaskell/stack/issues/1453) * Improve Unicode handling in project/package names [#1337](https://github.com/commercialhaskell/stack/issues/1337) * Fix ambiguity between a Stack command and a filename to execute (prefer `stack` subcommands) [#1471](https://github.com/commercialhaskell/stack/issues/1471) * Support multi line interpreter directive comments [#1394](https://github.com/commercialhaskell/stack/issues/1394) * Handle space separated pids in ghc-pkg dump (for GHC HEAD) [#1509](https://github.com/commercialhaskell/stack/issues/1509) * Add ghci --no-package-hiding option [#1517](https://github.com/commercialhaskell/stack/issues/1517) * `stack new` can download templates from URL [#1466](https://github.com/commercialhaskell/stack/issues/1466) Bug fixes: * Nix: `stack exec` options are passed properly to the Stack sub process [#1538](https://github.com/commercialhaskell/stack/issues/1538) * Nix: specifying a shell-file works in any current working directory [#1547](https://github.com/commercialhaskell/stack/issues/1547) * Nix: use `--resolver` argument * Docker: fix missing image message and '--docker-auto-pull' * No HTML escaping for "stack new" template params [#1475](https://github.com/commercialhaskell/stack/issues/1475) * Set permissions for generated .ghci script [#1480](https://github.com/commercialhaskell/stack/issues/1480) * Restrict commands allowed in interpreter mode [#1504](https://github.com/commercialhaskell/stack/issues/1504) * `stack ghci` doesn't see preprocessed files for executables [#1347](https://github.com/commercialhaskell/stack/issues/1347) * All test suites run even when only one is requested [#1550](https://github.com/commercialhaskell/stack/pull/1550) * Edge cases in broken templates give odd errors [#1535](https://github.com/commercialhaskell/stack/issues/1535) * Fix test coverage bug on windows ## 0.1.10.1 - 2015-12-13 Bug fixes: * `stack image container` did not actually build an image [#1473](https://github.com/commercialhaskell/stack/issues/1473) ## 0.1.10.0 - 2015-12-04 Release notes: * The Stack home page is now at [haskellstack.org](http://haskellstack.org), which shows the documentation rendered by readthedocs.org. Note: this has necessitated some changes to the links in the documentation's markdown source code, so please check the links on the website before submitting a PR to fix them. * The locations of the [Ubuntu](http://docs.haskellstack.org/en/stable/install_and_upgrade/#ubuntu) and [Debian](http://docs.haskellstack.org/en/stable/install_and_upgrade/#debian) package repositories have changed to have correct URL semantics according to Debian's guidelines [#1378](https://github.com/commercialhaskell/stack/issues/1378). The old locations will continue to work for some months, but we suggest that you adjust your `/etc/apt/sources.list.d/fpco.list` to the new location to avoid future disruption. * [openSUSE and SUSE Linux Enterprise](http://docs.haskellstack.org/en/stable/install_and_upgrade/#suse) packages are now available, thanks to [@mimi1vx](https://github.com/mimi1vx). Note: there will be some lag before these pick up new versions, as they are based on Stackage LTS. Major changes: * Support for building inside a Nix-shell providing system dependencies [#1285](https://github.com/commercialhaskell/stack/pull/1285) * Add optional GPG signing on `stack upload --sign` or with `stack sig sign ...` Other enhancements: * Print latest applicable version of packages on conflicts [#508](https://github.com/commercialhaskell/stack/issues/508) * Support for packages located in Mercurial repositories [#1397](https://github.com/commercialhaskell/stack/issues/1397) * Only run benchmarks specified as build targets [#1412](https://github.com/commercialhaskell/stack/issues/1412) * Support git-style executable fall-through (`stack something` executes `stack-something` if present) [#1433](https://github.com/commercialhaskell/stack/issues/1433) * GHCi now loads intermediate dependencies [#584](https://github.com/commercialhaskell/stack/issues/584) * `--work-dir` option for overriding `.stack-work` [#1178](https://github.com/commercialhaskell/stack/issues/1178) * Support `detailed-0.9` tests [#1429](https://github.com/commercialhaskell/stack/issues/1429) * Docker: improved POSIX signal proxying to containers [#547](https://github.com/commercialhaskell/stack/issues/547) Bug fixes: * Show absolute paths in error messages in multi-package builds [#1348](https://github.com/commercialhaskell/stack/issues/1348) * Docker-built binaries and libraries in different path [#911](https://github.com/commercialhaskell/stack/issues/911) [#1367](https://github.com/commercialhaskell/stack/issues/1367) * Docker: `--resolver` argument didn't effect selected image tag * GHCi: Spaces in filepaths caused module loading issues [#1401](https://github.com/commercialhaskell/stack/issues/1401) * GHCi: cpp-options in Cabal files weren't used [#1419](https://github.com/commercialhaskell/stack/issues/1419) * Benchmarks couldn't be run independently of each other [#1412](https://github.com/commercialhaskell/stack/issues/1412) * Send output of building setup to stderr [#1410](https://github.com/commercialhaskell/stack/issues/1410) ## 0.1.8.0 - 2015-11-20 Major changes: * GHCJS can now be used with stackage snapshots via the new `compiler` field. * Windows installers are now available: [download them here](http://docs.haskellstack.org/en/stable/install_and_upgrade/#windows) [#613](https://github.com/commercialhaskell/stack/issues/613) * Docker integration works with non-FPComplete generated images [#531](https://github.com/commercialhaskell/stack/issues/531) Other enhancements: * Added an `allow-newer` config option [#922](https://github.com/commercialhaskell/stack/issues/922) [#770](https://github.com/commercialhaskell/stack/issues/770) * When a Hackage revision invalidates a build plan in a snapshot, trust the snapshot [#770](https://github.com/commercialhaskell/stack/issues/770) * Added a `stack config set resolver RESOLVER` command. Part of work on [#115](https://github.com/commercialhaskell/stack/issues/115) * `stack setup` can now install GHCJS on windows. See [#1145](https://github.com/commercialhaskell/stack/issues/1145) and [#749](https://github.com/commercialhaskell/stack/issues/749) * `stack hpc report` command added, which generates reports for HPC tix files * `stack ghci` now accepts all the flags accepted by `stack build`. See [#1186](https://github.com/commercialhaskell/stack/issues/1186) * `stack ghci` builds the project before launching GHCi. If the build fails, try to launch GHCi anyway. Use `stack ghci --no-build` option to disable [#1065](https://github.com/commercialhaskell/stack/issues/1065) * `stack ghci` now detects and warns about various circumstances where it is liable to fail. See [#1270](https://github.com/commercialhaskell/stack/issues/1270) * Added `require-docker-version` configuration option * Packages will now usually be built along with their tests and benchmarks. See [#1166](https://github.com/commercialhaskell/stack/issues/1166) * Relative `local-bin-path` paths will be relative to the project's root directory, not the current working directory. [#1340](https://github.com/commercialhaskell/stack/issues/1340) * `stack clean` now takes an optional `[PACKAGE]` argument for use in multi-package projects. See [#583](https://github.com/commercialhaskell/stack/issues/583) * Ignore cabal_macros.h as a dependency [#1195](https://github.com/commercialhaskell/stack/issues/1195) * Pad timestamps and show local time in --verbose output [#1226](https://github.com/commercialhaskell/stack/issues/1226) * GHCi: Import all modules after loading them [#995](https://github.com/commercialhaskell/stack/issues/995) * Add subcommand aliases: `repl` for `ghci`, and `runhaskell` for `runghc` [#1241](https://github.com/commercialhaskell/stack/issues/1241) * Add typo recommendations for unknown package identifiers [#158](https://github.com/commercialhaskell/stack/issues/158) * Add `stack path --local-hpc-root` option * Overhaul dependencies' haddocks copying [#1231](https://github.com/commercialhaskell/stack/issues/1231) * Support for extra-package-dbs in 'stack ghci' [#1229](https://github.com/commercialhaskell/stack/pull/1229) * `stack new` disallows package names with "words" consisting solely of numbers [#1336](https://github.com/commercialhaskell/stack/issues/1336) * `stack build --fast` turns off optimizations * Show progress while downloading package index [#1223](https://github.com/commercialhaskell/stack/issues/1223). Bug fixes: * Fix: Haddocks not copied for dependencies [#1105](https://github.com/commercialhaskell/stack/issues/1105) * Fix: Global options did not work consistently after subcommand [#519](https://github.com/commercialhaskell/stack/issues/519) * Fix: 'stack ghci' doesn't notice that a module got deleted [#1180](https://github.com/commercialhaskell/stack/issues/1180) * Rebuild when Cabal file is changed * Fix: Paths in GHC warnings not canonicalized, nor those for packages in subdirectories or outside the project root [#1259](https://github.com/commercialhaskell/stack/issues/1259) * Fix: unlisted files in tests and benchmarks trigger extraneous second build [#838](https://github.com/commercialhaskell/stack/issues/838) ## 0.1.6.0 - 2015-10-15 Major changes: * `stack setup` now supports building and booting GHCJS from source tarball. * On Windows, build directories no longer display "pretty" information (like x86_64-windows/Cabal-1.22.4.0), but rather a hash of that content. The reason is to avoid the 260 character path limitation on Windows. See [#1027](https://github.com/commercialhaskell/stack/pull/1027) * Rename config files and clarify their purposes [#969](https://github.com/commercialhaskell/stack/issues/969) * `~/.stack/stack.yaml` --> `~/.stack/config.yaml` * `~/.stack/global` --> `~/.stack/global-project` * `/etc/stack/config` --> `/etc/stack/config.yaml` * Old locations still supported, with deprecation warnings * New command "stack eval CODE", which evaluates to "stack exec ghc -- -e CODE". Other enhancements: * No longer install `git` on Windows [#1046](https://github.com/commercialhaskell/stack/issues/1046). You can still get this behavior by running the following yourself: `stack exec -- pacman -Sy --noconfirm git`. * Typing enter during --file-watch triggers a rebuild [#1023](https://github.com/commercialhaskell/stack/pull/1023) * Use Haddock's `--hyperlinked-source` (crosslinked source), if available [#1070](https://github.com/commercialhaskell/stack/pull/1070) * Use Stack-installed GHCs for `stack init --solver` [#1072](https://github.com/commercialhaskell/stack/issues/1072) * New experimental `stack query` command [#1087](https://github.com/commercialhaskell/stack/issues/1087) * By default, Stack no longer rebuilds a package due to GHC options changes. This behavior can be tweaked with the `rebuild-ghc-options` setting. [#1089](https://github.com/commercialhaskell/stack/issues/1089) * By default, ghc-options are applied to all local packages, not just targets. This behavior can be tweaked with the `apply-ghc-options` setting. [#1089](https://github.com/commercialhaskell/stack/issues/1089) * Docker: download or override location of Stack executable to re-run in container [#974](https://github.com/commercialhaskell/stack/issues/974) * Docker: when Docker Engine is remote, don't run containerized processes as host's UID/GID [#194](https://github.com/commercialhaskell/stack/issues/194) * Docker: `set-user` option to enable/disable running containerized processes as host's UID/GID [#194](https://github.com/commercialhaskell/stack/issues/194) * Custom Setup.hs files are now precompiled instead of interpreted. This should be a major performance win for certain edge cases (biggest example: [building Cabal itself](https://github.com/commercialhaskell/stack/issues/1041)) while being either neutral or a minor slowdown for more common cases. * `stack test --coverage` now also generates a unified coverage report for multiple test-suites / packages. In the unified report, test-suites can contribute to the coverage of other packages. Bug fixes: * Ignore stack-built executables named `ghc` [#1052](https://github.com/commercialhaskell/stack/issues/1052) * Fix quoting of output failed command line arguments * Mark executable-only packages as installed when copied from cache [#1043](https://github.com/commercialhaskell/stack/pull/1043) * Canonicalize temporary directory paths [#1047](https://github.com/commercialhaskell/stack/pull/1047) * Put code page fix inside the build function itself [#1066](https://github.com/commercialhaskell/stack/issues/1066) * Add `explicit-setup-deps` option [#1110](https://github.com/commercialhaskell/stack/issues/1110), and change the default to the old behavior of using any package in the global and snapshot database [#1025](https://github.com/commercialhaskell/stack/issues/1025) * Precompiled cache checks full package IDs on Cabal < 1.22 [#1103](https://github.com/commercialhaskell/stack/issues/1103) * Pass -package-id to ghci [#867](https://github.com/commercialhaskell/stack/issues/867) * Ignore global packages when copying precompiled packages [#1146](https://github.com/commercialhaskell/stack/issues/1146) ## 0.1.5.0 - 2015-09-24 Major changes: * On Windows, we now use a full MSYS2 installation in place of the previous PortableGit. This gives you access to the pacman package manager for more easily installing libraries. * Support for custom GHC binary distributions [#530](https://github.com/commercialhaskell/stack/issues/530) * `ghc-variant` option in `stack.yaml` to specify the variant (also `--ghc-variant` command-line option) * `setup-info` in `stack.yaml`, to specify where to download custom binary distributions (also `--ghc-bindist` command-line option) * Note: On systems with libgmp4 (aka `libgmp.so.3`), such as CentOS 6, you may need to re-run `stack setup` due to the centos6 GHC bindist being treated like a variant * A new `--pvp-bounds` flag to the sdist and upload commands allows automatic adding of PVP upper and/or lower bounds to your dependencies Other enhancements: * Adapt to upcoming Cabal installed package identifier format change [#851](https://github.com/commercialhaskell/stack/issues/851) * `stack setup` takes a `--stack-setup-yaml` argument * `--file-watch` is more discerning about which files to rebuild for [#912](https://github.com/commercialhaskell/stack/issues/912) * `stack path` now supports `--global-pkg-db` and `--ghc-package-path` * `--reconfigure` flag [#914](https://github.com/commercialhaskell/stack/issues/914) [#946](https://github.com/commercialhaskell/stack/issues/946) * Cached data is written with a checksum of its structure [#889](https://github.com/commercialhaskell/stack/issues/889) * Fully removed `--optimizations` flag * Added `--cabal-verbose` flag * Added `--file-watch-poll` flag for polling instead of using filesystem events (useful for running tests in a Docker container while modifying code in the host environment. When code is injected into the container via a volume, the container won't propagate filesystem events). * Give a preemptive error message when `-prof` is given as a GHC option [#1015](https://github.com/commercialhaskell/stack/issues/1015) * Locking is now optional, and will be turned on by setting the `STACK_LOCK` environment variable to `true` [#950](https://github.com/commercialhaskell/stack/issues/950) * Create default `stack.yaml` with documentation comments and commented out options [#226](https://github.com/commercialhaskell/stack/issues/226) * Out of memory warning if Cabal exits with -9 [#947](https://github.com/commercialhaskell/stack/issues/947) Bug fixes: * Hacky workaround for optparse-applicative issue with `stack exec --help` [#806](https://github.com/commercialhaskell/stack/issues/806) * Build executables for local extra deps [#920](https://github.com/commercialhaskell/stack/issues/920) * copyFile can't handle directories [#942](https://github.com/commercialhaskell/stack/pull/942) * Support for spaces in Haddock interface files [fpco/minghc#85](https://github.com/fpco/minghc/issues/85) * Temporarily building against a "shadowing" local package? [#992](https://github.com/commercialhaskell/stack/issues/992) * Fix `Setup.exe` name for `--upgrade-cabal` on Windows [#1002](https://github.com/commercialhaskell/stack/issues/1002) * Unlisted dependencies no longer trigger extraneous second build [#838](https://github.com/commercialhaskell/stack/issues/838) ## 0.1.4.1 - 2015-09-04 Fix stack's own Haddocks. No changes to functionality (only comments updated). ## 0.1.4.0 - 2015-09-04 Major changes: * You now have more control over how GHC versions are matched, e.g. "use exactly this version," "use the specified minor version, but allow patches," or "use the given minor version or any later minor in the given major release." The default has switched from allowing newer later minor versions to a specific minor version allowing patches. For more information, see [#736](https://github.com/commercialhaskell/stack/issues/736) and [#784](https://github.com/commercialhaskell/stack/pull/784). * Support added for compiling with GHCJS * Stack can now reuse prebuilt binaries between snapshots. That means that, if you build package foo in LTS-3.1, that binary version can be reused in LTS-3.2, assuming it uses the same dependencies and flags. [#878](https://github.com/commercialhaskell/stack/issues/878) Other enhancements: * Added the `--docker-env` argument, to set environment variables in Docker container. * Set locale environment variables to UTF-8 encoding for builds to avoid "commitBuffer: invalid argument" errors from GHC [#793](https://github.com/commercialhaskell/stack/issues/793) * Enable transliteration for encoding on stdout and stderr [#824](https://github.com/commercialhaskell/stack/issues/824) * By default, `stack upgrade` automatically installs GHC as necessary [#797](https://github.com/commercialhaskell/stack/issues/797) * Added the `ghc-options` field to `stack.yaml` [#796](https://github.com/commercialhaskell/stack/issues/796) * Added the `extra-path` field to `stack.yaml` * Code page changes on Windows only apply to the build command (and its synonyms), and can be controlled via a command line flag (still defaults to on) [#757](https://github.com/commercialhaskell/stack/issues/757) * Implicitly add packages to extra-deps when a flag for them is set [#807](https://github.com/commercialhaskell/stack/issues/807) * Use a precompiled Setup.hs for simple build types [#801](https://github.com/commercialhaskell/stack/issues/801) * Set --enable-tests and --enable-benchmarks optimistically [#805](https://github.com/commercialhaskell/stack/issues/805) * `--only-configure` option added [#820](https://github.com/commercialhaskell/stack/issues/820) * Check for duplicate local package names * Stop nagging people that call `stack test` [#845](https://github.com/commercialhaskell/stack/issues/845) * `--file-watch` will ignore files that are in your VCS boring/ignore files [#703](https://github.com/commercialhaskell/stack/issues/703) * Add `--numeric-version` option Bug fixes: * `stack init --solver` fails if `GHC_PACKAGE_PATH` is present [#860](https://github.com/commercialhaskell/stack/issues/860) * `stack solver` and `stack init --solver` check for test suite and benchmark dependencies [#862](https://github.com/commercialhaskell/stack/issues/862) * More intelligent logic for setting UTF-8 locale environment variables [#856](https://github.com/commercialhaskell/stack/issues/856) * Create missing directories for `stack sdist` * Don't ignore Cabal files with extra periods [#895](https://github.com/commercialhaskell/stack/issues/895) * Deprecate unused `--optimizations` flag * Truncated output on slow terminals [#413](https://github.com/commercialhaskell/stack/issues/413) ## 0.1.3.1 - 2015-08-12 Bug fixes: * Ignore disabled executables [#763](https://github.com/commercialhaskell/stack/issues/763) ## 0.1.3.0 - 2015-08-12 Major changes: * Detect when a module is compiled but not listed in the Cabal file ([#32](https://github.com/commercialhaskell/stack/issues/32)) * A warning is displayed for any modules that should be added to `other-modules` in the Cabal file * These modules are taken into account when determining whether a package needs to be built * Respect TemplateHaskell addDependentFile dependency changes ([#105](https://github.com/commercialhaskell/stack/issues/105)) * TH dependent files are taken into account when determining whether a package needs to be built. * Overhauled target parsing, added `--test` and `--bench` options [#651](https://github.com/commercialhaskell/stack/issues/651) * For details, see [Build commands documentation](http://docs.haskellstack.org/en/stable/build_command/) Other enhancements: * Set the `HASKELL_DIST_DIR` environment variable [#524](https://github.com/commercialhaskell/stack/pull/524) * Track build status of tests and benchmarks [#525](https://github.com/commercialhaskell/stack/issues/525) * `--no-run-tests` [#517](https://github.com/commercialhaskell/stack/pull/517) * Targets outside of root dir don't build [#366](https://github.com/commercialhaskell/stack/issues/366) * Upper limit on number of flag combinations to test [#543](https://github.com/commercialhaskell/stack/issues/543) * Fuzzy matching support to give better error messages for close version numbers [#504](https://github.com/commercialhaskell/stack/issues/504) * `--local-bin-path` global option. Use to change where binaries get placed on a `--copy-bins` [#342](https://github.com/commercialhaskell/stack/issues/342) * Custom snapshots [#111](https://github.com/commercialhaskell/stack/issues/111) * --force-dirty flag: Force treating all local packages as having dirty files (useful for cases where Stack can't detect a file change) * GHC error messages: display file paths as absolute instead of relative for better editor integration * Add the `--copy-bins` option [#569](https://github.com/commercialhaskell/stack/issues/569) * Give warnings on unexpected config keys [#48](https://github.com/commercialhaskell/stack/issues/48) * Remove Docker `pass-host` option * Don't require `cabal-install` to upload [#313](https://github.com/commercialhaskell/stack/issues/313) * Generate indexes for all deps and all installed snapshot packages [#143](https://github.com/commercialhaskell/stack/issues/143) * Provide `--resolver global` option [#645](https://github.com/commercialhaskell/stack/issues/645) * Also supports `--resolver nightly`, `--resolver lts`, and `--resolver lts-X` * Make `stack build --flag` error when flag or package is unknown [#617](https://github.com/commercialhaskell/stack/issues/617) * Preserve file permissions when unpacking sources [#666](https://github.com/commercialhaskell/stack/pull/666) * `stack build` etc work outside of a project * `list-dependencies` command [#638](https://github.com/commercialhaskell/stack/issues/638) * `--upgrade-cabal` option to `stack setup` [#174](https://github.com/commercialhaskell/stack/issues/174) * `--exec` option [#651](https://github.com/commercialhaskell/stack/issues/651) * `--only-dependencies` implemented correctly [#387](https://github.com/commercialhaskell/stack/issues/387) Bug fixes: * Extensions from the `other-extensions` field no longer enabled by default [#449](https://github.com/commercialhaskell/stack/issues/449) * Fix: haddock forces rebuild of empty packages [#452](https://github.com/commercialhaskell/stack/issues/452) * Don't copy over executables excluded by component selection [#605](https://github.com/commercialhaskell/stack/issues/605) * Fix: Stack fails on Windows with git package in `stack.yaml` and no git binary on path [#712](https://github.com/commercialhaskell/stack/issues/712) * Fixed GHCi issue: Specifying explicit package versions (#678) * Fixed GHCi issue: Specifying -odir and -hidir as .stack-work/odir (#529) * Fixed GHCi issue: Specifying A instead of A.ext for modules (#498) ## 0.1.2.0 - 2015-07-05 * Add `--prune` flag to `stack dot` [#487](https://github.com/commercialhaskell/stack/issues/487) * Add `--[no-]external`,`--[no-]include-base` flags to `stack dot` [#437](https://github.com/commercialhaskell/stack/issues/437) * Add `--ignore-subdirs` flag to init command [#435](https://github.com/commercialhaskell/stack/pull/435) * Handle attempt to use non-existing resolver [#436](https://github.com/commercialhaskell/stack/pull/436) * Add `--force` flag to `init` command * exec style commands accept the `--package` option (see [Reddit discussion](http://www.reddit.com/r/haskell/comments/3bd66h/stack_runghc_turtle_as_haskell_script_solution/)) * `stack upload` without arguments doesn't do anything [#439](https://github.com/commercialhaskell/stack/issues/439) * Print latest version of packages on conflicts [#450](https://github.com/commercialhaskell/stack/issues/450) * Flag to avoid rerunning tests that haven't changed [#451](https://github.com/commercialhaskell/stack/issues/451) * Stack can act as a script interpreter (see [Script interpreter] (https://github.com/commercialhaskell/stack/wiki/Script-interpreter) and [Reddit discussion](http://www.reddit.com/r/haskell/comments/3bd66h/stack_runghc_turtle_as_haskell_script_solution/)) * Add the __`--file-watch`__ flag to auto-rebuild on file changes [#113](https://github.com/commercialhaskell/stack/issues/113) * Rename `stack docker exec` to `stack exec --plain` * Add the `--skip-msys` flag [#377](https://github.com/commercialhaskell/stack/issues/377) * `--keep-going`, turned on by default for tests and benchmarks [#478](https://github.com/commercialhaskell/stack/issues/478) * `concurrent-tests: BOOL` [#492](https://github.com/commercialhaskell/stack/issues/492) * Use hashes to check file dirtiness [#502](https://github.com/commercialhaskell/stack/issues/502) * Install correct GHC build on systems with libgmp.so.3 [#465](https://github.com/commercialhaskell/stack/issues/465) * `stack upgrade` checks version before upgrading [#447](https://github.com/commercialhaskell/stack/issues/447) ## 0.1.1.0 - 2015-06-26 * Remove GHC uncompressed tar file after installation [#376](https://github.com/commercialhaskell/stack/issues/376) * Put stackage snapshots JSON on S3 [#380](https://github.com/commercialhaskell/stack/issues/380) * Specifying flags for multiple packages [#335](https://github.com/commercialhaskell/stack/issues/335) * single test suite failure should show entire log [#388](https://github.com/commercialhaskell/stack/issues/388) * valid-wanted is a confusing option name [#386](https://github.com/commercialhaskell/stack/issues/386) * `stack init` in multi-package project should use local packages for dependency checking [#384](https://github.com/commercialhaskell/stack/issues/384) * Display information on why a snapshot was rejected [#381](https://github.com/commercialhaskell/stack/issues/381) * Give a reason for unregistering packages [#389](https://github.com/commercialhaskell/stack/issues/389) * `stack exec` accepts the `--no-ghc-package-path` parameter * Don't require build plan to upload [#400](https://github.com/commercialhaskell/stack/issues/400) * Specifying test components only builds/runs those tests [#398](https://github.com/commercialhaskell/stack/issues/398) * `STACK_EXE` environment variable * Add the `stack dot` command * `stack upgrade` added [#237](https://github.com/commercialhaskell/stack/issues/237) * `--stack-yaml` command line flag [#378](https://github.com/commercialhaskell/stack/issues/378) * `--skip-ghc-check` command line flag [#423](https://github.com/commercialhaskell/stack/issues/423) Bug fixes: * Haddock links to global packages no longer broken on Windows [#375](https://github.com/commercialhaskell/stack/issues/375) * Make flags case-insensitive [#397](https://github.com/commercialhaskell/stack/issues/397) * Mark packages uninstalled before rebuilding [#365](https://github.com/commercialhaskell/stack/issues/365) ## 0.1.0.0 - 2015-06-23 * Fall back to Cabal dependency solver when a snapshot can't be found * Basic implementation of `stack new` [#137](https://github.com/commercialhaskell/stack/issues/137) * `stack solver` command [#364](https://github.com/commercialhaskell/stack/issues/364) * `stack path` command [#95](https://github.com/commercialhaskell/stack/issues/95) * Haddocks [#143](https://github.com/commercialhaskell/stack/issues/143): * Build for dependencies * Use relative links * Generate module contents and index for all packages in project ## 0.0.3 - 2015-06-17 * `--prefetch` [#297](https://github.com/commercialhaskell/stack/issues/297) * `upload` command ported from stackage-upload [#225](https://github.com/commercialhaskell/stack/issues/225) * `--only-snapshot` [#310](https://github.com/commercialhaskell/stack/issues/310) * `--resolver` [#224](https://github.com/commercialhaskell/stack/issues/224) * `stack init` [#253](https://github.com/commercialhaskell/stack/issues/253) * `--extra-include-dirs` and `--extra-lib-dirs` [#333](https://github.com/commercialhaskell/stack/issues/333) * Specify intra-package target [#201](https://github.com/commercialhaskell/stack/issues/201) ## 0.0.2 - 2015-06-14 * Fix some Windows specific bugs [#216](https://github.com/commercialhaskell/stack/issues/216) * Improve output for package index updates [#227](https://github.com/commercialhaskell/stack/issues/227) * Automatically update indices as necessary [#227](https://github.com/commercialhaskell/stack/issues/227) * --verbose flag [#217](https://github.com/commercialhaskell/stack/issues/217) * Remove packages (HTTPS and Git) [#199](https://github.com/commercialhaskell/stack/issues/199) * Config values for system-ghc and install-ghc * Merge `stack deps` functionality into `stack build` * `install` command [#153](https://github.com/commercialhaskell/stack/issues/153) and [#272](https://github.com/commercialhaskell/stack/issues/272) * overriding architecture value (useful to force 64-bit GHC on Windows, for example) * Overhauled test running (allows cycles, avoids unnecessary recompilation, etc) ## 0.0.1 - 2015-06-09 * First public release, beta quality stack-2.9.3.1/README.md0000644000000000000000000000234314445022466012447 0ustar0000000000000000## The Haskell Tool Stack [![Unit tests](https://github.com/commercialhaskell/stack/workflows/Unit%20tests/badge.svg)](https://github.com/commercialhaskell/stack/actions/workflows/unit-tests.yml) [![Integration tests](https://github.com/commercialhaskell/stack/workflows/Integration%20tests/badge.svg)](https://github.com/commercialhaskell/stack/actions/workflows/integration-tests.yml) [![Release](https://img.shields.io/github/release/commercialhaskell/stack.svg)](https://github.com/commercialhaskell/stack/releases) Stack is a cross-platform program for developing Haskell projects. It is intended for Haskellers both new and experienced. See [haskellstack.org](http://haskellstack.org) or the [doc](./doc) directory for more information. ### Community You can participate with the Stack community in the following areas: * [Haskell Foundation Slack](https://haskell-foundation.slack.com/join/shared_invite/zt-z45o9x38-8L55P27r12YO0YeEufcO2w#/shared-invite/email) * `#stack-users` for general Stack discussion * `#stack-collaborators` for working on the Stack code base * [Stack Google Group mailing list](https://groups.google.com/g/haskell-stack) * [Haskell Community Discourse](https://discourse.haskell.org/) stack-2.9.3.1/stack.yaml0000644000000000000000000000061314445113031013144 0ustar0000000000000000# GHC 9.4.5 resolver: lts-21.0 packages: - . drop-packages: # See https://github.com/commercialhaskell/stack/pull/4712 - cabal-install docker: enable: false repo: fpco/alpine-haskell-stack:9.2.5 nix: # --nix on the command-line to enable. packages: - zlib - unzip flags: stack: developer-mode: true ghc-options: "$locals": -fhide-source-paths stack-2.9.3.1/doc/azure_ci.md0000644000000000000000000001715714353310351014060 0ustar0000000000000000
# Azure CI This page documents how to use Stack on [Azure CI](http://dev.azure.com/). ## Quick Start Note that you have to create [azure pipelines](#creating-azure-pipelines) for your project and then you need to put the relevant configuration files: * For simple Azure configuration, copy-paste the [azure-simple](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/azure/azure-simple.yml) file into `azure-pipelines.yml`. * For complex Azure configuration, you need to take the below linked four files and put all of them into the `.azure` directory. For a more detailed explanation, you can read further. ## Simple and Complex configuration We provide two fully baked configuration ready to be used on your projects: * [The simple Azure configuration](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/azure/azure-simple.yml) is intended for applications that do not require multiple GHC support or cross-platform support. It builds and tests your project with just the settings present in your `stack.yaml` file. * The complex Azure configuration is intended for projects that need to support multiple GHC versions and multiple operating systems, such as open source libraries to be released to Hackage. It tests against Stack for different resolvers on Linux, macOS and Windows. These are the files for the complex configuration: - [azure-pipelines.yml](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/azure/azure-pipelines.yml) : This is the starter file used by the Azure CI. - [azure-linux-template.yml](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/azure/azure-linux-template.yml) : Template for Azure Linux build - [azure-osx-template.yml](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/azure/azure-osx-template.yml) : Template for Azure macOS build - [azure-windows-template.yml](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/azure/azure-windows-template.yml) : Template for Azure Windows build !!! note It is likely going to be necessary to modify this configuration to match the needs of your project, such as tweaking the build matrix to alter which GHC versions you test against, or to specify GHC-version-specific `stack.yaml` files if necessary. Don't be surprised if it doesn't work the first time around. See the multiple GHC section below for more information. ## Creating Azure Pipelines Each of these configurations is ready to be used immediately. But before we go into where to put them, we have to create pipeline for your project in Azure CI platform: * Go to [dev.azure.com](https://dev.azure.com). You have to initially sign-in to your microsoft account there. * Once you have logged in to your Microsoft account, you have to sign in to [Azure devops](https://user-images.githubusercontent.com/737477/52465678-70963080-2ba5-11e9-83d8-84112b140236.png) from there. * You will be greeted with a [dashboard](https://user-images.githubusercontent.com/737477/52465677-70963080-2ba5-11e9-904a-c15c7c0524ef.png) where you can create your projects. * Click the "Create Project" button and fill the relevant information in the [dialog](https://user-images.githubusercontent.com/737477/52465676-70963080-2ba5-11e9-82a4-093ee58f11c9.png) and then click the "Create" button. * This will lead you to the project [dashboard](https://user-images.githubusercontent.com/737477/52465675-6ffd9a00-2ba5-11e9-917e-3dec251fcc87.png) page where you can create pipelines. * Click on "Pipelines" in the left menu. This will load the [pipelines page](https://user-images.githubusercontent.com/737477/52465673-6ffd9a00-2ba5-11e9-97a4-04e703ae1fbc.png) on the right. * Click on the button "New Pipeline" and you have to follow through the wizard there. You need to choose your github repository (or Azure repos) and follow the wizard. Note that in the [Configure step](https://user-images.githubusercontent.com/737477/52465670-6ffd9a00-2ba5-11e9-83a3-9fffdacbf249.png) you have to select the "Starter Pipeline". This will open up an [editor window](https://user-images.githubusercontent.com/737477/52465669-6f650380-2ba5-11e9-9662-e9c6fc2682b5.png). You can leave the existing YAML configuration there as it is and click the "Save and run" button. That will popup a [dialog](https://user-images.githubusercontent.com/737477/52465668-6f650380-2ba5-11e9-9203-6347a609e3c4.png). Select the relevant option and click "Save and run" button. (Note that this step would have created `azure-pipelines.yml` in your repository. You have to replace that with the appropriate configuration file.) The rest of this document explains the details of common Azure configurations for those of you who want to tweak the above configuration files or write your own. *Note:* both Azure and Stack infrastructures are actively developed. We try to document best practices at the moment. ## Infrastructure Note that you need at least one agent to build your code. You can specify which virtual image you want to choose using this configuration: ~~~yaml pool: vmImage: ubuntu-latest ~~~ The other popular options are `macOS-latest`, `windows-latest` for macOS and Windows respectively. You can find the [complete list](https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=vsts&tabs=yaml) here. You also have the option to select a specific supported ubuntu version like `ubuntu-18.08`. ## Installing Stack Currently there is only one reasonable way to install Stack: fetch a precompiled binary from GitHub. ~~~yaml - script: | mkdir -p ~/.local/bin curl -L https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' displayName: Install Stack ~~~ ## Installing GHC There are two ways to install GHC: - Let Stack download GHC - Install GHC using apt package manger. This method is only applicable for Debian based images. But we only use the first method of using Stack to download GHC. ### Multiple GHC - parametrised builds For different GHC versions, you probably want to use different project-level configuration files (`stack.yaml`). If you don't want to put a specific `stack.yaml` for a particular resolver and still want to test it, you have specify your resolver argument in `ARGS` environment variable (you will see an example below). ~~~yaml strategy: matrix: GHC 8.0: ARGS: "--resolver lts-9" GHC 8.2: ARGS: "--resolver lts-11" GHC 8.4: ARGS: "--resolver lts-12" GHC 8.6: ARGS: "--resolver lts-14" GHC 8.8: ARGS: "--resolver lts-15" nightly: ARGS: "--resolver nightly" ~~~ ## Running tests After the environment setup, actual test running is simple. Command: ~~~text stack $ARGS test --bench --no-run-benchmarks --haddock --no-haddock-deps ~~~ ## Other details Some Stack commands will run for long time. To avoid timeouts, use the [timeoutInMinutes](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?tabs=yaml&view=azdevops#timeouts) for jobs. ## Examples - [commercialhaskell/stack](https://github.com/commercialhaskell/stack/blob/master/azure-pipelines.yml) - [psibi/tldr-hs](http://github.com/psibi/tldr-hs) - [psibi/wai-slack-middleware](https://github.com/psibi/wai-slack-middleware) stack-2.9.3.1/doc/build_command.md0000644000000000000000000004102514445022466015054 0ustar0000000000000000
# The `stack build` command and its synonyms ~~~text stack build [TARGET] [--dry-run] [--pedantic] [--fast] [--ghc-options OPTIONS] [--flag PACKAGE:[-]FLAG] [--dependencies-only | --only-snapshot | --only-dependencies | --only-locals] [--file-watch | --file-watch-poll] [--watch-all] [--exec COMMAND [ARGUMENT(S)]] [--only-configure] [--trace] [--profile] [--no-strip] [--[no-]library-profiling] [--[no-]executable-profiling] [--[no-]library-stripping] [--[no-]executable-stripping] [--[no-]haddock] [--haddock-arguments HADDOCK_ARGS] [--[no-]open] [--[no-]haddock-deps] [--[no-]haddock-internal] [--[no-]haddock-hyperlink-source] [--[no-]copy-bins] [--[no-]copy-compiler-tool] [--[no-]prefetch] [--[no-]keep-going] [--[no-]keep-tmp-files] [--[no-]force-dirty] [--[no-]test] [--[no-]rerun-tests] [--ta|--test-arguments TEST_ARGS] [--coverage] [--no-run-tests] [--test-suite-timeout ARG] [--[no-]tests-allow-stdin] [--[no-]bench] [--ba|--benchmark-arguments BENCH_ARGS] [--no-run-benchmarks] [--[no-]reconfigure] [--cabal-verbosity VERBOSITY | --[no-]cabal-verbose] [--[no-]split-objs] [--skip ARG] [--[no-]interleaved-output] [--ddump-dir ARG] ~~~ ## Overview Stack's primary command is `build`. This page describes its interface. The goal of the interface is to do the right thing for simple input, and allow flexibility for more complicated goals. See the introductory part of Stack's [user's guide](GUIDE.md#the-stack-build-command) for an introduction to the command. ## Synonyms The synonym commands for `build` are: |Synonym command|Equivalent `build` command flag| |---------------|-------------------------------| |`stack test` |`stack build --test` | |`stack bench` |`stack build --bench` | |`stack haddock`|`stack build --haddock` | |`stack install`|`stack build --copy-bins` | The advantage of the synonym commands is that they are convenient and short. The advantage of the flags is that they compose. For example, `stack build --test --copy-bins` will build libraries, executables, and test suites, run the test suites, and then copy the executables to your local bin path (more on this below). ## Components Every Cabal package is made up of one or more components. It can have an optional library component, one or more optional executable components, one or more optional test suite components, and one or more optional benchmark components. Stack allows you to identify a specific component to be built. For example, `stack build mypackage:test:mytests` will build (and run - see further below) the `mytests` component of the `mypackage` package. `mytests` must be a test suite component. By default, if a test suite component is targeted, the component is built and run. The running behaviour can be disabled with the `--no-run-tests` flag. Similarly, if a benchmark component is targeted, it is built and run unless the running behaviour is disabled with the `--no-run-benchmarks` flag. This ability to specify a component applies only to a local package. With dependencies, Stack will *always* build the library (if present) and all executables (if any), and ignore test suites and benchmarks. If you want more control over a package, you must add it to your `packages` setting in your project-level configuration file (`stack.yaml`). ## Target syntax `stack build` takes a list of one or more optional *targets* to be built. The supported syntaxes for targets are: * *package*, e.g. `stack build foobar`, is the most commonly used target. It will try to find the package in the following locations: local packages, extra deps, snapshots, and package index (e.g. Hackage). If it's found in the package index, then the latest version of that package from the index is implicitly added to your extra dependencies. If the package is a local package, the library and executable components are selected to be built. If the `--test` and `--bench` flags are set, then all of the test suite and benchmark components, respectively, are selected to be built. * *package identifier*, e.g. `stack build foobar-1.2.3`, is usually used to include specific package versions from the package index. If the version selected conflicts with an existing local package or extra dep, then Stack fails with an error. Otherwise, this is the same as using `stack build foobar`, except instead of using the latest version from the package index, the version specified is used. * *component*. Instead of referring to an entire package and letting Stack decide which components to build, you select individual components from inside a package. This can be done for more fine-grained control over which test suites to run, or to have a faster compilation cycle. There are multiple ways to refer to a specific component (provided for convenience): * `packagename:comptype:compname` is the most explicit. The available comptypes are `exe`, `test`, and `bench`. !!! note When any `exe` component is specified, all of the package's executable components will be built. This is due to limitations in all currently released versions of Cabal. See [issue#1046](https://github.com/commercialhaskell/stack/issues/1406) * `packagename:compname` allows you to leave out the component type, as that will (almost?) always be redundant with the component name. For example, `stack build mypackage:mytestsuite`. * `:compname` is a useful shortcut, saying "find the component in all of the local packages." This will result in an error if multiple packages have a component with the same name. To continue the above example, `stack build :mytestsuite`. * *directory*, e.g. `stack build foo/bar`, will find all local packages that exist in the given directory hierarchy and then follow the same procedure as passing in package names as mentioned above. There's an important caveat here: if your directory name is parsed as one of the above target types, it will be treated as that. Explicitly starting your target with `./` can be a good way to avoid that, e.g. `stack build ./foo`. !!! note `stack build .` will target local packages in the current working directory or its subdirectories. `stack build` with no targets specified will build all local packages. Command `stack ide targets` to get a list of the available targets in your project. ## Controlling what gets built Stack will automatically build the necessary dependencies. See the introductory part of Stack's [user's guide](GUIDE.md#the-stack-build-command) for information about how these dependencies get specified. In addition to specifying targets, you can also control what gets built, or retained, with the following flags: ### The `stack build --bench` flag Pass the flag to add benchmark components to the targets, if specific components are not identified. ### The `stack build --dependencies-only` flag Pass the flag to skip building the targets. The flag `--only-dependencies` has the same effect. ### The `stack build --[no-]dry-run` flag Default: Disabled Set the flag to build nothing and output information about the build plan. ### The `stack build --flag` option `stack build --flag :[-]` sets (or unsets) the specified Cabal flag for the specified package. This option can be specified multiple times to set (or unset) multiple Cabal flags. The same Cabal flag name can be set (or unset) for multiple packages (at the command line only) with: ~~~text stack build --flag *:[-] ~~~ !!! note Currently you needs to list all of your modules that interpret flags in the `other-modules` section of a Cabal file. Cabal (the tool) has a different behavior currently and doesn't require that the modules be listed. This may change in a future release. ### The `stack build --[no-]force-dirty` flag Default: Disabled Set the flag to force rebuild of packages even when it doesn't seem necessary based on file dirtiness. ### The `stack build --[no-]haddock` flag Default: Disabled Set the flag to build Haddock documentation. This may cause a lot of packages to get re-built, so that the documentation links work. ### The `stack build --[no-]keep-going` flag Default (`stack build`): Disabled Default (`stack test` or `stack bench`): Enabled Set the flag to continue building packages even after some build step fails. The packages which depend upon the failed build won't get built. ### The `stack build --[no-]keep-tmp-files` flag Default: Disabled Set the flag to keep intermediate files and build directories that would otherwise be considered temporary and deleted. It may be useful to inspect these, if a build fails. By default, they are not kept. ### The `stack build --only-configure` flag [:octicons-tag-24: 0.1.4.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.4.0) Pass the flag to perform only the configure step, not any builds. This is intended for tool usage. It may break when used on multiple packages at once. !!! note If there are downstream actions that require a package to be built then a full build will occur, even if the flag is passed. ### The `stack build --only-dependencies` flag Pass the flag to skip building the targets. The flag `--dependencies-only` has the same effect. ### The `stack build --only-snapshot` flag Pass the flag to build only snapshot dependencies, which are cached and shared with other projects. ### The `stack build --[no-]reconfigure` flag Default: Disabled Set the flag to force reconfiguration even when it doesn't seem necessary based on file dirtiness. This is sometimes useful with custom `Setup.hs` files, in particular when they depend on external data files. ### The `stack build --skip` option `stack build --skip ` skips building the specified components of a local package. It allows you to skip test suites and benchmark without specifying other components (e.g. `stack test --skip long-test-suite` will run the tests without the `long-test-suite` test suite). Be aware that skipping executables won't work the first time the package is built due to an issue in [Cabal](https://github.com/commercialhaskell/stack/issues/3229). This option can be specified multiple times to skip multiple components. ### The `stack build --test` flag Pass the flag to add test suite components to the targets, if specific components are not identified. ## Other flags and options There are a number of other flags accepted by `stack build`. Instead of listing all of them, please use `stack build --help`. Some particularly convenient ones worth mentioning here since they compose well with the rest of the build system as described: ### The `stack build --coverage` flag Pass the flag to generate a code coverage report. For further information, see the [code coverage](hpc_command.md) documentation. ### The `stack build --exec` option `stack build --exec " []"` will run a command after a successful build. ### The `stack build --file-watch` flag Pass the flag to rebuild your project every time a file changes. By default it will take into account all files belonging to the targets you specify. See also the `--watch-all` flag. ### The `stack build --[no-]interleaved-output` flag [:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1) Default: Enabled Set the flag for interleaved output. With interleaved output, each line of output from each package being built (targets and dependencies) is sent to the console as it happens and output relating to different packages can be interleaved. Each line will be prefixed with the name of the relevant package. The spacing between the prefix and the output will be set based on the longest relevant package name, so that the start of the output itself aligns. For example (extract): ~~~text hpack > build mustache > configure hpack > Preprocessing library for hpack-0.35.0.. hpack > Building library for hpack-0.35.0.. mustache > Configuring mustache-2.4.1... hpack > [ 1 of 29] Compiling Data.Aeson.Config.Key hpack > [ 2 of 29] Compiling Data.Aeson.Config.KeyMap mustache > build hpack > [ 3 of 29] Compiling Data.Aeson.Config.Util mustache > Preprocessing library for mustache-2.4.1.. mustache > Building library for mustache-2.4.1.. hpack > [ 4 of 29] Compiling Hpack.Haskell hpack > [ 5 of 29] Compiling Hpack.Utf8 mustache > [1 of 8] Compiling Paths_mustache hpack > [ 6 of 29] Compiling Imports hpack > [ 7 of 29] Compiling Hpack.Util mustache > [2 of 8] Compiling Text.Mustache.Internal ~~~ Unset the flag for non-interleaved output. With non-interleaved output, the build output from GHC (as opposed to from Stack) in respect of dependencies is ignored. The behaviour then depends whether there is one target package or more than one. There can be one target if the project has a single package or if one package is targetted in a multi-package project (for example, using `stack build `). * **One target package:** The build output for the target package is sent to the console as it happens. * **More than one target package:** The build output from GHC (as opposed to from Stack) for each target package is sent to a log file for that package, unless an error occurs. At the end of the build, the location of the directory containing the log files is reported. To also output the contents of the log files to the console at the end of the build, use Stack's `dump-logs` option. For further information about that option, see the [YAML configuration](yaml_configuration.md#dump-logs) documentation. The default `dump-logs` mode is to output the contents of the log files that are warnings. ### The `stack build --pedantic` flag Pass the flag to build your project with the GHC options `-Wall` and `-Werror`. `-Wall` turns on all warning options that indicate potentially suspicious code. `-Werror` makes any warning into a fatal error. ### The `stack build --watch-all` flag Pass the flag to rebuild your project every time any local file changes (from project packages or from local dependencies). See also the `--file-watch` flag. ### The `stack build --tests-allow-stdin` flag [:octicons-tag-24: 2.9.3](https://github.com/commercialhaskell/stack/releases/tag/v2.9.3) Default: Enabled Cabal defines a test suite interface ['exitcode-stdio-1.0'](https://hackage.haskell.org/package/Cabal-syntax-3.8.1.0/docs/Distribution-Types-TestSuiteInterface.html#v:TestSuiteExeV1.0) where the test suite takes the form of an executable and the executable takes nothing on the standard input channel (`stdin`). Pass this flag to override that specification and allow the executable to receive input on that channel. If you pass `--no-tests-allow-stdin` and the executable seeks input on the standard input channel, an exception will be thown. ## Composition To come back to the composable approach described above, consider this example (which uses the `wai` [repository](https://github.com/yesodweb/wai/)). The command: ~~~text stack build --file-watch --test --copy-bins --haddock wai-extra :warp warp:doctest --exec 'echo Yay, it worked!' ~~~ will start Stack up in file watch mode, waiting for files in your project to change. When first starting, and each time a file changes, it will do all of the following. * Build the wai-extra package and its test suites * Build the `warp` executable * Build the warp package's doctest component (which, as you may guess, is a test site) * Run all of the wai-extra package's test suite components and the doctest test suite component * If all of that succeeds: * Copy generated executables to the local bin path * Run the command `echo Yay, it worked!` stack-2.9.3.1/doc/build_overview.md0000644000000000000000000002766514353310351015311 0ustar0000000000000000
# Build overview !!! warning This document should not be considered accurate until this warning is removed. This is a work-in-progress document covering the build process used by Stack. It was started following the Pantry rewrite work in Stack 2.1.1, and contains some significant changes/simplifications from how things used to work. This document will likely not fully be reflected in the behavior of Stack itself until late in the Stack 2.0 development cycle. ## Terminology * Project package: anything listed in `packages` in stack.yaml * Dependency: anything listed in extra-deps or a snapshot * Target: package and/or component listed on the command line to be built. Can be either project package or dependency. If none specified, automatically targets all project packages * Immutable package: a package which comes from Hackage, an archive, or a repository. In contrast to... * Mutable package: a package which comes from a local file path. The contents of such a package are assumed to mutate over time. * Write only database: a package database and set of executables for a given set of _immutable_ packages. Only packages from immutable sources and which depend exclusively on other immutable packages can be in this database. *NOTE* formerly this was the _snapshot database_. * Mutable database: a package database and set of executables for packages which are either mutable or depend on such mutable packages. Importantly, packages in this database can be unregister, replaced, etc, depending on what happens with the source packages. *NOTE* formerly this was the *local database*. Outdated terminology to be purged: * Wanted * Local * Snapshot package ## Inputs Stack pays attention to the following inputs: * Current working directory, used for finding the default `stack.yaml` file and resolving relative paths * The `STACK_YAML` environment variable * Command line arguments (CLI args), as will be referenced below Given these inputs, Stack attempts the following process when performing a build. ## Find the `stack.yaml` file * Check for a `--stack-yaml` CLI arg, and use that * Check for a `STACK_YAML` env var * Look for a `stack.yaml` in this directory or ancestor directories * Fall back to the default global project This file is parsed to provide the following config values: * `resolver` (required field) * `compiler` (optional field) * `packages` (optional field, defaults to `["."]`) * `extra-deps` (optional field, defaults to `[]`) * `flags` (optional field, defaults to `{}`) * `ghc-options` (optional field, defaults to `{}`) `flags` and `ghc-options` break down into both _by name_ (applied to a specific package) and _general_ (general option `*` for flags is only available in CLI). ## Wanted compiler, dependencies, and project packages * If the `--resolver` CLI is present, ignore the `resolver` and `compiler` config values * Load up the snapshot indicated by the `resolver` (either config value or CLI arg). This will provide: * A map from package name to package location, flags, GHC options, and if a package should be hidden. All package locations here are immutable. * A wanted compiler version, e.g. `ghc-8.6.5` * If the `--compiler` CLI arg is set, or the `compiler` config value is set (and `--resolver` CLI arg is not set), ignore the wanted compiler from the snapshot and use the specified wanted compiler * Parse `extra-deps` into a `Map PackageName PackageLocation`, containing both mutable and immutable package locations. Parse `packages` into a `Map PackageName ProjectPackage`. * Ensure there are no duplicates between these two sets of packages * Delete any packages from the snapshot packages that appear in `packages` or `extra-deps` * Perform a left biased union between the immutable `extra-deps` values and the snapshot packages. Ignore any settings in the snapshot packages that have been replaced. * Apply the `flags` and `ghc-options` by name to these packages overwriting any previous values coming from a snapshot. If any values are specified but no matching package is found, it's an error. If a flag is not defined in the corresponding package cabal file, it's an error. * We are now left with the following: * A wanted compiler version * A map from package name to immutable packages with package config (flags, GHC options, hidden) * A map from package name to mutable packages as dependencies with package config * A map from package name to mutable packages as project packages with package config ## Get actual compiler Use the wanted compiler and various other Stack config values (not all listed here) to find the actual compiler, potentially installing it in the process. ## Global package sources With the actual compiler discovered, list out the packages available in its database and create a map from package name to version/GhcPkgId. Remove any packages from this map which are present in one of the other three maps mentioned above. ## Resolve targets Take the CLI args for targets as raw text values and turn them into actual targets. * Do a basic parse of the values into one of the following: * Package name * Package identifier * Package name + component * Directory * An empty target list is equivalent to listing the package names of all project packages * For any directories specified, find all project packages in that directory or subdirectories therefore and convert to those package names * For all package identifiers, ensure that either the package name does not exist in any of the three parsed maps from the "wanted compiler" step above, or that the package is present as an immutable dependency from Hackage. If so, create an immutable dependency entry with default flags, GHC options, and hidden status, and add this package to the set of immutable package dependencies. * For all package names, ensure the package is in one of the four maps we have, and if so add to either the dependency or project package target set. * For all package name + component, ensure that the package is a project package, and add that package + component to the set of project targets. * Ensure that no target has been specified multiple times. (*FIXME* Mihai states: I think we will need an extra consistency step for internal libraries. Sometimes stack needs to use the mangled name (`z-package-internallibname-z..`), sometimes the `package:internallibname` one. But I think this will become obvious when doing the code changes.) We now have an update four package maps, a new set of dependency targets, and a new set of project package targets (potentially with specific components). ## Apply named CLI flags Named CLI flags are applied to specific packages by updating the config in one of the four maps. If a flag is specified and no package is found, it's an error. Note that flag settings are added _on top of_ previous settings in this case, and does not replace them. That is, if previously we have `singleton (FlagName "foo") True` and now add `singleton (FlagName "bar") True`, both `foo` and `bar` will now be true. If any flags are specified but no matching package is found, it's an error. If a flag is not defined in the corresponding package cabal file, it's an error. ## Apply CLI GHC options CLI GHC options are applied as general GHC options according to `apply-ghc-options` setting. ## Apply general flags from CLI `--flag *:flagname[:bool]` specified on the CLI are applied to any project package which uses that flag name. ## Apply general GHC options General options are divided into the following categories: * `$locals` is deprecated, it's now a synonym for `$project` * `$project` applies to all project packages, not to any dependencies * `$targets` applies to all project packages that are targets, not to any dependencies or non-target project packages. This is the default option for `apply-ghc-options` * `$everything` applies to all packages in the source map excluding global packages These options get applied to any corresponding packages in the source map. If some GHC options already exist for such a package then they get prepended otherwise they get used as is. ## Determine snapshot hash Use some deterministic binary serialization and SHA256 thereof to get a hash of the following information: * Actual compiler (GHC version, path, *FIXME* probably some other unique info from GHC, I've heard that `ghc --info` gives you something) * Global database map * Immutable dependency map Motivation: Any package built from the immutable dependency map and installed in this database will never need to be rebuilt. !!! bug "To do" Caveat: do we need to take profiling settings into account here? How about Haddock status? ## Determine actual target components * Dependencies: "default" components (all libraries and executables) * Project packages: * If specific components named: only those, plus any libraries present * If no specific components, include the following: * All libraries, always * All executables, always * All test suites, _if_ `--test` specified on command line * All benchmarks, _if_ `--bench` specified on command line ## Construct build plan * Applied to every target (project package or dependency) * Apply flags, platform, and actual GHC version to resolve dependencies in any package analyzed * Include all library dependencies for all enabled components * Include all build tool dependencies for all enabled components (using the fun backwards compat logic for `build-tools`) * Apply the logic recursively to come up with a full build plan * If a task depends exclusively on immutable packages, mark it as immutable. Otherwise, it's mutable. The former go into the snapshot database, the latter into the local database. We now have a set of tasks of packages/components to build, with full config information for each package, and dependencies that must be built first. !!! bug "To do" There's some logic to deal with cyclic dependencies between test suites and benchmarks, where a task can be broken up into individual components versus be kept as a single task. Need to document this better. Currently it's the "all in one" logic. ## Unregister local modified packages * For all mutable packages in the set of tasks, see if any files have changed since last successful build and, if so, unregister + delete their executables * For anything which depends on them directly or transitively, unregister + delete their executables ## Perform the tasks * Topological sort, find things which have no dependencies remaining * Check if already installed in the relevant database * Check package database * Check Stack specific "is installed" flags, necessary for non-library packages * For project packages, need to also check which components were built, if tests were run, if we need to rerun tests, etc * If all good: do nothing * Otherwise, for immutable tasks: check the precompiled cache for an identical package installation (same GHC, dependencies, etc). If present: copy that over, and we're done. * Otherwise, perform the build, register, write to the Stack specific "is installed" stuff, and (for immutable tasks) register to the precompiled cache "Perform the build" consists of: * Do a cabal configure, if needed * Build the desired components * For all test suites built, unless "no rerun tests" logic is on and we already ran the test, _or_ "no run tests" is on, run the test * For all benchmarks built, unless "no run benchmarks" is on, run the benchmark stack-2.9.3.1/doc/ChangeLog.md0000644000000000000000000045337514445117331014121 0ustar0000000000000000# Changelog ## v2.9.3.1 - 2023-06-22 Hackage-only release of the `stack` package: * Supports building against snapshot Stackage LTS Haskell 21.0 (GHC 9.4.5), without extra deps. * Supports build with `persistent-2.14.5.0`, using CPP directives. * Supports build with `unix-compat-0.7`, by removing reliance on the module `System.PosixCompat.User` removed in that package. * Includes `cabal.project` and `cabal.config` files in the package. ## v2.9.3 - 2022-12-16 **Changes since v2.9.1:** Behavior changes: * In YAML configuration files, the `package-index` key is introduced which takes precedence over the existing `package-indices` key. The latter is deprecated. * In YAML configuration files, the `hackage-security` key of the `package-index` key or the `package-indices` item can be omitted, and the Hackage Security configuration for the item will default to that for the official Hackage server. See [#5870](https://github.com/commercialhaskell/stack/issues/5870). * Add the `stack config set package-index download-prefix` command to set the location of Stack's package index in YAML configuration files. * `stack setup` with the `--no-install-ghc` flag warns that the flag and the command are inconsistent and now takes no action. Previously the flag was silently ignored. * To support the Haskell Foundation's [Haskell Error Index](https://errors.haskell.org/) initiative, all Stack error messages generated by Stack itself begin with an unique code in the form `[S-nnnn]`, where `nnnn` is a four-digit number. * Test suite executables that seek input on the standard input channel (`stdin`) will not throw an exception. Previously, they would thow an exception, consistent with Cabal's 'exitcode-stdio-1.0' test suite interface specification. Pass the flag `--no-tests-allow-stdin` to `stack build` to enforce Cabal's specification. See [#5897](https://github.com/commercialhaskell/stack/issues/5897) Other enhancements: * Help documentation for `stack upgrade` warns that if GHCup is used to install Stack, only GHCup should be used to upgrade Stack. That is because GHCup uses an executable named `stack` to manage versions of Stack, that Stack will likely overwrite on upgrade. * Add `stack ls dependencies cabal` command, which lists dependencies in the format of exact Cabal constraints. * Add `STACK_XDG` environment variable to use the XDG Base Directory Specification for the Stack root and Stack's global YAML configuration file, if the Stack root location is not set on the command line or by using the `STACK_ROOT` environment variable. * Add `stack path --global-config`, to yield the full path of Stack's user-specific global YAML configuration file (`config.yaml`). * Add an experimental option, `allow-newer-deps`, which allows users to specify a subset of dependencies for which version bounds should be ignored (`allow-newer-deps: ['foo', 'bar']`). This field has no effect unless `allow-newer` is enabled. Bug fixes: * Fix ambiguous module name `Distribution.PackageDescription`, if compiling `StackSetupShim` with `Cabal-syntax-3.8.1.0` in package database. See [#5886](https://github.com/commercialhaskell/stack/pull/5886). * In YAML configuration files, if the `package-indices` key (or the `hackage-security` key of its item) is omitted, the expiration of timestamps is now ignored, as intended. See Pantry [#63](https://github.com/commercialhaskell/pantry/pull/63) ## v2.9.1 - 2022-09-19 **Changes since v2.7.5:** Release notes: * After an upgrade from an earlier version of Stack, on first use only, Stack 2.9.1 may warn that it had trouble loading the CompilerPaths cache. Behavior changes: * `stack build --coverage` will generate a unified coverage report, even if there is only one `*.tix` file, in case a package has tested the library of another package that has not tested its own library. See [#5713](https://github.com/commercialhaskell/stack/issues/5713) * `stack --verbose` no longer includes the lengthy raw snapshot layer (rsl) in the debug output by default. The new `stack --[no-]rsl-in-log` flag enables or disables the inclusion of the rsl in the debug output. Other enhancements: * Bump to Hpack 0.35.0. * On Windows, the installer now sets `DisplayVersion` in the registry, enabling tools like `winget` to properly read the version number. * Adds flag `--script-no-run-compile` (disabled by default) that uses the `--no-run` option with `stack script` (and forces the `--compile` option). This enables a command like `stack --script-no-run-compile Script.hs` to behave like `stack script --no-run --compile -- Script.hs` but without having to list all the `` in the Stack interpreter options comment in `Script.hs` on the command line. That may help test that scripts compile in CI (continuous integration). See [#5755](https://github.com/commercialhaskell/stack/issues/5755) * Fuller help is provided at the command line if a subcommand is missing (for example, `stack ls` now yields the equivalent of `stack ls --help`). See [#809](https://github.com/commercialhaskell/stack/issues/809) * Add build option `--cabal-verbosity=VERBOSITY` to specify the Cabal verbosity level (the option accepts Cabal's numerical and extended syntax). See [#1369](https://github.com/commercialhaskell/stack/issues/809) * Add the possibility of a `sh` script to customise fully GHC installation. See [#5585](https://github.com/commercialhaskell/stack/pull/5585) * `tools` subcommand added to `stack ls`, to list stack's installed tools. * `stack uninstall` shows how to uninstall Stack. * `--ghc-variant` accepts `int-native` as a variant. Bug fixes: * Fix `stack clean --full`, so that the files to be deleted are not in use. See [#5714](https://github.com/commercialhaskell/stack/issues/5714) * Fix an inconsistency in the pretty formatting of the output of `stack build --coverage` * Fix repeated warning about missing parameters when using `stack new` * Include `pantry-0.5.6`: Remove operational and mirror keys from bootstrap key set [#53](https://github.com/commercialhaskell/pantry/pull/53) * Pass any CPP options specified via `cpp-options:` in the Cabal file to GHCi using GHC's `-optP` flag. See [#5608](https://github.com/commercialhaskell/stack/pull/5608) * On Unix-like operating systems, respect the `with-gcc` option when installing GHC. See [#5609](https://github.com/commercialhaskell/stack/pull/5609) * Fixed logic in `get_isa()` in `get-stack.sh` to exclude systems that don't have x86 in their `uname -m` output. See [5792](https://github.com/commercialhaskell/stack/issues/5792). * Fixed output of `stack ls snapshots local` on Windows, to behave like that on Unix-like operating systems. * Fix non-deterministic test failures when executing a test suite for a multi-project repository with parallelism enabled. See [#5024](https://github.com/commercialhaskell/stack/issues/5024) ## v2.7.5 - 2022-03-06 **Changes since v2.7.3:** Behavior changes: * Cloning git repositories isn't per sub-directory anymore, see [#5411](https://github.com/commercialhaskell/stack/issues/5411) Other enhancements: * `stack setup` supports installing GHC for macOS aarch64 (M1) * `stack upload` supports authentication with a Hackage API key (via `HACKAGE_KEY` environment variable). Bug fixes: * Ensure that `extra-path` works for case-insensitive `PATH`s on Windows. See [rio#237](https://github.com/commercialhaskell/rio/pull/237) * Fix handling of overwritten `ghc` and `ghc-pkg` locations. [#5597](https://github.com/commercialhaskell/stack/pull/5597) * Fix failure to find package when a dependency is shared between projects. [#5680](https://github.com/commercialhaskell/stack/issues/5680) * `stack ghci` now uses package flags in `stack.yaml` [#5434](https://github.com/commercialhaskell/stack/issues/5434) ## v2.7.3 - 2021-07-20 **Changes since v2.7.1:** Other enhancements: * `stack upgrade` will download from `haskellstack.org` before trying `github.com`. See [#5288](https://github.com/commercialhaskell/stack/issues/5288) * `stack upgrade` makes less assumptions about archive format. See [#5288](https://github.com/commercialhaskell/stack/issues/5288) * Add a `--no-run` flag to the `script` command when compiling. Bug fixes: * GHC source builds work properly for recent GHC versions again. See [#5528](https://github.com/commercialhaskell/stack/issues/5528) * `stack setup` always looks for the unpacked directory name to support different tar file naming conventions. See [#5545](https://github.com/commercialhaskell/stack/issues/5545) * Bump `pantry` version for better OS support. See [pantry#33](https://github.com/commercialhaskell/pantry/issues/33) * When building the sanity check for a new GHC install, make sure to clear `GHC_PACKAGE_PATH`. * Specifying GHC RTS flags in the `stack.yaml` no longer fails with an error. [#5568](https://github.com/commercialhaskell/stack/pull/5568) * `stack setup` will look in sandboxed directories for executables, not relying on `findExecutables. See [GHC issue 20074](https://gitlab.haskell.org/ghc/ghc/-/issues/20074) * Track changes to `setup-config` properly to avoid reconfiguring on every change. See [#5578](https://github.com/commercialhaskell/stack/issues/5578) ## v2.7.1 - 2021-05-07 **Changes since v2.5.1.1:** Behavior changes: * `stack repl` now always warns about GHCi problems with loading multiple packages. It also sets now proper working directory when invoked with one package. See [#5421](https://github.com/commercialhaskell/stack/issues/5421) * `custom-setup` dependencies are now properly initialized for `stack dist`. This makes `explicit-setup-deps` no longer required and that option was removed. See [#4006](https://github.com/commercialhaskell/stack/issues/4006) Other enhancements: * Nix integration now passes `ghcVersion` (in addition to existing `ghc`) to `shell-file` as an identifier that can be looked up in a compiler attribute set. * Nix integration now allows Nix integration if the user is ready in nix-shell. This gets rid of "In Nix shell but reExecL is False" error. * `stack list` is a new command to list package versions in a snapshot. See [#5431](https://github.com/commercialhaskell/stack/pull/5431) * Consider GHC 9.0 a tested compiler and remove warnings. * `custom-preprocessor-extensions` is a new configuration option for allowing Stack to be aware of any custom preprocessors you have added to `Setup.hs`. See [#3491](https://github.com/commercialhaskell/stack/issues/3491) * Added `--candidate` flag to `upload` command to upload a package candidate rather than publishing the package. * Error output using `--no-interleaved-output` no longer prepends indenting whitespace. This allows emacs compilation-mode and vim quickfix to locate and track errors. See [#5523](https://github.com/commercialhaskell/stack/pull/5523) Bug fixes: * `stack new` now supports branches other than `master` as default for GitHub repositories. See [#5422](https://github.com/commercialhaskell/stack/issues/5422) * Ignore all errors from `hi-file-parser`. See [#5445](https://github.com/commercialhaskell/stack/issues/5445) and [#5486](https://github.com/commercialhaskell/stack/issues/5486). * Support basic auth in package-indices. See [#5509](https://github.com/commercialhaskell/stack/issues/5509). * Add support for parsing `.hi`. files from GHC 8.10 and 9.0. See [hi-file-parser#2](https://github.com/commercialhaskell/hi-file-parser/pull/2). ## v2.5.1.1 - 2020-12-09 Hackage-only release: * Support build with persistent-2.11.x and optparse-applicative-0.16.x ## v2.5.1 - 2020-10-15 **Changes since v2.3.3** Major changes: * Add the `snapshot-location-base` yaml configuration option, which allows to override the default location of snapshot configuration files. This option affects how snapshot synonyms (LTS/Nightly) are expanded to URLs by the `pantry` library. * `docker-network` configuration key added to override docker `--net` arg Behavior changes: * File watching now takes into account specified targets, old behavior could be restored using the new flag `--watch-all` [#5310](https://github.com/commercialhaskell/stack/issues/5310) Other enhancements: * `stack ls dependencies json` now includes fields `sha256` and `size` for dependencies of `type` `archive` in `location`. [#5280](https://github.com/commercialhaskell/stack/issues/5280) * Build failures now show a hint to scroll up to the corresponding section [#5279](https://github.com/commercialhaskell/stack/issues/5279) * Customisable output styles (see `stack --help` and the `--stack-colors` option, and `stack ls stack-colors --help`) now include `info`, `debug`, `other-level`, `secondary` and `highlight`, used with verbose output. Bug fixes: * Fix `stack test --coverage` when using Cabal 3 * `stack new` now generates PascalCase'd module name correctly. [#5376](https://github.com/commercialhaskell/stack/issues/5376) * Connection issues to Casa server no longer cause builds to failure. Casa acts only as an optimizing cache layer, not a critical piece of infrastructure. * Fix modified time busting caches by always calculating sha256 digest during the build process. [#5125](https://github.com/commercialhaskell/stack/issues/5125) ## v2.3.3 - 2020-08-06 **Changes since v2.3.1** Other enhancements: * Add the `stack-developer-mode` flag Bug fixes: * When using the `STACK_YAML` env var with Docker, make the path absolute. * Fix the problem of `stack repl foo:test:bar` failing without a project build before that. See [#5213](https://github.com/commercialhaskell/stack/issues/5213) * Fix `stack sdist` introducing unnecessary sublibrary syntax when using pvp-bounds. See [#5289](https://github.com/commercialhaskell/stack/issues/5289) ## v2.3.1 - 2020-04-29 Release notes: * We have reduced the number of platforms that we support with binary releases. The reason behind this is that we've been slowed down in our release process until now with issues trying to build binaries for less common platforms. In order to make sure we can address issues more quickly (like supporting new GHC versions), we're limiting support from the Stack team to: * Linux 64-bit (static) * macOS * Windows 64-bit If others want to provide additional binaries, we will definitely be happy for the support. But since our CI system is currently able to produce these three bindists only, that's what we will be providing with the next release. * Since we no longer have dynamically linked Linux binaries, we are removing removing the `-static` suffix from the static Linux binaries. If you have scripts to download the latest stable Linux binary, update them to use `linux-x86_64` instead of `linux-x86_64-static` (if you are already using the former, nothing needs to change). For this release, both are supported, but the next release will no longer have the `-static` variant. * We are also deprecating the download links at https://stackage.org/stack. See this page for the current installation instructions: https://docs.haskellstack.org/en/stable/install_and_upgrade/. * These are the canonical locations to download the latest stable binaries from, and will continue to be supported going forward: * Linux 64-bit (static): https://get.haskellstack.org/stable/linux-x86_64.tar.gz * macOS: https://get.haskellstack.org/stable/osx-x86_64.tar.gz * Windows 64-bit: https://get.haskellstack.org/stable/windows-x86_64.zip As always, binaries for specific versions are available from the GitHub releases: https://github.com/commercialhaskell/stack/releases. **Changes since v2.1.3.1** Major changes: * `setup-info-locations` yaml configuration now allows overwriting the default locations of `stack-setup-2.yaml`. [#5031](https://github.com/commercialhaskell/stack/pull/5031) [#2983](https://github.com/commercialhaskell/stack/issues/2983) [#2913](https://github.com/commercialhaskell/stack/issues/2913) * The `setup-info` configuration key now allows overwriting parts of the default `setup-info` * The `--setup-info-yaml` command line flag now may be used in all Stack commands such as `stack build`, and not only in `stack setup` * The `--setup-info-yaml` may specify multiple locations for `stack-setup.yaml` files. * The `stack upload` can read first reads environment Variable `$HACKAGE_USERNAME` and `$HACKAGE_PASSWORD` if they are missing only then asks for `username` or `password` * Fully remove GHCJS support. * Remove the `freeze` command. It has been replaced by lock files. Behavior changes: * Remove the deprecated `--stack-setup-yaml` command line argument in favor of `--setup-info-yaml`. See [#2647](https://github.com/commercialhaskell/stack/issues/2647) * We now recommend checking in generated Cabal files for repos. When generating lock files for extra-deps that only include `package.yaml` files, a deprecation warning will be generated. Also, those packages will no longer be included in the generated lock files. See [#5210](https://github.com/commercialhaskell/stack/issues/5210). Other enhancements: * Add `build-output-timestamps` flag in yaml. Setting it to true prefixes each build log output line with a timestamp. * Show warning about `local-programs-path` with spaces on windows when running scripts. See [#5013](https://github.com/commercialhaskell/stack/pull/5013) * Add `ls dependencies json` which will print dependencies as JSON. `ls dependencies --tree` is now `ls dependencies tree`. See [#4424](https://github.com/commercialhaskell/stack/pull/4424) * Remove warning for using Stack with GHC 8.8-8.10, and Cabal 3.0-3.2. * Allow relative paths in `--setup-info-yaml` and tool paths [#3394](https://github.com/commercialhaskell/stack/issues/3394) * Added the `--only-locals` flag. See [#5272](https://github.com/commercialhaskell/stack/issues/5272) Bug fixes: * Upgrade `pantry`: module mapping insertions into the database are now atomic. Previously, if you SIGTERMed at the wrong time while running a script, you could end up with an inconsistent database state. * `--resolver global` doesn't retrieve snapshots list from the internet because doesn't need it. See [#5103](https://github.com/commercialhaskell/stack/issues/5103) * Fix using relative links in haddocks output. See [#4971](https://github.com/commercialhaskell/stack/issues/4971). * Do not include generated Cabal file information in lock files. See [#5045](https://github.com/commercialhaskell/stack/issues/5045). * Use proper Hoogle executable path when installed automatically. See [#4905](https://github.com/commercialhaskell/stack/issues/4905) * Fix GHC version for batched package unregistration. See [#4951](https://github.com/commercialhaskell/stack/issues/4951) * Use Hoogle from the snapshot used and not the latest version. See [#4905](https://github.com/commercialhaskell/stack/issues/4905) * Resolve "'stty' is not recognized". See [#4901](https://github.com/commercialhaskell/stack/issues/4901) * Fix missing reconfigure check causing errors when a package gets used in multiple projects. See [#5147](https://github.com/commercialhaskell/stack/issues/5147) ## v2.1.3.1 - 2019-07-16 Hackage-only release: * Support persistent-template-2.7.x * Support rio-0.1.11.0 * Add `stack.yaml` back to hackage sdist, and add `snapshot.yaml` ## v2.1.3 - 2019-07-13 **Changes since v2.1.1** Behavior changes: * Disable WAL mode for SQLite3 databases, to improve compatibility with some platforms and filesystems. See [#4876](https://github.com/commercialhaskell/stack/issues/4876). * By default, do not perform expiry checks in Hackage Security. See [#4928](https://github.com/commercialhaskell/stack/issues/4928). Other enhancements: * Do not rerun expected test failures. This is mostly a change that will only affect the Stackage Curator use case, but there is now an additional message letting the user know when a previously-failed test case is being rerun. * Move configure information for local packages back to .stack-work to improve caching. See [#4893](https://github.com/commercialhaskell/stack/issues/4893). Bug fixes: * Fix to allow dependencies on specific versions of local git repositories. See [#4862](https://github.com/commercialhaskell/stack/pull/4862) * Allow Stack commands to be run in Nix mode without having a project file available. See [#4854](https://github.com/commercialhaskell/stack/issues/4864). * Removes dependency on gnu-tar for OSX and Linux environment. The `--force-local` option was required only for windows environment. * Properly wait for the `tar` subprocess to complete before returning, thereby avoiding a SIGTERM screwing up GHC installation. See [#4888](https://github.com/commercialhaskell/stack/issues/4888). * Use package complete locations from lock files when resolving dependencies in `extra-deps`. See [#4887](https://github.com/commercialhaskell/stack/issues/4887). * Set the `HASKELL_DIST_DIR` environment to a proper package dist directory so `doctest` is able to load modules autogenerated by Cabal. * Expose package library when running tests. * Fix support for non-ASCII module names. See [#4938](https://github.com/commercialhaskell/stack/issues/4938) Other changes: * Rename `pantry-tmp` package back to `pantry`, now that we have gained maintainership (which had been used by someone else for a candidate-only test that made it look like the name was free but prevented uploading a real package). ## v2.1.1.1 - 2019-06-14 Hackage-only release that removes `stack.yaml` from the sdist. This is because `stack.yaml` now defines a multi-package project, whereas Hackage works on the basis on individual packages (see [#4860](https://github.com/commercialhaskell/stack/issues/4860)) If building a `stack` executable for distribution, please download the source code from https://github.com/commercialhaskell/stack/releases/tag/v2.1.1 and build it using Stack itself in order to ensure identical behaviour to official binaries. This package on Hackage is provided for convenience and bootstrapping purposes. ## v2.1.1 - 2019-06-13 The Stack 2 release represents a series of significant changes to how Stack works internally. For the vast majority of cases, these changes are backwards compatible, in that existing projects will continue to build in the same way with Stack 2 as they did with Stack 1. The large version bump is due to the fundamental internal changes to cache handling, database storage (using SQLite in place of binary files), implicit snapshots (which greatly improve the precompiled cache), and moving to Pantry. We have also removed some less used features, as listed below. **Changes since v1.9.3** Major changes: * Switch over to pantry for managing packages. This is a major change to Stack's internals, and affects user-visible behavior in a few places. Some highlights: * Drop support for multiple package indices and legacy `00-index.tar` style indices. See [#4137](https://github.com/commercialhaskell/stack/issues/4137). * Support for archives and repos in the `packages` section has been removed. Instead, you must use `extra-deps` for such dependencies. `packages` now only supports local filepaths. * Add support for Git repositories containing (recursive) submodules. * Addition of new configuration options for specifying a "pantry tree" key, which provides more reproducibility around builds, and (in the future) will be used for more efficient package content downloads. You can also specify package name and version for more efficient config parsing. * __NOTE__ The new `stack freeze` command provides support for automatically generating this additional information. * Package contents and metadata are stored in an SQLite database in place of files on the filesystem. The `pantry` library can be used for interacting with these contents. * Internally, Stack has changed many datatypes, including moving to Cabal's definition of many data types. As a result of such changes, existing cache files will in general be invalidated, resulting in Stack needing to rebuild many previously cached builds in the new version. Sorry :(. * A new command, `stack freeze` has been added which outputs project and snapshot definitions with dependencies pinned to their exact versions. * The `ignore-revision-mismatch` setting is no longer needed, and has been removed. * Overriding GHC boot packages results in any other GHC boot packages depending on it being no longer available as a dependency, such packages need to be added explicitly when needed. See [#4510] (https://github.com/commercialhaskell/stack/issues/4510). * Cabal solver integration was not updated to support newer `cabal-install` versions so `stack solver` command was removed as well as a related option `--solver` from `stack new` and `stack init`. * Upgrade to Cabal 2.4 * Note that, in this process, the behavior of file globbing has been modified to match that of Cabal. In particular, this means that for Cabal spec versions less than 2.4, `*.txt` will match `foo.txt`, but not `foo.2.txt`. * Remove the `stack image` command. With the advent of Docker multistage builds, this functionality is no longer useful. For an example, please see [Building Haskell Apps with Docker](https://www.fpcomplete.com/blog/2017/12/building-haskell-apps-with-docker). * Support building GHC from source (experimental) * Stack now supports building and installing GHC from source. The built GHC is uniquely identified by a commit id and an Hadrian "flavour" (Hadrian is the newer GHC build system), hence `compiler` can be set to use a GHC built from source with `ghc-git-COMMIT-FLAVOUR` * `stack.yaml` now supports a `configure-options`, which are passed directly to the `configure` step in the Cabal build process. See [#1438](https://github.com/commercialhaskell/stack/issues/1438) * Remove support for building GHCJS itself. Future releases of Stack may remove GHCJS support entirely. * Support for lock files for pinning exact project dependency versions Behavior changes: * `stack.yaml` now supports `snapshot`: a synonym for `resolver`. See [#4256](https://github.com/commercialhaskell/stack/issues/4256) * `stack script` now passes `-i -idir` in to the `ghc` invocation. This makes it so that the script can import local modules, and fixes an issue where `.hs` files in the current directory could affect interpretation of the script. See [#4538](https://github.com/commercialhaskell/stack/pull/4538) * When using `stack script`, custom snapshot files will be resolved relative to the directory containing the script. * Remove the deprecated `--upgrade-cabal` flag to `stack setup`. * Support the `drop-packages` field in `stack.yaml` * Remove the GPG signing code during uploads. The GPG signatures have never been used yet, and there are no plans to implement signature verification. * Remove the `--plain` option for the `exec` family of commands * Always use the `--exact-configuration` Cabal configuration option when building (should mostly be a non-user-visible enhancement). * No longer supports Cabal versions older than `1.19.2`. This means projects using snapshots earlier than `lts-3.0` or `nightly-2015-05-05` will no longer build. * Remove the `stack docker cleanup` command. Docker itself now has [`docker image prune`](https://docs.docker.com/engine/reference/commandline/image_prune/) and [`docker container prune`](https://docs.docker.com/engine/reference/commandline/container_prune/), which you can use instead. * Interleaved output is now turned on by default, see [#4702](https://github.com/commercialhaskell/stack/issues/4702). In addition, the `packagename> ` prefix is no longer included in interleaved mode when only building a single target. * The `-fhide-source-paths` GHC option is now enabled by default and can be disabled via the `hide-source-paths` configuration option in `stack.yaml`. See [#3784](https://github.com/commercialhaskell/stack/issues/3784) * Stack will reconfigure a package if you modify your `PATH` environment variable. See [#3138](https://github.com/commercialhaskell/stack/issues/3138). * For GHC 8.4 and later, disable the "shadowed dependencies" workaround. This means that Stack will no longer have to force reconfigures as often. See [#3554](https://github.com/commercialhaskell/stack/issues/3554). * When building a package, Stack takes a lock on the dist directory in use to avoid multiple runs of Stack from trampling each others' files. See [#2730](https://github.com/commercialhaskell/stack/issues/2730). * Stack will check occasionally if there is a new version available and prompt the user to upgrade. This will not incur any additional network traffic, as it will piggy-back on the existing Hackage index updates. You can set `recommend-stack-upgrade: false` to bypass this. See [#1681](https://github.com/commercialhaskell/stack/issues/1681). * `stack list-dependencies` has been removed in favour of `stack ls dependencies`. * The new default for `--docker-auto-pull` is enabled. See [#3332](https://github.com/commercialhaskell/stack/issues/3332). Other enhancements: * Support MX Linux in get-stack.sh. Fixes [#4769](https://github.com/commercialhaskell/stack/issues/4769). * Defer loading up of files for local packages. This allows us to get plan construction errors much faster, and avoid some unnecessary work when only building a subset of packages. This is especially useful for the curator use case. * Existing global option `--color=WHEN` is now also available as a non-project-specific yaml configuration parameter `color:`. * Adopt the standard proposed at http://no-color.org/, that color should not be added by default if the `NO_COLOR` environment variable is present. * New command `stack ls stack-colors` lists the styles and the associated 'ANSI' control character sequences that Stack uses to color some of its output. See `stack ls stack-colors --help` for more information. * New global option `--stack-colors=STYLES`, also available as a non-project-specific yaml configuration parameter, allows a Stack user to redefine the default styles that Stack uses to color some of its output. See `stack --help` for more information. * British English spelling of 'color' (colour) accepted as an alias for `--color`, `--stack-colors`, `stack ls stack-colors` at the command line and for `color:` and `stack-colors:` in yaml configuration files. * New build option `--ddump-dir`. (See [#4225](https://github.com/commercialhaskell/stack/issues/4225)) * Stack parses and respects the `preferred-versions` information from Hackage for choosing latest version of a package in some cases, e.g. `stack unpack packagename`. * The components output in the `The main module to load is ambiguous` message now include package names so they can be more easily copy-pasted. * Git repos are shared across multiple projects. See [#3551](https://github.com/commercialhaskell/stack/issues/3551) * Use en_US.UTF-8 locale by default in pure Nix mode so programs won't crash because of Unicode in their output [#4095](https://github.com/commercialhaskell/stack/issues/4095) * Add `--tree` to `ls dependencies` to list dependencies as tree. [#4101](https://github.com/commercialhaskell/stack/issues/4101) * Add `--pedantic` to `ghci` to run with `-Wall` and `-Werror` [#4463](https://github.com/commercialhaskell/stack/issues/4463) * Add `--cabal-files` flag to `stack ide targets` command. * Add `--stdout` flag to all `stack ide` subcommands. * Use batches when unregistering packages with `ghc-pkg`. (See [#2662](https://github.com/commercialhaskell/stack/issues/2662)) * `get-stack` script now works on Windows CI machines of Appveyor, Travis and Azure Pipelines. See [#4535](https://github.com/commercialhaskell/stack/issues/4535)/ * Show snapshot being used when `stack ghci` is invoked outside of a project directory. See [#3651](https://github.com/commercialhaskell/stack/issues/3651) * The script interpreter now accepts a `--extra-dep` flag for adding packages not present in the snapshot. Currently, this only works with packages from Hackage, not Git repos or archives. * When using the script interpreter with `--optimize` or `--compile`, Stack will perform an optimization of checking whether a newer executable exists, making reruns significantly faster. There's a downside to this, however: if you have a multifile script, and change one of the dependency modules, Stack will not automatically detect and recompile. * `stack clean` will delete the entire `.stack-work/dist` directory, not just the relevant subdirectory for the current GHC version. See [#4480](https://github.com/commercialhaskell/stack/issues/4480). * Add `stack purge` as a shortcut for `stack clean --full`. See [#3863](https://github.com/commercialhaskell/stack/issues/3863). * Both `stack dot` and `stack ls dependencies` accept a `--global-hints` flag to bypass the need for an installed GHC. See [#4390](https://github.com/commercialhaskell/stack/issues/4390). * Add the `stack config env` command for getting shell script environment variables. See [#620](https://github.com/commercialhaskell/stack/issues/620). * Less verbose output from `stack setup` on Windows. See [#1212](https://github.com/commercialhaskell/stack/issues/1212). * Add an optional `ignore-expiry` flag to the `hackage-security` section of the `~/.stack/config.yaml`. It allows to disable timestamp expiration verification just like `cabal --ignore-expiry` does. The flag is not enabled by default so that the default functionality is not changed. * Include default values for most command line flags in the `--help` output. See [#893](https://github.com/commercialhaskell/stack/issues/893). * Set the `GHC_ENVIRONMENT` environment variable to specify dependency packages explicitly when running test. This is done to prevent ambiguous module name errors in `doctest` tests. * `get-stack` script now works on Windows CI machines of Appveyor, Travis and Azure Pipelines. See [#4535](https://github.com/commercialhaskell/stack/issues/4535) * Warn when a Docker image does not include a `PATH` environment variable. See [#2472](https://github.com/commercialhaskell/stack/issues/2742) * When using `system-ghc: true`, Stack will now find the appropriate GHC installation based on the version suffix, allowing you to more easily switch between various system-installed GHCs. See [#2433](https://github.com/commercialhaskell/stack/issues/2433). * `stack init` will now support create a `stack.yaml` file without any local packages. See [#2465](https://github.com/commercialhaskell/stack/issues/2465) * Store caches in SQLite database instead of files. * No longer use "global" Docker image database (`docker.db`). * User config files are respected for the script command. See [#3705](https://github.com/commercialhaskell/stack/issues/3705), [#3887](https://github.com/commercialhaskell/stack/issues/3887). * Set the `GHC_ENVIRONMENT` environment variable to `-` to tell GHC to ignore any such files when GHC is new enough (>= 8.4.4), otherwise simply unset the variable. This allows Stack to have control of package databases when running commands like `stack exec ghci`, even in the presence of implicit environment files created by `cabal new-build`. See [#4706](https://github.com/commercialhaskell/stack/issues/4706). * Use a database cache table to speed up discovery of installed GHCs * You can specify multiple `--test-arguments` options. See [#2226](https://github.com/commercialhaskell/stack/issues/2226) * Windows terminal width detection is now done. See [#3588](https://github.com/commercialhaskell/stack/issues/3588) * On Windows, informs users if the 'programs' path contains a space character and further warns users if that path does not have an alternative short ('8 dot 3') name, referencing the `local-programs-path` configuration option. See [#4726](https://github.com/commercialhaskell/stack/issues/4726) * Add `--docker-mount-mode` option to set the Docker volume mount mode for performance tuning on macOS. Bug fixes: * Ignore duplicate files for a single module when a Haskell module was generated from a preprocessor file. See [#4076](https://github.com/commercialhaskell/stack/issues/4076). * Only track down components in current directory if there are no hs-source-dirs found. This eliminates a number of false-positive warnings, similar to [#4076](https://github.com/commercialhaskell/stack/issues/4076). * Handle a change in GHC's hi-dump format around `addDependentFile`, which now includes a hash. See [yesodweb/yesod#1551](https://github.com/yesodweb/yesod/issues/1551) * Fix `subdirs` for git repos in `extra-deps` to match whole directory names. Also fixes for `subdirs: .`. See [#4292](https://github.com/commercialhaskell/stack/issues/4292) * Fix for git packages to update submodules to the correct state. See [#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`. * Support loading in GHCi definitions from symlinked C files. Without this patch, Stack will try to find object files in the directory pointed to by symlinks, while GCC will produce the object files in the original directory. See [#4402](https://github.com/commercialhaskell/stack/pull/4402) * Fix handling of GitHub and URL templates on Windows. See [#4394](https://github.com/commercialhaskell/stack/issues/4394) * Fix `--file-watch` not responding to file modifications when running inside docker on Mac. See [#4506](https://github.com/commercialhaskell/stack/issues/4506) * Using `--ghc-options` with `stack script --compile` now works. * Ensure the detailed-0.9 type tests work. See [#4453](https://github.com/commercialhaskell/stack/issues/4453). * Extra include and lib dirs are now order-dependent. See [#4527](https://github.com/commercialhaskell/stack/issues/4527). * Apply GHC options when building a `Setup.hs` file. See [#4526](https://github.com/commercialhaskell/stack/issues/4526). * Stack handles ABI changes in FreeBSD 12 by differentiating that version from previous. * Help text for the `templates` subcommand now reflects behaviour in Stack 1.9 — that it downloads and shows a help file, rather than listing available templates. * Fix detection of aarch64 platform (this broke when we upgraded to a newer Cabal version). * Docker: fix detecting and pulling missing images with `--docker-auto-pull`. See [#4598](https://github.com/commercialhaskell/stack/issues/4598) * Hackage credentials are not world-readable. See [#2159](https://github.com/commercialhaskell/stack/issues/2159). * Warnings are dumped from logs even when color is enabled. See [#2997](https://github.com/commercialhaskell/stack/issues/2997) * `stack init` will now work for Cabal files with sublibraries. See [#4408](https://github.com/commercialhaskell/stack/issues/4408) * When the Cabal spec version is newer than the global Cabal version, build against the snapshot's Cabal library. See [#4488](https://github.com/commercialhaskell/stack/issues/4488) * Docker: fix detection of expected subprocess failures. This fixes downloading a compatible `stack` executable when the host `stack` is not compatible with the Docker image (on Linux), and doesn't show an unnecessary extra error when the in-container re-exec'ed `stack` exits with failure. * The `stack ghci` command's `--ghc-options` flag now parses multiple options. See [#3315](https://github.com/commercialhaskell/stack/issues/3315). ## v1.9.3.1 - 2019-04-18 Hackage-only release with no user facing changes (added compatibility with `rio-0.1.9.2`). ## v1.9.3 - 2018-12-02 Bug fixes: * Stack can now be compiled again inside a directory that does not contain a `.git` directory. See [#4364](https://github.com/commercialhaskell/stack/issues/4364#issuecomment-431600841) * Handle a change in GHC's hi-dump format around `addDependentFile`, which now includes a hash. See [yesodweb/yesod#1551](https://github.com/yesodweb/yesod/issues/1551) * Allow variables to appear in template file names. ## v1.9.1.1 - 2018-11-14 Hackage-only release with no user facing changes. * Stack can now be compiled again inside a directory that does not contain a `.git` directory. See [#4364](https://github.com/commercialhaskell/stack/issues/4364#issuecomment-431600841) ## v1.9.1 - 2018-10-17 Release notes: * Statically linked Linux bindists are back again, thanks to [@nh2](https://github.com/nh2). * We will be deleting the Ubuntu, Debian, CentOS, Fedora, and Arch package repos from `download.fpcomplete.com` soon. These have been deprecated for over a year and have not received new releases, but were left in place for compatibility with older scripts. Major changes: * Upgrade to Cabal 2.4 * Note that, in this process, the behavior of file globbing has been modified to match that of Cabal. In particular, this means that for Cabal spec versions less than 2.4, `*.txt` will match `foo.txt`, but not `foo.2.txt`. * `GHCJS` support is being downgraded to 'experimental'. A warning notifying the user of the experimental status of `GHCJS` will be displayed. Behavior changes: * `ghc-options` from `stack.yaml` are now appended to `ghc-options` from `config.yaml`, whereas before they would be replaced. * `stack build` will now announce when sublibraries of a package are being build, in the same way executables, tests, benchmarks and libraries are announced * `stack sdist` will now announce the destination of the generated tarball, regardless of whether or not it passed the sanity checks * The `--upgrade-cabal` option to `stack setup` has been deprecated. This feature no longer works with GHC 8.2 and later. Furthermore, the reason for this flag originally being implemented was drastically lessened once Stack started using the snapshot's `Cabal` library for custom setups. See: [#4070](https://github.com/commercialhaskell/stack/issues/4070). * With the new namespaced template feature, `stack templates` is no longer able to meaningfully display a list of all templates available. Instead, the command will download and display a [help file](https://github.com/commercialhaskell/stack-templates/blob/master/STACK_HELP.md) with more information on how to discover templates. See: [#4039](https://github.com/commercialhaskell/stack/issues/4039) * Build tools are now handled in a similar way to `cabal-install`. In particular, for legacy `build-tools` fields, we use a hard-coded list of build tools in place of looking up build tool packages in a tool map. This both brings Stack's behavior closer into line with `cabal-install`, avoids some bugs, and opens up some possible optimizations/laziness. See: [#4125](https://github.com/commercialhaskell/stack/issues/4125). * Mustache templating is not applied to large files (over 50kb) to avoid performance degradation. See: [#4133](https://github.com/commercialhaskell/stack/issues/4133). * `stack upload` signs the package by default, as documented. `--no-signature` turns the signing off. [#3739](https://github.com/commercialhaskell/stack/issues/3739) * In case there is a network connectivity issue while trying to download a template, Stack will check whether that template had been downloaded before. In that case, the cached version will be used. See [#3850](https://github.com/commercialhaskell/stack/issues/3850). Other enhancements: * On Windows before Windows 10, --color=never is the default on terminals that can support ANSI color codes in output only by emulation * On Windows, recognise a 'mintty' (false) terminal as a terminal, by default * `stack build` issues a warning when `base` is explicitly listed in `extra-deps` of `stack.yaml` * `stack build` suggests trying another GHC version should the build plan end up requiring unattainable `base` version. * A new sub command `run` has been introduced to build and run a specified executable similar to `cabal run`. If no executable is provided as the first argument, it defaults to the first available executable in the project. * `stack build` missing dependency suggestions (on failure to construct a valid build plan because of missing deps) are now printed with their latest Cabal file revision hash. See [#4068](https://github.com/commercialhaskell/stack/pull/4068). * Added new `--tar-dir` option to `stack sdist`, that allows to copy the resulting tarball to the specified directory. * Introduced the `--interleaved-output` command line option and `build.interleaved-output` config value which causes multiple concurrent builds to dump to stderr at the same time with a `packagename> ` prefix. See [#3225](https://github.com/commercialhaskell/stack/issues/3225). * The default retry strategy has changed to exponential backoff. This should help with [#3510](https://github.com/commercialhaskell/stack/issues/3510). * `stack new` now allows template names of the form `username/foo` to download from a user other than `commercialstack` on GitHub, and can be prefixed with the service `github:`, `gitlab:`, or `bitbucket:`. See [#4039](https://github.com/commercialhaskell/stack/issues/4039) * Switch to `githash` to include some unmerged bugfixes in `gitrev` Suggestion to add `'allow-newer': true` now shows path to user config file where this flag should be put into [#3685](https://github.com/commercialhaskell/stack/issues/3685) * `stack ghci` now asks which main target to load before doing the build, rather than after * Bump to Hpack 0.29.0 * With GHC 8.4 and later, Haddock is given the `--quickjump` flag. * It is possible to specify the Hackage base URL to upload packages to, instead of the default of `https://hackage.haskell.org/`, by using `hackage-base-url` configuration option. * When using Nix, if a specific minor version of GHC is not requested, the latest minor version in the given major branch will be used automatically. Bug fixes: * `stack ghci` now does not invalidate `.o` files on repeated runs, meaning any modules compiled with `-fobject-code` will be cached between ghci runs. See [#4038](https://github.com/commercialhaskell/stack/pull/4038). * `~/.stack/config.yaml` and `stack.yaml` terminating by newline * The previous released caused a regression where some `stderr` from the `ghc-pkg` command showed up in the terminal. This output is now silenced. * A regression in recompilation checking introduced in v1.7.1 has been fixed. See [#4001](https://github.com/commercialhaskell/stack/issues/4001) * `stack ghci` on a package with internal libraries was erroneously looking for a wrong package corresponding to the internal library and failing to load any module. This has been fixed now and changes to the code in the library and the sublibrary are properly tracked. See [#3926](https://github.com/commercialhaskell/stack/issues/3926). * For packages with internal libraries not depended upon, `stack build` used to fail the build process since the internal library was not built but it was tried to be registered. This is now fixed by always building internal libraries. See [#3996](https://github.com/commercialhaskell/stack/issues/3996). * `--no-nix` was not respected under NixOS * Fix a regression which might use a lot of RAM. See [#4027](https://github.com/commercialhaskell/stack/issues/4027). * Order of commandline arguments does not matter anymore. See [#3959](https://github.com/commercialhaskell/stack/issues/3959) * When prompting users about saving their Hackage credentials on upload, flush to stdout before waiting for the response so the prompt actually displays. Also fixes a similar issue with ghci target selection prompt. * If `cabal` is not on PATH, running `stack solver` now prompts the user to run `stack install cabal-install` * `stack build` now succeeds in building packages which contain sublibraries which are dependencies of executables, tests or benchmarks but not of the main library. See [#3787](https://github.com/commercialhaskell/stack/issues/3787). * Sublibraries are now properly considered for coverage reports when the test suite depends on the internal library. Before, Stack was erroring when trying to generate the coverage report, see [#4105](https://github.com/commercialhaskell/stack/issues/4105). * Sublibraries are now added to the precompiled cache and recovered from there when the snapshot gets updated. Previously, updating the snapshot when there was a package with a sublibrary in the snapshot resulted in broken builds. This is now fixed, see [#4071](https://github.com/commercialhaskell/stack/issues/4071). * [#4114](https://github.com/commercialhaskell/stack/issues/4114) Stack pretty prints error messages with proper `error` logging level instead of `warning` now. This also fixes self-executing scripts not piping plan construction errors from runhaskell to terminal (issue [#3942](https://github.com/commercialhaskell/stack/issues/3942)). * Fix invalid "While building Setup.hs" when Cabal calls fail. See: [#3934](https://github.com/commercialhaskell/stack/issues/3934) * `stack upload` signs the package by default, as documented. `--no-signature` turns the signing off. [#3739](https://github.com/commercialhaskell/stack/issues/3739) ## v1.7.1 - 2018-04-27 Release notes: * aarch64 (64-bit ARM) bindists are now available for the first time. * Statically linked Linux bindists are no longer available, due to difficulty with GHC 8.2.2 on Alpine Linux. * 32-bit Linux GMP4 bindists for CentOS 6 are no longer available, since GHC 8.2.2 is no longer being built for that platform. Major changes: * Upgrade from Cabal 2.0 to Cabal 2.2 Behavior changes: * `stack setup` no longer uses different GHC configure options on Linux distributions that use GCC with PIE enabled by default. GHC detects this itself since ghc-8.0.2, and Stack's attempted workaround for older versions caused more problems than it solved. * `stack new` no longer initializes a project if the project template contains a `stack.yaml` file. Other enhancements: * A new sub command `ls` has been introduced to Stack to view local and remote snapshots present in the system. Use `stack ls snapshots --help` to get more details about it. * `list-dependencies` has been deprecated. The functionality has to accessed through the new `ls dependencies` interface. See [#3669](https://github.com/commercialhaskell/stack/issues/3669) for details. * Specify User-Agent HTTP request header on every HTTP request. See [#3628](https://github.com/commercialhaskell/stack/issues/3628) for details. * `stack setup` looks for GHC bindists and installations by any OS key that is compatible (rather than only checking a single one). This is relevant on Linux where different distributions may have different combinations of libtinfo 5/6, ncurses 5/6, and gmp 4/5, and will allow simplifying the setup-info metadata YAML for future GHC releases. * The build progress bar reports names of packages currently building. * `stack setup --verbose` causes verbose output of GHC configure process. See [#3716](https://github.com/commercialhaskell/stack/issues/3716) * Improve the error message when an `extra-dep` from a path or git reference can't be found. See [#3808](https://github.com/commercialhaskell/stack/pull/3808) * Nix integration is now disabled on windows even if explicitly enabled, since it isn't supported. See [#3600](https://github.com/commercialhaskell/stack/issues/3600) * `stack build` now supports a new flag `--keep-tmp-files` to retain intermediate files and directories for the purpose of debugging. It is best used with ghc's equivalent flag, i.e. `stack build --keep-tmp-files --ghc-options=-keep-tmp-files`. See [#3857](https://github.com/commercialhaskell/stack/issues/3857) * Improved error messages for snapshot parse exceptions * `stack unpack` now supports a `--to /target/directory` option to specify where to unpack the package into * `stack hoogle` now supports a new flag `--server` that launches local Hoogle server on port 8080. See [#2310](https://github.com/commercialhaskell/stack/issues/2310) Bug fixes: * The script interpreter's implicit file arguments are now passed before other arguments. See [#3658](https://github.com/commercialhaskell/stack/issues/3658). In particular, this makes it possible to pass `-- +RTS ... -RTS` to specify RTS arguments used when running the script. * Don't ignore the template `year` parameter in config files, and clarify the surrounding documentation. See [#2275](https://github.com/commercialhaskell/stack/issues/2275). * Benchmarks used to be run concurrently with other benchmarks and build steps. This is non-ideal because CPU usage of other processes may interfere with benchmarks. It also prevented benchmark output from being displayed by default. This is now fixed. See [#3663](https://github.com/commercialhaskell/stack/issues/3663). * `stack ghci` now allows loading multiple packages with the same module name, as long as they have the same filepath. See [#3776](https://github.com/commercialhaskell/stack/pull/3776). * `stack ghci` no longer always adds a dependency on `base`. It is now only added when there are no local targets. This allows it to be to load code that uses replacements for `base`. See [#3589](https://github.com/commercialhaskell/stack/issues/3589#issuecomment) * `stack ghci` now uses correct paths for autogen files with [#3791](https://github.com/commercialhaskell/stack/issues/3791) * When a package contained sublibraries, Stack was always recompiling the package. This has been fixed now, no recompilation is being done because of sublibraries. See [#3899](https://github.com/commercialhaskell/stack/issues/3899). * The `get-stack.sh` install script now matches manual instructions when it comes to Debian/Fedora/CentOS install dependencies. * Compile Cabal-simple with gmp when using Nix. See [#2944](https://github.com/commercialhaskell/stack/issues/2944) * `stack ghci` now replaces the Stack process with ghci. This improves signal handling behavior. In particular, handling of Ctrl-C. To make this possible, the generated files are now left behind after exit. The paths are based on hashing file contents, and it's stored in the system temporary directory, so this shouldn't result in too much garbage. See [#3821](https://github.com/commercialhaskell/stack/issues/3821). ## v1.6.5 - 2018-02-19 Bug fixes: * Some unnecessary rebuilds when no files were changed are now avoided, by having a separate build cache for each component of a package. See [#3732](https://github.com/commercialhaskell/stack/issues/3732). * Correct the behavior of promoting a package from snapshot to local package. This would get triggered when version bounds conflicted in a snapshot, which could be triggered via Hackage revisions for old packages. This also should allow custom snapshots to define conflicting versions of packages without issue. See [Stackage issue #3185](https://github.com/fpco/stackage/issues/3185). * When promoting packages from snapshot to local, we were occasionally discarding the actual package location content and instead defaulting to pulling the package from the index. We now correctly retain this information. Note that if you were affected by this bug, you will likely need to delete the binary build cache associated with the relevant custom snapshot. See [#3714](https://github.com/commercialhaskell/stack/issues/3714). * `--no-rerun-tests` has been fixed. Previously, after running a test we were forgetting to record the result, which meant that all tests always ran even if they had already passed before. See [#3770](https://github.com/commercialhaskell/stack/pull/3770). * Includes a patched version of `hackage-security` which fixes both some issues around asynchronous exception handling, and moves from directory locking to file locking, making the update mechanism resilient against SIGKILL and machine failure. See `hackage-security` issue [#187](https://github.com/haskell/hackage-security/issues/187) and Stack issue [#3073](https://github.com/commercialhaskell/stack/issues/3073). ## v1.6.3.1 - 2018-02-16 Hackage-only release with no user facing changes (updated to build with newer version of Hpack dependency). ## v1.6.3 - 2017-12-23 Enhancements: * In addition to supporting `.tar.gz` and `.zip` files as remote archives, plain `.tar` files are now accepted too. This will additionally help with cases where HTTP servers mistakenly set the transfer encoding to `gzip`. See [#3647](https://github.com/commercialhaskell/stack/issues/3647). * Links to docs.haskellstack.org ignore Stack version patchlevel. * Downloading Docker-compatible `stack` binary ignores Stack version patchlevel. Bug fixes: * For versions of Cabal before 1.24, ensure that the dependencies of non-buildable components are part of the build plan to work around an old Cabal bug. See [#3631](https://github.com/commercialhaskell/stack/issues/3631). * Run the Cabal file checking in the `sdist` command more reliably by allowing the Cabal library to flatten the `GenericPackageDescription` itself. ## v1.6.1.1 - 2017-12-20 Hackage-only release with no user facing changes (updated to build with newer dependency versions). ## v1.6.1 - 2017-12-07 Major changes: * Complete overhaul of how snapshots are defined, the `packages` and `extra-deps` fields, and a number of related items. For full details, please see the [writeup](https://www.fpcomplete.com/blog/2017/07/stacks-new-extensible-snapshots) on these changes. [PR #3249](https://github.com/commercialhaskell/stack/pull/3249), see the PR description for a number of related issues. * Upgraded to version 2.0 of the Cabal library. Behavior changes: * The `--install-ghc` flag is now on by default. For example, if you run `stack build` in a directory requiring a GHC that you do not currently have, Stack will automatically download and install that GHC. You can explicitly set `install-ghc: false` or pass the flag `--no-install-ghc` to regain the previous behavior. * `stack ghci` no longer loads modules grouped by package. This is always an improvement for plain ghci - it makes loading faster and less noisy. For intero, this has the side-effect that it will no longer load multiple packages that depend on TH loading relative paths. TH relative paths will still work when loading a single package into intero. See [#3309](https://github.com/commercialhaskell/stack/issues/3309) * Setting GHC options for a package via `ghc-options:` in your `stack.yaml` will promote it to a local package, providing for more consistency with flags and better reproducibility. See: [#849](https://github.com/commercialhaskell/stack/issues/849) * The `package-indices` setting with Hackage no longer works with the `00-index.tar.gz` tarball, but must use the `01-index.tar.gz` file to allow revised packages to be found. * Options passed via `--ghci-options` are now passed to the end of the invocation of ghci, instead of the middle. This allows using `+RTS` 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) * Stack will ask before saving hackage credentials to file. This new prompt can be avoided by using the `save-hackage-creds` setting. Please see [#2159](https://github.com/commercialhaskell/stack/issues/2159). * The `GHCRTS` environment variable will no longer be passed through to every program Stack runs. Instead, it will only be passed through commands like `exec`, `runghc`, `script`, `ghci`, etc. See [#3444](https://github.com/commercialhaskell/stack/issues/3444). * `ghc-options:` for specific packages will now come after the options specified for all packages / particular sets of packages. See [#3573](https://github.com/commercialhaskell/stack/issues/3573). * The `pvp-bounds` feature is no longer fully functional, due to some issues with the Cabal library's printer. See [#3550](https://github.com/commercialhaskell/stack/issues/3550). Other enhancements: * The `with-hpack` configuration option specifies an Hpack executable to use instead of the Hpack bundled with Stack. Please see [#3179](https://github.com/commercialhaskell/stack/issues/3179). * It's now possible to skip tests and benchmarks using `--skip` flag * `GitSHA1` is now `StaticSHA256` and is implemented using the `StaticSize 64 ByteString` for improved performance. See [#3006](https://github.com/commercialhaskell/stack/issues/3006) * Dependencies via HTTP(S) archives have been generalized to allow local file path archives, as well as to support setting a cryptographic hash (SHA256) of the contents for better reproducibility. * Allow specifying `--git-branch` when upgrading * When running `stack upgrade` from a file which is different from the default executable path (e.g., on POSIX systems, `~/.local/bin/stack`), it will now additionally copy the new executable over the currently running `stack` executable. If permission is denied (such as in `/usr/local/bin/stack`), the user will be prompted to try again using `sudo`. This is intended to assist with the user experience when the `PATH` environment variable has not been properly configured, see [#3232](https://github.com/commercialhaskell/stack/issues/3232). * `stack setup` for ghcjs will now install `alex` and `happy` if they are not present. See [#3109](https://github.com/commercialhaskell/stack/issues/3232). * Added `stack ghci --only-main` flag, to skip loading / importing all but main modules. See the ghci documentation page for further info. * Allow GHC's colored output to show through. GHC colors output starting with version 8.2.1, for older GHC this does nothing. Sometimes GHC's heuristics would work fine even before this change, for example in `stack ghci`, but this override's GHC's heuristics when they're broken by our collecting and processing GHC's output. * Extended the `ghc-options` field to support `$locals`, `$targets`, and `$everything`. See: [#3329](https://github.com/commercialhaskell/stack/issues/3329) * Better error message for case that `stack ghci` file targets are combined with invalid package targets. See: [#3342](https://github.com/commercialhaskell/stack/issues/3342) * For profiling now uses `-fprof-auto -fprof-cafs` instead of the deprecated `-auto-all -caf-all`. See: [#3360](https://github.com/commercialhaskell/stack/issues/3360) * Better descriptions are now available for `stack upgrade --help`. See: [#3070](https://github.com/commercialhaskell/stack/issues/3070) * When using Nix, nix-shell now depends always on gcc to prevent build errors when using the FFI. As ghc depends on gcc anyway, this doesn't increase the dependency footprint. * `--cwd DIR` can now be passed to `stack exec` in order to execute the program in a different directory. See: [#3264](https://github.com/commercialhaskell/stack/issues/3264) * Plan construction will detect if you add an executable-only package as a library dependency, resulting in much clearer error messages. See: [#2195](https://github.com/commercialhaskell/stack/issues/2195). * Addition of `--ghc-options` to `stack script` to pass options directly to GHC. See: [#3454](https://github.com/commercialhaskell/stack/issues/3454) * Add Hpack `package.yaml` to build Stack itself * Add `ignore-revision-mismatch` setting. See: [#3520](https://github.com/commercialhaskell/stack/issues/3520). * Log when each individual test suite finishes. See: [#3552](https://github.com/commercialhaskell/stack/issues/3552). * Avoid spurious rebuilds when using `--file-watch` by not watching files for executable, test and benchmark components that aren't a target. See: [#3483](https://github.com/commercialhaskell/stack/issues/3483). * Stack will now try to detect the width of the running terminal (only on POSIX for the moment) and use that to better display output messages. Work is ongoing, so some messages will not be optimal yet. The terminal width can be overridden with the new `--terminal-width` command-line option (this works even on non-POSIX). * Passing non local packages as targets to `stack ghci` will now cause them to be used as `-package` args along with package hiding. * Detect when user changed Cabal file instead of `package.yaml`. This was implemented upstream in Hpack. See [#3383](https://github.com/commercialhaskell/stack/issues/3383). * Automatically run `autoreconf -i` as necessary when a `configure` script is missing. See [#3534](https://github.com/commercialhaskell/stack/issues/3534) * GHC bindists can now be identified by their SHA256 checksum in addition to their SHA1 checksum, allowing for more security in download. * For filesystem setup-info paths, it's no longer assumed that the directory is writable, instead a temp dir is used. See [#3188](https://github.com/commercialhaskell/stack/issues/3188). Bug fixes: * `stack hoogle` correctly generates Hoogle databases. See: [#3362](https://github.com/commercialhaskell/stack/issues/3362) * `stack --docker-help` is now clearer about --docker implying system-ghc: true, rather than both --docker and --no-docker. * `stack haddock` now includes package names for all modules in the Haddock index page. See: [#2886](https://github.com/commercialhaskell/stack/issues/2886) * Fixed an issue where Stack wouldn't detect missing Docker images properly with newer Docker versions. [#3171](https://github.com/commercialhaskell/stack/pull/3171) * Previously, Cabal files with just test-suite could cause build to fail ([#2862](https://github.com/commercialhaskell/stack/issues/2862)) * If an invalid snapshot file has been detected (usually due to mismatched hashes), Stack will delete the downloaded file and recommend either retrying or filing an issue upstream. See [#3319](https://github.com/commercialhaskell/stack/issues/3319). * Modified the flag parser within Stack to match the behavior of Cabal's flag parser, which allows multiple sequential dashes. See [#3345](https://github.com/commercialhaskell/stack/issues/3345) * Now clears the hackage index cache if it is older than the downloaded index. Fixes potential issue if Stack was interrupted when updating index. See [#3033](https://github.com/commercialhaskell/stack/issues/3033) * The Stack install script now respects the `-d` option. See [#3366](https://github.com/commercialhaskell/stack/pull/3366). * `stack script` can now handle relative paths to source files. See [#3372](https://github.com/commercialhaskell/stack/issues/3372). * Fixes explanation of why a target is needed by the build plan, when the target is an extra dependency from the commandline. See [#3378](https://github.com/commercialhaskell/stack/issues/3378). * Previously, if you delete a yaml file from ~/.stack/build-plan, it would trust the etag and not re-download. Fixed in this version. * Invoking `stack --docker` in parallel now correctly locks the sqlite database. See [#3400](https://github.com/commercialhaskell/stack/issues/3400). * docs.haskellstack.org RTD documentation search is replaced by the mkdocs search. Please see [#3376](https://github.com/commercialhaskell/stack/issues/3376). * `stack clean` now works with nix. See [#3468](https://github.com/commercialhaskell/stack/issues/3376). * `stack build --only-dependencies` no longer builds local project packages that are depended on. See [#3476](https://github.com/commercialhaskell/stack/issues/3476). * Properly handle relative paths stored in the precompiled cache files. See [#3431](https://github.com/commercialhaskell/stack/issues/3431). * In some cases, Cabal does not realize that it needs to reconfigure, and must be told to do so automatically. This would manifest as a "shadowed dependency" error message. We now force a reconfigure whenever a dependency is built, even if the package ID remained the same. See [#2781](https://github.com/commercialhaskell/stack/issues/2781). * When `--pvp-bounds` is enabled for sdist or upload, internal dependencies could cause errors when uploaded to hackage. This is fixed, see [#3290](https://github.com/commercialhaskell/stack/issues/3290) * Fixes a bug where nonexistent hackage versions would cause Stack to suggest the same package name, without giving version info. See [#3562](https://github.com/commercialhaskell/stack/issues/3562) * Fixes a bug that has existed since 1.5.0, where `stack setup --upgrade-cabal` would say that Cabal is already the latest version, when it wasn't. * Ensure that an `extra-dep` from a local directory is not treated as a `$locals` for GHC options purposes. See [#3574](https://github.com/commercialhaskell/stack/issues/3574). * Building all executables only happens once instead of every time. See [#3229](https://github.com/commercialhaskell/stack/issues/3229) for more info. ## 1.5.1 - 2017-08-05 Bug fixes: * Stack eagerly tries to parse all Cabal files related to a snapshot. Starting with Stackage Nightly 2017-07-31, snapshots are using GHC 8.2.1, and the `ghc.cabal` file implicitly referenced uses the (not yet supported) Cabal 2.0 file format. Future releases of Stack will both be less eager about Cabal file parsing and support Cabal 2.0. This patch simply bypasses the error for invalid parsing. ## 1.5.0 - 2017-07-25 Behavior changes: * `stack profile` and `stack trace` now add their extra RTS arguments for benchmarks and tests to the beginning of the args, instead of the end. See [#2399](https://github.com/commercialhaskell/stack/issues/2399) * Support for Git-based indices has been removed. Other enhancements: * `stack setup` allow to control options passed to ghcjs-boot with `--ghcjs-boot-options` (one word at a time) and `--[no-]ghcjs-boot-clean` * `stack setup` now accepts a `--install-cabal VERSION` option which will install a specific version of the Cabal library globally. * Updates to store-0.4.1, which has improved performance and better error reporting for version tags. A side-effect of this is that all of stack's binary caches will be invalidated. * `stack solver` will now warn about unexpected `cabal-install` versions. See [#3044](https://github.com/commercialhaskell/stack/issues/3044) * Upstream packages unpacked to a temp dir are now deleted as soon as possible to avoid running out of space in `/tmp`. See [#3018](https://github.com/commercialhaskell/stack/issues/3018) * Add short synonyms for `test-arguments` and `benchmark-arguments` options. * Adds `STACK_WORK` environment variable, to specify work dir. See [#3063](https://github.com/commercialhaskell/stack/issues/3063) * Can now use relative paths for `extra-include-dirs` and `extra-lib-dirs`. See [#2830](https://github.com/commercialhaskell/stack/issues/2830) * Improved bash completion for many options, including `--ghc-options`, `--flag`, targets, and project executables for `exec`. * `--haddock-arguments` is actually used now when `haddock` is invoked during documentation generation. * `--[no-]haddock-hyperlink-source` flag added which allows toggling of sources being included in Haddock output. See [#3099](https://github.com/commercialhaskell/stack/issues/3099) * `stack ghci` will now skip building all local targets, even if they have downstream deps, as long as it's registered in the DB. * The `pvp-bounds` feature now supports adding `-revision` to the end of each value, e.g. `pvp-bounds: both-revision`. This means that, when uploading to Hackage, Stack will first upload your tarball with an unmodified Cabal file, and then upload a Cabal file revision with the PVP bounds added. This can be useful - especially combined with the [Stackage no-revisions feature](http://www.snoyman.com/blog/2017/04/stackages-no-revisions-field) - as a method to ensure PVP compliance without having to proactively fix bounds issues for Stackage maintenance. * Expose a `save-hackage-creds` configuration option * On GHC <= 7.8, filters out spurious linker warnings on windows See [#3127](https://github.com/commercialhaskell/stack/pull/3127) * Better error messages when creating or building packages which alias wired-in packages. See [#3172](https://github.com/commercialhaskell/stack/issues/3172). * MinGW bin folder now is searched for dynamic libraries. See [#3126](https://github.com/commercialhaskell/stack/issues/3126) * When using Nix, nix-shell now depends always on git to prevent runtime errors while fetching metadata * The `stack unpack` command now accepts a form where an explicit Hackage revision hash is specified, e.g. `stack unpack foo-1.2.3@gitsha1:deadbeef`. Note that this should be considered _experimental_, Stack will likely move towards a different hash format in the future. * Binary "stack upgrade" will now warn if the installed executable is not on the PATH or shadowed by another entry. * Allow running tests on tarball created by sdist and upload [#717](https://github.com/commercialhaskell/stack/issues/717). Bug fixes: * Fixes case where `stack build --profile` might not cause executables / tests / benchmarks to be rebuilt. See [#2984](https://github.com/commercialhaskell/stack/issues/2984) * `stack ghci file.hs` now loads the file even if it isn't part of your project. * `stack clean --full` now works when docker is enabled. See [#2010](https://github.com/commercialhaskell/stack/issues/2010) * Fixes an issue where cyclic deps can cause benchmarks or tests to be run before they are built. See [#2153](https://github.com/commercialhaskell/stack/issues/2153) * Fixes `stack build --file-watch` in cases where a directory is removed See [#1838](https://github.com/commercialhaskell/stack/issues/1838) * Fixes `stack dot` and `stack list-dependencies` to use info from the package database for wired-in-packages (ghc, base, etc). See [#3084](https://github.com/commercialhaskell/stack/issues/3084) * Fixes `stack --docker build` when user is part of libvirt/libvirtd groups on Ubuntu Yakkety (16.10). See [#3092](https://github.com/commercialhaskell/stack/issues/3092) * Switching a package between extra-dep and local package now forces rebuild (previously it wouldn't if versions were the same). See [#2147](https://github.com/commercialhaskell/stack/issues/2147) * `stack upload` no longer reveals your password when you type it on MinTTY-based Windows shells, such as Cygwin and MSYS2. See [#3142](https://github.com/commercialhaskell/stack/issues/3142) * `stack script`'s import parser will now properly parse files that have Windows-style line endings (CRLF) ## 1.4.0 - 2017-03-15 Release notes: * Docker images: [fpco/stack-full](https://hub.docker.com/r/fpco/stack-full/) and [fpco/stack-run](https://hub.docker.com/r/fpco/stack-run/) are no longer being built for LTS 8.0 and above. [fpco/stack-build](https://hub.docker.com/r/fpco/stack-build/) images continue to be built with a [simplified process](https://github.com/commercialhaskell/stack/tree/master/etc/dockerfiles/stack-build). [#624](https://github.com/commercialhaskell/stack/issues/624) Major changes: * A new command, `script`, has been added, intended to make the script interpreter workflow more reliable, easier to use, and more efficient. This command forces the user to provide a `--resolver` value, ignores all config files for more reproducible results, and optimizes the existing package check to make the common case of all packages already being present much faster. This mode does require that all packages be present in a snapshot, however. [#2805](https://github.com/commercialhaskell/stack/issues/2805) Behavior changes: * The default package metadata backend has been changed from Git to the 01-index.tar.gz file, from the hackage-security project. This is intended to address some download speed issues from GitHub for people in certain geographic regions. There is now full support for checking out specific Cabal file revisions from downloaded tarballs as well. If you manually specify a package index with only a Git URL, Git will still be used. See [#2780](https://github.com/commercialhaskell/stack/issues/2780) * When you provide the `--resolver` argument to the `stack unpack` command, any packages passed in by name only will be looked up in the given snapshot instead of taking the latest version. For example, `stack --resolver lts-7.14 unpack mtl` will get version 2.2.1 of `mtl`, regardless of the latest version available in the package indices. This will also force the same Cabal file revision to be used as is specified in the snapshot. Unpacking via a package identifier (e.g. `stack --resolver lts-7.14 unpack mtl-2.2.1`) will ignore any settings in the snapshot and take the most recent revision. For backwards compatibility with tools relying on the presence of a `00-index.tar`, Stack will copy the `01-index.tar` file to `00-index.tar`. Note, however, that these files are different; most importantly, 00-index contains only the newest revisions of Cabal files, while 01-index contains all versions. You may still need to update your tooling. * Passing `--(no-)nix-*` options now no longer implies `--nix`, except for `--nix-pure`, so that the user preference whether or not to use Nix is honored even in the presence of options that change the Nix behavior. Other enhancements: * Internal cleanup: configuration types are now based much more on lenses * `stack build` and related commands now allow the user to disable debug symbol stripping with new `--no-strip`, `--no-library-stripping`, and `--no-executable-shipping` flags, closing [#877](https://github.com/commercialhaskell/stack/issues/877). Also turned error message for missing targets more readable ([#2384](https://github.com/commercialhaskell/stack/issues/2384)) * `stack haddock` now shows index.html paths when documentation is already up to date. Resolved [#781](https://github.com/commercialhaskell/stack/issues/781) * Respects the `custom-setup` field introduced in Cabal 1.24. This supercedes any `explicit-setup-deps` settings in your `stack.yaml` and trusts the package's Cabal file to explicitly state all its dependencies. * If system package installation fails, `get-stack.sh` will fail as well. Also shows warning suggesting to run `apt-get update` or similar, depending on the OS. ([#2898](https://github.com/commercialhaskell/stack/issues/2898)) * When `stack ghci` is run with a config with no packages (e.g. global project), it will now look for source files in the current work dir. ([#2878](https://github.com/commercialhaskell/stack/issues/2878)) * Bump to Hpack 0.17.0 to allow `custom-setup` and `!include "..."` in `package.yaml`. * The script interpreter will now output error logging. In particular, this means it will output info about plan construction errors. ([#2879](https://github.com/commercialhaskell/stack/issues/2879)) * `stack ghci` now takes `--flag` and `--ghc-options` again (inadvertently removed in 1.3.0). ([#2986](https://github.com/commercialhaskell/stack/issues/2986)) * `stack exec` now takes `--rts-options` which passes the given arguments inside of `+RTS ... args .. -RTS` to the executable. This works around Stack itself consuming the RTS flags on Windows. ([#2640](https://github.com/commercialhaskell/stack/issues/2640)) * Upgraded `http-client-tls` version, which now offers support for the `socks5://` and `socks5h://` values in the `http_proxy` and `https_proxy` environment variables. Bug fixes: * Bump to Hpack 0.16.0 to avoid character encoding issues when reading and writing on non-UTF8 systems. * `stack ghci` will no longer ignore hsSourceDirs that contain `..`. ([#2895](https://github.com/commercialhaskell/stack/issues/2895)) * `stack list-dependencies --license` now works for wired-in-packages, like base. ([#2871](https://github.com/commercialhaskell/stack/issues/2871)) * `stack setup` now correctly indicates when it uses system ghc ([#2963](https://github.com/commercialhaskell/stack/issues/2963)) * Fix to `stack config set`, in 1.3.2 it always applied to the global project. ([#2709](https://github.com/commercialhaskell/stack/issues/2709)) * Previously, Cabal files without exe or lib would fail on the "copy" step. ([#2862](https://github.com/commercialhaskell/stack/issues/2862)) * `stack upgrade --git` now works properly. Workaround for affected versions (>= 1.3.0) is to instead run `stack upgrade --git --source-only`. ([#2977](https://github.com/commercialhaskell/stack/issues/2977)) * Added support for GHC 8's slightly different warning format for dumping warnings from logs. * Work around a bug in Cabal/GHC in which package IDs are not unique for different source code, leading to Stack not always rebuilding packages depending on local packages which have changed. ([#2904](https://github.com/commercialhaskell/stack/issues/2904)) ## 1.3.2 - 2016-12-27 Bug fixes: * `stack config set` can now be used without a compiler installed [#2852](https://github.com/commercialhaskell/stack/issues/2852). * `get-stack.sh` now installs correct binary on ARM for generic linux and raspbian, closing [#2856](https://github.com/commercialhaskell/stack/issues/2856). * Correct the testing of whether a package database exists by checking for the `package.cache` file itself instead of the containing directory. * Revert a change in the previous release which made it impossible to set local extra-dep packages as targets. This was overkill; we really only wanted to disable their test suites, which was already handled by a later patch. [#2849](https://github.com/commercialhaskell/stack/issues/2849) * `stack new` always treats templates as being UTF-8 encoding, ignoring locale settings on a local machine. See [Yesod mailing list discussion](https://groups.google.com/d/msg/yesodweb/ZyWLsJOtY0c/aejf9E7rCAAJ) ## 1.3.0 - 2016-12-12 Release notes: * For the _next_ Stack release after this one, we are planning changes to our Linux releases, including dropping our Ubuntu, Debian, CentOS, and Fedora package repositories and switching to statically linked binaries. See [#2534](https://github.com/commercialhaskell/stack/issues/2534). Note that upgrading without a package manager has gotten easier with new binary upgrade support in `stack upgrade` (see the Major Changes section below for more information). In addition, the get.haskellstack.org script no longer installs from Ubuntu, Debian, CentOS, or Fedora package repositories. Instead it places a generic binary in /usr/local/bin. Major changes: * Stack will now always use its own GHC installation, even when a suitable GHC installation is available on the PATH. To get the old behaviour, use the `--system-ghc` flag or run `stack config set system-ghc --global true`. Docker- and Nix-enabled projects continue to use the GHC installations in their environment by default. NB: Scripts that previously used Stack in combination with a system GHC installation should now include a `stack setup` line or use the `--install-ghc` flag. [#2221](https://github.com/commercialhaskell/stack/issues/2221) * `stack ghci` now defaults to skipping the build of target packages, because support has been added for invoking "initial build steps", which create autogen files and run preprocessors. The `--no-build` flag is now deprecated because it should no longer be necessary. See [#1364](https://github.com/commercialhaskell/stack/issues/1364) * Stack is now capable of doing binary upgrades instead of always recompiling a new version from source. Running `stack upgrade` will now default to downloading a binary version of Stack from the most recent release, if one is available. See `stack upgrade --help` for more options. [#1238](https://github.com/commercialhaskell/stack/issues/1238) Behavior changes: * Passing `--resolver X` with a Stack command which forces creation of a global project config, will pass resolver X into the initial config. See [#2579](https://github.com/commercialhaskell/stack/issues/2229). * Switch the "Run from outside project" messages to debug-level, to avoid spamming users in the normal case of non-project usage * If a remote package is specified (such as a Git repo) without an explicit `extra-dep` setting, a warning is given to the user to provide one explicitly. Other enhancements: * `stack haddock` now supports `--haddock-internal`. See [#2229](https://github.com/commercialhaskell/stack/issues/2229) * Add support for `system-ghc` and `install-ghc` fields to `stack config set` command. * Add `ghc-build` option to override autodetected GHC build to use (e.g. gmp4, tinfo6, nopie) on Linux. * `stack setup` detects systems where gcc enables PIE by default (such as Ubuntu 16.10 and Hardened Gentoo) and adjusts the GHC `configure` options accordingly. [#2542](https://github.com/commercialhaskell/stack/issues/2542) * Upload to Hackage with HTTP digest instead of HTTP basic. * Make `stack list-dependencies` understand all of the `stack dot` options too. * Add the ability for `stack list-dependencies` to list dependency licenses by passing the `--license` flag. * Dump logs that contain warnings for any local non-dependency packages [#2545](https://github.com/commercialhaskell/stack/issues/2545) * Add the `dump-logs` config option and `--dump-logs` command line option to get full build output on the console. [#426](https://github.com/commercialhaskell/stack/issues/426) * Add the `--open` option to "stack hpc report" command, causing the report to be opened in the browser. * The `stack config set` command now accepts a `--global` flag for suitable fields which causes it to modify the global user configuration (`~/.stack/config.yaml`) instead of the project configuration. [#2675](https://github.com/commercialhaskell/stack/pull/2675) * Information on the latest available snapshots is now downloaded from S3 instead of stackage.org, increasing reliability in case of stackage.org outages. [#2653](https://github.com/commercialhaskell/stack/pull/2653) * `stack dot` and `stack list-dependencies` now take targets and flags. [#1919](https://github.com/commercialhaskell/stack/issues/1919) * Deprecate `stack setup --stack-setup-yaml` for `--setup-info-yaml` based on discussion in [#2647](https://github.com/commercialhaskell/stack/issues/2647). * The `--main-is` flag for GHCI now implies the TARGET, fixing [#1845](https://github.com/commercialhaskell/stack/issues/1845). * `stack ghci` no longer takes all build options, as many weren't useful [#2199](https://github.com/commercialhaskell/stack/issues/2199) * `--no-time-in-log` option, to make verbose logs more diffable [#2727](https://github.com/commercialhaskell/stack/issues/2727) * `--color` option added to override auto-detection of ANSI support [#2725](https://github.com/commercialhaskell/stack/issues/2725) * Missing extra-deps are now warned about, adding a degree of typo detection [#1521](https://github.com/commercialhaskell/stack/issues/1521) * No longer warns about missing build-tools if they are on the PATH. [#2235](https://github.com/commercialhaskell/stack/issues/2235) * Replace enclosed-exceptions with safe-exceptions. [#2768](https://github.com/commercialhaskell/stack/issues/2768) * The install location for GHC and other programs can now be configured with the `local-programs-path` option in `config.yaml`. [#1644](https://github.com/commercialhaskell/stack/issues/1644) * Added option to add nix dependencies as nix GC roots * Proper pid 1 (init) process for `stack exec` with Docker * Dump build logs if they contain warnings. [#2545](https://github.com/commercialhaskell/stack/issues/2545) * Docker: redirect stdout of `docker pull` to stderr so that it will not interfere with output of other commands. * Nix & docker can be activated at the same time, in order to run Stack in a nix-shell in a container, preferably from an image already containing the nix dependencies in its /nix/store * Stack/nix: Dependencies can be added as nix GC roots, so they are not removed when running `nix-collect-garbage` Bug fixes: * Fixed a gnarly bug where programs and package tarballs sometimes have corrupted downloads. See [#2657](https://github.com/commercialhaskell/stack/issues/2568). * Add proper support for non-ASCII characters in file paths for the `sdist` command. See [#2549](https://github.com/commercialhaskell/stack/issues/2549) * Never treat `extra-dep` local packages as targets. This ensures things like test suites are not run for these packages, and that build output is not hidden due to their presence. * Fix a resource leak in `sinkProcessStderrStdout` which could affect much of the codebase, in particular copying precompiled packages. [#1979](https://github.com/commercialhaskell/stack/issues/1979) * Docker: ensure that interrupted extraction process does not cause corrupt file when downloading a Docker-compatible Stack executable [#2568](https://github.com/commercialhaskell/stack/issues/2568) * Fixed running `stack hpc report` on package targets. [#2664](https://github.com/commercialhaskell/stack/issues/2664) * Fix a long-standing performance regression where Stack would parse the `.dump-hi` files of the library components of local packages twice. [#2658](https://github.com/commercialhaskell/stack/pull/2658) * Fixed a regression in "stack ghci --no-load", where it would prompt for a main module to load. [#2603](https://github.com/commercialhaskell/stack/pull/2603) * Build Setup.hs files with the threaded RTS, mirroring the behavior of `cabal-install` and enabling more complex build systems in those files. * Fixed a bug in passing along `--ghc-options` to ghcjs. They were being provided as `--ghc-options` to Cabal, when it needs to be `--ghcjs-options`. [#2714](https://github.com/commercialhaskell/stack/issues/2714) * Launch Docker from the project root regardless of the working directory Stack is invoked from. This means paths relative to the project root (e.g. environment files) can be specified in `stack.yaml`'s docker `run-args`. * `stack setup --reinstall` now behaves as expected. [#2554](https://github.com/commercialhaskell/stack/issues/2554) ## 1.2.0 - 2016-09-16 Release notes: * On many Un*x systems, Stack can now be installed with a simple one-liner: wget -qO- https://get.haskellstack.org/ | sh * The fix for [#2175](https://github.com/commercialhaskell/stack/issues/2175) entails that Stack must perform a full clone of a large Git repo of Hackage meta-information. The total download size is about 200 MB. Please be aware of this when upgrading your Stack installation. * If you use Mac OS X, you may want to delay upgrading to macOS Sierra as there are reports of GHC panics when building some packages (including Stack itself). See [#2577](https://github.com/commercialhaskell/stack/issues/2577) * This version of Stack does not build on ARM or PowerPC systems (see [store#37](https://github.com/fpco/store/issues/37)). Please stay with version 1.1.2 for now on those architectures. This will be rectified soon! * We are now releasing a statically linked Stack binary for [64-bit Linux](https://get.haskellstack.org/stable/linux-x86_64-static.tar.gz). Please try it and let us know if you run into any trouble on your platform. * We are planning some changes to our Linux releases, including dropping our Ubuntu, Debian, CentOS, and Fedora package repositories and switching to statically linked binaries. We would value your feedback in [#2534](https://github.com/commercialhaskell/stack/issues/2534). Major changes: * Add `stack hoogle` command. [#55](https://github.com/commercialhaskell/stack/issues/55) * Support for absolute file path in `url` field of `setup-info` or `--ghc-bindist` * Add support for rendering GHCi scripts targeting different GHCi like applications [#2457](https://github.com/commercialhaskell/stack/pull/2457) Behavior changes: * Remove `stack ide start` and `stack ide load-targets` commands. [#2178](https://github.com/commercialhaskell/stack/issues/2178) * Support .buildinfo files in `stack ghci`. [#2242](https://github.com/commercialhaskell/stack/pull/2242) * Support -ferror-spans syntax in GHC error messages. * Avoid unpacking ghc to `/tmp` [#996](https://github.com/commercialhaskell/stack/issues/996) * The Linux `gmp4` GHC bindist is no longer considered a full-fledged GHC variant and can no longer be specified using the `ghc-variant` option, and instead is treated more like a slightly different platform. Other enhancements: * Use the `store` package for binary serialization of most caches. * Only require minor version match for Docker Stack exe. This way, we can make patch releases for version bounds and similar build issues without needing to upload new binaries for Docker. * Stack/Nix: Passes the right ghc derivation as an argument to the `shell.nix` when a custom `shell.nix` is used. See [#2243](https://github.com/commercialhaskell/stack/issues/2243) * Stack/Nix: Sets `LD_LIBRARY_PATH` so packages using C libs for Template Haskell can work (See _e.g._ [this HaskellR issue](https://github.com/tweag/HaskellR/issues/253)) * Parse CLI arguments and configuration files into less permissive types, improving error messages for bad inputs. [#2267](https://github.com/commercialhaskell/stack/issues/2267) * Add the ability to explicitly specify a gcc executable. [#593](https://github.com/commercialhaskell/stack/issues/593) * Nix: No longer uses LTS mirroring in nixpkgs. Gives to nix-shell a derivation like `haskell.compiler.ghc801` See [#2259](https://github.com/commercialhaskell/stack/issues/2259) * Perform some subprocesses during setup concurrently, slightly speeding up most commands. [#2346](https://github.com/commercialhaskell/stack/pull/2346) * `stack setup` no longer unpacks to the system temp dir on posix systems. [#996](https://github.com/commercialhaskell/stack/issues/996) * `stack setup` detects libtinfo6 and ncurses6 and can download alternate GHC bindists [#257](https://github.com/commercialhaskell/stack/issues/257) [#2302](https://github.com/commercialhaskell/stack/issues/2302). * `stack setup` detects Linux ARMv7 downloads appropriate GHC bindist [#2103](https://github.com/commercialhaskell/stack/issues/2103) * Custom `stack` binaries list dependency versions in output for `--version`. See [#2222](https://github.com/commercialhaskell/stack/issues/2222) and [#2450](https://github.com/commercialhaskell/stack/issues/2450). * Use a pretty printer to output dependency resolution errors. [#1912](https://github.com/commercialhaskell/stack/issues/1912) * Remove the `--os` flag [#2227](https://github.com/commercialhaskell/stack/issues/2227) * Add 'netbase' and 'ca-certificates' as dependency for .deb packages. [#2293](https://github.com/commercialhaskell/stack/issues/2293). * Add `stack ide targets` command. * Enhance debug logging with subprocess timings. * Pretty-print YAML parse errors [#2374](https://github.com/commercialhaskell/stack/issues/2374) * Clarify confusing `stack setup` output [#2314](https://github.com/commercialhaskell/stack/issues/2314) * Delete `Stack.Types` multimodule to improve build times [#2405](https://github.com/commercialhaskell/stack/issues/2405) * Remove spurious newlines in build logs [#2418](https://github.com/commercialhaskell/stack/issues/2418) * Interpreter: Provide a way to hide implicit packages [#1208](https://github.com/commercialhaskell/stack/issues/1208) * Check executability in exec lookup [#2489](https://github.com/commercialhaskell/stack/issues/2489) Bug fixes: * Fix Cabal warning about use of a deprecated Cabal flag [#2350](https://github.com/commercialhaskell/stack/issues/2350) * Support most executable extensions on Windows [#2225](https://github.com/commercialhaskell/stack/issues/2225) * Detect resolver change in `stack solver` [#2252](https://github.com/commercialhaskell/stack/issues/2252) * Fix a bug in docker image creation where the wrong base image was selected [#2376](https://github.com/commercialhaskell/stack/issues/2376) * Ignore special entries when unpacking tarballs [#2361](https://github.com/commercialhaskell/stack/issues/2361) * Fixes src directory pollution of `style.css` and `highlight.js` with GHC 8's haddock [#2429](https://github.com/commercialhaskell/stack/issues/2429) * Handle filepaths with spaces in `stack ghci` [#2266](https://github.com/commercialhaskell/stack/issues/2266) * Apply ghc-options to snapshot packages [#2289](https://github.com/commercialhaskell/stack/issues/2289) * `stack sdist`: Fix timestamp in tarball [#2394](https://github.com/commercialhaskell/stack/pull/2394) * Allow global Stack arguments with a script [#2316](https://github.com/commercialhaskell/stack/issues/2316) * Inconsistency between ToJSON and FromJSON instances of PackageLocation [#2412](https://github.com/commercialhaskell/stack/pull/2412) * Perform Unicode normalization on filepaths [#1810](https://github.com/commercialhaskell/stack/issues/1810) * Solver: always keep ghc wired-in as hard constraints [#2453](https://github.com/commercialhaskell/stack/issues/2453) * Support OpenBSD's tar where possible, require GNU tar for xz support [#2283](https://github.com/commercialhaskell/stack/issues/2283) * Fix using --coverage with Cabal-1.24 [#2424](https://github.com/commercialhaskell/stack/issues/2424) * When marking exe installed, remove old version [#2373](https://github.com/commercialhaskell/stack/issues/2373) * Stop truncating `all-cabal-hashes` git repo [#2175](https://github.com/commercialhaskell/stack/issues/2175) * Handle non-ASCII filenames on Windows [#2491](https://github.com/commercialhaskell/stack/issues/2491) * Avoid using multiple versions of a package in script interpreter by passing package-id to ghc/runghc [#1957](https://github.com/commercialhaskell/stack/issues/1957) * Only pre-load compiler version when using nix integration [#2459](https://github.com/commercialhaskell/stack/issues/2459) * Solver: parse Cabal errors also on Windows [#2502](https://github.com/commercialhaskell/stack/issues/2502) * Allow exec and ghci commands in interpreter mode. Scripts can now automatically open in the repl by using `exec ghci` instead of `runghc` in the shebang command. [#2510](https://github.com/commercialhaskell/stack/issues/2510) * Now consider a package to be dirty when an extra-source-file is changed. See [#2040](https://github.com/commercialhaskell/stack/issues/2040) ## 1.1.2 - 2016-05-20 Release notes: * Official FreeBSD binaries are [now available](http://docs.haskellstack.org/en/stable/install_and_upgrade/#freebsd) [#1253](https://github.com/commercialhaskell/stack/issues/1253). Major changes: * Extensible custom snapshots implemented. These allow you to define snapshots which extend other snapshots. See [#863](https://github.com/commercialhaskell/stack/issues/863). Local file custom snapshots can now be safely updated without changing their name. Remote custom snapshots should still be treated as immutable. Behavior changes: * `stack path --compiler` was added in the last release, to yield a path to the compiler. Unfortunately, `--compiler` is a global option that is useful to use with `stack path`. The same functionality is now provided by `stack path --compiler-exe`. See [#2123](https://github.com/commercialhaskell/stack/issues/2123) * For packages specified in terms of a git or hg repo, the hash used in the location has changed. This means that existing downloads from older stack versions won't be used. This is a side-effect of the fix to [#2133](https://github.com/commercialhaskell/stack/issues/2133) * `stack upgrade` no longer pays attention to local `stack.yaml` files, just the global config and CLI options. [#1392](https://github.com/commercialhaskell/stack/issues/1392) * `stack ghci` now uses `:add` instead of `:load`, making it potentially work better with user scripts. See [#1888](https://github.com/commercialhaskell/stack/issues/1888) Other enhancements: * Grab Cabal files via Git SHA to avoid regressions from Hackage revisions [#2070](https://github.com/commercialhaskell/stack/pull/2070) * Custom snapshots now support `ghc-options`. * Package git repos are now re-used rather than re-cloned. See [#1620](https://github.com/commercialhaskell/stack/issues/1620) * `DESTDIR` is filtered from environment when installing GHC. See [#1460](https://github.com/commercialhaskell/stack/issues/1460) * `stack haddock` now supports `--haddock-arguments`. See [#2144](https://github.com/commercialhaskell/stack/issues/2144) * Signing: warn if GPG_TTY is not set as per `man gpg-agent` Bug fixes: * Now ignore project config when doing `stack init` or `stack new`. See [#2110](https://github.com/commercialhaskell/stack/issues/2110) * Packages specified by git repo can now have submodules. See [#2133](https://github.com/commercialhaskell/stack/issues/2133) * Fix of hackage index fetch retry. See re-opening of [#1418](https://github.com/commercialhaskell/stack/issues/1418#issuecomment-217633843) * HPack now picks up changes to filesystem other than package.yaml. See [#2051](https://github.com/commercialhaskell/stack/issues/2051) * "stack solver" no longer suggests --omit-packages. See [#2031](https://github.com/commercialhaskell/stack/issues/2031) * Fixed an issue with building Cabal's Setup.hs. See [#1356](https://github.com/commercialhaskell/stack/issues/1356) * Package dirtiness now pays attention to deleted files. See [#1841](https://github.com/commercialhaskell/stack/issues/1841) * `stack ghci` now uses `extra-lib-dirs` and `extra-include-dirs`. See [#1656](https://github.com/commercialhaskell/stack/issues/1656) * Relative paths outside of source dir added via `qAddDependentFile` are now checked for dirtiness. See [#1982](https://github.com/commercialhaskell/stack/issues/1982) * Signing: always use `--with-fingerprints` ## 1.1.0 - 2016-05-04 Release notes: * Added Ubuntu 16.04 LTS (xenial) Apt repo. * No longer uploading new versions to Fedora 21 repo. Behavior changes: * Snapshot packages are no longer built with executable profiling. See [#1179](https://github.com/commercialhaskell/stack/issues/1179). * `stack init` now ignores symlinks when searching for Cabal files. It also now ignores any directory that begins with `.` (as well as `dist` dirs) - before it would only ignore `.git`, `.stack-work`, and `dist`. * The Stack executable is no longer built with `-rtsopts`. Before, when `-rtsopts` was enabled, Stack would process `+RTS` options even when intended for some other program, such as when used with `stack exec -- prog +RTS`. See [#2022](https://github.com/commercialhaskell/stack/issues/2022). * The `stack path --ghc-paths` option is deprecated and renamed to `--programs`. `--compiler` is added, which points directly at the compiler used in the current project. `--compiler-bin` points to the compiler's bin dir. * For consistency with the `$STACK_ROOT` environment variable, the `stack path --global-stack-root` flag and the `global-stack-root` field in the output of `stack path` are being deprecated and replaced with the `stack-root` flag and output field. Additionally, the Stack root can now be specified via the `--stack-root` command-line flag. See [#1148](https://github.com/commercialhaskell/stack/issues/1148). * `stack sig` GPG-related sub-commands were removed (folded into `upload` and `sdist`) * GPG signing of packages while uploading to Hackage is now the default. Use `upload --no-signature` if you would rather not contribute your package signature. If you don't yet have a GPG keyset, read this [blog post on GPG keys](https://fpcomplete.com/blog/2016/05/stack-security-gnupg-keys). We can add a `stack.yaml` config setting to disable signing if some people desire it. We hope that people will sign. Later we will be adding GPG signature verification options. * `stack build pkg-1.2.3` will now build even if the snapshot has a different package version - it is treated as an extra-dep. `stack build local-pkg-1.2.3` is an error even if the version number matches the local package [#2028](https://github.com/commercialhaskell/stack/issues/2028). * Having a `nix:` section no longer implies enabling nix build. This allows the user to globally configure whether nix is used (unless the project overrides the default explicitly). See [#1924](https://github.com/commercialhaskell/stack/issues/1924). * Remove deprecated valid-wanted field. * Docker: mount home directory in container [#1949](https://github.com/commercialhaskell/stack/issues/1949). * Deprecate `--local-bin-path` instead `--local-bin`. * `stack image`: allow absolute source paths for `add`. Other enhancements: * `stack haddock --open [PACKAGE]` opens the local haddocks in the browser. * Fix too much rebuilding when enabling/disabling profiling flags. * `stack build pkg-1.0` will now build `pkg-1.0` even if the snapshot specifies a different version (it introduces a temporary extra-dep) * Experimental support for `--split-objs` added [#1284](https://github.com/commercialhaskell/stack/issues/1284). * `git` packages with submodules are supported by passing the `--recursive` flag to `git clone`. * When using [Hpack](https://github.com/sol/hpack), only regenerate Cabal files when Hpack files change. * Hpack files can now be used in templates * `stack ghci` now runs ghci as a separate process [#1306](https://github.com/commercialhaskell/stack/issues/1306) * Retry when downloading snapshots and package indices * Many build options are configurable now in `stack.yaml`: ~~~yaml build: library-profiling: true executable-profiling: true haddock: true haddock-deps: true copy-bins: true prefetch: true force-dirty: true keep-going: true test: true test-arguments: rerun-tests: true additional-args: ['-fprof'] coverage: true no-run-tests: true bench: true benchmark-opts: benchmark-arguments: -O2 no-run-benchmarks: true reconfigure: true cabal-verbose: true ~~~ * A number of URLs are now configurable, useful for firewalls. See [#1794](https://github.com/commercialhaskell/stack/issues/1884). * Suggest causes when executables are missing. * Allow `--omit-packages` even without `--solver`. * Improve the generated `stack.yaml`. * Improve ghci results after :load Main module collision with main file path. * Only load the hackage index if necessary [#1883](https://github.com/commercialhaskell/stack/issues/1883), [#1892](https://github.com/commercialhaskell/stack/issues/1892). * init: allow local packages to be deps of deps [#1965](https://github.com/commercialhaskell/stack/issues/1965). * Always use full fingerprints from GPG [#1952](https://github.com/commercialhaskell/stack/issues/1952). * Default to using `gpg2` and fall back to `gpg` [#1976](https://github.com/commercialhaskell/stack/issues/1976). * Add a flag for --verbosity silent. * Add `haddock --open` flag [#1396](https://github.com/commercialhaskell/stack/issues/1396). Bug fixes: * Package tarballs would fail to unpack. [#1884](https://github.com/commercialhaskell/stack/issues/1884). * Fixed errant warnings about missing modules, after deleted and removed from Cabal file [#921](https://github.com/commercialhaskell/stack/issues/921) [#1805](https://github.com/commercialhaskell/stack/issues/1805). * Now considers a package to dirty when the Hpack file is changed [#1819](https://github.com/commercialhaskell/stack/issues/1819). * Nix: cancelling a Stack build now exits properly rather than dropping into a nix-shell [#1778](https://github.com/commercialhaskell/stack/issues/1778). * `allow-newer: true` now causes `--exact-configuration` to be passed to Cabal. See [#1579](https://github.com/commercialhaskell/stack/issues/1579). * `stack solver` no longer fails with `InvalidRelFile` for relative package paths including `..`. See [#1954](https://github.com/commercialhaskell/stack/issues/1954). * Ignore emacs lock files when finding Cabal files [#1897](https://github.com/commercialhaskell/stack/issues/1897). * Use lenient UTF-8 decode for build output [#1945](https://github.com/commercialhaskell/stack/issues/1945). * Clear index cache whenever index updated [#1962](https://github.com/commercialhaskell/stack/issues/1962). * Fix: Building a container image drops a .stack-work dir in the current working (sub)directory [#1975](https://github.com/commercialhaskell/stack/issues/1975). * Fix: Rebuilding when disabling profiling [#2023](https://github.com/commercialhaskell/stack/issues/2023). ## 1.0.4.3 - 2016-04-07 Bug fixes: * Don't delete contents of ~/.ssh when using `stack clean --full` with Docker enabled [#2000](https://github.com/commercialhaskell/stack/issues/2000) ## 1.0.4.2 - 2016-03-09 Build with `path-io-1.0.0`. There are no changes in behaviour from 1.0.4, so no binaries are released for this version. ## 1.0.4.1 - 2016-02-21 Fixes build with `aeson-0.11.0.0`. There are no changes in behaviour from 1.0.4, so no binaries are released for this version. ## 1.0.4 - 2016-02-20 Major changes: * Some notable changes in `stack init`: * Overall it should now be able to initialize almost all existing Cabal packages out of the box as long as the package itself is consistently defined. * Choose the best possible snapshot and add extra dependencies on top of a snapshot resolver rather than a compiler resolver - [#1583](https://github.com/commercialhaskell/stack/pull/1583) * Automatically omit a package (`--omit-packages`) when it is compiler incompatible or when there are packages with conflicting dependency requirements. See [#1674](https://github.com/commercialhaskell/stack/pull/1674). * Some more changes for a better user experience. Please refer to the doc guide for details. * Add support for Hpack, alternative package description format [#1679](https://github.com/commercialhaskell/stack/issues/1679) Other enhancements: * Docker: pass ~/.ssh and SSH auth socket into container, so that git repos work [#1358](https://github.com/commercialhaskell/stack/issues/1358). * Docker: strip suffix from docker --version. [#1653](https://github.com/commercialhaskell/stack/issues/1653) * Docker: pass USER and PWD environment variables into container. * On each run, Stack will test the Stack root directory (~/.stack), and the project and package work directories (.stack-work) for whether they are owned by the current user and abort if they are not. This precaution can be disabled with the `--allow-different-user` flag or `allow-different-user` option in the global config (~/.stack/config.yaml). [#471](https://github.com/commercialhaskell/stack/issues/471) * Added `stack clean --full` option for full working dir cleanup. * YAML config: support Zip archives. * Redownload build plan if parsing fails [#1702](https://github.com/commercialhaskell/stack/issues/1702). * Give mustache templates access to a 'year' tag [#1716](https://github.com/commercialhaskell/stack/pull/1716). * Have "stack ghci" warn about module name aliasing. * Add "stack ghci --load-local-deps". * Build Setup.hs with -rtsopts [#1687](https://github.com/commercialhaskell/stack/issues/1687). * `stack init` accepts a list of directories. * Add flag infos to DependencyPlanFailures (for better error output in case of flags) [#713](https://github.com/commercialhaskell/stack/issues/713) * `stack new --bare` complains for overwrites, and add `--force` option [#1597](https://github.com/commercialhaskell/stack/issues/1597). Bug fixes: * Previously, `stack ghci` would fail with `cannot satisfy -package-id` when the implicit build step changes the package key of some dependency. * Fix: Building with ghcjs: "ghc-pkg: Prelude.chr: bad argument: 2980338" [#1665](https://github.com/commercialhaskell/stack/issues/1665). * Fix running test / bench with `--profile` / `--trace`. * Fix: build progress counter is no longer visible [#1685](https://github.com/commercialhaskell/stack/issues/1685). * Use "-RTS" w/ profiling to allow extra args [#1772](https://github.com/commercialhaskell/stack/issues/1772). * Fix withUnpackedTarball7z to find name of srcDir after unpacking (fixes `stack setup` fails for ghcjs project on windows) [#1774](https://github.com/commercialhaskell/stack/issues/1774). * Add space before auto-generated bench opts (makes profiling options work uniformly for applications and benchmark suites) [#1771](https://github.com/commercialhaskell/stack/issues/1771). * Don't try to find plugin if it resembles flag. * Setup.hs changes cause package dirtiness [#1711](https://github.com/commercialhaskell/stack/issues/1711). * Send "stack templates" output to stdout [#1792](https://github.com/commercialhaskell/stack/issues/1792). ## 1.0.2 - 2016-01-18 Release notes: - Arch Linux: Stack has been adopted into the [official community repository](https://www.archlinux.org/packages/community/x86_64/stack/), so we will no longer be updating the AUR with new versions. See the [install/upgrade guide](http://docs.haskellstack.org/en/stable/install_and_upgrade/#arch-linux) for current download instructions. Major changes: - `stack init` and `solver` overhaul [#1583](https://github.com/commercialhaskell/stack/pull/1583) Other enhancements: - Disable locale/codepage hacks when GHC >=7.10.3 [#1552](https://github.com/commercialhaskell/stack/issues/1552) - Specify multiple images to build for `stack image container` [docs](http://docs.haskellstack.org/en/stable/yaml_configuration/#image) - Specify which executables to include in images for `stack image container` [docs](http://docs.haskellstack.org/en/stable/yaml_configuration/#image) - Docker: pass supplementary groups and umask into container - If git fetch fails wipe the directory and try again from scratch [#1418](https://github.com/commercialhaskell/stack/issues/1418) - Warn if newly installed executables won't be available on the PATH [#1362](https://github.com/commercialhaskell/stack/issues/1362) - `stack.yaml`: for `stack image container`, specify multiple images to generate, and which executables should be added to those images - GHCI: add interactive Main selection [#1068](https://github.com/commercialhaskell/stack/issues/1068) - Care less about the particular name of a GHCJS sdist folder [#1622](https://github.com/commercialhaskell/stack/issues/1622) - Unified Enable/disable help messaging [#1613](https://github.com/commercialhaskell/stack/issues/1613) Bug fixes: - Don't share precompiled packages between GHC/platform variants and Docker [#1551](https://github.com/commercialhaskell/stack/issues/1551) - Properly redownload corrupted downloads with the correct file size. [Mailing list discussion](https://groups.google.com/d/msg/haskell-stack/iVGDG5OHYxs/FjUrR5JsDQAJ) - Gracefully handle invalid paths in error/warning messages [#1561](https://github.com/commercialhaskell/stack/issues/1561) - Nix: select the correct GHC version corresponding to the snapshot even when an abstract resolver is passed via `--resolver` on the command-line. [#1641](https://github.com/commercialhaskell/stack/issues/1641) - Fix: Stack does not allow using an external package from ghci [#1557](https://github.com/commercialhaskell/stack/issues/1557) - Disable ambiguous global '--resolver' option for 'stack init' [#1531](https://github.com/commercialhaskell/stack/issues/1531) - Obey `--no-nix` flag - Fix: GHCJS Execute.hs: Non-exhaustive patterns in lambda [#1591](https://github.com/commercialhaskell/stack/issues/1591) - Send file-watch and sticky logger messages to stderr [#1302](https://github.com/commercialhaskell/stack/issues/1302) [#1635](https://github.com/commercialhaskell/stack/issues/1635) - Use globaldb path for querying Cabal version [#1647](https://github.com/commercialhaskell/stack/issues/1647) ## 1.0.0 - 2015-12-24 Release notes: * We're calling this version 1.0.0 in preparation for Stackage LTS 4. Note, however, that this does not mean the code's API will be stable as this is primarily an end-user tool. Enhancements: * Added flag `--profile` flag: passed with `stack build`, it will enable profiling, and for `--bench` and `--test` it will generate a profiling report by passing `+RTS -p` to the executable(s). Great for using like `stack build --bench --profile` (remember that enabling profile will slow down your benchmarks by >4x). Run `stack build --bench` again to disable the profiling and get proper speeds * Added flag `--trace` flag: just like `--profile`, it enables profiling, but instead of generating a report for `--bench` and `--test`, prints out a stack trace on exception. Great for using like `stack build --test --trace` * Nix: all options can be overridden on command line [#1483](https://github.com/commercialhaskell/stack/issues/1483) * Nix: build environments (shells) are now pure by default. * Make verbosity silent by default in script interpreter mode [#1472](https://github.com/commercialhaskell/stack/issues/1472) * Show a message when resetting git commit fails [#1453](https://github.com/commercialhaskell/stack/issues/1453) * Improve Unicode handling in project/package names [#1337](https://github.com/commercialhaskell/stack/issues/1337) * Fix ambiguity between a Stack command and a filename to execute (prefer `stack` subcommands) [#1471](https://github.com/commercialhaskell/stack/issues/1471) * Support multi line interpreter directive comments [#1394](https://github.com/commercialhaskell/stack/issues/1394) * Handle space separated pids in ghc-pkg dump (for GHC HEAD) [#1509](https://github.com/commercialhaskell/stack/issues/1509) * Add ghci --no-package-hiding option [#1517](https://github.com/commercialhaskell/stack/issues/1517) * `stack new` can download templates from URL [#1466](https://github.com/commercialhaskell/stack/issues/1466) Bug fixes: * Nix: `stack exec` options are passed properly to the Stack sub process [#1538](https://github.com/commercialhaskell/stack/issues/1538) * Nix: specifying a shell-file works in any current working directory [#1547](https://github.com/commercialhaskell/stack/issues/1547) * Nix: use `--resolver` argument * Docker: fix missing image message and '--docker-auto-pull' * No HTML escaping for "stack new" template params [#1475](https://github.com/commercialhaskell/stack/issues/1475) * Set permissions for generated .ghci script [#1480](https://github.com/commercialhaskell/stack/issues/1480) * Restrict commands allowed in interpreter mode [#1504](https://github.com/commercialhaskell/stack/issues/1504) * `stack ghci` doesn't see preprocessed files for executables [#1347](https://github.com/commercialhaskell/stack/issues/1347) * All test suites run even when only one is requested [#1550](https://github.com/commercialhaskell/stack/pull/1550) * Edge cases in broken templates give odd errors [#1535](https://github.com/commercialhaskell/stack/issues/1535) * Fix test coverage bug on windows ## 0.1.10.1 - 2015-12-13 Bug fixes: * `stack image container` did not actually build an image [#1473](https://github.com/commercialhaskell/stack/issues/1473) ## 0.1.10.0 - 2015-12-04 Release notes: * The Stack home page is now at [haskellstack.org](http://haskellstack.org), which shows the documentation rendered by readthedocs.org. Note: this has necessitated some changes to the links in the documentation's markdown source code, so please check the links on the website before submitting a PR to fix them. * The locations of the [Ubuntu](http://docs.haskellstack.org/en/stable/install_and_upgrade/#ubuntu) and [Debian](http://docs.haskellstack.org/en/stable/install_and_upgrade/#debian) package repositories have changed to have correct URL semantics according to Debian's guidelines [#1378](https://github.com/commercialhaskell/stack/issues/1378). The old locations will continue to work for some months, but we suggest that you adjust your `/etc/apt/sources.list.d/fpco.list` to the new location to avoid future disruption. * [openSUSE and SUSE Linux Enterprise](http://docs.haskellstack.org/en/stable/install_and_upgrade/#suse) packages are now available, thanks to [@mimi1vx](https://github.com/mimi1vx). Note: there will be some lag before these pick up new versions, as they are based on Stackage LTS. Major changes: * Support for building inside a Nix-shell providing system dependencies [#1285](https://github.com/commercialhaskell/stack/pull/1285) * Add optional GPG signing on `stack upload --sign` or with `stack sig sign ...` Other enhancements: * Print latest applicable version of packages on conflicts [#508](https://github.com/commercialhaskell/stack/issues/508) * Support for packages located in Mercurial repositories [#1397](https://github.com/commercialhaskell/stack/issues/1397) * Only run benchmarks specified as build targets [#1412](https://github.com/commercialhaskell/stack/issues/1412) * Support git-style executable fall-through (`stack something` executes `stack-something` if present) [#1433](https://github.com/commercialhaskell/stack/issues/1433) * GHCi now loads intermediate dependencies [#584](https://github.com/commercialhaskell/stack/issues/584) * `--work-dir` option for overriding `.stack-work` [#1178](https://github.com/commercialhaskell/stack/issues/1178) * Support `detailed-0.9` tests [#1429](https://github.com/commercialhaskell/stack/issues/1429) * Docker: improved POSIX signal proxying to containers [#547](https://github.com/commercialhaskell/stack/issues/547) Bug fixes: * Show absolute paths in error messages in multi-package builds [#1348](https://github.com/commercialhaskell/stack/issues/1348) * Docker-built binaries and libraries in different path [#911](https://github.com/commercialhaskell/stack/issues/911) [#1367](https://github.com/commercialhaskell/stack/issues/1367) * Docker: `--resolver` argument didn't effect selected image tag * GHCi: Spaces in filepaths caused module loading issues [#1401](https://github.com/commercialhaskell/stack/issues/1401) * GHCi: cpp-options in Cabal files weren't used [#1419](https://github.com/commercialhaskell/stack/issues/1419) * Benchmarks couldn't be run independently of each other [#1412](https://github.com/commercialhaskell/stack/issues/1412) * Send output of building setup to stderr [#1410](https://github.com/commercialhaskell/stack/issues/1410) ## 0.1.8.0 - 2015-11-20 Major changes: * GHCJS can now be used with stackage snapshots via the new `compiler` field. * Windows installers are now available: [download them here](http://docs.haskellstack.org/en/stable/install_and_upgrade/#windows) [#613](https://github.com/commercialhaskell/stack/issues/613) * Docker integration works with non-FPComplete generated images [#531](https://github.com/commercialhaskell/stack/issues/531) Other enhancements: * Added an `allow-newer` config option [#922](https://github.com/commercialhaskell/stack/issues/922) [#770](https://github.com/commercialhaskell/stack/issues/770) * When a Hackage revision invalidates a build plan in a snapshot, trust the snapshot [#770](https://github.com/commercialhaskell/stack/issues/770) * Added a `stack config set resolver RESOLVER` command. Part of work on [#115](https://github.com/commercialhaskell/stack/issues/115) * `stack setup` can now install GHCJS on windows. See [#1145](https://github.com/commercialhaskell/stack/issues/1145) and [#749](https://github.com/commercialhaskell/stack/issues/749) * `stack hpc report` command added, which generates reports for HPC tix files * `stack ghci` now accepts all the flags accepted by `stack build`. See [#1186](https://github.com/commercialhaskell/stack/issues/1186) * `stack ghci` builds the project before launching GHCi. If the build fails, try to launch GHCi anyway. Use `stack ghci --no-build` option to disable [#1065](https://github.com/commercialhaskell/stack/issues/1065) * `stack ghci` now detects and warns about various circumstances where it is liable to fail. See [#1270](https://github.com/commercialhaskell/stack/issues/1270) * Added `require-docker-version` configuration option * Packages will now usually be built along with their tests and benchmarks. See [#1166](https://github.com/commercialhaskell/stack/issues/1166) * Relative `local-bin-path` paths will be relative to the project's root directory, not the current working directory. [#1340](https://github.com/commercialhaskell/stack/issues/1340) * `stack clean` now takes an optional `[PACKAGE]` argument for use in multi-package projects. See [#583](https://github.com/commercialhaskell/stack/issues/583) * Ignore cabal_macros.h as a dependency [#1195](https://github.com/commercialhaskell/stack/issues/1195) * Pad timestamps and show local time in --verbose output [#1226](https://github.com/commercialhaskell/stack/issues/1226) * GHCi: Import all modules after loading them [#995](https://github.com/commercialhaskell/stack/issues/995) * Add subcommand aliases: `repl` for `ghci`, and `runhaskell` for `runghc` [#1241](https://github.com/commercialhaskell/stack/issues/1241) * Add typo recommendations for unknown package identifiers [#158](https://github.com/commercialhaskell/stack/issues/158) * Add `stack path --local-hpc-root` option * Overhaul dependencies' haddocks copying [#1231](https://github.com/commercialhaskell/stack/issues/1231) * Support for extra-package-dbs in 'stack ghci' [#1229](https://github.com/commercialhaskell/stack/pull/1229) * `stack new` disallows package names with "words" consisting solely of numbers [#1336](https://github.com/commercialhaskell/stack/issues/1336) * `stack build --fast` turns off optimizations * Show progress while downloading package index [#1223](https://github.com/commercialhaskell/stack/issues/1223). Bug fixes: * Fix: Haddocks not copied for dependencies [#1105](https://github.com/commercialhaskell/stack/issues/1105) * Fix: Global options did not work consistently after subcommand [#519](https://github.com/commercialhaskell/stack/issues/519) * Fix: 'stack ghci' doesn't notice that a module got deleted [#1180](https://github.com/commercialhaskell/stack/issues/1180) * Rebuild when Cabal file is changed * Fix: Paths in GHC warnings not canonicalized, nor those for packages in subdirectories or outside the project root [#1259](https://github.com/commercialhaskell/stack/issues/1259) * Fix: unlisted files in tests and benchmarks trigger extraneous second build [#838](https://github.com/commercialhaskell/stack/issues/838) ## 0.1.6.0 - 2015-10-15 Major changes: * `stack setup` now supports building and booting GHCJS from source tarball. * On Windows, build directories no longer display "pretty" information (like x86_64-windows/Cabal-1.22.4.0), but rather a hash of that content. The reason is to avoid the 260 character path limitation on Windows. See [#1027](https://github.com/commercialhaskell/stack/pull/1027) * Rename config files and clarify their purposes [#969](https://github.com/commercialhaskell/stack/issues/969) * `~/.stack/stack.yaml` --> `~/.stack/config.yaml` * `~/.stack/global` --> `~/.stack/global-project` * `/etc/stack/config` --> `/etc/stack/config.yaml` * Old locations still supported, with deprecation warnings * New command "stack eval CODE", which evaluates to "stack exec ghc -- -e CODE". Other enhancements: * No longer install `git` on Windows [#1046](https://github.com/commercialhaskell/stack/issues/1046). You can still get this behavior by running the following yourself: `stack exec -- pacman -Sy --noconfirm git`. * Typing enter during --file-watch triggers a rebuild [#1023](https://github.com/commercialhaskell/stack/pull/1023) * Use Haddock's `--hyperlinked-source` (crosslinked source), if available [#1070](https://github.com/commercialhaskell/stack/pull/1070) * Use Stack-installed GHCs for `stack init --solver` [#1072](https://github.com/commercialhaskell/stack/issues/1072) * New experimental `stack query` command [#1087](https://github.com/commercialhaskell/stack/issues/1087) * By default, Stack no longer rebuilds a package due to GHC options changes. This behavior can be tweaked with the `rebuild-ghc-options` setting. [#1089](https://github.com/commercialhaskell/stack/issues/1089) * By default, ghc-options are applied to all local packages, not just targets. This behavior can be tweaked with the `apply-ghc-options` setting. [#1089](https://github.com/commercialhaskell/stack/issues/1089) * Docker: download or override location of Stack executable to re-run in container [#974](https://github.com/commercialhaskell/stack/issues/974) * Docker: when Docker Engine is remote, don't run containerized processes as host's UID/GID [#194](https://github.com/commercialhaskell/stack/issues/194) * Docker: `set-user` option to enable/disable running containerized processes as host's UID/GID [#194](https://github.com/commercialhaskell/stack/issues/194) * Custom Setup.hs files are now precompiled instead of interpreted. This should be a major performance win for certain edge cases (biggest example: [building Cabal itself](https://github.com/commercialhaskell/stack/issues/1041)) while being either neutral or a minor slowdown for more common cases. * `stack test --coverage` now also generates a unified coverage report for multiple test-suites / packages. In the unified report, test-suites can contribute to the coverage of other packages. Bug fixes: * Ignore stack-built executables named `ghc` [#1052](https://github.com/commercialhaskell/stack/issues/1052) * Fix quoting of output failed command line arguments * Mark executable-only packages as installed when copied from cache [#1043](https://github.com/commercialhaskell/stack/pull/1043) * Canonicalize temporary directory paths [#1047](https://github.com/commercialhaskell/stack/pull/1047) * Put code page fix inside the build function itself [#1066](https://github.com/commercialhaskell/stack/issues/1066) * Add `explicit-setup-deps` option [#1110](https://github.com/commercialhaskell/stack/issues/1110), and change the default to the old behavior of using any package in the global and snapshot database [#1025](https://github.com/commercialhaskell/stack/issues/1025) * Precompiled cache checks full package IDs on Cabal < 1.22 [#1103](https://github.com/commercialhaskell/stack/issues/1103) * Pass -package-id to ghci [#867](https://github.com/commercialhaskell/stack/issues/867) * Ignore global packages when copying precompiled packages [#1146](https://github.com/commercialhaskell/stack/issues/1146) ## 0.1.5.0 - 2015-09-24 Major changes: * On Windows, we now use a full MSYS2 installation in place of the previous PortableGit. This gives you access to the pacman package manager for more easily installing libraries. * Support for custom GHC binary distributions [#530](https://github.com/commercialhaskell/stack/issues/530) * `ghc-variant` option in `stack.yaml` to specify the variant (also `--ghc-variant` command-line option) * `setup-info` in `stack.yaml`, to specify where to download custom binary distributions (also `--ghc-bindist` command-line option) * Note: On systems with libgmp4 (aka `libgmp.so.3`), such as CentOS 6, you may need to re-run `stack setup` due to the centos6 GHC bindist being treated like a variant * A new `--pvp-bounds` flag to the sdist and upload commands allows automatic adding of PVP upper and/or lower bounds to your dependencies Other enhancements: * Adapt to upcoming Cabal installed package identifier format change [#851](https://github.com/commercialhaskell/stack/issues/851) * `stack setup` takes a `--stack-setup-yaml` argument * `--file-watch` is more discerning about which files to rebuild for [#912](https://github.com/commercialhaskell/stack/issues/912) * `stack path` now supports `--global-pkg-db` and `--ghc-package-path` * `--reconfigure` flag [#914](https://github.com/commercialhaskell/stack/issues/914) [#946](https://github.com/commercialhaskell/stack/issues/946) * Cached data is written with a checksum of its structure [#889](https://github.com/commercialhaskell/stack/issues/889) * Fully removed `--optimizations` flag * Added `--cabal-verbose` flag * Added `--file-watch-poll` flag for polling instead of using filesystem events (useful for running tests in a Docker container while modifying code in the host environment. When code is injected into the container via a volume, the container won't propagate filesystem events). * Give a preemptive error message when `-prof` is given as a GHC option [#1015](https://github.com/commercialhaskell/stack/issues/1015) * Locking is now optional, and will be turned on by setting the `STACK_LOCK` environment variable to `true` [#950](https://github.com/commercialhaskell/stack/issues/950) * Create default `stack.yaml` with documentation comments and commented out options [#226](https://github.com/commercialhaskell/stack/issues/226) * Out of memory warning if Cabal exits with -9 [#947](https://github.com/commercialhaskell/stack/issues/947) Bug fixes: * Hacky workaround for optparse-applicative issue with `stack exec --help` [#806](https://github.com/commercialhaskell/stack/issues/806) * Build executables for local extra deps [#920](https://github.com/commercialhaskell/stack/issues/920) * copyFile can't handle directories [#942](https://github.com/commercialhaskell/stack/pull/942) * Support for spaces in Haddock interface files [fpco/minghc#85](https://github.com/fpco/minghc/issues/85) * Temporarily building against a "shadowing" local package? [#992](https://github.com/commercialhaskell/stack/issues/992) * Fix `Setup.exe` name for `--upgrade-cabal` on Windows [#1002](https://github.com/commercialhaskell/stack/issues/1002) * Unlisted dependencies no longer trigger extraneous second build [#838](https://github.com/commercialhaskell/stack/issues/838) ## 0.1.4.1 - 2015-09-04 Fix stack's own Haddocks. No changes to functionality (only comments updated). ## 0.1.4.0 - 2015-09-04 Major changes: * You now have more control over how GHC versions are matched, e.g. "use exactly this version," "use the specified minor version, but allow patches," or "use the given minor version or any later minor in the given major release." The default has switched from allowing newer later minor versions to a specific minor version allowing patches. For more information, see [#736](https://github.com/commercialhaskell/stack/issues/736) and [#784](https://github.com/commercialhaskell/stack/pull/784). * Support added for compiling with GHCJS * Stack can now reuse prebuilt binaries between snapshots. That means that, if you build package foo in LTS-3.1, that binary version can be reused in LTS-3.2, assuming it uses the same dependencies and flags. [#878](https://github.com/commercialhaskell/stack/issues/878) Other enhancements: * Added the `--docker-env` argument, to set environment variables in Docker container. * Set locale environment variables to UTF-8 encoding for builds to avoid "commitBuffer: invalid argument" errors from GHC [#793](https://github.com/commercialhaskell/stack/issues/793) * Enable transliteration for encoding on stdout and stderr [#824](https://github.com/commercialhaskell/stack/issues/824) * By default, `stack upgrade` automatically installs GHC as necessary [#797](https://github.com/commercialhaskell/stack/issues/797) * Added the `ghc-options` field to `stack.yaml` [#796](https://github.com/commercialhaskell/stack/issues/796) * Added the `extra-path` field to `stack.yaml` * Code page changes on Windows only apply to the build command (and its synonyms), and can be controlled via a command line flag (still defaults to on) [#757](https://github.com/commercialhaskell/stack/issues/757) * Implicitly add packages to extra-deps when a flag for them is set [#807](https://github.com/commercialhaskell/stack/issues/807) * Use a precompiled Setup.hs for simple build types [#801](https://github.com/commercialhaskell/stack/issues/801) * Set --enable-tests and --enable-benchmarks optimistically [#805](https://github.com/commercialhaskell/stack/issues/805) * `--only-configure` option added [#820](https://github.com/commercialhaskell/stack/issues/820) * Check for duplicate local package names * Stop nagging people that call `stack test` [#845](https://github.com/commercialhaskell/stack/issues/845) * `--file-watch` will ignore files that are in your VCS boring/ignore files [#703](https://github.com/commercialhaskell/stack/issues/703) * Add `--numeric-version` option Bug fixes: * `stack init --solver` fails if `GHC_PACKAGE_PATH` is present [#860](https://github.com/commercialhaskell/stack/issues/860) * `stack solver` and `stack init --solver` check for test suite and benchmark dependencies [#862](https://github.com/commercialhaskell/stack/issues/862) * More intelligent logic for setting UTF-8 locale environment variables [#856](https://github.com/commercialhaskell/stack/issues/856) * Create missing directories for `stack sdist` * Don't ignore Cabal files with extra periods [#895](https://github.com/commercialhaskell/stack/issues/895) * Deprecate unused `--optimizations` flag * Truncated output on slow terminals [#413](https://github.com/commercialhaskell/stack/issues/413) ## 0.1.3.1 - 2015-08-12 Bug fixes: * Ignore disabled executables [#763](https://github.com/commercialhaskell/stack/issues/763) ## 0.1.3.0 - 2015-08-12 Major changes: * Detect when a module is compiled but not listed in the Cabal file ([#32](https://github.com/commercialhaskell/stack/issues/32)) * A warning is displayed for any modules that should be added to `other-modules` in the Cabal file * These modules are taken into account when determining whether a package needs to be built * Respect TemplateHaskell addDependentFile dependency changes ([#105](https://github.com/commercialhaskell/stack/issues/105)) * TH dependent files are taken into account when determining whether a package needs to be built. * Overhauled target parsing, added `--test` and `--bench` options [#651](https://github.com/commercialhaskell/stack/issues/651) * For details, see [Build commands documentation](http://docs.haskellstack.org/en/stable/build_command/) Other enhancements: * Set the `HASKELL_DIST_DIR` environment variable [#524](https://github.com/commercialhaskell/stack/pull/524) * Track build status of tests and benchmarks [#525](https://github.com/commercialhaskell/stack/issues/525) * `--no-run-tests` [#517](https://github.com/commercialhaskell/stack/pull/517) * Targets outside of root dir don't build [#366](https://github.com/commercialhaskell/stack/issues/366) * Upper limit on number of flag combinations to test [#543](https://github.com/commercialhaskell/stack/issues/543) * Fuzzy matching support to give better error messages for close version numbers [#504](https://github.com/commercialhaskell/stack/issues/504) * `--local-bin-path` global option. Use to change where binaries get placed on a `--copy-bins` [#342](https://github.com/commercialhaskell/stack/issues/342) * Custom snapshots [#111](https://github.com/commercialhaskell/stack/issues/111) * --force-dirty flag: Force treating all local packages as having dirty files (useful for cases where Stack can't detect a file change) * GHC error messages: display file paths as absolute instead of relative for better editor integration * Add the `--copy-bins` option [#569](https://github.com/commercialhaskell/stack/issues/569) * Give warnings on unexpected config keys [#48](https://github.com/commercialhaskell/stack/issues/48) * Remove Docker `pass-host` option * Don't require `cabal-install` to upload [#313](https://github.com/commercialhaskell/stack/issues/313) * Generate indexes for all deps and all installed snapshot packages [#143](https://github.com/commercialhaskell/stack/issues/143) * Provide `--resolver global` option [#645](https://github.com/commercialhaskell/stack/issues/645) * Also supports `--resolver nightly`, `--resolver lts`, and `--resolver lts-X` * Make `stack build --flag` error when flag or package is unknown [#617](https://github.com/commercialhaskell/stack/issues/617) * Preserve file permissions when unpacking sources [#666](https://github.com/commercialhaskell/stack/pull/666) * `stack build` etc work outside of a project * `list-dependencies` command [#638](https://github.com/commercialhaskell/stack/issues/638) * `--upgrade-cabal` option to `stack setup` [#174](https://github.com/commercialhaskell/stack/issues/174) * `--exec` option [#651](https://github.com/commercialhaskell/stack/issues/651) * `--only-dependencies` implemented correctly [#387](https://github.com/commercialhaskell/stack/issues/387) Bug fixes: * Extensions from the `other-extensions` field no longer enabled by default [#449](https://github.com/commercialhaskell/stack/issues/449) * Fix: haddock forces rebuild of empty packages [#452](https://github.com/commercialhaskell/stack/issues/452) * Don't copy over executables excluded by component selection [#605](https://github.com/commercialhaskell/stack/issues/605) * Fix: Stack fails on Windows with git package in `stack.yaml` and no git binary on path [#712](https://github.com/commercialhaskell/stack/issues/712) * Fixed GHCi issue: Specifying explicit package versions (#678) * Fixed GHCi issue: Specifying -odir and -hidir as .stack-work/odir (#529) * Fixed GHCi issue: Specifying A instead of A.ext for modules (#498) ## 0.1.2.0 - 2015-07-05 * Add `--prune` flag to `stack dot` [#487](https://github.com/commercialhaskell/stack/issues/487) * Add `--[no-]external`,`--[no-]include-base` flags to `stack dot` [#437](https://github.com/commercialhaskell/stack/issues/437) * Add `--ignore-subdirs` flag to init command [#435](https://github.com/commercialhaskell/stack/pull/435) * Handle attempt to use non-existing resolver [#436](https://github.com/commercialhaskell/stack/pull/436) * Add `--force` flag to `init` command * exec style commands accept the `--package` option (see [Reddit discussion](http://www.reddit.com/r/haskell/comments/3bd66h/stack_runghc_turtle_as_haskell_script_solution/)) * `stack upload` without arguments doesn't do anything [#439](https://github.com/commercialhaskell/stack/issues/439) * Print latest version of packages on conflicts [#450](https://github.com/commercialhaskell/stack/issues/450) * Flag to avoid rerunning tests that haven't changed [#451](https://github.com/commercialhaskell/stack/issues/451) * Stack can act as a script interpreter (see [Script interpreter] (https://github.com/commercialhaskell/stack/wiki/Script-interpreter) and [Reddit discussion](http://www.reddit.com/r/haskell/comments/3bd66h/stack_runghc_turtle_as_haskell_script_solution/)) * Add the __`--file-watch`__ flag to auto-rebuild on file changes [#113](https://github.com/commercialhaskell/stack/issues/113) * Rename `stack docker exec` to `stack exec --plain` * Add the `--skip-msys` flag [#377](https://github.com/commercialhaskell/stack/issues/377) * `--keep-going`, turned on by default for tests and benchmarks [#478](https://github.com/commercialhaskell/stack/issues/478) * `concurrent-tests: BOOL` [#492](https://github.com/commercialhaskell/stack/issues/492) * Use hashes to check file dirtiness [#502](https://github.com/commercialhaskell/stack/issues/502) * Install correct GHC build on systems with libgmp.so.3 [#465](https://github.com/commercialhaskell/stack/issues/465) * `stack upgrade` checks version before upgrading [#447](https://github.com/commercialhaskell/stack/issues/447) ## 0.1.1.0 - 2015-06-26 * Remove GHC uncompressed tar file after installation [#376](https://github.com/commercialhaskell/stack/issues/376) * Put stackage snapshots JSON on S3 [#380](https://github.com/commercialhaskell/stack/issues/380) * Specifying flags for multiple packages [#335](https://github.com/commercialhaskell/stack/issues/335) * single test suite failure should show entire log [#388](https://github.com/commercialhaskell/stack/issues/388) * valid-wanted is a confusing option name [#386](https://github.com/commercialhaskell/stack/issues/386) * `stack init` in multi-package project should use local packages for dependency checking [#384](https://github.com/commercialhaskell/stack/issues/384) * Display information on why a snapshot was rejected [#381](https://github.com/commercialhaskell/stack/issues/381) * Give a reason for unregistering packages [#389](https://github.com/commercialhaskell/stack/issues/389) * `stack exec` accepts the `--no-ghc-package-path` parameter * Don't require build plan to upload [#400](https://github.com/commercialhaskell/stack/issues/400) * Specifying test components only builds/runs those tests [#398](https://github.com/commercialhaskell/stack/issues/398) * `STACK_EXE` environment variable * Add the `stack dot` command * `stack upgrade` added [#237](https://github.com/commercialhaskell/stack/issues/237) * `--stack-yaml` command line flag [#378](https://github.com/commercialhaskell/stack/issues/378) * `--skip-ghc-check` command line flag [#423](https://github.com/commercialhaskell/stack/issues/423) Bug fixes: * Haddock links to global packages no longer broken on Windows [#375](https://github.com/commercialhaskell/stack/issues/375) * Make flags case-insensitive [#397](https://github.com/commercialhaskell/stack/issues/397) * Mark packages uninstalled before rebuilding [#365](https://github.com/commercialhaskell/stack/issues/365) ## 0.1.0.0 - 2015-06-23 * Fall back to Cabal dependency solver when a snapshot can't be found * Basic implementation of `stack new` [#137](https://github.com/commercialhaskell/stack/issues/137) * `stack solver` command [#364](https://github.com/commercialhaskell/stack/issues/364) * `stack path` command [#95](https://github.com/commercialhaskell/stack/issues/95) * Haddocks [#143](https://github.com/commercialhaskell/stack/issues/143): * Build for dependencies * Use relative links * Generate module contents and index for all packages in project ## 0.0.3 - 2015-06-17 * `--prefetch` [#297](https://github.com/commercialhaskell/stack/issues/297) * `upload` command ported from stackage-upload [#225](https://github.com/commercialhaskell/stack/issues/225) * `--only-snapshot` [#310](https://github.com/commercialhaskell/stack/issues/310) * `--resolver` [#224](https://github.com/commercialhaskell/stack/issues/224) * `stack init` [#253](https://github.com/commercialhaskell/stack/issues/253) * `--extra-include-dirs` and `--extra-lib-dirs` [#333](https://github.com/commercialhaskell/stack/issues/333) * Specify intra-package target [#201](https://github.com/commercialhaskell/stack/issues/201) ## 0.0.2 - 2015-06-14 * Fix some Windows specific bugs [#216](https://github.com/commercialhaskell/stack/issues/216) * Improve output for package index updates [#227](https://github.com/commercialhaskell/stack/issues/227) * Automatically update indices as necessary [#227](https://github.com/commercialhaskell/stack/issues/227) * --verbose flag [#217](https://github.com/commercialhaskell/stack/issues/217) * Remove packages (HTTPS and Git) [#199](https://github.com/commercialhaskell/stack/issues/199) * Config values for system-ghc and install-ghc * Merge `stack deps` functionality into `stack build` * `install` command [#153](https://github.com/commercialhaskell/stack/issues/153) and [#272](https://github.com/commercialhaskell/stack/issues/272) * overriding architecture value (useful to force 64-bit GHC on Windows, for example) * Overhauled test running (allows cycles, avoids unnecessary recompilation, etc) ## 0.0.1 - 2015-06-09 * First public release, beta quality stack-2.9.3.1/doc/CI.md0000644000000000000000000000106514353310533012543 0ustar0000000000000000
# Continuous integration (CI) ## GitHub Actions The Stack repository uses GitHub Actions for its own CI. For further information, see the guide to [contributing](CONTRIBUTING.md#continuous-integration-ci). ## Azure For further information, see the [Azure CI](azure_ci.md) documentation. ## Travis For further information, see the [Travis CI](travis_ci.md) documentation. stack-2.9.3.1/doc/clean_command.md0000644000000000000000000000103014353310533015020 0ustar0000000000000000
# The `stack clean` command Either ~~~text stack clean [PACKAGE] ~~~ or ~~~text stack clean --full ~~~ `stack clean` deletes build artefacts for one or more project packages specified as arguments. If no project packages are specified, all project packages are cleaned. `stack clean --full` deletes the project's Stack working directory. stack-2.9.3.1/doc/config_command.md0000644000000000000000000000747114445022466015231 0ustar0000000000000000
# The `stack config` commands ~~~text stack config COMMAND Available commands: env Print environment variables for use in a shell set Sets a key in YAML configuration file to value ~~~ The `stack config` commands provide assistance with accessing or modifying Stack's configuration. See `stack config` for the available commands. ## The `stack config env` command ~~~text stack config env [--[no-]locals] [--[no-]ghc-package-path] [--[no-]stack-exe] [--[no-]locale-utf8] [--[no-]keep-ghc-rts] ~~~ `stack config env` outputs a script that sets or unsets environment variables for a Stack environment. Flags modify the script that is output: * `--[no-]locals` (enabled by default) include/exclude local package information * `--[no-]ghc-package-path` (enabled by default) set `GHC_PACKAGE_PATH` environment variable or not * `--[no-]stack-exe` (enabled by default) set `STACK_EXE` environment variable or not * `--[no-]locale-utf8` (disabled by default) set the `GHC_CHARENC` environment variable to `UTF-8` or not * `--[no-]keep-ghc-rts` (disabled by default) keep/discard any `GHCRTS` environment variable ## The `stack config set` commands ~~~text stack config set COMMAND Available commands: install-ghc Configure whether Stack should automatically install GHC when necessary. package-index Configure Stack's package index resolver Change the resolver of the current project. system-ghc Configure whether Stack should use a system GHC installation or not. ~~~ The `stack config set` commands allow the values of keys in YAML configuration files to be set. See `stack config set` for the available keys. ## The `stack config set install-ghc` command ~~~text stack config set install-ghc [--global] true|false ~~~ `stack config set install-ghc true` or `false` sets the `install-ghc` key in a YAML configuration file, accordingly. By default, the project-level configuration file (`stack.yaml`) 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) ~~~text stack config set package-index download-prefix [--global] [URL] ~~~ `stack config set package-index download-prefix ` sets the `download-prefix` key of the `package-index` key in a YAML configuration file, accordingly. By default, the project-level configuration file (`stack.yaml`) is altered. The `--global` flag specifies the user-specific global configuration file (`config.yaml`). ## The `stack config set resolver` command ~~~text stack config set resolver SNAPSHOT ~~~ `stack config set resolver ` sets the `resolver` key in the project-level configuration file (`stack.yaml`). A snapshot of `lts` or `nightly` will be translated into the most recent available. A snapshot of `lts-19` will be translated into the most recent available in the `lts-19` sequence. Known bug: * The command does not respect the presence of a `snapshot` key. ## The `stack config set system-ghc` command ~~~text stack config set system-ghc [--global] true|false ~~~ `stack config set system-ghc true` or `false` sets the `system-ghc` key in a YAML configuration file, accordingly. By default, the project-level configuration file (`stack.yaml`) is altered. The `--global` flag specifies the user-specific global configuration file (`config.yaml`). stack-2.9.3.1/doc/CONTRIBUTING.md0000644000000000000000000005202214445022466014165 0ustar0000000000000000# Contributors Guide Thank you for considering contributing to the maintenance or development of Stack, or otherwise supporting users of Stack! We hope that the following information will encourage and assist you. We start with some advice about Stack's goals and governance, and approach to supporting users. ## Stack's goals Stack's current goals are: * To provide easy to use tooling for Haskell development * To provide complete support for at least the following three development environments: Linux, macOS, and Windows * To address the needs of industrial users, open source maintainers, and other people * To focus on the 'curated package set' use case * To prioritize reproducible build plans The goals above are not set in stone. However, any major changes to them should involve significant public discussion and a public vote by the Stack maintainer team. ## Stack's governance People involved in maintaining or developing Stack with rights to make commits to the repository can be classified into two groups: 'committers' and 'maintainers'. ### Stack's committers We encourages a wide range of people to be granted rights to make commits to the repository. People are encouraged to take initiative to make non-controversial changes, such as documentation improvements, bug fixes, performance improvements, and feature enhancements. Maintainers should be included in discussions of controversial changes and tricky code changes. Our general approach is **"it's easier to ask forgiveness than permission"**. If there is ever a bad change, it can always be rolled back. ### Stack's maintainers Stack's maintainers are long-term contributors to the project. Michael Snoyman (@snoyberg) was the founder of Stack, and its initial maintainer - and he has added others. Michael's current interests and priorities mean that he is no longer actively involved in adding new features to Stack. Maintainers are recognized for their contributions including: * Direct code contribution * Review of pull requests * Interactions on the GitHub issue tracker * Documentation management * External support - for example, hosting or training The maintainer team make certain decisions when that is necessary, specifically: * How to proceed, if there is disagreement on how to do so on a specific topic * Whether to add or remove (see further below) a maintainer Generally, maintainers are only removed due to non-participation or actions unhealthy to the project. Removal due to non-participation is not a punishment, simply a recognition that maintainership is for active participants only. We hope that removal due to unhealthy actions will never be necessary, but would include protection for cases of: * Disruptive behavior in public channels related to Stack * Impairing the codebase through bad commits/merges Like committers, maintainers are broadly encouraged to make autonomous decisions. Each maintainer is empowered to make a unilateral decision. However, maintainers should favor getting consensus first if: * They are uncertain what is the best course of action * They anticipate that other maintainers or users of Stack will disagree on the decision ## Stack's support A large part of the general discussion around Stack is on support-related topics, and that is reflected in the current issue tracker content. Assistance in responding to such matters is greatly appreciated. While support-related matters can be posted here as an 'issue', we encourage the use of other forums, in particular [Haskell's Discourse](https://discourse.haskell.org/). We also recommend Haskell's Discourse for general discussions about Stack's current or desired features. Stack is also discussed on Reddit's [Haskell community](https://www.reddit.com/r/haskell/). We encourage use of those other forums because support-related discussions can clog up the issue tracker and make it more difficult to maintain the project. People needing support may also get a faster and fuller response on other forums. Additions to the issue tracker are better suited to concrete feature proposals, bug reports, and other code base discussions (for example, refactorings). ## Bug Reports Please [open an issue](https://github.com/commercialhaskell/stack/issues/new) and use the provided template to include all necessary details. The more detailed your report, the faster it can be resolved and will ensure it is resolved in the right way. Once your bug has been resolved, the responsible person will tag the issue as _Needs confirmation_ and assign the issue back to you. Once you have tested and confirmed that the issue is resolved, close the issue. If you are not a member of the project, you will be asked for confirmation and we will close it. ## Documentation Consistent with its goal of being easy to use, Stack aims to maintain a high quality of in-tool and online documentation. The in-tool documentation includes the output when the `--help` flag is specified and the content of Stack's warning and error messages. When drafting documentation it is helpful to have in mind the intended reader and what they are assumed to know, and not know, already. In that regard, documentation should aim to meet, at least, the needs of a person who is about to begin to study computing as an undergraduate but who has not previously coded using Haskell. That person may be familiar with one popular operating system but may not be familiar with others. The files which make up Stack's online documentation are located in the `doc` directory of the repository. They are formatted in the [Markdown syntax](https://daringfireball.net/projects/markdown/), with some extensions. Those files are rendered on [haskellstack.org](http://haskellstack.org) by [Read the Docs](https://readthedocs.org/) using [MkDocs](https://www.mkdocs.org/) and the [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) theme. The `stable` branch of the repository provides the 'stable' version of the online documentation. The `master` branch provides the 'latest' version of the documentation. The 'stable' version of the online documentation is intended to be applicable to the latest released version of Stack. If you would like to help with that documentation, please submit a [pull request](https://help.github.com/articles/using-pull-requests/) with your changes/additions based off the [stable branch](https://github.com/commercialhaskell/stack/tree/stable). The Markdown files are organised into the navigation menu (the table of contents) in the file `mkdocs.yml`, the configuration file for MkDocs. The description of a file in the menu can differ from the file's name. The navigation menu allows files to be organised in a hierarchy. Currently, up to three levels are used. The top level is: * **Welcome!:** The introduction to Stack. This page aims to be no longer than necessary but also to not assume much existing knowledge on the part of the reader. It provides a 'quick start' guide to getting and using Stack. * **How to get & use Stack:** This includes Stack's user's guide, answers to frequently asked questions, and more thorough explanations of aspects of Stack. The user's guide is divided into two parts. The first part is 'introductory', and has the style of a tutorial. The second part is 'advanced', and has more of a reference style. * **How Stack works (advanced):** Many users will not need to consult this advanced documentation. * **Stack's code (advanced):** Other information useful to people contributing to, or maintaining, Stack's code, documentation, and other files. * **Signing key:** How Stack's released executables are signed. * **Glossary:** A glossary of terms used throughout Stack's in-tool and online documentation. We aim to describe the same things in the same way in different places. * **Version history:** The log of changes to Stack between versions. The specific versions of the online documentation (eg `v: v2.9.1`) are generated from the content of files at the point in the repository's history specified by the corresponding release tag. Consequently, that content is fixed once released. If the names of Markdown files do not change between versions, then people can use the flyout on the online documentation to move between different versions of the same page. For that reason, the names of new Markdown files should be chosen with care and existing Markdown files should not be deleted or renamed without due consideration of the consequences. The Markdown syntax supported by MkDocs and the Material for MkDocs theme can differ from the GitHub Flavored Markdown ([GFM](https://github.github.com/gfm/)) supported for content on GitHub.com. Please refer to the [MkDocs documentation](https://www.mkdocs.org/user-guide/writing-your-docs/#writing-with-markdown) and the [Material for MkDocs reference](https://squidfunk.github.io/mkdocs-material/reference/) to ensure your pull request will achieve the desired rendering. The extensions to the basic Markdown syntax used are set out in `mkdocs.yml` and include: * admonitions * code blocks, with syntax highlighting provided by [Pygments](https://pygments.org/) * content tabs, which can be nested * icons and emojis The files in the `doc` directory of the repository include two symbolic links (symlinks), `ChangeLog.md` and `CONTRIBUTING.md`. Users of Git on Windows should be aware of its approach to symbolic links. See the [Git for Windows Wiki](https://github.com/git-for-windows/git/wiki/Symbolic-Links). If `git config --show-scope --show-origin core.symlinks` is `false` in a local repository on Windows, then the files will be checked out as small plain files that contain the link text See the [Git documentation](https://git-scm.com/docs/git-config#Documentation/git-config.txt-coresymlinks). ## Error messages Stack catches exceptions thrown by its dependencies or by Stack itself in `Main.main`. In addition to exceptions that halt Stack's execution, Stack logs certain other matters as 'errors'. To support the Haskell Foundation's [Haskell Error Index](https://errors.haskell.org/) initiative, all Stack error messages generated by Stack itself should have a unique initial line: ~~~text Error: [S-nnnn] ~~~ where `nnnn` is a four-digit number in the range 1000 to 9999. If you create a new Stack error, select a number using a random number generator (see, for example, [RANDOM.ORG](https://www.random.org/)) and check that number is not already in use in Stack's code. If it is, pick another until the number is unique. All exceptions generated by Stack itself are implemented using data constructors of closed sum types. Typically, there is one such type for each module that exports functions that throw exceptions. This type and the related `instance` definitions are usually located at the top of the relevant module. Stack supports two types of exceptions: 'pretty' exceptions that are instances of class `RIO.PrettyPrint.Pretty`, which provides `pretty :: e -> StyleDoc`, and thrown as expressions of type `RIO.PrettyPrint.PrettyException.PrettyException`; and other 'plain' exceptions that are simply instances of class `Control.Exception.Exception` and, hence, instances of class `Show`. These types and classes are re-exported by `Stack.Prelude`. Stack throws exceptions in parts of the code that should, in principle, be unreachable. The functions `Stack.Prelude.bugReport` and `Stack.Prelude.bugPrettyReport` are used to give the messages a consistent format. The names of the data constructors for those exceptions usually end in `Bug`. In a few cases, Stack may throw an exception in 'pure' code. The function `RIO.impureThrow :: Exception e => e -> a`, re-exported by `Stack.Prelude`, is used for that purpose. ## Code If you would like to contribute code to fix a bug, add a new feature, or otherwise improve `stack`, pull requests are most welcome. It's a good idea to [submit an issue](https://github.com/commercialhaskell/stack/issues/new) to discuss the change before plowing into writing code. If you'd like to help out but aren't sure what to work on, look for issues with the [awaiting pull request](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3A%22awaiting+pull+request%22) label. Issues that are suitable for newcomers to the codebase have the [newcomer friendly](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3A%22awaiting+pull+request%22+label%3a%22newcomer+friendly%22) label. Best to post a comment to the issue before you start work, in case anyone has already started. Please include a [ChangeLog](https://github.com/commercialhaskell/stack/blob/master/ChangeLog.md) entry and [documentation](https://github.com/commercialhaskell/stack/tree/master/doc/) updates with your pull request. ## Backwards Compatability The Stack executable does not need to, and does not, strive for the same broad compatibility with versions of GHC that a library package (such as `pantry`) would seek. Instead, Stack aims to define a well-known combination of dependencies on which its executable relies. That applies in particular to the `Cabal` package, where Stack aims to support one, and only one, version of `Cabal` with each release of its executable. At the time of writing (September 2022) that combination is defined by resolver `nightly-2022-11-14` (for GHC 9.2.4, and including `Cabal-3.6.3.0`) - see `stack.yaml`. ## Code Quality The Stack project uses [yamllint](https://github.com/adrienverge/yamllint) as a YAML file quality tool and [HLint](https://github.com/ndmitchell/hlint) as a code quality tool. ### Linting of YAML files The yamllint configuration extends the tools default and is set out in `.yamllint.yaml`. In particular, indentation is set at 2 spaces and `- ` in sequences is treated as part of the indentation. ### Linting of Haskell source code The HLint configurations is set out in `.hlint.yaml`. Stack contributors need not follow dogmatically the suggested HLint hints but are encouraged to debate their usefulness. If you find a HLint hint is not useful and detracts from readability of code, consider marking it in the [configuration file](https://github.com/commercialhaskell/stack/blob/master/.hlint.yaml) to be ignored. Please refer to the [HLint manual](https://github.com/ndmitchell/hlint#readme) for configuration syntax. Quoting [@mgsloan](https://github.com/commercialhaskell/stack/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Amgsloan): > We are optimizing for code clarity, not code concision or what HLint thinks. You can install HLint with Stack. You might want to install it in the global project in case you run into dependency conflicts. HLint can report hints in your favourite text editor. Refer to the HLint repository for more details. To install, command: ~~~text stack install hlint ~~~ Once installed, you can check your changes with command: ~~~text stack exec -- sh ./etc/scripts/hlint.sh ~~~ ## Testing The Stack code has both unit tests and integration tests. Integration tests can be found in the [test/integration](https://github.com/commercialhaskell/stack/tree/master/test/integration) folder and unit tests, in the [src/test](https://github.com/commercialhaskell/stack/tree/master/src/test) folder. Tests are written using the [Hspec](https://hspec.github.io/) framework. In order to run the full test suite, you can simply command: ~~~text stack test ~~~ The `--file-watch` is a very useful option to get quick feedback. However, running the entire test suite after each file change will slow you down. You'll need to specify which test suite (unit test or integration) and pass arguments to specify which module you'd specifically like to run to get quick feedback. A description of this follows below. ### Working with Unit Tests If you would like to run the unit tests on their own, you can command: ~~~text stack test stack:stack-test ~~~ Running an individual module works with a command like this: ~~~text stack test stack:stack-test --ta "-m " ~~~ Where `` is the name of the module without `Spec.hs`. You may also load tests into GHCi and run them with these command: ~~~text stack ghci stack:stack-test --only-main # GHCi starting up output ... > :main -m "" ~~~ Where again, `` is the name of the module without `Spec.hs`. ### Working with Integration Tests Running the integration tests is a little involved, you'll need to command: ~~~text stack build --flag stack:integration-tests stack --exec stack-integration-test ~~~ Running an individual module works with a command like this: ~~~text stack build --flag stack:integration-tests stack --exec "stack-integration-test -m " ~~~ Where `` is the name of the folder listed in the [test/integration/tests/](https://github.com/commercialhaskell/stack/tree/master/test/integration/tests) directory. You may also achieve this through GHCi with this command: ~~~text stack ghci stack:stack-integration-test # GHCi starting up output ... > :main -m "" ~~~ Where again, `` is the name of the folder listed in the [test/integration/tests/](https://github.com/commercialhaskell/stack/tree/master/test/integration/tests) directory. ## Continuous integration (CI) We use [GitHub Actions](https://docs.github.com/en/actions) to do CI on Stack. The configuration of the workflows is in the YAML files in `.github/workflows`. The current active workflows are: ### Linting - `lint.yml` This workflow will run if: * there is a pull request * commits are pushed to these branches: `master`, `stable` and `rc/**` The workflow has one job (`style`). It runs on `ubuntu` only and applies yamllint and Hlint. ### Test suite - `unit-tests.yml` This workflow will run if: * there is a pull request * commits are pushed to these branches: `master`, `stable` and `rc/**`. * requested The workflow has two jobs: `pedantic` and `unit-tests`. The `pedantic` job runs on `ubuntu` only and builds Stack with the `--pedantic` flag. The `unit-tests` job runs on a matrix of operating systems and Stack project-level YAML configuration files (`stack.yaml`). It builds and tests Stack with the following flags: `--haddock --no-haddock-deps`. Its approach to creating a cache depends on the operating system. Its 'Cache dependencies on Unix-like OS' step caches the Stack root on Unix-like operating systems. Its 'Cache dependencies on Windows' step caches the same information on Windows, but takes into account that a relevant directory is located outside of the Stack root. ### Integration-based - `integration-tests.yml` This workflow will run if: * there is a pull request * commits are pushed to these branches: `master`, `stable` and `rc/**` * any tag is created * requested The workflow has three jobs: `integration-tests`, `linux-arm64` and `github-release`. The `integration-tests` job runs on a matrix of operating systems (`ubuntu`, `windows` and `macos`) and makes use of the `release.hs` script at `etc/scripts`. Its approach to creating a cache is the same as for `unit-tests.yml`, described above. Its 'Install deps and run checks' step uses `release.hs check`. Its 'Build bindist' step uses `release.hs build`. Its 'Upload bindist' step uploads artifacts using the name of the runner's operating system (`Linux`, `Windows` or `macOS`) as the name for the artifacts. The `linux-arm64` job runs on a self-hosted runner for Linux and ARM64. It makes use of Docker and a Docker file at `etc/dockerfiles/arm64.Dockerfile`. Its 'Build bindist' step makes use of a compiled version of `release.hs` script at `etc/scripts` to command `release build`. Its 'Upload bindist' step uploads artifacts using `Linux-ARM64` as the name for the artifacts. The `github-release` job needs `integration-tests` and `linux-arm64`. It only takes effect if the trigger for the workflow was the creation of a tag. Its four steps `Download Linux/Windows/macOS/Linux-ARM64 artifact` download the named artifacts to path `_release`. Its step 'Hash and sign assets' makes use of a 'secret' environment variable `RELEASE_SIGNING_KEY` established by the owner of the Stack repository. The variable contains the private key for the GPG key with ID 0x575159689BEFB442. That key is imported into GPG and then used by GPG to create a detached signature for each file. ### Inactive - `stan.yml` Stan is a Haskell static analysis tool. As of 29 August 2022, it does not support GHC >= 9.0.1 and Stack is built with GHC >= 9.2.4. Consequently, this workflow does not run. Its intent is to apply Stan to Stack. ## Slack channel If you're making deep changes and real-time communication with the Stack team would be helpful, we have a `#stack-collaborators` Slack channel in the Haskell Foundation workspace. To join the workspace, follow this [link](https://haskell-foundation.slack.com/join/shared_invite/zt-z45o9x38-8L55P27r12YO0YeEufcO2w#/shared-invite/email). stack-2.9.3.1/doc/coverage.md0000644000000000000000000001457314353310533014053 0ustar0000000000000000
# The `stack hpc` commands ~~~text stack hpc COMMAND Available commands: report Generate unified HPC coverage report from tix files and project targets ~~~ Code coverage is a measure of the degree to which the source code of a program is executed when a test suite is run. [Haskell Program Coverage (HPC)](https://ku-fpg.github.io/software/hpc/) is a code coverage tool for Haskell that is provided with GHC. Code coverage is enabled by passing the flag `--coverage` to `stack build`. `stack hpc` provides commands specific to HPC. Command `stack hpc` for the available commands. The following refers to the local HPC root directory. Its location can be obtained by command: ~~~text stack path --local-hpc-root ~~~ ## The `stack hpc report` command ~~~text stack hpc report [TARGET_OR_TIX] [--all] [--destdir DIR] [--open] ~~~ The `stack hpc report` command generates a report for a selection of targets and `.tix` files. Pass the flag `--all` for a report that uses all stored results. Pass the flag --open` to open the HTML report in your browser. ## The `extra-tix-files` directory During the execution of the build, you can place additional tix files in the `extra-tix-files` subdirectory in the local HPC root directory, in order for them to be included in the unified report. A couple caveats: 1. These tix files must be generated by executables that are built against the exact same library versions. Also note that, on subsequent builds with coverage, the local HPC root directory will be recursively deleted. It just stores the most recent coverage data. 2. These tix files will not be considered by `stack hpc report` unless listed explicitly by file name. ## Examples If we have three different packages with test suites, packages `A`, `B`, and `C`, the default unified report will have coverage from all three. If we want a unified report with just two, we can instead command: ~~~text stack hpc report A B ~~~ This will output a textual report for the combined coverage from `A` and `B`'s test suites, along with a path to the HTML for the report. This command also supports taking extra `.tix` files. If you've also built an executable, against exactly the same library versions of `A`, `B`, and `C`, then you could command the following: ~~~text stack exec -- an-exe stack hpc report A B C an-exe.tix ~~~ or, equivalently: ~~~text stack exec -- an-exe stack hpc report --all an-exe.tix ~~~ This report will consider all test results as well as the newly generated `an-exe.tix` file. ## Usage `stack test --coverage` is quite streamlined for the following use-case: 1. You have test suites which exercise your local packages. 2. These test suites link against your library, rather than building the library directly. Coverage information is only given for libraries, ignoring the modules which get compiled directly into your executable. A common case where this doesn't happen is when your test suite and library both have something like `hs-source-dirs: src/`. In this case, when building your test suite you may also be compiling your library, instead of just linking against it. When your project has these properties, you will get the following: 1. Textual coverage reports in the build output. 2. A unified textual and HTML report, considering the coverage on all local libraries, based on all of the tests that were run. 3. An index of all generated HTML reports, in `index.html` in the local HPC root directory. ## Implementation details Most users can get away with just understanding the above documentation. However, advanced users may want to understand exactly how `--coverage` works: 1. The GHC option `-fhpc` gets passed to all local packages. This tells GHC to output executables that track coverage information and output them to `.tix` files. `the-exe-name.tix` files will get written to the working directory of the executable. When switching on this flag, it will usually cause all local packages to be rebuilt (see issue [#1940](https://github.com/commercialhaskell/stack/issues/1940)). 2. Before the build runs with `--coverage`, the contents of the local HPC root directory gets deleted. This prevents old reports from getting mixed with new reports. If you want to preserve report information from multiple runs, copy the contents of this path to a new directory. 3. Before a test run, if a `test-name.tix` file exists in the package directory, it will be deleted. 4. After a test run, it will expect a `test-name.tix` file to exist. This file will then get loaded, modified, and outputted to `pkg-name/test-name/test-name.tix` in the local HPC root directory. The `.tix` file gets modified to remove coverage file that isn't associated with a library. So, this means that you won't get coverage information for the modules compiled in the `executable` or `test-suite` stanza of your Cabal file. This makes it possible to directly union multiple `*.tix` files from different executables (assuming they are using the exact same versions of the local packages). If there is enough popular demand, it may be possible in the future to give coverage information for modules that are compiled directly into the executable. See issue [#1359](https://github.com/commercialhaskell/stack/issues/1359). 5. Once we have a `.tix` file for a test, we also generate a textual and HTML report for it. The textual report is sent to the terminal. The index of the test-specific HTML report is available `pkg-name/test-name/index.html` in the local HPC root directory. 6. After the build completes, if there are multiple output `*.tix` files, they get combined into a unified report. The index of this report will be available at `combined/all/index.html` in the local HPC root directory. 7. Finally, an index of the resulting coverage reports is generated. It links to the individual coverage reports (one for each test-suite), as well as the unified report. This index is available at `index.html` in the local HPC root directory. stack-2.9.3.1/doc/custom_snapshot.md0000644000000000000000000001001514445022466015503 0ustar0000000000000000
## Snapshot specification [:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1) Snapshots provide a list of packages to use, along with flags, GHC options, and a few other settings. Snapshots may extend any other snapshot that can be specified in a `resolver` or `snapshot` key. The packages specified follow the same syntax for dependencies in Stack's project-level configuration files. Unlike the `extra-deps` key, however, no support for local directories is available in snapshots to ensure reproducibility. !!! info Stack uses the [Pantry](https://hackage.haskell.org/package/pantry) for snapshot specification. ~~~yaml resolver: lts-8.21 # Inherits GHC version and package set compiler: ghc-8.0.1 # Overwrites GHC version in the resolver, optional # Additional packages, follows extra-deps syntax packages: - unordered-containers-0.2.7.1 - hashable-1.2.4.0 - text-1.2.2.1 # Packages from the parent snapshot to ignore drop-packages: - wai-extra # Packages which should be hidden hidden: wai: true warp: false # Set GHC options for specific packages ghc-options: warp: - -O2 # Override flags, can also override flags in the parent snapshot flags: unordered-containers: debug: true ~~~ If you put this in a `snapshot.yaml` file in the same directory as your project, you can now use the snapshot like this: ~~~yaml resolver: snapshot.yaml ~~~ This is an example of a custom snapshot stored in the filesystem. They are assumed to be mutable, so you are free to modify it. We detect that the snapshot has changed by hashing the contents of the involved files, and using it to identify the snapshot internally. It is often reasonably efficient to modify a custom snapshot, due to Stack sharing snapshot packages whenever possible. ### Overriding the compiler The following snapshot specification will be identical to `lts-7.1`, but instead use `ghc-7.10.3` instead of `ghc-8.0.1`: ~~~yaml resolver: lts-7.1 compiler: ghc-7.10.3 ~~~ ### Dropping packages The following snapshot specification will be identical to `lts-7.1`, but without the `text` package in our snapshot. Removing this package will cause all the packages that depend on `text` to be unbuildable, but they will still be present in the snapshot. ~~~yaml resolver: lts-7.1 drop-packages: - text ~~~ ### Hiding packages The following snapshot specification will be identical to `lts-7.1`, but the `text` package will be hidden when registering. This will affect, for example, the import parser in the script command. ~~~yaml resolver: lts-7.1 hidden: - text ~~~ ### Specifying GHC options In order to specify GHC options for a package, you use the same syntax as the [ghc-options](yaml_configuration.md#ghc-options) key for build configuration. The following snapshot specification will be identical to `lts-7.1`, but provides `-O1` as a ghc-option for `text`: ~~~yaml resolver: lts-7.1 packages: - text-1.2.2.1 ghc-options: text: -O1 ~~~ This works somewhat differently than the stack.yaml `ghc-options` field, in that options can only be specified for packages that are mentioned in the custom snapshot's `packages` list. It sets the ghc-options, rather than extending those specified in the snapshot being extended. Another difference is that the `*` entry for `ghc-options` applies to all packages in the `packages` list, rather than all packages in the snapshot. ### Specifying Cabal flags In order to specify Cabal flags for a package, you use the same syntax as the [flags](yaml_configuration.md#flags) key for build configuration. The following snapshot specification will be identical to `lts-7.1`, but it enables the `developer` Cabal flag: ~~~yaml resolver: lts-7.1 packages: - text-1.2.2.1 flags: text: developer: true ~~~ stack-2.9.3.1/doc/debugging.md0000644000000000000000000000573714353310533014215 0ustar0000000000000000
# Debugging To profile a component of the current project, simply pass the `--profile` flag to `stack`. The `--profile` flag turns on the `--enable-library-profiling` and `--enable-executable-profiling` Cabal options _and_ passes the `+RTS -p` runtime options to any testsuites and benchmarks. For example the following command will build the `my-tests` testsuite with profiling options and create a `my-tests.prof` file in the current directory as a result of the test run. ~~~text stack test --profile my-tests ~~~ The `my-tests.prof` file now contains time and allocation info for the test run. To create a profiling report for an executable, e.g. `my-exe`, you can command: ~~~text stack exec --profile -- my-exe +RTS -p ~~~ For more fine-grained control of compilation options there are the `--library-profiling` and `--executable-profiling` flags which will turn on the `--enable-library-profiling` and `--enable-executable-profiling` Cabal options respectively. Custom GHC options can be passed in with `--ghc-options "more options here"`. To enable compilation with profiling options by default you can add the following snippet to your `stack.yaml` or `~/.stack/config.yaml`: ~~~yaml build: library-profiling: true executable-profiling: true ~~~ ## Further reading For more commands and uses, see the [official GHC chapter on profiling](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html), the [Haskell wiki](https://wiki.haskell.org/How_to_profile_a_Haskell_program), and the [chapter on profiling in Real World Haskell](http://book.realworldhaskell.org/read/profiling-and-optimization.html). ## Tracing To generate a backtrace in case of exceptions during a test or benchmarks run, use the `--trace` flag. Like `--profile` this compiles with profiling options, but adds the `+RTS -xc` runtime option. ## Debugging symbols Building with debugging symbols in the [DWARF information](https://ghc.haskell.org/trac/ghc/wiki/DWARF) is supported by Stack. This can be done by passing the flag `--ghc-options="-g"` and also to override the default behaviour of stripping executables of debugging symbols by passing either one of the following flags: `--no-strip`, `--no-library-stripping` or `--no-executable-stripping`. In Windows, GDB can be installed to debug an executable with `stack exec -- pacman -S gdb`. Windows' Visual Studio compiler's debugging format PDB is not supported at the moment. This might be possible by [separating](https://stackoverflow.com/questions/866721/how-to-generate-gcc-debug-symbol-outside-the-build-target) debugging symbols and [converting](https://github.com/rainers/cv2pdb) their format. Or as an option when [using the LLVM backend](http://blog.llvm.org/2017/08/llvm-on-windows-now-supports-pdb-debug.html). stack-2.9.3.1/doc/dependency_visualization.md0000644000000000000000000001164314353310533017352 0ustar0000000000000000
# The `stack dot` command ~~~text stack dot [--[no-]external] [--[no-]include-base] [--depth DEPTH] [--prune PACKAGES] [TARGET] [--flag PACKAGE:[-]FLAG] [--test] [--bench] [--global-hints] ~~~ A package and its dependencies and the direct dependency relationships between them form a directed graph. [Graphviz](https://www.graphviz.org/) is open source software that visualises graphs. It provides the DOT language for defining graphs and the `dot` executable for drawing directed graphs. Graphviz is available to [download](https://www.graphviz.org/download/) for Linux, Windows, macOS and FreeBSD. `stack dot` produces output, to the standard output channel, in the DOT language to represent the relationships between your packages and their dependencies. By default: * external dependencies are excluded from the output. Pass the flag `--external` to include external dependencies; * the `base` package and its dependencies are included in the output. Pass the flag `--no-include-base` to exclude `base` and its dependencies; * there is no limit to the depth of the resolution of dependencies. Pass the `--depth ` option to limit the depth; * all relevant packages are included in the output. Pass the `--prude ` option to exclude the specified packages, where `` is a list of package names separated by commas; * all packages in the project are included in the output. However, the target for the command can be specified as an argument. It uses the same format as the [`stack build` command](build_command.md); * test components of the packages in the project are excluded from the output. Pass the flag `--test` to include test components; and * benchmark components of the packages in the project are excluded from the output. Pass the flag `--bench` to include benchmark components.git p Pass the option `--flag :` or `--flag :-` to set or unset a Cabal flag. This option can be specified multiple times. Pass the flag `--global-hints` to use a hint file for global packages. If a hint file is used, GHC does not need to be installed. ## Examples The following examples are based on a version of the [`wreq` package](https://hackage.haskell.org/package/wreq). In each case, the output from `stack dot` is piped as an input into Graphviz's `dot` executable, and `dot` produces output in the form of a PNG file named `wreq.png`. * A simple example: ~~~text stack dot | dot -Tpng -o wreq.png ~~~ [![wreq](https://cloud.githubusercontent.com/assets/591567/8478591/ae10a418-20d2-11e5-8945-55246dcfac62.png)](https://cloud.githubusercontent.com/assets/591567/8478591/ae10a418-20d2-11e5-8945-55246dcfac62.png) * Include external dependencies: ~~~text stack dot --external | dot -Tpng -o wreq.png ~~~ [![wreq_ext](https://cloud.githubusercontent.com/assets/591567/8478621/d247247e-20d2-11e5-993d-79096e382abd.png)](https://cloud.githubusercontent.com/assets/591567/8478621/d247247e-20d2-11e5-993d-79096e382abd.png) * Include external dependencies, limit the depth and save the output from `stack dot` as an intermediate file (`wreq.dot`). ~~~text stack dot --external --depth 1 > wreq.dot dot -Tpng -o wreq.png wreq.dot ~~~ * Include external dependencies, exclude `base` and limit the depth: ~~~text stack dot --no-include-base --external --depth 1 | dot -Tpng -o wreq.png ~~~ [![wreq_depth](https://cloud.githubusercontent.com/assets/591567/8484310/45b399a0-20f7-11e5-8068-031c2b352961.png)](https://cloud.githubusercontent.com/assets/591567/8484310/45b399a0-20f7-11e5-8068-031c2b352961.png) * Include external dependencies and prune `base` and other packages: ~~~text stack dot --external --prune base,lens,wreq-examples,http-client,aeson,tls,http-client-tls,exceptions | dot -Tpng -o wreq.png ~~~ [![wreq_pruned](https://cloud.githubusercontent.com/assets/591567/8478768/adbad280-20d3-11e5-9992-914dc24fe569.png)](https://cloud.githubusercontent.com/assets/591567/8478768/adbad280-20d3-11e5-9992-914dc24fe569.png) * Include external dependencies, prune `base` and other packages, and use a different Graphviz executable to draw the graph: Graphviz's `twopi` executable draws graphs in a radial layout. ~~~text stack dot --external --prune base,lens,wreq-examples,http-client,aeson,tls,http-client-tls,exceptions | twopi -Groot=wreq -Goverlap=false -Tpng -o wreq.png ~~~ [![wreq_pruned](https://cloud.githubusercontent.com/assets/591567/8495538/9fae1184-216e-11e5-9931-99e6147f8aed.png)](https://cloud.githubusercontent.com/assets/591567/8495538/9fae1184-216e-11e5-9931-99e6147f8aed.png) stack-2.9.3.1/doc/developing_on_windows.md0000644000000000000000000000721314445022466016662 0ustar0000000000000000
# Developing on Windows # On Windows, Stack comes with an installation of [MSYS2](https://www.msys2.org/). MSYS2 will be used by Stack to provide a Unix-like shell and environment for Stack. This may be necessary for installing some Haskell packages, such as those which use `configure` scripts, or if your project needs some additional tools during the build phase. No matter which terminal software you choose (Windows Terminal, Console Windows Host, Command Prompt, PowerShell, Git bash or any other) you can use this environment too by executing all programs through `stack exec -- `. Executables and libraries can be installed with the MSYS2 package manager `pacman`. All tools can be found in the [package list](https://github.com/msys2/msys2/wiki/Packages). A [list of commands](https://github.com/msys2/msys2/wiki/Using-packages) that work with `pacman` is also available. Just remember that `pacman` — like all other tools — should be started with `stack exec -- pacman`. Command `stack path --bin-path` to see the PATH in the Stack environment. On Windows, it includes the `\mingw64\bin`, `\usr\bin` and `\usr\local\bin` directories of the Stack-supplied MSYS2. If your executable depends on files (for example, dynamic-link libraries) in those directories and you want ro run it outside of the Stack environment, you will need to ensure copies of those files are on the PATH. The Stack-supplied MSYS2 can itself be updated with the Stack-supplied `pacman`. See the MSYS2 guide ['III. Updating packages'](https://www.msys2.org/wiki/MSYS2-installation/). If the Stack-supplied `pacman` has a version that is 5.0.1.6403 or greater (see `stack exec -- pacman --version`) then the command to update is simply: stack exec -- pacman -Syuu This command may need to be run more than once, until everything is reported by `pacman` as 'up to date' and 'nothing to do'. ## Setup.hs ## `Setup.hs` is automatically run inside the Stack environment. So when you need to launch another tool you don't need to prefix the command with `stack exec --` within the custom `Setup.hs` file. ## Pacman packages to install for common Haskell packages ## The following lists MSYS2 packages known to allow the installation of some common Haskell packages on Windows. Feel free to submit additional entries via a pull request. * For [text-icu](https://github.com/bos/text-icu) install `mingw64/mingw-w64-x86_64-icu` ## CMake ## CMake has trouble finding other tools even if they are available on the PATH. Likely this is not a CMake problem but one of the environment not fully integrating. For example GHC comes with a copy of GCC which is not installed by MSYS2 itself. If you want to use this GCC you can provide a full path to it, or find it first with `System.Directory.findExecutable` if you want to launch GCC from a Haskell file such as `Setup.hs`. Experience tells that the `mingw-w64` versions of Make and CMake are most likely to work. Though there are other versions available through `pacman`, so have a look to see what works for you. Both tools can be installed with the commands: stack exec -- pacman -S mingw-w64-x86_64-make stack exec -- pacman -S mingw-w64-x86_64-cmake Even though Make and CMake are then both installed into the same environment, CMake still seems to have trouble to find Make. To help CMake find GCC and Make supply the following flags: -DCMAKE_C_COMPILER=path -DCMAKE_MAKE_PROGRAM=path stack-2.9.3.1/doc/docker_command.md0000644000000000000000000000204514353310533015214 0ustar0000000000000000
# The `stack docker` commands ~~~text stack docker COMMAND Available commands: pull Pull latest version of Docker image from registry reset Reset the Docker sandbox ~~~ Stack is able to build your code inside a Docker image, which means even more reproducibility to your builds, since you and the rest of your team will always have the same system libraries. For further information, see the [Docker integration](docker_integration.md) documentation. ## The `stack docker pull` command ~~~text stack docker pull ~~~ `stack docker pull` pulls the latest version of the Docker image from the registry. ## The `stack docker reset` command ~~~text stack docker reset [--keep-home] ~~~ `stack docker reset` resets the Docker sandbox. Pass the flag `--keep-home` to preserve the sandbox's home directory. stack-2.9.3.1/doc/docker_integration.md0000644000000000000000000005275614331513214016134 0ustar0000000000000000
Docker integration =============================================================================== Stack has support for automatically performing builds inside a Docker container, using volume mounts and user ID switching to make it mostly seamless. FP Complete provides images for use with stack that include GHC, tools, and optionally have all of the Stackage LTS packages pre-installed in the global package database. The primary purpose for using stack/docker this way is for teams to ensure all developers are building in an exactly consistent environment without team members needing to deal with Docker themselves. See the [how stack can use Docker under the hood](https://www.fpcomplete.com/blog/2015/08/stack-docker) blog post for more information about the motivation and implementation of stack's Docker support. If you'd like to build Docker images that contain your Haskell executables, see [Building Haskell Apps with Docker](https://www.fpcomplete.com/blog/2017/12/building-haskell-apps-with-docker). Prerequisites ------------------------------------------------------------------------------- ### Supported operating systems **Linux 64-bit**: Docker use requires machine (virtual or metal) running a Linux distribution [that Docker supports](https://docs.docker.com/installation/#installation), with a 64-bit kernel. If you do not already have one, we suggest Ubuntu 14.04 ("trusty") since this is what we test with. **macOS**: [Docker for Mac](https://docs.docker.com/docker-for-mac/) is the supported way to use Docker integration on macOS (the older Docker Machine (boot2docker) approach to using Docker on macOS is not supported due to issues with host volume mounting that make Stack nearly unusable for anything but the most trivial projects). Other Un*xen are not officially supported but there are ways to get them working. See [#194](https://github.com/commercialhaskell/stack/issues/194) for details and workarounds. Note: you may want to use set the `mount-mode` option to `delegated`, since this can dramatically improve performance on macOS (see [configuration](#configuration) for more information). **Windows does not work at all** (see [#2421](https://github.com/commercialhaskell/stack/issues/2421)). ### Docker Install the latest version of Docker by following the [instructions for your operating system](http://docs.docker.com/installation/). The Docker client should be able to connect to the Docker daemon as a non-root user. For example (from [here](http://docs.docker.com/installation/ubuntulinux/#ubuntu-raring-1304-and-saucy-1310-64-bit)): # Add the connected user "${USER}" to the docker group. # Change the user name to match your preferred user. sudo gpasswd -a ${USER} docker # Restart the Docker daemon. sudo service docker restart You will now need to log out and log in again for the group addition to take effect. Note the above has security implications. See [security](#security) for more. Usage ------------------------------------------------------------------------------- This section assumes that you already have Docker installed and working. If not, see the [prerequisites](#prerequisites) section. If you run into any trouble, see the [troubleshooting](#troubleshooting) section. ### Enable in stack.yaml The most basic configuration is to add this to your project's `stack.yaml`: docker: enable: true See [configuration](#configuration) for additional options. You can enable it on the command-line using `stack --docker`. Please note that in a docker-enabled configuration, stack uses the GHC installed in the Docker container by default. To use a compiler installed by stack, add system-ghc: false (see [`system-ghc`](yaml_configuration.md#system-ghc)). ### Use stack as normal With Docker enabled, most stack sub-commands will automatically launch themselves in an ephemeral Docker container (the container is deleted as soon as the command completes). The project directory and `~/.stack` are volume-mounted into the container, so any build artifacts are "permanent" (not deleted with the container). The first time you run a command with a new image, you will be prompted to run `stack docker pull` to pull the image first. This will pull a Docker image with a tag that matches your resolver. Only LTS resolvers are supported (we do not generate images for nightly snapshots). Not every LTS version is guaranteed to have an image existing, and new LTS images tend to lag behind the LTS snapshot being published on stackage.org. Be warned: these images are rather large! Docker sub-commands ------------------------------------------------------------------------------- These `stack docker` sub-commands have Docker-specific functionality. Most other `stack` commands will also use a Docker container under the surface if Docker is enabled. ### pull - Pull latest version of image `stack docker pull` pulls an image from the Docker registry for the first time, or updates the image by pulling the latest version. ### reset - Reset the Docker "sandbox" In order to preserve the contents of the in-container home directory between runs, a special "sandbox" directory is volume-mounted into the container. `stack docker reset` will reset that sandbox to its defaults. Note: `~/.stack` is separately volume-mounted, and is left alone during reset. Command-line options ------------------------------------------------------------------------------- The default Docker configuration can be overridden on the command-line. See `stack --docker-help` for a list of all Docker options, and consult [configuration](#configuration) section below for more information about their meanings. These are global options, and apply to all commands (not just `stack docker` sub-commands). Configuration ------------------------------------------------------------------------------- `stack.yaml` contains a `docker:` section with Docker settings. If this section is omitted, Docker containers will not be used. These settings can be included in project, user, or global configuration. Here is an annotated configuration file. The default values are shown unless otherwise noted. docker: # Set to false to disable using Docker. In the project configuration, # the presence of a `docker:` section implies docker is enabled unless # `enable: false` is set. In user and global configuration, this is not # the case. enable: true # The name of the repository to pull the image from. See the "repositories" # section of this document for more information about available repositories. # If this includes a tag (e.g. "my/image:tag"), that tagged image will be # used. Without a tag specified, the LTS version slug is added automatically. # Either `repo` or `image` may be specified, but not both. repo: "fpco/stack-build" # Exact Docker image name or ID. Overrides `repo`. Either `repo` or `image` # may be specified, but not both. (default none) image: "5c624ec1d63f" # Registry requires login. A login will be requested before attempting to # pull. registry-login: false # Username to log into the registry. (default none) registry-username: "myuser" # Password to log into the registry. (default none) registry-password: "SETME" # If true, the image will be pulled from the registry automatically, without # needing to run `stack docker pull`. See the "security" section of this # document for implications of enabling this. auto-pull: true # If true, the container will be run "detached" (in the background). Refer # to the Docker users guide for information about how to manage containers. # This option would rarely make sense in the configuration file, but can be # useful on the command-line. When true, implies `persist`. detach: false # If true, the container will not be deleted after it terminates. Refer to # the Docker users guide for information about how to manage containers. This # option would rarely make sense in the configuration file, but can be # useful on the command-line. `detach` implies `persist`. persist: false # What to name the Docker container. Only useful with `detach` or # `persist` true. (default none) container-name: "example-name" # Sets the network used by docker. Gets directly passed to dockers `net` # argument (default: host) network: host # Additional arguments to pass to `docker run`. (default none) run-args: ["--net=bridge"] # Directories from the host to volume-mount into the container. If it # contains a `:`, the part before the `:` is the directory on the host and # the part after the `:` is where it should be mounted in the container. # (default none, aside from the project and stack root directories which are # always mounted) mount: - "/foo/bar" - "/baz:/tmp/quux" # Sets the volume mount mode, passed directly to `docker`. # The default mode (consistent) is safest, but may suffer poor performance # on non-Linux platforms such as macOS, where the `delegated` mode will # be significantly faster. # See https://docs.docker.com/docker-for-mac/osxfs-caching/ # for valid values and the implications of changing the default. mount-mode: delegated # Environment variables to set in the container. Environment variables # are not automatically inherited from the host, so if you need any specific # variables, use the `--docker-env` command-line argument version of this to # pass them in. (default none) env: - "FOO=BAR" - "BAR=BAZ QUUX" # Location of a Docker container-compatible 'stack' executable with the # matching version. This executable must be compatible with the Docker # image in terms of platform (linux-x86_64) and shared libraries # (statically linked is best, otherwise the image needs to have the # same shared libraries installed). # Valid values are: # host: use the host's executable. This is the default when the host's # executable is known to work (e.g., from official linux-x86_64 bindist) # download: download a compatible executable matching the host's version. # This is the default when the host's executable is not known to work # image: use the 'stack' executable baked into the image. The version # must match the host's version # /path/to/stack: path on the host's local filesystem stack-exe: host # If true (the default when using the local Docker Engine), run processes # in the Docker container as the same UID/GID as the host. The ensures # that files written by the container are owned by you on the host. # When the Docker Engine is remote (accessed by tcp), defaults to false. set-user: true # Require the version of the Docker client to be within the specified # Cabal-style version range (e.g., ">= 1.6.0 && < 1.9.0") require-docker-version: "any" Image Repositories ------------------------------------------------------------------------------- FP Complete provides the following public image repositories on Docker Hub: - [fpco/stack-build](https://registry.hub.docker.com/u/fpco/stack-build/) (the default) - GHC (patched), tools (Stack, Cabal (the tool), happy, alex, etc.), and system developer libraries required to build all Stackage packages. FP Complete also builds custom variants of these images for their clients. These images can also be used directly with `docker run` and provide a complete Haskell build environment. In addition, most Docker images that contain the basics for running GHC can be used with Stack's Docker integration. For example, the [official Haskell image repository](https://hub.docker.com/_/haskell/) works. See [Custom images](#custom-images) for more details. Security ------------------------------------------------------------------------------- Having `docker` usable as a non-root user is always a security risk, and will allow root access to your system. It is also possible to craft a `stack.yaml` that will run arbitrary commands in an arbitrary docker container through that vector, thus a `stack.yaml` could cause stack to run arbitrary commands as root. While this is a risk, it is not really a greater risk than is posed by the docker permissions in the first place (for example, if you ever run an unknown shell script or executable, or ever compile an unknown Haskell package that uses Template Haskell, you are at equal risk). Nevertheless, there are [plans to close the stack.yaml loophole](https://github.com/commercialhaskell/stack/issues/260). One way to mitigate this risk is, instead of allowing `docker` to run as non-root, replace `docker` with a wrapper script that uses `sudo` to run the real Docker client as root. This way you will at least be prompted for your root password. As [@gregwebs](https://github.com/gregwebs) pointed out, put this script named `docker` in your PATH (and make sure you remove your user from the `docker` group as well, if you added it earlier): #!/bin/bash -e # The goal of this script is to maintain the security privileges of sudo # Without having to constantly type "sudo" exec sudo /usr/bin/docker "$@" Additional notes ------------------------------------------------------------------------------- ### Volume-mounts and ephemeral containers Since filesystem changes outside of the volume-mounted project directory are not persisted across runs, this means that if you `stack exec sudo apt-get install some-ubuntu-package`, that package will be installed but then the container it's installed in will disappear, thus causing it to have no effect. If you wish to make this kind of change permanent, see later instructions for how to create a [derivative Docker image](#derivative-image). Inside the container, your home directory is a special location that volume- mounted from within your project directory's `.stack-work` in such a way as that installed GHC/cabal packages are not shared between different Stackage snapshots. In addition, `~/.stack` is volume-mounted from the host. ### Network stack containers use the host's network stack within the container by default, meaning a process running in the container can connect to services running on the host, and a server process run within the container can be accessed from the host without needing to explicitly publish its port. To run the container with an isolated network, use `--docker-run-args` to pass the `--net` argument to `docker-run`. For example: stack --docker-run-args='--net=bridge --publish=3000:3000' \ exec some-server will run the container's network in "bridge" mode (which is Docker's default) and publish port 3000. ### Persistent container If you do want to do all your work, including editing, in the container, it might be better to use a persistent container in which you can install Ubuntu packages. You could get that by running something like `stack --docker-container-name=NAME --docker-persist exec bash`. This means when the container exits, it won't be deleted. You can then restart it using `docker start -a -i NAME`. It's also possible to detach from a container while it continues running in the background using by pressing Ctrl-P Ctrl-Q, and then reattach to it using `docker attach NAME`. Note that each time you run `stack --docker-persist`, a _new_ persistent container is created (it will not automatically reuse the previous one). See the [Docker user guide](https://docs.docker.com/userguide/) for more information about managing Docker containers. ### Derivative image Creating your own custom derivative image can be useful if you need to install additional Ubuntu packages or make other changes to the operating system. Here is an example (replace `stack-build:custom` if you prefer a different name for your derived container, but it's best if the repo name matches what you're deriving from, only with a different tag, to avoid recompilation): ;;; On host $ sudo stack --docker-persist --docker-container-name=temp exec bash ;;; In container, make changes to OS # apt-get install r-cran-numderiv [...] # exit ;;; On host again $ docker commit temp stack-build:custom $ docker rm temp Now you have a new Docker image named `stack-build:custom`. To use the new image, run a command such as the following or update the corresponding values in your `stack.yaml`: stack --docker-image=stack-build:custom Note, however, that any time a new image is used, you will have to re-do this process. You could also use a Dockerfile to make this reusable. Consult the [Docker user guide](https://docs.docker.com/userguide/) for more on creating Docker images. ### Custom images The easiest way to create your own custom image us by extending FP Complete's images, but if you prefer to start from scratch, most images that include the basics for building code with GHC will work. The image doesn't even, strictly speaking, need to include GHC, but it does need to have libraries and tools that GHC requires (e.g., libgmp, gcc, etc.). There are also a few ways to set up images that tightens the integration: * Create a user and group named `stack`, and create a `~/.stack` directory for it. Any build plans and caches from it will be copied from the image by Stack, meaning they don't need to be downloaded separately. * Any packages in GHC's global package database will be available. This can be used to add private libraries to the image, or the make available a set of packages from an LTS release. Troubleshooting ------------------------------------------------------------------------------- ### "No Space Left on Device", but 'df' shows plenty of disk space This is likely due to the storage driver Docker is using, in combination with the large size and number of files in these images. Use `docker info|grep 'Storage Driver'` to determine the current storage driver. We recommend using either the `overlay` or `aufs` storage driver for stack, as they are least likely to give you trouble. On Ubuntu, `aufs` is the default for new installations, but older installations sometimes used `devicemapper`. The `devicemapper` storage driver's doesn't work well with large filesystems, and we have experienced other instabilities with it as well. We recommend against its use. The `btrfs` storage driver has problems running out of metadata space long before running out of actual disk space, which requires rebalancing or adding more metadata space. See [CoreOS's btrfs troubleshooting page](https://coreos.com/docs/cluster-management/debugging/btrfs-troubleshooting/) for details about how to do this. Pass the `-s ` argument to the Docker daemon to set the storage driver (in `/etc/default/docker` on Ubuntu). See [Docker daemon storage-driver option](https://docs.docker.com/reference/commandline/cli/#daemon-storage-driver-option) for more details. You may also be running out of inodes on your filesystem. Use `df -i` to check for this condition. Unfortunately, the number of inodes is set when creating the filesystem, so fixing this requires reformatting and passing the `-N` argument to mkfs.ext4. ### Name resolution doesn't work from within container On Ubuntu 12.04, by default `NetworkManager` runs `dnsmasq` service, which sets `127.0.0.1` as your DNS server. Since Docker containers cannot access this dnsmasq, Docker falls back to using Google DNS (8.8.8.8/8.8.4.4). This causes problems if you are forced to use internal DNS server. This can be fixed by executing: sudo sed 's@dns=dnsmasq@#dns=dnsmasq@' -i \ /etc/NetworkManager/NetworkManager.conf && \ sudo service network-manager restart If you have already installed Docker, you must restart the daemon for this change to take effect: sudo service docker restart The above commands turn off `dnsmasq` usage in NetworkManager configuration and restart network manager. They can be reversed by executing `sudo sed 's@#dns=dnsmasq@dns=dnsmasq@' -i /etc/NetworkManager/NetworkManager.conf && sudo service network-manager restart`. These instructions are adapted from [the Shipyard Project's QuickStart guide](https://github.com/shipyard/shipyard/wiki/QuickStart#127011-dns-server-problem-on-ubuntu). ### Cannot pull images from behind firewall that blocks TLS/SSL If you are behind a firewall that blocks TLS/SSL and pulling images from a private Docker registry, you must edit the system configuration so that the `--insecure-registry ` option is passed to the Docker daemon. For example, on Ubuntu: echo 'DOCKER_OPTS="--insecure-registry registry.example.com"' \ |sudo tee -a /etc/default/docker sudo service docker restart This does require the private registry to be available over plaintext HTTP. See [Docker daemon insecure registries documentation](https://docs.docker.com/reference/commandline/cli/#insecure-registries) for details. stack-2.9.3.1/doc/dot_command.md0000644000000000000000000001164314353310533014537 0ustar0000000000000000
# The `stack dot` command ~~~text stack dot [--[no-]external] [--[no-]include-base] [--depth DEPTH] [--prune PACKAGES] [TARGET] [--flag PACKAGE:[-]FLAG] [--test] [--bench] [--global-hints] ~~~ A package and its dependencies and the direct dependency relationships between them form a directed graph. [Graphviz](https://www.graphviz.org/) is open source software that visualises graphs. It provides the DOT language for defining graphs and the `dot` executable for drawing directed graphs. Graphviz is available to [download](https://www.graphviz.org/download/) for Linux, Windows, macOS and FreeBSD. `stack dot` produces output, to the standard output channel, in the DOT language to represent the relationships between your packages and their dependencies. By default: * external dependencies are excluded from the output. Pass the flag `--external` to include external dependencies; * the `base` package and its dependencies are included in the output. Pass the flag `--no-include-base` to exclude `base` and its dependencies; * there is no limit to the depth of the resolution of dependencies. Pass the `--depth ` option to limit the depth; * all relevant packages are included in the output. Pass the `--prude ` option to exclude the specified packages, where `` is a list of package names separated by commas; * all packages in the project are included in the output. However, the target for the command can be specified as an argument. It uses the same format as the [`stack build` command](build_command.md); * test components of the packages in the project are excluded from the output. Pass the flag `--test` to include test components; and * benchmark components of the packages in the project are excluded from the output. Pass the flag `--bench` to include benchmark components.git p Pass the option `--flag :` or `--flag :-` to set or unset a Cabal flag. This option can be specified multiple times. Pass the flag `--global-hints` to use a hint file for global packages. If a hint file is used, GHC does not need to be installed. ## Examples The following examples are based on a version of the [`wreq` package](https://hackage.haskell.org/package/wreq). In each case, the output from `stack dot` is piped as an input into Graphviz's `dot` executable, and `dot` produces output in the form of a PNG file named `wreq.png`. * A simple example: ~~~text stack dot | dot -Tpng -o wreq.png ~~~ [![wreq](https://cloud.githubusercontent.com/assets/591567/8478591/ae10a418-20d2-11e5-8945-55246dcfac62.png)](https://cloud.githubusercontent.com/assets/591567/8478591/ae10a418-20d2-11e5-8945-55246dcfac62.png) * Include external dependencies: ~~~text stack dot --external | dot -Tpng -o wreq.png ~~~ [![wreq_ext](https://cloud.githubusercontent.com/assets/591567/8478621/d247247e-20d2-11e5-993d-79096e382abd.png)](https://cloud.githubusercontent.com/assets/591567/8478621/d247247e-20d2-11e5-993d-79096e382abd.png) * Include external dependencies, limit the depth and save the output from `stack dot` as an intermediate file (`wreq.dot`). ~~~text stack dot --external --depth 1 > wreq.dot dot -Tpng -o wreq.png wreq.dot ~~~ * Include external dependencies, exclude `base` and limit the depth: ~~~text stack dot --no-include-base --external --depth 1 | dot -Tpng -o wreq.png ~~~ [![wreq_depth](https://cloud.githubusercontent.com/assets/591567/8484310/45b399a0-20f7-11e5-8068-031c2b352961.png)](https://cloud.githubusercontent.com/assets/591567/8484310/45b399a0-20f7-11e5-8068-031c2b352961.png) * Include external dependencies and prune `base` and other packages: ~~~text stack dot --external --prune base,lens,wreq-examples,http-client,aeson,tls,http-client-tls,exceptions | dot -Tpng -o wreq.png ~~~ [![wreq_pruned](https://cloud.githubusercontent.com/assets/591567/8478768/adbad280-20d3-11e5-9992-914dc24fe569.png)](https://cloud.githubusercontent.com/assets/591567/8478768/adbad280-20d3-11e5-9992-914dc24fe569.png) * Include external dependencies, prune `base` and other packages, and use a different Graphviz executable to draw the graph: Graphviz's `twopi` executable draws graphs in a radial layout. ~~~text stack dot --external --prune base,lens,wreq-examples,http-client,aeson,tls,http-client-tls,exceptions | twopi -Groot=wreq -Goverlap=false -Tpng -o wreq.png ~~~ [![wreq_pruned](https://cloud.githubusercontent.com/assets/591567/8495538/9fae1184-216e-11e5-9931-99e6147f8aed.png)](https://cloud.githubusercontent.com/assets/591567/8495538/9fae1184-216e-11e5-9931-99e6147f8aed.png) stack-2.9.3.1/doc/editor_integration.md0000644000000000000000000000164614353310533016146 0ustar0000000000000000
# Editor integration ## Visual Studio Code For further information, see the [Stack and Visual Code](Stack_and_VS_Code.md) documentation. ## The `intero` project For editor integration, Stack has a related project called [intero](https://github.com/commercialhaskell/intero). It is particularly well supported by Emacs, but some other editors have integration for it as well. ## Shell auto-completion Love tab-completion of commands? You're not alone. If you're on bash, just run the following command (or add it to `.bashrc`): ~~~text eval "$(stack --bash-completion-script stack)" ~~~ For more information and other shells, see the [Shell auto-completion wiki page](https://docs.haskellstack.org/en/stable/shell_autocompletion) stack-2.9.3.1/doc/environment_variables.md0000644000000000000000000000654514445022466016663 0ustar0000000000000000
# Stack's environment variables The environment variables listed in alphabetal order below can affect how Stack behaves. ## `HACKAGE_KEY` [:octicons-tag-24: 2.7.5](https://github.com/commercialhaskell/stack/releases/tag/v2.7.5) Related command: [`stack upload`](upload_command.md) Hackage allows its members to register an API authentification token and to authenticate using the token. A Hackage API authentification token can be used with `stack upload` instead of username and password, by setting the `HACKAGE_KEY` environment variable. For example: === "Unix-like" ~~~text HACKAGE_KEY= stack upload . ~~~ === "Windows (with PowerShell)" ~~~text $Env:HACKAGE_KEY= stack upload . ~~~ ## `HACKAGE_USERNAME` and `HACKAGE_PASSWORD` [:octicons-tag-24: 2.3.1](https://github.com/commercialhaskell/stack/releases/tag/v2.3.1) Related command: [`stack upload`](upload_command.md) `stack upload` will request a Hackage username and password to authenticate. This can be avoided by setting the `HACKAGE_USERNAME` and `HACKAGE_PASSWORD` environment variables. For example: === "Unix-like" ~~~text export $HACKAGE_USERNAME="" export $HACKAGE_PASSWORD="" stack upload . ~~~ === "Windows (with PowerShell)" ~~~text $Env:HACKAGE_USERNAME='' $Env:HACKAGE_PASSWORD='' stack upload . ~~~ ## `NO_COLOR` Related command: all commands that can produce colored output using control character sequences. Stack follows the standard at http://no-color.org/. Stack checks for a `NO_COLOR` environment variable. When it is present and not an empty string (regardless of its value), Stack prevents the addition of control character sequences for color to its output. ## `STACK_ROOT` Related command: all commands that make use of Stack's global YAML configuration file (`config.yaml`). Overridden by: Stack's global `--stack-root` option. The environment variable `STACK_ROOT` can be used to specify the Stack root directory. ## `STACK_WORK` Related command: all commands that make use of Stack's working directory. Overridden by: Stack's global `--work-dir` option. The environment variable `STACK_YAML` can be used to specify Stack's working directory in a project. The path must be a relative one, relative to the root directory of the project. ## `STACK_XDG` Related command: all commands that make use of Stack's user-specific general YAML configuration file (`config.yaml`). Overridden by: the use of Stack's `STACK_ROOT` environment variable, or the use of Stack's global `--stack-root` option. On Unix-like operating systems and Windows, Stack can be configured to follow the XDG Base Directory Specification if the environment variable `STACK_XDG` is set to any non-empty value. ## `STACK_YAML` Related command: all commands that make use of Stack's project-level YAML configuration file. Overridden by: Stack's global `--stack-yaml` option. The environment variable `STACK_YAML` can be used to specify Stack's project-level YAML configuration file. stack-2.9.3.1/doc/eval_command.md0000644000000000000000000000132014353310533014667 0ustar0000000000000000
# The `stack eval` command ~~~text stack eval CODE [--[no-]ghc-package-path] [--[no-]stack-exe] [--package PACKAGE] [--rts-options RTSFLAG] [--cwd DIR] ~~~ GHC has an [expression-evaluation mode](https://downloads.haskell.org/ghc/latest/docs/users_guide/using.html#eval-mode), set by passing the GHC option `-e `. Commanding `stack eval ` is equivalent to commanding: ~~~text stack exec ghc -- -e ~~~ For further information, see the [`stack exec` command](exec_command.md) documentation. stack-2.9.3.1/doc/exec_command.md0000644000000000000000000000327314353310533014675 0ustar0000000000000000
# The `stack exec` command ~~~text stack exec COMMAND [-- ARGUMENT(S) (e.g. stack exec ghc-pkg -- describe base)] [--[no-]ghc-package-path] [--[no-]stack-exe] [--package PACKAGE] [--rts-options RTSFLAG] [--cwd DIR] ~~~ `stack exec` executes the specified executable as a command in the Stack environment. If an executable is not specified, the first argument after `--` is taken to be the executable. Otherwise, all arguments after `--` are taken to be command line arguments for the specified executable. By default: * the `GHC_PACKAGE_PATH` environment variable is set for the command's process. Pass the flag `--no-ghc-package-path` to not set the environment variable; * the `STACK_EXE` environment variable is set for the command's process. Pass the flag `--no-stack-exe` to not set the environment variable; and * the specified executable is executed in the current directory. Pass the option `--cwd ` to execute the executable in the specified directory. The option `--package ` has no effect for the `stack exec` command. For further information about its use, see the [`stack ghc` command](ghc_command.md) documentation or the [`stack runghc` command](runghc_command.md) documentation. Pass the option `--rts-option ` to specify a GHC RTS flag or option. The option can be specified multiple times. All specified GHC RTS flags and options are added to the arguments for the specified executable between arguments `+RTS` and `-RTS`. stack-2.9.3.1/doc/faq.md0000644000000000000000000007055214445022466013035 0ustar0000000000000000
# FAQ So that this doesn't become repetitive: for the reasons behind the answers below, see the [Build overview](build_overview.md) page. The goal of the answers here is to be as helpful and concise as possible. ## What version of GHC is used when I run something like `stack ghci`? The version of GHC, as well as which packages can be installed, are specified by the _resolver_. This may be something like `lts-19.19`, which is from [Stackage](https://www.stackage.org/). The [user's guide](GUIDE.md) discusses the resolver in more detail. The resolver is determined by finding the relevant project-level configuration file (`stack.yaml`) for the directory you're running the command from. This essentially works by: 1. Check for a `STACK_YAML` environment variable or the `--stack-yaml` command line argument 2. If none present, check for a `stack.yaml` file in the current directory or any parents 3. If no `stack.yaml` file was found, use the _implicit global_ The implicit global is a shared project used whenever you're outside of another project. It's a sort of "mutable shared state" that you should be aware of when working with Stack. A frequent request when working with the implicit global is how to move to a more recent LTS snapshot. You can do this using the following command from outside of a project: ~~~text stack config set resolver lts ~~~ ## Where is Stack installed and will it interfere with the GHC (etc) I already have installed? Stack itself is installed in normal system locations based on the mechanism you used (see the [Install and upgrade](install_and_upgrade.md) page). Stack installs files in the Stack root and other files in a `.stack-work` directory within each project's directory. None of this should affect any existing Haskell tools at all. ## What is the relationship between Stack and Cabal (the tool)? * 'Cabal' can refer to Cabal (the library) or to Cabal (the tool). Cabal (the library) is used by Stack to build your Haskell code. Cabal (the tool) is provided by the `cabal-install` package. * A Cabal file is provided for each package, named `.cabal`. It defines all package-level metadata, just like it does in the world of Cabal (the tool): modules, executables, test suites, etc. No change at all on this front. * A `stack.yaml` file references one or more packages, and provides information on where dependencies come from. * The `stack init` command initializes a `stack.yaml` file from an existing Cabal file. * Stack uses Cabal (the library) via an executable. For `build-type: Simple` (the most common case), Stack builds that executable using the version of Cabal which came with the compiler. Stack caches such executables, in the Stack root under directory `setup-exe-cache`. * In rare or complex cases, a different version of Cabal to the one that came with the compiler may be needed. `build-type: Custom` and a `setup-custom` stanza in the Cabal file, and a `Setup.hs` file in the package directory, can be specified. The `stack.yaml` file can then specify the version of Cabal that Stack will use to build the executable (named `setup`) from `Setup.hs`. Stack will use Cabal via `setup`. For detail on the differences between a `stack.yaml` file and a Cabal file, see [stack.yaml vs a Cabal file](stack_yaml_vs_cabal_package_file.md). ## I need to use a different version of a package than what is provided by the LTS Haskell snapshot I'm using, what should I do? You can make tweaks to a snapshot by modifying the `extra-deps` configuration value in your `stack.yaml` file, e.g.: ~~~yaml resolver: lts-19.19 packages: - '.' extra-deps: - text-2.0.1 ~~~ ## I need to use a package (or version of a package) that is not available on Hackage, what should I do? Add it to the [`extra-deps`](yaml_configuration.md#extra-deps) list in your project's `stack.yaml` file, specifying the package's source code location relative to the directory where your `stack.yaml` file lives, e.g. ~~~yaml resolver: lts-19.19 packages: - '.' extra-deps: - third-party/proprietary-dep - github-version-of/conduit - patched/diagrams ~~~ The above example specifies that the `proprietary-dep` package is found in the project's `third-party` directory, that the `conduit` package is found in the project's `github-version-of` directory, and that the `diagrams` package is found in the project's `patched` directory. This autodetects changes and reinstalls the package. To install packages directly from a Git repository, use e.g.: ~~~yaml extra-deps: - git: https://github.com/githubuser/reponame.git commit: somecommitID ~~~ ## What is the meaning of the arguments given to `stack build`, `test`, etc? Those are the targets of the build, and can have one of three formats: * A package name (e.g., `my-package`) will mean that the `my-package` package must be built * A package identifier (e.g., `my-package-1.2.3`), which includes a specific version. This is useful for passing to `stack install` for getting a specific version from upstream * A directory (e.g., `./my-package`) for including a local directory's package, including any packages in subdirectories ## I need to modify an upstream package, how should I do it? Typically, you will want to get the source for the package and then add it to your `packages` list in the `stack.yaml` file. (See the previous question.) `stack unpack` is one approach for getting the source. Another would be to add the upstream package as a submodule to your project. ## How do I use this with sandboxes? Explicit sandboxing on the part of the user is not required by Stack. All builds are automatically isolated into separate package databases without any user interaction. This ensures that you won't accidentally corrupt your installed packages with actions taken in other projects. ## Can I run `cabal` commands inside `stack exec`? With a recent enough version of Cabal (the tool) (1.22 or later), you can. For earlier versions this does not work, due to Cabal issue [#1800](https://github.com/haskell/cabal/issues/1800). Note that even with recent versions, for some commands you may need the following extra level of indirection. Command: ~~~text stack exec -- cabal exec -- cabal ~~~ However, virtually all `cabal` commands have an equivalent in Stack, so this should not be necessary. In particular, users of Cabal (the tool) may be accustomed to the `cabal run` command. With Stack, command: ~~~text stack build stack exec ~~~ Or, if you want to install the binaries in a shared location, command: ~~~text stack install ~~~ assuming your PATH has been set appropriately. ## Using custom preprocessors If you have a custom preprocessor, for example, Ruby, you may have a file like: ***B.erb*** ~~~haskell module B where <% (1..5).each do |i| %> test<%= i %> :: Int test<%= i %> = <%= i %> <% end %> ~~~ To ensure that Stack picks up changes to this file for rebuilds, add the following lines to your `stack.yaml` file: ~~~yaml custom-preprocessor-extensions: - erb require-stack-version: ">= 2.6.0" ~~~ And for backwards compatability with older versions of Stack, also add the following line to your Cabal file: extra-source-files: B.erb You could also use the [`--custom-preprocessor-extensions`](yaml_configuration.md#custom-preprocessor-extensions) flag. ## I already have GHC installed, can I still use Stack? Yes. In its default configuration, Stack will simply ignore any system GHC installation and use a sandboxed GHC that it has installed itself. You can find these sandboxed GHC installations in the `ghc-*` directories in the `stack path --programs` directory. If you would like Stack to use your system GHC installation, use the [`--system-ghc`](yaml_configuration.md#system-ghc) flag or run `stack config set system-ghc --global true` to make Stack check your PATH for a suitable GHC by default. Stack can only use a system GHC installation if its version is compatible with the configuration of the current project, particularly the [`resolver` or `snapshot`](yaml_configuration.md#resolver-or-snapshot) setting. GHC installation doesn't work for all operating systems, so in some cases you will need to use `system-ghc` and install GHC yourself. ## How does Stack determine what GHC to use? In its default configuration, Stack determines from the current project which GHC version, architecture etc it needs. It then looks in the `ghc-` subdirectory of the `stack path --programs` directory for a compatible GHC, requesting to install one via `stack setup` if none is found. If you are using the [`--system-ghc`](yaml_configuration.md/#system-ghc) flag or have configured `system-ghc: true` either in the project `stack.yaml` or the global `config.yaml`, Stack will use the first GHC that it finds on your PATH, falling back on its sandboxed installations only if the found GHC doesn't comply with the various requirements (version, architecture) that your project needs. See issue [#420](https://github.com/commercialhaskell/stack/issues/420) for a detailed discussion of Stack's behavior when `system-ghc` is enabled. ## How do I upgrade to GHC 7.10.2 with stack? If you already have a prior version of GHC use `stack --resolver ghc-7.10 setup --reinstall`. If you don't have any GHC installed, you can skip the `--reinstall`. ## How do I get extra build tools? Stack will automatically install build tools required by your packages or their dependencies, in particular [Alex](https://hackage.haskell.org/package/alex) and [Happy](https://hackage.haskell.org/package/happy). !!! note This works when using LTS or nightly resolvers, not with GHC or custom resolvers. You can manually install build tools by running, e.g., `stack build alex happy`. ## How does Stack choose which snapshot to use when creating a new configuration file? It checks the two most recent LTS Haskell major versions and the most recent Stackage Nightly for a snapshot that is compatible with all of the version bounds in your Cabal file, favoring the most recent LTS. For more information, see the snapshot auto-detection section in the architecture document. ## I'd like to use my installed packages in a different directory. How do I tell Stack where to find my packages? Set the `STACK_YAML` environment variable to point to the `stack.yaml` configuration file for your project. Then you can run `stack exec`, `stack ghc`, etc., from any directory and still use your packages. ## My tests are failing. What should I do? Like all other targets, `stack test` runs test suites in parallel by default. This can cause problems with test suites that depend on global resources such as a database or binding to a fixed port number. A quick hack is to force stack to run all test suites in sequence, using `stack test --jobs=1`. For test suites to run in parallel developers should ensure that their test suites do not depend on global resources (e.g. by asking the operating system for a random port to bind to) and where unavoidable, add a lock in order to serialize access to shared resources. ## Can I get bash autocompletion? Yes, see the [shell-autocompletion](shell_autocompletion.md) documentation. ## How do I update my package index? Users of Cabal (the tool) are used to running `cabal update` regularly. You can do the same with Stack by running `stack update`. But generally, it's not necessary: if the package index is missing, or if a snapshot refers to package/version that isn't available, Stack will automatically update and then try again. If you run into a situation where Stack doesn't automatically do the update for you, please report it as a bug. ## Isn't it dangerous to automatically update the index? Can't that corrupt build plans? No, Stack is very explicit about which packages it's going to build for you. There are three sources of information to tell it which packages to install: the selected snapshot, the `extra-deps` configuration value, and your local packages. The only way to get Stack to change its build plan is to modify one of those three. Updating the index will have no impact on Stack's behavior. ## I have a custom package index I'd like to use, how do I do so? You can configure this in your project-level configuration file (`stack.yaml`). See [YAML configuration](yaml_configuration.md). ## How can I make sure my project builds against multiple GHC versions? You can create multiple YAML configuration files for your project, one for each build plan. For example, you might set up your project directory like so: ~~~text myproject/ stack-ghc-9.0.2.yaml stack-ghc-9.2.4.yaml stack.yaml --> symlink to stack-ghc-9.2.4.yaml myproject.cabal src/ ... ~~~ When you run `stack build`, you can set the `STACK_YAML` environment variable to indicate which build plan to use. On Unix-like operating systems command: ~~~bash stack build # builds using the default stack.yaml STACK_YAML=stack-ghc-7.10.yaml stack build # builds using the given yaml file ~~~ On Windows (with PowerShell) command: ~~~ps $Env:STACK_YAML='stack-ghc-9.0.2.yaml' stack build ~~~ ## I heard you can use this with Docker? Yes, Stack supports using Docker with images that contain preinstalled Stackage packages and the tools. See [Docker integration](docker_integration.md) for details. ## How do I use this with Travis CI? See the [Travis CI instructions](travis_ci.md) ## How do I use this with Azure CI? See the [Azure CI instructions](azure_ci.md) ## What is licensing restrictions on Windows? Currently, on Windows, GHC produces binaries linked statically with [GNU Multiple Precision Arithmetic Library](https://gmplib.org/) (GMP), which is used by [integer-gmp](https://hackage.haskell.org/package/integer-gmp) library to provide big integer implementation for Haskell. Contrary to the majority of Haskell code licensed under permissive BSD3 license, GMP library is licensed under LGPL, which means resulting binaries [have to be provided with source code or object files](http://www.gnu.org/licenses/gpl-faq.html#LGPLStaticVsDynamic). That may or may not be acceptable for your situation. Current workaround is to use GHC built with alternative big integer implementation called `integer-simple`, which is free from LGPL limitations as it's pure Haskell and does not use GMP. Unfortunately it has yet to be available out of the box with Stack. See issue [#399](https://github.com/commercialhaskell/stack/issues/399) for the ongoing effort and information on workarounds. ## How to get a working executable on Windows? When executing a binary after building with `stack build` (e.g. for target "foo"), the command `foo.exe` might complain about missing runtime libraries (whereas `stack exec foo` works). Windows is not able to find the necessary C++ libraries from the standard prompt because they're not in the PATH environment variable. `stack exec` works because it's modifying PATH to include extra things. Those libraries are shipped with GHC (and, theoretically in some cases, MSYS). The easiest way to find them is `stack exec which`. For example, command: ~~~text stack exec -- which libstdc++-6.dll /c/Users/Michael/AppData/Local/Programs/stack/i386-windows/ghc-7.8.4/mingw/bin/libstdc++-6.dll ~~~ A quick workaround is adding this path to the PATH environment variable or copying the files somewhere Windows finds them (see https://msdn.microsoft.com/de-de/library/7d83bc18.aspx). See issue [#425](https://github.com/commercialhaskell/stack/issues/425). Another issue that may arise with building on Windows is as follows. The default location of Stack's programs folder is `%LOCALAPPDATA\Programs\stack`. If there is a space character in the `%LOCALAPPDATA%` path this may, in some circumstances, cause problems with building packages that make use of the GNU project's `autoconf` package and `configure` shell script files. It may be necessary to override the default location of Stack's programs folder. See the [local-programs-path](yaml_configuration.md#local-programs-path) option for more information. See issue [#4726](https://github.com/commercialhaskell/stack/issues/4726). ## Can I change Stack's default temporary directory? Stack downloads and extracts files to `$STACK_ROOT/programs` on most platforms, which defaults to `~/.stack/programs`. On Windows `$LOCALAPPDATA\Programs\stack` is used. If there is not enough free space in this directory, Stack may fail. For instance, `stack setup` with a GHC installation requires roughly 1GB free. If this is an issue, you can set `local-programs-path` in your `~/.stack/config.yaml` to a directory on a file system with more free space. If you use Stack with Nix integration, be aware that Nix uses a `TMPDIR` variable, and if it is not set Nix sets it to some subdirectory of `/run`, which on most Linuxes is a Ramdir. Nix will run the builds in `TMPDIR`, therefore if you don't have enough RAM you will get errors about disk space. If this happens to you, please _manually_ set `TMPDIR` before launching Stack to some directory on the disk. ## Why doesn't Stack rebuild my project when I specify `--ghc-options` on the command line? Because GHC options often only affect optimization levels and warning behavior, Stack doesn't recompile when it detects an option change by default. This behavior can be changed though by setting the [`rebuild-ghc-options` option](yaml_configuration.md#rebuild-ghc-options) to `true`. To force recompilation manually, use the `--force-dirty` flag. If this still doesn't lead to a rebuild, add the `-fforce-recomp` flag to your `--ghc-options`. ## Why doesn't Stack apply my `--ghc-options` to my dependencies? By default, Stack applies command line GHC options only to local packages (these are all the packages that are specified in the `packages` section of your `stack.yaml` file). For an explanation of this choice see this discussion on issue [#827](https://github.com/commercialhaskell/stack/issues/827#issuecomment-133263678). If you still want to set specific GHC options for a dependency, use the [`ghc-options`](yaml_configuration.md#ghc-options) option in your YAML configuration file. To change the set of packages that command line GHC options apply to, use the [`apply-ghc-options`](yaml_configuration.md#apply-ghc-options) option. ## `stack setup` on a Windows system only tells me to add certain paths to the PATH variable instead of doing it With PowerShell, it is easy to automate even that step. Command: ~~~ps $Env:Path = ( stack setup | %{ $_ -replace '[^ ]+ ', ''} ), $Env:Path -join ";" ~~~ ## How do I reset/remove Stack (such as to do a completely fresh build)? The first thing to remove is project-specific `.stack-work` directory within the project's directory. Next, remove the Stack root directory overall. You may have errors if you remove the latter but leave the former. Removing Stack itself will relate to how it was installed, and if you used GHC installed outside of Stack, that would need to be removed separately. ## How does Stack handle parallel builds? What exactly does it run in parallel? See issue [#644](https://github.com/commercialhaskell/stack/issues/644) for more details. ## I get strange `ld` errors about recompiling with "-fPIC" (Updated in January 2019) This is related to more recent versions of Linux distributions that have GCC with PIE enabled by default. The continuously-updated distros like Arch, in particular, had been in flux with this change and the upgrading libtinfo6/ncurses6, and there were some workarounds attempted in Stack that ended up causing trouble as these distros evolved. GHC added official support for this setup in 8.0.2, so if you are using an older version your best bet is to upgrade. You may be able to work around it for older versions by editing `~/.stack/programs/x86_64-osx/ghc-VER/lib/ghc- VER/settings` (replace `VER` with the GHC version) and adding `-no-pie` (or `--no-pie` in the case of Gentoo, at least as of December 2017) to the __C compiler link flags__. If `stack setup` complains that there is no `linuxNN-*-nopie` bindist available, try adding `ghc-build: *` (replacing the `*` with the actual value that precedes `-nopie`, which may be empty) to your `~/.stack/config.yaml` (this will no longer be necessary for stack >= 1.7). If you are experiencing this with GHC >= 8.0.2, try running `stack setup --reinstall` if you've upgraded your Linux distribution or you set up GHC before late December 2017. If GHC doesn't recognize your C compiler as being able to use `-no-pie`, this can happen even with GCC and Clang, it might be necessary to enable this feature manually. To do this, just change `("C compiler supports -no-pie", "NO"),` to `("C compiler supports -no-pie", "YES"),` in the file `~/.stack/programs/x86_64-osx/ghc-VER/lib/ghc-VER/settings`. If you are still having trouble after trying the above, check the following for more possible workarounds: * Previous version of this [FAQ entry](https://docs.haskellstack.org/en/v1.6.3/faq/#i-get-strange-ld-errors-about-recompiling-with-fpic) * Related issues: [#3518](https://github.com/commercialhaskell/stack/issues/3518), [#2712](https://github.com/commercialhaskell/stack/issues/2712), [#3630](https://github.com/commercialhaskell/stack/issues/3630), [#3648](https://github.com/commercialhaskell/stack/issues/3648) ## Where does the output from `--ghc-options=-ddump-splices` (and other `-ddump*` options) go? These are written to `*.dump-*` files inside the package's `.stack-work` directory. Specifically, they will be available at `PKG-DIR/$(stack path --dist-dir)/build/SOURCE-PATH`, where `SOURCE-PATH` is the path to the source file, relative to the location of the Cabal file. When building named components such as test-suites, `SOURCE-PATH` will also include `COMPONENT/COMPONENT-tmp`, where `COMPONENT` is the name of the component. ## Why is DYLD_LIBRARY_PATH ignored? If you are on Mac OS X 10.11 ("El Capitan") or later, there is a GHC issue [#11617](https://ghc.haskell.org/trac/ghc/ticket/11617) which prevents the `DYLD_LIBRARY_PATH` environment variable from being passed to GHC (see issue [#1161](https://github.com/commercialhaskell/stack/issues/1161)) when System Integrity Protection (a.k.a. "rootless") is enabled. There are two known workarounds: 1. Known to work in all cases: [disable System Integrity Protection](http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/). **WARNING: Disabling SIP will severely reduce the security of your system, so only do this if absolutely necessary!** 2. Experimental: modify GHC's shell script wrappers to use a shell outside the protected directories (see issue [#1161](https://github.com/commercialhaskell/stack/issues/1161#issuecomment-186690904)). ## Why do I get a `/usr/bin/ar: permission denied` error? If you are on OS X 10.11 ("El Capitan") or later, GHC 7.8.4 is incompatible with System Integrity Protection (a.k.a. "rootless") (see issue [#563](https://github.com/commercialhaskell/stack/issues/563)). GHC 7.10.2 includes a fix, so this only affects users of GHC 7.8.4. If you cannot upgrade to GHC 7.10.2, you can work around it by [disabling System Integrity Protection](http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/). **WARNING: Disabling SIP will severely reduce the security of your system, so only do this if absolutely necessary!** ## Why is the `--` argument separator ignored in Windows PowerShell Some versions of Windows PowerShell don't pass the `--` to programs (see issue [#813](https://github.com/commercialhaskell/stack/issues/813)). The workaround is to quote the `"--"`. For example, command: ~~~ps stack exec "--" cabal --version ~~~ This is known to be a problem on Windows 7, but seems to be fixed on Windows 10. ## Does Stack also install the system/C libraries that some Cabal packages depend on? No, this is currently out of the scope of Stack's target set of features. Instead of attempting to automate the installation of 3rd party dependencies, we have the following approaches for handling system dependencies: * Nix and docker help make your build and execution environment deterministic and predictable. This way, you can install system dependencies into a container, and share this container with all developers. * If you have installed some libraries into a non-standard location, use the [`extra-lib-dirs`](yaml_configuration.md#extra-lib-dirs) option or the [`extra-include-dirs`](yaml_configuration.md#extra-include-dirs) option to specify it. In the future, Stack might give operating system-specific suggestions for how to install system libraries. ## How can I make Stack aware of my custom SSL certificates? ### macOS In principle, you can use the following command to add a certificate to your system certificate keychain: ~~~bash sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~~~ Some users have reported issues with this approach, see issue [#907](https://github.com/commercialhaskell/stack/issues/907) for more information. ### Other *NIX OSs Use the `SYSTEM_CERTIFICATE_PATH` environment variable to point at the directory where you keep your SSL certificates. ## How do I get `verbose` output from GHC when I build? Add `ghc-options: -vN` to the Cabal file or pass it via `stack build --ghc-options="-v"`. ## Does Stack support the Hpack specification? Yes: * If a package directory contains an [Hpack](https://github.com/sol/hpack) `package.yaml` file, then Stack will use it to generate a Cabal file when building the package. * You can run `stack init` to initialize a `stack.yaml` file regardless of whether your packages are declared with Cabal files or with Hpack `package.yaml` files. * You can use the `with-hpack` YAML configuration or command line option to specify an Hpack executable to use instead of Stack's in-built Hpack functionality. ## How do I resolve linker errors when running `stack setup` or `stack build` on macOS? This is likely to be caused by having both a LLVM installation and default Apple Clang compiler on the PATH. The symptom of this issue is a linker error "bad relocation (Invalid pointer diff)". The compiler picks up inconsistent versions of binaries and the mysterious error occurs. The workaround is to remove LLVM binaries from the PATH. ## How do I suppress `'-nopie'` warnings with `stack build` on macOS? ~~~bash clang: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument] ~~~ This warning is shown when compiler support of `-no-pie` is expected but unavailable. It's possible to bypass the warning for a specific version of GHC by modifying a global setting: ~~~bash # ~/.stack/programs/x86_64-osx/ghc-8.2.2/lib/ghc-8.2.2/settings -- ("C compiler supports -no-pie", "YES"), ++ ("C compiler supports -no-pie", "NO"), ~~~ **Note that we're fixing `ghc-8.2.2` in this case; repeat for other versions as necessary.** You should apply this fix for the version of GHC that matches your resolver. Issue [#4009](https://github.com/commercialhaskell/stack/issues/4009) goes into further detail. ## How do I install GHC in Stack when it fails with the error: Missing ghc bindist for "linux64-ncurses6"? Example Error: ~~~text No setup information found for ghc-8.6.4 on your platform. This probably means a GHC bindist has not yet been added for OS key 'linux64-ncurses6'. Supported versions: ghc-7.10.3, ghc-8.0.1, ghc-8.0.2, ghc-8.2.1, ghc-8.2.2 ~~~ Most Linux distributions have standardized on providing libtinfo.so.6 (either directly or as a symlink to libncursesw.so.6). As such, there aren't GHC 8.6.* bindists that link to libncursesw.so.6 available. So creating a symlink to libncursesw.so.6 as libtinfo.so.6 can prevent this error (root privileges might be required). Command: ~~~bash ln -s /usr/lib/libncursesw.so.6 /usr/lib/libtinfo.so.6 ~~~ stack-2.9.3.1/doc/ghc_command.md0000644000000000000000000000143314445022466014515 0ustar0000000000000000
# The `stack ghc` command ~~~text stack ghc [-- ARGUMENT(S) (e.g. stack ghc -- X.hs -o x)] [--[no-]ghc-package-path] [--[no-]stack-exe] [--package PACKAGE] [--rts-options RTSFLAG] [--cwd DIR] ~~~ `stack ghc` has the same effect as, and is provided as a shorthand for, [`stack exec ghc`](exec_command.md), with the exception of the `--package` option. Pass the option `--package ` to add the initial GHC argument `-package-id=`, where `` is the unit ID of the specified package in the installed package database. The option can be specified multiple times. stack-2.9.3.1/doc/ghci.md0000644000000000000000000001173414445022466013175 0ustar0000000000000000
# The `stack ghci` and `stack repl` commands ~~~text stack ghci [TARGET/FILE] [--pedantic] [--ghci-options OPTIONS] [--ghc-options OPTIONS] [--flag PACKAGE:[-]FLAG] [--with-ghc GHC] [--[no-]load] [--package PACKAGE] [--main-is TARGET] [--load-local-deps] [--[no-]package-hiding] [--only-main] [--trace] [--profile] [--no-strip] [--[no-]test] [--[no-]bench] ~~~ A read–evaluate–print loop (REPL) environment takes single user inputs, executes them, and returns the result to the user. GHCi is GHC's interactive environment. The `stack ghci` or `stack repl` commands, which are equivalent, allow you to load components and files of your project into GHCi. The command uses the same TARGET syntax as `stack build`. It can also take flags like `--test` and `--bench` and options like `--flag`. Similarly to `stack build`, the default is to load up GHCi with all libraries and executables in the project. In order to load multiple components, `stack ghci` combines all of the GHC options together. This doesn't work in the general case, but when the packages being loaded share similar conventions, it should work out. A common source of issues is when one component defines default extensions which aren't assumed by another component. For example, specifying `NoImplicitPrelude` in one component but not another is quite likely to cause failures. GHCi will be run with `-XNoImplicitPrelude`, but it is likely that modules in the other component assume that the `Prelude` is implicitly imported. ## Selecting Main module When loading multiple packages, there may be multiple definitions for the `Main` module. You can specify which `Main` module to load with the `--main-is ` option. If no selection is made and there are multiple `Main` modules, you will be asked to select from a list of options. ## Speeding up initial load There are two ways to speed up the initial startup of GHCi: 1. Pass the `--no-build` flag, to skip an initial build step. This works only if the dependencies have already been built. 2. Pass the `--no-load` flag, to skip loading all defined modules into GHCi. You can then directly use `:load MyModule` in GHCi to load a specific module in your project. ## Loading just the main module By default, `stack ghci` loads and imports all of the modules in the package. This allows you to easily use anything exported by your package. This is usually quite convenient, but in some cases it makes sense to only load one module, or no modules at all. The `--only-main` flag allows this. It specifies that only the main module will be loaded, if any. This is particularly useful in the following circumstances: 1. You're loading the project in order to run it in GHCi (e.g. via `main`), and you intend to reload while developing. Without the `--only-main` flag, you will need to quit and restart GHCi whenever a module gets deleted. With the flag, reloading should work fine in this case. 2. If many of your modules have exports named the same thing, then you'll need to refer to them using qualified names. To avoid this, it may be easier to use the `--only-main` flag to start with a blank slate and just import the modules you are interested in. ## Loading a filepath directly Instead of the `TARGET` syntax, it is also possible to command directly, for example: ~~~text stack ghci src/MyFile.hs ~~~ This will figure out which component the file is associated with, and use the options from that component. ## Specifying extra packages to build or depend on Sometimes you want to load GHCi with an additional package, that isn't a direct dependency of your components. This can be achieved by using the `--package` option. For example, if I want to experiment with the `lens` library, I can command: ~~~text stack ghci --package lens ~~~ ## Running plain GHCi `stack ghci` always runs GHCi configured to load code from packages in your project. In particular, this means it passes in flags like `-hide-all-packages` and `-package-id=` in order to configure which packages are visible to GHCi. For doing experiments which just involve packages installed in your databases, it may be useful to run GHCi plainly like: ~~~text stack exec ghci ~~~ This will run a plain GHCi in an environment which includes `GHC_PACKAGE_PATH`, and so will have access to your databases. !!! note Running `stack ghci` on a pristine copy of the code doesn't currently build libraries (issue [#2790](https://github.com/commercialhaskell/stack/issues/2790)) or internal libraries (issue [#4148](https://github.com/commercialhaskell/stack/issues/4148)). It is recommended to always use `stack build` before using `stack ghci`, until these two issues are closed. stack-2.9.3.1/doc/global_flags.md0000644000000000000000000002517214445022466014700 0ustar0000000000000000
# Stack's global flags and options Stack can also be configured by flags and options on the command line. Global flags and options apply to all of Stack's commands. In addition, all of Stack's commands accept the `--setup-info-yaml` and `--snapshot-location-base` options and the `--help` flag. ## The `--allow-different-user` flag Restrictions: POSIX systems only Default: True, if inside Docker; false otherwise Enable/disable permitting users other than the owner of the Stack root directory to use a Stack installation. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#allow-different-user). ## The `--arch` option Pass the option `--arch ` to specify the relevant machine architecture. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#arch). ## The `--color` or `-colour` options Pass the option `stack --color ` to specify when to use color in output. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#color). ## The `--compiler` option Pass the option `--compiler ` to specify the compiler. For further information, see the [YAML configuration](yaml_configuration.md#compiler) documentation. ## The `--custom-preprocessor-extensions` option Pass the option `--custom-preprocessor-extensions ` to specify an extension used for a custom preprocessor. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#custom-preprocessor-extensions). ## The `--docker*` flags and options Stack supports automatically performing builds inside a Docker container. For further information see `stack --docker-help` or the [Docker integratiom](docker_integration.md) documentation. ## The `--[no-]dump-logs` flag Default: Dump warning logs Enables/disables the dumping of the build output logs for local packages to the console. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#dump-logs). ## The `--extra-include-dirs` option Pass the option `--extra-include-dirs ` to specify an extra directory to check for C header files. The option can be specified multiple times. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#extra-include-dirs). ## The `--extra-lib-dirs` option Pass the option `--extra-lib-dirs ` to specify an extra directory to check for libraries. The option can be specified multiple times. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#extra-lib-dirs). ## The `--ghc-build` option Pass the option `--ghc-build ` to specify the relevant specialised GHC build. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#ghc-build). ## The `--ghc-variant` option Pass the option `--ghc-variant ` to specify the relevant GHC variant. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#ghc-variant). ## The `--hpack-numeric-version` flag Pass the flag `--hpack-numeric-version` to cause Stack to report the numeric version of its built-in Hpack library to standard output (e.g. `0.35.0`) and quit. ## The `--[no-]install-ghc` flag Default: Enabled Enables/disables the download and instalation of GHC if necessary. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#install-ghc). ## The `--jobs` or `-j` option Pass the option `--jobs ` to specify the number of concurrent jobs to run. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#jobs). ## The `--local-bin-path` option Pass the option `--local-bin-path ` to specify the directory in which Stack installs executables. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#local-bin-path). ## The `--lock-file` option Default: `read-write`, if snapshot specified in YAML configuration file; `read-only`, if a different snapshot is specified on the command line. Pass the option `--lock-file ` to specify how Stack interacts with lock files. Valid modes are `error-on-write`, `ignore`, `read-only` and `read-write`. ## The `--[no-]modify-code-page` flag Restrictions: Windows systems only Default: Enabled Enables/disables setting the codepage to support UTF-8. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#modify-code-page). ## The `--nix*` flags and options Stack can be configured to integrate with Nix. For further information, see `stack --nix-help` or the [Nix integration](nix_integration.md) documentation. ## The `--numeric-version` flag Pass the flag `--numeric-version` to cause Stack to report its numeric version to standard output (e.g. `2.9.1`) and quit. ## The `--resolver` option Pass the option `--resolver ` to specify the snapshot. For further information, see the [YAML configuration](yaml_configuration.md#resolver-or-snapshot) documentation. ## The `--[no-]rsl-in-log` flag [:octicons-tag-24: 2.9.1](https://github.com/commercialhaskell/stack/releases/tag/v2.9.1) Default: Disabled Enables/disables the logging of the raw snapshot layer (rsl) in debug output. Information about the raw snapshot layer can be lengthy. If you do not need it, it is best omitted from the debug output. ## The `--[no-]script-no-run-compile` flag Default: Disabled Enables/disables the use of options `--no-run --compile` with the [`stack script` command](script_command.md). ## The `--silent` flag Equivalent to the `--verbosity silent` option. ## The `--[no-]skip-ghc-check` option Default: Disabled Enables/disables the skipping of checking the GHC version and architecture. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#skip-ghc-check). ## The `--[no-]skip-msys` option Restrictions: Windows systems only Default: Disabled Enables/disables the skipping of installing MSYS2. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#skip-msys). ## The `--stack-colors` or `--stack-colours` options Pass the option `--stack-colors ` to specify Stack's output styles. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#stack-colors). ## The `--stack-root` option Overrides: `STACK_ROOT` environment variable Pass the option `--stack-root ` to specify the path to the Stack root directory. The path must be an absolute one. ## The `--stack-yaml` option Default: `stack.yaml` Overrides: `STACK_YAML` enviroment variable Pass the option `--stack-yaml ` to specify Stack's project-level YAML configuration file. ## The `--[no-]system-ghc` flag Default: Disabled Enables/disables the use of a GHC executable on the PATH, if one is available and its version matches. ## The `--[no-]terminal` flag Default: Stack is running in a terminal (as detected) Enables/disables whether Stack is running in a terminal. ## The `--terminal-width` option Default: the terminal width (if detected); otherwise `100` Pass the option `--terminal-width ` to specify the width of the terminal, used by Stack's pretty printed messages. ## The `--[no-]time-in-logs` flag Default: Enabled Enables/disables the inclusion of time stamps against logging entries when the verbosity level is 'debug'. ## The `--verbose` or `-v` flags Equivalent to the `--verbosity debug` option. ## The `--verbosity` option Default: `info` Pass the option `--verbosity ` to specify the level for logging. Possible levels are `silent`, `error`, `warn`, `info` and `debug`, in order of increasing amounts of information provided by logging. ## The `--version` flag Pass the flag `--version` to cause Stack to report its version to standard output and quit. For versions that are release candidates, the report will list the dependencies that Stack has been compiled with. ## The `--with-gcc` option Pass the option `--with-gcc ` to specify use of a GCC executable. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#with-gcc). ## The `--with-hpack` option Pass the option `--with-hpack ` to specify use of an Hpack executable. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#with-hpack). ## The `--work-dir` option Default: `.stack-work` Overrides: `STACK_WORK` environment variable Pass the option `--work-dir ` to specify the path to Stack's work directory for the project. The path must be a relative one, relative to the project's root directory. For further information, see the documentation for the corresponding non-project specific configuration [option](yaml_configuration.md#work-dir). ## The `--setup-info-yaml` command option Default: `https://raw.githubusercontent.com/commercialhaskell/stackage-content/master/stack/stack-setup-2.yaml` The `--setup-info-yaml ` command option specifies the location of a `setup-info` dictionary. The option can be specified multiple times. ## The `--snapshot-location-base` command option Default: `https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master` The `--snapshot-location-base ` command option specifies the base location of snapshots. ## The `--help` command flag If Stack is passed the `--help` command flag, it will output help for the command. stack-2.9.3.1/doc/glossary.md0000644000000000000000000001346414445022466014130 0ustar0000000000000000
# Glossary The following terms are used in Stack's documentation. |Term |Meaning | |-------------------|----------------------------------------------------------| |Cabal |The Haskell Common Architecture for Building Applications and Libraries, provided by the [`Cabal` package](https://hackage.haskell.org/package/Cabal). Also referred to as Cabal (the library) to distinguish it from Cabal (the tool).| |Cabal file|A file containing a [package description](https://cabal.readthedocs.io/en/stable/cabal-package.html) used by Cabal, named `.cabal`.| |Cabal (the tool)|The Haskell build tool provided by the [`cabal-install` package](https://hackage.haskell.org/package/cabal-install).| |CI |Continuous integration. | |CMake |A [system](https://cmake.org/) for managing build processes.| |`config.yaml` |A global and non-project-specific configuration file used by Stack.| |Docker |A [platform](https://www.docker.com/) for developing, shipping, and running applications. It can package and run an application in a loosely isolated environment called a _container_.| |Emacs |[GNU Emacs](https://www.gnu.org/software/emacs/), an extensible, customisable text editor.| |extra-deps |Packages in addition to those in a snapshot, named after a key used in `stack.yaml` files.| |FreeBSD |A Unix-like operating system. | |GCC |The [GNU Compiler Collection](https://gcc.gnu.org/) or its executable `gcc`.| |GHC |The [Glasgow Haskell Compiler](https://www.haskell.org/ghc/).| |GHCi |GHC's [interactive environment](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html).| |GHCJS |A Haskell to JavaScript [compiler](https://github.com/ghcjs/ghcjs).| |GHCup |An [installer](https://www.haskell.org/ghcup/) for Haskell. |Git |A [distributed version control system](https://git-scm.com/).| |GPG |The [GNU Privacy Guard](https://gnupg.org/) or GnuPG, software that allows you to encrypt or sign your data and communications.| |Hackage |The [Haskell Package Repository](https://hackage.haskell.org/). |Haddock |The [document generation tool](https://hackage.haskell.org/package/haddock) for Haskell libraries.| |'Haskell' extension|The ['Haskell' extension]() for VS Code. | |HLS |[Haskell Language Server](https://haskell-language-server.readthedocs.io/en/latest/), an implementation of the Language Server Protocol for Haskell.| |Homebrew |A [package manager](https://brew.sh/) for macOS or Linux, or its executable `brew`.| |Hoogle |A Haskell API [search engine](https://hoogle.haskell.org/).| |Hpack |A [format](https://github.com/sol/hpack) for Haskell packages or the executable `hpack` that produces a Cabal file from `package.yaml`.| |Linux |A family of operating systems based on the Linux kernel. | |macOS |The primary operating system for Apple's Mac computers. Previously known as Mac OS X or OS X.| |Make |A [build automation tool](https://www.gnu.org/software/make/).| |MSYS2 |The [MSYS2](https://www.msys2.org/) software distribution and building platform for Windows.| |Nix |A purely functional [package manager](https://nixos.org/), available for Linux and macOS.| |`package.yaml` |A file that describes a package in the Hpack format. | |Pantry |A library for content-addressable Haskell package management, provided by the [`pantry` package](https://hackage.haskell.org/package/pantry). A dependency of Stack.| |PATH |The `PATH` environment variable, specifying a list of directories searched for executable files.| |PVP |The Haskell [Package Versioning Policy](https://pvp.haskell.org/), which tells developers of libraries how to set their version numbers.| |REPL |An interactive (run-eval-print loop) programming environment.| |resolver |A synonym for snapshot. | |`Setup.hs` |A project-specific file used by Cabal to perform setup tasks.| |snapshot |A snapshot defines a GHC version, a set of packages, and build flags or other settings.| |Stack |The Haskell Tool Stack project or its executable `stack`. | |`stack.yaml` |A project-level configuration file used by Stack, which may also contain non-project-specific options.| |Stackage |A [distribution](https://www.stackage.org/) of compatible Haskell packages.| |Stack root |A directory in which Stack stores important files. See `stack path --stack-root`. On Windows, or if Stack is configured to use the XDG Base Directory Specification, Stack also stores important files outside of the Stack root.| |Unix-like operating systems|Linux, FreeBSD and macOS. | |VS Code |[Visual Studio Code](https://code.visualstudio.com/), a source code editor.| |Windows |A group of operating systems developed by Microsoft. | |WSL |[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/). Provides a Linux environment on Windows.| |XDG Base Directory Specification|A [specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) of directories relative to which files should be located.| |YAML |A human-friendly [data serialization language](https://yaml.org/).| stack-2.9.3.1/doc/GUIDE.md0000644000000000000000000017416614445022466013131 0ustar0000000000000000
# User guide (introductory) Stack is a modern, cross-platform build tool for Haskell code. This introductory guide takes a new Stack user through the typical workflows. This guide will not teach Haskell or involve much code, and it requires no prior experience with the Haskell packaging system or other build tools. Terms used in the guide are defined in the [glossary](glossary.md). Some of Stack's features will not be needed regularly or by all users. See the [advanced user's guide](GUIDE_advanced.md) for information about those features. ## Stack's functions Stack handles the management of your toolchain (including GHC — the Glasgow Haskell Compiler — and, for Windows users, MSYS2), building and registering libraries, building build tool dependencies, and more. While it can use existing tools on your system, Stack has the capacity to be your one-stop shop for all Haskell tooling you need. This guide will follow that Stack-centric approach. ### What makes Stack special? The primary Stack design point is __reproducible builds__. If you run `stack build` today, you should get the same result running `stack build` tomorrow. There are some cases that can break that rule (changes in your operating system configuration, for example), but, overall, Stack follows this design philosophy closely. To make this a simple process, Stack uses curated package sets called __snapshots__. Stack has also been designed from the ground up to be user friendly, with an intuitive, discoverable command line interface. For many users, simply downloading Stack and reading `stack --help` will be enough to get up and running. This guide provides a more gradual tour for users who prefer that learning style. To build your project, Stack uses a project-level configuration file, named `stack.yaml`, in the root directory of your project as a sort of blueprint. That file contains a reference, called a __resolver__, to the snapshot which your package will be built against. Finally, Stack is __isolated__: it will not make changes outside of specific Stack directories. Stack-built files generally go in either the Stack root directory or `./.stack-work` directories local to each project. The Stack root directory holds packages belonging to snapshots and any Stack-installed versions of GHC. Stack will not tamper with any system version of GHC or interfere with packages installed by other build tools, such as Cabal (the tool). ## Downloading and Installation The [documentation dedicated to downloading Stack](install_and_upgrade.md) has the most up-to-date information for a variety of operating systems. Instead of repeating that content here, please go check out that page and come back here when you can successfully run `stack --version`. We also assume that the directory reported by `stack path --local-bin` has been added to the PATH. ## Hello World Example With Stack installed, let's create a new project from a template and walk through the most common Stack commands. In this guide, an initial `$` represents the command line prompt. The prompt may differ in the terminal on your operating system. Unless stated otherwise, the working directory is the project's root directory. ### The `stack new` command We'll start off with the `stack new` command to create a new *project*, that will contain a Haskell *package* of the same name. So let's pick a valid package name first: > A package is identified by a globally-unique package name, which consists > of one or more alphanumeric words separated by hyphens. To avoid ambiguity, > each of these words should contain at least one letter. (From the [Cabal users guide](https://www.haskell.org/cabal/users-guide/developing-packages.html#developing-packages)) We'll call our project `helloworld`, and we'll use the `new-template` project template. This template is used by default, but in our example we will refer to it expressly. Other templates are available. For further information about templates, see the `stack templates` command [documentation](GUIDE_advanced.md#the-stack-templates-command). From the root directory for all our Haskell projects, we command: ~~~text stack new helloworld new-template ~~~ For this first Stack command, there's quite a bit of initial setup it needs to do (such as downloading the list of packages available upstream), so you'll see a lot of output. Over the course of this guide a lot of the content will begin to make more sense. After creating the project directory, and obtaining and populating the project template, Stack will initialise its own project-level configuration. For further information about setting paramaters to populate templates, see the YAML configuration [documentation](yaml_configuration.md#templates). For further information about initialisation, see the `stack init` command [documentation](#the-stack-init-command). The `stack new` and `stack init` commands have options and flags in common. !!! info Pass the `--bare` flag to cause Stack to create the project in the current working directory rather than in a new project directory. !!! info Parameters to populate project templates can be set at the command line with the `--param :` (or `-p`) option. We now have a project in the `helloworld` directory! We will change to that directory, with command: ~~~text cd helloworld ~~~ ### The `stack build` command Next, we'll run the most important Stack command, `stack build`: ~~~text stack build # installing ... building ... ~~~ Stack needs a version of GHC in order to build your project. Stack will discover that you are missing it and will install it for you. You'll get intermediate download percentage statistics while the download is occurring. This command may take some time, depending on download speeds. !!! note GHC will be installed to your Stack programs directory, so calling `ghc` on the command line won't work. See the `stack exec`, `stack ghc`, and `stack runghc` commands below for more information. Once a version of GHC is installed, Stack will then build your project. ### The `stack exec` command Looking closely at the output of the previous command, you can see that it built both a library called `helloworld` and an executable called `helloworld-exe` (on Windows, `helloworld-exe.exe`). We'll explain more in the next section, but, for now, just notice that the executables are installed in a location in our project's `.stack-work` directory. Now, Let's use the `stack exec` command to run our executable (which just outputs "someFunc"): ~~~text stack exec helloworld-exe someFunc ~~~ `stack exec` works by providing the same reproducible environment that was used to build your project to the command that you are running. Thus, it knew where to find `helloworld-exe` even though it is hidden in the `.stack-work` directory. Command `stack path --bin-path` to see the PATH in the Stack environment. !!! info On Windows, the Stack environment includes the `\mingw64\bin`, `\usr\bin` and `\usr\local\bin` directories of the Stack-supplied MSYS2. If your executable depends on files (for example, dynamic-link libraries) in those directories and you want ro run it outside of the Stack environment, you will need to ensure copies of those files are on the PATH. ### The `stack test` command Finally, like all good software, `helloworld` actually has a test suite. Let's run it with the `stack test` command: ~~~text stack test # build output ... ~~~ Reading the output, you'll see that Stack first builds the test suite and then automatically runs it for us. For both the `build` and `test` command, already built components are not built again. You can see this by using the `stack build` and `stack test` commands a second time: ~~~text stack build stack test # build output ... ~~~ ## Inner Workings of Stack In this subsection, we'll dissect the `helloworld` example in more detail. ### Files in helloworld Before studying Stack more, let's understand our project a bit better. The files in the directory include: ~~~text app/Main.hs src/Lib.hs test/Spec.hs ChangeLog.md README.md LICENSE Setup.hs helloworld.cabal package.yaml stack.yaml .gitignore ~~~ The `app/Main.hs`, `src/Lib.hs`, and `test/Spec.hs` files are all Haskell source files that compose the actual functionality of our project (we won't dwell on them here). The `ChangeLog.md`, `README.md`, `LICENSE` and `.gitignore` files have no effect on the build. The `helloworld.cabal` file is updated automatically as part of the `stack build` process and should not be modified. The files of interest here are `Setup.hs`, `stack.yaml`, and `package.yaml`. The `Setup.hs` file is a component of the Cabal build system which Stack uses. It's technically not needed by Stack, but it is still considered good practice in the Haskell world to include it. The file we're using is straight boilerplate: ~~~haskell import Distribution.Simple main = defaultMain ~~~ Next, let's look at our `stack.yaml` file, which gives our project-level settings. Ignoring comments beginning `#`, the contents will look something like this: ~~~yaml resolver: url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/28.yaml packages: - . ~~~ The value of the `resolver` key tells Stack *how* to build your package: which GHC version to use, versions of package dependencies, and so on. Our value here says to use [LTS Haskell 19.28](https://www.stackage.org/lts-19.28), which implies GHC 9.0.2 (which is why `stack build` installs that version of GHC if it is not already available to Stack). There are a number of values you can use for `resolver`, which we'll cover later. The value of the `packages` key tells Stack which local packages to build. In our simple example, we have only a single package in our project, located in the same directory, so '`.`' suffices. However, Stack has powerful support for multi-package projects, which we'll elaborate on as this guide progresses. Another file important to the build is `package.yaml`. The `package.yaml` file describes the package in the [Hpack](https://github.com/sol/hpack) format. Stack has in-built Hpack functionality and this is its preferred package format. The default behaviour is to generate the Cabal file (here named `helloworld.cabal`) from this `package.yaml` file, and accordingly you should **not** modify the Cabal file. It is also important to remember that Stack is built on top of the Cabal build system. Therefore, an understanding of the moving parts in Cabal are necessary. In Cabal, we have individual *packages*, each of which contains a single Cabal file, named `.cabal`. The Cabal file can define one or more *components*: a library, executables, test suites, and benchmarks. It also specifies additional information such as library dependencies, default language pragmas, and so on. In this guide, we'll discuss the bare minimum necessary to understand how to modify a `package.yaml` file. You can see a full list of the available options at the [Hpack documentation](https://github.com/sol/hpack#quick-reference). The Cabal User Guide the definitive reference for the [Cabal file format](https://cabal.readthedocs.io/en/stable/cabal-package.html). ### The location of GHC As we saw above, the `build` command installed GHC for us. You can use the `stack path` command for quite a bit of path information (which we'll play with more later). We'll look at where GHC is installed: === "Unix-like" Command: ~~~text stack exec -- which ghc /home//.stack/programs/x86_64-linux/ghc-9.0.2/bin/ghc ~~~ === "Windows (with PowerShell)" Command: ~~~text stack exec -- where.exe ghc C:\Users\\AppData\Local\Programs\stack\x86_64-windows\ghc-9.0.2\bin\ghc.exe ~~~ As you can see from that path (and as emphasized earlier), the installation is placed to not interfere with any other GHC installation, whether system-wide or even different GHC versions installed by Stack. ## Cleaning your project You can clean up build artifacts for your project using the `stack clean` and `stack purge` commands. ### The `stack clean` command `stack clean` deletes the local working directories containing compiler output. By default, that means the contents of directories in `.stack-work/dist`, for all the `.stack-work` directories within a project. Use `stack clean ` to delete the output for the package _specific-package_ only. ### The `stack purge` command `stack purge` deletes the local stack working directories, including extra-deps, git dependencies and the compiler output (including logs). It does not delete any snapshot packages, compilers or programs installed using `stack install`. This essentially reverts the project to a completely fresh state, as if it had never been built. `stack purge` is just a shortcut for `stack clean --full` ### The `stack build` command The `build` command is the heart and soul of Stack. It is the engine that powers building your code, testing it, getting dependencies, and more. Quite a bit of the remainder of this guide will cover more advanced `build` functions and features, such as building test and Haddocks at the same time, or constantly rebuilding blocking on file changes. !!! note Using the `build` command twice with the same options and arguments should generally do nothing (besides things like rerunning test suites), and should, in general, produce a reproducible result between different runs. ## Adding dependencies Let's say we decide to modify our `helloworld` source a bit to use a new library, perhaps the ubiquitous `text` package. In `src/Lib.hs`, we can, for example add: ~~~haskell {-# LANGUAGE OverloadedStrings #-} module Lib ( someFunc ) where import qualified Data.Text.IO as T someFunc :: IO () someFunc = T.putStrLn "someFunc" ~~~ When we try to build this, things don't go as expected: ~~~text stack build # build failure output (abridged for clarity) ... src\Lib.hs:6:1: error: Could not load module ‘Data.Text.IO’ It is a member of the hidden package ‘text-1.2.5.0’. Perhaps you need to add ‘text’ to the build-depends in your .cabal file. Use -v (or `:set -v` in ghci) to see a list of the files searched for. | 6 | import qualified Data.Text.IO as T | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ~~~ This means that the package containing the module in question is not available. To tell Stack to use [text](https://hackage.haskell.org/package/text), you need to add it to your `package.yaml` file — specifically in your `dependencies` section, like this: ~~~yaml dependencies: - base >= 4.7 && < 5 - text # added here ~~~ Now if we rerun `stack build`, we should get a successful result. Command: ~~~text stack build # build output ... ~~~ This output means that the `text` package was downloaded, configured, built, and locally installed. Once that was done, we moved on to building our local package (`helloworld`). At no point did we need to ask Stack to build dependencies — it does so automatically. ### Listing Dependencies Let's have Stack add a few more dependencies to our project. First, we'll include two new packages in the `dependencies` section for our library in our `package.yaml`: ~~~yaml dependencies: - base >= 4.7 && < 5 - text - filepath - containers ~~~ After adding these two dependencies, we can again run `stack build` to have them installed. Command: ~~~text stack build # build output ... ~~~ Finally, to find out which versions of these libraries Stack installed, we can ask Stack to `ls dependencies`. Command: ~~~text stack ls dependencies # dependency output ... ~~~ ### extra-deps Let's try a more off-the-beaten-track package: the joke [acme-missiles](http://www.stackage.org/package/acme-missiles) package. Our source code is simple: ~~~haskell module Lib ( someFunc ) where import Acme.Missiles someFunc :: IO () someFunc = launchMissiles ~~~ Again, we add this new dependency to the `package.yaml` file like this: ~~~yaml dependencies: - base >= 4.7 && < 5 - text - filepath - containers - acme-missiles # added ~~~ However, rerunning `stack build` shows us the following error message. Command: ~~~text stack build # build failure output ... ~~~ It says that it was unable to construct the build plan. This brings us to the next major topic in using Stack. ## Curated package sets Remember above when `stack new` selected some [LTS resolver](https://github.com/commercialhaskell/lts-haskell#readme) for us? That defined our build plan and available packages. When we tried using the `text` package, it just worked, because it was part of the LTS *package set*. We've specified the `acme-missiles` package in the `package.yaml` file (see above), but `acme-missiles` is not part of that LTS package set, so building failed. To add `acme-missiles` to the available packages, we'll use the `extra-deps` key in the `stack.yaml` file. That key defines extra packages, not present in the resolver, that will be needed as dependencies. You can add this like so: ~~~yaml extra-deps: - acme-missiles-0.3 # not in the LTS resolver ~~~ Now `stack build` will succeed. With that out of the way, let's dig a little bit more into these package sets, also known as *snapshots*. We mentioned the LTS resolvers, and you can get quite a bit of information about it at [https://www.stackage.org/lts](https://www.stackage.org/lts), including: * The appropriate resolver value (`resolver: lts-20.4`, as is currently the latest LTS) * The GHC version used * A full list of all packages available in this snapshot * The ability to perform a Hoogle search on the packages in this snapshot * A [list of all modules](https://www.stackage.org/lts/docs) in a snapshot, which can be useful when trying to determine which package to add to your `package.yaml` file. You can also see a [list of all available snapshots](https://www.stackage.org/snapshots). You'll notice two flavors: LTS (for "Long Term Support") and Nightly. You can read more about them on the [LTS Haskell GitHub page](https://github.com/commercialhaskell/lts-haskell#readme). If you're not sure which to use, start with LTS Haskell (which Stack will lean towards by default as well). ## Resolvers and changing your compiler version Let's explore package sets a bit further. Instead of lts-19.17, let's change our `stack.yaml` file to use the [latest nightly](https://www.stackage.org/nightly). Right now, this is currently 2022-12-16 - please see the resolver from the link above to get the latest. Then, commanding `stack build` again will produce: ~~~text stack build # Downloaded nightly-2022-12-16 build plan. # build output ... ~~~ We can also change resolvers on the command line, which can be useful in a Continuous Integration (CI) setting, like on Travis. For example, command: ~~~text stack --resolver lts-18.28 build # Downloaded lts-18.28 build plan. # build output ... ~~~ When passed on the command line, you also get some additional "short-cut" versions of resolvers: `--resolver nightly` will use the newest Nightly resolver available, `--resolver lts` will use the newest LTS, and `--resolver lts-19` will use the newest LTS in the 19.x series. The reason these are only available on the command line and not in your `stack.yaml` file is that using them: 1. Will slow down your build (since Stack then needs to download information on the latest available LTS each time it builds) 2. Produces unreliable results (since a build run today may proceed differently tomorrow because of changes outside of your control) ### Changing GHC versions Finally, let's try using an older LTS snapshot. We'll use the newest 18.x snapshot with the command: ~~~text stack --resolver lts-18 build # build output ... ~~~ This succeeds, automatically installing the necessary GHC along the way. So, we see that different LTS versions use different GHC versions and Stack can handle that. ### Other resolver values We've mentioned `nightly-YYYY-MM-DD` and `lts-X.Y` values for the resolver. There are actually other options available, and the list will grow over time. At the time of writing: * `ghc-X.Y.Z`, for requiring a specific GHC version but no additional packages * Experimental custom snapshot support The most up-to-date information can always be found in the [stack.yaml documentation](yaml_configuration.md#resolver). ## Existing projects Alright, enough playing around with simple projects. Let's take an open source package and try to build it. We'll be ambitious and use [yackage](https://hackage.haskell.org/package/yackage), a local package server using [Yesod](http://www.yesodweb.com/). To get the code, we'll use the `stack unpack` command from the root directory for all our Haskell projects: ~~~text stack unpack yackage Unpacked yackage-0.8.1 to /yackage-0.8.1/ ~~~ You can also unpack to the directory of your liking instead of the current one by issuing the command: ~~~text stack unpack yackage --to ~~~ This will create a `yackage-0.8.1` directory inside ``. We will change to that directory, with the command: ~~~text cd yackage-0.8.1 ~~~ ### The `stack init` command This new directory does not have a `stack.yaml` file, so we need to make one first. We could do it by hand, but let's be lazy instead with the `stack init` command: ~~~text stack init # init output ... ~~~ `stack init` does quite a few things for you behind the scenes: * Finds all of the Cabal files in your current directory and subdirectories (unless you use `--ignore-subdirs`) and determines the packages and versions they require * Finds the best combination of snapshot and package flags that allows everything to compile with minimum external dependencies * It tries to look for the best matching snapshot from latest LTS, latest nightly, other LTS versions in that order Assuming it finds a match, it will write your `stack.yaml` file, and everything will work. !!! note The `yackage` package does not currently support Hpack, but you can also use `hpack-convert` should you need to generate a `package.yaml` file. #### Excluded Packages Sometimes multiple packages in your project may have conflicting requirements. In that case `stack init` will fail, so what do you do? You could manually create `stack.yaml` by omitting some packages to resolve the conflict. Alternatively you can ask `stack init` to do that for you by specifying `--omit-packages` flag on the command line. Let's see how that works. To simulate a conflict we will use `acme-missiles-0.3` in `yackage` and we will also copy `yackage.cabal` to another directory and change the name of the file and package to `yackage-test`. In this new package we will use `acme-missiles-0.2` instead. Let's see what happens when we command `stack init` again: ~~~text stack init --force --omit-packages # init failure output ... ~~~ Looking at `stack.yaml`, you will see that the excluded packages have been commented out under the `packages` field. In case wrong packages are excluded you can uncomment the right one and comment the other one. Packages may get excluded due to conflicting requirements among user packages or due to conflicting requirements between a user package and the resolver compiler. If all of the packages have a conflict with the compiler then all of them may get commented out. When packages are commented out you will see a warning every time you run a command which needs the configuration file. The warning can be disabled by editing the configuration file and removing it. #### Using a specific resolver Sometimes you may want to use a specific resolver for your project instead of `stack init` picking one for you. You can do that by using `stack init --resolver `. You can also init with a compiler resolver if you do not want to use a snapshot. That will result in all of your project's dependencies being put under the `extra-deps` section. #### Installing the compiler Stack will automatically install the compiler when you run `stack build` but you can manually specify the compiler by running `stack setup `. #### Miscellaneous and diagnostics _Add selected packages_: If you want to use only selected packages from your project directory you can do so by explicitly specifying the package directories on the command line. _Duplicate package names_: If multiple packages under the directory tree have same name, `stack init` will report those and automatically ignore one of them. _Ignore subdirectories_: By default `stack init` searches all the subdirectories for Cabal files. If you do not want that then you can use `--ignore-subdirs` command line switch. _Cabal warnings_: `stack init` will show warnings if there were issues in reading a Cabal file. You may want to pay attention to the warnings as sometimes they may result in incomprehensible errors later on during dependency solving. _Package naming_: If the `Name` field defined in a Cabal file does not match with the Cabal file name then `stack init` will refuse to continue. _User warnings_: When packages are excluded or external dependencies added Stack will show warnings every time the configuration file is loaded. You can suppress the warnings by editing the configuration file and removing the warnings from it. You may see something like this: ~~~text stack build Warning: Some packages were found to be incompatible with the resolver and have been left commented out in the packages section. Warning: Specified resolver could not satisfy all dependencies. Some external packages have been added as dependencies. You can suppress this message by removing it from stack.yaml ~~~ ## Different databases Time to take a short break from hands-on examples and discuss a little architecture. Stack has the concept of multiple *databases*. A database consists of a GHC package database (which contains the compiled version of a library), executables, and a few other things as well. To give you an idea, the contents of the parent directory of the `stack path --local-pkg-db` directory are the directories: ~~~text bin doc lib pkgdb ~~~ Databases in Stack are *layered*. For example, the database listing we just gave is called a *local* database (also known as a *mutable* database). That is layered on top of a *snapshot* database (also known as a *write-only* database). The snapshot database contains the libraries and executables that are considered to be *immutable*. Finally, GHC itself ships with a number of libraries and executables, also considered to be immutable, which forms the *global* database. To get a quick idea of this, we can look at the output of the `stack exec -- ghc-pkg list` command in our `helloworld` project: ~~~text Cabal-3.6.3.0 Win32-2.12.0.1 array-0.5.4.0 base-4.16.2.0 binary-0.8.9.0 bytestring-0.11.3.1 containers-0.6.5.1 deepseq-1.4.6.1 directory-1.3.6.2 exceptions-0.10.4 filepath-1.4.2.2 (ghc-9.2.3) ghc-bignum-1.2 ghc-boot-9.2.3 ghc-boot-th-9.2.3 ghc-compact-0.1.0.0 ghc-heap-9.2.3 ghc-prim-0.8.0 ghci-9.2.3 haskeline-0.8.2 hpc-0.6.1.0 integer-gmp-1.1 libiserv-9.2.3 mtl-2.2.2 parsec-3.1.15.0 pretty-1.1.3.6 process-1.6.13.2 rts-1.0.2 stm-2.5.0.2 template-haskell-2.18.0.0 text-1.2.5.0 time-1.11.1.1 transformers-0.5.6.2 xhtml-3000.2.2.1 acme-missiles-0.3 helloworld-0.1.0.0 ~~~ where `` refers to the directory output by the command `stack path --global-pkg-db`, and so on. Notice that `acme-missiles` ends up in the *snapshot* database. Any package which comes from Hackage, an archive, or a repository is considered to be an *immutable* package. Anything which is considered *mutable*, or depends on something mutable, ends up in the *local* database. This includes your own code and any other packages located on a local file path. The reason we have this structure is that: * it lets multiple projects reuse the same binary builds of immutable packages, * but doesn't allow different projects to "contaminate" each other by putting non-standard content into the shared snapshot database. As you probably guessed, there can be multiple snapshot databases available. See the contents of the `snapshots` directory in the Stack root. * On Unix-like operating systems, each snapshot is in the last of a sequence of three subdirectories named after the platform, a 256-bit hash of the source map (how the package should be built -- including the compiler, options, and immutable dependencies), and the GHC version. * On Windows, each snapshot is in a subdirectory that is a shorter hash (eight characters) of the sequence of three directories used on Unix-like operating systems. This is done to avoid problems created by default limits on file path lengths on Windows systems. These snapshot databases don't get layered on top of each other; they are each used separately. In reality, you'll rarely — if ever — interact directly with these databases, but it's good to have a basic understanding of how they work so you can understand why rebuilding may occur at different points. ## The build synonyms Let's look at a subset of the `stack --help` output: ~~~text build Build the package(s) in this directory/configuration install Shortcut for 'build --copy-bins' test Shortcut for 'build --test' bench Shortcut for 'build --bench' haddock Shortcut for 'build --haddock' ~~~ Four of these commands are just synonyms for the `build` command. They are provided for convenience for common cases (e.g., `stack test` instead of `stack build --test`) and so that commonly expected commands just work. What's so special about these commands being synonyms? It allows us to make much more composable command lines. For example, we can have a command that builds executables, generates Haddock documentation (Haskell API-level docs), and builds and runs your test suites, with: ~~~text stack build --haddock --test ~~~ You can even get more inventive as you learn about other flags. For example, take the following command: ~~~text stack build --pedantic --haddock --test --exec "echo Yay, it succeeded" --file-watch ~~~ This command will: * turn on all warnings and errors (the `--pedantic` flag) * build your library and executables * generate Haddocks (the `--haddock` flag) * build and run your test suite (the `--test` flag) * run the command `echo Yay, it succeeded` when that completes (the `--exec` option) * after building, watch for changes in the files used to build the project, and kick off a new build when done (the `--file-watch` flag) ### The `stack install` command and `copy-bins` option It's worth calling out the behavior of the `install` command and `--copy-bins` option, since this has confused a number of users (especially when compared to behavior of other tools like Cabal (the tool)). The `install` command does precisely one thing in addition to the build command: it copies any generated executables to the local binary directory. You may recognize the default value for that path: On Unix-like operating systems, command: ~~~text stack path --local-bin /home//.local/bin ~~~ On Windows, command: ~~~text stack path --local-bin C:\Users\\AppData\Roaming\local\bin ~~~ That's why the download page recommends adding that directory to your PATH. This feature is convenient, because now you can simply run `executable-name` in your shell instead of having to run `stack exec executable-name` from inside your project directory. Since it's such a point of confusion, let me list a number of things Stack does *not* do specially for the `install` command: * Stack will always build any necessary dependencies for your code. The install command is not necessary to trigger this behavior. If you just want to build a project, run `stack build`. * Stack will *not* track which files it's copied to your local binary directory nor provide a way to automatically delete them. There are many great tools out there for managing installation of binaries, and Stack does not attempt to replace those. * Stack will not necessarily be creating a relocatable executable. If your executables hard-codes paths, copying the executable will not change those hard-coded paths. * At the time of writing, there's no way to change those kinds of paths with Stack, but see [issue #848 about --prefix](https://github.com/commercialhaskell/stack/issues/848) for future plans. That's really all there is to the `install` command: for the simplicity of what it does, it occupies a much larger mental space than is warranted. ## Targets, locals, and extra-deps We haven't discussed this too much yet, but, in addition to having a number of synonyms *and* taking a number of options on the command line, the `build` command *also* takes many arguments. These are parsed in different ways, and can be used to achieve a high level of flexibility in telling Stack exactly what you want to build. We're not going to cover the full generality of these arguments here; instead, there's documentation covering the full [build command syntax](build_command.md). Here, we'll just point out a few different types of arguments: * You can specify a *package name*, e.g. `stack build vector`. * This will attempt to build the `vector` package, whether it's a local package, in your extra-deps, in your snapshot, or just available upstream. If it's just available upstream but not included in your locals, extra-deps, or snapshot, the newest version is automatically promoted to an extra-dep. * You can also give a *package identifier*, which is a package name plus version, e.g. `stack build yesod-bin-1.4.14`. * This is almost identical to specifying a package name, except it will (1) choose the given version instead of latest, and (2) error out if the given version conflicts with the version of a local package. * The most flexibility comes from specifying individual *components*, e.g. `stack build helloworld:test:helloworld-test` says "build the test suite component named helloworld-test from the helloworld package." * In addition to this long form, you can also shorten it by skipping what type of component it is, e.g. `stack build helloworld:helloworld-test`, or even skip the package name entirely, e.g. `stack build :helloworld-test`. * Finally, you can specify individual *directories* to build to trigger building of any local packages included in those directories or subdirectories. When you give no specific arguments on the command line (e.g., `stack build`), it's the same as specifying the names of all of your local packages. If you just want to build the package for the directory you're currently in, you can use `stack build .`. ### Components, --test, and --bench Here's one final important yet subtle point. Consider our `helloworld` package: it has a library component, an executable `helloworld-exe`, and a test suite `helloworld-test`. When you run `stack build helloworld`, how does it know which ones to build? By default, it will build the library (if any) and all of the executables but ignore the test suites and benchmarks. This is where the `--test` and `--bench` flags come into play. If you use them, those components will also be included. So `stack build --test helloworld` will end up including the helloworld-test component as well. You can bypass this implicit adding of components by being much more explicit, and stating the components directly. For example, the following will not build the `helloworld-exe` executable once all executables have been successfully built: ~~~text stack clean stack build :helloworld-test Building all executables for `helloworld' once. After a successful build of all of them, only specified executables will be rebuilt. helloworld> configure (lib + exe + test) Configuring helloworld-0.1.0.0... helloworld> build (lib + exe + test) Preprocessing library for helloworld-0.1.0.0.. Building library for helloworld-0.1.0.0.. [1 of 2] Compiling Lib [2 of 2] Compiling Paths_helloworld Preprocessing executable 'helloworld-exe' for helloworld-0.1.0.0.. Building executable 'helloworld-exe' for helloworld-0.1.0.0.. [1 of 2] Compiling Main [2 of 2] Compiling Paths_helloworld Linking .stack-work\dist\\build\helloworld-exe\helloworld-exe.exe ... Preprocessing test suite 'helloworld-test' for helloworld-0.1.0.0.. Building test suite 'helloworld-test' for helloworld-0.1.0.0.. [1 of 2] Compiling Main [2 of 2] Compiling Paths_helloworld Linking .stack-work\dist\\build\helloworld-test\helloworld-test.exe ... helloworld> copy/register Installing library in ...\helloworld\.stack-work\install\... Installing executable helloworld-exe in ...\helloworld\.stack-work\install\...\bin Registering library for helloworld-0.1.0.0.. helloworld> test (suite: helloworld-test) Test suite not yet implemented helloworld> Test suite helloworld-test passed Completed 2 action(s). ~~~ We first cleaned our project to clear old results so we know exactly what Stack is trying to do. Note that it says it is building all executables for `helloworld` once, and that after a successful build of all of them, only specified executables will be rebuilt. If we change the source code of `test/Spec.hs`, say to: ~~~haskell main :: IO () main = putStrLn "Test suite still not yet implemented" ~~~ and command again: ~~~text stack build :helloworld-test helloworld-0.1.0.0: unregistering (local file changes: test\Spec.hs) helloworld> build (lib + test) Preprocessing library for helloworld-0.1.0.0.. Building library for helloworld-0.1.0.0.. Preprocessing test suite 'helloworld-test' for helloworld-0.1.0.0.. Building test suite 'helloworld-test' for helloworld-0.1.0.0.. [2 of 2] Compiling Main Linking .stack-work\dist\\build\helloworld-test\helloworld-test.exe ... helloworld> copy/register Installing library in ...\helloworld\.stack-work\install\... Installing executable helloworld-exe in ...\helloworld\.stack-work\install\...\bin Registering library for helloworld-0.1.0.0.. helloworld> blocking for directory lock on ...\helloworld\.stack-work\dist\\build-lock helloworld> test (suite: helloworld-test) Test suite still not yet implemented helloworld> Test suite helloworld-test passed Completed 2 action(s). ~~~ Notice that this time it builds the `helloworld-test` test suite, and the `helloworld` library (since it's used by the test suite), but it does not build the `helloworld-exe` executable. And now the final point: in both cases, the last line shows that our command also *runs* the test suite it just built. This may surprise some people who would expect tests to only be run when using `stack test`, but this design decision is what allows the `stack build` command to be as composable as it is (as described previously). The same rule applies to benchmarks. To spell it out completely: * The `--test` and `--bench` flags simply state which components of a package should be built, if no explicit set of components is given * The default behavior for any test suite or benchmark component which has been built is to also run it You can use the `--no-run-tests` and `--no-run-benchmarks` flags to disable running of these components. You can also use `--no-rerun-tests` to prevent running a test suite which has already passed and has not changed. !!! note Stack doesn't build or run test suites and benchmarks for non-local packages. This is done so that a command like `stack test` doesn't need to run 200 test suites! ## Multi-package projects Until now, everything we've done with Stack has used a single-package project. However, Stack's power truly shines when you're working on multi-package projects. All the functionality you'd expect to work just does: dependencies between packages are detected and respected, dependencies of all packages are just as one cohesive whole, and if anything fails to build, the build commands exits appropriately. Let's demonstrate this with the `wai-app-static` and `yackage` packages, starting in the root directory for all our Haskell projects. Command: ~~~text mkdir multi cd multi stack unpack wai-app-static yackage Unpacked wai-app-static (from Hackage) to .../multi/wai-app-static-3.1.7.4/ Unpacked yackage (from Hackage) to .../multi/yackage-0.8.1/ stack init Looking for .cabal or package.yaml files to use to init the project. Using cabal packages: - wai-app-static-3.1.7.4/ - yackage-0.8.1/ Cabal file warning in .../multi/yackage-0.8.1/yackage.cabal@47:40: version operators used. To use version operators the package needs to specify at least 'cabal-version: >= 1.8'. Cabal file warning in .../multi/yackage-0.8.1/yackage.cabal@21:36: version operators used. To use version operators the package needs to specify at least 'cabal-version: >= 1.8'. Selecting the best among 18 snapshots... * Matches ... Selected resolver: ... Initialising configuration using resolver: ... Total number of user packages considered: 2 Writing configuration to file: stack.yaml stack build --haddock --test # Goes off to build a whole bunch of packages ~~~ If you look at the `stack.yaml` file, you'll see exactly what you'd expect: ~~~yaml resolver: url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/17.yaml packages: - wai-app-static-3.1.7.4 - yackage-0.8.1 ~~~ Notice that multiple directories are listed in the `packages` key. In addition to local directories, you can also refer to packages available in a Git repository or in a tarball over HTTP/HTTPS. This can be useful for using a modified version of a dependency that hasn't yet been released upstream. !!! note When adding upstream packages directly to your project it is important to distinguish _local packages_ from the upstream _dependency packages_. Otherwise you may have trouble running `stack ghci`. See [stack.yaml documentation](yaml_configuration.md#packages) for more details. ## Flags and GHC options There are two common ways to alter how a package will install: with Cabal flags and with GHC options. ### Cabal flag management To change a Cabal flag setting, we can use the command line `--flag` option. The `yackage` package has an `upload` flag that is enabled by default. We can command: ~~~text stack build --flag yackage:-upload ~~~ This means: when compiling the `yackage` package, turn off the `upload` flag (thus the `-` in `-upload`). Unlike other tools, Stack is explicit about which package's flag you want to change. It does this for two reasons: 1. There's no global meaning for Cabal flags, and therefore two packages can use the same flag name for completely different things. 2. By following this approach, we can avoid unnecessarily recompiling snapshot packages that happen to use a flag that we're using. You can also change flag values on the command line for extra-dep and snapshot packages. If you do this, that package will automatically be promoted to an extra-dep, since the build plan is different than what the plan snapshot definition would entail. ### GHC options GHC options follow a similar logic as in managing Cabal flags, with a few nuances to adjust for common use cases. Let's consider the command: ~~~text stack build --ghc-options="-Wall -Werror" ~~~ This will set the `-Wall -Werror` options for all *local targets*. Note that this will not affect extra-dep and snapshot packages at all. This design provides us with reproducible and fast builds. (By the way: the above GHC options have a special convenience flag: `--pedantic`.) There's one extra nuance about command line GHC options: Since they only apply to local targets, if you change your local targets, they will no longer apply to other packages. Let's play around with an example from the `wai` repository, which includes the `wai` and `warp` packages, the latter depending on the former. If we command again: ~~~text stack build --ghc-options=-O0 wai ~~~ It will build all of the dependencies of `wai`, and then build `wai` with all optimizations disabled. Now let's add in `warp` as well. Command: ~~~text stack build --ghc-options=-O0 wai warp ~~~ This builds the additional dependencies for `warp`, and then builds `warp` with optimizations disabled. Importantly: it does not rebuild `wai`, since `wai`'s configuration has not been altered. Now the surprising case. Command: ~~~text stack build --ghc-options=-O0 warp wai-3.0.3.0-5a49351d03cba6cbaf906972d788e65d: unregistering (flags changed from ["--ghc-options","-O0"] to []) warp-3.1.3-a91c7c3108f63376877cb3cd5dbe8a7a: unregistering (missing dependencies: wai) wai-3.0.3.0: configure ~~~ You may expect this to be a no-op: neither `wai` nor `warp` has changed. However, Stack will instead recompile `wai` with optimizations enabled again, and then rebuild `warp` (with optimizations disabled) against this newly built `wai`. The reason: reproducible builds. If we'd never built `wai` or `warp` before, trying to build `warp` would necessitate building all of its dependencies, and it would do so with default GHC options (optimizations enabled). This dependency would include `wai`. So when we command: ~~~text stack build --ghc-options=-O0 warp ~~~ We want its behavior to be unaffected by any previous build steps we took. While this specific corner case does catch people by surprise, the overall goal of reproducible builds is - in the Stack maintainers' views - worth the confusion. Final point: if you have GHC options that you'll be regularly passing to your packages, you can add them to your `stack.yaml` file. See the [documentation section on ghc-options](yaml_configuration.md#ghc-options) for more information. !!! note That's it, the heavy content of this guide is done! Everything from here on out is simple explanations of commands. Congratulations! ## The `stack path` command Generally, you don't need to worry about where Stack stores various files. But some people like to know this stuff. That's when the `stack path` command is useful. `stack path --help` explains the available options and, consequently, the output of the command: ~~~text --stack-root Global Stack root directory --global-config Global Stack configuration file --project-root Project root (derived from stack.yaml file) --config-location Configuration location (where the stack.yaml file is) --bin-path PATH environment variable --programs Install location for GHC and other core tools (see 'stack ls tools' command) --compiler-exe Compiler binary (e.g. ghc) --compiler-bin Directory containing the compiler binary (e.g. ghc) --compiler-tools-bin Directory containing binaries specific to a particular compiler (e.g. intero) --local-bin Directory where Stack installs executables (e.g. ~/.local/bin (Unix-like OSs) or %APPDATA%\local\bin (Windows)) --extra-include-dirs Extra include directories --extra-library-dirs Extra library directories --snapshot-pkg-db Snapshot package database --local-pkg-db Local project package database --global-pkg-db Global package database --ghc-package-path GHC_PACKAGE_PATH environment variable --snapshot-install-root Snapshot installation root --local-install-root Local project installation root --snapshot-doc-root Snapshot documentation root --local-doc-root Local project documentation root --local-hoogle-root Local project documentation root --dist-dir Dist work directory, relative to package directory --local-hpc-root Where HPC reports and tix files are stored --local-bin-path DEPRECATED: Use '--local-bin' instead --ghc-paths DEPRECATED: Use '--programs' instead --global-stack-root DEPRECATED: Use '--stack-root' instead ~~~ In addition, `stack path` accepts the flags above on the command line to state which keys you're interested in. This can be convenient for scripting. As a simple example, let's find out the sandboxed versions of GHC that Stack installed: === "Unix-like" Command: ~~~text ls $(stack path --programs)/*.installed /home//.stack/programs/x86_64-linux/ghc-9.0.2.installed ~~~ === "Windows (with PowerShell)" Command: ~~~text dir "$(stack path --programs)/*.installed" Directory: C:\Users\mikep\AppData\Local\Programs\stack\x86_64-windows Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 27/07/2022 5:40 PM 9 ghc-9.0.2.installed -a--- 25/02/2022 11:39 PM 9 msys2-20210604.installed ~~~ While we're talking about paths, to wipe our Stack install completely, here's what typically needs to be removed: 1. the Stack root folder (see `stack path --stack-root`, before you uninstall); 2. if different, the folder containing Stack's global YAML configuration file (see `stack path --global-config`, before you uninstall); 3. on Windows, the folder containing Stack's tools (see `stack path --programs`, before you uninstall), which is located outside of the Stack root folder; and 4. the `stack` executable file (see `which stack`, on Unix-like operating systems, or `where.exe stack`, on Windows). You may also want to delete `.stack-work` folders in any Haskell projects that you have built using Stack. The `stack uninstall` command provides information about how to uninstall Stack. ## The `stack exec` command We've already used `stack exec` multiple times in this guide. As you've likely already guessed, it allows you to run executables, but with a slightly modified environment. In particular: `stack exec` looks for executables on Stack's bin paths, and sets a few additional environment variables (like adding those paths to the PATH, and setting `GHC_PACKAGE_PATH`, which tells GHC which package databases to use). If you want to see exactly what the modified environment looks like, try command: ~~~text stack exec env ~~~ The only issue is how to distinguish flags to be passed to Stack versus those for the underlying program. Thanks to the `optparse-applicative` library, Stack follows the Unix convention of `--` to separate these. For example, command: ~~~text stack exec --package stm -- echo I installed the stm package via --package stm ~~~ yields output like: ~~~text Run from outside a project, using implicit global project config Using latest snapshot resolver: lts-18.3 Writing global (non-project-specific) config file to: /home/michael/.stack/global/stack.yaml Note: You can change the snapshot via the resolver field there. I installed the stm package via --package stm ~~~ Flags worth mentioning: * `--package foo` can be used to force a package to be installed before running the given command. * `--no-ghc-package-path` can be used to stop the `GHC_PACKAGE_PATH` environment variable from being set. Some tools — notably Cabal (the tool) — do not behave well with that variable set. You may also find it convenient to use `stack exec` to launch a subshell (substitute `bash` with your preferred shell) where your compiled executable is available at the front of your PATH. Command: ~~~text stack exec bash ~~~ ## The `stack ghci` or `stack repl` command GHCi is the interactive GHC environment, a.k.a. the REPL. You *could* access it with command: ~~~text stack exec ghci ~~~ But that won't load up locally written modules for access. For that, use the `stack ghci` or `stack repl` commands, which are equivalent. To then load modules from your project in GHCi, use the `:module` command (`:m` for short) followed by the module name. !!! note If you have added packages to your project please make sure to mark them as extra deps for faster and reliable usage of `stack ghci`. Otherwise GHCi may have trouble due to conflicts of compilation flags or having to unnecessarily interpret too many modules. See Stack's project-level [configuration](yaml_configuration.md#extra-deps) to learn how to configure a package as an extra-dep. For further information, see the [REPL environment](ghci.md) documentation. ## The `stack ghc` and `stack runghc` commands You'll sometimes want to just compile (or run) a single Haskell source file, instead of creating an entire Cabal package for it. You can use `stack exec ghc` or `stack exec runghc` for that. As simple helpers, we also provide the `stack ghc` and `stack runghc` commands, for these common cases. ## Finding project configs, and the implicit global project Whenever you run something with Stack, it needs a project-level configuration file. The algorithm Stack uses to find such a file is: 1. Check for a `--stack-yaml` option on the command line 2. Check for a `STACK_YAML` environment variable 3. Check the current directory and all ancestor directories for a `stack.yaml` file The first two provide a convenient method for using an alternate configuration. For example: `stack build --stack-yaml stack-ghc-9.2.3.yaml` can be used by your CI system to check your code against GHC 9.2.3. Setting the `STACK_YAML` environment variable can be convenient if you're going to be running commands like `stack ghc` in other directories, but you want to use the configuration you defined in a specific project. If Stack does not find a project level configuration file in any of the three specified locations, the *implicit global* logic kicks in. You've probably noticed that phrase a few times in the output from commands above. Implicit global is essentially a hack to allow Stack to be useful in a non-project setting. When no implicit global configuration file exists, Stack creates one for you with the latest LTS snapshot as the resolver. This allows you to do things like: * compile individual files easily with `stack ghc` * build executables without starting a project, e.g. `stack install pandoc` Keep in mind that there's nothing magical about this implicit global configuration. It has no effect on projects at all. Every package you install with it is put into isolated databases just like everywhere else. The only magic is that it's the catch-all project whenever you're running Stack somewhere else. ## Setting the Stack root location The Stack root is a directory where Stack stores important files. The location and contents of the directory depend on the operating system and/or whether Stack is configured to use the XDG Base Directory Specification. The location of the Stack root can be configured by setting the `STACK_ROOT` environment variable or using Stack's `--stack-root` option on the command line. === "Unix-like" The Stack root contains snapshot packages; tools such as GHC, in a `programs` directory; and Stack's global YAML configuration file (`config.yaml`). The default Stack root is `~/.stack`. === "Windows" The Stack root contains snapshot packages; and Stack's global YAML configuration file (`config.yaml`). The default location of tools such as GHC and MSYS2 is outside of the Stack root. The default Stack root is `%APPDIR%\stack`. The default location of tools is `%LOCALAPPDATA%\Programs\stack`. On Windows, the length of filepaths may be limited (to [MAX_PATH](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd)), and things can break when this limit is exceeded. Setting a Stack root with a short path to its location (for example, `C:\sr`) can help. === "XDG Base Directory Specification" On Unix-like operating systems and Windows, Stack can be configured to follow the XDG Base Directory Specification if the environment variable `STACK_XDG` is set to any non-empty value. However, Stack will ignore that configuration if the Stack root location has been set on the command line or the `STACK_ROOT` environment variable exists. If Stack is following the XDG Base Directory Specification, the Stack root contains what it would otherwise contain for the operating system, but Stack's global YAML configuration file (`config.yaml`) may be located elsewhere. The Stack root is `/stack`. If the `XDG_DATA_HOME` environment variable does not exist, the default is `~/.local/share/stack` on Unix-like operating systems and `%APPDIR%\stack` on Windows. The location of `config.yaml` is `/stack`. If the `XDG_CONFIG_HOME` environment variable does not exist, the default is `~/.config/stack` on Unix-like operating systems and `%APPDIR%\stack` on Windows. The location of the Stack root is reported by command: ~~~text stack path --stack-root ~~~ The full path of Stack's global YAML configuration file is reported by command: ~~~text stack path --global-config ~~~ ## `stack.yaml` versus Cabal files Now that we've covered a lot of Stack use cases, this quick summary of `stack.yaml` versus Cabal files will hopefully make sense and be a good reminder for future uses of Stack: * A project can have multiple packages. * Each project has a `stack.yaml`. * Each package has a Cabal file, named `.cabal`. * The Cabal file specifies which packages are dependencies. * The `stack.yaml` file specifies which packages are available to be used. * The Cabal file specifies the components, modules, and build flags provided by a package * `stack.yaml` can override the flag settings for individual packages * `stack.yaml` specifies which packages to include ## Comparison to other tools Stack is not the only tool available for building Haskell code. Stack came into existence due to limitations at that time with some of the existing tools. If you are happily building Haskell code with other tools, you may not need Stack. If you're experiencing problems with other tools, give Stack a try instead. If you're a new user who has no experience with other tools, we recommend Stack. The defaults match modern best practices in Haskell development, and there are fewer corner cases you need to be aware of. You *can* develop Haskell code with other tools, but you probably want to spend your time writing code, not convincing a tool to do what you want. ### Underlying package format Before turning to differences, we clarify an important similarity: Stack, Cabal (the tool), and presumably all other tools share the same underlying package format of Cabal (the library). This is a Good Thing: we can share the same set of upstream libraries, and collaboratively work on the same project with Stack, Cabal (the tool), and NixOS. In that sense, we're sharing the same ecosystem. ### Curation vs dependency solving * Stack uses 'curation' (snapshots and Stack's project-level configuration file (`stack.yaml`) define precisely the set of packages available for a project). The Stack team firmly believes that the majority of users want to simply ignore dependency resolution nightmares and get a valid build plan from day one. That's why we've made 'curation' the focus of Stack. * Cabal (the tool) can use 'curation' too but its origins are in dependency solving. ### Emphasis on reproducibility * Stack goes to great lengths to ensure that `stack build` today does the same thing tomorrow. With Stack, changing the build plan is always an explicit decision. * Cabal (the tool) does not go to the same lengths: build plans can be affected by the presence of pre-installed packages, and running `cabal update` can cause a previously successful build to fail. ### Automatic building of dependencies * Stack's automatically builds dependencies. So for example, in Stack, `stack test` does the same job as: ~~~text cabal install --enable-tests --only-dependencies cabal configure --enable-tests cabal build cabal test ~~~ (newer versions of Cabal (the tool) may make this command sequence shorter). * With Cabal (the tool), you need to use `cabal install` to trigger dependency building. This is somewhat necessary as building dependencies can, in some cases, break existing installed packages. ### Isolation * Stack is isolated - provides 'sandboxed' behaviour - by default, via its databases. In other words: when you use Stack, there's __no need for sandboxes__, everything is (essentially) sandboxed by default. * With Cabal (the tool), the default behavior is a non-isolated build where working on two projects can cause the user package database to become corrupted. The Cabal solution to this is sandboxes. ### Tools other than Stack and Cabal (the tool) * [cabal-meta](https://hackage.haskell.org/package/cabal-meta) inspired a lot of the multi-package functionality of Stack. Still relevant for Cabal (the tool). * [cabal-src](https://hackage.haskell.org/package/cabal-src). Deprecated in favor of Stack in 2016. * [stackage-cli](https://hackage.haskell.org/package/stackage-cli).Deprecated in favor of Stack in 2015. * [cabal-dev](https://hackage.haskell.org/package/cabal-dev). Deprecated in favor of Cabal (the tool) in 2013. stack-2.9.3.1/doc/GUIDE_advanced.md0000644000000000000000000000740014353310533014731 0ustar0000000000000000
# User guide (advanced) Some of Stack's features will not be needed regularly or by all users. This part of the guide provides information about those features, organised as a reference guide. Some of the features are complex and separate pages are dedicated to them. ## Environment variables The existence or content of certain environment variables can affect how Stack behaves. For further information, see the [environment variables](environment_variables.md) documentation. ## YAML configuration files Stack is configured by the content of YAML files. A global YAML configuration file contains non-project specific options. A project-level YAML configuration file contains project-specific options and may contain non-project specific options. For further information, see the [YAML configuration](yaml_configuration.md) documentation. ## Global flags and options Stack can also be configured by flags and options on the command line. Global flags and options apply to all of Stack's commands. For further information, see the [global flags and options](global_flags.md) documentation. ## Stack commands Stack's commands are listed below, in alphabetical order. * [`bench`](build_command.md) - a synonym for `stack build --bench` * [`build`](build_command.md) - build packages * [`clean`](clean_command.md) - delete build artefacts for the project packages * [`config`](config_command.md) - access and modify Stack's configuration * [`docker`](docker_command.md) - use Stack with Docker * [`dot`](dot_command.md) - dependency visualization * [`eval`](eval_command.md) - evaluate some Haskell code inline * [`exec`](exec_command.md) - executate a command in the Stack environment * [`haddock`](build_command.md) - a synonym for `stack build --haddock` * [`hoogle`](hoogle_command.md) - run `hoogle` * [`hpc`](hpc_command.md) - generate Haskell Program Coverage (HPC) code coverage reports * [`ghc`](ghc_command.md) - run `ghc` * [`ghci`](ghci.md) - run GHCi, a REPL environment * [`ide`](ide_command.md) - information for an integrated development environment (IDE) * [`init`](init_command.md) - initialise Stack's project-level YAML configuration file for an existing project * [`install`](build_command.md) - a synonym for `stack build --copy-bins` * [`list`](list_command.md) - list packages on Hackage or in a snapshot * [`ls`](ls_command.md) - list information about Stack * [`new`](new_command.md) - create a new project with Stack * [`path`](path_command.md) - information about locations used by Stack * [`purge`](purge_command.md) - delete the Stack working directories * [`query`](query_command.md) - information about the build * [`repl`](ghci.md) - a synonym for `stack ghci` * [`run`](run_command.md) - build and run an executable * [`runghc`](runghc_command.md) - run `runghc` * [`runhaskell`](runghc_command.md) - a synoynm for `stack runghc` * [`script`](script_command.md) - run a Haskell source file as a script * [`sdist`](sdist_command.md) - create an archive file for a package, in a form accepted by Hackage * [`setup`](setup_command.md) - get GHC for a Stack project * [`templates`](templates_command.md) - information about templates for use with `stack new` * [`test`](build_command.md) - a synonym for `stack build --test` * [`uninstall`](uninstall_command.md) - information about how to uninstall Stack * [`unpack`](unpack_command.md) - unpack one or more packages locally * [`update`](update_command.md) - update the package index * [`upgrade`](upgrade_command.md) - upgrade Stack * [`upload`](upload_command.md) - upload a package to Hackage stack-2.9.3.1/doc/hoogle_command.md0000644000000000000000000000063414445022466015233 0ustar0000000000000000
# The `stack hoogle` command ~~~text stack hoogle [-- ARGUMENT(S) (e.g. 'stack hoogle -- server --local')] [--[no-]setup] [--rebuild] [--server] ~~~ Hoogle is a Haskell API search engine. `stack hoogle` runs Hoogle. stack-2.9.3.1/doc/hpc_command.md0000644000000000000000000001457314353310533014530 0ustar0000000000000000
# The `stack hpc` commands ~~~text stack hpc COMMAND Available commands: report Generate unified HPC coverage report from tix files and project targets ~~~ Code coverage is a measure of the degree to which the source code of a program is executed when a test suite is run. [Haskell Program Coverage (HPC)](https://ku-fpg.github.io/software/hpc/) is a code coverage tool for Haskell that is provided with GHC. Code coverage is enabled by passing the flag `--coverage` to `stack build`. `stack hpc` provides commands specific to HPC. Command `stack hpc` for the available commands. The following refers to the local HPC root directory. Its location can be obtained by command: ~~~text stack path --local-hpc-root ~~~ ## The `stack hpc report` command ~~~text stack hpc report [TARGET_OR_TIX] [--all] [--destdir DIR] [--open] ~~~ The `stack hpc report` command generates a report for a selection of targets and `.tix` files. Pass the flag `--all` for a report that uses all stored results. Pass the flag --open` to open the HTML report in your browser. ## The `extra-tix-files` directory During the execution of the build, you can place additional tix files in the `extra-tix-files` subdirectory in the local HPC root directory, in order for them to be included in the unified report. A couple caveats: 1. These tix files must be generated by executables that are built against the exact same library versions. Also note that, on subsequent builds with coverage, the local HPC root directory will be recursively deleted. It just stores the most recent coverage data. 2. These tix files will not be considered by `stack hpc report` unless listed explicitly by file name. ## Examples If we have three different packages with test suites, packages `A`, `B`, and `C`, the default unified report will have coverage from all three. If we want a unified report with just two, we can instead command: ~~~text stack hpc report A B ~~~ This will output a textual report for the combined coverage from `A` and `B`'s test suites, along with a path to the HTML for the report. This command also supports taking extra `.tix` files. If you've also built an executable, against exactly the same library versions of `A`, `B`, and `C`, then you could command the following: ~~~text stack exec -- an-exe stack hpc report A B C an-exe.tix ~~~ or, equivalently: ~~~text stack exec -- an-exe stack hpc report --all an-exe.tix ~~~ This report will consider all test results as well as the newly generated `an-exe.tix` file. ## Usage `stack test --coverage` is quite streamlined for the following use-case: 1. You have test suites which exercise your local packages. 2. These test suites link against your library, rather than building the library directly. Coverage information is only given for libraries, ignoring the modules which get compiled directly into your executable. A common case where this doesn't happen is when your test suite and library both have something like `hs-source-dirs: src/`. In this case, when building your test suite you may also be compiling your library, instead of just linking against it. When your project has these properties, you will get the following: 1. Textual coverage reports in the build output. 2. A unified textual and HTML report, considering the coverage on all local libraries, based on all of the tests that were run. 3. An index of all generated HTML reports, in `index.html` in the local HPC root directory. ## Implementation details Most users can get away with just understanding the above documentation. However, advanced users may want to understand exactly how `--coverage` works: 1. The GHC option `-fhpc` gets passed to all local packages. This tells GHC to output executables that track coverage information and output them to `.tix` files. `the-exe-name.tix` files will get written to the working directory of the executable. When switching on this flag, it will usually cause all local packages to be rebuilt (see issue [#1940](https://github.com/commercialhaskell/stack/issues/1940)). 2. Before the build runs with `--coverage`, the contents of the local HPC root directory gets deleted. This prevents old reports from getting mixed with new reports. If you want to preserve report information from multiple runs, copy the contents of this path to a new directory. 3. Before a test run, if a `test-name.tix` file exists in the package directory, it will be deleted. 4. After a test run, it will expect a `test-name.tix` file to exist. This file will then get loaded, modified, and outputted to `pkg-name/test-name/test-name.tix` in the local HPC root directory. The `.tix` file gets modified to remove coverage file that isn't associated with a library. So, this means that you won't get coverage information for the modules compiled in the `executable` or `test-suite` stanza of your Cabal file. This makes it possible to directly union multiple `*.tix` files from different executables (assuming they are using the exact same versions of the local packages). If there is enough popular demand, it may be possible in the future to give coverage information for modules that are compiled directly into the executable. See issue [#1359](https://github.com/commercialhaskell/stack/issues/1359). 5. Once we have a `.tix` file for a test, we also generate a textual and HTML report for it. The textual report is sent to the terminal. The index of the test-specific HTML report is available `pkg-name/test-name/index.html` in the local HPC root directory. 6. After the build completes, if there are multiple output `*.tix` files, they get combined into a unified report. The index of this report will be available at `combined/all/index.html` in the local HPC root directory. 7. Finally, an index of the resulting coverage reports is generated. It links to the individual coverage reports (one for each test-suite), as well as the unified report. This index is available at `index.html` in the local HPC root directory. stack-2.9.3.1/doc/ide_command.md0000644000000000000000000000301014445022466014506 0ustar0000000000000000
# The `stack ide` commands ~~~text stack ide COMMAND Available commands: packages List all available local loadable packages targets List all available Stack targets ~~~ The `stack ide` commands provide information that may be of use in an integrated development environment (IDE). See `stack ide` for the available commands. ## The `stack ide packages` command ~~~text stack ide packages [--stdout] [--cabal-files] ~~~ `stack ide packages` lists all available local packages that are loadable. By default: * its output is sent to the standard error channel. Pass the flag `--stdout` to change to the standard output channel; and * the output is the package name (without its version). Pass the flag `--cabal-files` to change to the full path to the package's Cabal file. ## The `stack ide targets` command ~~~text stack ide targets [--stdout] ~~~ `stack ide targets` lists all available Stack targets. By default, its output is sent to the standard error channel. Pass the flag `--stdout` to change to the standard output channel. For example, for the Stack project itself, command: ~~~text cd stack stack ide targets ~~~ and the output from the second command is: ~~~text stack:lib stack:exe:stack stack:exe:stack-integration-test stack:test:stack-test ~~~ stack-2.9.3.1/doc/init_command.md0000644000000000000000000000167614445022466014730 0ustar0000000000000000
# The `stack init` command ~~~text stack init [DIR(S)] [--omit-packages] [--force] [--ignore-subdirs] ~~~ `stack init` initialises Stack's project-level YAML configuration file (`stack.yaml`) for an existing project, based on the Cabal file or `package.yaml` file for each of its packages. Stack searches for Cabal and `package.yaml` files in the current directory, unless one or more directories are specified as arguments. Stack also searches for Cabal and `package.yaml` files in subdirectories, unless the `--ignore-subdirs` flag is passed. Stack will not overwrite an existing `stack.yaml` file, unless the `--force` flag is passed. Pass the `--ignore-subdirs` flag to cause Stack to ignore conflicting or incompatible user packages while initialising. stack-2.9.3.1/doc/install_and_upgrade.md0000644000000000000000000005152214445022466016261 0ustar0000000000000000
# Install or upgrade ## Install Stack Stack can be installed on most Linux distributions, macOS and Windows. Stack is open to supporting more operating systems. To request support for an operating system, please submit an [issue](https://github.com/commercialhaskell/stack/issues/new) at Stack's GitHub repository. !!! info In addition to the methods described below, Stack can also be installed using the separate [GHCup](https://www.haskell.org/ghcup/) installer for Haskell-related tools. GHCup provides Stack for some combinations of machine architecture and operating system not provided elsewhere. Unlike Stack, other build tools do not automatically install GHC. GHCup can be used to install GHC for those other tools. By default, the script to install GHCup (which can be run more than once) also configures Stack so that if Stack needs a version of GHC, GHCup takes over obtaining and installing that version. !!! info "Releases on GitHub" Stack executables are also available on the [releases](https://github.com/commercialhaskell/stack/releases) page of Stack's GitHub repository. !!! info "`https://get.haskellstack.org/stable` URLs" URLs with the format `https://get.haskellstack.org/stable/.` point to the latest stable release. See the manual download links for examples. === "Linux" For most Linux distributions, the easiest way to install Stack is to command: ~~~text curl -sSL https://get.haskellstack.org/ | sh ~~~ or: ~~~text wget -qO- https://get.haskellstack.org/ | sh ~~~ !!! note The script at [get.haskellstack.org](https://get.haskellstack.org/) will ask for root access using `sudo`. It needs such access in order to use your platform's package manager to install dependencies and to install to `/usr/local/bin`. If you prefer more control, follow the manual installation instructions for your platform below. ### Manual download Manual download for Linux distributions depends on your machine architecture, x86_64 or AArch64/ARM64. === "x86_64" * Click [:material-cloud-download-outline:](https://get.haskellstack.org/stable/linux-x86_64.tar.gz) to download an archive file with the latest release. * Extract the archive and place the `stack` executable somewhere on your PATH (see the [Path](#path) section below). * Ensure you have the required system dependencies installed. These include GCC, GNU Make, xz, perl, libgmp, libffi, and zlib. We also recommend Git and GPG. The installation of system dependencies will depend on the package manager for your Linux distribution. Notes are provided for Arch Linux, CentOS, Debian, Fedora, Gentoo and Ubuntu. === "Arch Linux" ~~~text sudo pacman -S make gcc ncurses git gnupg xz zlib gmp libffi zlib ~~~ === "CentOS" ~~~text sudo yum install perl make automake gcc gmp-devel libffi zlib zlib-devel xz tar git gnupg ~~~ === "Debian" ~~~text sudo apt-get install g++ gcc libc6-dev libffi-dev libgmp-dev make xz-utils zlib1g-dev git gnupg netbase ~~~ === "Fedora" ~~~text sudo dnf install perl make automake gcc gmp-devel libffi zlib zlib-devel xz tar git gnupg ~~~ === "Gentoo" Ensure you have the `ncurses` package with `USE=tinfo`. Without it, Stack will not be able to install GHC. === "Ubuntu" ~~~text sudo apt-get install g++ gcc libc6-dev libffi-dev libgmp-dev make xz-utils zlib1g-dev git gnupg netbase ~~~ ### Linux packages Some Linux distributions have official or unofficial packages for Stack, including Arch Linux, Debian, Fedora, NixOS, openSUSE/SUSE Linux Enterprise, and Ubuntu. !!! info "Linux packages that lag behind Stack's current version" The Stack version available as a Linux package may lag behind Stack's current version. If so, using `stack upgrade --binary-only` is recommended after installing it. For Stack versions before 1.3.0 which do not support `--binary-only`, just `stack upgrade` may work too. === "Arch Linux" The Arch community package repository provides an official [package](https://www.archlinux.org/packages/community/x86_64/stack/). You can install it with the command: ~~~text sudo pacman -S stack ~~~ This version may slightly lag behind, but it should be updated within the day. The package is also always rebuilt and updated when one of its dependencies gets an update. The Arch User Repository (AUR) also provides a [package](https://aur.archlinux.org/packages/haskell-stack-git). However, its Stack version lags behind, so running `stack upgrade --binary-only` is recommended after installing it. For older Stack versions which do not support `--binary-only`, just `stack upgrade` may work too. To use `stack setup` with versions of GHC before 7.10.3 or on a 32-bit system, you may need the AUR [ncurses5-compat-libs](https://aur.archlinux.org/packages/ncurses5-compat-libs/) package installed. === "Debian" There are Debian [packages](https://packages.debian.org/search?keywords=haskell-stack&searchon=names&suite=all§ion=all) for Stretch and up. However, the distribution's Stack version lags behind. === "Fedora" Fedora includes Stack, but its Stack version may lag behind. === "NixOS" Users who follow the `nixos-unstable` channel or the Nixpkgs `master` branch can install the latest Stack release into their profile with the command: ~~~text nix-env -f "" -iA stack ~~~ Alternatively, the package can be built from source as follows. 1. Clone the git repo, with the command: ~~~text git clone https://github.com/commercialhaskell/stack.git ~~~ 2. Create a `shell.nix` file with the command: ~~~text cabal2nix --shell ./. --no-check --no-haddock > shell.nix ~~~ Note that the tests fail on NixOS, so disable them with `--no-check`. Also, Haddock currently doesn't work for Stack, so `--no-haddock` disables it. 3. Install Stack to your user profile with the command: ~~~text nix-env -i -f shell.nix ~~~ For more information on using Stack together with Nix, please see the [NixOS manual section on Stack](http://nixos.org/nixpkgs/manual/#how-to-build-a-haskell-project-using-stack). === "SUSE" There is also an unofficial package for openSUSE or SUSE Linux Enterprise. Its Stack version may lag behind. To install it: === openSUSE Tumbleweed ~~~text sudo zypper in stack ~~~ === openSUSE Leap ~~~text sudo zypper ar http://download.opensuse.org/repositories/devel:/languages:/haskell/openSUSE_Leap_42.1/devel:languages:haskell.repo sudo zypper in stack ~~~ === SUSE Linux Enterprise 12 ~~~text sudo zypper ar http://download.opensuse.org/repositories/devel:/languages:/haskell/SLE_12/devel:languages:haskell.repo sude zypper in stack ~~~ === "Ubuntu" There are Ubuntu [packages](http://packages.ubuntu.com/search?keywords=haskell-stack&searchon=names&suite=all§ion=all) for Ubuntu 18.04 and up. However, the distribution's Stack version lags behind. It is possible to set up auto-completion of Stack commands. For further information, see the [shell auto-completion](shell_autocompletion.md) documentation. === "macOS" The easiest way to install Stack is to command: ~~~text curl -sSL https://get.haskellstack.org/ | sh ~~~ or: ~~~text wget -qO- https://get.haskellstack.org/ | sh ~~~ !!! note The script at [get.haskellstack.org](https://get.haskellstack.org/) will ask for root access using `sudo`. It needs such access in order to use your platform's package manager to install dependencies and to install to `/usr/local/bin`. If you prefer more control, follow the manual installation instructions below. !!! info We generally test on the current version of macOS and do our best to keep it compatible with the three most recent major versions. Stack may also work on older versions. ### Manual download * Click [:material-cloud-download-outline:](https://get.haskellstack.org/stable/osx-x86_64.tar.gz) to download an archive file with the latest release for x86_64 architectures. * Extract the archive and place `stack` somewhere on your PATH (see the [Path](#path) section below). * Now you can run Stack from the command line in a terminal. ### Using Homebrew [Homebrew](https://brew.sh/) is a popular package manager for macOS. If you have its `brew` tool installed, you can just command: ~~~text brew install haskell-stack ~~~ * The Homebrew formula and bottles are **unofficial** and lag slightly behind new Stack releases, but tend to be updated within a day or two. * Normally, Homebrew will install from a pre-built binary (aka "pour from a bottle"), but if it starts trying to build everything from source (which will take hours), see [their FAQ on the topic](https://github.com/Homebrew/brew/blob/master/docs/FAQ.md#why-do-you-compile-everything). ### Notes After installation, running `stack setup` might fail with `configure: error: cannot run C compiled programs.` in which case you should command: ~~~text xcode-select --install ~~~ Starting with macOs 10.14 (Mojave) running `xcode-select --install` [might not be enough](https://forums.developer.apple.com/thread/104296). You will need to install additional headers with commands: ~~~text cd /Library/Developer/CommandLineTools/Packages/ open macOS_SDK_headers_for_macOS_10.14.pkg ~~~ If you are on OS X 10.11 (El Capitan) and encounter either of these problems, see the linked FAQ entries: * [GHC 7.8.4 fails with `/usr/bin/ar: permission denied`](faq.md#usr-bin-ar-permission-denied) * [DYLD_LIBRARY_PATH is ignored](faq.md#dyld-library-path-ignored) If you are on macOS 10.12 (Sierra) and encounter GHC panic while building, see this [issue](https://github.com/commercialhaskell/stack/issues/2577) On Apple silicon chip (AArch64/ARM64) architectures, the installation of Stack or some packages (e.g. `network`) requiring C source compilation might fail with `configure: error: C compiler cannot build executables`. In that case you should pass `-arch arm64` as part of the `CFLAGS` environment variable. This setting will be picked up by the C compiler of your choice. ~~~bash # Assuming BASH below # passing CFLAGS in-line with the command giving rise to the error CFLAGS="-arch arm64 ${CFLAGS:-}" some_command_to_install_stack CFLAGS="-arch arm64 ${CFLAGS:-}" stack [build|install] # -- OR -- # ~/.bash_profile # NOTE: only do this if you do not have to cross-compile, or remember to unset # CFLAGS when needed export CFLAGS="-arch arm64 ${CFLAGS:-}" ~~~ The setting instructs the C compiler to compile objects for ARM64. These can then be linked with libraries built for ARM64. Without the instruction, the C compiler, invoked by Cabal running in x86-64, would compile x86-64 objects and attempt to link them with existing ARM64 libraries, resulting in the error above. It is possible to set up auto-completion of Stack commands. For further information, see the [shell auto-completion](shell_autocompletion.md) documentation. === "Windows" On 64-bit Windows, you can download and install the [Windows installer](https://get.haskellstack.org/stable/windows-x86_64-installer.exe). !!! note "Anti-virus software" Systems with antivirus software may need to add Stack to the list of 'trusted' applications. You may see a "Windows Defender SmartScreen prevented an unrecognized app from starting" warning when you try to run the installer. If so, click on **More info**, and then click on the **Run anyway** button that appears. We recommend installing to the default location with the installer, as that will make `stack install` and `stack upgrade` work correctly out of the box. ### Manual download * Click [:material-cloud-download-outline:](https://get.haskellstack.org/stable/windows-x86_64.zip) to download an archive file with the latest release. * Unpack the archive and place `stack.exe` somewhere on your PATH (see the [Path](#path) section below). * Now you can run Stack from the command line in a terminal. ## Path You can install Stack by copying the executable file anywhere on your PATH. A good place to install is the same directory where Stack itself will install executables, which depends on the operating system: === "Unix-like" Stack installs executables to: ~~~text $HOME/.local/bin ~~~ If you don't have that directory in your PATH, you may need to update your PATH. That can be done by editing the `~/.bashrc` file. === "Windows" Stack installs executables to: ~~~text %APPDATA%\local\bin ~~~ For example: `C:\Users\\AppData\Roaming\local\bin`. If you don't have that directory in your PATH, you may need to update your PATH. That can be done by searching for 'Edit Environment variables for your account' under Start. !!! note If you used [GHCup](https://www.haskell.org/ghcup/) to install Stack, GHCup puts executable files in the `bin` directory in the GHCup root directory. ## China-based users If you're attempting to install Stack from within China: * As of 24 February 2020, the download link has limited connectivity from within mainland China. If this is the case, please proceed by manually downloading (ideally via a VPN) and installing Stack per the instructions found on this page pertinent to your operating system. * After installation, your `config.yaml` file will need to be configured before Stack can download large files consistently from within China (without reliance on a VPN). Please add the following to the bottom of the `config.yaml` file: ~~~yaml ###ADD THIS IF YOU LIVE IN CHINA setup-info-locations: - "http://mirrors.tuna.tsinghua.edu.cn/stackage/stack-setup.yaml" urls: latest-snapshot: http://mirrors.tuna.tsinghua.edu.cn/stackage/snapshots.json package-indices: - download-prefix: http://mirrors.tuna.tsinghua.edu.cn/hackage/ ~~~ ## Using an HTTP proxy To use Stack behind a HTTP proxy with IP address *IP* and port *PORT*, first set up an environment variable `http_proxy` and then run the Stack command. For example: === "Unix-like" ~~~text export http_proxy=IP:PORT stack install ~~~ On most operating systems, it is not mandatory for programs to follow the "system-wide" HTTP proxy. Some programs, such as browsers, do honor this "system-wide" HTTP proxy setting, while other programs, including Bash, do not. That means configuring "http proxy setting" in your System Preferences (macOS) would not result in Stack traffic going through the proxy. === "Windows" ~~~text $Env:http_proxy=IP:PORT stack install ~~~ It is not mandatory for programs to follow the "system-wide" HTTP proxy. Some programs, such as browsers, do honor this "system-wide" HTTP proxy setting, while other programs do not. That means configuring "http proxy setting" in your Control Panel would not result in Stack traffic going through the proxy. ## Upgrade Stack There are different approaches to upgrading Stack, which vary as between Unix-like operating systems (including macOS) and Windows. !!! note If you used [GHCup](https://www.haskell.org/ghcup/) to install Stack, you should also use GHCup to upgrade Stack. GHCup uses an executable named `stack` to manage versions of Stack, through a file `stack.shim`. Stack will likely overwrite the executable on upgrade. === "Unix-like" There are essentially four different approaches: 1. The `stack upgrade` command, which downloads a Stack executable, or builds it from source, and installs it to Stack's 'local-bin' directory (see `stack path --local-bin`). If different and permitted, it also installs a copy in the directory of the current Stack executable. (If copying is not permitted, copy `stack` from Stack's 'local-bin' directory to the system location afterward.) You can use `stack upgrade` to get the latest official release, and `stack upgrade --git` to install from GitHub and live on the bleeding edge. Make sure the location of the Stack executable is on the PATH. See the [Path](#Path) section above. 2. If you're using a package manager and are happy with sticking with the officially released binaries from the distribution (which may the lag behind the latest version of Stack significantly), simply follow your normal package manager strategies for upgrading. For example: ~~~text apt-get update apt-get upgrade ~~~ 3. The `get.haskellstack.org` script supports the `-f` argument to over-write the current Stack executable. For example, command: ~~~text curl -sSL https://get.haskellstack.org/ | sh -s - -f ~~~ or: ~~~text wget -qO- https://get.haskellstack.org/ | sh -s - -f ~~~ 4. Manually follow the steps above to download the newest executable from the GitHub releases page and replace the old executable. === "Windows" There are essentially two different approaches: 1. The `stack upgrade` command, which downloads a Stack executable, or builds it from source, and installs it to Stack's 'local-bin' directory (see `stack path --local-bin`). If different and permitted, it also installs a copy in the directory of the current Stack executable. (If copying is not permitted, copy `stack` from Stack's 'local-bin' directory to the system location afterward.) You can use `stack upgrade` to get the latest official release, and `stack upgrade --git` to install from GitHub and live on the bleeding edge. Make sure the location of the Stack executable is on the PATH. See the [Path](#Path) section above. 2. Manually follow the steps above to download the newest executable from the GitHub releases page and replace the old executable. ## Install earlier versions To install a specific version of Stack, navigate to the desired version on the [GitHub release page](https://github.com/commercialhaskell/stack/releases), and click the appropriate link under its "Assets" drop-down menu. Alternatively, use the URL `https://github.com/commercialhaskell/stack/releases/download/vVERSION/stack-VERSION-PLATFORM.EXTENSION`. For example, the tarball for Stack version 2.1.0.1, osx-x86_64 is at `https://github.com/commercialhaskell/stack/releases/download/v2.1.0.1/stack-2.1.0.1-osx-x86_64.tar.gz`. Here's a snippet for `appveyor.yml` files, borrowed from `dhall`'s [`appveyor.yml`](https://github.com/dhall-lang/dhall-haskell/blob/1079b7a3a7a6922f72a373e47daf6f1b74f128b1/appveyor.yml). Change the values of PATH and VERSION as needed. ~~~yaml install: - set PATH=C:\Program Files\Git\mingw64\bin;%PATH% - curl --silent --show-error --output stack.zip --location "https://github.com/commercialhaskell/stack/releases/download/v%STACK_VERSION%/stack-%STACK_VERSION%-windows-x86_64.zip" - 7z x stack.zip stack.exe - stack setup > nul - git submodule update --init --recursive ~~~ stack-2.9.3.1/doc/list_command.md0000644000000000000000000000354614445022466014736 0ustar0000000000000000
# The `stack list` command [:octicons-tag-24: 2.7.1](https://github.com/commercialhaskell/stack/releases/tag/v2.7.1) ~~~text stack list [PACKAGE] ~~~ `stack list ` will list the latest version of the package from Hackage. If the package name cannot be found on Hackage, even after updating the package index, suggestions (not necessarily good ones) will be made about the intended package name. `stack --resolver ` will list the version of the package in the specified snapshot, unless the package comes with GHC on Unix-like operating systems. If the package name cannot be found in the snapshot, the command will fail, identifying only the package(s) that did not appear in the snapshot. More than one package name can be specified. `stack --resolver ` will list all the packages in the specified snapshot, except those which come with GHC on Unix-like operating systems. For example: ~~~text stack list base unix Win32 acme-missiles pantry base-4.17.0.0 unix-2.8.0.0 Win32-2.13.3.0 acme-missiles-0.3 pantry-0.5.7 stack list paltry Could not find package paltry, updating ... Package index cache populated - Could not find package paltry on Hackage. Perhaps you meant: pretty, pasty, xattr, alloy, para, pappy, alure, polar, factory, pastis stack --resolver lts-19.25 base unix Win32 acme-missiles pantry - Package does not appear in snapshot: base - Package does not appear in snapshot: unix - Package does not appear in snapshot: acme-missiles stack --resolver lts-19.25 Win32 pantry Win32-2.12.0.1 pantry-0.5.7 stack --resolver lts-19.25 AC-Angle-1.0 ALUT-2.4.0.3 ... zstd-0.1.3.0 ztail-1.2.0.3 ~~~ stack-2.9.3.1/doc/lock_files.md0000644000000000000000000001460414445022466014374 0ustar0000000000000000
# Lock Files Stack attempts to provide reproducible build plans. This involves reproducibly getting the exact same contents of source packages and configuration options (like Cabal flags and GHC options) for a given set of input files. There are a few problems with making this work: * Entering all of the information to fully provide reproducibility is tedious. This would include things like Hackage revisions, hashes of remote tarballs, etc. Users don't want to enter this information. * Many operations in Stack rely upon a "snapshot hash," which transitively includes the completed information for all of these dependencies. If any of that information is missing when parsing the `stack.yaml` file or snapshot files, it could be expensive for Stack to calculate it. To address this, we follow the (fairly standard) approach of having a _lock file_. The goal of the lock file is to cache completed locations of project, snapshot packages and snapshots themselves so that: * These files can be stored in source control * Users on other machines can reuse these lock files and get identical build plans given that the used local packages and local snapshots are the same on those machines * Rerunning `stack build` in the future is deterministic in the build plan, not depending on mutable state in the world like Hackage revisions !!! note If, for example, a tarball available remotely is deleted or the hash changes, it will not be possible for Stack to perform the build. However, by deterministic, we mean it either performs the same build or fails, never accidentally doing something different. This document explains the contents of a lock file, how they are used, and how they are created and updated. ## stack.yaml and snapshot files Relevant to this discussion, Stack's project-level configuration file (`stack.yaml`) specifies: * the parent snapshot (`resolver` or `snapshot`) * extra-deps Some of this information can be incomplete. Consider this `stack.yaml` file: ~~~yaml resolver: lts-19.22 packages: - . extra-deps: - acme-missiles-0.3 ~~~ This information is _incomplete_. For example, the extra-deps may change in the future. Instead, you could specify enough information in the `stack.yaml` file to fully resolve that package. That looks like: ~~~yaml extra-deps: - hackage: acme-missiles-0.3@sha256:2ba66a092a32593880a87fb00f3213762d7bca65a687d45965778deb8694c5d1,613 pantry-tree: size: 226 sha256: 614bc0cca76937507ea0a5ccc17a504c997ce458d7f2f9e43b15a10c8eaeb033 ~~~ The `lts-19.22` information is also incomplete. While we assume in general that Haskell LTS snapshots never change, there's nothing that prohibits that from happening. Instead, the complete version of that key is: ~~~yaml resolver: - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/19/22.yaml size: 619399 sha256: 5098594e71bdefe0c13e9e6236f12e3414ef91a2b89b029fd30e8fc8087f3a07 ~~~ Users don't particularly feel like writing all of that. Therefore, it's common to see _incomplete_ information in a `stack.yaml` file. ## Recursive snapshot layers Snapshot files can be _recursive_, where `stack.yaml` refers to `foo.yaml`, which refers to `bar.yaml`, which refers to `baz.yaml`. A local snapshot file can refer to a remote snapshot file (available via an HTTP(S) URL). We need to encode information from _all_ of these snapshot layers and the `stack.yaml` file in the lock file, to ensure that we can detect if anything changes. ## Performance In addition to acting as a pure correctness mechanism, the design of a lock file given here also works as a performance improvement. Instead of requiring that all snapshot files be fully parsed on each Stack invocation, we can store information in the lock file and bypass parsing of the additional files in the common case of no changes. ## Lock file contents The lock file contains the following information: * Completed package locations for extra deps and packages in snapshot files !!! note This only applies to _immutable_ packages. Mutable packages are not included in the lock file. * Completed information for the snapshot locations It looks like the following: ~~~yaml # Lock file, some message about the file being auto-generated snapshots: # Starts with the snapshot specified in stack.yaml, # then continues with the snapshot specified in each # subsequent snapshot file - original: foo.yaml # raw content specified in a snapshot file completed: file: foo.yaml sha256: XXXX size: XXXX - original: lts-13.9 completed: size: 496662 url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/9.yaml sha256: 83de9017d911cf7795f19353dba4d04bd24cd40622b7567ff61fc3f7223aa3ea packages: - original: https://hackage.haskell.org/package/acme-missiles-0.3.tar.gz completed: size: 1442 url: https://hackage.haskell.org/package/acme-missiles-0.3.tar.gz name: acme-missiles version: '0.3' sha256: e563d8b524017a06b32768c4db8eff1f822f3fb22a90320b7e414402647b735b pantry-tree: size: 226 sha256: 614bc0cca76937507ea0a5ccc17a504c997ce458d7f2f9e43b15a10c8eaeb033 ~~~ ## Creation Whenever a project-level configuration file (`stack.yaml`) is loaded, Stack checks for a lock file in the same file path, with a `.lock` extension added. For example, if you command: ~~~text stack build --stack-yaml my-stack.yaml ~~~ Stack will use a lock file in the location `my-stack.yaml.lock`. For the rest of this document, we'll assume that the files are simply `stack.yaml` and `stack.yaml.lock`. If the lock file does not exist, it will be created by: * Loading the `stack.yaml` * Loading all snapshot files * Completing all missing information * Writing out the new `stack.yaml.lock` file ## Update procedure When loading a Stack project all completed package or snapshot locations (even when they were completed using information from a lock file) get collected to form a new lock file in memory and compare against the one on disk, writing if there are any differences. stack-2.9.3.1/doc/ls_command.md0000644000000000000000000001345314353310533014370 0ustar0000000000000000
# The `stack ls` commands ~~~text stack ls COMMAND Available commands: dependencies View the dependencies snapshots View snapshots (local by default) stack-colors View Stack's output styles stack-colours View Stack's output styles (alias for 'stack-colors') tools View Stack's installed tools ~~~ The `stack ls` commands list different types of information. Command `stack ls` for the available commands. ## The `stack ls dependencies` command Either ~~~text stack ls dependencies COMMAND Available commands: cabal Print dependencies as exact Cabal constraints json Print dependencies as JSON text Print dependencies as text (default) tree Print dependencies as tree ~~~ or ~~~text stack ls dependencies [--separator SEP] [--[no-]license] [--[no-]external] [--[no-]include-base] [--depth DEPTH] [--prune PACKAGES] [TARGET] [--flag PACKAGE:[-]FLAG] [--test] [--bench] [--global-hints] ~~~ `stack ls dependencies` lists all of the packages and versions used for a project. All local packages are considered by default, but a target can be specified as an argument. For further information, see the [target syntax](build_command.md#target-syntax) documentation. Subcommands specify the format of the output, as follows: * `cabal` lists the packages in the format of exact Cabal constraints. For example (extract): ~~~text constraints: , Cabal ==3.6.3.0 , Cabal-syntax ==3.6.0.0 , Glob ==0.10.2 ~~~ * `json` lists dependencies in JSON format (an array of objects). For example (extract): ~~~text [{"dependencies":["base","bytestring"],"license":"BSD3","location":{"type":"hackage","url":"https://hackage.haskell.org/package/zlib-0.6.3.0"},"name":"zlib","version":"0.6.3.0"}, ~~~ Each object has the following keys: ~~~json name: zlib version: 0.6.3.0 location: type: hackage url: https://hackage.haskell.org/package/zlib-0.6.3.0 licence: BSD3 dependencies: - base - bytestring ~~~ * `text` (the default) lists the packages, each on a separate line. For example (extract): ~~~text Cabal 3.6.3.0 Cabal-syntax 3.6.0.0 Glob 0.10.2 ~~~ * `tree` lists dependencies in the format of a tree. For example (extract): ~~~text Packages └─┬ stack 2.10.0 ├─┬ Cabal 3.6.3.0 │ ├─┬ Win32 2.12.0.1 │ │ ├─┬ base 4.16.3.0 │ │ │ ├─┬ ghc-bignum 1.2 │ │ │ │ └─┬ ghc-prim 0.8.0 │ │ │ │ └── rts 1.0.2 │ │ │ ├─┬ ghc-prim 0.8.0 ~~~ The `--separator` option specifies the separator between the package name and its version. The default is a space character. Set the `--licence` flag, after the `text` or `tree` subcommand, to replace each package's version with its licence. Set the `--no-external` flag to exclude external dependencies. Set the `--no-include-base` flag to exclude dependencies on the `base` package. The `--depth` option limits the depth of dependency resolution. The `--prune ` option prunes the specified packages from the output, where `` is a comma separated list of package names. The `--flag` option allows Cabal flags to be specified. Pass the `--test` flag to consider the dependencies of test suite components. Pass the `--bench` flag to consider the dependencies of benchmark components. Pass the `--global-hints` flag to use a hints file for global packages. The command then does not require an installed GHC. ## The `stack ls snapshots` command ~~~text stack ls snapshots [COMMAND] [-l|--lts] [-n|--nightly] Available commands: local View local snapshots remote View remote snapshots ~~~ `stack ls snapshots` will list all the local snapshots by default. You can also view the remote snapshots using `stack ls snapshots remote`. It also supports options for viewing only lts (`-l`) and nightly (`-n`) snapshots. ## The `stack ls stack-colors` command ~~~text stack ls stack-colors [--[no-]basic] [--[no-]sgr] [--[no-]example] ~~~ The British English spelling is also accepted (`stack ls stack-colours`). `stack ls stack-colors` will list all of Stack's output styles. A number of different formats for the output are available, see `stack ls stack-colors --help`. The default is a full report, with the equivalent SGR instructions and an example of the applied style. The latter can be disabled with flags `--no-sgr` and `--no-example`. The flag `--basic` specifies a more basic report, in the format that is accepted by Stack's command line option `--stack-colors` and the YAML configuration key `stack-colors`. ## The `stack ls tools` command ~~~text stack ls tools [--filter TOOL_NAME] ~~~ `stack ls tools` will list Stack's installed tools. On Unix-like operating systems, they will be one or more versions of GHC. On Windows, they will include MSYS2. For example, on Windows the command: ~~~text stack ls tools ~~~ yields output like: ~~~text ghc-9.4.1 ghc-9.2.4 ghc-9.0.2 msys2-20210604 ~~~ The `--filter ` option will filter the output by a tool name (e.g. 'ghc', 'ghc-git' or 'msys2'). The tool name is case sensitive. For example the command: ~~~text stack ls tools --filter ghc ~~~ yields output like: ~~~text ghc-9.4.1 ghc-9.2.4 ghc-9.0.2 ~~~ stack-2.9.3.1/doc/new_command.md0000644000000000000000000000177714445022466014560 0ustar0000000000000000
# The `stack new` command ~~~text stack new PACKAGE_NAME [--bare] [TEMPLATE_NAME] [-p|--param KEY:VALUE] [DIR(S)] [--omit-packages] [--force] [--ignore-subdirs] ~~~ `stack new` creates a new Stack project for a package using a template. The project is created in a new directory named after the package, unless the `--bare` flag is passed, in which case the project is created in the current directory. The template used is a default one (named `new-template`), unless another template is specified as an argument. The `--param :` option specifies a key-value pair to populate a key in a template. The option can be specified multiple times. The arguments specifying directories and the `--ignore-subdirs`, `--force` and `--omit-packages` flags are as for the [`stack init` command](init_command.md). stack-2.9.3.1/doc/nix_integration.md0000644000000000000000000004063314445022466015464 0ustar0000000000000000
# Nix integration [:octicons-tag-24: 0.1.10.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.10.0) [Nix](https://nixos.org/) is a purely functional package manager. Stack can be configured to integrate with Nix. The Nix package manager is a pre-requisite for integration. On Linux (including Windows Subsystem for Linux) and macOS, it can be downloaded and installed from the [Nix download page](https://nixos.org/download.html). When integrated with Nix, Stack handles Haskell dependencies as it usually does and the Nix package manager handles the _non-Haskell_ dependencies needed by the Haskell packages. Stack downloads Haskell packages from [Stackage](https://www.stackage.org/lts) and builds them locally. Stack uses Nix to download [Nix packages][nix-search-packages]. These provide the GHC compiler and external C libraries that you would normally install manually. Nix's `nix-shell` starts an interactive shell based on a Nix expression. Stack can automatically create a Nix build environment in the background using `nix-shell`. There are two alternative options to create such a build environment: 1. provide a list of [Nix packages][nix-search-packages] 2. provide a `shell.nix` file that gives you more control over the libraries and tools available inside the shell. A `shell.nix` file requires writing code in Nix's [custom language][nix-language]. Use this option only if you know Nix and have special requirements, such as using custom Nix packages that override the standard ones or using system libraries with special requirements. ### Checking the Nix installation Once Nix is installed, the Nix commands (`nix-shell` etc) should be available. If they are not, it could be because the file `$HOME/.nix-profile/etc/profile.d/nix.sh` is not sourced by your shell. You should either: 1. run `source ~/.nix-profile/etc/profile.d/nix.sh` each time you open a terminal and need Nix; or 2. add the command `source ~/.nix-profile/etc/profile.d/nix.sh` to your `~/.bashrc` or `~/.bash_profile` file. ### Enable Nix integration To enable Nix integration, add the following section to your Stack YAML configuration file (`stack.yaml` or `config.yaml`): ~~~yaml nix: enable: true # false by default ~~~ The equivalent command line flag (which will prevail) is `--[no-]nix`. Passing any `--nix-*` option on the command line will imply the `--nix` option. With Nix integration enabled, `stack build` and `stack exec` will automatically launch themselves in a local build environment (using `nix-shell` behind the scenes). It is not necessary to run `stack setup`, unless you want to cache a GHC installation before running a build. **Known limitation on macOS:** currently, `stack --nix ghci` fails on macOS, due to a bug in GHCi when working with external shared libraries. ### Supporting both Nix and non-Nix developers With Nix integration enabled in Stack's YAML configuration file, every developer of your project needs to have Nix installed, but the developer also gets all external libraries automatically. Julien Debon of Tweag has published a [blog post][tweag-blog-post] on *Smooth, non-invasive Haskell Stack and Nix shell integration* (2 June 2022). The post explains how to set things up so that both Nix and non-Nix developers can work together on the same project. The `tweag/haskell-stack-nix-example` [GitHub repository][tweag-example] provides an example of working Stack and Nix shell integration to accompany the post. Nix 2.4 (released 1 November 2021) introduced a new and experimental format to package Nix-based projects, known as 'flakes'. The example below adapts and extends the example accompanying the blog post above to use Nix flakes. The `flake.nix` file is: ~~~nix { description = "my project description"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.flake-utils.url = "github:numtide/flake-utils"; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; hPkgs = pkgs.haskell.packages."ghc8107"; # need to match Stackage LTS version # from stack.yaml resolver myDevTools = [ hPkgs.ghc # GHC compiler in the desired version (will be available on PATH) hPkgs.ghcid # Continuous terminal Haskell compile checker hPkgs.ormolu # Haskell formatter hPkgs.hlint # Haskell codestyle checker hPkgs.hoogle # Lookup Haskell documentation hPkgs.haskell-language-server # LSP server for editor hPkgs.implicit-hie # auto generate LSP hie.yaml file from cabal hPkgs.retrie # Haskell refactoring tool # hPkgs.cabal-install stack-wrapped pkgs.zlib # External C library needed by some Haskell packages ]; # Wrap Stack to work with our Nix integration. We don't want to modify # stack.yaml so non-Nix users don't notice anything. # - no-nix: We don't want Stack's way of integrating Nix. # --system-ghc # Use the existing GHC on PATH (will come from this Nix file) # --no-install-ghc # Don't try to install GHC if no matching GHC found on PATH stack-wrapped = pkgs.symlinkJoin { name = "stack"; # will be available as the usual `stack` in terminal paths = [ pkgs.stack ]; buildInputs = [ pkgs.makeWrapper ]; postBuild = '' wrapProgram $out/bin/stack \ --add-flags "\ --no-nix \ --system-ghc \ --no-install-ghc \ " ''; }; in { devShells.default = pkgs.mkShell { buildInputs = myDevTools; # Make external Nix c libraries like zlib known to GHC, like # pkgs.haskell.lib.buildStackProject does # https://github.com/NixOS/nixpkgs/blob/d64780ea0e22b5f61cd6012a456869c702a72f20/pkgs/development/haskell-modules/generic-stack-builder.nix#L38 LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath myDevTools; }; }); } ~~~ Check-in this `flake.nix` to your project's repository. Run the `nix develop` command (it searches for `flake.nix` by default) and you'll find a new `flake.lock` file. That file that pins the precise nixpkgs package set. Check-in that `flake.lock` file as well, and every Nix developer of your project will use precisely the same package set. ### GHC through Nix packages Nix integration will instruct Stack to build inside a local build environment. That environment will also download and use a [GHC Nix package](https://search.nixos.org/packages?query=haskell.compiler.ghc) matching the required version of the configured [Stack resolver](yaml_configuration.md#resolver-or-snapshot). Enabling Nix integration means that packages will always be built using the local GHC from Nix inside your shell, rather than your globally installed system GHC (if any). Stack can use only GHC versions that are in the Nix package repository. The [Nixpkgs master branch](https://github.com/NixOS/nixpkgs/tree/master/pkgs/development/haskell-modules) usually picks up new versions quickly, but it takes two or three days before those updates arrive in the `unstable` channel. Release channels, like `nixos-22.05`, receive those updates only occasionally -- say, every two or three months --, so you should not expect them to have the latest compiler available. Fresh NixOS installs use a release version by default. To identify whether a given compiler is available, you can use the following Nix command: ~~~sh nix-env -f "" -qaP -A haskell.compiler.ghc924 haskell.compiler.ghc924 ghc-9.2.4 ~~~ If Nix doesn't know that version of GHC, you'll see the following error message: ~~~sh nix-env -f "" -qaP -A haskell.compiler.ghc999 error: attribute ‘ghc999’ in selection path ‘haskell.compiler.ghc999’ not found ~~~ You can list all known Haskell compilers in Nix with the following: ~~~sh nix-instantiate --eval -E "with import {}; lib.attrNames haskell.compiler" ~~~ Alternatively, use `nix repl`, a convenient tool to explore nixpkgs: ~~~sh nix repl ~~~ In the REPL, load nixpkgs and get the same information through autocomplete: ~~~sh nix-repl> :l nix-repl> haskell.compiler.ghc ~~~ You can type and evaluate any Nix expression in the Nix REPL, such as the one we gave to `nix-instantiate` earlier. ### External C libraries through Nix packages To let Nix manage external C libraries, add (for example) the following section to your Stack YAML configuration file: ~~~yaml nix: enable: true packages: [zlib, glpk, pcre] ~~~ The equivalent command line option is `--nix-packages "zlib glpk pcre"`. The `packages` key and the `shell-file` key (see further below) are alternatives. Specifying both results in an error. The example above will instruct Stack to build inside a local build environment that will have the Nix packages [zlib](https://search.nixos.org/packages?query=zlib), [glpk](https://search.nixos.org/packages?query=glpk) and [pcre](https://search.nixos.org/packages?query=pcre) installed, which provide the C libraries of the same names. **Note:** currently, Stack only discovers dynamic and static libraries in the `lib/` folder of any Nix package, and likewise header files in the `include/` folder. If you're dealing with a package that doesn't follow this standard layout, you'll have to deal with that using a custom `shell.nix` file (see further below). ### External C libraries through a `shell.nix` file In Nix, a 'derivation' is a description of a build action and its result is a Nix store object. Nix's [custom language][nix-language] can provide a fully customized derivation as an environment to use. To specify such a `shell.nix` file, add the following section to your Stack YAML configuration file: ~~~yaml nix: enable: true shell-file: shell.nix ~~~ The equivalent command line option (which will prevail) is `--nix-shell-file shell.nix`. The `packages` and `shell-file` keys are alternatives. Specifying both results in an error. Defining a `shell.nix` file allow you to override some Nix derivations, for instance to change some build options of the libraries you use, or to set additional environment variables. For further information, see the [Nix manual][nix-manual-exprs]. The `shell.nix` file that is the equivalent of the `packages: [zlib, glpk, pcre]` example above is: ~~~nix {ghc}: with (import {}); haskell.lib.buildStackProject { inherit ghc; name = "myEnv"; buildInputs = [ zlib glpk pcre ]; } ~~~ The `buildStackProject` utility function is documented in the [Nixpkgs manual][nixpkgs-manual-haskell]. Stack expects the `shell.nix` file to define a function of with one argument called `ghc` (arguments are not positional), which you should give to function `buildStackProject`. This argument is a GHC Nix package in the version as defined in the resolver you set in Stack's project-level configuration file (`stack.yaml`). ### Pure and impure Nix shells By default, Stack will run the build in a *pure* Nix build environment (or *shell*), which means two important things: 1. basically **no environment variable will be forwarded** from your user session to the nix-shell (variables like `HTTP_PROXY` or `PATH` notably will not be available); and 2. the build should fail if you haven't specified all the dependencies in the `packages:` section of the Stack YAML configuration file, even if these dependencies are installed elsewhere on your system. This behaviour enforces a complete description of the build environment to facilitate reproducibility. To override this behaviour, add the following section to your Stack YAML configuration file: ~~~yaml nix: enable: true pure: false ~~~ The equivalent command line flag (which will prevail) is `--[no-]-nix-pure`. **Note:** On macOS, shells are non-pure by default currently. This is due soon to be resolved locale issues. So on macOS you'll need to be a bit more careful to check that you really have listed all dependencies. ### Nix package sources Nix organizes its packages in snapshots of packages (each snapshot being a "package set") similar to how Stackage organizes Haskell packages. By default, `nix-shell` will look for the "nixpkgs" package set located by your `NIX_PATH` environment variable. This package set can be different depending on when you installed Nix and which nixpkgs channel you're using (similar to the LTS channel for stable packages and the nightly channel for bleeding edge packages in [Stackage](https://www.stackage.org/)). This is bad for reproducibility so that nixpkgs should be pinned, i.e., set to the same package set for every developer of your project. To set or override the Nix package set, add the following section to your Stack YAML configuration file: ~~~yaml nix: path: [nixpkgs=] ~~~ The equivalent command line option is `--nix-path `. By this means, you can ask Nix to use your own local checkout of the nixpkgs repository. You could in this way use a bleeding edge nixpkgs, cloned from the `NixOS/nixpkgs` [repository](http://www.github.com/NixOS/nixpkgs) `master` branch, or edit the Nix descriptions of some packages. The Tweag example [repository][tweag-example] shows how you can pin a package set. ## Configuration options Below is a summary of the Stack YAML configuration file settings, identifying default values: ~~~yaml nix: # false by default. Must be present and set to `true` to enable Nix, except on # NixOS where it is enabled by default (see #3938). You can set it in # your `$HOME/.stack/config.yaml` to enable Nix for all your projects without # having to repeat it enable: true # true by default. Tells Nix whether to run in a pure shell or not. pure: true # Empty by default. The list of packages you want to be # available in the nix-shell at build time (with `stack # build`) and run time (with `stack exec`). packages: [] # Unset by default. You cannot set this option if `packages:` # is already present and not empty. shell-file: shell.nix # A list of strings, empty by default. Additional options that # will be passed verbatim to the `nix-shell` command. nix-shell-options: [] # A list of strings, empty by default, such as # `[nixpkgs=/my/local/nixpkgs/clone]` that will be used to override # NIX_PATH. path: [] # false by default. Whether to add your Nix dependencies as Nix garbage # collection roots. This way, calling nix-collect-garbage will not remove # those packages from the Nix store, saving you some time when running # stack build again with Nix support activated. # This creates a `nix-gc-symlinks` directory in the project `.stack-work`. # To revert that, just delete this `nix-gc-symlinks` directory. add-gc-roots: false ~~~ `stack --nix-help` will list the equivalent command line flags and options. ## Stack and developer tools on NixOS NixOS is a Linux distribution based on Nix, that is composed using modules and packages defined in the Nixpkgs project. When using Stack on NixOS, you must use Stack's Nix integration to install GHC. That is because external C libraries in NixOS are not installed in the usual distribution directories. GHC installed through Stack (without Nix) can't find those libraries and, therefore, can't build most projects. However, GHC provided through Nix can be modified to find the external C libraries provided through Nix. [nix-language]: https://nixos.wiki/wiki/Overview_of_the_Nix_Language [nix-manual-exprs]: http://nixos.org/manual/nix/stable/expressions/writing-nix-expressions.html [nix-search-packages]: https://search.nixos.org/packages [nixpkgs-manual-haskell]: https://haskell4nix.readthedocs.io/nixpkgs-users-guide.html?highlight=buildStackProject#how-to-build-a-haskell-project-using-stack [tweag-blog-post]: https://www.tweag.io/blog/2022-06-02-haskell-stack-nix-shell/ [tweag-example]: https://github.com/tweag/haskell-stack-nix-example/ stack-2.9.3.1/doc/nonstandard_project_init.md0000644000000000000000000000255514353310351017337 0ustar0000000000000000
# Non-standard project initialization You may need to configure Stack to work with an existing project that has one or more Cabal files but no Stack project-level configuration file (`stack.yaml`). ## The `stack init` command The `stack init` command: * finds all of the Cabal files in your current directory and subdirectories (unless you use `--ignore-subdirs`) and determines the packages and versions they require * Finds the best combination of snapshot and package flags that allows everything to compile with minimum external dependencies * Tries to look for the best matching snapshot from latest Haskell LTS, latest Stackage Nightly, and other Haskell LTS, in that order If `stack init` finds a match, it will generate a `stack.yaml` file. You can specify the directory, or directories to include in the search for Cabal files. ### The `stack init --force` flag Set the flag to force the over-writing of any existing `stack.yaml` file. ### The `stack init --ignore-subdirs` flag Set the flag to not search for Cabal files in subdirectories. ### The `stack init --omit-packages` flag Set the flag to exclude any conflicting or incompatible user packages. stack-2.9.3.1/doc/other_resources.md0000644000000000000000000000217714353310533015470 0ustar0000000000000000
# Other resources There are lots of resources available for learning more about Stack: * `stack` or `stack --help` — lists Stack's commands, and flags and options common to those commands * `stack --help` — provides help on the particular Stack command, including flags and options specific to the command * `stack --version` — identify the version and Git hash of the Stack executable * `--verbose` (or `-v`) — much more info about internal operations (useful for bug reports) * The [home page](http://haskellstack.org) * The [Stack mailing list](https://groups.google.com/d/forum/haskell-stack) * The [FAQ](faq.md) * The [haskell-stack tag on Stack Overflow](http://stackoverflow.com/questions/tagged/haskell-stack) * [Another getting started with Stack tutorial](http://seanhess.github.io/2015/08/04/practical-haskell-getting-started.html) * [Why is Stack not Cabal?](https://www.fpcomplete.com/blog/2015/06/why-is-stack-not-cabal) stack-2.9.3.1/doc/pantry.md0000644000000000000000000002012014445022466013565 0ustar0000000000000000
# Snapshot and package location [:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1) This document describes: * the specification of a snapshot location (in the `resolver` key) * the specification of a package location (in the `extra-deps` key and in a snapshot) !!! info Stack uses the [Pantry](https://hackage.haskell.org/package/pantry) to specify the location of snapshots and packages. Pantry is geared towards reproducible build plans with cryptographically secure specification of snapshots and packages. ## Snapshot location There are essentially four different ways of specifying a snapshot location: 1. Via a compiler version, which is a "compiler only" snapshot. This could be, for example: ~~~yaml resolver: ghc-8.6.5` ~~~ 2. Via a URL pointing to a snapshot configuration file, for example: ~~~yaml resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2018/8/21.yaml` ~~~ 3. Via a local file path pointing to a snapshot configuration file, for example: ~~~yaml resolver: my-local-snapshot.yaml ~~~ 4. Via a _convenience synonym_, which provides a short form for some common URLs. These are: * GitHub: `github:user/repo:path` is treated as: ~~~text https://raw.githubusercontent.com/user/repo/master/path ~~~ * LTS Haskell: `lts-X.Y` is treated (by default) as: ~~~text github:commercialhaskell/stackage-snapshots:lts/X/Y.yaml ~~~ * Stackage Nightly: `nightly-YYYY-MM-DD` is treated (by default) as: ~~~text github:commercialhaskell/stackage-snapshots:nightly/YYYY/M/D.yaml ~~~ !!! info By default, LTS Haskell and Stackage Nightly snapshot configurations are retrieved from the `stackage-snapshots` GitHub repository of user `commercialhaskell`. The [snapshot-location-base](yaml_configuration.md#snapshot-location-base) option allows a custom location to be set. For safer, more reproducible builds, you can optionally specify a URL together with a cryptographic hash of its content. For example: ~~~yaml resolver: url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/12/0.yaml size: 499143 sha256: 781ea577595dff08b9c8794761ba1321020e3e1ec3297fb833fe951cce1bee11 ~~~ `size` is the number of bytes in the file and `sha256` is the file's SHA256 hash. If not provided, the information will automatically be generated and stored in a [lock file](lock_files.md). ## Package location There are three types of package locations: 1. Hackage packages 2. Git and Mecurial repositories 3. Local or remote archives All three types support optional tree metadata to be added, which can be used for reproducibility and faster downloads. This information can automatically be generated in a [lock file](lock_files.md). ### Hackage packages Packages can be stated by a name-version combination. The basic syntax for this is: ~~~yaml extra-deps: - acme-missiles-0.3 ~~~ Using this syntax, the most recent Cabal file revision available will be used. You can specify a specific revision number, with `0` being the original file, like this: ~~~yaml extra-deps: - acme-missiles-0.3@rev:0 ~~~ For safer, more reproducible builds, you can optionally specify the SHA256 hash of the Cabal file's contents, like this: ~~~yaml extra-deps: - acme-missiles-0.3@sha256:2ba66a092a32593880a87fb00f3213762d7bca65a687d45965778deb8694c5d1 ~~~ You can optionally also specify the size of the Cabal file in bytes, like this: ~~~yaml extra-deps: - acme-missiles-0.3@sha256:2ba66a092a32593880a87fb00f3213762d7bca65a687d45965778deb8694c5d1,631 ~~~ !!! note Specifying package using SHA256 is slightly more resilient in that it does not rely on correct ordering in the package index, while revision number is likely simpler to use. In practice, both should guarantee equally reproducible build plans. You can also include the Pantry tree information. The following would be generated and stored in the lock file: ~~~yaml - hackage: acme-missiles-0.3@sha256:2ba66a092a32593880a87fb00f3213762d7bca65a687d45965778deb8694c5d1,613 pantry-tree: size: 226 sha256: 614bc0cca76937507ea0a5ccc17a504c997ce458d7f2f9e43b15a10c8eaeb033 ~~~ ### Git and Mercurial repositories You can give a Git or Mercurial repository at a specific commit, and Stack will clone that repository. For example: ~~~yaml extra-deps: - git: git@github.com:commercialhaskell/stack.git commit: 6a86ee32e5b869a877151f74064572225e1a0398 - git: git@github.com:snoyberg/http-client.git commit: "a5f4f3" - hg: https://example.com/hg/repo commit: da39a3ee5e6b4b0d3255bfef95601890afd80709 ~~~ !!! note It is highly recommended that you only use SHA1 values for a Git or Mercurial commit. Other values may work, but they are not officially supported, and may result in unexpected behavior (namely, Stack will not automatically pull to update to new versions). Another problem with this is that your build will not be deterministic, because when someone else tries to build the project they can get a different checkout of the package. A common practice in the Haskell world is to use "megarepos", or repositories with multiple packages in various subdirectories. Some common examples include [wai](https://github.com/yesodweb/wai/) and [digestive-functors](https://github.com/jaspervdj/digestive-functors). To support this, you may also specify `subdirs` for repositories. For example: ~~~yaml extra-deps: - git: git@github.com:yesodweb/wai commit: 2f8a8e1b771829f4a8a77c0111352ce45a14c30f subdirs: - auto-update - wai ~~~ If unspecified, `subdirs` defaults to `['.']` meaning looking for a package in the root of the repository. If you specify a value of `subdirs`, then `'.'` is _not_ included by default and needs to be explicitly specified if a required package is found in the top-level directory of the repository. #### GitHub [:octicons-tag-24: 1.7.1](https://github.com/commercialhaskell/stack/releases/tag/v1.7.1) You can specify packages from GitHub repository name using `github`. For example: ~~~yaml extra-deps: - github: snoyberg/http-client commit: a5f4f30f01366738f913968163d856366d7e0342 ~~~ #### git-annex [git-annex](https://git-annex.branchable.com) is not supported. This is because `git archive` does not handle symbolic links outside the work tree. It is still possible to use repositories which use git-annex but do not require the annex files for the package to be built. To do so, ensure that any files or directories stored by git-annex are marked [export-ignore](https://git-scm.com/docs/git-archive#Documentation/git-archive.txt-export-ignore) in the `.gitattributes` file in the repository. For further information, see issue [#4579](https://github.com/commercialhaskell/stack/issues/4579). For example, if the directory `fonts/` is controlled by git-annex, use the following line: ~~~gitattributes fonts export-ignore ~~~ ### Local or remote archives You can use filepaths referring to local archive files or HTTP or HTTPS URLs referring to remote archive files, either tarballs or ZIP files. !!! note Stack assumes that these archive files never change after downloading to avoid needing to make an HTTP request on each build. For safer, more reproducible builds, you can optionally specify a cryptographic hash of the archive file. For example: ~~~yaml extra-deps: - https://example.com/foo/bar/baz-0.0.2.tar.gz - archive: http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip subdirs: - wai - warp - archive: ../acme-missiles-0.3.tar.gz sha256: e563d8b524017a06b32768c4db8eff1f822f3fb22a90320b7e414402647b735b ~~~ stack-2.9.3.1/doc/path_command.md0000644000000000000000000000631514445022466014714 0ustar0000000000000000
# The `stack path` command ~~~text stack path [--stack-root] [--global-config] [--project-root] [--config-location] [--bin-path] [--programs] [--compiler-exe] [--compiler-bin] [--compiler-tools-bin] [--local-bin] [--extra-include-dirs] [--extra-library-dirs] [--snapshot-pkg-db] [--local-pkg-db] [--global-pkg-db] [--ghc-package-path] [--snapshot-install-root] [--local-install-root] [--snapshot-doc-root] [--local-doc-root] [--local-hoogle-root] [--dist-dir] [--local-hpc-root] [--local-bin-path] [--ghc-paths] [--global-stack-root] ~~~ `stack path` provides information about files and locations used by Stack. Pass the following flags for information about specific files or locations: |Flag |File or location | |-----------------------|------------------------------------------------------| |--bin-path |The PATH in the Stack environment. | |--compiler-bin |The directory containing the GHC executable. | |--compiler-exe |The GHC executable. | |--compiler-tools-bin |The directory containing binaries specific to a particular compiler.| |--config-location |Stack's project-level YAML configuration file (`stack.yaml`).| |--dist-dir |The dist working directory, relative to the package directory.| |--extra-include-dirs |Extra include directories. | |--extra-library-dirs |Extra library directories. | |--ghc-package-path |The `GHC_PACKAGE_PATH` environment variable. | |--ghc-paths |Deprecated. | |--global-config |Stack's user-specific global YAML configuration file (`config.yaml`).| |--global-pkg-db |The global package database. | |--global-stack-root |Deprecated. | |--local-bin |The directory in which Stack installs executables. | |--local-bin-path |Deprecated. | |--local-doc-root |The root directory for local project documentation. | |--local-hoogle-root |The root directory for local project documentation. | |--local-hpc-root |The root directory for .tix files and HPC reports. | |--local-install-root |The root directory for local project installation. | |--local-pkg-db |The local package database. | |--programs |The root directory for GHC and other Stack-supplied tools.| |--project-root |The project root directory.| |--snapshot-doc-root |The root directory for snapshot documentation. | |--snapshot-install-root|The root directory for snapshot installation. | |--snapshot-pkg-db |The snapshot package database. | |--stack-root |The Stack root. | stack-2.9.3.1/doc/purge_command.md0000644000000000000000000000053714353310533015073 0ustar0000000000000000
# The `stack purge` command ~~~text stack purge ~~~ `stack purge` has the same effect as, and is provided as a shorthand for, [`stack clean --full`](clean_command.md). stack-2.9.3.1/doc/query_command.md0000644000000000000000000000237214445022466015124 0ustar0000000000000000
# The `stack query` command [:octicons-tag-24: 0.1.6.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.6.0) ~~~text stack query [SELECTOR...] ~~~ `stack query` outputs certain build information. For example, for a multi-package project `multi` specifying snapshot `lts-19.25` (GHC 9.0.2) and with two local packages, `my-package-A` (version 0.1.0.0) and `my-package-B` (version 0.2.0.0), command `stack query` outputs: ~~~text compiler: actual: ghc-9.0.2 wanted: ghc-9.0.2 locals: my-package-A: path: \multi\my-package-A\ version: 0.1.0.0 my-package-B: path: \multi\my-package-B\ version: 0.2.0.0 ~~~ The component parts of the information can be specified using 'selectors' with the command. In the example above the selectors include `compiler`, `compiler actual`, `locals`, `locals my-package-A`, and `locals my-package-A version`. For example, commanding: ~~~text stack query locals my-package-B path ~~~ results in output: ~~~text \multi\my-package-B\ ~~~ stack-2.9.3.1/doc/README.md0000644000000000000000000002725614445022466013226 0ustar0000000000000000
# The Haskell Tool Stack Welcome to the [Haskell](https://www.haskell.org/) programming language and the Haskell Tool Stack (Stack)! Stack is a program for developing Haskell projects. It is aimed at Haskellers both new and experienced. It is cross-platform and aims to support fully users on Linux, macOS and Windows. Stack features: * Installing the [Glasgow Haskell Compiler (GHC)](https://www.haskell.org/ghc/) automatically, in an isolated location. * Installing packages needed for your project. * Building your project. * Testing your project. * Benchmarking your project. ## How to install Stack Stack can be installed on most Unix-like operating systems (including macOS) and Windows. !!! info In addition to the methods described below, Stack can also be installed using the separate [GHCup](https://www.haskell.org/ghcup/) installer for Haskell-related tools. GHCup provides Stack for some combinations of machine architecture and operating system not provided elsewhere. By default, the script to install GHCup (which can be run more than once) also configures Stack so that if Stack needs a version of GHC, GHCup takes over obtaining and installing that version. === "Unix-like" For most Unix-like operating systems, the easiest way to install Stack directly is to command: ~~~text curl -sSL https://get.haskellstack.org/ | sh ~~~ or: ~~~text wget -qO- https://get.haskellstack.org/ | sh ~~~ !!! note The script at [get.haskellstack.org](https://get.haskellstack.org/) will ask for root access using `sudo`. It needs such access in order to use your platform's package manager to install dependencies and to install to `/usr/local/bin`. If you prefer more control, follow the manual installation instructions in the [install and upgrade guide](install_and_upgrade.md). === "Windows" On 64-bit Windows, the easiest way to install Stack directly is to download and install the [Windows installer](https://get.haskellstack.org/stable/windows-x86_64-installer.exe). !!! note Systems with antivirus software may need to add Stack to the list of 'trusted' applications. === "Other/direct downloads" For other operating systems and direct downloads, see the [install and upgrade guide](install_and_upgrade.md). ## How to upgrade Stack If Stack is already installed, you can upgrade it to the latest version by the command: ~~~text stack upgrade ~~~ !!! note If you used [GHCup](https://www.haskell.org/ghcup/) to install Stack, you should also use GHCup, and not Stack, to upgrade Stack. ## Quick Start guide For an immediate experience of using Stack to build an executable with Haskell, first you need to follow the [guide to install Stack](#how-to-install-Stack). ### Step 1: Start your new project To start a new project named `my-project`, issue these four commands in a terminal: ~~~text stack new my-project cd my-project stack build stack exec my-project-exe ~~~ - The `stack new my-project` command will create a new directory, named `my-project`. It contains all the files needed to start a project correctly, using a default template. - The `cd my-project` command will change the current working directory to that directory. - The `stack build` command will build the template project and create an executable named `my-project-exe` (on Windows, `my-project-exe.exe`). First, if necessary, Stack will download a version of GHC in an isolated location. That won't interfere with other GHC installations on your system. - The `stack exec my-project-exe` command will run (execute) the built executable, in Stack's environment. For a complete list of Stack's commands, and flags and options common to those commands, simply command: ~~~text stack ~~~ For help on a particular Stack command, including flags and options specific to that command, for example `stack build`, command: ~~~text stack build --help ~~~ If you want to launch a run-eval-print loop (REPL) environment, then command: ~~~text stack repl ~~~ !!! info `stack ghci` can be used instead of `stack repl`. GHCi is GHC's REPL tool. People organise Haskell code into packages. If you want to use Stack to install an executable provided by a Haskell package, then all you have to do is command: ~~~text stack install ~~~ ### Step 2: Next steps The `stack new my-project` command in step one should have created the following files and directories (among others): ~~~text . ├── app │   └── Main.hs ├── src │   └── Lib.hs ├── test │ └── Spec.hs ├── my-project.cabal ├── package.yaml └── stack.yaml ~~~ The Haskell source code for the executable (application) is in file `Main.hs`. The executable uses a library. Its source code is in file `Lib.hs`. The contents of `my-project.cabal` describes the project's package. That file is generated by the contents of `package.yaml`. !!! info If you want, you can delete the `package.yaml` file and update the `my-project.cabal` file directly. Stack will then use that file. The contents of `stack.yaml` describe Stack's own project-level configuration. You can edit the source files in the `src` directory (used for the library) or the `app` directory (used for the executable (application)). As your project develops, you may need to depend on a library provided by another Haskell package. If you do, then add the name of that new package to the file `package.yaml`, in its `dependencies:` section. !!! info When you use `stack build` again, Stack will use `package.yaml` to create an updated `my-project.cabal` for you. If Stack reports that the Stack configuration has no specified version for the new package, then follow Stack's likely recommended action to add a specific version of that package your project's `stack.yaml` file, in its `extra-deps:` section. That was a really fast introduction on how to start to code in Haskell using Stack. If you want to go further, we highly recommend you read Stack's introductory [user's guide](GUIDE.md). ## Complete guide to Stack A complete [user's guide](GUIDE.md) to Stack is available, covering all of the most common ways to use Stack. Terms used in Stack's documentation are also explained in the [glossary](glossary.md). ## Why Stack? Stack is a build tool for Haskell designed to answer the needs of Haskell users, both new and experienced. It has a strong focus on reproducible build plans, multi-package projects, and a consistent, easy-to-learn set of Stack commands. It also aims to provide the customizability and power that experienced developers need. Stack does not stand alone. It is built on the great work provided by: * The __Glasgow Haskell Compiler__ ([GHC](https://www.haskell.org/ghc/)), the premier Haskell compiler. Stack will manage your GHC installations and automatically select the appropriate version of GHC for your project. * The __Cabal build system__. Cabal is a specification for defining Haskell packages and a [library](https://hackage.haskell.org/package/Cabal) for performing builds. !!! info Cabal is also the name of another build tool, provided by the `cabal-install` package. This guide distinguishes between them by Cabal (the library) and Cabal (the tool). * The __Hackage Haskell Package Repository__, a [repository](https://hackage.haskell.org/) of Haskell packages providing thousands of open source libraries and applications to help you get your work done. * The __Stackage package collection__, sets of packages from Hackage that are [curated](https://www.stackage.org/). That is, they are regularly tested for compatibility. Stack defaults to using Stackage package sets to avoid problems with incompatible dependencies. Stack is provided by a team of volunteers and companies under the auspices of the [Commercial Haskell](http://commercialhaskell.com/) group. The project was spearheaded by [FP Complete](https://www.fpcomplete.com/) to answer the needs of commercial Haskell users. It has since become a thriving open source project meeting the needs of Haskell users of all stripes. If you'd like to get involved with Stack, check out the [newcomer friendly](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3a%22newcomer+friendly%22) label on the GitHub issue tracker. ## Questions, feedback, and discussion * For answers to frequently asked questions about Stack, please see the [FAQ](faq.md). * For general questions, comments, feedback and support, please post to the [Haskell Community](https://discourse.haskell.org/about). * For bugs, issues, or requests, please [open an issue](https://github.com/commercialhaskell/stack/issues/new). * When using Stack Overflow, please use the [haskell-stack](http://stackoverflow.com/questions/tagged/haskell-stack) tag. ## How to contribute to the maintenance or development of Stack The following assumes that you already have installed a version of Stack and the [Git application](https://git-scm.com/). 1. Clone the `stack` repository from GitHub with the command: ~~~text git clone https://github.com/commercialhaskell/stack.git` ~~~ 2. Change the current working directory to the cloned `stack` directory with the command: ~~~text cd stack ~~~ 3. Build the `stack` executable using a preexisting installation of Stack with the command: ~~~text stack build ~~~ 4. Once the `stack` executable has been built, check its version with the command: ~~~text stack exec -- stack --version ~~~ Make sure the version is the latest one. 5. In the GitHub repository's issue tracker, look for issues tagged with [newcomer friendly](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3a%22newcomer+friendly%22) and [awaiting pull request](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3A%22awaiting+pull+request%22) labels. If you need to check your changes quickly command: ~~~text stack repl ~~~ and then, at the REPL's prompt, command: ~~~text :main --stack-root= --stack-yaml= ~~~ This allows you to set a special Stack root (instead of the default Stack root) and to target your commands at a particular `stack.yaml` file instead of the one found in the current directory. ## How to uninstall To uninstall Stack, it should be sufficient to delete: 1. the Stack root directory (see `stack path --stack-root`, before you uninstall); 2. if different, the directory containing Stack's global YAML configuration file (see `stack path --global-config`, before you uninstall); 3. on Windows, the directory containing Stack's tools (see `stack path --programs`, before you uninstall), which is located outside of the Stack root directory; and 4. the `stack` executable file (see `which stack`, on Unix-like operating systems, or `where.exe stack`, on Windows). You may also want to delete ``.stack-work`` directories in any Haskell projects that you have built using Stack. The `stack uninstall` command provides information about how to uninstall Stack. stack-2.9.3.1/doc/run_command.md0000644000000000000000000000321514445022466014560 0ustar0000000000000000
# The `stack run` command ~~~text stack run [-- ARGUMENT(S) (e.g. stack run -- file.txt)] [--[no-]ghc-package-path] [--[no-]stack-exe] [--package PACKAGE] [--rts-options RTSFLAG] [--cwd DIR] ~~~ `stack run` builds a project executable and runs it. If the command has a first argument and it is recognised as an executable target then that is built. Otherwise, the project's first executable is built. If the project has no executables Stack reports no executables found as an error. Everything after `--` on the command line is interpreted as a command line argument to be passed to what is run, other than a first argument recognised as an executable target. By default, the `GHC_PACKAGE_PATH` environment variable is set for the subprocess. Pass the `--no-ghc-package-path` flag to not set the variable. By default, the `STACK_EXE` environment variable is set with the path to Stack. Pass the `--no-stack-exe` flag to not set the variable. The `--cwd` option can be used to set the working directory before the executable is run. The `--rts-options` option (which can be specified multiple times) can be used to pass a list of GHC's [runtime system (RTS) options](https://downloads.haskell.org/~ghc/latest/docs/users_guide/runtime_control.html#) to the executable when it is run. (The `+RTS` and `-RTS` must not be included.) The `--package` option (which can be specified multiple times) can be used to add a package name to build targets. stack-2.9.3.1/doc/runghc_command.md0000644000000000000000000000157614445022466015252 0ustar0000000000000000
# The `stack runghc` and `stack runhaskell` commands ~~~text stack runghc [-- ARGUMENT(S) (e.g. stack runghc -- X.hs)] [--[no-]ghc-package-path] [--[no-]stack-exe] [--package PACKAGE] [--rts-options RTSFLAG] [--cwd DIR] ~~~ `stack runhaskell` has the same effect as `stack runghc`. `stack runghc` has the same effect as, and is provided as a shorthand for, [`stack exec runghc`](exec_command.md), with the exception of the `--package` option. Pass the option `--package ` to add the initial GHC argument `-package-id=`, where `` is the unit ID of the specified package in the installed package database. The option can be specified multiple times. stack-2.9.3.1/doc/script_command.md0000644000000000000000000000516014445022466015261 0ustar0000000000000000
# The `stack script` command ~~~text stack script [--package PACKAGE] FILE [-- ARGUMENT(S) (e.g. stack script X.hs -- argument(s) to program)] [--compile | --optimize] [--ghc-options OPTIONS] [--extra-dep PACKAGE-VERSION] [--no-run] ~~~ The `stack script` command also either runs a specified Haskell source file (using GHC's `runghc`) or, optionally, compiles a specified Haskell source file (using GHC) and, by default, runs it. However, unlike `stack ghc` and `stack runghc`, the command ignores all Stack YAML configuration files. A snapshot must be specified on the command line (with the `--resolver` option). For example: ~~~text stack --resolver lts-19.28 MyScript.hs ~~~ or, equivalently: ~~~text stack script --resolver lts-19.28 MyScript.hs ~~~ Everything after `--` on the command line is interpreted as a command line argument to be passed to what is run. A package can be added to the snapshot on the command line with the `--extra-dep` option (which can be specified multiple times). Each required package can be specified by name on the command line with the `--package` option (which can be specified multiple times). A single `--package` option can also refer to a list of package names, separated by a space or comma character. If the package is not in the snapshot, the most recent version on Hackage will be obtained. If no packages are specified in that way, all the required packages that are in the snapshot will be deduced by reference to the `import` statements in the source file. The `base` package associated with the version of GHC specified by the snapshot is always available. The source file can be compiled by passing either the `--compile` flag (no optimization) or the `--optimize` flag (compilation with optimization). If the file is compiled, passing the `--no-run` flag will mean the compiled code is not run. Additional options can be passed to GHC using the `--ghc-options` option. For example, `MyScript.hs`: ~~~haskell module Main (main) where import Data.List (intercalate) import System.Environment (getArgs) import Acme.Missiles (launchMissiles) main :: IO () main = do advices <- getArgs launchMissiles putStrLn $ intercalate "\n" advices ~~~ can be compiled and run, with arguments, with: ~~~text stack --resolver lts-19.28 script --package acme-missiles --compile MyScript.hs -- "Don't panic!" "Duck and cover!" ~~~ stack-2.9.3.1/doc/scripts.md0000644000000000000000000002223414445022466013747 0ustar0000000000000000
# Stack's script interpreter Stack also offers a very useful feature for running files: a script interpreter. For too long have Haskellers felt shackled to bash or Python because it's just too hard to create reusable source-only Haskell scripts. Stack attempts to solve that. You can use `stack ` to execute a Haskell source file. Usually, the Stack command to be applied is specified using a special Haskell comment (the Stack interpreter options comment) at the start of the source file. That command is most often `stack script` but it can be, for example, `stack runghc`. If there is no Stack interpreter options comment, Stack will warn that one was expected. An example will be easiest to understand. Consider the Haskell source file `turtle-example.hs` with contents: ~~~haskell #!/usr/bin/env stack -- stack script --resolver lts-19.28 --package turtle {-# LANGUAGE OverloadedStrings #-} import Turtle (echo) main = echo "Hello World!" ~~~ === "Unix-like" The first line beginning with the 'shebang' (`#!`) tells Unix to use Stack as a script interpreter, if the file's permissions mark it as executable. A shebang line is limited to a single argument, here `stack`. The file's permissions can be set with command `chmod` and then it can be run: ~~~text chmod +x turtle-example.hs ./turtle-example.hs ~~~ !!! note On macOS: - Avoid `{-# LANGUAGE CPP #-}` in Stack scripts; it breaks the shebang line ([GHC #6132](https://gitlab.haskell.org/ghc/ghc/issues/6132)) - Use a compiled executable, not another script, in the shebang line. Eg `#!/usr/bin/env runhaskell` will work but `#!/usr/local/bin/runhaskell` would not. Alternatively, the script can be run with command: ~~~text stack turtle-example.hs ~~~ === "Windows (with PowerShell)" The first line beginning with the 'shebang' (`#!`) has a meaning on Unix-like operating systems but will be ignored by PowerShell. It can be omitted on Windows. The script can be run with command: ~~~text stack turtle-example.hs ~~~ In both cases, the command yields: ~~~text Hello World! ~~~ the first time after a little delay (as GHC is downloaded, if necessary, and dependencies are built) and subsequent times more promptly (as the runs are able to reuse everything already built). The second line of the source code is the Stack interpreter options comment. In this example, it specifies the `stack script` command with the options of a LTS Haskell 19.28 snapshot (`--resolver lts-19.28`) and ensuring the [`turtle` package](https://hackage.haskell.org/package/turtle) is available (`--package turtle`). The version of the package will be that in the specified snapshot (`lts-19.28` provides `turtle-1.5.25`). ## Arguments and interpreter options and arguments Arguments for the script can be specified on the command line after the file name: `stack ...`. The Stack interpreter options comment must specify what would be a single valid Stack command at the command line if the file name were included as an argument, starting with `stack`. It can include `--` followed by arguments. In particular, the Stack command `stack MyScript.hs ` with Stack interpreter options comment: ~~~haskell -- stack -- ~~~ is equivalent to the following command at the command line: ~~~text stack -- MyScript.hs ~~~ The Stack interpreter options comment must be the first line of the file, unless a shebang line is the first line, when the comment must be the second line. The comment must start in the first column of the line. When many options are needed, a block style comment that splits the command over more than one line may be more convenient and easier to read. For example, the command `stack MyScript.hs arg1 arg2` with `MyScript.hs`: ~~~haskell #!/usr/bin/env stack {- stack script --resolver lts-19.28 -- +RTS -s -RTS -} import Data.List (intercalate) import System.Environment (getArgs) import Turtle (echo, fromString) main = do args <- getArgs echo $ fromString $ intercalate ", " args ~~~ is equivalent to the following command at the command line: ~~~text stack script --resolver lts-19.28 -- MyScript.hs arg1 arg2 +RTS -s -RTS ~~~ where `+RTS -s -RTS` are some of GHC's [runtime system (RTS) options](https://downloads.haskell.org/~ghc/latest/docs/users_guide/runtime_control.html). ## Just-in-time compilation As with using `stack script` at the command line, you can pass the `--compile` flag to make Stack compile the script, and then run the compiled executable. Compilation is done quickly, without optimization. To compile with optimization, pass the `--optimize` flag instead. Compilation is done only if needed; if the executable already exists, and is newer than the script, Stack just runs the executable directly. This feature can be good for speed (your script runs faster) and also for durability (the executable remains runnable even if the script is disturbed, eg due to changes in your installed GHC/snapshots, changes to source files during git bisect, etc.) ## Using multiple packages As with using `stack script` at the command line, you can also specify multiple packages, either with multiple `--package` options, or by providing a comma or space separated list. For example: ~~~haskell #!/usr/bin/env stack {- stack script --resolver lts-19.28 --package turtle --package "stm async" --package http-client,http-conduit -} ~~~ ## Stack configuration for scripts With the `stack script` command, all Stack YAML configuration files are ignored. With the `stack runghc` command, if the current working directory is inside a project then that project's Stack project-level YAML configuration is effective when running the script. Otherwise the script uses the global project configuration specified in `/global-project/stack.yaml`. ## Testing scripts You can use the flag `--script-no-run-compile` on the command line to enable (it is disabled by default) the use of the `--no-run` option with `stack script` (and forcing the `--compile` option). The flag may help test that scripts compile in CI (continuous integration). For example, consider the following simple script, in a file named `Script.hs`, which makes use of the joke package [`acme-missiles`](https://hackage.haskell.org/package/acme-missiles): ~~~haskell {- stack script --resolver lts-19.28 --package acme-missiles -} import Acme.Missiles (launchMissiles) main :: IO () main = launchMissiles ~~~ The command `stack --script-no-run-compile Script.hs` then behaves as if the command `stack script --resolver lts-19.28 --package acme-missiles --no-run --compile -- Script.hs` had been given. `Script.hs` is compiled (without optimisation) and the resulting executable is not run: no missiles are launched in the process! ## Writing independent and reliable scripts The `stack script` command will automatically: * Install GHC and libraries if missing * Require that all packages used be explicitly stated on the command line This ensures that your scripts are _independent_ of any prior deployment specific configuration, and are _reliable_ by using exactly the same version of all packages every time it runs so that the script does not break by accidentally using incompatible package versions. In earlier versions of Stack, the `runghc` command was used for scripts and can still be used in that way. In order to achieve the same effect with the `runghc` command, you can do the following: 1. Use the `--install-ghc` option to install the compiler automatically 2. Explicitly specify all packages required by the script using the `--package` option. Use `-hide-all-packages` GHC option to force explicit specification of all packages. 3. Use the `--resolver` Stack option to ensure a specific GHC version and package set is used. It is possible for configuration files to affect `stack runghc`. For that reason, `stack script` is strongly recommended. For those curious, here is an example with `runghc`: ~~~haskell #!/usr/bin/env stack {- stack runghc --install-ghc --resolver lts-19.17 --package base --package turtle -- -hide-all-packages -} ~~~ The `runghc` command is still very useful, especially when you're working on a project and want to access the package databases and configurations used by that project. See the next section for more information on configuration files. ## Loading scripts in GHCi Sometimes you want to load your script in GHCi to play around with your program. In those cases, you can use `exec ghci` option in the script to achieve it. Here is an example: ~~~haskell #!/usr/bin/env stack {- stack exec ghci --install-ghc --resolver lts-19.28 --package turtle -} ~~~ stack-2.9.3.1/doc/sdist_command.md0000644000000000000000000000317614445022466015110 0ustar0000000000000000
# The `stack sdist` command ~~~text stack sdist [DIR] [--pvp-bounds PVP-BOUNDS] [--ignore-check] [--[no-]test-tarball] [--tar-dir ARG] ~~~ Hackage only accepts packages for uploading in a standard form, a compressed archive ('tarball') in the format produced by Cabal's `sdist` action. `stack sdist` generates a file for your package, in the format accepted by Hackage for uploads. The command will report the location of the generated file. ## The `stack sdist --ignore-check` flag Pass the flag to disable checks of the package for common mistakes. By default, the command will check the package for common mistakes. ## The `stack sdist --pvp-bounds` option The `--pvp-bounds ` option determines whether and, if so, how PVP version bounds should be added to the Cabal file of the package. The available modes for basic use are: `none`, `lower`, `upper`, and `both`. The available modes for use with Cabal file revisions are `lower-revision`, `upper-revision` and `both-revision`. For futher information, see the [YAML configuration](yaml_configuration.md#pvp-bounds) documentation. ## The `stack sdist --tar-dir` option The `--tar-dir ` option determines whether the package archive should be copied to the specified directory. ## The `stack sdist --[no-]test-tarball` flag Default: Disabled Set the flag to cause Stack to test the resulting package archive, by attempting to build it. stack-2.9.3.1/doc/setup_command.md0000644000000000000000000000267514445022466015125 0ustar0000000000000000
# The `stack setup` command ~~~text 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 - by default, the version required by the project and only if it is not already available to Stack. For example: ~~~text stack setup stack will use a sandboxed GHC it installed For more information on paths, see 'stack path' and 'stack exec env' To use this GHC and packages outside of a project, consider using: stack ghc, stack ghci, stack runghc, or stack exec ~~~ Alternatively, the version of GHC to be installed can be specified as an argument. For example `stack setup 9.0.2`. Set the `--reinstall` flag (disabled by default) to attempt to install the version of GHC regardless of whether it is already available to Stack. The `--ghc-bindist ` option can be used to specify the URL of the GHC to be downloaded and installed. This option requires the use of the `--ghc-variant` option specifying a custom GHC variant. 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. stack-2.9.3.1/doc/shell_autocompletion.md0000644000000000000000000000403214353310351016474 0ustar0000000000000000
# Shell auto-completion The following adds support for the tab completion of standard Stack arguments to the following shell programs: Bash, Zsh (the Z shell) and fish. Completion of file names and executables within Stack is still lacking. For further information, see issue [#823](https://github.com/commercialhaskell/stack/issues/832). !!! info Stack's completion library provides [hidden options](https://github.com/pcapriotti/optparse-applicative#bash-zsh-and-fish-completions) for Bash, Zsh, and fish which output commands used for shell auto-completion. For example: ~~~bash $ stack --bash-completion-script stack _stack() { local CMDLINE local IFS=$'\n' CMDLINE=(--bash-completion-index $COMP_CWORD) for arg in ${COMP_WORDS[@]}; do CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg) done COMPREPLY=( $(stack "${CMDLINE[@]}") ) } complete -o filenames -F _stack stack ~~~ === "Bash" Add the output of the following command to your preferred completions file (e.g. `~/.config/bash_completions.d/stack`). ~~~bash stack --bash-completion-script $(which stack) ~~~ You may need to `source` this. === "Zsh" Add the output of the following command to your preferred completions file (e.g. `~/.config/zsh/completions/_stack`). ~~~zsh stack --zsh-completion-script $(which stack) ~~~ You won't need to `source` this, but do update your `fpath`: ~~~zsh fpath=($HOME/.config/zsh/completions $fpath) autoload -U compinit && compinit ~~~ === "fish" Add the output of the following command to your preferred completions file (e.g. `~/.config/fish/completions/stack.fish`). ~~~fish stack --fish-completion-script $(which stack) ~~~ stack-2.9.3.1/doc/SIGNING_KEY.md0000644000000000000000000000710514353310351014055 0ustar0000000000000000
# Signing key Each released Stack executable is signed with either: * the GPG key with ID 0x575159689BEFB442; or * the GPG key of a person that has been authorised by the GPG key with ID 0x575159689BEFB442. The signature is in an `*.asc` file. For example: ~~~text stack-2.7.5-linux-x86_64-bin stack-2.7.5-linux-x86_64-bin.asc ~~~ The signature can be verified with GPG, as follows: ~~~text # Receive the public key from a keyserver gpg --keyserver keyserver.ubuntu.com --recv-keys 0x575159689BEFB442 # Get information about the key gpg --keyid-format long --list-keys 0x575159689BEFB442 pub rsa2048/575159689BEFB442 2015-06-02 [SC] C5705533DA4F78D8664B5DC0575159689BEFB442 uid [ unknown] FPComplete sub rsa2048/85A738994664AB89 2015-06-02 [E] # Attempt to verify the file using the signature file. The public key has not # yet been certified with a trusted signature. gpg --verify stack-2.7.5-linux-x86_64-bin.asc stack-2.7.5-linux-x86_64-bin gpg: Signature made 06/03/2022 15:15:21 GMT Standard Time gpg: using RSA key C5705533DA4F78D8664B5DC0575159689BEFB442 gpg: Good signature from "FPComplete " [unknown] gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: C570 5533 DA4F 78D8 664B 5DC0 5751 5968 9BEF B442 ~~~ The GPG key with ID 0x575159689BEFB442, and keys it has signed, have been uploaded to the [Ubuntu Keyserver](https://keyserver.ubuntu.com/pks/lookup?search=0x575159689BEFB442&fingerprint=on&op=index). This is the public key block for GPG key ID 0x575159689BEFB442: ~~~text -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1 mQENBFVs+cMBCAC5IsLWTikd1V70Ur1FPJMn14Sc/C2fbXc0zRcPuWX+JaXgrIJQ 74A3UGBpa07wJDZiQLLz4AasDQj++9gXdiM9MlK/xWt8BQpgQqSMgkktFVajSWX2 rSXPjqLtsl5dLsc8ziBkd/AARXoeITmXX+n6oRTy6QfdMv2Tacnq7r9M9J6bAz6/ 7UsKkyZVwsbUPea4SuD/s7jkXAuly15APaYDmF5mMlpoRWp442lJFpA0h52mREX1 s5FDbuKRQW7OpZdLcmOgoknJBDSpKHuHEoUhdG7Y3WDUGYFZcTtta1qSVHrm3nYa 7q5yOzPW4/VpftkBs1KzIxx0nQ5INT5W5+oTABEBAAG0H0ZQQ29tcGxldGUgPGRl dkBmcGNvbXBsZXRlLmNvbT6JATcEEwEKACEFAlVs+cMCGwMFCwkIBwMFFQoJCAsF FgMCAQACHgECF4AACgkQV1FZaJvvtEIP8gf/S/k4C3lp/BFb0K9DHHSt6EaGQPwy g+O8d+JvL7ghkvMjlQ+UxDw+LfRKANTpl8a4vHtEQLHEy1tPJfrnMA8DNci8HLVx rK3lIqMfv5t85VST9rz3X8huSw7qwFyxsmIqFtJC/BBQfsOXC+Q5Z2nbResXHMeA 5ZvDopZnqKPdmMOngabPGZd89hOKn6r8k7+yvZ/mXmrGOB8q5ZGbOXUbCshst7lc yZWmoK3VJdErQjGHCdF4MC9KFBQsYYUy9b1q0OUv9QLtq/TeKxfpvYk9zMWAoafk M8QBE/qqOpqkBRoKbQHCDQgx7AXJMKnOA0jPx1At57hWl7PuEH4rK38UtLkBDQRV bPnDAQgAx1+4ENyaMk8XznQQ4l+nl8qw4UedZhnR5Xxr6z2kcMO/0VdwmIDCpxaM spurOF+yExfY/Chbex7fThWTwVgfsItUc/QLLv9jkvpveMUDuPyh/4QrAQBYoW09 jMJcOTFQU+f4CtKaN/1PNoTSU2YkVpbhvtV3Jn2LPFjUSPb7z2NZ9NKe10M0/yN+ l0CuPlqu6GZR5L3pA5i8PZ0Nh47j0Ux5KIjrjCGne4p+J8qqeRhUf04yHAYfDLgE aLAG4v4pYbb1jNPUm1Kbk0lo2c3dxx0IU201uAQ6LNLdF/WW/ZF7w3iHn7kbbzXO jhbq2rvZEn3K9xDr7homVnnj21/LSQARAQABiQEfBBgBCgAJBQJVbPnDAhsMAAoJ EFdRWWib77RC3ukH/R9jQ4q6LpXynQPJJ9QKwstglKfoKNpGeAYVTEn0e7NB0HV5 BC+Da5SzBowboxC2YCD1wTAjBjLLQfAYNyR+tHpJBaBmruafj87nBCDhSWwWDXwx OUDpNOwKUkrwZDRlM7n4byoMRl7Vh/7CXxaTqkyao1c5v3mHh/DremiTvOJ4OXgJ 77NHaPXezHkCFZC8/sX6aY0DJxF+LIE84CoLI1LYBatH+NKxoICKA+yeF3RIVw0/ F3mtEFEtmJ6ljSks5tECxfJFvQlkpILBbGvHfuljKMeaj+iN+bsHmV4em/ELB1ku N9Obs/bFDBMmQklIdLP7dOunDjY4FwwcFcXdNyg= =YUsC -----END PGP PUBLIC KEY BLOCK----- ~~~ stack-2.9.3.1/doc/Stack_and_VS_Code.md0000644000000000000000000001567114445022466015520 0ustar0000000000000000
# Stack and Visual Studio Code [Visual Studio Code](https://code.visualstudio.com/) (VS Code) is a popular source code editor, and ['Haskell'](https://marketplace.visualstudio.com/items?itemName=haskell.haskell) is an extension for VS Code that is popular with Haskell coders. The 'Haskell' extension can be used with Stack but there are some things to be aware of, set out below. ## Haskell Language Server The VS Code extension makes use of the Haskell Language Server (HLS). To work, HLS has to be built with the same version of GHC that it will support. That is, a version of HLS is required for each version of GHC in use. It is possible that the most recent versions of GHC are not supported by HLS. By default, the VS Code extension uses tools that are in the PATH. However, the extension's settings (under 'Haskell: Manage HLS') allow a user to specify that the extension should use a separate application, [GHCup](https://www.haskell.org/ghcup/), to download and install the versions of HLS that it needs. GHCup can download and install things other than HLS, including GHC, MSYS2 (on Windows), Cabal (a build tool), and Stack itself. GHCup can also update itself. On Windows, GHCup has the capability of using the Stack-supplied MSYS2 rather than installing a duplicate copy. Cabal (the build tool), like Stack, depends on the Cabal (the library). Cabal (the tool), unlike Stack, does not have the capability to automatically install necessary versions of GHC, and (as well as supporting the extension) GHCup fills a important gap for users of the Cabal tool. If the VS Code extension is set not to use GHCup, its user needs to ensure that each version of HLS that the extension needs is on the PATH. For the most part, the versions of HLS provided by GHCup are built with the same versions of GHC that Stack downloads from its default `setup-info` dictionary (see [YAML configuration: setup-info](yaml_configuration.md)). Stack's default is to mirror the 'official' binary distributions published by GHC. However, in some cases, it is possible that a GHCup-supplied and GHCup-selected HLS has been built with a different binary distribution of GHC than the one which Stack has installed. One example of that occurred with the release of GHC 9.0.2. For some Linux users (Debian 9 and Fedora 27), the version of GHC 9.0.2 linked on GHC’s download [web page](https://www.haskell.org/ghc/download_ghc_9_0_2.html) was broken. The GHC developers made alternative ‘9.0.2a’ versions available. For a while, Stack referred to the versions published by GHC on its download web page while the GHCup-supplied versions of HLS were built using alternative versions. This incompatibility led to problems. It was resolved by Stack's default also being changed to refer to the '9.0.2a' versions. (Where Stack has already installed GHC 9.0.2, it is necessary to delete GHC 9.0.2 from the `stack path --programs` directory. This will cause Stack to reinstall the alternative version, when it first needs GHC 9.0.2. Stack should distinguish what it builds with the alternative from what it has built, and cached, with the original GHC 9.0.2.) ### GHCup and Stack >= 2.9.1 From Stack 2.9.1, GHCup can configure Stack so that if Stack needs a version of GHC, GHCup takes over obtaining and installing that version. By default, the script to install GHCup (which can be run more than once) configures Stack in that way. For further information about how GHCup configures Stack, see the GHC installation customisation [documentation](yaml_configuration.md#ghc-installation-customisation). ### Workaround #1 If GHCup does not configure Stack in the way described above, one workaround is to allow GHCup to install versions of GHC on the PATH and to cause Stack to use those versions of GHC, by making use of Stack's `install-ghc` option (which needs to be disabled) and Stack's `system-ghc` option (which needs to be enabled). For further information about these options, see the `install-ghc` [documentation](yaml_configuration.md#install-ghc) and the `system-ghc` [documentation](yaml_configuration.md#system-ghc). For this workaround to work, each time that a resolver is used that references a different version of GHC, then GHCup must be used to install it (if GHCup has not already installed that version). For example, to use `resolver: lts-19.16` (GHC 9.0.2), the command `ghcup install ghc 9.0.2` must have been used to install GHC 9.0.2. That may be a minor inconvenience for some people, as one the primary benefits of Stack over other Haskell build tools has been that Stack automatically ensures that the necessary version of GHC is available. ### Workaround #2 If GHCup does not configure Stack, another partial workaround is to install GHCup so that it is 'empty' except for the current version of HLS, allow the VS Code extension to use GHCup to manage HLS requirements only, and to ignore any messages (if any) from the extension on start-up that installation of GHC, Cabal (the tool) and/or Stack are also necessary (they are not, if only Stack is being used). For this workaround to work, however, there can be no differences between the version of GHC that the GHCup-supplied HLS was built with and the version that Stack has installed. A slight inconvenience here is also the possibility of false messages from the start-up that need to be ignored. In principle, those messages can be disabled by [setting the following](https://github.com/haskell/vscode-haskell#setting-a-specific-toolchain) for the VS Code extension: ~~~yaml "haskell.toolchain": { "ghc": null, "cabal": null, "stack": null } ~~~ To install a version of GHCup that is 'empty' is a little more complicated than a default installation of GHCup. On Unix-like operating systems, the following environment variable must be set before GHCup's installation `sh` script is run: `BOOTSTRAP_HASKELL_MINIMAL`. On Windows, the second argument to the PowerShell script must be set to `$false`, namely: Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $true,$false ### Cradle HLS may need a 'cradle' - an [`hie.yaml` file](https://hackage.haskell.org/package/hie-bios#stack) - in the project's root directory in order to work well. The [`gen-hie` tool](https://hackage.haskell.org/package/implicit-hie) can help generate such a cradle. ### Tips It has been suggested that a project must have been successfully built before the VS code extension (and HLS) is first activated on the project, for HLS to work reliably. stack-2.9.3.1/doc/stack_yaml_vs_cabal_package_file.md0000644000000000000000000001657714445022466020730 0ustar0000000000000000
# stack.yaml versus package.yaml versus a Cabal file What is the difference between a `stack.yaml` file, a `package.yaml` file and a Cabal file (named `.cabal`)? This page aims to make that clear. In short: * `stack.yaml` contains project-level configuration for Stack, and may contain project-specific options and non-project-specific options. * `package.yaml` contains a description of a package in the [Hpack](https://github.com/sol/hpack) format. Hpack, including Stack's built-in version, uses the file to create a Cabal file. * a Cabal file also contains a description of a package, but in the format used by Cabal. ## package.yaml versus a Cabal file Why two different formats to describe packages? Hpack is considered to have some advantages over the underlying Cabal format, which are explained its project repository. They include that the Hpack format supports YAML syntax and the automatic generation of the lists of `exposed-modules` used in the Cabal format. The remainder of this page will focus on the difference between a `stack.yaml` file and a package description file. ## Package versus project Stack is a build tool and it uses Cabal, a build system. Cabal defines the concept of a _package_. A package has: * A name and version * optionally, one library * optionally, one or more executables * A Cabal file (or, as mentioned above, an [Hpack](https://github.com/sol/hpack) `package.yaml` file that generates a Cabal file) * And a bunch more There is a one-to-one correspondence between a package and a Cabal file. Stack defines a new concept called a _project_. A project has: * A _resolver_, which tells it about a snapshot (more on this later) * Extra dependencies on top of the snapshot * Optionally, one or more local Cabal packages * Flag and GHC options configurations * And a bunch more Stack configuration Often you will have a project that defines only one local Cabal package that you are working on. If you need to specify an extra dependency, a source of confusion can be why you need to specify it both in the `stack.yaml` file _and_ in the Cabal file. To explain, let's take a quick detour to talk about snapshots and how Stack resolves dependencies. ## Resolvers and snapshots Stack follows a rule that says, for any projects, there is precisely one version of each package available. Obviously, for many packages there are _many_ versions available in the world. But when resolving a `stack.yaml` file, Stack requires that you have chosen a specific version for each package available. The most common means by which this set of packages is defined is via a snapshot provided by Stackage. For example, if you go to the page , you will see a list of 2,910 packages at specific version numbers. When you then specify `resolver: lts-19.17`, you're telling Stack to use those package versions in resolving dependencies down to specific versions of packages. Sometimes a snapshot doesn't have all of the packages that you want. Or you want a different version of a package. Or you want to work on a local modification of a package. In all of those cases, you can add more configuration data to your `stack.yaml` file to override the values it received from your `resolver` setting. At the end of the day, each of your projects will end up with some way of resolving a package name into a specific version of that package. ## Why specify dependencies twice? The package `acme-missiles` is not included in any Stackage snapshots. When you add something like this to your `stack.yaml` file: ~~~yaml extra-deps: - acme-missiles-0.3 ~~~ what you're saying to Stack is: "if at any point you find that you need to build the `acme-missiles` package, please use version `0.3`". You are _not_ saying "please build `acme-missiles` now." You are also not saying "my package depends on `acme-missiles`." You are simply making it available should the need arise. When you add to your `package.yaml` file: ~~~yaml dependencies: - acme-missiles ~~~ or, alternatively, you add directly to your Cabal file: ~~~yaml build-depends: acme-missiles ~~~ you're saying "this package requires that `acme-missiles` be available." Since `acme-missiles` doesn't appear in your snapshot, without also modifying your `stack.yaml` to mention it via `extra-deps`, Stack will complain about the dependency being unavailable. You may challenge: but why go through all of that annoyance? Stack knows what package I want, why not just go grab it? The answer is that, if Stack just grabbed `acme-missiles` for you without it being specified in the `stack.yaml` somehow, you'd lose reproducibility. How would Stack know which version to use? It may elect to use the newest version, but if a new version is available in the future, will it automatically switch to that? Stack's core philosophy is that build plans are always reproducible. The purpose of the `stack.yaml` file is to define an immutable set of packages. No matter when in time you use it, and no matter how many new release happen in the interim, the build plan generated should be the same. (There is, however, at least one hole in this theory today, which is Hackage revisions. When you specify `extra-deps: [acme-missiles-0.3]`, it doesn't specify which revision of the Cabal file to use, and Stack will just choose the latest. Stack has the ability to specify exact revisions of Cabal files, but this isn't enforced as a requirement, because it is so different from the way most people work with packages.) And now, how about the other side: why doesn't Stack automatically add `acme-missiles` to `build-depends` in your Cabal file if you add it as an extra-dep? There are a surprising number reasons for this: * The Cabal specification doesn't support anything like that * There can be multiple packages in a project, and how do we know which package actually needs the dependency? * There can be multiple components (libraries, executable, etc) in a package, and how do we know which of those actually needs the dependency? * The dependency may only be conditionally needed, based on flags, operating system, or architecture. As an extreme example, we wouldn't want a Linux-only package to be built by force on Windows. While for simple use cases it seems like automatically adding dependencies from the Cabal file to the `stack.yaml` file or vice-versa would be a good thing, it breaks down immediately for any semi-difficult case. Therefore, Stack requires you to add it to both places. And a final note, in case it wasn't clear. The example above used `acme-missiles`, which is not in Stackage snapshots. If, however, you want to depend on a package already present in the snapshot you've selected, there's no need to add it explicitly to your `stack.yaml` file: it's already there implicitly via the `resolver` setting. This is what you do the majority of the time, such as when you add `vector` or `mtl` as a `build-depends` value. ## Should I check-in automatically generated Cabal files? Yes, you should. This recommendation was changed in [issue #5210](https://github.com/commercialhaskell/stack/issues/5210). Please see the discussion there. stack-2.9.3.1/doc/templates_command.md0000644000000000000000000000470014445022466015752 0ustar0000000000000000
# The `stack templates` command ~~~text stack templates ~~~ `stack templates` provides information about how to find templates available for `stack new`. Stack provides multiple templates to start a new project from. You can specify one of these templates following your project name in the `stack new` command: ~~~text stack new my-rio-project rio Downloading template "rio" to create project "my-rio-project" in my-rio-project/ ... Looking for .cabal or package.yaml files to use to init the project. Using cabal packages: - my-rio-project/ Selecting the best among 18 snapshots... * Matches ... Selected resolver: ... Initialising configuration using resolver: ... Total number of user packages considered: 1 Writing configuration to file: my-rio-project/stack.yaml All done. \templates\rio.hsfiles: 10.10 KiB downloaded... ~~~ The default templates repository is https://github.com/commercialhaskell/stack-templates. You can download templates from a different GitHub user by prefixing the username and a slash. Command: ~~~text stack new my-yesod-project yesodweb/simple ~~~ Then template file `simple.hsfiles` would be downloaded from GitHub repository `yesodweb/stack-templates`. You can even download templates from a service other that GitHub, such as [GitLab](https://gitlab.com) or [Bitbucket](https://bitbucket.com). For example, command: ~~~text stack new my-project gitlab:user29/foo ~~~ Template file `foo.hsfiles` would be downloaded from GitLab, user account `user29`, repository `stack-templates`. If you need more flexibility, you can specify the full URL of the template. Command: ~~~text stack new my-project https://my-site.com/content/template9.hsfiles ~~~ (The `.hsfiles` extension is optional; it will be added if it's not specified.) Alternatively you can use a local template by specifying the path. Command: ~~~text stack new project /template.hsfiles ~~~ As a starting point for creating your own templates, you can use the ["simple" template](https://github.com/commercialhaskell/stack-templates/blob/master/simple.hsfiles). The [stack-templates repository](https://github.com/commercialhaskell/stack-templates#readme) provides an introduction into creating templates. stack-2.9.3.1/doc/travis_ci.md0000644000000000000000000001456214353310351014237 0ustar0000000000000000
# Travis CI This page documents how to use Stack on [Travis CI](https://travis-ci.org/). We assume you have basic familiarity with Travis. We provide two fully baked example files ready to be used on your projects: * [The simple Travis configuration](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/travis-simple.yml) is intended for applications that do not require multiple GHC support or cross-platform support. It builds and tests your project with just the settings present in your `stack.yaml` file. * [The complex Travis configuration](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/travis-complex.yml) is intended for projects that need to support multiple GHC versions and multiple OSes, such as open source libraries to be released to Hackage. It tests against cabal-install, as well as Stack on Linux and macOS. The configuration is significantly more involved to allow for all of this branching behavior. !!! note It is likely going to be necessary to modify this configuration to match the needs of your project, such as tweaking the build matrix to alter which GHC versions you test against, or to specify GHC-version-specific `stack.yaml` files if necessary. Don't be surprised if it doesn't work the first time around. See the multiple GHC section below for more information. Each of these configurations is ready to be used immediately, just copy-paste the content into the `.travis.yml` file in the root or your repo, enable Travis on the repo, and you're good to go. You may also be interested in using AppVeyor, which supports Windows builds, for more cross-platform testing. There's a [short blog post available on how to do this](http://www.snoyman.com/blog/2016/08/appveyor-haskell-windows-ci), or just copy in [the appveyor.yml file](https://raw.githubusercontent.com/commercialhaskell/stack/stable/doc/appveyor.yml) The rest of this document explains the details of common Travis configurations for those of you who want to tweak the above configuration files or write your own. *Note:* both Travis and Stack infrastructures are actively developed. We try to document best practices at the moment. ## Container infrastructure For Stack on Travis to be practical, we must use caching. Otherwise build times will take an incredibly long time, about 30 minutes versus 3-5. Caching is currently available only for [container-based Travis infrastructure](http://docs.travis-ci.com/user/workers/container-based-infrastructure/). Shortly we have to add ~~~yaml sudo: false # Caching so the next build will be fast too. cache: directories: - $HOME/.stack ~~~ To the `.travis.yml`. This however restricts how we can install GHC and Stack on the Travis machines. ## Installing Stack Currently there is only one reasonable way to install Stack: fetch precompiled binary from the GitHub. ~~~yaml before_install: # Download and unpack the stack executable - mkdir -p ~/.local/bin - export PATH=$HOME/.local/bin:$PATH - travis_retry curl -L https://get.haskellstack.org/stable/linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack' ~~~ ## Installing GHC There are two ways to install GHC: - Let Stack download GHC - Install GHC using [apt plugin](http://docs.travis-ci.com/user/apt/) See the above scripts for an example of the first option (letting Stack download GHC). Here, we will explain the second option. With single GHC the situation is simple: ~~~yaml before_install: # Install stack as above # ... # Configure stack to use the system GHC installation - stack config set system-ghc --global true - export PATH=/opt/ghc/7.10.2/bin:$PATH addons: apt: sources: - hvr-ghc packages: - ghc-7.10.2 ~~~ ### Multiple GHC - parametrised builds Travis apt plugin doesn't yet support installing apt packages dynamically (https://github.com/travis-ci/travis-ci/issues/4291). That for we need to write a bit repetitive `.travis.yml`. Also for different GHC versions, you probably want to use different `stack.yaml` files. ~~~yaml # N.B. No top-level env: declaration! matrix: include: - env: GHCVER=7.8.4 STACK_YAML=stack.yaml addons: apt: sources: - hvr-ghc packages: - ghc-7.8.4 - env: GHCVER=7.10.1 STACK_YAML=stack-7.10.yaml addons: apt: sources: - hvr-ghc packages: - ghc-7.10.1 - env: GHCVER=head STACK_YAML=stack-head.yaml addons: apt: sources: - hvr-ghc packages: - ghc-head allow_failures: - env: GHCVER=head STACK_YAML=stack-head.yaml before_install: # ghc - export PATH=/opt/ghc/$GHCVER/bin:$PATH ~~~ Especially to use ghc `HEAD` you need to pass `--skip-ghc-check` option to Stack. ## Running tests After the environment setup, actual test running is simple: ~~~yaml script: - stack --no-terminal --skip-ghc-check test ~~~ In case you're wondering: we need `--no-terminal` because stack does some fancy sticky display on smart terminals to give nicer status and progress messages, and the terminal detection is broken on Travis. ## Other details Some Stack commands will run for long time (when cache is cold) without producing any output. To avoid timeouts, use the built in [travis_wait](https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received). ~~~yaml install: - travis_wait stack --no-terminal --skip-ghc-check setup - travis_wait stack --no-terminal --skip-ghc-check test --only-snapshot ~~~ ## Examples - [futurice/fum2github](https://github.com/futurice/fum2github/blob/master/.travis.yml) - [haskell-distributed/cloud-haskell](https://github.com/haskell-distributed/cloud-haskell/blob/master/.travis.yml) - [simonmichael/hledger](https://github.com/simonmichael/hledger/blob/master/.travis.yml) - [fpco/wai-middleware-crowd](https://github.com/fpco/wai-middleware-crowd/blob/master/.travis.yml) - [commercialhaskell/all-cabal-hashes-tool](https://github.com/commercialhaskell/all-cabal-hashes-tool/blob/master/.travis.yml) stack-2.9.3.1/doc/uninstall_command.md0000644000000000000000000000053414445022466015766 0ustar0000000000000000
# The `stack uninstall` command ~~~text stack uninstall ~~~ `stack uninstall` provides information about how to uninstall Stack. It does not itself uninstall Stack. stack-2.9.3.1/doc/unpack_command.md0000644000000000000000000000063014445022466015233 0ustar0000000000000000
# The `stack unpack` command ~~~text stack unpack PACKAGE [--to ARG] ~~~ `stack unpack` downloads a tarball for the specified package and unpacks it. Pass the option `--to ` to specify the destination directory. stack-2.9.3.1/doc/update_command.md0000644000000000000000000000064014353310533015226 0ustar0000000000000000
# The `stack update` command ~~~text stack update ~~~ Generally, Stack automatically updates the package index when necessary. `stack update` will download the most recent set of packages from your package indices (e.g. Hackage). stack-2.9.3.1/doc/upgrade_command.md0000644000000000000000000000157314445022466015410 0ustar0000000000000000
# The `stack upgrade` command Either: ~~~text stack upgrade [--binary-only] [--binary-platform ARG] [--force-download] [--binary-version ARG] [--github-org ARG] [--github-repo ARG] ~~~ or: ~~~text stack upgrade [--source-only] [--git] [--git-repo ARG] [--git-branch ARG] ~~~ `stack upgrade` will get a new version of Stack, either from an existing binary distribution (pass the `--binary-only` flag, the default) or from compiling source code (pass the `--source-only` flag). The `--binary-only` and `--source-only` flags are alternatives. `--git` is a convenient way to get the most recent version from the `master` branch, for those testing and living on the bleeding edge. stack-2.9.3.1/doc/upload_command.md0000644000000000000000000000626214445022466015245 0ustar0000000000000000
# The `stack upload` command ~~~text stack upload [DIR] [--pvp-bounds PVP-BOUNDS] [--ignore-check] [--[no-]test-tarball] [--tar-dir ARG] [--candidate] ~~~ Hackage accepts packages for uploading in a standard form, a compressed archive ('tarball') in the format produced by Cabal's `sdist` action. `stack upload` generates a file for your package, in the format accepted by Hackage for uploads, and uploads the package to Hackage. For example, if the current working directory is the root directory of your project: ~~~text stack upload . ~~~ ## The `HACKAGE_USERNAME` and `HACKAGE_PASSWORD` environment variables [:octicons-tag-24: 2.3.1](https://github.com/commercialhaskell/stack/releases/tag/v2.3.1) `stack upload` will request a Hackage username and password to authenticate. This can be avoided by setting the `HACKAGE_USERNAME` and `HACKAGE_PASSWORD` environment variables. For example: === "Unix-like" ~~~text export $HACKAGE_USERNAME="" export $HACKAGE_PASSWORD="" stack upload . ~~~ === "Windows (with PowerShell)" ~~~text $Env:HACKAGE_USERNAME='' $Env:HACKAGE_PASSWORD='' stack upload . ~~~ ## The `HACKAGE_KEY` environment variable [:octicons-tag-24: 2.7.5](https://github.com/commercialhaskell/stack/releases/tag/v2.7.5) Hackage allows its members to register an API authentification token and to authenticate using the token. A Hackage API authentification token can be used with `stack upload` instead of username and password, by setting the `HACKAGE_KEY` environment variable. For example: === "Unix-like" ~~~text HACKAGE_KEY= stack upload . ~~~ === "Windows (with PowerShell)" ~~~text $Env:HACKAGE_KEY= stack upload . ~~~ ## The `stack upload --candidate` flag Pass the flag to upload a [package candidate](http://hackage.haskell.org/upload#candidates). ## The `stack upload --ignore-check` flag Pass the flag to disable checks of the package for common mistakes. By default, the command will check the package for common mistakes. ## The `stack upload --pvp-bounds` option The `--pvp-bounds ` option determines whether and, if so, how PVP version bounds should be added to the Cabal file of the package. The available modes for basic use are: `none`, `lower`, `upper`, and `both`. The available modes for use with Cabal file revisions are `lower-revision`, `upper-revision` and `both-revision`. For futher information, see the [YAML configuration](yaml_configuration.md#pvp-bounds) documentation. ## The `stack upload --tar-dir` option The `--tar-dir ` option determines whether the package archive should be copied to the specified directory. ## The `stack upload --[no-]test-tarball` flag Default: Disabled Set the flag to cause Stack to test the resulting package archive, by attempting to build it. stack-2.9.3.1/doc/yaml_configuration.md0000644000000000000000000015565614445022466016170 0ustar0000000000000000
# Configuration and customisation Stack is configured by the content of YAML files. Some Stack operations can also be customised by the use of scripts. ## YAML configuration Stack's YAML configuration options break down into [project-specific](#project-specific-configuration) options and [non-project-specific](#non-project-specific-configuration) options. They are configured at the project-level or globally. The **project-level** configuration file (`stack.yaml`) contains project-specific options and may contain non-project-specific options. Stack obtains project-level configuration from one of the following (in order of preference): 1. A file specified by the `--stack-yaml` command line option. 2. A file specified by the `STACK_YAML` environment variable. 3. A file named `stack.yaml` in the current directory or an ancestor directory. 4. A file name `stack.yaml` in the `global-project` directory in the Stack root. The **global** configuration file (`config.yaml`) contains only non-project-specific options. Stack obtains global configuration from a file named `config.yaml`. The location of this file depends on the operating system and whether Stack is configured to use the XDG Base Directory Specification. === "Unix-like" `config.yaml` is located in `/etc/stack` (for system-wide options); and/or in the Stack root (for user-specific options). === "Windows" `config.yaml` is located in the Stack root. === "XDG Base Directory Specification" On Unix-like operating systems and Windows, Stack can be configured to follow the XDG Base Directory Specification if the environment variable `STACK_XDG` is set to any non-empty value. However, Stack will ignore that configuration if the Stack root location has been set on the command line or the `STACK_ROOT` environment variable exists. If Stack is following the XDG Base Directory Specification, the location of `config.yaml` (for user-specific options) is `/stack`. If the `XDG_CONFIG_HOME` environment variable does not exist, the default is `~/.config/stack` on Unix-like operating systems and `%APPDIR%\stack` on Windows. This page is intended to document fully all YAML configuration options. If you identify any inaccuracies or incompleteness, please update the page, and if you're not sure how, open an issue labeled "question". If you wish to understand the difference between a `stack.yaml` files and a Cabal file (named `.cabal`), see the [stack.yaml vs a Cabal file](stack_yaml_vs_cabal_package_file.md) documentation. ## Project-specific configuration Project-specific configuration options are valid only in a project-level configuration file (`stack.yaml`). > Note: We define **project** to mean a directory that contains a `stack.yaml` > file, which specifies how to build a set of packages. We define **package** to > be a package with a Cabal file or an Hpack `package.yaml` file. In your project-specific options, you specify both **which local packages** to build and **which dependencies to use** when building these packages. Unlike the user's local packages, these dependencies aren't built by default. They only get built when needed. Shadowing semantics, described [here](https://docs.haskellstack.org/en/v1.5.1/architecture/#shadowing), are applied to your configuration. So, if you add a package to your `packages` list, it will be used even if you're using a snapshot that specifies a particular version. Similarly, `extra-deps` will shadow the version specified in the resolver. ### resolver or snapshot Command line equivalent (takes precedence): `--resolver` option `resolver` and `snapshot` are synonyms. Only one of these keys is permitted, not both. The `resolver` or `snapshot` key specifies which snapshot is to be used for this project. A snapshot defines a GHC version, a number of packages available for installation, and various settings like build flags. It is called a resolver since a snapshot states how dependencies are resolved. There are currently four resolver types: * LTS Haskell snapshots, e.g. `resolver: lts-19.17` * Stackage Nightly snapshots, e.g. `resolver: nightly-2002-08-04` * No snapshot, just use packages shipped with the compiler. For GHC this looks like `resolver: ghc-9.2.4` * Custom snapshot, via a URL or relative file path. For further information, see the [Pantry](pantry.md) documentation. Each of these resolvers will also determine what constraints are placed on the compiler version. See the [compiler-check](#compiler-check) option for some additional control over compiler version. The `resolver` key corresponds to a Pantry snapshot location. For further information, see the [Pantry](pantry.md) documentation. ### packages Default: ~~~yaml packages: - . ~~~ _NOTE_ From Stack 1.11, Stack moved over to Pantry for managing extra-deps, and removed some legacy syntax for specifying dependencies in `packages`. Some conversion notes are provided below. The `packages` key specifies a list of packages that are part of your local project. These are specified via paths to local directories. The paths are considered relative to the directory containing the `stack.yaml` file. For example, if your `stack.yaml` is located at `/foo/bar/stack.yaml`, and you have: ~~~yaml packages: - hello - there/world ~~~ Your configuration means "I have packages in `/foo/bar/hello` and `/foo/bar/there/world`. If these packages should be treated as dependencies instead, specify them in `extra-deps` key, described below. The `packages` key is _optional_. The default item, '`.`', means that your project has exactly one package, and it is located in the current directory. Each package directory specified must have a valid Cabal file or Hpack `package.yaml` file present. The subdirectories of the directory are not searched for Cabal files. Subdirectories will have to be specified as independent items in the list of packages. Project packages are different from snapshot dependencies (via `resolver`) and extra dependencies (via `extra-deps`) in multiple ways, e.g.: * Project packages will be built by default with a `stack build` without specific targets. Dependencies will only be built if they are depended upon. * Test suites and benchmarks may be run for project packages. They are never run for extra dependencies. __Legacy syntax__ Prior to Stack 1.11, it was possible to specify dependencies in your `packages` configuration value as well. This support was removed to simplify the file format. Instead, these values should be moved to `extra-deps`. As a concrete example, you would convert: ~~~yaml packages: - . - location: git: https://github.com/bitemyapp/esqueleto.git commit: 08c9b4cdf977d5bcd1baba046a007940c1940758 extra-dep: true - location: git: https://github.com/yesodweb/wai.git commit: 6bf765e000c6fd14e09ebdea6c4c5b1510ff5376 subdirs: - wai-extra extra-dep: true extra-deps: - streaming-commons-0.2.0.0 - time-1.9.1 - yesod-colonnade-1.3.0.1 - yesod-elements-1.1 ~~~ into ~~~yaml packages: - . extra-deps: - streaming-commons-0.2.0.0 - time-1.9.1 - yesod-colonnade-1.3.0.1 - yesod-elements-1.1 - git: https://github.com/bitemyapp/esqueleto.git commit: 08c9b4cdf977d5bcd1baba046a007940c1940758 - git: https://github.com/yesodweb/wai.git commit: 6bf765e000c6fd14e09ebdea6c4c5b1510ff5376 subdirs: - wai-extra ~~~ And, in fact, the `packages` value could be left off entirely since it's using the default value. ### extra-deps Default: `[]` This key allows you to specify extra dependencies on top of what is defined in your snapshot (specified by the `resolver` key mentioned above). These dependencies may either come from a local file path or a Pantry package location. For the local file path case, the same relative path rules as apply to `packages` apply. Pantry package locations allow you to include dependencies from three different kinds of sources: * Hackage * Archives (tarballs or zip files, either local or over HTTP or HTTPS) * Git or Mercurial repositories Here's an example using all of the above: ~~~yaml extra-deps: - vendor/hashable - streaming-commons-0.2.0.0 - time-1.9.1 - yesod-colonnade-1.3.0.1 - yesod-elements-1.1 - git: https://github.com/bitemyapp/esqueleto.git commit: 08c9b4cdf977d5bcd1baba046a007940c1940758 - url: https://github.com/yesodweb/wai/archive/6bf765e000c6fd14e09ebdea6c4c5b1510ff5376.tar.gz subdirs: - wai-extra - github: snoyberg/conduit commit: 2e3e41de93821bcfe8ec6210aeca21be3f2087bf subdirs: - network-conduit-tls ~~~ For further information on the format for specifying dependencies, see the [Pantry](pantry.md) documentation. ### flags Default: `{}` Command line equivalent (takes precedence): `stack build --flag` option Flags can be set for each package separately. For example: ~~~yaml flags: package-name: flag-name: true ~~~ If a specified flag is different than the one specified for a snapshot package, then the snapshot package will automatically be promoted to be an extra-dep. ### drop-packages [:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1) Default: `[]` Packages which, when present in the snapshot specified in `resolver`, should not be included in our package. This can be used for a few different purposes, e.g.: * Ensure that packages you don't want used in your project cannot be used in a `package.yaml` file (e.g., for license reasons) * Prevent overriding of a global package like `Cabal`. For more information, see Stackage issue [#4425](https://github.com/commercialhaskell/stackage/issues/4425) * When using a custom GHC build, avoid incompatible packages (see this [comment](https://github.com/commercialhaskell/stack/pull/4655#issuecomment-477954429)). ~~~yaml drop-packages: - Cabal - buggy-package - package-with-unacceptable-license ~~~ ### user-message If present, specifies a message to be displayed every time the configuration is loaded by Stack. It can serve as a reminder for the user to review the configuration and make any changes if needed. The user can delete this message if the generated configuration is acceptable. For example, a user-message is inserted by `stack init` when it omits packages or adds external dependencies, namely: ~~~yaml user-message: ! 'Warning: Some packages were found to be incompatible with the resolver and have been left commented out in the packages section. Warning: Specified resolver could not satisfy all dependencies. Some external packages have been added as dependencies. You can omit this message by removing it from stack.yaml ' ~~~ ### custom-preprocessor-extensions Default: `[]` Command line equivalent: `--customer-preprocessor-extensions` option In order for Stack to be aware of any custom preprocessors you are using, add their extensions here ~~~yaml custom-preprocessor-extensions: - erb ~~~ TODO: Add a simple example of how to use custom preprocessors. ## Non-project-specific configuration Non-project configuration options are valid in a project-level configuration file (`stack.yaml`) or in global configuration files (`config.yaml`). The options below are listed in alphabetic order. ### allow-different-user [:octicons-tag-24: 1.0.1.0](https://github.com/commercialhaskell/stack/releases/tag/v1.0.1.0) Restrictions: POSIX systems only. Default: `false` Command line equivalent (takes precedence): `--[no-]allow-different-user` flag Allow users other than the owner of the Stack root to use the Stack installation. ~~~yaml allow-different-user: true ~~~ The intention of this option is to prevent file permission problems, for example as the result of a Stack command executed under `sudo`. The option is automatically enabled when Stack is re-spawned in a Docker process. ### allow-newer [:octicons-tag-24: 0.1.8.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.8.0) Default: `false` Whether to ignore version bounds in Cabal files. This also ignores lower bounds. The name `allow-newer` is chosen to match the commonly-used Cabal option. ~~~yaml allow-newer: true ~~~ ### allow-newer-deps (experimental) [:octicons-tag-24: 2.9.3](https://github.com/commercialhaskell/stack/releases/tag/v2.9.3) Default: `none` Determines a subset of packages to which `allow-newer` should apply. This option has no effect (but warns) if `allow-newer` is `false`. ~~~yaml allow-newer-deps: - foo - bar ~~~ ### apply-ghc-options [:octicons-tag-24: 0.1.6.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.6.0) Default: `locals` Which packages do ghc-options on the command line get applied to? Before Stack 0.1.6, the default value was `targets` ~~~yaml apply-ghc-options: locals # all local packages # apply-ghc-options: targets # all local packages that are targets # apply-ghc-options: everything # applied even to snapshot and extra-deps ~~~ Note that `everything` is a slightly dangerous value, as it can break invariants about your snapshot database. ### arch Default: The machine architecture on which Stack is running. Command line equivalent (takes precedence): `--arch` option Stack identifies different GHC executables by platform (operating system and machine architecture), (optional) GHC variant and (optional) GHC build. See [`setup-info`](#setup-info). `arch` sets the machine architecture. Values are those recognized by Cabal, including `x86_64`, `i386` and `aarch64`. ### build [:octicons-tag-24: 1.1.0](https://github.com/commercialhaskell/stack/releases/tag/v1.1.0) Default: ~~~yaml build: library-profiling: false executable-profiling: false copy-bins: false prefetch: false keep-going: false keep-tmp-files: false # NOTE: global usage of haddock can cause build failures when documentation is # incorrectly formatted. This could also affect scripts which use Stack. haddock: false haddock-arguments: haddock-args: [] # Additional arguments passed to haddock, --haddock-arguments # haddock-args: # - "--css=/home/user/my-css" open-haddocks: false # --open haddock-deps: false # if unspecified, defaults to true if haddock is set haddock-internal: false # These are inadvisable to use in your global configuration, as they make the # Stack build command line behave quite differently. test: false test-arguments: rerun-tests: true # Rerun successful tests additional-args: [] # --test-arguments # additional-args: # - "--fail-fast" coverage: false no-run-tests: false bench: false benchmark-opts: benchmark-arguments: "" # benchmark-arguments: "--csv bench.csv" no-run-benchmarks: false force-dirty: false reconfigure: false cabal-verbose: false split-objs: false # Since 1.8. Starting with 2.0, the default is true interleaved-output: true # Since 1.10 ddump-dir: "" ~~~ Command line equivalents (take precedence): Yes, see below. Allows setting build options which are usually specified on the command line. The meanings of these settings correspond directly with the command line flags of the same name. For further information, see the [`stack build` command](build_command.md) documentation and the [users guide](GUIDE.md#the-build-command). ### color Command line equivalent (takes precedence): `--color` option This option specifies when to use color in output. The option is used as `color: `, where `` is 'always', 'never', or 'auto'. On Windows versions before Windows 10, for terminals that do not support color codes, the default is 'never'; color may work on terminals that support color codes. (The British English spelling (colour) is also accepted. In yaml configuration files, the American spelling is the alternative that has priority.) ### compiler [:octicons-tag-24: 0.1.8.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.8.0) Command line equivalent (takes precedence): `--compiler` option Overrides the compiler version in the resolver. Note that the `compiler-check` flag also applies to the version numbers. This uses the same syntax as compiler resolvers like `ghc-9.2.4`. This can be used to override the compiler for a Stackage snapshot, like this: ~~~yaml resolver: lts-14.20 compiler: ghc-8.6.4 compiler-check: match-exact ~~~ #### Building GHC from source (experimental) [:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1) Stack supports building the GHC compiler from source. The version to build and to use is defined by a a Git commit ID and an Hadrian "flavour" (Hadrian is the build system of GHC) with the following syntax: ~~~yaml compiler: ghc-git-COMMIT-FLAVOUR ~~~ In the following example the commit ID is "5be7ad..." and the flavour is "quick": ~~~yaml compiler: ghc-git-5be7ad7861c8d39f60b7101fd8d8e816ff50353a-quick ~~~ By default the code is retrieved from the main GHC repository. If you want to select another repository, set the "compiler-repository" option: ~~~yaml compiler-repository: git://my/ghc/repository # default # compiler-repository: https://gitlab.haskell.org/ghc/ghc.git ~~~ Note that Stack doesn't check the compiler version when it uses a compiler built from source. Moreover it is assumed that the built compiler is recent enough as Stack doesn't enable any known workaround to make older compilers work. Building the compiler can take a very long time (more than one hour). Hint: for faster build times, use Hadrian flavours that disable documentation generation. #### Global packages The GHC compiler you build from sources may depend on unreleased versions of some global packages (e.g. Cabal). It may be an issue if a package you try to build with this compiler depends on such global packages because Stack may not be able to find versions of those packages (on Hackage, etc.) that are compatible with the compiler. The easiest way to deal with this issue is to drop the offending packages as follows. Instead of using the packages specified in the resolver, the global packages bundled with GHC will be used. ~~~yaml drop-packages: - Cabal - ... ~~~ Another way to deal with this issue is to add the relevant packages as `extra-deps` built from source. To avoid mismatching versions, you can use exactly the same commit id you used to build GHC as follows: ~~~ extra-deps: - git: https://gitlab.haskell.org/ghc/ghc.git commit: 5be7ad7861c8d39f60b7101fd8d8e816ff50353a subdirs: - libraries/Cabal/Cabal - libraries/... ~~~ #### Bootstrapping compiler Building GHC from source requires a working GHC (known as the bootstrap compiler). As we use a Stack based version of Hadrian (`hadrian/build-stack` in GHC sources), the bootstrap compiler is configured into `hadrian/stack.yaml` and fully managed by Stack. ### compiler-check [:octicons-tag-24: 0.1.4.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.4.0) Default: `match-minor` Specifies how the compiler version in the resolver is matched against concrete versions. Valid values: * `match-minor`: make sure that the first three components match, but allow patch-level differences. For example< 7.8.4.1 and 7.8.4.2 would both match 7.8.4. This is useful to allow for custom patch levels of a compiler. * `match-exact`: the entire version number must match precisely * `newer-minor`: the third component can be increased, e.g. if your resolver is `ghc-7.10.1`, then 7.10.2 will also be allowed. This was the default up through Stack 0.1.3 ### concurrent-tests [:octicons-tag-24: 0.1.2.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.2.0) Default: `true` This option specifies whether test suites should be executed concurrently with each other. The default is `true` since this is usually fine and it often means that tests can complete earlier. However, if some test suites require exclusive access to some resource, or require a great deal of CPU or memory resources, then it makes sense to set this to `false`. ~~~yaml concurrent-tests: false ~~~ ### configure-options [:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1) Options which are passed to the configure step of the Cabal build process. These can either be set by package name, or using the `$everything`, `$targets`, and `$locals` special keys. These special keys have the same meaning as in `ghc-options`. ~~~yaml configure-options: $everything: - --with-gcc - /some/path my-package: - --another-flag ~~~ ### connection-count Default: `8` Integer indicating how many simultaneous downloads are allowed to happen. ### default-template Default: `new-template` in the [stack-templates](https://github.com/commercialhaskell/stack-templates/) repository. This option specifies which template to use with `stack new`, when none is specified. Other templates are listed in the [stack-templates](https://github.com/commercialhaskell/stack-templates/) repository. See the output of `stack templates`. ### docker Command line equivalents: `--docker-*` flags and options (see `stack --docker-help` for details). For further information, see the [Docker integration](docker_integration.md#configuration) documentation. ### dump-logs [:octicons-tag-24: 1.3.0](https://github.com/commercialhaskell/stack/releases/tag/v1.3.0) Default: `warning` Command line equivalent (takes precedence): `--[no-]dump-logs` flag In the case of *non-interleaved* output and *more than one* target package, Stack sends the build output from GHC for each target package to a log file, unless an error occurs. For further information, see the [`stack build --[no-]interleaved-output` flag](build_command.md#the-stack-build---no-interleaved-output-flag) documentation. The value of the `dump-logs` key controls what, if any, log file content is sent ('dumped') to the console at the end of the build. Possible values are: ~~~yaml dump-logs: none # don't dump the content of any log files dump-logs: warning # dump the content of log files that are warnings dump-logs: all # dump all of the content of log files ~~~ At the command line, `--no-dump-logs` is equivalent to `dump-logs: none` and `--dump-logs` is equivalent to `dump-logs: all`. ### extra-include-dirs Default: `[]` Command line equivalent: `--extra-include-dirs` option (repeat for each directory) A list of extra paths to be searched for header files. Paths should be absolute ~~~yaml extra-include-dirs: - /opt/foo/include ~~~ Since these are system-dependent absolute paths, it is recommended that you specify these in your `config.yaml` file. If you control the build environment in your project's ``stack.yaml``, perhaps through docker or other means, then it may well make sense to include these there as well. ### extra-lib-dirs Default: `[]` Command line equivalent: `--extra-lib-dirs` option (repeat for each directory) A list of extra paths to be searched for libraries. Paths should be absolute ~~~yaml extra-lib-dirs: - /opt/foo/lib ~~~ Since these are system-dependent absolute paths, it is recommended that you specify these in your `config.yaml` file. If you control the build environment in your project's ``stack.yaml``, perhaps through Docker or other means, then it may well make sense to include these there as well. ### extra-path [:octicons-tag-24: 0.1.4.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.4.0) This option specifies additional directories to prepend to the PATH. These will be used when resolving the location of executables, and will also be visible in the PATH of processes run by Stack. For example, to prepend `/path-to-some-dep/bin` to your PATH: ~~~yaml extra-path: - /path-to-some-dep/bin ~~~ Other paths added by Stack - things like the project's binary directory and the compiler's binary directory - will take precedence over those specified here (the automatic paths get prepended). ### ghc-build [:octicons-tag-24: 1.3.0](https://github.com/commercialhaskell/stack/releases/tag/v1.3.0) Default: `standard` Command line equivalent (takes precedence): `--ghc-build` option Stack identifies different GHC executables by platform (operating system and machine architecture), (optional) GHC variant and (optional) GHC build. See [`setup-info`](#setup-info). `ghc-build` specifies a specialized architecture for the GHC executable. Normally this is determined automatically, but it can be overridden. Possible arguments include `standard`, `gmp4`, `nopie`, `tinfo6`, `tinfo6-nopie`, `ncurses6`, `int-native` and `integersimple`. ### ghc-options [:octicons-tag-24: 0.1.4.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.4.0) Allows specifying per-package and global GHC options: ~~~yaml ghc-options: # All packages "$locals": -Wall "$targets": -Werror "$everything": -O2 some-package: -DSOME_CPP_FLAG ~~~ Since Stack 1.6.0, setting a GHC options for a specific package will automatically promote it to a local package (much like setting a custom package flag). However, setting options via `$everything` on all flags will not do so (see [GitHub discussion](https://github.com/commercialhaskell/stack/issues/849#issuecomment-320892095) for reasoning). This can lead to unpredictable behavior by affecting your snapshot packages. The behavior of the `$locals`, `$targets`, and `$everything` special keys mirrors the behavior for the [`apply-ghc-options` setting](#apply-ghc-options), which affects command line parameters. !!! note Prior to Stack 1.6.0, the `$locals`, `$targets`, and `$everything` keys were not supported. Instead, you could use `"*"` for the behavior represented now by `$everything`. It is highly recommended to switch to the new, more expressive, keys. ### ghc-variant [:octicons-tag-24: 0.1.5.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.5.0) Default: `standard` Command line equivalent (takes precedence): `--ghc-variant` option Stack identifies different GHC executables by platform (operating system and machine architecture), (optional) GHC variant and (optional) GHC build. See [`setup-info`](#setup-info). `ghc-variant` specifies a variant of the GHC executable. Known values are: * `standard`: Use the standard GHC binary distribution * `int-native`: From GHC 9.4.1, use a GHC bindist that uses the Haskell-native big-integer [backend](https://downloads.haskell.org/~ghc/9.0.2/docs/html/users_guide/9.0.1-notes.html#highlights). For further information, see this [article](https://iohk.io/en/blog/posts/2020/07/28/improving-haskells-big-numbers-support/). * `integersimple`: Use a GHC bindist that uses [integer-simple instead of GMP](https://ghc.haskell.org/trac/ghc/wiki/ReplacingGMPNotes) * any other value: Use a custom GHC bindist. You should specify [setup-info](#setup-info) or [setup-info-locations](#setup-info-locations) so `stack setup` knows where to download it, or pass the `stack setup --ghc-bindist` argument on the command-line This option is incompatible with `system-ghc: true`. ### hackage-base-url [:octicons-tag-24: 1.9.1](https://github.com/commercialhaskell/stack/releases/tag/v1.9.1) Default: `https://hackage.haskell.org/` Sets the address of the Hackage server to upload the package to. ~~~yaml hackage-base-url: https://hackage.example.com/ ~~~ ### hide-source-paths Default: `true` ([:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1)) Whether to use the `-fhide-source-paths` option by default for GHC >= 8.2: ~~~yaml hide-source-paths: false ~~~ Build output when enabled: ~~~text ... [1 of 2] Compiling Lib [2 of 2] Compiling Paths_test_pr ... ~~~ Build output when disabled: ~~~text ... [1 of 2] Compiling Lib ( src/Lib.hs, .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/Lib.o ) ... ~~~ ### hide-th-loading Default: `true` Strip out the "Loading ..." lines from GHC build output, produced when using Template Haskell. ### ignore-revision-mismatch (Removed 1.11) This flag was introduced in Stack 1.6, and removed on the move to Pantry. You will receive a warning if this configuration value is set. ### install-ghc 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 Whether or not to automatically install GHC when necessary. ### jobs Default: the number of processors reported by your CPU. Command line equivalent (takes precedence): `-j`, `--jobs` option Specifies how many build tasks should be run in parallel. One usage for this might be to avoid running out of memory by setting it to 1, like this: ~~~yaml jobs: 1 ~~~ ### local-bin-path Default (on Unix-like operating systems): `~/.local/bin` Default (on Windows): `%APPDATA%\local\bin` Command line equivalent (takes precedence): `--local-bin-path` option Target directory for `stack install` and `stack build --copy-bins`. ### local-programs-path [:octicons-tag-24: 1.3.0](https://github.com/commercialhaskell/stack/releases/tag/v1.3.0) The behaviour of this option differs between Unix-like operating systems and Windows. === "Unix-like" Default: `programs` directory in the Stack root. This overrides the location of the Stack 'programs' directory, where tools like GHC get installed. === "Windows" Default: `%LOCALAPPDATA%\Programs\stack`, if the `%LOCALAPPDATA%` environment variable exists. This overrides the location of the Stack 'programs' directory, where tools like GHC and MSYS2 get installed. !!! warning If there is a space character in the `%LOCALAPPDATA%` path (which may be the case if the relevant user account name and its corresponding user profile path have a space) this may cause problems with building packages that make use of the GNU project's `autoconf` package and `configure` shell script files. That may be the case particularly if there is no corresponding short name ('8 dot 3' name) for the directory in the path with the space (which may be the case if '8 dot 3' names have been stripped or their creation not enabled by default). If there are problems building, it will be necessary to override the default location of Stack's 'programs' directory to specify an alternative path that does not contain space characters. Examples of packages on Hackage that make use of `configure` are `network` and `process`. ### modify-code-page [:octicons-tag-24: 0.1.6.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.6.0) Restrictions: Windows systems only. Default: `true` Command line equivalent (takes precedence): `--[no-]modify-code-page` flag Whether to modify the code page for UTF-8 output. ~~~yaml modify-code-page: false ~~~ ### nix [:octicons-tag-24: 0.1.10.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.10.0) Default: ~~~yaml nix: add-gc-roots: false enable: false nix-shell-options: [] packages: [] path: [] pure: true shell-file: ~~~ Command line equivalents: `--nix-*` flags and options (see `stack --nix-help` for details). For further information, see the [Nix integration](nix_integration.md#configuration) documentation. ### package-index [:octicons-tag-24: 2.9.3](https://github.com/commercialhaskell/stack/releases/tag/v2.9.3) Default: ~~~yaml package-index: download-prefix: https://hackage.haskell.org/ hackage-security: keyids: - 0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d - 1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42 - 2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3 - 51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921 - fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0 key-threshold: 3 ignore-expiry: true ~~~ Takes precedence over the `package-indices` key, which is deprecated. Specify the package index. The index must use the [Hackage Security](https://hackage.haskell.org/package/hackage-security) format. This setting is most useful for providing a mirror of the official Hackage server for * bypassing a firewall; or * faster downloads. If the setting specifies an index that does not mirror Hackage, it is likely that will result in significant breakage, including most snapshots failing to work. In the case of Hackage, the keys of its root key holders are contained in the `haskell-infra/hackage-root-keys` [repository](https://github.com/haskell-infra/hackage-root-keys). The Hackage package index is signed. A signature is valid when three key holders have signed. The Hackage timestamp is also signed. A signature is valid when one key holder has signed. If the `hackage-security` key is absent, the Hackage Security configuration will default to that for the official Hackage server. `key-threshold` specifies the minimum number of keyholders that must have signed the package index for it to be considered valid. `ignore-expiry` specifies whether or not the expiration of timestamps should be ignored. ### package-indices [:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1) Deprecated in favour of [`package-index`](#package-index), which takes precedence if present. Default: ~~~yaml package-indices: - download-prefix: https://hackage.haskell.org/ hackage-security: keyids: - 0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d - 1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42 - 2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3 - 51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921 - fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0 key-threshold: 3 ignore-expiry: true ~~~ !!! note Before Stack 2.1.3, the default for `ignore-expiry` was `false`. For more information, see [issue #4928](https://github.com/commercialhaskell/stack/issues/4928). !!! note Before Stack 2.1.1, Stack had a different approach to `package-indices`. For more information, see [issue #4137](https://github.com/commercialhaskell/stack/issues/4137). Specify the package index. For further information, see the `package-index` [documentation](#package-index). ### pvp-bounds [:octicons-tag-24: 0.1.5.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.5.0) Default: `none` Command line equivalent (takes precedence): `stack sdist --pvp-bounds` option or `stack upload --pvp-bounds` option !!! warning As of Stack 1.6.0, this feature does not reliably work, due to issues with the Cabal library's printer. Stack will generate a warning when a lossy conversion occurs, in which case you may need to disable this setting. For further information, see issue [#3550](https://github.com/commercialhaskell/stack/issues/3550). When using the `sdist` and `upload` commands, this setting determines whether the Cabal file's dependencies should be modified to reflect PVP lower and upper bounds. #### Basic use Values are `none` (unchanged), `upper` (add upper bounds), `lower` (add lower bounds), and both (and upper and lower bounds). The algorithm it follows is: * If an upper or lower bound already exists on a dependency, it's left alone * When adding a lower bound, we look at the current version specified by `stack.yaml`, and set it as the lower bound (e.g., `foo >= 1.2.3`) * When adding an upper bound, we require less than the next major version (e.g., `foo < 1.3`) ~~~yaml pvp-bounds: none ~~~ For further information, see the announcement [blog post](https://www.fpcomplete.com/blog/2015/09/stack-pvp). #### Use with Cabal file revisions [:octicons-tag-24: 1.5.0](https://github.com/commercialhaskell/stack/releases/tag/v1.5.0) Each of the values listed above supports adding `-revision` to the end of the value, e.g. `pvp-bounds: both-revision`. This means that, when uploading to Hackage, Stack will first upload your tarball with an unmodified Cabal file, and then upload a Cabal file revision with the PVP bounds added. This can be useful - especially combined with the [Stackage no-revisions feature](http://www.snoyman.com/blog/2017/04/stackages-no-revisions-field) - as a method to ensure PVP compliance without having to proactively fix bounds issues for Stackage maintenance. ### recommend-stack-upgrade [:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1) When Stack notices that a new version of Stack is available, should it notify the user? ~~~yaml recommend-stack-upgrade: true ~~~ ### rebuild-ghc-options [:octicons-tag-24: 0.1.6.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.6.0) Default: `false` Should we rebuild a package when its GHC options change? Before Stack 0.1.6, this was a non-configurable `true`. However, in most cases, the flag is used to affect optimization levels and warning behavior, for which GHC itself doesn't actually recompile the modules anyway. Therefore, the new behavior is to not recompile on an options change, but this behavior can be changed back with the following: ~~~yaml rebuild-ghc-options: true ~~~ ### require-stack-version Default: `"-any"` Require a version of Stack within the specified range ([cabal-style](https://www.haskell.org/cabal/users-guide/developing-packages.html#build-information)) to be used for this project. Example: `require-stack-version: "== 0.1.*"` ### save-hackage-creds [:octicons-tag-24: 1.5.0](https://github.com/commercialhaskell/stack/releases/tag/v1.5.0) Default: `true` Controls whether, when using `stack upload`, the user's Hackage username and password are stored in a local file. ~~~yaml save-hackage-creds: true ~~~ ### setup-info [:octicons-tag-24: 0.1.5.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.5.0) The `setup-info` dictionary specifies download locations for tools to be installed during set-up, such as GHC or, on Windows, 7z and MSYS2. The dictionary maps `('Tool', 'Platform', 'Version')` to the location where it can be obtained. For example, mapping `(GHC, 64-bit Windows, 9.2.3)` to the URL hosting the archive file for GHC's installation. Possible usages of this configuration option are: 1. Using Stack offline or behind a firewall. 2. Extending the tools known to Stack, such as cutting-edge versions of GHC or builds for custom Linux distributions (for use with the [ghc-variant](#ghc-variant) option). By default, Stack obtains the dictionary from [stack-setup-2.yaml](https://github.com/commercialhaskell/stackage-content/raw/master/stack/stack-setup-2.yaml). The `setup-info` dictionary is constructed in the following order: 1. `setup-info` in the YAML configuration - inline configuration 2. `--setup-info-yaml` command line arguments - URLs or paths. Multiple locations may be specified. 3. `setup-info-locations` in the YAML configuration - URLs or paths. See further below. The format of this key is the same as in the default [stack-setup-2.yaml](https://github.com/commercialhaskell/stackage-content/raw/master/stack/stack-setup-2.yaml). For example, GHC 9.2.3 of custom variant `myvariant` (see further below) on 64-bit Windows: ~~~yaml setup-info: ghc: windows64-custom-myvariant: 9.2.3: url: "https://example.com/ghc-9.2.3-x86_64-unknown-mingw32-myvariant.tar.xz" ~~~ 'Platforms' are pairs of an operating system and a machine architecture (for example, 32-bit i386 or 64-bit x86-64) (represented by the `Cabal.Distribution.Systems.Platform` type). Stack currently (version 2.9.1) supports the following pairs in the format of the `setup-info` key: |Operating system|I386 arch|X86_64 arch|Other machine architectures | |----------------|---------|-----------|------------------------------------------------------------| |Linux |linux32 |linux64 |AArch64: linux-aarch64, Arm: linux-armv7, Sparc: linux-sparc| |OSX |macosx |macosx | | |Windows |windows32|windows64 | | |FreeBSD |freebsd32|freebsd64 |AArch64: freebsd-aarch64 | |OpenBSD |openbsd32|openbsd64 | | For GHC, the distinguishing 'Version' in the key format includes a 'tag' for any (optional) GHC variant (see [ghc-variant](#ghc-variant)) and a further 'tag' for any (optional) specialised GHC build (see [ghc-build](#ghc-build)). The optional variant 'tag' is either `-integersimple` or `-custom-`. For example, for GHC 9.0.2 of specialised GHC build `tinfo6` on x86_64 Linux: ~~~yaml setup-info: ghc: linux64-tinfo6: 9.0.2: url: "http://downloads.haskell.org/~ghc/9.0.2/ghc-9.0.2a-x86_64-fedora27-linux.tar.xz" content-length: 237286244 sha1: affc2aaa3e6a1c446698a884f56a0a13e57f00b4 sha256: b2670e9f278e10355b0475c2cc3b8842490f1bca3c70c306f104aa60caff37b0 ~~~ On Windows, the required 7z executable and DLL tools are represented in the format of the `setup-info` key simply by `sevenzexe-info` and `sevenzdll-info`. This configuration **adds** the specified setup information metadata to the default. Specifying this configuration **does not** prevent the default [stack-setup-2.yaml](https://github.com/commercialhaskell/stackage-content/raw/master/stack/stack-setup-2.yaml) from being consulted as a fallback. If, however, you need to **replace** the default `setup-info` dictionary, use the following: ~~~yaml setup-info-locations: [] ~~~ ### setup-info-locations [:octicons-tag-24: 2.3.1](https://github.com/commercialhaskell/stack/releases/tag/v2.3.1) Command line equivalent (takes precedence): `--setup-info-yaml` option By way of introduction, see the [`setup-info`](#setup-info) option. This option specifies the location(s) of `setup-info` dictionaries. The first location which provides a dictionary that specifies the location of a tool - `('Tool', 'Platform', 'Version')` - takes precedence. For example, you can extend the default tools, with a fallback to the default `setup-info` location, as follows: ~~~yaml setup-info-locations: - C:/stack-offline/my-stack-setup.yaml - relative/inside/my/project/setup-info.yaml - \\smbShare\stack\my-stack-setup.yaml - http://stack-mirror.com/stack-setup.yaml # Fallback to the default location - https://github.com/commercialhaskell/stackage-content/raw/master/stack/stack-setup-2.yaml ~~~ Stack only refers to the default `setup-info` location if no locations are specified in the `setup-info-locations` configuration or on the command line using the `--setup-info-yaml` option. For example, both of the following will cause `stack setup` not to consult the default `setup-info` location: ~~~yaml setup-info-locations: - C:/stack-offline/my-stack-setup.yaml ~~~ and ~~~yaml setup-info-locations: [] ~~~ Relative paths are resolved relative to the `stack.yaml` file (either the one in the local project or the global `stack.yaml`). Relative paths may also be used for the installation paths to tools (such as GHC or 7z). This allows vendoring the tools inside a monorepo (a single repository storing many projects). For example: Directory structure: ~~~text - src/ - installs/ - my-stack-setup.yaml - 7z.exe - 7z.dll - ghc-9.2.3.tar.xz - stack.yaml ~~~ In the project's `stack.yaml`: ~~~yaml setup-info-locations: - installs/my-stack-setup.yaml ~~~ In `installs/my-stack-setup.yaml`: ~~~yaml sevenzexe-info: url: "installs/7z.exe" sevenzdll-info: url: "installs/7z.dll" ghc: windows64: 9.2.3: url: "installs/ghc-9.2.3.tar.xz" ~~~ ### skip-ghc-check Default: `false` Command line equivalent (takes precedence): `--[no-]skip-ghc-check` flag Should we skip the check to confirm that your system GHC version (on the PATH) matches what your project expects? ### skip-msys [:octicons-tag-24: 0.1.2.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.2.0) Restrictions: Windows systems only Default: `false` Command line equivalent (takes precedence): `--[no-]skip-msys` flag Skips checking for and installing MSYS2 when stack is Setting up the environment. This usually doesn't make sense in project-level configurations, just in `config.yaml`. ~~~yaml skip-msys: true ~~~ ### snapshot-location-base [:octicons-tag-24: 2.5.1](https://github.com/commercialhaskell/stack/releases/tag/v2.5.1) Default: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/ (as set in the `pantry` library) Command line equivalent (takes precedence): `--snapshot-location-base` option Sets the base location of the LTS Haskell or Stackage Nightly snapshots. For example: ~~~yaml snapshot-location-base: https://example.com/snapshots/location/ ~~~ has the following effect: * `lts-X.Y` expands to `https://example.com/snapshots/location/lts/X/Y.yaml` * `nightly-YYYY-MM-DD` expands to `https://example.com/snapshots/location/nightly/YYYY/M/D.yaml` This key is convenient in setups that restrict access to GitHub, for instance closed corporate setups. In this setting, it is common for the development environment to have general access to the internet, but not for testing/building environments. To avoid the firewall, one can run a local snapshots mirror and then use a custom `snapshot-location-base` in the closed environments only. ### stack-colors Command line equivalent (takes precedence): `--stack-colors` option Stack uses styles to format some of its output. The default styles do not work well with every terminal theme. This option specifies Stack's output styles, allowing new styles to replace the defaults. The option is used as `stack-colors: `, where `` is a colon-delimited sequence of key=value, 'key' is a style name and 'value' is a semicolon-delimited list of 'ANSI' SGR (Select Graphic Rendition) control codes (in decimal). Use the command `stack ls stack-colors --basic` to see the current sequence. The 'ANSI' standards refer to (1) standard ECMA-48 'Control Functions for Coded Character Sets' (5th edition, 1991); (2) extensions in ITU-T Recommendation (previously CCITT Recommendation) T.416 (03/93) 'Information Technology – Open Document Architecture (ODA) and Interchange Format: Character Content Architectures' (also published as ISO/IEC International Standard 8613-6); and (3) further extensions used by 'XTerm', a terminal emulator for the X Window System. The 'ANSI' SGR codes are described in a [Wikipedia article](http://en.wikipedia.org/wiki/ANSI_escape_code) and those codes supported on current versions of Windows in [Microsoft's documentation](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences). For example, users of the popular [Solarized Dark](https://ethanschoonover.com/solarized/) terminal theme might wish to set the styles as follows: ~~~yaml stack-colors: error=31:good=32:shell=35:dir=34:recommendation=32:target=95:module=35:package-component=95:secondary=92:highlight=32 ~~~ In respect of styles used in verbose output, some of that output occurs before the configuration file is processed. (The British English spelling (colour) is also accepted. In YAML configuration files, the American spelling is the alternative that has priority.) ### stack-developer-mode [:octicons-tag-24: 2.3.3](https://github.com/commercialhaskell/stack/releases/tag/v2.3.3) Default (official distributed binaries): `false` Default (built from source): `true` Turns on a mode where some messages are printed at WARN level instead of DEBUG level, especially useful for developers of Stack itself. ~~~yaml stack-developer-mode: false ~~~ ### system-ghc Default: `false`, unless the [Docker](docker_integration.md) or [Nix](nix_integration.md) integration is enabled. Command line equivalent (takes precedence): `--[no-]system-ghc` flag Enables or disables using the GHC available on the PATH. (Make sure PATH is explicit, i.e., don't use ~.) Useful to enable if you want to save the time, bandwidth or storage space needed to setup an isolated GHC. In a Nix-enabled configuration, Stack is incompatible with `system-ghc: false`. ~~~yaml # Turn on system GHC system-ghc: true ~~~ ### templates Command line equivalent (takes precedence): `stack new --param :` (or `-p`) option Templates used with `stack new` have a number of parameters that affect the generated code. These can be set for all new projects you create. The result of them can be observed in the generated LICENSE and Cabal files. The value for all of these parameters must be strings. The parameters are: `author-email`, `author-name`, `category`, `copyright`, `year` and `github-username`. * _author-email_ - sets the `maintainer` property in Cabal * _author-name_ - sets the `author` property in Cabal and the name used in LICENSE * _category_ - sets the `category` property in Cabal. This is used in Hackage. For examples of categories see [Packages by category](https://hackage.haskell.org/packages/). It makes sense for `category` to be set on a per project basis because it is uncommon for all projects a user creates to belong to the same category. The category can be set per project by passing `-p "category:value"` to the `stack new` command. * _copyright_ - sets the `copyright` property in Cabal. It is typically the name of the holder of the copyright on the package and the year(s) from which copyright is claimed. For example: `Copyright (c) 2006-2007 Joe Bloggs` * _year_ - if `copyright` is not specified, `year` and `author-name` are used to generate the copyright property in Cabal. If `year` is not specified, it defaults to the current year. * _github-username_ - used to generate `homepage` and `source-repository` in Cabal. For instance `github-username: myusername` and `stack new my-project new-template` would result: ~~~yaml homepage: http://github.com/myusername/my-project#readme source-repository head type: git location: https://github.com/myusername/my-project ~~~ These properties can be set in `config.yaml` as follows: ~~~yaml templates: params: author-name: Your Name author-email: youremail@example.com category: Your Projects Category copyright: 'Copyright (c) 2022 Your Name' github-username: yourusername ~~~ Additionally, `stack new` can automatically initialize source control repositories in the directories it creates. Source control tools can be specified with the `scm-init` option. At the moment, only `git` is supported. ~~~yaml templates: scm-init: git ~~~ ### urls Default: ~~~yaml urls: latest-snapshot: https://www.stackage.org/download/snapshots.json ~~~ Customize the URLs where Stack looks for snapshot build plans. ### with-gcc Command line equivalent (takes precedence): `--with-gcc` option Specify a path to GCC explicitly, rather than relying on the normal path resolution. ~~~yaml with-gcc: /usr/local/bin/gcc-5 ~~~ ### with-hpack Command line equivalent (takes precedence): `--with-hpack` option Use an [Hpack](https://github.com/sol/hpack) executable, rather than Stack's in-built version of the Hpack functionality. ~~~yaml with-hpack: /usr/local/bin/hpack ~~~ ### work-dir [:octicons-tag-24: 0.1.10.0](https://github.com/commercialhaskell/stack/releases/tag/v0.1.10.0) Default: `.stack-work` Command line equivalent (takes precedence): `--work-dir` option Environment variable alternative (lowest precedence): `STACK_WORK` `work-dir` (or the contents of `STACK_WORK`) specifies the relative path of Stack's 'work' directory. ## Customisation scripts ### GHC installation customisation [:octicons-tag-24: 2.9.1](https://github.com/commercialhaskell/stack/releases/tag/v2.9.1) On Unix-like operating systems and Windows, Stack's installation procedure can be fully customised by placing a `sh` shell script (a 'hook') in the Stack root directory at `hooks/ghc-install.sh`. On Unix-like operating systems, the script file must be made executable. The script is run by the `sh` application (which is provided by MSYS2 on Windows). The script **must** return an exit code of `0` and the standard output **must** be the absolute path to the GHC binary that was installed. Otherwise Stack will ignore the script and possibly fall back to its own installation procedure. The script is not run when `system-ghc: true`. When `install-ghc: false`, the script is still run, which allows you to ensure that only your script will install GHC and Stack won't default to its own installation logic, even when the script fails. The following environment variables are always available to the script: * `HOOK_GHC_TYPE = "bindist" | "git" | "ghcjs"` For "bindist", additional variables are: * `HOOK_GHC_VERSION = ` For "git", additional variables are: * `HOOK_GHC_COMMIT = ` * `HOOK_GHC_FLAVOR = ` For "ghcjs", additional variables are: * `HOOK_GHC_VERSION = ` * `HOOK_GHCJS_VERSION = ` An example script is: ~~~sh #!/bin/sh set -eu case $HOOK_GHC_TYPE in bindist) # install GHC here, not printing to stdout, e.g.: # command install $HOOK_GHC_VERSION >/dev/null ;; git) >&2 echo "Hook doesn't support installing from source" exit 1 ;; *) >&2 echo "Unsupported GHC installation type: $HOOK_GHC_TYPE" exit 2 ;; esac echo "location/to/ghc/executable" ~~~ If the following script is installed by GHCup, GHCup makes use of it, so that if Stack needs a version of GHC, GHCup takes over obtaining and installing that version: ~~~sh #!/bin/sh set -eu case $HOOK_GHC_TYPE in bindist) ghcdir=$(ghcup whereis --directory ghc "$HOOK_GHC_VERSION" || ghcup run --ghc "$HOOK_GHC_VERSION" --install) || exit 3 printf "%s/ghc" "${ghcdir}" ;; git) # TODO: should be somewhat possible >&2 echo "Hook doesn't support installing from source" exit 1 ;; *) >&2 echo "Unsupported GHC installation type: $HOOK_GHC_TYPE" exit 2 ;; esac ~~~ stack-2.9.3.1/src/setup-shim/StackSetupShim.hs0000644000000000000000000000304114445022466017314 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE PackageImports #-} module StackSetupShim where import Main #if MIN_VERSION_Cabal(3,8,1) import Distribution.PackageDescription (PackageDescription, emptyHookedBuildInfo) #else import "Cabal" Distribution.PackageDescription (PackageDescription, emptyHookedBuildInfo) #endif import Distribution.Simple import Distribution.Simple.Build import Distribution.Simple.Setup (ReplFlags, fromFlag, replDistPref, replVerbosity) import Distribution.Simple.LocalBuildInfo (LocalBuildInfo) import System.Environment (getArgs) mainOverride :: IO () mainOverride = do args <- getArgs if "repl" `elem` args && "stack-initial-build-steps" `elem` args then do defaultMainWithHooks simpleUserHooks { preRepl = \_ _ -> pure emptyHookedBuildInfo , replHook = stackReplHook , postRepl = \_ _ _ _ -> pure () } else main stackReplHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> ReplFlags -> [String] -> IO () stackReplHook pkg_descr lbi hooks flags args = do let distPref = fromFlag (replDistPref flags) verbosity = fromFlag (replVerbosity flags) case args of ("stack-initial-build-steps":rest) | null rest -> initialBuildSteps distPref pkg_descr lbi verbosity | otherwise -> fail "Misuse of running Setup.hs with stack-initial-build-steps, expected no arguments" _ -> replHook simpleUserHooks pkg_descr lbi hooks flags args stack-2.9.3.1/test/package-dump/ghc-7.10.txt0000644000000000000000000016144714353310352016375 0ustar0000000000000000name: ghc version: 7.10.1 id: ghc-7.10.1-325809317787a897b7a97d646ceaa3a3 key: ghc_EMlWrQ42XY0BNVbSrKixqY license: BSD3 maintainer: glasgow-haskell-users@haskell.org homepage: http://www.haskell.org/ghc/ synopsis: The GHC API description: GHC's functionality can be useful for more things than just compiling Haskell programs. Important use cases are programs that analyse (and perhaps transform) Haskell code. Others include loading Haskell code dynamically in a GHCi-like manner. For this reason, a lot of GHC's functionality is made available through this package. category: Development author: The GHC Team exposed: False exposed-modules: Avail BasicTypes ConLike DataCon PatSyn Demand Debug Exception GhcMonad Hooks Id IdInfo Lexeme Literal Llvm Llvm.AbsSyn Llvm.MetaData Llvm.PpLlvm Llvm.Types LlvmCodeGen LlvmCodeGen.Base LlvmCodeGen.CodeGen LlvmCodeGen.Data LlvmCodeGen.Ppr LlvmCodeGen.Regs LlvmMangler MkId Module Name NameEnv NameSet OccName RdrName SrcLoc UniqSupply Unique Var VarEnv VarSet UnVarGraph BlockId CLabel Cmm CmmBuildInfoTables CmmPipeline CmmCallConv CmmCommonBlockElim CmmContFlowOpt CmmExpr CmmInfo CmmLex CmmLint CmmLive CmmMachOp CmmNode CmmOpt CmmParse CmmProcPoint CmmSink CmmType CmmUtils CmmLayoutStack MkGraph PprBase PprC PprCmm PprCmmDecl PprCmmExpr Bitmap CodeGen.Platform CodeGen.Platform.ARM CodeGen.Platform.ARM64 CodeGen.Platform.NoRegs CodeGen.Platform.PPC CodeGen.Platform.PPC_Darwin CodeGen.Platform.SPARC CodeGen.Platform.X86 CodeGen.Platform.X86_64 CgUtils StgCmm StgCmmBind StgCmmClosure StgCmmCon StgCmmEnv StgCmmExpr StgCmmForeign StgCmmHeap StgCmmHpc StgCmmArgRep StgCmmLayout StgCmmMonad StgCmmPrim StgCmmProf StgCmmTicky StgCmmUtils StgCmmExtCode SMRep CoreArity CoreFVs CoreLint CorePrep CoreSubst CoreSyn TrieMap CoreTidy CoreUnfold CoreUtils MkCore PprCore Check Coverage Desugar DsArrows DsBinds DsCCall DsExpr DsForeign DsGRHSs DsListComp DsMonad DsUtils Match MatchCon MatchLit HsBinds HsDecls HsDoc HsExpr HsImpExp HsLit PlaceHolder HsPat HsSyn HsTypes HsUtils BinIface BuildTyCl IfaceEnv IfaceSyn IfaceType LoadIface MkIface TcIface FlagChecker Annotations BreakArray CmdLineParser CodeOutput Config Constants DriverMkDepend DriverPhases PipelineMonad DriverPipeline DynFlags ErrUtils Finder GHC GhcMake GhcPlugins DynamicLoading HeaderInfo HscMain HscStats HscTypes InteractiveEval InteractiveEvalTypes PackageConfig Packages PlatformConstants Plugins TcPluginM PprTyThing StaticFlags StaticPtrTable SysTools TidyPgm Ctype HaddockUtils Lexer OptCoercion Parser RdrHsSyn ApiAnnotation ForeignCall PrelInfo PrelNames PrelRules PrimOp TysPrim TysWiredIn CostCentre ProfInit SCCfinal RnBinds RnEnv RnExpr RnHsDoc RnNames RnPat RnSource RnSplice RnTypes CoreMonad CSE FloatIn FloatOut LiberateCase OccurAnal SAT SetLevels SimplCore SimplEnv SimplMonad SimplUtils Simplify SimplStg StgStats UnariseStg Rules SpecConstr Specialise CoreToStg StgLint StgSyn CallArity DmdAnal WorkWrap WwLib FamInst Inst TcAnnotations TcArrows TcBinds TcClassDcl TcDefaults TcDeriv TcEnv TcExpr TcForeign TcGenDeriv TcGenGenerics TcHsSyn TcHsType TcInstDcls TcMType TcValidity TcMatches TcPat TcPatSyn TcRnDriver TcRnMonad TcRnTypes TcRules TcSimplify TcErrors TcTyClsDecls TcTyDecls TcType TcEvidence TcUnify TcInteract TcCanonical TcFlatten TcSMonad TcTypeNats TcSplice Class Coercion FamInstEnv FunDeps InstEnv TyCon CoAxiom Kind Type TypeRep Unify Bag Binary BooleanFormula BufWrite Digraph Encoding FastBool FastFunctions FastMutInt FastString FastTypes Fingerprint FiniteMap GraphBase GraphColor GraphOps GraphPpr IOEnv ListSetOps Maybes MonadUtils OrdList Outputable Pair Panic Pretty Serialized State Stream StringBuffer UniqFM UniqSet Util ExtsCompat46 Vectorise.Builtins.Base Vectorise.Builtins.Initialise Vectorise.Builtins Vectorise.Monad.Base Vectorise.Monad.Naming Vectorise.Monad.Local Vectorise.Monad.Global Vectorise.Monad.InstEnv Vectorise.Monad Vectorise.Utils.Base Vectorise.Utils.Closure Vectorise.Utils.Hoisting Vectorise.Utils.PADict Vectorise.Utils.Poly Vectorise.Utils Vectorise.Generic.Description Vectorise.Generic.PAMethods Vectorise.Generic.PADict Vectorise.Generic.PData Vectorise.Type.Env Vectorise.Type.Type Vectorise.Type.TyConDecl Vectorise.Type.Classify Vectorise.Convert Vectorise.Vect Vectorise.Var Vectorise.Env Vectorise.Exp Vectorise Hoopl.Dataflow Hoopl AsmCodeGen TargetReg NCGMonad Instruction Size Reg RegClass PIC Platform CPrim X86.Regs X86.RegInfo X86.Instr X86.Cond X86.Ppr X86.CodeGen PPC.Regs PPC.RegInfo PPC.Instr PPC.Cond PPC.Ppr PPC.CodeGen SPARC.Base SPARC.Regs SPARC.Imm SPARC.AddrMode SPARC.Cond SPARC.Instr SPARC.Stack SPARC.ShortcutJump SPARC.Ppr SPARC.CodeGen SPARC.CodeGen.Amode SPARC.CodeGen.Base SPARC.CodeGen.CondCode SPARC.CodeGen.Gen32 SPARC.CodeGen.Gen64 SPARC.CodeGen.Sanity SPARC.CodeGen.Expand RegAlloc.Liveness RegAlloc.Graph.Main RegAlloc.Graph.Stats RegAlloc.Graph.ArchBase RegAlloc.Graph.ArchX86 RegAlloc.Graph.Coalesce RegAlloc.Graph.Spill RegAlloc.Graph.SpillClean RegAlloc.Graph.SpillCost RegAlloc.Graph.TrivColorable RegAlloc.Linear.Main RegAlloc.Linear.JoinToTargets RegAlloc.Linear.State RegAlloc.Linear.Stats RegAlloc.Linear.FreeRegs RegAlloc.Linear.StackMap RegAlloc.Linear.Base RegAlloc.Linear.X86.FreeRegs RegAlloc.Linear.X86_64.FreeRegs RegAlloc.Linear.PPC.FreeRegs RegAlloc.Linear.SPARC.FreeRegs Dwarf Dwarf.Types Dwarf.Constants DsMeta Convert ByteCodeAsm ByteCodeGen ByteCodeInstr ByteCodeItbls ByteCodeLink Debugger LibFFI Linker ObjLink RtClosureInspect DebuggerUtils trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/ghc_EMlWrQ42XY0BNVbSrKixqY library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/ghc_EMlWrQ42XY0BNVbSrKixqY data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/ghc-7.10.1 hs-libraries: HSghc-7.10.1-EMlWrQ42XY0BNVbSrKixqY include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/ghc_EMlWrQ42XY0BNVbSrKixqY/include depends: array-0.5.1.0-e29cdbe82692341ebb7ce6e2798294f9 base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a bin-package-db-0.0.0.0-708fc7d634a370b311371a5bcde40b62 bytestring-0.10.6.0-0909f8f31271f3d75749190bf2ee35db containers-0.5.6.2-2114032c163425cc264e6e1169dc2f6d directory-1.2.2.0-b4959b472d9eee380c6b32291ade29e0 filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6 hoopl-3.10.0.2-8c8dfc4c3140e5f7c982da224c3cb1f0 hpc-0.6.0.2-ac9064885aa8cb08a93314222939ead4 process-1.2.3.0-3b1e9bca6ac38225806ff7bbf3f845b1 template-haskell-2.10.0.0-e895139a0ffff267d412e3d0191ce93b time-1.5.0.1-e17a9220d438435579d2914e90774246 transformers-0.4.2.0-c1a7bb855a176fe475d7b665301cd48f unix-2.7.1.0-e5915eb989e568b732bc7286b0d0817f haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/ghc-7.10.1/ghc.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/ghc-7.10.1 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: haskeline version: 0.7.2.1 id: haskeline-0.7.2.1-a646e1ddf1a755ca5b5775dcb2ef8d8b key: haske_IlDhIe25uAn0WJY379Nu1M license: BSD3 copyright: (c) Judah Jacobson maintainer: Judah Jacobson stability: Experimental homepage: http://trac.haskell.org/haskeline synopsis: A command-line interface for user input, written in Haskell. description: Haskeline provides a user interface for line input in command-line programs. This library is similar in purpose to readline, but since it is written in Haskell it is (hopefully) more easily used in other Haskell programs. . Haskeline runs both on POSIX-compatible systems and on Windows. category: User Interfaces author: Judah Jacobson exposed: True exposed-modules: System.Console.Haskeline System.Console.Haskeline.Completion System.Console.Haskeline.MonadException System.Console.Haskeline.History System.Console.Haskeline.IO hidden-modules: System.Console.Haskeline.Backend System.Console.Haskeline.Backend.WCWidth System.Console.Haskeline.Command System.Console.Haskeline.Command.Completion System.Console.Haskeline.Command.History System.Console.Haskeline.Command.KillRing System.Console.Haskeline.Directory System.Console.Haskeline.Emacs System.Console.Haskeline.InputT System.Console.Haskeline.Key System.Console.Haskeline.LineState System.Console.Haskeline.Monads System.Console.Haskeline.Prefs System.Console.Haskeline.RunCommand System.Console.Haskeline.Term System.Console.Haskeline.Command.Undo System.Console.Haskeline.Vi System.Console.Haskeline.Recover System.Console.Haskeline.Backend.Posix System.Console.Haskeline.Backend.Posix.Encoder System.Console.Haskeline.Backend.DumbTerm System.Console.Haskeline.Backend.Terminfo trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/haske_IlDhIe25uAn0WJY379Nu1M library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/haske_IlDhIe25uAn0WJY379Nu1M data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/haskeline-0.7.2.1 hs-libraries: HShaskeline-0.7.2.1-IlDhIe25uAn0WJY379Nu1M depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a bytestring-0.10.6.0-0909f8f31271f3d75749190bf2ee35db containers-0.5.6.2-2114032c163425cc264e6e1169dc2f6d directory-1.2.2.0-b4959b472d9eee380c6b32291ade29e0 filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6 terminfo-0.4.0.1-75199801b414a3f4c9de438be2a4e967 transformers-0.4.2.0-c1a7bb855a176fe475d7b665301cd48f unix-2.7.1.0-e5915eb989e568b732bc7286b0d0817f haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/haskeline-0.7.2.1/haskeline.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/haskeline-0.7.2.1 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: terminfo version: 0.4.0.1 id: terminfo-0.4.0.1-75199801b414a3f4c9de438be2a4e967 key: termi_7qZwBlx3clR8sTBilJl253 license: BSD3 copyright: (c) Judah Jacobson maintainer: Judah Jacobson stability: Stable homepage: https://github.com/judah/terminfo synopsis: Haskell bindings to the terminfo library. description: This library provides an interface to the terminfo database (via bindings to the curses library). allows POSIX systems to interact with a variety of terminals using a standard set of capabilities. category: User Interfaces author: Judah Jacobson exposed: True exposed-modules: System.Console.Terminfo System.Console.Terminfo.Base System.Console.Terminfo.Cursor System.Console.Terminfo.Color System.Console.Terminfo.Edit System.Console.Terminfo.Effects System.Console.Terminfo.Keys trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/termi_7qZwBlx3clR8sTBilJl253 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/termi_7qZwBlx3clR8sTBilJl253 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/terminfo-0.4.0.1 hs-libraries: HSterminfo-0.4.0.1-7qZwBlx3clR8sTBilJl253 extra-libraries: tinfo includes: ncurses.h term.h depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/terminfo-0.4.0.1/terminfo.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/terminfo-0.4.0.1 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: xhtml version: 3000.2.1 id: xhtml-3000.2.1-7de0560ea74b173b7313fc2303cc6c58 key: xhtml_0mVDYvYGgNUBWShvlDofr1 license: BSD3 copyright: Bjorn Bringert 2004-2006, Andy Gill and the Oregon Graduate Institute of Science and Technology, 1999-2001 maintainer: Chris Dornan stability: Stable homepage: https://github.com/haskell/xhtml synopsis: An XHTML combinator library description: This package provides combinators for producing XHTML 1.0, including the Strict, Transitional and Frameset variants. category: Web, XML, Pretty Printer author: Bjorn Bringert exposed: True exposed-modules: Text.XHtml Text.XHtml.Frameset Text.XHtml.Strict Text.XHtml.Transitional Text.XHtml.Debug Text.XHtml.Table hidden-modules: Text.XHtml.Strict.Attributes Text.XHtml.Strict.Elements Text.XHtml.Frameset.Attributes Text.XHtml.Frameset.Elements Text.XHtml.Transitional.Attributes Text.XHtml.Transitional.Elements Text.XHtml.BlockTable Text.XHtml.Extras Text.XHtml.Internals trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/xhtml_0mVDYvYGgNUBWShvlDofr1 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/xhtml_0mVDYvYGgNUBWShvlDofr1 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/xhtml-3000.2.1 hs-libraries: HSxhtml-3000.2.1-0mVDYvYGgNUBWShvlDofr1 depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/xhtml-3000.2.1/xhtml.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/xhtml-3000.2.1 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: transformers version: 0.4.2.0 id: transformers-0.4.2.0-c1a7bb855a176fe475d7b665301cd48f key: trans_ALYlebOVzVI4kxbFX5SGhm license: BSD3 maintainer: Ross Paterson synopsis: Concrete functor and monad transformers description: A portable library of functor and monad transformers, inspired by the paper \"Functional Programming with Overloading and Higher-Order Polymorphism\", by Mark P Jones, in /Advanced School of Functional Programming/, 1995 (). . This package contains: . * the monad transformer class (in "Control.Monad.Trans.Class") and IO monad class (in "Control.Monad.IO.Class") . * concrete functor and monad transformers, each with associated operations and functions to lift operations associated with other transformers. . The package can be used on its own in portable Haskell code, in which case operations need to be manually lifted through transformer stacks (see "Control.Monad.Trans.Class" for some examples). Alternatively, it can be used with the non-portable monad classes in the @mtl@ or @monads-tf@ packages, which automatically lift operations introduced by monad transformers through other transformers. category: Control author: Andy Gill, Ross Paterson exposed: True exposed-modules: Control.Applicative.Backwards Control.Applicative.Lift Control.Monad.IO.Class Control.Monad.Signatures Control.Monad.Trans.Class Control.Monad.Trans.Cont Control.Monad.Trans.Except Control.Monad.Trans.Error Control.Monad.Trans.Identity Control.Monad.Trans.List Control.Monad.Trans.Maybe Control.Monad.Trans.Reader Control.Monad.Trans.RWS Control.Monad.Trans.RWS.Lazy Control.Monad.Trans.RWS.Strict Control.Monad.Trans.State Control.Monad.Trans.State.Lazy Control.Monad.Trans.State.Strict Control.Monad.Trans.Writer Control.Monad.Trans.Writer.Lazy Control.Monad.Trans.Writer.Strict Data.Functor.Classes Data.Functor.Compose Data.Functor.Constant Data.Functor.Product Data.Functor.Reverse Data.Functor.Sum trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/trans_ALYlebOVzVI4kxbFX5SGhm library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/trans_ALYlebOVzVI4kxbFX5SGhm data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/transformers-0.4.2.0 hs-libraries: HStransformers-0.4.2.0-ALYlebOVzVI4kxbFX5SGhm depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/transformers-0.4.2.0/transformers.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/transformers-0.4.2.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: hoopl version: 3.10.0.2 id: hoopl-3.10.0.2-8c8dfc4c3140e5f7c982da224c3cb1f0 key: hoopl_JxODiSRz1e84NbH6nnZuUk license: BSD3 maintainer: nr@cs.tufts.edu homepage: http://ghc.cs.tufts.edu/hoopl/ synopsis: A library to support dataflow analysis and optimization description: Higher-order optimization library . See /Norman Ramsey, Joao Dias, and Simon Peyton Jones./ /(2010)/ for more details. category: Compilers/Interpreters author: Norman Ramsey, Joao Dias, Simon Marlow and Simon Peyton Jones exposed: True exposed-modules: Compiler.Hoopl Compiler.Hoopl.Internals Compiler.Hoopl.Wrappers Compiler.Hoopl.Passes.Dominator Compiler.Hoopl.Passes.DList hidden-modules: Compiler.Hoopl.Checkpoint Compiler.Hoopl.Collections Compiler.Hoopl.Combinators Compiler.Hoopl.Dataflow Compiler.Hoopl.Debug Compiler.Hoopl.Block Compiler.Hoopl.Graph Compiler.Hoopl.Label Compiler.Hoopl.MkGraph Compiler.Hoopl.Fuel Compiler.Hoopl.Pointed Compiler.Hoopl.Shape Compiler.Hoopl.Show Compiler.Hoopl.Unique Compiler.Hoopl.XUtil trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/hoopl_JxODiSRz1e84NbH6nnZuUk library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/hoopl_JxODiSRz1e84NbH6nnZuUk data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/hoopl-3.10.0.2 hs-libraries: HShoopl-3.10.0.2-JxODiSRz1e84NbH6nnZuUk depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a containers-0.5.6.2-2114032c163425cc264e6e1169dc2f6d haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/hoopl-3.10.0.2/hoopl.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/hoopl-3.10.0.2 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: bin-package-db version: 0.0.0.0 id: bin-package-db-0.0.0.0-708fc7d634a370b311371a5bcde40b62 key: binpa_JNoexmBMuO8C771QaIy3YN license: BSD3 maintainer: ghc-devs@haskell.org synopsis: The GHC compiler's view of the GHC package database format description: This library is shared between GHC and ghc-pkg and is used by GHC to read package databases. . It only deals with the subset of the package database that the compiler cares about: modules paths etc and not package metadata like description, authors etc. It is thus not a library interface to ghc-pkg and is *not* suitable for modifying GHC package databases. . The package database format and this library are constructed in such a way that while ghc-pkg depends on Cabal, the GHC library and program do not have to depend on Cabal. exposed: True exposed-modules: GHC.PackageDb trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/binpa_JNoexmBMuO8C771QaIy3YN library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/binpa_JNoexmBMuO8C771QaIy3YN data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/bin-package-db-0.0.0.0 hs-libraries: HSbin-package-db-0.0.0.0-JNoexmBMuO8C771QaIy3YN depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a binary-0.7.3.0-0f543654a1ae447e0d4d0bbfc1bb704e bytestring-0.10.6.0-0909f8f31271f3d75749190bf2ee35db directory-1.2.2.0-b4959b472d9eee380c6b32291ade29e0 filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/bin-package-db-0.0.0.0/bin-package-db.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/bin-package-db-0.0.0.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: Cabal version: 1.22.2.0 id: Cabal-1.22.2.0-9f7cae2e98cca225e3d159c1e1bc773c key: Cabal_HWT8QvVfJLn2ubvobpycJY license: BSD3 copyright: 2003-2006, Isaac Jones 2005-2011, Duncan Coutts maintainer: cabal-devel@haskell.org homepage: http://www.haskell.org/cabal/ synopsis: A framework for packaging Haskell software description: The Haskell Common Architecture for Building Applications and Libraries: a framework defining a common interface for authors to more easily build their Haskell applications in a portable way. . The Haskell Cabal is part of a larger infrastructure for distributing, organizing, and cataloging Haskell libraries and tools. category: Distribution author: Isaac Jones Duncan Coutts exposed: True exposed-modules: Distribution.Compat.CreatePipe Distribution.Compat.Environment Distribution.Compat.Exception Distribution.Compat.ReadP Distribution.Compiler Distribution.InstalledPackageInfo Distribution.License Distribution.Make Distribution.ModuleName Distribution.Package Distribution.PackageDescription Distribution.PackageDescription.Check Distribution.PackageDescription.Configuration Distribution.PackageDescription.Parse Distribution.PackageDescription.PrettyPrint Distribution.PackageDescription.Utils Distribution.ParseUtils Distribution.ReadE Distribution.Simple Distribution.Simple.Bench Distribution.Simple.Build Distribution.Simple.Build.Macros Distribution.Simple.Build.PathsModule Distribution.Simple.BuildPaths Distribution.Simple.BuildTarget Distribution.Simple.CCompiler Distribution.Simple.Command Distribution.Simple.Compiler Distribution.Simple.Configure Distribution.Simple.GHC Distribution.Simple.GHCJS Distribution.Simple.Haddock Distribution.Simple.HaskellSuite Distribution.Simple.Hpc Distribution.Simple.Install Distribution.Simple.InstallDirs Distribution.Simple.JHC Distribution.Simple.LHC Distribution.Simple.LocalBuildInfo Distribution.Simple.PackageIndex Distribution.Simple.PreProcess Distribution.Simple.PreProcess.Unlit Distribution.Simple.Program Distribution.Simple.Program.Ar Distribution.Simple.Program.Builtin Distribution.Simple.Program.Db Distribution.Simple.Program.Find Distribution.Simple.Program.GHC Distribution.Simple.Program.HcPkg Distribution.Simple.Program.Hpc Distribution.Simple.Program.Ld Distribution.Simple.Program.Run Distribution.Simple.Program.Script Distribution.Simple.Program.Strip Distribution.Simple.Program.Types Distribution.Simple.Register Distribution.Simple.Setup Distribution.Simple.SrcDist Distribution.Simple.Test Distribution.Simple.Test.ExeV10 Distribution.Simple.Test.LibV09 Distribution.Simple.Test.Log Distribution.Simple.UHC Distribution.Simple.UserHooks Distribution.Simple.Utils Distribution.System Distribution.TestSuite Distribution.Text Distribution.Utils.NubList Distribution.Verbosity Distribution.Version Language.Haskell.Extension hidden-modules: Distribution.Compat.Binary Distribution.Compat.CopyFile Distribution.Compat.TempFile Distribution.GetOpt Distribution.Simple.GHC.Internal Distribution.Simple.GHC.IPI641 Distribution.Simple.GHC.IPI642 Distribution.Simple.GHC.ImplInfo Paths_Cabal trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/Cabal_HWT8QvVfJLn2ubvobpycJY library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/Cabal_HWT8QvVfJLn2ubvobpycJY data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/Cabal-1.22.2.0 hs-libraries: HSCabal-1.22.2.0-HWT8QvVfJLn2ubvobpycJY depends: array-0.5.1.0-e29cdbe82692341ebb7ce6e2798294f9 base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a binary-0.7.3.0-0f543654a1ae447e0d4d0bbfc1bb704e bytestring-0.10.6.0-0909f8f31271f3d75749190bf2ee35db containers-0.5.6.2-2114032c163425cc264e6e1169dc2f6d deepseq-1.4.1.1-c1376f846fa170f2cc2cb2e57b203339 directory-1.2.2.0-b4959b472d9eee380c6b32291ade29e0 filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6 pretty-1.1.2.0-0d4e1eca3b0cfcebe20b9405f7bdaca9 process-1.2.3.0-3b1e9bca6ac38225806ff7bbf3f845b1 time-1.5.0.1-e17a9220d438435579d2914e90774246 unix-2.7.1.0-e5915eb989e568b732bc7286b0d0817f haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/Cabal-1.22.2.0/Cabal.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/Cabal-1.22.2.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: binary version: 0.7.3.0 id: binary-0.7.3.0-0f543654a1ae447e0d4d0bbfc1bb704e key: binar_EKE3c9Lmxb3DQpU0fPtru6 license: BSD3 maintainer: Lennart Kolmodin, Don Stewart stability: provisional homepage: https://github.com/kolmodin/binary synopsis: Binary serialisation for Haskell values using lazy ByteStrings description: Efficient, pure binary serialisation using lazy ByteStrings. Haskell values may be encoded to and from binary formats, written to disk as binary, or sent over the network. The format used can be automatically generated, or you can choose to implement a custom format if needed. Serialisation speeds of over 1 G\/sec have been observed, so this library should be suitable for high performance scenarios. category: Data, Parsing author: Lennart Kolmodin exposed: True exposed-modules: Data.Binary Data.Binary.Put Data.Binary.Get Data.Binary.Get.Internal Data.Binary.Builder Data.Binary.Builder.Internal hidden-modules: Data.Binary.Builder.Base Data.Binary.Class Data.Binary.Generic trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/binar_EKE3c9Lmxb3DQpU0fPtru6 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/binar_EKE3c9Lmxb3DQpU0fPtru6 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/binary-0.7.3.0 hs-libraries: HSbinary-0.7.3.0-EKE3c9Lmxb3DQpU0fPtru6 depends: array-0.5.1.0-e29cdbe82692341ebb7ce6e2798294f9 base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a bytestring-0.10.6.0-0909f8f31271f3d75749190bf2ee35db containers-0.5.6.2-2114032c163425cc264e6e1169dc2f6d haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/binary-0.7.3.0/binary.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/binary-0.7.3.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: template-haskell version: 2.10.0.0 id: template-haskell-2.10.0.0-e895139a0ffff267d412e3d0191ce93b key: templ_BVMCZyLwIlfGfcqqzyUAI8 license: BSD3 maintainer: libraries@haskell.org synopsis: Support library for Template Haskell description: This package provides modules containing facilities for manipulating Haskell source code using Template Haskell. . See for more information. category: Template Haskell exposed: True exposed-modules: Language.Haskell.TH Language.Haskell.TH.Lib Language.Haskell.TH.Ppr Language.Haskell.TH.PprLib Language.Haskell.TH.Quote Language.Haskell.TH.Syntax hidden-modules: Language.Haskell.TH.Lib.Map trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/templ_BVMCZyLwIlfGfcqqzyUAI8 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/templ_BVMCZyLwIlfGfcqqzyUAI8 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/template-haskell-2.10.0.0 hs-libraries: HStemplate-haskell-2.10.0.0-BVMCZyLwIlfGfcqqzyUAI8 depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a pretty-1.1.2.0-0d4e1eca3b0cfcebe20b9405f7bdaca9 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/template-haskell-2.10.0.0/template-haskell.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/template-haskell-2.10.0.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: pretty version: 1.1.2.0 id: pretty-1.1.2.0-0d4e1eca3b0cfcebe20b9405f7bdaca9 key: prett_7jIfj8VCGFf1WS0tIQ1XSZ license: BSD3 maintainer: David Terei stability: Stable homepage: http://github.com/haskell/pretty synopsis: Pretty-printing library description: This package contains a pretty-printing library, a set of API's that provides a way to easily print out text in a consistent format of your choosing. This is useful for compilers and related tools. . This library was originally designed by John Hughes's and has since been heavily modified by Simon Peyton Jones. category: Text exposed: True exposed-modules: Text.PrettyPrint Text.PrettyPrint.HughesPJ Text.PrettyPrint.HughesPJClass trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/prett_7jIfj8VCGFf1WS0tIQ1XSZ library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/prett_7jIfj8VCGFf1WS0tIQ1XSZ data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/pretty-1.1.2.0 hs-libraries: HSpretty-1.1.2.0-7jIfj8VCGFf1WS0tIQ1XSZ depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a deepseq-1.4.1.1-c1376f846fa170f2cc2cb2e57b203339 ghc-prim-0.4.0.0-7c945cc0c41d3b7b70f3edd125671166 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/pretty-1.1.2.0/pretty.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/pretty-1.1.2.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: hpc version: 0.6.0.2 id: hpc-0.6.0.2-ac9064885aa8cb08a93314222939ead4 key: hpc_CmUUQl5bURfBueJrdYfNs3 license: BSD3 maintainer: ghc-devs@haskell.org synopsis: Code Coverage Library for Haskell description: This package provides the code coverage library for Haskell. . See for more information. category: Control author: Andy Gill exposed: True exposed-modules: Trace.Hpc.Util Trace.Hpc.Mix Trace.Hpc.Tix Trace.Hpc.Reflect trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/hpc_CmUUQl5bURfBueJrdYfNs3 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/hpc_CmUUQl5bURfBueJrdYfNs3 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/hpc-0.6.0.2 hs-libraries: HShpc-0.6.0.2-CmUUQl5bURfBueJrdYfNs3 depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a containers-0.5.6.2-2114032c163425cc264e6e1169dc2f6d directory-1.2.2.0-b4959b472d9eee380c6b32291ade29e0 filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6 time-1.5.0.1-e17a9220d438435579d2914e90774246 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/hpc-0.6.0.2/hpc.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/hpc-0.6.0.2 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: process version: 1.2.3.0 id: process-1.2.3.0-3b1e9bca6ac38225806ff7bbf3f845b1 key: proce_0hwN3CTKynhHQqQkChnSdH license: BSD3 maintainer: libraries@haskell.org synopsis: Process libraries description: This package contains libraries for dealing with system processes. category: System exposed: True exposed-modules: System.Cmd System.Process System.Process.Internals trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/proce_0hwN3CTKynhHQqQkChnSdH library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/proce_0hwN3CTKynhHQqQkChnSdH data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/process-1.2.3.0 hs-libraries: HSprocess-1.2.3.0-0hwN3CTKynhHQqQkChnSdH include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/proce_0hwN3CTKynhHQqQkChnSdH/include includes: runProcess.h depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a deepseq-1.4.1.1-c1376f846fa170f2cc2cb2e57b203339 directory-1.2.2.0-b4959b472d9eee380c6b32291ade29e0 filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6 unix-2.7.1.0-e5915eb989e568b732bc7286b0d0817f haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/process-1.2.3.0/process.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/process-1.2.3.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: directory version: 1.2.2.0 id: directory-1.2.2.0-b4959b472d9eee380c6b32291ade29e0 key: direc_3TcTyYedch32o1zTH2MR00 license: BSD3 maintainer: libraries@haskell.org synopsis: Platform-agnostic library for filesystem operations description: This library provides a basic set of operations for manipulating files and directories in a portable way. category: System exposed: True exposed-modules: System.Directory trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/direc_3TcTyYedch32o1zTH2MR00 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/direc_3TcTyYedch32o1zTH2MR00 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/directory-1.2.2.0 hs-libraries: HSdirectory-1.2.2.0-3TcTyYedch32o1zTH2MR00 include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/direc_3TcTyYedch32o1zTH2MR00/include includes: HsDirectory.h depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6 time-1.5.0.1-e17a9220d438435579d2914e90774246 unix-2.7.1.0-e5915eb989e568b732bc7286b0d0817f haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/directory-1.2.2.0/directory.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/directory-1.2.2.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: unix version: 2.7.1.0 id: unix-2.7.1.0-e5915eb989e568b732bc7286b0d0817f key: unix_G4Yo1pNtYrk8nCq1cx8P9d license: BSD3 maintainer: libraries@haskell.org homepage: https://github.com/haskell/unix synopsis: POSIX functionality description: This package gives you access to the set of operating system services standardised by POSIX 1003.1b (or the IEEE Portable Operating System Interface for Computing Environments - IEEE Std. 1003.1). . The package is not supported under Windows (except under Cygwin). category: System exposed: True exposed-modules: System.Posix System.Posix.ByteString System.Posix.Error System.Posix.Resource System.Posix.Time System.Posix.Unistd System.Posix.User System.Posix.Signals System.Posix.Signals.Exts System.Posix.Semaphore System.Posix.SharedMem System.Posix.ByteString.FilePath System.Posix.Directory System.Posix.Directory.ByteString System.Posix.DynamicLinker.Module System.Posix.DynamicLinker.Module.ByteString System.Posix.DynamicLinker.Prim System.Posix.DynamicLinker.ByteString System.Posix.DynamicLinker System.Posix.Files System.Posix.Files.ByteString System.Posix.IO System.Posix.IO.ByteString System.Posix.Env System.Posix.Env.ByteString System.Posix.Fcntl System.Posix.Process System.Posix.Process.Internals System.Posix.Process.ByteString System.Posix.Temp System.Posix.Temp.ByteString System.Posix.Terminal System.Posix.Terminal.ByteString hidden-modules: System.Posix.Directory.Common System.Posix.DynamicLinker.Common System.Posix.Files.Common System.Posix.IO.Common System.Posix.Process.Common System.Posix.Terminal.Common trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/unix_G4Yo1pNtYrk8nCq1cx8P9d library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/unix_G4Yo1pNtYrk8nCq1cx8P9d data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/unix-2.7.1.0 hs-libraries: HSunix-2.7.1.0-G4Yo1pNtYrk8nCq1cx8P9d extra-libraries: rt util dl pthread include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/unix_G4Yo1pNtYrk8nCq1cx8P9d/include includes: HsUnix.h execvpe.h depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a bytestring-0.10.6.0-0909f8f31271f3d75749190bf2ee35db time-1.5.0.1-e17a9220d438435579d2914e90774246 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/unix-2.7.1.0/unix.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/unix-2.7.1.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: time version: 1.5.0.1 id: time-1.5.0.1-e17a9220d438435579d2914e90774246 key: time_Hh2clZW6in4HpYHx5bLtb7 license: BSD3 maintainer: stability: stable homepage: https://github.com/haskell/time synopsis: A time library description: A time library category: System author: Ashley Yakeley exposed: True exposed-modules: Data.Time.Calendar Data.Time.Calendar.MonthDay Data.Time.Calendar.OrdinalDate Data.Time.Calendar.WeekDate Data.Time.Calendar.Julian Data.Time.Calendar.Easter Data.Time.Clock Data.Time.Clock.POSIX Data.Time.Clock.TAI Data.Time.LocalTime Data.Time.Format Data.Time hidden-modules: Data.Time.Calendar.Private Data.Time.Calendar.Days Data.Time.Calendar.Gregorian Data.Time.Calendar.JulianYearDay Data.Time.Clock.Scale Data.Time.Clock.UTC Data.Time.Clock.CTimeval Data.Time.Clock.UTCDiff Data.Time.LocalTime.TimeZone Data.Time.LocalTime.TimeOfDay Data.Time.LocalTime.LocalTime Data.Time.Format.Parse Data.Time.Format.Locale trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/time_Hh2clZW6in4HpYHx5bLtb7 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/time_Hh2clZW6in4HpYHx5bLtb7 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/time-1.5.0.1 hs-libraries: HStime-1.5.0.1-Hh2clZW6in4HpYHx5bLtb7 include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/time_Hh2clZW6in4HpYHx5bLtb7/include depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a deepseq-1.4.1.1-c1376f846fa170f2cc2cb2e57b203339 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/time-1.5.0.1/time.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/time-1.5.0.1 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: containers version: 0.5.6.2 id: containers-0.5.6.2-2114032c163425cc264e6e1169dc2f6d key: conta_47ajk3tbda43DFWyeF3oHQ license: BSD3 maintainer: fox@ucw.cz synopsis: Assorted concrete container types description: This package contains efficient general-purpose implementations of various basic immutable container types. The declared cost of each operation is either worst-case or amortized, but remains valid even if structures are shared. category: Data Structures exposed: True exposed-modules: Data.IntMap Data.IntMap.Lazy Data.IntMap.Strict Data.IntSet Data.Map Data.Map.Lazy Data.Map.Strict Data.Set Data.Graph Data.Sequence Data.Tree hidden-modules: Data.IntMap.Base Data.IntSet.Base Data.Map.Base Data.Set.Base Data.Utils.BitUtil Data.Utils.StrictFold Data.Utils.StrictPair trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/conta_47ajk3tbda43DFWyeF3oHQ library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/conta_47ajk3tbda43DFWyeF3oHQ data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/containers-0.5.6.2 hs-libraries: HScontainers-0.5.6.2-47ajk3tbda43DFWyeF3oHQ depends: array-0.5.1.0-e29cdbe82692341ebb7ce6e2798294f9 base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a deepseq-1.4.1.1-c1376f846fa170f2cc2cb2e57b203339 ghc-prim-0.4.0.0-7c945cc0c41d3b7b70f3edd125671166 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/containers-0.5.6.2/containers.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/containers-0.5.6.2 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: bytestring version: 0.10.6.0 id: bytestring-0.10.6.0-0909f8f31271f3d75749190bf2ee35db key: bytes_6vj5EoliHgNHISHCVCb069 license: BSD3 copyright: Copyright (c) Don Stewart 2005-2009, (c) Duncan Coutts 2006-2015, (c) David Roundy 2003-2005, (c) Jasper Van der Jeugt 2010, (c) Simon Meier 2010-2013. maintainer: Duncan Coutts homepage: https://github.com/haskell/bytestring synopsis: Fast, compact, strict and lazy byte strings with a list interface description: An efficient compact, immutable byte string type (both strict and lazy) suitable for binary or 8-bit character data. . The 'ByteString' type represents sequences of bytes or 8-bit characters. It is suitable for high performance use, both in terms of large data quantities, or high speed requirements. The 'ByteString' functions follow the same style as Haskell\'s ordinary lists, so it is easy to convert code from using 'String' to 'ByteString'. . Two 'ByteString' variants are provided: . * Strict 'ByteString's keep the string as a single large array. This makes them convenient for passing data between C and Haskell. . * Lazy 'ByteString's use a lazy list of strict chunks which makes it suitable for I\/O streaming tasks. . The @Char8@ modules provide a character-based view of the same underlying 'ByteString' types. This makes it convenient to handle mixed binary and 8-bit character content (which is common in many file formats and network protocols). . The 'Builder' module provides an efficient way to build up 'ByteString's in an ad-hoc way by repeated concatenation. This is ideal for fast serialisation or pretty printing. . There is also a 'ShortByteString' type which has a lower memory overhead and can be converted to or from a 'ByteString', but supports very few other operations. It is suitable for keeping many short strings in memory. . 'ByteString's are not designed for Unicode. For Unicode strings you should use the 'Text' type from the @text@ package. . These modules are intended to be imported qualified, to avoid name clashes with "Prelude" functions, e.g. . > import qualified Data.ByteString as BS category: Data author: Don Stewart, Duncan Coutts exposed: True exposed-modules: Data.ByteString Data.ByteString.Char8 Data.ByteString.Unsafe Data.ByteString.Internal Data.ByteString.Lazy Data.ByteString.Lazy.Char8 Data.ByteString.Lazy.Internal Data.ByteString.Short Data.ByteString.Short.Internal Data.ByteString.Builder Data.ByteString.Builder.Extra Data.ByteString.Builder.Prim Data.ByteString.Builder.Internal Data.ByteString.Builder.Prim.Internal Data.ByteString.Lazy.Builder Data.ByteString.Lazy.Builder.Extras Data.ByteString.Lazy.Builder.ASCII hidden-modules: Data.ByteString.Builder.ASCII Data.ByteString.Builder.Prim.Binary Data.ByteString.Builder.Prim.ASCII Data.ByteString.Builder.Prim.Internal.Floating Data.ByteString.Builder.Prim.Internal.UncheckedShifts Data.ByteString.Builder.Prim.Internal.Base16 trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/bytes_6vj5EoliHgNHISHCVCb069 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/bytes_6vj5EoliHgNHISHCVCb069 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/bytestring-0.10.6.0 hs-libraries: HSbytestring-0.10.6.0-6vj5EoliHgNHISHCVCb069 include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/bytes_6vj5EoliHgNHISHCVCb069/include includes: fpstring.h depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a deepseq-1.4.1.1-c1376f846fa170f2cc2cb2e57b203339 ghc-prim-0.4.0.0-7c945cc0c41d3b7b70f3edd125671166 integer-gmp-1.0.0.0-3c947e5fb6dca14804d9b2793c521b67 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/bytestring-0.10.6.0/bytestring.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/bytestring-0.10.6.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: deepseq version: 1.4.1.1 id: deepseq-1.4.1.1-c1376f846fa170f2cc2cb2e57b203339 key: deeps_FpR4obOZALU1lutWnrBldi license: BSD3 maintainer: libraries@haskell.org synopsis: Deep evaluation of data structures description: This package provides methods for fully evaluating data structures (\"deep evaluation\"). Deep evaluation is often used for adding strictness to a program, e.g. in order to force pending exceptions, remove space leaks, or force lazy I/O to happen. It is also useful in parallel programs, to ensure pending work does not migrate to the wrong thread. . The primary use of this package is via the 'deepseq' function, a \"deep\" version of 'seq'. It is implemented on top of an 'NFData' typeclass (\"Normal Form Data\", data structures with no unevaluated components) which defines strategies for fully evaluating different data types. category: Control exposed: True exposed-modules: Control.DeepSeq trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/deeps_FpR4obOZALU1lutWnrBldi library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/deeps_FpR4obOZALU1lutWnrBldi data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/deepseq-1.4.1.1 hs-libraries: HSdeepseq-1.4.1.1-FpR4obOZALU1lutWnrBldi depends: array-0.5.1.0-e29cdbe82692341ebb7ce6e2798294f9 base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/deepseq-1.4.1.1/deepseq.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/deepseq-1.4.1.1 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: array version: 0.5.1.0 id: array-0.5.1.0-e29cdbe82692341ebb7ce6e2798294f9 key: array_FaHmcBFfuRM8kmZLEY8D5S license: BSD3 maintainer: libraries@haskell.org synopsis: Mutable and immutable arrays description: In addition to providing the "Data.Array" module , this package also defines the classes 'IArray' of immutable arrays and 'MArray' of arrays mutable within appropriate monads, as well as some instances of these classes. category: Data Structures exposed: True exposed-modules: Data.Array Data.Array.Base Data.Array.IArray Data.Array.IO Data.Array.IO.Safe Data.Array.IO.Internals Data.Array.MArray Data.Array.MArray.Safe Data.Array.ST Data.Array.ST.Safe Data.Array.Storable Data.Array.Storable.Safe Data.Array.Storable.Internals Data.Array.Unboxed Data.Array.Unsafe trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/array_FaHmcBFfuRM8kmZLEY8D5S library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/array_FaHmcBFfuRM8kmZLEY8D5S data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/array-0.5.1.0 hs-libraries: HSarray-0.5.1.0-FaHmcBFfuRM8kmZLEY8D5S depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/array-0.5.1.0/array.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/array-0.5.1.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: filepath version: 1.4.0.0 id: filepath-1.4.0.0-40d643aa87258c186441a1f8f3e13ca6 key: filep_5HhyRonfEZoDO205Wm9E4h license: BSD3 copyright: Neil Mitchell 2005-2015 maintainer: Neil Mitchell homepage: https://github.com/haskell/filepath#readme synopsis: Library for manipulating FilePaths in a cross platform way. description: This package provides functionality for manipulating @FilePath@ values, and is shipped with both and the . It provides three modules: . * "System.FilePath.Posix" manipulates POSIX\/Linux style @FilePath@ values (with @\/@ as the path separator). . * "System.FilePath.Windows" manipulates Windows style @FilePath@ values (with either @\\@ or @\/@ as the path separator, and deals with drives). . * "System.FilePath" is an alias for the module appropriate to your platform. . All three modules provide the same API, and the same documentation (calling out differences in the different variants). category: System author: Neil Mitchell exposed: True exposed-modules: System.FilePath System.FilePath.Posix System.FilePath.Windows trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/filep_5HhyRonfEZoDO205Wm9E4h library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/filep_5HhyRonfEZoDO205Wm9E4h data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/filepath-1.4.0.0 hs-libraries: HSfilepath-1.4.0.0-5HhyRonfEZoDO205Wm9E4h depends: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/filepath-1.4.0.0/filepath.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/filepath-1.4.0.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: base version: 4.8.0.0 id: base-4.8.0.0-1b689eb8d72c4d4cc88f445839c1f01a key: base_I5BErHzyOm07EBNpKBEeUv license: BSD3 maintainer: libraries@haskell.org synopsis: Basic libraries description: This package contains the "Prelude" and its support libraries, and a large collection of useful libraries ranging from data structures to parsing combinators and debugging utilities. category: Prelude exposed: True exposed-modules: Control.Applicative Control.Arrow Control.Category Control.Concurrent Control.Concurrent.Chan Control.Concurrent.MVar Control.Concurrent.QSem Control.Concurrent.QSemN Control.Exception Control.Exception.Base Control.Monad Control.Monad.Fix Control.Monad.Instances Control.Monad.ST Control.Monad.ST.Lazy Control.Monad.ST.Lazy.Safe Control.Monad.ST.Lazy.Unsafe Control.Monad.ST.Safe Control.Monad.ST.Strict Control.Monad.ST.Unsafe Control.Monad.Zip Data.Bifunctor Data.Bits Data.Bool Data.Char Data.Coerce Data.Complex Data.Data Data.Dynamic Data.Either Data.Eq Data.Fixed Data.Foldable Data.Function Data.Functor Data.Functor.Identity Data.IORef Data.Int Data.Ix Data.List Data.Maybe Data.Monoid Data.Ord Data.Proxy Data.Ratio Data.STRef Data.STRef.Lazy Data.STRef.Strict Data.String Data.Traversable Data.Tuple Data.Type.Bool Data.Type.Coercion Data.Type.Equality Data.Typeable Data.Typeable.Internal Data.Unique Data.Version Data.Void Data.Word Debug.Trace Foreign Foreign.C Foreign.C.Error Foreign.C.String Foreign.C.Types Foreign.Concurrent Foreign.ForeignPtr Foreign.ForeignPtr.Safe Foreign.ForeignPtr.Unsafe Foreign.Marshal Foreign.Marshal.Alloc Foreign.Marshal.Array Foreign.Marshal.Error Foreign.Marshal.Pool Foreign.Marshal.Safe Foreign.Marshal.Unsafe Foreign.Marshal.Utils Foreign.Ptr Foreign.Safe Foreign.StablePtr Foreign.Storable GHC.Arr GHC.Base GHC.Char GHC.Conc GHC.Conc.IO GHC.Conc.Signal GHC.Conc.Sync GHC.ConsoleHandler GHC.Constants GHC.Desugar GHC.Enum GHC.Environment GHC.Err GHC.Exception GHC.Exts GHC.Fingerprint GHC.Fingerprint.Type GHC.Float GHC.Float.ConversionUtils GHC.Float.RealFracMethods GHC.Foreign GHC.ForeignPtr GHC.GHCi GHC.Generics GHC.IO GHC.IO.Buffer GHC.IO.BufferedIO GHC.IO.Device GHC.IO.Encoding GHC.IO.Encoding.CodePage GHC.IO.Encoding.Failure GHC.IO.Encoding.Iconv GHC.IO.Encoding.Latin1 GHC.IO.Encoding.Types GHC.IO.Encoding.UTF16 GHC.IO.Encoding.UTF32 GHC.IO.Encoding.UTF8 GHC.IO.Exception GHC.IO.FD GHC.IO.Handle GHC.IO.Handle.FD GHC.IO.Handle.Internals GHC.IO.Handle.Text GHC.IO.Handle.Types GHC.IO.IOMode GHC.IOArray GHC.IORef GHC.IP GHC.Int GHC.List GHC.MVar GHC.Natural GHC.Num GHC.OldList GHC.PArr GHC.Pack GHC.Profiling GHC.Ptr GHC.Read GHC.Real GHC.RTS.Flags GHC.ST GHC.StaticPtr GHC.STRef GHC.Show GHC.Stable GHC.Stack GHC.Stats GHC.Storable GHC.TopHandler GHC.TypeLits GHC.Unicode GHC.Weak GHC.Word Numeric Numeric.Natural Prelude System.CPUTime System.Console.GetOpt System.Environment System.Exit System.IO System.IO.Error System.IO.Unsafe System.Info System.Mem System.Mem.StableName System.Mem.Weak System.Posix.Internals System.Posix.Types System.Timeout Text.ParserCombinators.ReadP Text.ParserCombinators.ReadPrec Text.Printf Text.Read Text.Read.Lex Text.Show Text.Show.Functions Unsafe.Coerce GHC.Event hidden-modules: Control.Monad.ST.Imp Control.Monad.ST.Lazy.Imp Data.OldList Foreign.ForeignPtr.Imp System.Environment.ExecutablePath GHC.Event.Arr GHC.Event.Array GHC.Event.Clock GHC.Event.Control GHC.Event.EPoll GHC.Event.IntTable GHC.Event.Internal GHC.Event.KQueue GHC.Event.Manager GHC.Event.PSQ GHC.Event.Poll GHC.Event.Thread GHC.Event.TimerManager GHC.Event.Unique trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/base_I5BErHzyOm07EBNpKBEeUv library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/base_I5BErHzyOm07EBNpKBEeUv data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/base-4.8.0.0 hs-libraries: HSbase-4.8.0.0-I5BErHzyOm07EBNpKBEeUv include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/base_I5BErHzyOm07EBNpKBEeUv/include includes: HsBase.h depends: builtin_rts ghc-prim-0.4.0.0-7c945cc0c41d3b7b70f3edd125671166 integer-gmp-1.0.0.0-3c947e5fb6dca14804d9b2793c521b67 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/base.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: integer-gmp version: 1.0.0.0 id: integer-gmp-1.0.0.0-3c947e5fb6dca14804d9b2793c521b67 key: integ_2aU3IZNMF9a7mQ0OzsZ0dS license: BSD3 maintainer: hvr@gnu.org synopsis: Integer library based on GMP category: Numeric, Algebra author: Herbert Valerio Riedel exposed: True exposed-modules: GHC.Integer GHC.Integer.Logarithms GHC.Integer.Logarithms.Internals GHC.Integer.GMP.Internals hidden-modules: GHC.Integer.Type trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/integ_2aU3IZNMF9a7mQ0OzsZ0dS library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/integ_2aU3IZNMF9a7mQ0OzsZ0dS data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/integer-gmp-1.0.0.0 hs-libraries: HSinteger-gmp-1.0.0.0-2aU3IZNMF9a7mQ0OzsZ0dS extra-libraries: gmp include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/integ_2aU3IZNMF9a7mQ0OzsZ0dS/include depends: ghc-prim-0.4.0.0-7c945cc0c41d3b7b70f3edd125671166 haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/integer-gmp-1.0.0.0/integer-gmp.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/integer-gmp-1.0.0.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: ghc-prim version: 0.4.0.0 id: ghc-prim-0.4.0.0-7c945cc0c41d3b7b70f3edd125671166 key: ghcpr_8TmvWUcS1U1IKHT0levwg3 license: BSD3 maintainer: libraries@haskell.org synopsis: GHC primitives description: GHC primitives. category: GHC exposed: True exposed-modules: GHC.CString GHC.Classes GHC.Debug GHC.IntWord64 GHC.Magic GHC.PrimopWrappers GHC.Tuple GHC.Types GHC.Prim trusted: False import-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/ghcpr_8TmvWUcS1U1IKHT0levwg3 library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/ghcpr_8TmvWUcS1U1IKHT0levwg3 data-dir: /opt/ghc/7.10.1/share/x86_64-linux-ghc-7.10.1/ghc-prim-0.4.0.0 hs-libraries: HSghc-prim-0.4.0.0-8TmvWUcS1U1IKHT0levwg3 depends: builtin_rts haddock-interfaces: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/ghc-prim-0.4.0.0/ghc-prim.haddock haddock-html: /opt/ghc/7.10.1/share/doc/ghc/html/libraries/ghc-prim-0.4.0.0 pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" --- name: rts version: 1.0 id: builtin_rts key: rts license: BSD3 maintainer: glasgow-haskell-users@haskell.org exposed: True trusted: False library-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/rts hs-libraries: HSrts Cffi extra-libraries: m rt dl include-dirs: /opt/ghc/7.10.1/lib/ghc-7.10.1/include includes: Stg.h ld-options: "-Wl,-u,ghczmprim_GHCziTypes_Izh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Czh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Fzh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Dzh_static_info" "-Wl,-u,base_GHCziPtr_Ptr_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Wzh_static_info" "-Wl,-u,base_GHCziInt_I8zh_static_info" "-Wl,-u,base_GHCziInt_I16zh_static_info" "-Wl,-u,base_GHCziInt_I32zh_static_info" "-Wl,-u,base_GHCziInt_I64zh_static_info" "-Wl,-u,base_GHCziWord_W8zh_static_info" "-Wl,-u,base_GHCziWord_W16zh_static_info" "-Wl,-u,base_GHCziWord_W32zh_static_info" "-Wl,-u,base_GHCziWord_W64zh_static_info" "-Wl,-u,base_GHCziStable_StablePtr_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Izh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Czh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Fzh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Dzh_con_info" "-Wl,-u,base_GHCziPtr_Ptr_con_info" "-Wl,-u,base_GHCziPtr_FunPtr_con_info" "-Wl,-u,base_GHCziStable_StablePtr_con_info" "-Wl,-u,ghczmprim_GHCziTypes_False_closure" "-Wl,-u,ghczmprim_GHCziTypes_True_closure" "-Wl,-u,base_GHCziPack_unpackCString_closure" "-Wl,-u,base_GHCziIOziException_stackOverflow_closure" "-Wl,-u,base_GHCziIOziException_heapOverflow_closure" "-Wl,-u,base_ControlziExceptionziBase_nonTermination_closure" "-Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnMVar_closure" "-Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnSTM_closure" "-Wl,-u,base_GHCziIOziException_allocationLimitExceeded_closure" "-Wl,-u,base_ControlziExceptionziBase_nestedAtomically_closure" "-Wl,-u,base_GHCziEventziThread_blockedOnBadFD_closure" "-Wl,-u,base_GHCziWeak_runFinalizzerBatch_closure" "-Wl,-u,base_GHCziTopHandler_flushStdHandles_closure" "-Wl,-u,base_GHCziTopHandler_runIO_closure" "-Wl,-u,base_GHCziTopHandler_runNonIO_closure" "-Wl,-u,base_GHCziConcziIO_ensureIOManagerIsRunning_closure" "-Wl,-u,base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure" "-Wl,-u,base_GHCziConcziSync_runSparks_closure" "-Wl,-u,base_GHCziConcziSignal_runHandlersPtr_closure" pkgroot: "/opt/ghc/7.10.1/lib/ghc-7.10.1" stack-2.9.3.1/test/package-dump/ghc-7.8.4-osx.txt0000644000000000000000000000636214266741655017310 0ustar0000000000000000name: hmatrix version: 0.16.1.5 id: hmatrix-0.16.1.5-12d5d21f26aa98774cdd8edbc343fbfe license: BSD3 copyright: maintainer: Alberto Ruiz stability: provisional homepage: https://github.com/albertoruiz/hmatrix package-url: synopsis: Numeric Linear Algebra description: Linear algebra based on BLAS and LAPACK. . The package is organized as follows: . ["Numeric.LinearAlgebra.HMatrix"] Starting point and recommended import module for most applications. . ["Numeric.LinearAlgebra.Static"] Experimental alternative interface. . ["Numeric.LinearAlgebra.Devel"] Tools for extending the library. . (Other modules are exposed with hidden documentation for backwards compatibility.) . Code examples: category: Math author: Alberto Ruiz exposed: True exposed-modules: Data.Packed Data.Packed.Vector Data.Packed.Matrix Data.Packed.Foreign Data.Packed.ST Data.Packed.Development Numeric.LinearAlgebra Numeric.LinearAlgebra.LAPACK Numeric.LinearAlgebra.Algorithms Numeric.Container Numeric.LinearAlgebra.Util Numeric.LinearAlgebra.Devel Numeric.LinearAlgebra.Data Numeric.LinearAlgebra.HMatrix Numeric.LinearAlgebra.Static hidden-modules: Data.Packed.Internal Data.Packed.Internal.Common Data.Packed.Internal.Signatures Data.Packed.Internal.Vector Data.Packed.Internal.Matrix Data.Packed.IO Numeric.Chain Numeric.Vectorized Numeric.Vector Numeric.Matrix Data.Packed.Internal.Numeric Data.Packed.Numeric Numeric.LinearAlgebra.Util.Convolution Numeric.LinearAlgebra.Util.CG Numeric.LinearAlgebra.Random Numeric.Conversion Numeric.Sparse Numeric.LinearAlgebra.Static.Internal trusted: False import-dirs: /Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/lib/x86_64-osx-ghc-7.8.4/hmatrix-0.16.1.5 library-dirs: /Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/lib/x86_64-osx-ghc-7.8.4/hmatrix-0.16.1.5 /opt/local/lib/ /usr/local/lib/ "C:/Program Files/Example/" hs-libraries: HShmatrix-0.16.1.5 extra-libraries: blas lapack extra-ghci-libraries: include-dirs: /opt/local/include/ /usr/local/include/ includes: depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b base-4.7.0.2-918c7ac27f65a87103264a9f51652d63 binary-0.7.1.0-108d06eea2ef05e517f9c1facf10f63c bytestring-0.10.4.0-78bc8f2c724c765c78c004a84acf6cc3 deepseq-1.3.0.2-0ddc77716bd2515426e1ba39f6788a4f random-1.1-822c19b7507b6ac1aaa4c66731e775ae split-0.2.2-34cfb851cc3784e22bfae7a7bddda9c5 storable-complex-0.2.2-e962c368d58acc1f5b41d41edc93da72 vector-0.10.12.3-f4222db607fd5fdd7545d3e82419b307 hugs-options: cc-options: ld-options: framework-dirs: frameworks: Accelerate haddock-interfaces: /Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/doc/html/hmatrix.haddock haddock-html: /Users/alexbiehl/.stack/snapshots/x86_64-osx/lts-2.13/7.8.4/doc/html stack-2.9.3.1/test/package-dump/ghc-7.8.txt0000644000000000000000000020303114353310352016306 0ustar0000000000000000name: haskell2010 version: 1.1.2.0 id: haskell2010-1.1.2.0-05c8dd51009e08c6371c82972d40f55a license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: http://www.haskell.org/onlinereport/haskell2010/ package-url: synopsis: Compatibility with Haskell 2010 description: This package provides exactly the library modules defined by the . category: Haskell2010, Prelude author: exposed: False exposed-modules: Prelude Control.Monad Data.Array Data.Bits Data.Char Data.Complex Data.Int Data.Ix Data.List Data.Maybe Data.Ratio Data.Word Foreign Foreign.C Foreign.C.Error Foreign.C.String Foreign.C.Types Foreign.ForeignPtr Foreign.Marshal Foreign.Marshal.Alloc Foreign.Marshal.Array Foreign.Marshal.Error Foreign.Marshal.Utils Foreign.Ptr Foreign.StablePtr Foreign.Storable Numeric System.Environment System.Exit System.IO System.IO.Error hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/haskell2010-1.1.2.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/haskell2010-1.1.2.0 hs-libraries: HShaskell2010-1.1.2.0 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 ghc-prim-0.3.1.0-a24f9c14c632d75b683d0f93283aea37 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/haskell2010-1.1.2.0/haskell2010.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/haskell2010-1.1.2.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: haskell98 version: 2.0.0.3 id: haskell98-2.0.0.3-045e8778b656db76e2c729405eee707b license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: http://www.haskell.org/definition/ package-url: synopsis: Compatibility with Haskell 98 description: This package provides compatibility with the modules of Haskell 98 and the FFI addendum, by means of wrappers around modules from the base package (which in many cases have additional features). However "Prelude", "Numeric" and "Foreign" are provided directly by the @base@ package. category: Haskell98, Prelude author: exposed: False exposed-modules: Prelude Array CPUTime Char Complex Directory IO Ix List Locale Maybe Monad Numeric Random Ratio System Time Bits CError CForeign CString CTypes ForeignPtr Int MarshalAlloc MarshalArray MarshalError MarshalUtils Ptr StablePtr Storable Word hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/haskell98-2.0.0.3 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/haskell98-2.0.0.3 hs-libraries: HShaskell98-2.0.0.3 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 directory-1.2.1.0-07cd1f59e3c6cac5e3e180019c59a115 old-locale-1.0.0.6-50b0125c49f76af85dc7aa22975cdc34 old-time-1.1.0.2-e3f776e97c1a6ff1770b04943a7ef7c6 process-1.2.0.0-06c3215a79834ce4886ae686a0f81122 time-1.4.2-9b3076800c33f8382c38628f35717951 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/haskell98-2.0.0.3/haskell98.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/haskell98-2.0.0.3 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: old-time version: 1.1.0.2 id: old-time-1.1.0.2-e3f776e97c1a6ff1770b04943a7ef7c6 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: Time library description: This package provides the old time library. . For new projects, the newer is recommended. category: System author: exposed: True exposed-modules: System.Time hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/old-time-1.1.0.2 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/old-time-1.1.0.2 hs-libraries: HSold-time-1.1.0.2 extra-libraries: extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/old-time-1.1.0.2/include includes: HsTime.h depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 old-locale-1.0.0.6-50b0125c49f76af85dc7aa22975cdc34 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/old-time-1.1.0.2/old-time.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/old-time-1.1.0.2 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: ghc version: 7.8.4 id: ghc-7.8.4-6c4818bc66adb23509058069f781d99a license: BSD3 copyright: maintainer: glasgow-haskell-users@haskell.org stability: homepage: http://www.haskell.org/ghc/ package-url: synopsis: The GHC API description: GHC's functionality can be useful for more things than just compiling Haskell programs. Important use cases are programs that analyse (and perhaps transform) Haskell code. Others include loading Haskell code dynamically in a GHCi-like manner. For this reason, a lot of GHC's functionality is made available through this package. category: Development author: The GHC Team exposed: False exposed-modules: Avail BasicTypes ConLike DataCon PatSyn Demand Exception GhcMonad Hooks Id IdInfo Literal Llvm Llvm.AbsSyn Llvm.MetaData Llvm.PpLlvm Llvm.Types LlvmCodeGen LlvmCodeGen.Base LlvmCodeGen.CodeGen LlvmCodeGen.Data LlvmCodeGen.Ppr LlvmCodeGen.Regs LlvmMangler MkId Module Name NameEnv NameSet OccName RdrName SrcLoc UniqSupply Unique Var VarEnv VarSet BlockId CLabel Cmm CmmBuildInfoTables CmmPipeline CmmCallConv CmmCommonBlockElim CmmContFlowOpt CmmExpr CmmInfo CmmLex CmmLint CmmLive CmmMachOp CmmNode CmmOpt CmmParse CmmProcPoint CmmRewriteAssignments CmmSink CmmType CmmUtils CmmLayoutStack MkGraph PprBase PprC PprCmm PprCmmDecl PprCmmExpr Bitmap CodeGen.Platform CodeGen.Platform.ARM CodeGen.Platform.NoRegs CodeGen.Platform.PPC CodeGen.Platform.PPC_Darwin CodeGen.Platform.SPARC CodeGen.Platform.X86 CodeGen.Platform.X86_64 CgUtils StgCmm StgCmmBind StgCmmClosure StgCmmCon StgCmmEnv StgCmmExpr StgCmmForeign StgCmmHeap StgCmmHpc StgCmmArgRep StgCmmLayout StgCmmMonad StgCmmPrim StgCmmProf StgCmmTicky StgCmmUtils StgCmmExtCode SMRep CoreArity CoreFVs CoreLint CorePrep CoreSubst CoreSyn TrieMap CoreTidy CoreUnfold CoreUtils ExternalCore MkCore MkExternalCore PprCore PprExternalCore Check Coverage Desugar DsArrows DsBinds DsCCall DsExpr DsForeign DsGRHSs DsListComp DsMonad DsUtils Match MatchCon MatchLit HsBinds HsDecls HsDoc HsExpr HsImpExp HsLit HsPat HsSyn HsTypes HsUtils BinIface BuildTyCl IfaceEnv IfaceSyn IfaceType LoadIface MkIface TcIface FlagChecker Annotations BreakArray CmdLineParser CodeOutput Config Constants DriverMkDepend DriverPhases PipelineMonad DriverPipeline DynFlags ErrUtils Finder GHC GhcMake GhcPlugins DynamicLoading HeaderInfo HscMain HscStats HscTypes InteractiveEval InteractiveEvalTypes PackageConfig Packages PlatformConstants PprTyThing StaticFlags SysTools TidyPgm Ctype HaddockUtils LexCore Lexer OptCoercion Parser ParserCore ParserCoreUtils RdrHsSyn ForeignCall PrelInfo PrelNames PrelRules PrimOp TysPrim TysWiredIn CostCentre ProfInit SCCfinal RnBinds RnEnv RnExpr RnHsDoc RnNames RnPat RnSource RnSplice RnTypes CoreMonad CSE FloatIn FloatOut LiberateCase OccurAnal SAT SetLevels SimplCore SimplEnv SimplMonad SimplUtils Simplify SimplStg StgStats UnariseStg Rules SpecConstr Specialise CoreToStg StgLint StgSyn DmdAnal WorkWrap WwLib FamInst Inst TcAnnotations TcArrows TcBinds TcClassDcl TcDefaults TcDeriv TcEnv TcExpr TcForeign TcGenDeriv TcGenGenerics TcHsSyn TcHsType TcInstDcls TcMType TcValidity TcMatches TcPat TcPatSyn TcRnDriver TcRnMonad TcRnTypes TcRules TcSimplify TcErrors TcTyClsDecls TcTyDecls TcType TcEvidence TcUnify TcInteract TcCanonical TcSMonad TcTypeNats TcSplice Class Coercion FamInstEnv FunDeps InstEnv TyCon CoAxiom Kind Type TypeRep Unify Bag Binary BooleanFormula BufWrite Digraph Encoding FastBool FastFunctions FastMutInt FastString FastTypes Fingerprint FiniteMap GraphBase GraphColor GraphOps GraphPpr IOEnv ListSetOps Maybes MonadUtils OrdList Outputable Pair Panic Pretty Serialized State Stream StringBuffer UniqFM UniqSet Util ExtsCompat46 Vectorise.Builtins.Base Vectorise.Builtins.Initialise Vectorise.Builtins Vectorise.Monad.Base Vectorise.Monad.Naming Vectorise.Monad.Local Vectorise.Monad.Global Vectorise.Monad.InstEnv Vectorise.Monad Vectorise.Utils.Base Vectorise.Utils.Closure Vectorise.Utils.Hoisting Vectorise.Utils.PADict Vectorise.Utils.Poly Vectorise.Utils Vectorise.Generic.Description Vectorise.Generic.PAMethods Vectorise.Generic.PADict Vectorise.Generic.PData Vectorise.Type.Env Vectorise.Type.Type Vectorise.Type.TyConDecl Vectorise.Type.Classify Vectorise.Convert Vectorise.Vect Vectorise.Var Vectorise.Env Vectorise.Exp Vectorise Hoopl.Dataflow Hoopl AsmCodeGen TargetReg NCGMonad Instruction Size Reg RegClass PIC Platform CPrim X86.Regs X86.RegInfo X86.Instr X86.Cond X86.Ppr X86.CodeGen PPC.Regs PPC.RegInfo PPC.Instr PPC.Cond PPC.Ppr PPC.CodeGen SPARC.Base SPARC.Regs SPARC.Imm SPARC.AddrMode SPARC.Cond SPARC.Instr SPARC.Stack SPARC.ShortcutJump SPARC.Ppr SPARC.CodeGen SPARC.CodeGen.Amode SPARC.CodeGen.Base SPARC.CodeGen.CondCode SPARC.CodeGen.Gen32 SPARC.CodeGen.Gen64 SPARC.CodeGen.Sanity SPARC.CodeGen.Expand RegAlloc.Liveness RegAlloc.Graph.Main RegAlloc.Graph.Stats RegAlloc.Graph.ArchBase RegAlloc.Graph.ArchX86 RegAlloc.Graph.Coalesce RegAlloc.Graph.Spill RegAlloc.Graph.SpillClean RegAlloc.Graph.SpillCost RegAlloc.Graph.TrivColorable RegAlloc.Linear.Main RegAlloc.Linear.JoinToTargets RegAlloc.Linear.State RegAlloc.Linear.Stats RegAlloc.Linear.FreeRegs RegAlloc.Linear.StackMap RegAlloc.Linear.Base RegAlloc.Linear.X86.FreeRegs RegAlloc.Linear.X86_64.FreeRegs RegAlloc.Linear.PPC.FreeRegs RegAlloc.Linear.SPARC.FreeRegs DsMeta Convert ByteCodeAsm ByteCodeGen ByteCodeInstr ByteCodeItbls ByteCodeLink Debugger LibFFI Linker ObjLink RtClosureInspect DebuggerUtils hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/ghc-7.8.4 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/ghc-7.8.4 hs-libraries: HSghc-7.8.4 extra-libraries: extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/ghc-7.8.4/include includes: depends: Cabal-1.18.1.5-6478013104bde01737bfd67d34bbee0a array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 bin-package-db-0.0.0.0-0f3da03684207f2dc4dce793df1db62e bytestring-0.10.4.0-d6f1d17d717e8652498cab8269a0acd5 containers-0.5.5.1-d4bd887fb97aa3a46cbadc13709b7653 directory-1.2.1.0-07cd1f59e3c6cac5e3e180019c59a115 filepath-1.3.0.2-25a474a9272ae6260626ce0d70ad1cab hoopl-3.10.0.1-267659e4b5b51c3d2e02f2a6d6f46936 hpc-0.6.0.1-cca17f12dab542e09c423a74a4590c5d process-1.2.0.0-06c3215a79834ce4886ae686a0f81122 template-haskell-2.9.0.0-6d27c2b362b15abb1822f2f34b9ae7f9 time-1.4.2-9b3076800c33f8382c38628f35717951 transformers-0.3.0.0-6458c21515cab7c1cf21e53141557a1c unix-2.7.0.1-f8658ba9ec1c4fba8a371a8e0f42ec6c hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/ghc-7.8.4/ghc.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/ghc-7.8.4 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: haskeline version: 0.7.1.2 id: haskeline-0.7.1.2-2dd2f2fb537352f5367ae77fe47ab211 license: BSD3 copyright: (c) Judah Jacobson maintainer: Judah Jacobson stability: Experimental homepage: http://trac.haskell.org/haskeline package-url: synopsis: A command-line interface for user input, written in Haskell. description: Haskeline provides a user interface for line input in command-line programs. This library is similar in purpose to readline, but since it is written in Haskell it is (hopefully) more easily used in other Haskell programs. . Haskeline runs both on POSIX-compatible systems and on Windows. category: User Interfaces author: Judah Jacobson exposed: True exposed-modules: System.Console.Haskeline System.Console.Haskeline.Completion System.Console.Haskeline.MonadException System.Console.Haskeline.History System.Console.Haskeline.IO hidden-modules: System.Console.Haskeline.Backend System.Console.Haskeline.Backend.WCWidth System.Console.Haskeline.Command System.Console.Haskeline.Command.Completion System.Console.Haskeline.Command.History System.Console.Haskeline.Command.KillRing System.Console.Haskeline.Directory System.Console.Haskeline.Emacs System.Console.Haskeline.InputT System.Console.Haskeline.Key System.Console.Haskeline.LineState System.Console.Haskeline.Monads System.Console.Haskeline.Prefs System.Console.Haskeline.RunCommand System.Console.Haskeline.Term System.Console.Haskeline.Command.Undo System.Console.Haskeline.Vi System.Console.Haskeline.Recover System.Console.Haskeline.Backend.Posix System.Console.Haskeline.Backend.Posix.Encoder System.Console.Haskeline.Backend.DumbTerm System.Console.Haskeline.Backend.Terminfo trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/haskeline-0.7.1.2 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/haskeline-0.7.1.2 hs-libraries: HShaskeline-0.7.1.2 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 bytestring-0.10.4.0-d6f1d17d717e8652498cab8269a0acd5 containers-0.5.5.1-d4bd887fb97aa3a46cbadc13709b7653 directory-1.2.1.0-07cd1f59e3c6cac5e3e180019c59a115 filepath-1.3.0.2-25a474a9272ae6260626ce0d70ad1cab terminfo-0.4.0.0-c1d02a7210b0d1bc250d87463b38b8d1 transformers-0.3.0.0-6458c21515cab7c1cf21e53141557a1c unix-2.7.0.1-f8658ba9ec1c4fba8a371a8e0f42ec6c hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/haskeline-0.7.1.2/haskeline.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/haskeline-0.7.1.2 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: terminfo version: 0.4.0.0 id: terminfo-0.4.0.0-c1d02a7210b0d1bc250d87463b38b8d1 license: BSD3 copyright: (c) Judah Jacobson maintainer: Judah Jacobson stability: Stable homepage: https://github.com/judah/terminfo package-url: synopsis: Haskell bindings to the terminfo library. description: This library provides an interface to the terminfo database (via bindings to the curses library). allows POSIX systems to interact with a variety of terminals using a standard set of capabilities. category: User Interfaces author: Judah Jacobson exposed: True exposed-modules: System.Console.Terminfo System.Console.Terminfo.Base System.Console.Terminfo.Cursor System.Console.Terminfo.Color System.Console.Terminfo.Edit System.Console.Terminfo.Effects System.Console.Terminfo.Keys hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/terminfo-0.4.0.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/terminfo-0.4.0.0 hs-libraries: HSterminfo-0.4.0.0 extra-libraries: tinfo extra-ghci-libraries: include-dirs: includes: ncurses.h term.h depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/terminfo-0.4.0.0/terminfo.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/terminfo-0.4.0.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: xhtml version: 3000.2.1 id: xhtml-3000.2.1-6a3ed472b07e58fe29db22a5bc2bdb06 license: BSD3 copyright: Bjorn Bringert 2004-2006, Andy Gill and the Oregon Graduate Institute of Science and Technology, 1999-2001 maintainer: Chris Dornan stability: Stable homepage: https://github.com/haskell/xhtml package-url: synopsis: An XHTML combinator library description: This package provides combinators for producing XHTML 1.0, including the Strict, Transitional and Frameset variants. category: Web, XML, Pretty Printer author: Bjorn Bringert exposed: True exposed-modules: Text.XHtml Text.XHtml.Frameset Text.XHtml.Strict Text.XHtml.Transitional Text.XHtml.Debug Text.XHtml.Table hidden-modules: Text.XHtml.Strict.Attributes Text.XHtml.Strict.Elements Text.XHtml.Frameset.Attributes Text.XHtml.Frameset.Elements Text.XHtml.Transitional.Attributes Text.XHtml.Transitional.Elements Text.XHtml.BlockTable Text.XHtml.Extras Text.XHtml.Internals trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/xhtml-3000.2.1 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/xhtml-3000.2.1 hs-libraries: HSxhtml-3000.2.1 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/xhtml-3000.2.1/xhtml.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/xhtml-3000.2.1 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: transformers version: 0.3.0.0 id: transformers-0.3.0.0-6458c21515cab7c1cf21e53141557a1c license: BSD3 copyright: maintainer: Ross Paterson stability: homepage: package-url: synopsis: Concrete functor and monad transformers description: A portable library of functor and monad transformers, inspired by the paper \"Functional Programming with Overloading and Higher-Order Polymorphism\", by Mark P Jones, in /Advanced School of Functional Programming/, 1995 (). . This package contains: . * the monad transformer class (in "Control.Monad.Trans.Class") . * concrete functor and monad transformers, each with associated operations and functions to lift operations associated with other transformers. . It can be used on its own in portable Haskell code, or with the monad classes in the @mtl@ or @monads-tf@ packages, which automatically lift operations introduced by monad transformers through other transformers. category: Control author: Andy Gill, Ross Paterson exposed: True exposed-modules: Control.Applicative.Backwards Control.Applicative.Lift Control.Monad.IO.Class Control.Monad.Trans.Class Control.Monad.Trans.Cont Control.Monad.Trans.Error Control.Monad.Trans.Identity Control.Monad.Trans.List Control.Monad.Trans.Maybe Control.Monad.Trans.Reader Control.Monad.Trans.RWS Control.Monad.Trans.RWS.Lazy Control.Monad.Trans.RWS.Strict Control.Monad.Trans.State Control.Monad.Trans.State.Lazy Control.Monad.Trans.State.Strict Control.Monad.Trans.Writer Control.Monad.Trans.Writer.Lazy Control.Monad.Trans.Writer.Strict Data.Functor.Compose Data.Functor.Constant Data.Functor.Identity Data.Functor.Product Data.Functor.Reverse hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/transformers-0.3.0.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/transformers-0.3.0.0 hs-libraries: HStransformers-0.3.0.0 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/transformers-0.3.0.0/transformers.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/transformers-0.3.0.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: hoopl version: 3.10.0.1 id: hoopl-3.10.0.1-267659e4b5b51c3d2e02f2a6d6f46936 license: BSD3 copyright: maintainer: nr@cs.tufts.edu stability: homepage: http://ghc.cs.tufts.edu/hoopl/ package-url: synopsis: A library to support dataflow analysis and optimization description: Higher-order optimization library . See /Norman Ramsey, Joao Dias, and Simon Peyton Jones./ /(2010)/ for more details. category: Compilers/Interpreters author: Norman Ramsey, Joao Dias, Simon Marlow and Simon Peyton Jones exposed: True exposed-modules: Compiler.Hoopl Compiler.Hoopl.Internals Compiler.Hoopl.Wrappers Compiler.Hoopl.Passes.Dominator Compiler.Hoopl.Passes.DList hidden-modules: Compiler.Hoopl.Checkpoint Compiler.Hoopl.Collections Compiler.Hoopl.Combinators Compiler.Hoopl.Dataflow Compiler.Hoopl.Debug Compiler.Hoopl.Block Compiler.Hoopl.Graph Compiler.Hoopl.Label Compiler.Hoopl.MkGraph Compiler.Hoopl.Fuel Compiler.Hoopl.Pointed Compiler.Hoopl.Shape Compiler.Hoopl.Show Compiler.Hoopl.Unique Compiler.Hoopl.XUtil trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/hoopl-3.10.0.1 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/hoopl-3.10.0.1 hs-libraries: HShoopl-3.10.0.1 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 containers-0.5.5.1-d4bd887fb97aa3a46cbadc13709b7653 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/hoopl-3.10.0.1/hoopl.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/hoopl-3.10.0.1 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: bin-package-db version: 0.0.0.0 id: bin-package-db-0.0.0.0-0f3da03684207f2dc4dce793df1db62e license: BSD3 copyright: maintainer: ghc-devs@haskell.org stability: homepage: package-url: synopsis: A binary format for the package database description: category: author: exposed: True exposed-modules: Distribution.InstalledPackageInfo.Binary hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/bin-package-db-0.0.0.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/bin-package-db-0.0.0.0 hs-libraries: HSbin-package-db-0.0.0.0 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: Cabal-1.18.1.5-6478013104bde01737bfd67d34bbee0a base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 binary-0.7.1.0-f867dbbb69966feb9f5c4ef7695a70a5 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/bin-package-db-0.0.0.0/bin-package-db.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/bin-package-db-0.0.0.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: binary version: 0.7.1.0 id: binary-0.7.1.0-f867dbbb69966feb9f5c4ef7695a70a5 license: BSD3 copyright: maintainer: Lennart Kolmodin, Don Stewart stability: provisional homepage: https://github.com/kolmodin/binary package-url: synopsis: Binary serialisation for Haskell values using lazy ByteStrings description: Efficient, pure binary serialisation using lazy ByteStrings. Haskell values may be encoded to and from binary formats, written to disk as binary, or sent over the network. The format used can be automatically generated, or you can choose to implement a custom format if needed. Serialisation speeds of over 1 G\/sec have been observed, so this library should be suitable for high performance scenarios. category: Data, Parsing author: Lennart Kolmodin exposed: True exposed-modules: Data.Binary Data.Binary.Put Data.Binary.Get Data.Binary.Get.Internal Data.Binary.Builder Data.Binary.Builder.Internal hidden-modules: Data.Binary.Builder.Base Data.Binary.Class Data.Binary.Generic trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/binary-0.7.1.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/binary-0.7.1.0 hs-libraries: HSbinary-0.7.1.0 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 bytestring-0.10.4.0-d6f1d17d717e8652498cab8269a0acd5 containers-0.5.5.1-d4bd887fb97aa3a46cbadc13709b7653 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/binary-0.7.1.0/binary.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/binary-0.7.1.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: Cabal version: 1.18.1.5 id: Cabal-1.18.1.5-6478013104bde01737bfd67d34bbee0a license: BSD3 copyright: 2003-2006, Isaac Jones 2005-2011, Duncan Coutts maintainer: cabal-devel@haskell.org stability: homepage: http://www.haskell.org/cabal/ package-url: synopsis: A framework for packaging Haskell software description: The Haskell Common Architecture for Building Applications and Libraries: a framework defining a common interface for authors to more easily build their Haskell applications in a portable way. . The Haskell Cabal is part of a larger infrastructure for distributing, organizing, and cataloging Haskell libraries and tools. category: Distribution author: Isaac Jones Duncan Coutts exposed: True exposed-modules: Distribution.Compat.Environment Distribution.Compat.Exception Distribution.Compat.ReadP Distribution.Compiler Distribution.InstalledPackageInfo Distribution.License Distribution.Make Distribution.ModuleName Distribution.Package Distribution.PackageDescription Distribution.PackageDescription.Check Distribution.PackageDescription.Configuration Distribution.PackageDescription.Parse Distribution.PackageDescription.PrettyPrint Distribution.PackageDescription.Utils Distribution.ParseUtils Distribution.ReadE Distribution.Simple Distribution.Simple.Bench Distribution.Simple.Build Distribution.Simple.Build.Macros Distribution.Simple.Build.PathsModule Distribution.Simple.BuildPaths Distribution.Simple.BuildTarget Distribution.Simple.CCompiler Distribution.Simple.Command Distribution.Simple.Compiler Distribution.Simple.Configure Distribution.Simple.GHC Distribution.Simple.Haddock Distribution.Simple.Hpc Distribution.Simple.Hugs Distribution.Simple.Install Distribution.Simple.InstallDirs Distribution.Simple.JHC Distribution.Simple.LHC Distribution.Simple.LocalBuildInfo Distribution.Simple.NHC Distribution.Simple.PackageIndex Distribution.Simple.PreProcess Distribution.Simple.PreProcess.Unlit Distribution.Simple.Program Distribution.Simple.Program.Ar Distribution.Simple.Program.Builtin Distribution.Simple.Program.Db Distribution.Simple.Program.Find Distribution.Simple.Program.GHC Distribution.Simple.Program.HcPkg Distribution.Simple.Program.Hpc Distribution.Simple.Program.Ld Distribution.Simple.Program.Run Distribution.Simple.Program.Script Distribution.Simple.Program.Types Distribution.Simple.Register Distribution.Simple.Setup Distribution.Simple.SrcDist Distribution.Simple.Test Distribution.Simple.UHC Distribution.Simple.UserHooks Distribution.Simple.Utils Distribution.System Distribution.TestSuite Distribution.Text Distribution.Verbosity Distribution.Version Language.Haskell.Extension hidden-modules: Distribution.Compat.CopyFile Distribution.Compat.TempFile Distribution.GetOpt Distribution.Simple.GHC.IPI641 Distribution.Simple.GHC.IPI642 Paths_Cabal trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/Cabal-1.18.1.5 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/Cabal-1.18.1.5 hs-libraries: HSCabal-1.18.1.5 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 bytestring-0.10.4.0-d6f1d17d717e8652498cab8269a0acd5 containers-0.5.5.1-d4bd887fb97aa3a46cbadc13709b7653 deepseq-1.3.0.2-63a1ab91b7017a28bb5d04cb1b5d2d02 directory-1.2.1.0-07cd1f59e3c6cac5e3e180019c59a115 filepath-1.3.0.2-25a474a9272ae6260626ce0d70ad1cab pretty-1.1.1.1-0984f47ffe93ef3983c80b96280f1c3a process-1.2.0.0-06c3215a79834ce4886ae686a0f81122 time-1.4.2-9b3076800c33f8382c38628f35717951 unix-2.7.0.1-f8658ba9ec1c4fba8a371a8e0f42ec6c hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/Cabal-1.18.1.5/Cabal.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/Cabal-1.18.1.5 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: template-haskell version: 2.9.0.0 id: template-haskell-2.9.0.0-6d27c2b362b15abb1822f2f34b9ae7f9 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: Support library for Template Haskell description: This package provides modules containing facilities for manipulating Haskell source code using Template Haskell. . See for more information. category: Template Haskell author: exposed: True exposed-modules: Language.Haskell.TH Language.Haskell.TH.Lib Language.Haskell.TH.Ppr Language.Haskell.TH.PprLib Language.Haskell.TH.Quote Language.Haskell.TH.Syntax hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/template-haskell-2.9.0.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/template-haskell-2.9.0.0 hs-libraries: HStemplate-haskell-2.9.0.0 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 containers-0.5.5.1-d4bd887fb97aa3a46cbadc13709b7653 pretty-1.1.1.1-0984f47ffe93ef3983c80b96280f1c3a hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/template-haskell-2.9.0.0/template-haskell.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/template-haskell-2.9.0.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: pretty version: 1.1.1.1 id: pretty-1.1.1.1-0984f47ffe93ef3983c80b96280f1c3a license: BSD3 copyright: maintainer: David Terei stability: Stable homepage: http://github.com/haskell/pretty package-url: synopsis: Pretty-printing library description: This package contains a pretty-printing library, a set of API's that provides a way to easily print out text in a consistent format of your choosing. This is useful for compilers and related tools. . This library was originally designed by John Hughes's and has since been heavily modified by Simon Peyton Jones. category: Text author: exposed: True exposed-modules: Text.PrettyPrint Text.PrettyPrint.HughesPJ hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/pretty-1.1.1.1 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/pretty-1.1.1.1 hs-libraries: HSpretty-1.1.1.1 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/pretty-1.1.1.1/pretty.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/pretty-1.1.1.1 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: hpc version: 0.6.0.1 id: hpc-0.6.0.1-cca17f12dab542e09c423a74a4590c5d license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: Code Coverage Library for Haskell description: This package provides the code coverage library for Haskell. . See for more information. category: Control author: Andy Gill exposed: True exposed-modules: Trace.Hpc.Util Trace.Hpc.Mix Trace.Hpc.Tix Trace.Hpc.Reflect hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/hpc-0.6.0.1 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/hpc-0.6.0.1 hs-libraries: HShpc-0.6.0.1 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 containers-0.5.5.1-d4bd887fb97aa3a46cbadc13709b7653 directory-1.2.1.0-07cd1f59e3c6cac5e3e180019c59a115 time-1.4.2-9b3076800c33f8382c38628f35717951 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/hpc-0.6.0.1/hpc.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/hpc-0.6.0.1 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: process version: 1.2.0.0 id: process-1.2.0.0-06c3215a79834ce4886ae686a0f81122 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: Process libraries description: This package contains libraries for dealing with system processes. category: System author: exposed: True exposed-modules: System.Cmd System.Process System.Process.Internals hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/process-1.2.0.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/process-1.2.0.0 hs-libraries: HSprocess-1.2.0.0 extra-libraries: extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/process-1.2.0.0/include includes: runProcess.h depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 deepseq-1.3.0.2-63a1ab91b7017a28bb5d04cb1b5d2d02 directory-1.2.1.0-07cd1f59e3c6cac5e3e180019c59a115 filepath-1.3.0.2-25a474a9272ae6260626ce0d70ad1cab unix-2.7.0.1-f8658ba9ec1c4fba8a371a8e0f42ec6c hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/process-1.2.0.0/process.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/process-1.2.0.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: directory version: 1.2.1.0 id: directory-1.2.1.0-07cd1f59e3c6cac5e3e180019c59a115 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: library for directory handling description: This package provides a library for handling directories. category: System author: exposed: True exposed-modules: System.Directory hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/directory-1.2.1.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/directory-1.2.1.0 hs-libraries: HSdirectory-1.2.1.0 extra-libraries: extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/directory-1.2.1.0/include includes: HsDirectory.h depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 filepath-1.3.0.2-25a474a9272ae6260626ce0d70ad1cab time-1.4.2-9b3076800c33f8382c38628f35717951 unix-2.7.0.1-f8658ba9ec1c4fba8a371a8e0f42ec6c hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/directory-1.2.1.0/directory.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/directory-1.2.1.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: unix version: 2.7.0.1 id: unix-2.7.0.1-f8658ba9ec1c4fba8a371a8e0f42ec6c license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: POSIX functionality description: This package gives you access to the set of operating system services standardised by POSIX 1003.1b (or the IEEE Portable Operating System Interface for Computing Environments - IEEE Std. 1003.1). . The package is not supported under Windows (except under Cygwin). category: System author: exposed: True exposed-modules: System.Posix System.Posix.ByteString System.Posix.Error System.Posix.Resource System.Posix.Time System.Posix.Unistd System.Posix.User System.Posix.Signals System.Posix.Signals.Exts System.Posix.Semaphore System.Posix.SharedMem System.Posix.ByteString.FilePath System.Posix.Directory System.Posix.Directory.ByteString System.Posix.DynamicLinker.Module System.Posix.DynamicLinker.Module.ByteString System.Posix.DynamicLinker.Prim System.Posix.DynamicLinker.ByteString System.Posix.DynamicLinker System.Posix.Files System.Posix.Files.ByteString System.Posix.IO System.Posix.IO.ByteString System.Posix.Env System.Posix.Env.ByteString System.Posix.Process System.Posix.Process.Internals System.Posix.Process.ByteString System.Posix.Temp System.Posix.Temp.ByteString System.Posix.Terminal System.Posix.Terminal.ByteString hidden-modules: System.Posix.Directory.Common System.Posix.DynamicLinker.Common System.Posix.Files.Common System.Posix.IO.Common System.Posix.Process.Common System.Posix.Terminal.Common trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/unix-2.7.0.1 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/unix-2.7.0.1 hs-libraries: HSunix-2.7.0.1 extra-libraries: rt util dl pthread extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/unix-2.7.0.1/include includes: HsUnix.h execvpe.h depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 bytestring-0.10.4.0-d6f1d17d717e8652498cab8269a0acd5 time-1.4.2-9b3076800c33f8382c38628f35717951 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/unix-2.7.0.1/unix.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/unix-2.7.0.1 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: time version: 1.4.2 id: time-1.4.2-9b3076800c33f8382c38628f35717951 license: BSD3 copyright: maintainer: stability: stable homepage: http://semantic.org/TimeLib/ package-url: synopsis: A time library description: A time library category: System author: Ashley Yakeley exposed: True exposed-modules: Data.Time.Calendar Data.Time.Calendar.MonthDay Data.Time.Calendar.OrdinalDate Data.Time.Calendar.WeekDate Data.Time.Calendar.Julian Data.Time.Calendar.Easter Data.Time.Clock Data.Time.Clock.POSIX Data.Time.Clock.TAI Data.Time.LocalTime Data.Time.Format Data.Time hidden-modules: Data.Time.Calendar.Private Data.Time.Calendar.Days Data.Time.Calendar.Gregorian Data.Time.Calendar.JulianYearDay Data.Time.Clock.Scale Data.Time.Clock.UTC Data.Time.Clock.CTimeval Data.Time.Clock.UTCDiff Data.Time.LocalTime.TimeZone Data.Time.LocalTime.TimeOfDay Data.Time.LocalTime.LocalTime Data.Time.Format.Parse trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/time-1.4.2 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/time-1.4.2 hs-libraries: HStime-1.4.2 extra-libraries: extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/time-1.4.2/include includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 deepseq-1.3.0.2-63a1ab91b7017a28bb5d04cb1b5d2d02 old-locale-1.0.0.6-50b0125c49f76af85dc7aa22975cdc34 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/time-1.4.2/time.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/time-1.4.2 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: old-locale version: 1.0.0.6 id: old-locale-1.0.0.6-50b0125c49f76af85dc7aa22975cdc34 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: locale library description: This package provides the ability to adapt to locale conventions such as date and time formats. category: System author: exposed: True exposed-modules: System.Locale hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/old-locale-1.0.0.6 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/old-locale-1.0.0.6 hs-libraries: HSold-locale-1.0.0.6 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/old-locale-1.0.0.6/old-locale.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/old-locale-1.0.0.6 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: containers version: 0.5.5.1 id: containers-0.5.5.1-d4bd887fb97aa3a46cbadc13709b7653 license: BSD3 copyright: maintainer: fox@ucw.cz stability: homepage: package-url: synopsis: Assorted concrete container types description: This package contains efficient general-purpose implementations of various basic immutable container types. The declared cost of each operation is either worst-case or amortized, but remains valid even if structures are shared. category: Data Structures author: exposed: True exposed-modules: Data.IntMap Data.IntMap.Lazy Data.IntMap.Strict Data.IntSet Data.Map Data.Map.Lazy Data.Map.Strict Data.Set Data.Graph Data.Sequence Data.Tree hidden-modules: Data.BitUtil Data.IntMap.Base Data.IntSet.Base Data.Map.Base Data.Set.Base Data.StrictPair trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/containers-0.5.5.1 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/containers-0.5.5.1 hs-libraries: HScontainers-0.5.5.1 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 deepseq-1.3.0.2-63a1ab91b7017a28bb5d04cb1b5d2d02 ghc-prim-0.3.1.0-a24f9c14c632d75b683d0f93283aea37 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/containers-0.5.5.1/containers.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/containers-0.5.5.1 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: bytestring version: 0.10.4.0 id: bytestring-0.10.4.0-d6f1d17d717e8652498cab8269a0acd5 license: BSD3 copyright: Copyright (c) Don Stewart 2005-2009, (c) Duncan Coutts 2006-2013, (c) David Roundy 2003-2005, (c) Jasper Van der Jeugt 2010, (c) Simon Meier 2010-2013. maintainer: Don Stewart , Duncan Coutts stability: homepage: https://github.com/haskell/bytestring package-url: synopsis: Fast, compact, strict and lazy byte strings with a list interface description: An efficient compact, immutable byte string type (both strict and lazy) suitable for binary or 8-bit character data. . The 'ByteString' type represents sequences of bytes or 8-bit characters. It is suitable for high performance use, both in terms of large data quantities, or high speed requirements. The 'ByteString' functions follow the same style as Haskell\'s ordinary lists, so it is easy to convert code from using 'String' to 'ByteString'. . Two 'ByteString' variants are provided: . * Strict 'ByteString's keep the string as a single large array. This makes them convenient for passing data between C and Haskell. . * Lazy 'ByteString's use a lazy list of strict chunks which makes it suitable for I\/O streaming tasks. . The @Char8@ modules provide a character-based view of the same underlying 'ByteString' types. This makes it convenient to handle mixed binary and 8-bit character content (which is common in many file formats and network protocols). . The 'Builder' module provides an efficient way to build up 'ByteString's in an ad-hoc way by repeated concatenation. This is ideal for fast serialisation or pretty printing. . There is also a 'ShortByteString' type which has a lower memory overhead and can be converted to or from a 'ByteString', but supports very few other operations. It is suitable for keeping many short strings in memory. . 'ByteString's are not designed for Unicode. For Unicode strings you should use the 'Text' type from the @text@ package. . These modules are intended to be imported qualified, to avoid name clashes with "Prelude" functions, e.g. . > import qualified Data.ByteString as BS category: Data author: Don Stewart, Duncan Coutts exposed: True exposed-modules: Data.ByteString Data.ByteString.Char8 Data.ByteString.Unsafe Data.ByteString.Internal Data.ByteString.Lazy Data.ByteString.Lazy.Char8 Data.ByteString.Lazy.Internal Data.ByteString.Short Data.ByteString.Short.Internal Data.ByteString.Builder Data.ByteString.Builder.Extra Data.ByteString.Builder.Prim Data.ByteString.Builder.Internal Data.ByteString.Builder.Prim.Internal Data.ByteString.Lazy.Builder Data.ByteString.Lazy.Builder.Extras Data.ByteString.Lazy.Builder.ASCII hidden-modules: Data.ByteString.Builder.ASCII Data.ByteString.Builder.Prim.Binary Data.ByteString.Builder.Prim.ASCII Data.ByteString.Builder.Prim.Internal.Floating Data.ByteString.Builder.Prim.Internal.UncheckedShifts Data.ByteString.Builder.Prim.Internal.Base16 trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/bytestring-0.10.4.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/bytestring-0.10.4.0 hs-libraries: HSbytestring-0.10.4.0 extra-libraries: extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/bytestring-0.10.4.0/include includes: fpstring.h depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 deepseq-1.3.0.2-63a1ab91b7017a28bb5d04cb1b5d2d02 ghc-prim-0.3.1.0-a24f9c14c632d75b683d0f93283aea37 integer-gmp-0.5.1.0-26579559b3647acf4f01d5edd9491a46 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/bytestring-0.10.4.0/bytestring.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/bytestring-0.10.4.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: deepseq version: 1.3.0.2 id: deepseq-1.3.0.2-63a1ab91b7017a28bb5d04cb1b5d2d02 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: Deep evaluation of data structures description: This package provides methods for fully evaluating data structures (\"deep evaluation\"). Deep evaluation is often used for adding strictness to a program, e.g. in order to force pending exceptions, remove space leaks, or force lazy I/O to happen. It is also useful in parallel programs, to ensure pending work does not migrate to the wrong thread. . The primary use of this package is via the 'deepseq' function, a \"deep\" version of 'seq'. It is implemented on top of an 'NFData' typeclass (\"Normal Form Data\", data structures with no unevaluated components) which defines strategies for fully evaluating different data types. . If you want to automatically derive 'NFData' instances via the "GHC.Generics" facility, there is a companion package which builds on top of this package. category: Control author: exposed: True exposed-modules: Control.DeepSeq hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/deepseq-1.3.0.2 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/deepseq-1.3.0.2 hs-libraries: HSdeepseq-1.3.0.2 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/deepseq-1.3.0.2/deepseq.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/deepseq-1.3.0.2 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: array version: 0.5.0.0 id: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: Mutable and immutable arrays description: In addition to providing the "Data.Array" module , this package also defines the classes 'IArray' of immutable arrays and 'MArray' of arrays mutable within appropriate monads, as well as some instances of these classes. category: Data Structures author: exposed: True exposed-modules: Data.Array Data.Array.Base Data.Array.IArray Data.Array.IO Data.Array.IO.Safe Data.Array.IO.Internals Data.Array.MArray Data.Array.MArray.Safe Data.Array.ST Data.Array.ST.Safe Data.Array.Storable Data.Array.Storable.Safe Data.Array.Storable.Internals Data.Array.Unboxed Data.Array.Unsafe hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/array-0.5.0.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/array-0.5.0.0 hs-libraries: HSarray-0.5.0.0 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/array-0.5.0.0/array.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/array-0.5.0.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: filepath version: 1.3.0.2 id: filepath-1.3.0.2-25a474a9272ae6260626ce0d70ad1cab license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: http://www-users.cs.york.ac.uk/~ndm/filepath/ package-url: synopsis: Library for manipulating FilePaths in a cross platform way. description: A library for 'FilePath' manipulations, using Posix or Windows filepaths depending on the platform. . Both "System.FilePath.Posix" and "System.FilePath.Windows" provide the same interface. See either for examples and a list of the available functions. category: System author: Neil Mitchell exposed: True exposed-modules: System.FilePath System.FilePath.Posix System.FilePath.Windows hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/filepath-1.3.0.2 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/filepath-1.3.0.2 hs-libraries: HSfilepath-1.3.0.2 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/filepath-1.3.0.2/filepath.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/filepath-1.3.0.2 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: base version: 4.7.0.2 id: base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: Basic libraries description: This package contains the "Prelude" and its support libraries, and a large collection of useful libraries ranging from data structures to parsing combinators and debugging utilities. category: Prelude author: exposed: True exposed-modules: Control.Applicative Control.Arrow Control.Category Control.Concurrent Control.Concurrent.Chan Control.Concurrent.MVar Control.Concurrent.QSem Control.Concurrent.QSemN Control.Exception Control.Exception.Base Control.Monad Control.Monad.Fix Control.Monad.Instances Control.Monad.ST Control.Monad.ST.Lazy Control.Monad.ST.Lazy.Safe Control.Monad.ST.Lazy.Unsafe Control.Monad.ST.Safe Control.Monad.ST.Strict Control.Monad.ST.Unsafe Control.Monad.Zip Data.Bits Data.Bool Data.Char Data.Coerce Data.Complex Data.Data Data.Dynamic Data.Either Data.Eq Data.Fixed Data.Foldable Data.Function Data.Functor Data.IORef Data.Int Data.Ix Data.List Data.Maybe Data.Monoid Data.OldTypeable Data.OldTypeable.Internal Data.Ord Data.Proxy Data.Ratio Data.STRef Data.STRef.Lazy Data.STRef.Strict Data.String Data.Traversable Data.Tuple Data.Type.Bool Data.Type.Coercion Data.Type.Equality Data.Typeable Data.Typeable.Internal Data.Unique Data.Version Data.Word Debug.Trace Foreign Foreign.C Foreign.C.Error Foreign.C.String Foreign.C.Types Foreign.Concurrent Foreign.ForeignPtr Foreign.ForeignPtr.Safe Foreign.ForeignPtr.Unsafe Foreign.Marshal Foreign.Marshal.Alloc Foreign.Marshal.Array Foreign.Marshal.Error Foreign.Marshal.Pool Foreign.Marshal.Safe Foreign.Marshal.Unsafe Foreign.Marshal.Utils Foreign.Ptr Foreign.Safe Foreign.StablePtr Foreign.Storable GHC.Arr GHC.Base GHC.Char GHC.Conc GHC.Conc.IO GHC.Conc.Signal GHC.Conc.Sync GHC.ConsoleHandler GHC.Constants GHC.Desugar GHC.Enum GHC.Environment GHC.Err GHC.Exception GHC.Exts GHC.Fingerprint GHC.Fingerprint.Type GHC.Float GHC.Float.ConversionUtils GHC.Float.RealFracMethods GHC.Foreign GHC.ForeignPtr GHC.GHCi GHC.Generics GHC.IO GHC.IO.Buffer GHC.IO.BufferedIO GHC.IO.Device GHC.IO.Encoding GHC.IO.Encoding.CodePage GHC.IO.Encoding.Failure GHC.IO.Encoding.Iconv GHC.IO.Encoding.Latin1 GHC.IO.Encoding.Types GHC.IO.Encoding.UTF16 GHC.IO.Encoding.UTF32 GHC.IO.Encoding.UTF8 GHC.IO.Exception GHC.IO.FD GHC.IO.Handle GHC.IO.Handle.FD GHC.IO.Handle.Internals GHC.IO.Handle.Text GHC.IO.Handle.Types GHC.IO.IOMode GHC.IOArray GHC.IORef GHC.IP GHC.Int GHC.List GHC.MVar GHC.Num GHC.PArr GHC.Pack GHC.Profiling GHC.Ptr GHC.Read GHC.Real GHC.ST GHC.STRef GHC.Show GHC.Stable GHC.Stack GHC.Stats GHC.Storable GHC.TopHandler GHC.TypeLits GHC.Unicode GHC.Weak GHC.Word Numeric Prelude System.CPUTime System.Console.GetOpt System.Environment System.Exit System.IO System.IO.Error System.IO.Unsafe System.Info System.Mem System.Mem.StableName System.Mem.Weak System.Posix.Internals System.Posix.Types System.Timeout Text.ParserCombinators.ReadP Text.ParserCombinators.ReadPrec Text.Printf Text.Read Text.Read.Lex Text.Show Text.Show.Functions Unsafe.Coerce GHC.Event hidden-modules: Control.Monad.ST.Imp Control.Monad.ST.Lazy.Imp Foreign.ForeignPtr.Imp System.Environment.ExecutablePath GHC.Event.Arr GHC.Event.Array GHC.Event.Clock GHC.Event.Control GHC.Event.EPoll GHC.Event.IntTable GHC.Event.Internal GHC.Event.KQueue GHC.Event.Manager GHC.Event.PSQ GHC.Event.Poll GHC.Event.Thread GHC.Event.TimerManager GHC.Event.Unique trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/base-4.7.0.2 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/base-4.7.0.2 hs-libraries: HSbase-4.7.0.2 extra-libraries: extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/base-4.7.0.2/include includes: HsBase.h depends: ghc-prim-0.3.1.0-a24f9c14c632d75b683d0f93283aea37 integer-gmp-0.5.1.0-26579559b3647acf4f01d5edd9491a46 builtin_rts hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/base-4.7.0.2/base.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/base-4.7.0.2 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: integer-gmp version: 0.5.1.0 id: integer-gmp-0.5.1.0-26579559b3647acf4f01d5edd9491a46 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: Integer library based on GMP description: This package provides the low-level implementation of the standard 'Integer' type based on the . . This package provides access to the internal representation of 'Integer' as well as primitive operations with no proper error handling, and should only be used directly with the utmost care. . For more details about the design of @integer-gmp@, see . category: Numerical author: exposed: True exposed-modules: GHC.Integer GHC.Integer.GMP.Internals GHC.Integer.GMP.Prim GHC.Integer.Logarithms GHC.Integer.Logarithms.Internals hidden-modules: GHC.Integer.Type trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/integer-gmp-0.5.1.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/integer-gmp-0.5.1.0 hs-libraries: HSinteger-gmp-0.5.1.0 extra-libraries: gmp extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/integer-gmp-0.5.1.0/include includes: depends: ghc-prim-0.3.1.0-a24f9c14c632d75b683d0f93283aea37 hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/integer-gmp-0.5.1.0/integer-gmp.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/integer-gmp-0.5.1.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: ghc-prim version: 0.3.1.0 id: ghc-prim-0.3.1.0-a24f9c14c632d75b683d0f93283aea37 license: BSD3 copyright: maintainer: libraries@haskell.org stability: homepage: package-url: synopsis: GHC primitives description: GHC primitives. category: GHC author: exposed: True exposed-modules: GHC.CString GHC.Classes GHC.Debug GHC.IntWord64 GHC.Magic GHC.PrimopWrappers GHC.Tuple GHC.Types GHC.Prim hidden-modules: trusted: False import-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/ghc-prim-0.3.1.0 library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/ghc-prim-0.3.1.0 hs-libraries: HSghc-prim-0.3.1.0 extra-libraries: extra-ghci-libraries: include-dirs: includes: depends: builtin_rts hugs-options: cc-options: ld-options: framework-dirs: frameworks: haddock-interfaces: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/ghc-prim-0.3.1.0/ghc-prim.haddock haddock-html: /opt/ghc/7.8.4/share/doc/ghc/html/libraries/ghc-prim-0.3.1.0 pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" --- name: rts version: 1.0 id: builtin_rts license: BSD3 copyright: maintainer: glasgow-haskell-users@haskell.org stability: homepage: package-url: synopsis: description: category: author: exposed: True exposed-modules: hidden-modules: trusted: False import-dirs: library-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/rts-1.0 hs-libraries: HSrts Cffi extra-libraries: m rt dl extra-ghci-libraries: include-dirs: /opt/ghc/7.8.4/lib/ghc-7.8.4/include includes: Stg.h depends: hugs-options: cc-options: ld-options: "-Wl,-u,ghczmprim_GHCziTypes_Izh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Czh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Fzh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Dzh_static_info" "-Wl,-u,base_GHCziPtr_Ptr_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Wzh_static_info" "-Wl,-u,base_GHCziInt_I8zh_static_info" "-Wl,-u,base_GHCziInt_I16zh_static_info" "-Wl,-u,base_GHCziInt_I32zh_static_info" "-Wl,-u,base_GHCziInt_I64zh_static_info" "-Wl,-u,base_GHCziWord_W8zh_static_info" "-Wl,-u,base_GHCziWord_W16zh_static_info" "-Wl,-u,base_GHCziWord_W32zh_static_info" "-Wl,-u,base_GHCziWord_W64zh_static_info" "-Wl,-u,base_GHCziStable_StablePtr_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Izh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Czh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Fzh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Dzh_con_info" "-Wl,-u,base_GHCziPtr_Ptr_con_info" "-Wl,-u,base_GHCziPtr_FunPtr_con_info" "-Wl,-u,base_GHCziStable_StablePtr_con_info" "-Wl,-u,ghczmprim_GHCziTypes_False_closure" "-Wl,-u,ghczmprim_GHCziTypes_True_closure" "-Wl,-u,base_GHCziPack_unpackCString_closure" "-Wl,-u,base_GHCziIOziException_stackOverflow_closure" "-Wl,-u,base_GHCziIOziException_heapOverflow_closure" "-Wl,-u,base_ControlziExceptionziBase_nonTermination_closure" "-Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnMVar_closure" "-Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnSTM_closure" "-Wl,-u,base_ControlziExceptionziBase_nestedAtomically_closure" "-Wl,-u,base_GHCziWeak_runFinalizzerBatch_closure" "-Wl,-u,base_GHCziTopHandler_flushStdHandles_closure" "-Wl,-u,base_GHCziTopHandler_runIO_closure" "-Wl,-u,base_GHCziTopHandler_runNonIO_closure" "-Wl,-u,base_GHCziConcziIO_ensureIOManagerIsRunning_closure" "-Wl,-u,base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure" "-Wl,-u,base_GHCziConcziSync_runSparks_closure" "-Wl,-u,base_GHCziConcziSignal_runHandlersPtr_closure" framework-dirs: frameworks: haddock-interfaces: haddock-html: pkgroot: "/opt/ghc/7.8.4/lib/ghc-7.8.4" stack-2.9.3.1/test/package-dump/ghc-head.txt0000644000000000000000000015056114353310352016704 0ustar0000000000000000name: ghc-boot version: 0.0.0.0 id: ghc-boot-0.0.0.0 key: ghc-boot-0.0.0.0 license: BSD3 maintainer: ghc-devs@haskell.org synopsis: Shared functionality between GHC and its boot libraries description: This library is shared between GHC, ghc-pkg, and other boot libraries. . A note about "GHC.PackageDb": it only deals with the subset of the package database that the compiler cares about: modules paths etc and not package metadata like description, authors etc. It is thus not a library interface to ghc-pkg and is *not* suitable for modifying GHC package databases. . The package database format and this library are constructed in such a way that while ghc-pkg depends on Cabal, the GHC library and program do not have to depend on Cabal. exposed: True exposed-modules: GHC.Lexeme GHC.PackageDb abi: 7a24014b606b3e9dd8b7b8aa4cf35acc trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/ghc-boot-0.0.0.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/ghc-boot-0.0.0.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/ghc-boot-0.0.0.0 hs-libraries: HSghc-boot-0.0.0.0 depends: base-4.9.0.0 binary-0.7.5.0 bytestring-0.10.7.0 directory-1.2.5.0 filepath-1.4.1.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/ghc-boot-0.0.0.0/ghc-boot.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/ghc-boot-0.0.0.0 --- name: ghc version: 7.11.20151213 id: ghc-7.11.20151213 key: ghc-7.11.20151213 license: BSD3 maintainer: glasgow-haskell-users@haskell.org homepage: http://www.haskell.org/ghc/ synopsis: The GHC API description: GHC's functionality can be useful for more things than just compiling Haskell programs. Important use cases are programs that analyse (and perhaps transform) Haskell code. Others include loading Haskell code dynamically in a GHCi-like manner. For this reason, a lot of GHC's functionality is made available through this package. category: Development author: The GHC Team exposed: False exposed-modules: Avail BasicTypes ConLike DataCon PatSyn Demand Debug Exception FieldLabel GhcMonad Hooks Id IdInfo Lexeme Literal Llvm Llvm.AbsSyn Llvm.MetaData Llvm.PpLlvm Llvm.Types LlvmCodeGen LlvmCodeGen.Base LlvmCodeGen.CodeGen LlvmCodeGen.Data LlvmCodeGen.Ppr LlvmCodeGen.Regs LlvmMangler MkId Module Name NameEnv NameSet OccName RdrName SrcLoc UniqSupply Unique Var VarEnv VarSet UnVarGraph BlockId CLabel Cmm CmmBuildInfoTables CmmPipeline CmmCallConv CmmCommonBlockElim CmmImplementSwitchPlans CmmContFlowOpt CmmExpr CmmInfo CmmLex CmmLint CmmLive CmmMachOp CmmSwitch CmmNode CmmOpt CmmParse CmmProcPoint CmmSink CmmType CmmUtils CmmLayoutStack MkGraph PprBase PprC PprCmm PprCmmDecl PprCmmExpr Bitmap CodeGen.Platform CodeGen.Platform.ARM CodeGen.Platform.ARM64 CodeGen.Platform.NoRegs CodeGen.Platform.PPC CodeGen.Platform.PPC_Darwin CodeGen.Platform.SPARC CodeGen.Platform.X86 CodeGen.Platform.X86_64 CgUtils StgCmm StgCmmBind StgCmmClosure StgCmmCon StgCmmEnv StgCmmExpr StgCmmForeign StgCmmHeap StgCmmHpc StgCmmArgRep StgCmmLayout StgCmmMonad StgCmmPrim StgCmmProf StgCmmTicky StgCmmUtils StgCmmExtCode SMRep CoreArity CoreFVs CoreLint CorePrep CoreSubst CoreSyn TrieMap CoreTidy CoreUnfold CoreUtils CoreSeq CoreStats MkCore PprCore PmExpr TmOracle Check Coverage Desugar DsArrows DsBinds DsCCall DsExpr DsForeign DsGRHSs DsListComp DsMonad DsUtils Match MatchCon MatchLit HsBinds HsDecls HsDoc HsExpr HsImpExp HsLit PlaceHolder HsPat HsSyn HsTypes HsUtils BinIface BuildTyCl IfaceEnv IfaceSyn IfaceType LoadIface MkIface TcIface FlagChecker Annotations BreakArray CmdLineParser CodeOutput Config Constants DriverMkDepend DriverPhases PipelineMonad DriverPipeline DynFlags ErrUtils Finder GHC GhcMake GhcPlugins DynamicLoading HeaderInfo HscMain HscStats HscTypes InteractiveEval InteractiveEvalTypes PackageConfig Packages PlatformConstants Plugins TcPluginM PprTyThing StaticFlags StaticPtrTable SysTools Elf TidyPgm Ctype HaddockUtils Lexer OptCoercion Parser RdrHsSyn ApiAnnotation ForeignCall PrelInfo PrelNames PrelRules PrimOp TysPrim TysWiredIn CostCentre ProfInit SCCfinal RnBinds RnEnv RnExpr RnHsDoc RnNames RnPat RnSource RnSplice RnTypes CoreMonad CSE FloatIn FloatOut LiberateCase OccurAnal SAT SetLevels SimplCore SimplEnv SimplMonad SimplUtils Simplify SimplStg StgStats UnariseStg Rules SpecConstr Specialise CoreToStg StgLint StgSyn CallArity DmdAnal WorkWrap WwLib FamInst Inst TcAnnotations TcArrows TcBinds TcClassDcl TcDefaults TcDeriv TcEnv TcExpr TcForeign TcGenDeriv TcGenGenerics TcHsSyn TcHsType TcInstDcls TcMType TcValidity TcMatches TcPat TcPatSyn TcRnDriver TcRnMonad TcRnTypes TcRules TcSimplify TcErrors TcTyClsDecls TcTyDecls TcTypeable TcType TcEvidence TcUnify TcInteract TcCanonical TcFlatten TcSMonad TcTypeNats TcSplice Class Coercion DsMeta THNames FamInstEnv FunDeps InstEnv TyCon CoAxiom Kind Type TyCoRep Unify Bag Binary BooleanFormula BufWrite Digraph Encoding FastFunctions FastMutInt FastString FastStringEnv Fingerprint FiniteMap FV GraphBase GraphColor GraphOps GraphPpr IOEnv ListSetOps Maybes MonadUtils OrdList Outputable Pair Panic Pretty Serialized State Stream StringBuffer UniqDFM UniqDSet UniqFM UniqSet Util Vectorise.Builtins.Base Vectorise.Builtins.Initialise Vectorise.Builtins Vectorise.Monad.Base Vectorise.Monad.Naming Vectorise.Monad.Local Vectorise.Monad.Global Vectorise.Monad.InstEnv Vectorise.Monad Vectorise.Utils.Base Vectorise.Utils.Closure Vectorise.Utils.Hoisting Vectorise.Utils.PADict Vectorise.Utils.Poly Vectorise.Utils Vectorise.Generic.Description Vectorise.Generic.PAMethods Vectorise.Generic.PADict Vectorise.Generic.PData Vectorise.Type.Env Vectorise.Type.Type Vectorise.Type.TyConDecl Vectorise.Type.Classify Vectorise.Convert Vectorise.Vect Vectorise.Var Vectorise.Env Vectorise.Exp Vectorise Hoopl.Dataflow Hoopl AsmCodeGen TargetReg NCGMonad Instruction Format Reg RegClass PIC Platform CPrim X86.Regs X86.RegInfo X86.Instr X86.Cond X86.Ppr X86.CodeGen PPC.Regs PPC.RegInfo PPC.Instr PPC.Cond PPC.Ppr PPC.CodeGen SPARC.Base SPARC.Regs SPARC.Imm SPARC.AddrMode SPARC.Cond SPARC.Instr SPARC.Stack SPARC.ShortcutJump SPARC.Ppr SPARC.CodeGen SPARC.CodeGen.Amode SPARC.CodeGen.Base SPARC.CodeGen.CondCode SPARC.CodeGen.Gen32 SPARC.CodeGen.Gen64 SPARC.CodeGen.Sanity SPARC.CodeGen.Expand RegAlloc.Liveness RegAlloc.Graph.Main RegAlloc.Graph.Stats RegAlloc.Graph.ArchBase RegAlloc.Graph.ArchX86 RegAlloc.Graph.Coalesce RegAlloc.Graph.Spill RegAlloc.Graph.SpillClean RegAlloc.Graph.SpillCost RegAlloc.Graph.TrivColorable RegAlloc.Linear.Main RegAlloc.Linear.JoinToTargets RegAlloc.Linear.State RegAlloc.Linear.Stats RegAlloc.Linear.FreeRegs RegAlloc.Linear.StackMap RegAlloc.Linear.Base RegAlloc.Linear.X86.FreeRegs RegAlloc.Linear.X86_64.FreeRegs RegAlloc.Linear.PPC.FreeRegs RegAlloc.Linear.SPARC.FreeRegs Dwarf Dwarf.Types Dwarf.Constants Convert ByteCodeAsm ByteCodeGen ByteCodeInstr ByteCodeItbls ByteCodeLink Debugger LibFFI Linker ObjLink RtClosureInspect DebuggerUtils abi: bc2e1cb7cdee2089e52f007db59a253c trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/ghc-7.11.20151213 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/ghc-7.11.20151213 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/ghc-7.11.20151213 hs-libraries: HSghc-7.11.20151213 include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/ghc-7.11.20151213/include depends: array-0.5.1.0 base-4.9.0.0 binary-0.7.5.0 bytestring-0.10.7.0 containers-0.5.6.3 directory-1.2.5.0 filepath-1.4.1.0 ghc-boot-0.0.0.0 hoopl-3.10.2.0 hpc-0.6.0.2 process-1.4.1.0 template-haskell-2.11.0.0 time-1.5.0.1 transformers-0.4.3.0 unix-2.7.1.1 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/ghc-7.11.20151213/ghc.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/ghc-7.11.20151213 --- name: haskeline version: 0.7.2.1 id: haskeline-0.7.2.1 key: haskeline-0.7.2.1 license: BSD3 copyright: (c) Judah Jacobson maintainer: Judah Jacobson stability: Experimental homepage: http://trac.haskell.org/haskeline synopsis: A command-line interface for user input, written in Haskell. description: Haskeline provides a user interface for line input in command-line programs. This library is similar in purpose to readline, but since it is written in Haskell it is (hopefully) more easily used in other Haskell programs. . Haskeline runs both on POSIX-compatible systems and on Windows. category: User Interfaces author: Judah Jacobson exposed: True exposed-modules: System.Console.Haskeline System.Console.Haskeline.Completion System.Console.Haskeline.MonadException System.Console.Haskeline.History System.Console.Haskeline.IO hidden-modules: System.Console.Haskeline.Backend System.Console.Haskeline.Backend.WCWidth System.Console.Haskeline.Command System.Console.Haskeline.Command.Completion System.Console.Haskeline.Command.History System.Console.Haskeline.Command.KillRing System.Console.Haskeline.Directory System.Console.Haskeline.Emacs System.Console.Haskeline.InputT System.Console.Haskeline.Key System.Console.Haskeline.LineState System.Console.Haskeline.Monads System.Console.Haskeline.Prefs System.Console.Haskeline.RunCommand System.Console.Haskeline.Term System.Console.Haskeline.Command.Undo System.Console.Haskeline.Vi System.Console.Haskeline.Recover System.Console.Haskeline.Backend.Posix System.Console.Haskeline.Backend.Posix.Encoder System.Console.Haskeline.Backend.DumbTerm System.Console.Haskeline.Backend.Terminfo abi: 1084385e878ca046b1ba1b0149406b60 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/haskeline-0.7.2.1 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/haskeline-0.7.2.1 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/haskeline-0.7.2.1 hs-libraries: HShaskeline-0.7.2.1 depends: base-4.9.0.0 bytestring-0.10.7.0 containers-0.5.6.3 directory-1.2.5.0 filepath-1.4.1.0 terminfo-0.4.0.1 transformers-0.4.3.0 unix-2.7.1.1 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/haskeline-0.7.2.1/haskeline.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/haskeline-0.7.2.1 --- name: terminfo version: 0.4.0.1 id: terminfo-0.4.0.1 key: terminfo-0.4.0.1 license: BSD3 copyright: (c) Judah Jacobson maintainer: Judah Jacobson stability: Stable homepage: https://github.com/judah/terminfo synopsis: Haskell bindings to the terminfo library. description: This library provides an interface to the terminfo database (via bindings to the curses library). allows POSIX systems to interact with a variety of terminals using a standard set of capabilities. category: User Interfaces author: Judah Jacobson exposed: True exposed-modules: System.Console.Terminfo System.Console.Terminfo.Base System.Console.Terminfo.Cursor System.Console.Terminfo.Color System.Console.Terminfo.Edit System.Console.Terminfo.Effects System.Console.Terminfo.Keys abi: d0bd235d4bbae7f2cbb36b97e6bcfba9 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/terminfo-0.4.0.1 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/terminfo-0.4.0.1 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/terminfo-0.4.0.1 hs-libraries: HSterminfo-0.4.0.1 extra-libraries: tinfo includes: ncurses.h term.h depends: base-4.9.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/terminfo-0.4.0.1/terminfo.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/terminfo-0.4.0.1 --- name: xhtml version: 3000.2.1 id: xhtml-3000.2.1 key: xhtml-3000.2.1 license: BSD3 copyright: Bjorn Bringert 2004-2006, Andy Gill and the Oregon Graduate Institute of Science and Technology, 1999-2001 maintainer: Chris Dornan stability: Stable homepage: https://github.com/haskell/xhtml synopsis: An XHTML combinator library description: This package provides combinators for producing XHTML 1.0, including the Strict, Transitional and Frameset variants. category: Web, XML, Pretty Printer author: Bjorn Bringert exposed: True exposed-modules: Text.XHtml Text.XHtml.Frameset Text.XHtml.Strict Text.XHtml.Transitional Text.XHtml.Debug Text.XHtml.Table hidden-modules: Text.XHtml.Strict.Attributes Text.XHtml.Strict.Elements Text.XHtml.Frameset.Attributes Text.XHtml.Frameset.Elements Text.XHtml.Transitional.Attributes Text.XHtml.Transitional.Elements Text.XHtml.BlockTable Text.XHtml.Extras Text.XHtml.Internals abi: 932c4b6847d698115f4ad73b10e56807 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/xhtml-3000.2.1 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/xhtml-3000.2.1 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/xhtml-3000.2.1 hs-libraries: HSxhtml-3000.2.1 depends: base-4.9.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/xhtml-3000.2.1/xhtml.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/xhtml-3000.2.1 --- name: transformers version: 0.4.3.0 id: transformers-0.4.3.0 key: transformers-0.4.3.0 license: BSD3 maintainer: Ross Paterson synopsis: Concrete functor and monad transformers description: A portable library of functor and monad transformers, inspired by the paper \"Functional Programming with Overloading and Higher-Order Polymorphism\", by Mark P Jones, in /Advanced School of Functional Programming/, 1995 (). . This package contains: . * the monad transformer class (in "Control.Monad.Trans.Class") and IO monad class (in "Control.Monad.IO.Class") . * concrete functor and monad transformers, each with associated operations and functions to lift operations associated with other transformers. . The package can be used on its own in portable Haskell code, in which case operations need to be manually lifted through transformer stacks (see "Control.Monad.Trans.Class" for some examples). Alternatively, it can be used with the non-portable monad classes in the @mtl@ or @monads-tf@ packages, which automatically lift operations introduced by monad transformers through other transformers. category: Control author: Andy Gill, Ross Paterson exposed: True exposed-modules: Control.Applicative.Backwards Control.Applicative.Lift Control.Monad.Signatures Control.Monad.Trans.Class Control.Monad.Trans.Cont Control.Monad.Trans.Except Control.Monad.Trans.Error Control.Monad.Trans.Identity Control.Monad.Trans.List Control.Monad.Trans.Maybe Control.Monad.Trans.Reader Control.Monad.Trans.RWS Control.Monad.Trans.RWS.Lazy Control.Monad.Trans.RWS.Strict Control.Monad.Trans.State Control.Monad.Trans.State.Lazy Control.Monad.Trans.State.Strict Control.Monad.Trans.Writer Control.Monad.Trans.Writer.Lazy Control.Monad.Trans.Writer.Strict Data.Functor.Classes Data.Functor.Compose Data.Functor.Constant Data.Functor.Product Data.Functor.Reverse Data.Functor.Sum abi: d71166f18d2591685ff3ee72b17638c0 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/transformers-0.4.3.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/transformers-0.4.3.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/transformers-0.4.3.0 hs-libraries: HStransformers-0.4.3.0 depends: base-4.9.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/transformers-0.4.3.0/transformers.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/transformers-0.4.3.0 --- name: hoopl version: 3.10.2.0 id: hoopl-3.10.2.0 key: hoopl-3.10.2.0 license: BSD3 maintainer: nr@cs.tufts.edu, andreas.voellmy@gmail.com, email@ningwang.org homepage: http://ghc.cs.tufts.edu/hoopl/ synopsis: A library to support dataflow analysis and optimization description: Higher-order optimization library . See /Norman Ramsey, Joao Dias, and Simon Peyton Jones./ /(2010)/ for more details. category: Compilers/Interpreters author: Norman Ramsey, Joao Dias, Simon Marlow and Simon Peyton Jones exposed: True exposed-modules: Compiler.Hoopl Compiler.Hoopl.Internals Compiler.Hoopl.Wrappers Compiler.Hoopl.Passes.Dominator Compiler.Hoopl.Passes.DList hidden-modules: Compiler.Hoopl.Checkpoint Compiler.Hoopl.Collections Compiler.Hoopl.Combinators Compiler.Hoopl.Dataflow Compiler.Hoopl.Debug Compiler.Hoopl.Block Compiler.Hoopl.Graph Compiler.Hoopl.Label Compiler.Hoopl.MkGraph Compiler.Hoopl.Fuel Compiler.Hoopl.Pointed Compiler.Hoopl.Shape Compiler.Hoopl.Show Compiler.Hoopl.Unique Compiler.Hoopl.XUtil abi: 719b00050240e530b78b62520193b342 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/hoopl-3.10.2.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/hoopl-3.10.2.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/hoopl-3.10.2.0 hs-libraries: HShoopl-3.10.2.0 depends: base-4.9.0.0 containers-0.5.6.3 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/hoopl-3.10.2.0/hoopl.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/hoopl-3.10.2.0 --- name: template-haskell version: 2.11.0.0 id: template-haskell-2.11.0.0 key: template-haskell-2.11.0.0 license: BSD3 maintainer: libraries@haskell.org synopsis: Support library for Template Haskell description: This package provides modules containing facilities for manipulating Haskell source code using Template Haskell. . See for more information. category: Template Haskell exposed: True exposed-modules: Language.Haskell.TH Language.Haskell.TH.Lib Language.Haskell.TH.Ppr Language.Haskell.TH.PprLib Language.Haskell.TH.Quote Language.Haskell.TH.Syntax hidden-modules: Language.Haskell.TH.Lib.Map abi: 26855f7c84ab668b019a8d35abdb5276 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/template-haskell-2.11.0.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/template-haskell-2.11.0.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/template-haskell-2.11.0.0 hs-libraries: HStemplate-haskell-2.11.0.0 depends: base-4.9.0.0 ghc-boot-0.0.0.0 pretty-1.1.2.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/template-haskell-2.11.0.0/template-haskell.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/template-haskell-2.11.0.0 --- name: Cabal version: 1.23.0.0 id: Cabal-1.23.0.0 key: Cabal-1.23.0.0 license: BSD3 copyright: 2003-2006, Isaac Jones 2005-2011, Duncan Coutts maintainer: cabal-devel@haskell.org homepage: http://www.haskell.org/cabal/ synopsis: A framework for packaging Haskell software description: The Haskell Common Architecture for Building Applications and Libraries: a framework defining a common interface for authors to more easily build their Haskell applications in a portable way. . The Haskell Cabal is part of a larger infrastructure for distributing, organizing, and cataloging Haskell libraries and tools. category: Distribution author: Isaac Jones Duncan Coutts exposed: True exposed-modules: Distribution.Compat.CreatePipe Distribution.Compat.Environment Distribution.Compat.Exception Distribution.Compat.Internal.TempFile Distribution.Compat.ReadP Distribution.Compiler Distribution.InstalledPackageInfo Distribution.License Distribution.Make Distribution.ModuleName Distribution.Package Distribution.PackageDescription Distribution.PackageDescription.Check Distribution.PackageDescription.Configuration Distribution.PackageDescription.Parse Distribution.PackageDescription.PrettyPrint Distribution.PackageDescription.Utils Distribution.ParseUtils Distribution.ReadE Distribution.Simple Distribution.Simple.Bench Distribution.Simple.Build Distribution.Simple.Build.Macros Distribution.Simple.Build.PathsModule Distribution.Simple.BuildPaths Distribution.Simple.BuildTarget Distribution.Simple.CCompiler Distribution.Simple.Command Distribution.Simple.Compiler Distribution.Simple.Configure Distribution.Simple.GHC Distribution.Simple.GHCJS Distribution.Simple.Haddock Distribution.Simple.HaskellSuite Distribution.Simple.Hpc Distribution.Simple.Install Distribution.Simple.InstallDirs Distribution.Simple.JHC Distribution.Simple.LHC Distribution.Simple.LocalBuildInfo Distribution.Simple.PackageIndex Distribution.Simple.PreProcess Distribution.Simple.PreProcess.Unlit Distribution.Simple.Program Distribution.Simple.Program.Ar Distribution.Simple.Program.Builtin Distribution.Simple.Program.Db Distribution.Simple.Program.Find Distribution.Simple.Program.GHC Distribution.Simple.Program.HcPkg Distribution.Simple.Program.Hpc Distribution.Simple.Program.Internal Distribution.Simple.Program.Ld Distribution.Simple.Program.Run Distribution.Simple.Program.Script Distribution.Simple.Program.Strip Distribution.Simple.Program.Types Distribution.Simple.Register Distribution.Simple.Setup Distribution.Simple.SrcDist Distribution.Simple.Test Distribution.Simple.Test.ExeV10 Distribution.Simple.Test.LibV09 Distribution.Simple.Test.Log Distribution.Simple.UHC Distribution.Simple.UserHooks Distribution.Simple.Utils Distribution.System Distribution.TestSuite Distribution.Text Distribution.Utils.NubList Distribution.Verbosity Distribution.Version Language.Haskell.Extension hidden-modules: Distribution.Compat.Binary Distribution.Compat.CopyFile Distribution.GetOpt Distribution.Lex Distribution.Simple.GHC.Internal Distribution.Simple.GHC.IPI641 Distribution.Simple.GHC.IPI642 Distribution.Simple.GHC.ImplInfo Paths_Cabal abi: 4b55984d7d0e5898df279f52ba75702f trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/Cabal-1.23.0.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/Cabal-1.23.0.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/Cabal-1.23.0.0 hs-libraries: HSCabal-1.23.0.0 depends: array-0.5.1.0 base-4.9.0.0 binary-0.7.5.0 bytestring-0.10.7.0 containers-0.5.6.3 deepseq-1.4.2.0 directory-1.2.5.0 filepath-1.4.1.0 pretty-1.1.2.0 process-1.4.1.0 time-1.5.0.1 unix-2.7.1.1 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/Cabal-1.23.0.0/Cabal.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/Cabal-1.23.0.0 --- name: binary version: 0.7.5.0 id: binary-0.7.5.0 key: binary-0.7.5.0 license: BSD3 maintainer: Lennart Kolmodin, Don Stewart stability: provisional homepage: https://github.com/kolmodin/binary synopsis: Binary serialisation for Haskell values using lazy ByteStrings description: Efficient, pure binary serialisation using lazy ByteStrings. Haskell values may be encoded to and from binary formats, written to disk as binary, or sent over the network. The format used can be automatically generated, or you can choose to implement a custom format if needed. Serialisation speeds of over 1 G\/sec have been observed, so this library should be suitable for high performance scenarios. category: Data, Parsing author: Lennart Kolmodin exposed: True exposed-modules: Data.Binary Data.Binary.Put Data.Binary.Get Data.Binary.Get.Internal Data.Binary.Builder Data.Binary.Builder.Internal hidden-modules: Data.Binary.Builder.Base Data.Binary.Class Data.Binary.Generic abi: 023629bb1f3d2da077b9dfaec842d5d6 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/binary-0.7.5.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/binary-0.7.5.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/binary-0.7.5.0 hs-libraries: HSbinary-0.7.5.0 depends: array-0.5.1.0 base-4.9.0.0 bytestring-0.10.7.0 containers-0.5.6.3 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/binary-0.7.5.0/binary.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/binary-0.7.5.0 --- name: pretty version: 1.1.2.0 id: pretty-1.1.2.0 key: pretty-1.1.2.0 license: BSD3 maintainer: David Terei stability: Stable homepage: http://github.com/haskell/pretty synopsis: Pretty-printing library description: This package contains a pretty-printing library, a set of API's that provides a way to easily print out text in a consistent format of your choosing. This is useful for compilers and related tools. . This library was originally designed by John Hughes's and has since been heavily modified by Simon Peyton Jones. category: Text exposed: True exposed-modules: Text.PrettyPrint Text.PrettyPrint.HughesPJ Text.PrettyPrint.HughesPJClass abi: ff204a4f63b87ec08dfb63935ab60346 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/pretty-1.1.2.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/pretty-1.1.2.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/pretty-1.1.2.0 hs-libraries: HSpretty-1.1.2.0 depends: base-4.9.0.0 deepseq-1.4.2.0 ghc-prim-0.5.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/pretty-1.1.2.0/pretty.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/pretty-1.1.2.0 --- name: hpc version: 0.6.0.2 id: hpc-0.6.0.2 key: hpc-0.6.0.2 license: BSD3 maintainer: ghc-devs@haskell.org synopsis: Code Coverage Library for Haskell description: This package provides the code coverage library for Haskell. . See for more information. category: Control author: Andy Gill exposed: True exposed-modules: Trace.Hpc.Util Trace.Hpc.Mix Trace.Hpc.Tix Trace.Hpc.Reflect abi: b98013c17bf1741c790e3a830237e8bc trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/hpc-0.6.0.2 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/hpc-0.6.0.2 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/hpc-0.6.0.2 hs-libraries: HShpc-0.6.0.2 depends: base-4.9.0.0 containers-0.5.6.3 directory-1.2.5.0 filepath-1.4.1.0 time-1.5.0.1 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/hpc-0.6.0.2/hpc.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/hpc-0.6.0.2 --- name: process version: 1.4.1.0 id: process-1.4.1.0 key: process-1.4.1.0 license: BSD3 maintainer: libraries@haskell.org synopsis: Process libraries description: This package contains libraries for dealing with system processes. category: System exposed: True exposed-modules: System.Cmd System.Process System.Process.Internals hidden-modules: System.Process.Common System.Process.Posix abi: 483b4c1d894e8c880c567a1ee593790f trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/process-1.4.1.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/process-1.4.1.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/process-1.4.1.0 hs-libraries: HSprocess-1.4.1.0 include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/process-1.4.1.0/include includes: runProcess.h depends: base-4.9.0.0 deepseq-1.4.2.0 directory-1.2.5.0 filepath-1.4.1.0 unix-2.7.1.1 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/process-1.4.1.0/process.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/process-1.4.1.0 --- name: directory version: 1.2.5.0 id: directory-1.2.5.0 key: directory-1.2.5.0 license: BSD3 maintainer: libraries@haskell.org synopsis: Platform-agnostic library for filesystem operations description: This library provides a basic set of operations for manipulating files and directories in a portable way. category: System exposed: True exposed-modules: System.Directory hidden-modules: System.Directory.Internal System.Directory.Internal.Config System.Directory.Internal.C_utimensat System.Directory.Internal.Posix System.Directory.Internal.Windows abi: 73051d50bd0377c1f91d40ac29eafcde trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/directory-1.2.5.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/directory-1.2.5.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/directory-1.2.5.0 hs-libraries: HSdirectory-1.2.5.0 include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/directory-1.2.5.0/include includes: HsDirectory.h depends: base-4.9.0.0 filepath-1.4.1.0 time-1.5.0.1 unix-2.7.1.1 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/directory-1.2.5.0/directory.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/directory-1.2.5.0 --- name: unix version: 2.7.1.1 id: unix-2.7.1.1 key: unix-2.7.1.1 license: BSD3 maintainer: libraries@haskell.org homepage: https://github.com/haskell/unix synopsis: POSIX functionality description: This package gives you access to the set of operating system services standardised by POSIX 1003.1b (or the IEEE Portable Operating System Interface for Computing Environments - IEEE Std. 1003.1). . The package is not supported under Windows (except under Cygwin). category: System exposed: True exposed-modules: System.Posix System.Posix.ByteString System.Posix.Error System.Posix.Resource System.Posix.Time System.Posix.Unistd System.Posix.User System.Posix.Signals System.Posix.Signals.Exts System.Posix.Semaphore System.Posix.SharedMem System.Posix.ByteString.FilePath System.Posix.Directory System.Posix.Directory.ByteString System.Posix.DynamicLinker.Module System.Posix.DynamicLinker.Module.ByteString System.Posix.DynamicLinker.Prim System.Posix.DynamicLinker.ByteString System.Posix.DynamicLinker System.Posix.Files System.Posix.Files.ByteString System.Posix.IO System.Posix.IO.ByteString System.Posix.Env System.Posix.Env.ByteString System.Posix.Fcntl System.Posix.Process System.Posix.Process.Internals System.Posix.Process.ByteString System.Posix.Temp System.Posix.Temp.ByteString System.Posix.Terminal System.Posix.Terminal.ByteString hidden-modules: System.Posix.Directory.Common System.Posix.DynamicLinker.Common System.Posix.Files.Common System.Posix.IO.Common System.Posix.Process.Common System.Posix.Terminal.Common abi: 416bbf4a68812f768d46e0603efc98e6 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/unix-2.7.1.1 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/unix-2.7.1.1 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/unix-2.7.1.1 hs-libraries: HSunix-2.7.1.1 extra-libraries: rt util dl pthread include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/unix-2.7.1.1/include includes: HsUnix.h execvpe.h depends: base-4.9.0.0 bytestring-0.10.7.0 time-1.5.0.1 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/unix-2.7.1.1/unix.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/unix-2.7.1.1 --- name: time version: 1.5.0.1 id: time-1.5.0.1 key: time-1.5.0.1 license: BSD3 maintainer: stability: stable homepage: https://github.com/haskell/time synopsis: A time library description: A time library category: System author: Ashley Yakeley exposed: True exposed-modules: Data.Time.Calendar Data.Time.Calendar.MonthDay Data.Time.Calendar.OrdinalDate Data.Time.Calendar.WeekDate Data.Time.Calendar.Julian Data.Time.Calendar.Easter Data.Time.Clock Data.Time.Clock.POSIX Data.Time.Clock.TAI Data.Time.LocalTime Data.Time.Format Data.Time hidden-modules: Data.Time.Calendar.Private Data.Time.Calendar.Days Data.Time.Calendar.Gregorian Data.Time.Calendar.JulianYearDay Data.Time.Clock.Scale Data.Time.Clock.UTC Data.Time.Clock.CTimeval Data.Time.Clock.UTCDiff Data.Time.LocalTime.TimeZone Data.Time.LocalTime.TimeOfDay Data.Time.LocalTime.LocalTime Data.Time.Format.Parse Data.Time.Format.Locale abi: fa14628fffb7d93741bb88caab63757e trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/time-1.5.0.1 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/time-1.5.0.1 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/time-1.5.0.1 hs-libraries: HStime-1.5.0.1 include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/time-1.5.0.1/include depends: base-4.9.0.0 deepseq-1.4.2.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/time-1.5.0.1/time.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/time-1.5.0.1 --- name: containers version: 0.5.6.3 id: containers-0.5.6.3 key: containers-0.5.6.3 license: BSD3 maintainer: fox@ucw.cz synopsis: Assorted concrete container types description: This package contains efficient general-purpose implementations of various basic immutable container types. The declared cost of each operation is either worst-case or amortized, but remains valid even if structures are shared. category: Data Structures exposed: True exposed-modules: Data.IntMap Data.IntMap.Lazy Data.IntMap.Strict Data.IntSet Data.Map Data.Map.Lazy Data.Map.Strict Data.Set Data.Graph Data.Sequence Data.Tree hidden-modules: Data.IntMap.Base Data.IntSet.Base Data.Map.Base Data.Set.Base Data.Utils.BitUtil Data.Utils.StrictFold Data.Utils.StrictPair abi: 4ae96ef90aaf7e7c342611448391c5cd trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/containers-0.5.6.3 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/containers-0.5.6.3 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/containers-0.5.6.3 hs-libraries: HScontainers-0.5.6.3 depends: array-0.5.1.0 base-4.9.0.0 deepseq-1.4.2.0 ghc-prim-0.5.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/containers-0.5.6.3/containers.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/containers-0.5.6.3 --- name: bytestring version: 0.10.7.0 id: bytestring-0.10.7.0 key: bytestring-0.10.7.0 license: BSD3 copyright: Copyright (c) Don Stewart 2005-2009, (c) Duncan Coutts 2006-2015, (c) David Roundy 2003-2005, (c) Jasper Van der Jeugt 2010, (c) Simon Meier 2010-2013. maintainer: Duncan Coutts homepage: https://github.com/haskell/bytestring synopsis: Fast, compact, strict and lazy byte strings with a list interface description: An efficient compact, immutable byte string type (both strict and lazy) suitable for binary or 8-bit character data. . The 'ByteString' type represents sequences of bytes or 8-bit characters. It is suitable for high performance use, both in terms of large data quantities, or high speed requirements. The 'ByteString' functions follow the same style as Haskell\'s ordinary lists, so it is easy to convert code from using 'String' to 'ByteString'. . Two 'ByteString' variants are provided: . * Strict 'ByteString's keep the string as a single large array. This makes them convenient for passing data between C and Haskell. . * Lazy 'ByteString's use a lazy list of strict chunks which makes it suitable for I\/O streaming tasks. . The @Char8@ modules provide a character-based view of the same underlying 'ByteString' types. This makes it convenient to handle mixed binary and 8-bit character content (which is common in many file formats and network protocols). . The 'Builder' module provides an efficient way to build up 'ByteString's in an ad-hoc way by repeated concatenation. This is ideal for fast serialisation or pretty printing. . There is also a 'ShortByteString' type which has a lower memory overhead and can be converted to or from a 'ByteString', but supports very few other operations. It is suitable for keeping many short strings in memory. . 'ByteString's are not designed for Unicode. For Unicode strings you should use the 'Text' type from the @text@ package. . These modules are intended to be imported qualified, to avoid name clashes with "Prelude" functions, e.g. . > import qualified Data.ByteString as BS category: Data author: Don Stewart, Duncan Coutts exposed: True exposed-modules: Data.ByteString Data.ByteString.Char8 Data.ByteString.Unsafe Data.ByteString.Internal Data.ByteString.Lazy Data.ByteString.Lazy.Char8 Data.ByteString.Lazy.Internal Data.ByteString.Short Data.ByteString.Short.Internal Data.ByteString.Builder Data.ByteString.Builder.Extra Data.ByteString.Builder.Prim Data.ByteString.Builder.Internal Data.ByteString.Builder.Prim.Internal Data.ByteString.Lazy.Builder Data.ByteString.Lazy.Builder.Extras Data.ByteString.Lazy.Builder.ASCII hidden-modules: Data.ByteString.Builder.ASCII Data.ByteString.Builder.Prim.Binary Data.ByteString.Builder.Prim.ASCII Data.ByteString.Builder.Prim.Internal.Floating Data.ByteString.Builder.Prim.Internal.UncheckedShifts Data.ByteString.Builder.Prim.Internal.Base16 abi: d9206a8fe0d44e69be0c04076cabad23 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/bytestring-0.10.7.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/bytestring-0.10.7.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/bytestring-0.10.7.0 hs-libraries: HSbytestring-0.10.7.0 include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/bytestring-0.10.7.0/include includes: fpstring.h depends: base-4.9.0.0 deepseq-1.4.2.0 ghc-prim-0.5.0.0 integer-gmp-1.0.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/bytestring-0.10.7.0/bytestring.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/bytestring-0.10.7.0 --- name: deepseq version: 1.4.2.0 id: deepseq-1.4.2.0 key: deepseq-1.4.2.0 license: BSD3 maintainer: libraries@haskell.org synopsis: Deep evaluation of data structures description: This package provides methods for fully evaluating data structures (\"deep evaluation\"). Deep evaluation is often used for adding strictness to a program, e.g. in order to force pending exceptions, remove space leaks, or force lazy I/O to happen. It is also useful in parallel programs, to ensure pending work does not migrate to the wrong thread. . The primary use of this package is via the 'deepseq' function, a \"deep\" version of 'seq'. It is implemented on top of an 'NFData' typeclass (\"Normal Form Data\", data structures with no unevaluated components) which defines strategies for fully evaluating different data types. category: Control exposed: True exposed-modules: Control.DeepSeq abi: 63c4c214c0c19484502b3c8b7e42ec69 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/deepseq-1.4.2.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/deepseq-1.4.2.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/deepseq-1.4.2.0 hs-libraries: HSdeepseq-1.4.2.0 depends: array-0.5.1.0 base-4.9.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/deepseq-1.4.2.0/deepseq.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/deepseq-1.4.2.0 --- name: array version: 0.5.1.0 id: array-0.5.1.0 key: array-0.5.1.0 license: BSD3 maintainer: libraries@haskell.org synopsis: Mutable and immutable arrays description: In addition to providing the "Data.Array" module , this package also defines the classes 'IArray' of immutable arrays and 'MArray' of arrays mutable within appropriate monads, as well as some instances of these classes. category: Data Structures exposed: True exposed-modules: Data.Array Data.Array.Base Data.Array.IArray Data.Array.IO Data.Array.IO.Safe Data.Array.IO.Internals Data.Array.MArray Data.Array.MArray.Safe Data.Array.ST Data.Array.ST.Safe Data.Array.Storable Data.Array.Storable.Safe Data.Array.Storable.Internals Data.Array.Unboxed Data.Array.Unsafe abi: 2b2b879a09eb81c865ac273803e08132 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/array-0.5.1.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/array-0.5.1.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/array-0.5.1.0 hs-libraries: HSarray-0.5.1.0 depends: base-4.9.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/array-0.5.1.0/array.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/array-0.5.1.0 --- name: filepath version: 1.4.1.0 id: filepath-1.4.1.0 key: filepath-1.4.1.0 license: BSD3 copyright: Neil Mitchell 2005-2015 maintainer: Neil Mitchell homepage: https://github.com/haskell/filepath#readme synopsis: Library for manipulating FilePaths in a cross platform way. description: This package provides functionality for manipulating @FilePath@ values, and is shipped with both and the . It provides three modules: . * "System.FilePath.Posix" manipulates POSIX\/Linux style @FilePath@ values (with @\/@ as the path separator). . * "System.FilePath.Windows" manipulates Windows style @FilePath@ values (with either @\\@ or @\/@ as the path separator, and deals with drives). . * "System.FilePath" is an alias for the module appropriate to your platform. . All three modules provide the same API, and the same documentation (calling out differences in the different variants). category: System author: Neil Mitchell exposed: True exposed-modules: System.FilePath System.FilePath.Posix System.FilePath.Windows abi: 1e3d9055afc6aa08b97f5ad5f8014ce4 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/filepath-1.4.1.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/filepath-1.4.1.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/filepath-1.4.1.0 hs-libraries: HSfilepath-1.4.1.0 depends: base-4.9.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/filepath-1.4.1.0/filepath.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/filepath-1.4.1.0 --- name: base version: 4.9.0.0 id: base-4.9.0.0 key: base-4.9.0.0 license: BSD3 maintainer: libraries@haskell.org synopsis: Basic libraries description: This package contains the "Prelude" and its support libraries, and a large collection of useful libraries ranging from data structures to parsing combinators and debugging utilities. category: Prelude exposed: True exposed-modules: Control.Applicative Control.Arrow Control.Category Control.Concurrent Control.Concurrent.Chan Control.Concurrent.MVar Control.Concurrent.QSem Control.Concurrent.QSemN Control.Exception Control.Exception.Base Control.Monad Control.Monad.Fail Control.Monad.Fix Control.Monad.Instances Control.Monad.IO.Class Control.Monad.ST Control.Monad.ST.Lazy Control.Monad.ST.Lazy.Safe Control.Monad.ST.Lazy.Unsafe Control.Monad.ST.Safe Control.Monad.ST.Strict Control.Monad.ST.Unsafe Control.Monad.Zip Data.Bifunctor Data.Bits Data.Bool Data.Char Data.Coerce Data.Complex Data.Data Data.Dynamic Data.Either Data.Eq Data.Fixed Data.Foldable Data.Function Data.Functor Data.Functor.Identity Data.IORef Data.Int Data.Ix Data.Kind Data.List Data.List.NonEmpty Data.Maybe Data.Monoid Data.Ord Data.Proxy Data.Ratio Data.Semigroup Data.STRef Data.STRef.Lazy Data.STRef.Strict Data.String Data.Traversable Data.Tuple Data.Type.Bool Data.Type.Coercion Data.Type.Equality Data.Typeable Data.Typeable.Internal Data.Unique Data.Version Data.Void Data.Word Debug.Trace Foreign Foreign.C Foreign.C.Error Foreign.C.String Foreign.C.Types Foreign.Concurrent Foreign.ForeignPtr Foreign.ForeignPtr.Safe Foreign.ForeignPtr.Unsafe Foreign.Marshal Foreign.Marshal.Alloc Foreign.Marshal.Array Foreign.Marshal.Error Foreign.Marshal.Pool Foreign.Marshal.Safe Foreign.Marshal.Unsafe Foreign.Marshal.Utils Foreign.Ptr Foreign.Safe Foreign.StablePtr Foreign.Storable GHC.Arr GHC.Base GHC.Char GHC.Conc GHC.Conc.IO GHC.Conc.Signal GHC.Conc.Sync GHC.ConsoleHandler GHC.Constants GHC.Desugar GHC.Enum GHC.Environment GHC.Err GHC.Exception GHC.ExecutionStack GHC.ExecutionStack.Internal GHC.Exts GHC.Fingerprint GHC.Fingerprint.Type GHC.Float GHC.Float.ConversionUtils GHC.Float.RealFracMethods GHC.Foreign GHC.ForeignPtr GHC.GHCi GHC.Generics GHC.IO GHC.IO.Buffer GHC.IO.BufferedIO GHC.IO.Device GHC.IO.Encoding GHC.IO.Encoding.CodePage GHC.IO.Encoding.Failure GHC.IO.Encoding.Iconv GHC.IO.Encoding.Latin1 GHC.IO.Encoding.Types GHC.IO.Encoding.UTF16 GHC.IO.Encoding.UTF32 GHC.IO.Encoding.UTF8 GHC.IO.Exception GHC.IO.FD GHC.IO.Handle GHC.IO.Handle.FD GHC.IO.Handle.Internals GHC.IO.Handle.Text GHC.IO.Handle.Types GHC.IO.IOMode GHC.IO.Unsafe GHC.IOArray GHC.IORef GHC.Int GHC.List GHC.MVar GHC.Natural GHC.Num GHC.OldList GHC.OverloadedLabels GHC.PArr GHC.Pack GHC.Profiling GHC.Ptr GHC.Read GHC.Real GHC.RTS.Flags GHC.ST GHC.StaticPtr GHC.STRef GHC.Show GHC.Stable GHC.Stack GHC.Stack.CCS GHC.Stack.Types GHC.Stats GHC.Storable GHC.TopHandler GHC.TypeLits GHC.Unicode GHC.Weak GHC.Word Numeric Numeric.Natural Prelude System.CPUTime System.Console.GetOpt System.Environment System.Exit System.IO System.IO.Error System.IO.Unsafe System.Info System.Mem System.Mem.StableName System.Mem.Weak System.Posix.Internals System.Posix.Types System.Timeout Text.ParserCombinators.ReadP Text.ParserCombinators.ReadPrec Text.Printf Text.Read Text.Read.Lex Text.Show Text.Show.Functions Unsafe.Coerce GHC.Event hidden-modules: Control.Monad.ST.Imp Control.Monad.ST.Lazy.Imp Data.OldList Foreign.ForeignPtr.Imp System.Environment.ExecutablePath GHC.Event.Arr GHC.Event.Array GHC.Event.Clock GHC.Event.Control GHC.Event.EPoll GHC.Event.IntTable GHC.Event.Internal GHC.Event.KQueue GHC.Event.Manager GHC.Event.PSQ GHC.Event.Poll GHC.Event.Thread GHC.Event.TimerManager GHC.Event.Unique abi: 472df40e39128303d276cf121f250e89 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/base-4.9.0.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/base-4.9.0.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/base-4.9.0.0 hs-libraries: HSbase-4.9.0.0 include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/base-4.9.0.0/include includes: HsBase.h depends: ghc-prim-0.5.0.0 integer-gmp-1.0.0.0 rts haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/base-4.9.0.0/base.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/base-4.9.0.0 --- name: integer-gmp version: 1.0.0.0 id: integer-gmp-1.0.0.0 key: integer-gmp-1.0.0.0 license: BSD3 maintainer: hvr@gnu.org synopsis: Integer library based on GMP category: Numeric, Algebra author: Herbert Valerio Riedel exposed: True exposed-modules: GHC.Integer GHC.Integer.Logarithms GHC.Integer.Logarithms.Internals GHC.Integer.GMP.Internals hidden-modules: GHC.Integer.Type abi: 32980bb533b4a3996f3424fd198cf767 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/integer-gmp-1.0.0.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/integer-gmp-1.0.0.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/integer-gmp-1.0.0.0 hs-libraries: HSinteger-gmp-1.0.0.0 extra-libraries: gmp include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/integer-gmp-1.0.0.0/include depends: ghc-prim-0.5.0.0 haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/integer-gmp-1.0.0.0/integer-gmp.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/integer-gmp-1.0.0.0 --- name: ghc-prim version: 0.5.0.0 id: ghc-prim-0.5.0.0 key: ghc-prim-0.5.0.0 license: BSD3 maintainer: libraries@haskell.org synopsis: GHC primitives description: GHC primitives. category: GHC exposed: True exposed-modules: GHC.CString GHC.Classes GHC.Debug GHC.IntWord64 GHC.Magic GHC.PrimopWrappers GHC.Tuple GHC.Types GHC.Prim abi: 9f5ec1125ba73d164ce53f7b537009e8 trusted: False import-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/ghc-prim-0.5.0.0 library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/ghc-prim-0.5.0.0 data-dir: /opt/ghc/head/share/x86_64-linux-ghc-7.11.20151213/ghc-prim-0.5.0.0 hs-libraries: HSghc-prim-0.5.0.0 depends: rts haddock-interfaces: /opt/ghc/head/share/doc/ghc/html/libraries/ghc-prim-0.5.0.0/ghc-prim.haddock haddock-html: /opt/ghc/head/share/doc/ghc/html/libraries/ghc-prim-0.5.0.0 --- name: rts version: 1.0 id: rts key: rts license: BSD3 maintainer: glasgow-haskell-users@haskell.org exposed: True abi: trusted: False library-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/rts hs-libraries: HSrts Cffi extra-libraries: m rt dl include-dirs: /opt/ghc/head/lib/ghc-7.11.20151213/include includes: Stg.h ld-options: "-Wl,-u,ghczmprim_GHCziTypes_Izh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Czh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Fzh_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Dzh_static_info" "-Wl,-u,base_GHCziPtr_Ptr_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Wzh_static_info" "-Wl,-u,base_GHCziInt_I8zh_static_info" "-Wl,-u,base_GHCziInt_I16zh_static_info" "-Wl,-u,base_GHCziInt_I32zh_static_info" "-Wl,-u,base_GHCziInt_I64zh_static_info" "-Wl,-u,base_GHCziWord_W8zh_static_info" "-Wl,-u,base_GHCziWord_W16zh_static_info" "-Wl,-u,base_GHCziWord_W32zh_static_info" "-Wl,-u,base_GHCziWord_W64zh_static_info" "-Wl,-u,base_GHCziStable_StablePtr_static_info" "-Wl,-u,ghczmprim_GHCziTypes_Izh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Czh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Fzh_con_info" "-Wl,-u,ghczmprim_GHCziTypes_Dzh_con_info" "-Wl,-u,base_GHCziPtr_Ptr_con_info" "-Wl,-u,base_GHCziPtr_FunPtr_con_info" "-Wl,-u,base_GHCziStable_StablePtr_con_info" "-Wl,-u,ghczmprim_GHCziTypes_False_closure" "-Wl,-u,ghczmprim_GHCziTypes_True_closure" "-Wl,-u,base_GHCziPack_unpackCString_closure" "-Wl,-u,base_GHCziIOziException_stackOverflow_closure" "-Wl,-u,base_GHCziIOziException_heapOverflow_closure" "-Wl,-u,base_ControlziExceptionziBase_nonTermination_closure" "-Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnMVar_closure" "-Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnSTM_closure" "-Wl,-u,base_GHCziIOziException_allocationLimitExceeded_closure" "-Wl,-u,base_ControlziExceptionziBase_nestedAtomically_closure" "-Wl,-u,base_GHCziEventziThread_blockedOnBadFD_closure" "-Wl,-u,base_GHCziWeak_runFinalizzerBatch_closure" "-Wl,-u,base_GHCziTopHandler_flushStdHandles_closure" "-Wl,-u,base_GHCziTopHandler_runIO_closure" "-Wl,-u,base_GHCziTopHandler_runNonIO_closure" "-Wl,-u,base_GHCziConcziIO_ensureIOManagerIsRunning_closure" "-Wl,-u,base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure" "-Wl,-u,base_GHCziConcziSync_runSparks_closure" "-Wl,-u,base_GHCziConcziSignal_runHandlersPtr_closure" stack-2.9.3.1/src/test/Stack/Untar/test1.tar.gz0000644000000000000000000000042114331513215017245 0ustar0000000000000000꣌WMj0`s fFRȾ^AvɢXU"JZl? OMB5"8㚔V+C^ؐ1LJɩj?b4HW߼4k#nb;Yrs4a}!ڼ:sO]ŋce}ބŸ=}.k )?3;̜ză?zNFqk/Ƴf?;\(stack-2.9.3.1/src/test/Stack/Untar/test2.tar.gz0000644000000000000000000000055714331513215017260 0ustar0000000000000000꣌WAN0E)r lXr@S%)TIEyQ,+/V]~-MQVKh)I@cRF%!h kIzg:/9h_=Yo)ġ {w&_|7hG\my>r_Uxv{r'|yO1Q?};XqpO`96bOGc֘vM@VиBJ)^Ka`kLw9HA.߶a:k    ? 4(stack-2.9.3.1/cabal.project0000644000000000000000000000340014445113031013602 0ustar0000000000000000-- This file is a configuration file for Cabal (the tool). It is provided to -- assist some users of that tool to develop Stack. For information about -- `cabal.project` files, see: -- https://cabal.readthedocs.io/en/stable/cabal-project.html. -- -- For information about possible limitations of the `cabal.config` files -- corresponding to Stackage package sets that are made available by Stackage -- see: https://github.com/fpco/stackage-server/issues/232. -- -- `import:` is only available to users of Cabal (the tool) >= 3.8.1.0. -- -- The constraints in file `cabal.config` can be obtained by commanding: -- -- > stack ls dependencies cabal > cabal.config -- -- However, be aware that, in respect of the `unix` package or the `Win32` -- package (that may come with GHC, depending on the operating system): -- -- * on Windows, the Stack project does not depend on `unix` but depends on -- `Win32`; and -- -- * on non-Windows operating systems, the Stack project does not depend on -- `Win32` but depends on `unix`. -- -- The command above will add one of the two packages to `cabal.config` but omit -- the other. A comprehensive `cabal.config` will need to be created by editing -- the command's output. -- -- Also be aware that there may be other packages required only on non-Windows -- systems. For example, the `hinotify` package. -- -- Be sure to set `with-compiler: ghc-x.y.z` below to the version of GHC that is -- specified by the snapshot specifed in Stack's project-level YAML -- configuration file (`stack.yaml`). The relevant version of GHC can be -- confirmed by reviewing the snapshot on Stackage. For example, at: -- https://www.stackage.org/lts-20.23/cabal.config. -- with-compiler: ghc-9.4.5 import: cabal.config packages: . stack-2.9.3.1/cabal.config0000644000000000000000000001212114445113031013401 0ustar0000000000000000constraints: , Cabal ==3.8.1.0 , Cabal-syntax ==3.8.1.0 , Glob ==0.10.2 , OneTuple ==0.4.1.1 , QuickCheck ==2.14.3 , StateVar ==1.2.2 , Win32 ==2.12.0.1 , aeson ==2.1.2.1 , annotated-wl-pprint ==0.7.0 , ansi-terminal ==0.11.5 , ansi-terminal-types ==0.11.5 , ansi-wl-pprint ==0.6.9 , appar ==0.1.8 , array ==0.5.4.0 , asn1-encoding ==0.9.6 , asn1-parse ==0.9.5 , asn1-types ==0.3.4 , assoc ==1.1 , async ==2.2.4 , attoparsec ==0.14.4 , attoparsec-iso8601 ==1.1.0.0 , auto-update ==0.1.6 , base ==4.17.1.0 , base-compat ==0.12.2 , base-compat-batteries ==0.12.2 , base-orphans ==0.9.0 , base16-bytestring ==1.0.2.0 , base64-bytestring ==1.2.1.0 , basement ==0.0.16 , bifunctors ==5.5.15 , binary ==0.8.9.1 , bitvec ==1.1.4.0 , blaze-builder ==0.4.2.2 , blaze-html ==0.9.1.2 , blaze-markup ==0.8.2.8 , byteorder ==1.0.4 , bytestring ==0.11.4.0 , casa-client ==0.0.1 , casa-types ==0.0.2 , case-insensitive ==1.2.1.0 , cereal ==0.5.8.3 , clock ==0.8.3 , cmdargs ==0.10.22 , colour ==2.3.6 , comonad ==5.0.8 , conduit ==1.3.5 , conduit-combinators ==1.3.0 , conduit-extra ==1.3.6 , connection ==0.3.1 , containers ==0.6.7 , contravariant ==1.5.5 , cookie ==0.4.6 , cryptohash-sha256 ==0.11.102.1 , cryptonite ==0.30 , cryptonite-conduit ==0.2.2 , data-default-class ==0.1.2.0 , data-fix ==0.3.2 , deepseq ==1.4.8.0 , digest ==0.0.1.7 , directory ==1.3.7.1 , distributive ==0.6.2.1 , dlist ==1.0 , easy-file ==0.2.5 , echo ==0.1.4 , ed25519 ==0.0.5.0 , exceptions ==0.10.5 , extra ==1.7.13 , fast-logger ==3.2.1 , file-embed ==0.0.15.0 , filelock ==0.1.1.6 , filepath ==1.4.2.2 , foldable1-classes-compat ==0.1 , fsnotify ==0.4.1.0 , generic-deriving ==1.14.4 , generically ==0.1.1 , ghc-bignum ==1.3 , ghc-boot-th ==9.4.5 , ghc-prim ==0.9.0 , githash ==0.1.6.3 , hackage-security ==0.6.2.3 , hashable ==1.4.2.0 , hi-file-parser ==0.1.4.0 . hinotify ==0.4.1 , hourglass ==0.2.12 , hpack ==0.35.2 , hpc ==0.6.1.0 , http-api-data ==0.5 , http-client ==0.7.13.1 , http-client-tls ==0.3.6.1 , http-conduit ==2.3.8.1 , http-download ==0.2.0.0 , http-types ==0.12.3 , indexed-traversable ==0.1.2.1 , indexed-traversable-instances ==0.1.1.2 , infer-license ==0.2.0 , integer-gmp ==1.1 , integer-logarithms ==1.0.3.1 , iproute ==1.7.12 , libyaml ==0.1.2 , lift-type ==0.1.1.1 , lifted-base ==0.2.3.12 , lukko ==0.1.1.3 , megaparsec ==9.3.1 , memory ==0.18.0 , microlens ==0.4.13.1 , microlens-mtl ==0.2.0.3 , microlens-th ==0.4.3.13 , mime-types ==0.1.1.0 , mintty ==0.1.4 , monad-control ==1.0.3.1 , monad-logger ==0.3.40 , monad-loops ==0.4.3 , mono-traversable ==1.0.15.3 , mtl ==2.2.2 , mtl-compat ==0.2.2 , mustache ==2.4.2 , neat-interpolation ==0.5.1.3 , network ==3.1.4.0 , network-uri ==2.6.4.2 , old-locale ==1.0.0.7 , old-time ==1.1.0.3 , open-browser ==0.2.1.0 , optparse-applicative ==0.17.1.0 , optparse-simple ==0.1.1.4 , pantry ==0.8.2.2 , parsec ==3.1.16.1 , parser-combinators ==1.3.0 , path ==0.9.2 , path-io ==1.8.1 , path-pieces ==0.2.1 , pem ==0.2.4 , persistent ==2.14.5.0 , persistent-sqlite ==2.13.1.1 , persistent-template ==2.12.0.0 , pretty ==1.1.3.6 , primitive ==0.8.0.0 , process ==1.6.16.0 , project-template ==0.2.1.0 , random ==1.2.1.1 , resource-pool ==0.4.0.0 , resourcet ==1.2.6 , retry ==0.9.3.1 , rio ==0.1.22.0 , rio-orphans ==0.1.2.0 , rio-prettyprint ==0.1.4.0 , rts ==1.0.2 , safe ==0.3.19 , safe-exceptions ==0.1.7.3 , scientific ==0.3.7.0 , semialign ==1.3 , semigroupoids ==5.3.7 , semigroups ==0.20 , silently ==1.2.5.3 , socks ==0.6.1 , split ==0.2.3.5 , splitmix ==0.1.0.4 , stack ==2.9.3.1 , stm ==2.5.1.0 , stm-chans ==3.0.0.9 , streaming-commons ==0.2.2.6 , strict ==0.5 , syb ==0.7.2.3 , tagged ==0.8.7 , tar ==0.5.1.1 , tar-conduit ==0.3.2 , template-haskell ==2.19.0.0 , temporary ==1.3 , text ==2.0.2 , text-metrics ==0.3.2 , text-short ==0.1.5 , th-abstraction ==0.4.5.0 , th-compat ==0.1.4 , th-expand-syns ==0.4.11.0 , th-lift ==0.8.3 , th-lift-instances ==0.1.20 , th-reify-many ==0.1.10 , these ==1.2 , time ==1.12.2 , time-compat ==1.9.6.1 , tls ==1.6.0 , transformers ==0.5.6.2 , transformers-base ==0.4.6 , transformers-compat ==0.7.2 , typed-process ==0.2.11.0 , unix ==2.7.3 , unicode-data ==0.4.0.1 , unicode-transforms ==0.4.0.1 , unix-compat ==0.7 , unix-time ==0.4.9 , unliftio ==0.2.25.0 , unliftio-core ==0.2.1.0 , unordered-containers ==0.2.19.1 , uuid-types ==1.0.5 , vault ==0.3.1.5 , vector ==0.13.0.0 , vector-algorithms ==0.9.0.1 , vector-stream ==0.1.0.0 , witherable ==0.4.2 , x509 ==1.7.7 , x509-store ==1.6.9 , x509-system ==1.6.7 , x509-validation ==1.6.12 , yaml ==0.11.11.1 , zip-archive ==0.4.3 , zlib ==0.6.3.0 stack-2.9.3.1/LICENSE0000644000000000000000000000276114445022466012201 0ustar0000000000000000Copyright (c) 2015-2022, Stack contributors 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 Stack nor the names of its 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 STACK 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. stack-2.9.3.1/Setup.hs0000644000000000000000000000666614445022466012640 0ustar0000000000000000{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-} module Main ( main ) where import Data.List ( nub, sortBy ) import Data.Ord ( comparing ) import Distribution.InstalledPackageInfo ( sourcePackageId, installedUnitId ) import Distribution.Package ( PackageId, UnitId, packageVersion, packageName ) import Distribution.PackageDescription ( PackageDescription (), Executable (..) ) import Distribution.Pretty ( prettyShow ) import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks ) import Distribution.Simple.BuildPaths ( autogenPackageModulesDir ) import Distribution.Simple.LocalBuildInfo ( installedPkgs, withLibLBI, withExeLBI, LocalBuildInfo () , ComponentLocalBuildInfo (componentPackageDeps) ) import Distribution.Simple.PackageIndex ( allPackages, dependencyClosure ) import Distribution.Simple.Setup ( BuildFlags (buildVerbosity), fromFlag ) import Distribution.Simple.Utils ( rewriteFileEx, createDirectoryIfMissingVerbose ) import Distribution.Types.PackageName ( PackageName, unPackageName ) import Distribution.Types.UnqualComponentName ( unUnqualComponentName ) import Distribution.Verbosity ( Verbosity, normal ) import System.FilePath ( () ) main :: IO () main = defaultMainWithHooks simpleUserHooks { buildHook = \pkg lbi hooks flags -> do generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi buildHook simpleUserHooks pkg lbi hooks flags } generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO () generateBuildModule verbosity pkg lbi = do let dir = autogenPackageModulesDir lbi createDirectoryIfMissingVerbose verbosity True dir withLibLBI pkg lbi $ \_ libcfg -> do withExeLBI pkg lbi $ \exe clbi -> rewriteFileEx normal (dir "Build_" ++ exeName' exe ++ ".hs") $ unlines [ "module Build_" ++ exeName' exe ++ " where" , "" , "deps :: [String]" , "deps = " ++ (show $ formatdeps (transDeps libcfg clbi)) ] where exeName' = unUnqualComponentName . exeName formatdeps = map formatone . sortBy (comparing unPackageName') formatone p = unPackageName' p ++ "-" ++ prettyShow (packageVersion p) unPackageName' = unPackageName . packageName transDeps xs ys = either (map sourcePackageId . allPackages) handleDepClosureFailure $ dependencyClosure allInstPkgsIdx availInstPkgIds where allInstPkgsIdx = installedPkgs lbi allInstPkgIds = map installedUnitId $ allPackages allInstPkgsIdx -- instPkgIds includes `stack-X.X.X`, which is not a dependency hence is missing from allInstPkgsIdx. Filter that out. availInstPkgIds = filter (`elem` allInstPkgIds) $ testDeps xs ys handleDepClosureFailure unsatisfied = error $ "Computation of transitive dependencies failed." ++ if null unsatisfied then "" else " Unresolved dependencies: " ++ show unsatisfied testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [UnitId] testDeps xs ys = map fst $ nub $ componentPackageDeps xs ++ componentPackageDeps ys stack-2.9.3.1/stack.cabal0000644000000000000000000004410314445117331013255 0ustar0000000000000000cabal-version: 2.0 -- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack name: stack version: 2.9.3.1 synopsis: The Haskell Tool Stack description: Please see the documentation at for usage information. . If building a 'stack' executable for distribution, please download the source code from and build it using Stack itself in order to ensure identical behaviour to official binaries. This package on Hackage is provided for convenience and bootstrapping purposes. . Note that the API for the library is not currently stable, and may change significantly, even between minor releases. It is currently only intended for use by the executable. category: Development homepage: http://haskellstack.org bug-reports: https://github.com/commercialhaskell/stack/issues author: Commercial Haskell SIG maintainer: manny@fpcomplete.com license: BSD3 license-file: LICENSE build-type: Custom extra-source-files: CONTRIBUTING.md ChangeLog.md README.md stack.yaml doc/azure_ci.md doc/build_command.md doc/build_overview.md doc/ChangeLog.md doc/CI.md doc/clean_command.md doc/config_command.md doc/CONTRIBUTING.md doc/coverage.md doc/custom_snapshot.md doc/debugging.md doc/dependency_visualization.md doc/developing_on_windows.md doc/docker_command.md doc/docker_integration.md doc/dot_command.md doc/editor_integration.md doc/environment_variables.md doc/eval_command.md doc/exec_command.md doc/faq.md doc/ghc_command.md doc/ghci.md doc/global_flags.md doc/glossary.md doc/GUIDE.md doc/GUIDE_advanced.md doc/hoogle_command.md doc/hpc_command.md doc/ide_command.md doc/init_command.md doc/install_and_upgrade.md doc/list_command.md doc/lock_files.md doc/ls_command.md doc/new_command.md doc/nix_integration.md doc/nonstandard_project_init.md doc/other_resources.md doc/pantry.md doc/path_command.md doc/purge_command.md doc/query_command.md doc/README.md doc/run_command.md doc/runghc_command.md doc/script_command.md doc/scripts.md doc/sdist_command.md doc/setup_command.md doc/shell_autocompletion.md doc/SIGNING_KEY.md doc/Stack_and_VS_Code.md doc/stack_yaml_vs_cabal_package_file.md doc/templates_command.md doc/travis_ci.md doc/uninstall_command.md doc/unpack_command.md doc/update_command.md doc/upgrade_command.md doc/upload_command.md doc/yaml_configuration.md src/setup-shim/StackSetupShim.hs test/package-dump/ghc-7.10.txt test/package-dump/ghc-7.8.4-osx.txt test/package-dump/ghc-7.8.txt test/package-dump/ghc-head.txt src/test/Stack/Untar/test1.tar.gz src/test/Stack/Untar/test2.tar.gz cabal.project cabal.config source-repository head type: git location: https://github.com/commercialhaskell/stack custom-setup setup-depends: Cabal <3.10 , base >=4.14.3.0 && <5 , filepath flag developer-mode description: By default, should extra developer information be output? manual: True default: False flag disable-git-info description: Disable compile-time inclusion of current git info in stack manual: True default: False flag hide-dependency-versions description: Hides dependency versions from 'stack --version', used only by building Stack and the default 'stack.yaml'. Note to packagers/distributors: DO NOT OVERRIDE THIS FLAG IF YOU ARE BUILDING 'stack' ANY OTHER WAY (e.g. using cabal or from Hackage), as it makes debugging support requests more difficult. manual: True default: False flag integration-tests description: Run the integration test suite manual: True default: False flag static description: Pass -static/-pthread to ghc when linking the stack binary. manual: True default: False flag supported-build description: If false, causes 'stack --version' to issue a warning about the build being unsupported. Should be True only if building with Stack and the default 'stack.yaml'. Note to packagers/distributors: DO NOT OVERRIDE THIS FLAG IF YOU ARE BUILDING 'stack' ANY OTHER WAY (e.g. using cabal or from Hackage), as it makes debugging support requests more difficult. manual: True default: False library exposed-modules: Control.Concurrent.Execute Data.Attoparsec.Args Data.Attoparsec.Combinators Data.Attoparsec.Interpreter Data.Monoid.Map Network.HTTP.StackClient Options.Applicative.Args Options.Applicative.Builder.Extra Options.Applicative.Complicated Path.CheckInstall Path.Extra Path.Find Stack.Build Stack.Build.Cache Stack.Build.ConstructPlan Stack.Build.Execute Stack.Build.Haddock Stack.Build.Installed Stack.Build.Source Stack.Build.Target Stack.BuildPlan Stack.Clean Stack.Config Stack.Config.Build Stack.Config.Docker Stack.Config.Nix Stack.ConfigCmd Stack.Constants Stack.Constants.Config Stack.Coverage Stack.DefaultColorWhen Stack.Docker Stack.Dot Stack.FileWatch Stack.GhcPkg Stack.Ghci Stack.Ghci.Script Stack.Hoogle Stack.IDE Stack.Init Stack.List Stack.Ls Stack.Lock Stack.New Stack.Nix Stack.Options.BenchParser Stack.Options.BuildMonoidParser Stack.Options.BuildParser Stack.Options.CleanParser Stack.Options.ConfigParser Stack.Options.Completion Stack.Options.DockerParser Stack.Options.DotParser Stack.Options.ExecParser Stack.Options.GhcBuildParser Stack.Options.GhciParser Stack.Options.GhcVariantParser Stack.Options.GlobalParser Stack.Options.HaddockParser Stack.Options.HpcReportParser Stack.Options.LogLevelParser Stack.Options.NewParser Stack.Options.NixParser Stack.Options.PackageParser Stack.Options.ResolverParser Stack.Options.ScriptParser Stack.Options.SDistParser Stack.Options.TestParser Stack.Options.UploadParser Stack.Options.Utils Stack.Package Stack.PackageDump Stack.Path Stack.Prelude Stack.Runners Stack.Script Stack.SDist Stack.Setup Stack.Setup.Installed Stack.SetupCmd Stack.SourceMap Stack.Storage.Project Stack.Storage.User Stack.Storage.Util Stack.Types.Build Stack.Types.CompilerBuild Stack.Types.Compiler Stack.Types.Config Stack.Types.Config.Build Stack.Types.Docker Stack.Types.GhcPkgId Stack.Types.NamedComponent Stack.Types.Nix Stack.Types.Package Stack.Types.PackageName Stack.Types.Resolver Stack.Types.SourceMap Stack.Types.TemplateName Stack.Types.Version Stack.Unpack Stack.Upgrade Stack.Upload System.Info.ShortPathName System.Permissions System.Process.Pager System.Terminal Paths_stack other-modules: Path.Extended Stack.ComponentFile Stack.PackageFile Stack.Types.Cache Stack.Types.Dependency Stack.Types.PackageFile Stack.Types.Storage autogen-modules: Paths_stack hs-source-dirs: src/ ghc-options: -fwrite-ide-info -hiedir=.hie -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns -fwarn-incomplete-record-updates -optP-Wno-nonportable-include-path -fwarn-identities build-depends: Cabal >=3.6.3.0 , aeson >=2.0.3.0 , annotated-wl-pprint , ansi-terminal , array , async , attoparsec , base >=4.14.3.0 && <5 , base64-bytestring , bytestring , casa-client , casa-types , colour , conduit , conduit-extra , containers , cryptonite , cryptonite-conduit , deepseq , directory , echo , exceptions , extra , file-embed , filelock , filepath , fsnotify >=0.4.1 , generic-deriving , hackage-security , hashable , hi-file-parser , hpack , hpc , http-client , http-client-tls , http-conduit , http-download , http-types , memory , microlens , mintty , mono-traversable , mtl , mustache , neat-interpolation , network-uri , open-browser , optparse-applicative >=0.17.0.0 , pantry >=0.8.1 , path , path-io , persistent >=2.13.3.5 && <2.15 , persistent-sqlite , persistent-template , pretty , primitive , process >=1.6.13.2 , project-template , random , retry , rio >=0.1.22.0 , rio-prettyprint >=0.1.4.0 , semigroups , split , stm , streaming-commons , tar , template-haskell , temporary , text , text-metrics , th-reify-many , time , tls , transformers , typed-process , unicode-transforms , unix-compat , unliftio , unordered-containers , vector , yaml , zip-archive , zlib default-language: Haskell2010 if os(windows) cpp-options: -DWINDOWS build-depends: Win32 else build-depends: unix build-tool-depends: hsc2hs:hsc2hs if flag(developer-mode) cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True else cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False if os(windows) other-modules: System.Posix.User System.Uname hs-source-dirs: src/windows/ else other-modules: System.Uname hs-source-dirs: src/unix/ c-sources: src/unix/cbits/uname.c executable stack main-is: Main.hs other-modules: BuildInfo Build_stack Paths_stack autogen-modules: Build_stack Paths_stack hs-source-dirs: src/main ghc-options: -fwrite-ide-info -hiedir=.hie -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns -fwarn-incomplete-record-updates -optP-Wno-nonportable-include-path -threaded -rtsopts build-depends: Cabal >=3.6.3.0 , aeson >=2.0.3.0 , annotated-wl-pprint , ansi-terminal , array , async , attoparsec , base >=4.14.3.0 && <5 , base64-bytestring , bytestring , casa-client , casa-types , colour , conduit , conduit-extra , containers , cryptonite , cryptonite-conduit , deepseq , directory , echo , exceptions , extra , file-embed , filelock , filepath , fsnotify >=0.4.1 , generic-deriving , hackage-security , hashable , hi-file-parser , hpack , hpc , http-client , http-client-tls , http-conduit , http-download , http-types , memory , microlens , mintty , mono-traversable , mtl , mustache , neat-interpolation , network-uri , open-browser , optparse-applicative >=0.17.0.0 , pantry >=0.8.1 , path , path-io , persistent >=2.13.3.5 && <2.15 , persistent-sqlite , persistent-template , pretty , primitive , process >=1.6.13.2 , project-template , random , retry , rio >=0.1.22.0 , rio-prettyprint >=0.1.4.0 , semigroups , split , stack , stm , streaming-commons , tar , template-haskell , temporary , text , text-metrics , th-reify-many , time , tls , transformers , typed-process , unicode-transforms , unix-compat , unliftio , unordered-containers , vector , yaml , zip-archive , zlib default-language: Haskell2010 if os(windows) cpp-options: -DWINDOWS build-depends: Win32 else build-depends: unix build-tool-depends: hsc2hs:hsc2hs if flag(developer-mode) cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True else cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False if flag(static) ld-options: -static -pthread if !(flag(disable-git-info)) cpp-options: -DUSE_GIT_INFO build-depends: githash , optparse-simple if flag(hide-dependency-versions) cpp-options: -DHIDE_DEP_VERSIONS if flag(supported-build) cpp-options: -DSUPPORTED_BUILD executable stack-integration-test main-is: IntegrationSpec.hs other-modules: StackTest Paths_stack autogen-modules: Paths_stack hs-source-dirs: test/integration test/integration/lib ghc-options: -fwrite-ide-info -hiedir=.hie -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns -fwarn-incomplete-record-updates -optP-Wno-nonportable-include-path -threaded -rtsopts -with-rtsopts=-N build-depends: Cabal >=3.6.3.0 , aeson >=2.0.3.0 , annotated-wl-pprint , ansi-terminal , array , async , attoparsec , base >=4.14.3.0 && <5 , base64-bytestring , bytestring , casa-client , casa-types , colour , conduit , conduit-extra , containers , cryptonite , cryptonite-conduit , deepseq , directory , echo , exceptions , extra , file-embed , filelock , filepath , fsnotify >=0.4.1 , generic-deriving , hackage-security , hashable , hi-file-parser , hpack , hpc , hspec , http-client , http-client-tls , http-conduit , http-download , http-types , memory , microlens , mintty , mono-traversable , mtl , mustache , neat-interpolation , network-uri , open-browser , optparse-applicative >=0.17.0.0 , optparse-generic , pantry >=0.8.1 , path , path-io , persistent >=2.13.3.5 && <2.15 , persistent-sqlite , persistent-template , pretty , primitive , process >=1.6.13.2 , project-template , random , retry , rio >=0.1.22.0 , rio-prettyprint >=0.1.4.0 , semigroups , split , stm , streaming-commons , tar , template-haskell , temporary , text , text-metrics , th-reify-many , time , tls , transformers , typed-process , unicode-transforms , unix-compat , unliftio , unordered-containers , vector , yaml , zip-archive , zlib default-language: Haskell2010 if os(windows) cpp-options: -DWINDOWS build-depends: Win32 else build-depends: unix build-tool-depends: hsc2hs:hsc2hs if flag(developer-mode) cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True else cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False if !(flag(integration-tests)) buildable: False if flag(static) ld-options: -static -pthread test-suite stack-test type: exitcode-stdio-1.0 main-is: Spec.hs other-modules: Stack.ArgsSpec Stack.Build.ExecuteSpec Stack.Build.TargetSpec Stack.Config.DockerSpec Stack.ConfigSpec Stack.DotSpec Stack.Ghci.PortableFakePaths Stack.Ghci.ScriptSpec Stack.GhciSpec Stack.LockSpec Stack.NixSpec Stack.PackageDumpSpec Stack.Types.TemplateNameSpec Stack.UploadSpec Paths_stack autogen-modules: Paths_stack hs-source-dirs: src/test ghc-options: -fwrite-ide-info -hiedir=.hie -Wall -fwarn-tabs -fwarn-incomplete-uni-patterns -fwarn-incomplete-record-updates -optP-Wno-nonportable-include-path -threaded build-depends: Cabal >=3.6.3.0 , QuickCheck , aeson >=2.0.3.0 , annotated-wl-pprint , ansi-terminal , array , async , attoparsec , base >=4.14.3.0 && <5 , base64-bytestring , bytestring , casa-client , casa-types , colour , conduit , conduit-extra , containers , cryptonite , cryptonite-conduit , deepseq , directory , echo , exceptions , extra , file-embed , filelock , filepath , fsnotify >=0.4.1 , generic-deriving , hackage-security , hashable , hi-file-parser , hpack , hpc , hspec , http-client , http-client-tls , http-conduit , http-download , http-types , memory , microlens , mintty , mono-traversable , mtl , mustache , neat-interpolation , network-uri , open-browser , optparse-applicative >=0.17.0.0 , pantry >=0.8.1 , path , path-io , persistent >=2.13.3.5 && <2.15 , persistent-sqlite , persistent-template , pretty , primitive , process >=1.6.13.2 , project-template , random , raw-strings-qq , retry , rio >=0.1.22.0 , rio-prettyprint >=0.1.4.0 , semigroups , smallcheck , split , stack , stm , streaming-commons , tar , template-haskell , temporary , text , text-metrics , th-reify-many , time , tls , transformers , typed-process , unicode-transforms , unix-compat , unliftio , unordered-containers , vector , yaml , zip-archive , zlib default-language: Haskell2010 if os(windows) cpp-options: -DWINDOWS build-depends: Win32 else build-depends: unix build-tool-depends: hsc2hs:hsc2hs if flag(developer-mode) cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True else cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False build-tool-depends: hspec-discover:hspec-discover