Skip to content
3 changes: 1 addition & 2 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Control.Monad.IO.Class
import Control.Monad.Logger (MonadLogger, logWarn)
import Control.Monad.RWS.Strict
import Control.Monad.Trans.Resource
import qualified Data.ByteString.Char8 as S8
import Data.Either
import Data.Function
import Data.List
Expand Down Expand Up @@ -180,7 +179,7 @@ constructPlan mbp0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackag
, combinedMap = combineMap sourceMap installedMap
, toolToPackages = \ (Dependency name _) ->
maybe Map.empty (Map.fromSet (const anyVersion)) $
Map.lookup (S8.pack . packageNameString . fromCabalPackageName $ name) toolMap
Map.lookup (T.pack . packageNameString . fromCabalPackageName $ name) toolMap
, ctxEnvConfig = econfig
, callStack = []
, extraToBuild = extraToBuild0
Expand Down
52 changes: 25 additions & 27 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ import Control.Concurrent.MVar.Lifted
import Control.Concurrent.STM
import Control.Exception.Enclosed (catchIO, tryIO)
import Control.Exception.Lifted
import Control.Monad (liftM, when, unless, void, join, guard, filterM, (<=<))
import Control.Monad (liftM, when, unless, void, join, filterM, (<=<))
import Control.Monad.Catch (MonadCatch, MonadMask)
import Control.Monad.IO.Class
import Control.Monad.Logger
import Control.Monad.Reader (MonadReader, asks)
import Control.Monad.Trans.Control (liftBaseWith)
import Control.Monad.Trans.Resource
import Data.ByteString (ByteString)
import Data.Attoparsec.Text
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as S8
import Data.Conduit
import qualified Data.Conduit.Binary as CB
import qualified Data.Conduit.List as CL
import qualified Data.Conduit.Text as CT
import Data.Either (isRight)
import Data.Foldable (forM_, any)
import Data.Function
import Data.IORef.RunOnce (runOnce)
Expand All @@ -55,7 +56,6 @@ import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8)
import Data.Time.Clock (getCurrentTime)
import Data.Traversable (forM)
import Data.Word8 (_colon)
import qualified Distribution.PackageDescription as C
import Distribution.System (OS (Windows),
Platform (Platform))
Expand Down Expand Up @@ -828,6 +828,7 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
liftIO $ hClose h
runResourceT
$ CB.sourceFile (toFilePath logFile)
=$= CT.decodeUtf8
$$ mungeBuildOutput stripTHLoading makeAbsolute pkgDir
=$ CL.consume
throwM $ CabalExitedUnsuccessfully
Expand Down Expand Up @@ -1297,7 +1298,8 @@ singleBench runInBase beopts benchesToRun ac ee task installedMap = do
-- | Grab all output from the given @Handle@ and log it, stripping
-- Template Haskell "Loading package" lines and making paths absolute.
-- thread.
printBuildOutput :: (MonadIO m, MonadBaseControl IO m, MonadLogger m)
printBuildOutput :: (MonadIO m, MonadBaseControl IO m, MonadLogger m,
MonadThrow m)
=> Bool -- ^ exclude TH loading?
-> Bool -- ^ convert paths to absolute?
-> Path Abs Dir -- ^ package's root directory
Expand All @@ -1306,60 +1308,56 @@ printBuildOutput :: (MonadIO m, MonadBaseControl IO m, MonadLogger m)
-> m ()
printBuildOutput excludeTHLoading makeAbsolute pkgDir level outH = void $
CB.sourceHandle outH
$$ mungeBuildOutput excludeTHLoading makeAbsolute pkgDir
$$ CT.decodeUtf8
=$ mungeBuildOutput excludeTHLoading makeAbsolute pkgDir
=$ CL.mapM_ (monadLoggerLog $(TH.location >>= liftLoc) "" level)

-- | Strip Template Haskell "Loading package" lines and making paths absolute.
mungeBuildOutput :: MonadIO m
=> Bool -- ^ exclude TH loading?
-> Bool -- ^ convert paths to absolute?
-> Path Abs Dir -- ^ package's root directory
-> ConduitM ByteString ByteString m ()
-> ConduitM Text Text m ()
mungeBuildOutput excludeTHLoading makeAbsolute pkgDir = void $
CB.lines
CT.lines
=$ CL.map stripCarriageReturn
=$ CL.filter (not . isTHLoading)
=$ CL.mapM toAbsolutePath
where
-- | Is this line a Template Haskell "Loading package" line
-- ByteString
isTHLoading :: S8.ByteString -> Bool
isTHLoading :: Text -> Bool
isTHLoading _ | not excludeTHLoading = False
isTHLoading bs =
"Loading package " `S8.isPrefixOf` bs &&
("done." `S8.isSuffixOf` bs || "done.\r" `S8.isSuffixOf` bs)
"Loading package " `T.isPrefixOf` bs &&
("done." `T.isSuffixOf` bs || "done.\r" `T.isSuffixOf` bs)

-- | Convert GHC error lines with file paths to have absolute file paths
toAbsolutePath bs | not makeAbsolute = return bs
toAbsolutePath bs = do
let (x, y) = S.break (== _colon) bs
let (x, y) = T.break (== ':') bs
mabs <-
if isValidSuffix y
then do
efp <- liftIO $ tryIO $ resolveFile pkgDir (S8.unpack x)
efp <- liftIO $ tryIO $ resolveFile pkgDir (T.unpack x)
case efp of
Left _ -> return Nothing
Right fp -> return $ Just $ S8.pack (toFilePath fp)
Right fp -> return $ Just $ T.pack (toFilePath fp)
else return Nothing
case mabs of
Nothing -> return bs
Just fp -> return $ fp `S.append` y
Just fp -> return $ fp `T.append` y

-- | Match the line:column format at the end of lines
isValidSuffix bs0 = maybe False (const True) $ do
guard $ not $ S.null bs0
guard $ S.head bs0 == _colon
(_, bs1) <- S8.readInt $ S.drop 1 bs0

guard $ not $ S.null bs1
guard $ S.head bs1 == _colon
(_, bs2) <- S8.readInt $ S.drop 1 bs1

guard $ (bs2 == ":" || bs2 == ": Warning:")
isValidSuffix = isRight . parseOnly (lineCol <* endOfInput)
lineCol = char ':' >> (decimal :: Parser Int)
>> char ':' >> (decimal :: Parser Int)
>> (string ":" <|> string ": Warning:")
>> return ()

-- | Strip @\r@ characters from the byte vector. Used because Windows.
stripCarriageReturn :: ByteString -> ByteString
stripCarriageReturn = S8.filter (not . (=='\r'))
stripCarriageReturn :: Text -> Text
stripCarriageReturn = T.filter (/= '\r')

-- | Find the Setup.hs or Setup.lhs in the given directory. If none exists,
-- throw an exception.
Expand Down
5 changes: 3 additions & 2 deletions src/Stack/BuildPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Data.Maybe (fromMaybe, mapMaybe)
import Data.Monoid
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import Data.Time (Day)
Expand Down Expand Up @@ -283,7 +284,7 @@ addDeps allowMissing compilerVersion toCalc = do
}
name = packageIdentifierName ident
pd = resolvePackageDescription packageConfig gpd
exes = Set.fromList $ map (ExeName . S8.pack . exeName) $ executables pd
exes = Set.fromList $ map (ExeName . T.pack . exeName) $ executables pd
notMe = Set.filter (/= name) . Map.keysSet
return (name, MiniPackageInfo
{ mpiVersion = packageIdentifierVersion ident
Expand Down Expand Up @@ -368,7 +369,7 @@ getDeps mbp isShadowed packages =
type ToolMap = Map ByteString (Set PackageName)

-- | Map from tool name to package providing it
getToolMap :: MiniBuildPlan -> Map ByteString (Set PackageName)
getToolMap :: MiniBuildPlan -> Map Text (Set PackageName)
getToolMap mbp =
Map.unionsWith Set.union

Expand Down
2 changes: 1 addition & 1 deletion src/Stack/GhcPkg.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ findGhcPkgVersion :: (MonadIO m, MonadLogger m, MonadBaseControl IO m, MonadCatc
findGhcPkgVersion menv wc pkgDbs name = do
mv <- findGhcPkgField menv wc pkgDbs (packageNameString name) "version"
case mv of
Just !v -> return (parseVersion (T.encodeUtf8 v))
Just !v -> return (parseVersion v)
_ -> return Nothing

unregisterGhcPkgId :: (MonadIO m, MonadLogger m, MonadThrow m, MonadCatch m, MonadBaseControl IO m)
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,10 @@ packageDependencies =
allBuildInfo'

-- | Get all build tool dependencies of the package (buildable targets only).
packageToolDependencies :: PackageDescription -> Map BS.ByteString VersionRange
packageToolDependencies :: PackageDescription -> Map Text VersionRange
packageToolDependencies =
M.fromList .
concatMap (fmap (packageNameByteString . depName &&& depRange) .
concatMap (fmap (packageNameText . depName &&& depRange) .
buildTools) .
allBuildInfo'

Expand Down
Loading