{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE DeriveGeneric              #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings          #-}

-- | Build-specific types.

module Stack.Types.Build
    (StackBuildException(..)
    ,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           Stack.Prelude
import           Data.Aeson                      (ToJSON, FromJSON)
import qualified Data.ByteString                 as S
import           Data.Char                       (isSpace)
import           Data.List.Extra
import qualified Data.Map                        as Map
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)
import           Distribution.System             (Arch)
import qualified Distribution.Text               as C
import           Distribution.Version            (mkVersion)
import           Path                            (parseRelDir, (</>), parent)
import           Path.Extra                      (toFilePathNoTrailingSep)
import           Stack.Constants
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)
import           RIO.Process                     (showProcessArgDebug)

----------------------------------------------
-- Exceptions
data StackBuildException
  = 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
  | ConstructPlanFailed String
  | 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
  | ExecutionFailure [SomeException]
  | 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)
  deriving Typeable

data FlagSource = FSCommandLine | FSStackYaml
    deriving (Int -> FlagSource -> ShowS
[FlagSource] -> ShowS
FlagSource -> String
(Int -> FlagSource -> ShowS)
-> (FlagSource -> String)
-> ([FlagSource] -> ShowS)
-> Show FlagSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FlagSource] -> ShowS
$cshowList :: [FlagSource] -> ShowS
show :: FlagSource -> String
$cshow :: FlagSource -> String
showsPrec :: Int -> FlagSource -> ShowS
$cshowsPrec :: Int -> FlagSource -> ShowS
Show, FlagSource -> FlagSource -> Bool
(FlagSource -> FlagSource -> Bool)
-> (FlagSource -> FlagSource -> Bool) -> Eq FlagSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FlagSource -> FlagSource -> Bool
$c/= :: FlagSource -> FlagSource -> Bool
== :: FlagSource -> FlagSource -> Bool
$c== :: FlagSource -> FlagSource -> Bool
Eq, Eq FlagSource
Eq FlagSource
-> (FlagSource -> FlagSource -> Ordering)
-> (FlagSource -> FlagSource -> Bool)
-> (FlagSource -> FlagSource -> Bool)
-> (FlagSource -> FlagSource -> Bool)
-> (FlagSource -> FlagSource -> Bool)
-> (FlagSource -> FlagSource -> FlagSource)
-> (FlagSource -> FlagSource -> FlagSource)
-> Ord FlagSource
FlagSource -> FlagSource -> Bool
FlagSource -> FlagSource -> Ordering
FlagSource -> FlagSource -> FlagSource
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FlagSource -> FlagSource -> FlagSource
$cmin :: FlagSource -> FlagSource -> FlagSource
max :: FlagSource -> FlagSource -> FlagSource
$cmax :: FlagSource -> FlagSource -> FlagSource
>= :: FlagSource -> FlagSource -> Bool
$c>= :: FlagSource -> FlagSource -> Bool
> :: FlagSource -> FlagSource -> Bool
$c> :: FlagSource -> FlagSource -> Bool
<= :: FlagSource -> FlagSource -> Bool
$c<= :: FlagSource -> FlagSource -> Bool
< :: FlagSource -> FlagSource -> Bool
$c< :: FlagSource -> FlagSource -> Bool
compare :: FlagSource -> FlagSource -> Ordering
$ccompare :: FlagSource -> FlagSource -> Ordering
$cp1Ord :: Eq FlagSource
Ord)

data UnusedFlags = UFNoPackage FlagSource PackageName
                 | UFFlagsNotDefined
                       FlagSource
                       PackageName
                       (Set FlagName) -- defined in package
                       (Set FlagName) -- not defined
                 | UFSnapshot PackageName
    deriving (Int -> UnusedFlags -> ShowS
[UnusedFlags] -> ShowS
UnusedFlags -> String
(Int -> UnusedFlags -> ShowS)
-> (UnusedFlags -> String)
-> ([UnusedFlags] -> ShowS)
-> Show UnusedFlags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnusedFlags] -> ShowS
$cshowList :: [UnusedFlags] -> ShowS
show :: UnusedFlags -> String
$cshow :: UnusedFlags -> String
showsPrec :: Int -> UnusedFlags -> ShowS
$cshowsPrec :: Int -> UnusedFlags -> ShowS
Show, UnusedFlags -> UnusedFlags -> Bool
(UnusedFlags -> UnusedFlags -> Bool)
-> (UnusedFlags -> UnusedFlags -> Bool) -> Eq UnusedFlags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnusedFlags -> UnusedFlags -> Bool
$c/= :: UnusedFlags -> UnusedFlags -> Bool
== :: UnusedFlags -> UnusedFlags -> Bool
$c== :: UnusedFlags -> UnusedFlags -> Bool
Eq, Eq UnusedFlags
Eq UnusedFlags
-> (UnusedFlags -> UnusedFlags -> Ordering)
-> (UnusedFlags -> UnusedFlags -> Bool)
-> (UnusedFlags -> UnusedFlags -> Bool)
-> (UnusedFlags -> UnusedFlags -> Bool)
-> (UnusedFlags -> UnusedFlags -> Bool)
-> (UnusedFlags -> UnusedFlags -> UnusedFlags)
-> (UnusedFlags -> UnusedFlags -> UnusedFlags)
-> Ord UnusedFlags
UnusedFlags -> UnusedFlags -> Bool
UnusedFlags -> UnusedFlags -> Ordering
UnusedFlags -> UnusedFlags -> UnusedFlags
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: UnusedFlags -> UnusedFlags -> UnusedFlags
$cmin :: UnusedFlags -> UnusedFlags -> UnusedFlags
max :: UnusedFlags -> UnusedFlags -> UnusedFlags
$cmax :: UnusedFlags -> UnusedFlags -> UnusedFlags
>= :: UnusedFlags -> UnusedFlags -> Bool
$c>= :: UnusedFlags -> UnusedFlags -> Bool
> :: UnusedFlags -> UnusedFlags -> Bool
$c> :: UnusedFlags -> UnusedFlags -> Bool
<= :: UnusedFlags -> UnusedFlags -> Bool
$c<= :: UnusedFlags -> UnusedFlags -> Bool
< :: UnusedFlags -> UnusedFlags -> Bool
$c< :: UnusedFlags -> UnusedFlags -> Bool
compare :: UnusedFlags -> UnusedFlags -> Ordering
$ccompare :: UnusedFlags -> UnusedFlags -> Ordering
$cp1Ord :: Eq UnusedFlags
Ord)

instance Show StackBuildException where
    show :: StackBuildException -> String
show (Couldn'tFindPkgId PackageName
name) =
              String
"After installing " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> PackageName -> String
packageNameString PackageName
name String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
               String
", the package id couldn't be found " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"(via ghc-pkg describe " String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
               PackageName -> String
packageNameString PackageName
name String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"). This shouldn't happen, " String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
               String
"please report as a bug"
    show (CompilerVersionMismatch Maybe (ActualCompiler, Arch)
mactual (WantedCompiler
expected, Arch
earch) GHCVariant
ghcVariant CompilerBuild
ghcBuild VersionCheck
check Maybe (Path Abs File)
mstack Text
resolution) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
                [ case Maybe (ActualCompiler, Arch)
mactual of
                    Maybe (ActualCompiler, Arch)
Nothing -> String
"No compiler found, expected "
                    Just (ActualCompiler
actual, Arch
arch) -> [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
                        [ String
"Compiler version mismatched, found "
                        , ActualCompiler -> String
compilerVersionString ActualCompiler
actual
                        , String
" ("
                        , Arch -> String
forall a. Pretty a => a -> String
C.display Arch
arch
                        , String
")"
                        , String
", but expected "
                        ]
                , case VersionCheck
check of
                    VersionCheck
MatchMinor -> String
"minor version match with "
                    VersionCheck
MatchExact -> String
"exact version "
                    VersionCheck
NewerMinor -> String
"minor version match or newer with "
                , Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ Utf8Builder -> Text
utf8BuilderToText (Utf8Builder -> Text) -> Utf8Builder -> Text
forall a b. (a -> b) -> a -> b
$ WantedCompiler -> Utf8Builder
forall a. Display a => a -> Utf8Builder
display WantedCompiler
expected
                , String
" ("
                , Arch -> String
forall a. Pretty a => a -> String
C.display Arch
earch
                , GHCVariant -> String
ghcVariantSuffix GHCVariant
ghcVariant
                , CompilerBuild -> String
compilerBuildSuffix CompilerBuild
ghcBuild
                , String
") (based on "
                , case Maybe (Path Abs File)
mstack of
                    Maybe (Path Abs File)
Nothing -> String
"command line arguments"
                    Just Path Abs File
stack -> String
"resolver setting in " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs File -> String
forall b t. Path b t -> String
toFilePath Path Abs File
stack
                , String
").\n"
                , Text -> String
T.unpack Text
resolution
                ]
    show (Couldn'tParseTargets [Text]
targets) = [String] -> String
unlines
                ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ String
"The following targets could not be parsed as package names or directories:"
                String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack [Text]
targets
    show (UnknownTargets Set PackageName
noKnown Map PackageName Version
notInSnapshot Path Abs File
stackYaml) =
        [String] -> String
unlines ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [String]
noKnown' [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
notInSnapshot'
      where
        noKnown' :: [String]
noKnown'
            | Set PackageName -> Bool
forall a. Set a -> Bool
Set.null Set PackageName
noKnown = []
            | Bool
otherwise = String -> [String]
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> [String]) -> String -> [String]
forall a b. (a -> b) -> a -> b
$
                String
"The following target packages were not found: " String -> ShowS
forall a. [a] -> [a] -> [a]
++
                String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
", " ((PackageName -> String) -> [PackageName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map PackageName -> String
packageNameString ([PackageName] -> [String]) -> [PackageName] -> [String]
forall a b. (a -> b) -> a -> b
$ Set PackageName -> [PackageName]
forall a. Set a -> [a]
Set.toList Set PackageName
noKnown) String -> ShowS
forall a. [a] -> [a] -> [a]
++
                String
"\nSee https://docs.haskellstack.org/en/stable/build_command/#target-syntax for details."
        notInSnapshot' :: [String]
notInSnapshot'
            | Map PackageName Version -> Bool
forall k a. Map k a -> Bool
Map.null Map PackageName Version
notInSnapshot = []
            | Bool
otherwise =
                  String
"The following packages are not in your snapshot, but exist"
                String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String
"in your package index. Recommended action: add them to your"
                String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (String
"extra-deps in " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs File -> String
forall b t. Path b t -> String
toFilePath Path Abs File
stackYaml)
                String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String
"(Note: these are the most recent versions,"
                String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String
"but there's no guarantee that they'll build together)."
                String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String
""
                String -> [String] -> [String]
forall a. a -> [a] -> [a]
: ((PackageName, Version) -> String)
-> [(PackageName, Version)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map
                    (\(PackageName
name, Version
version') -> String
"- " String -> ShowS
forall a. [a] -> [a] -> [a]
++ PackageIdentifier -> String
packageIdentifierString
                        (PackageName -> Version -> PackageIdentifier
PackageIdentifier PackageName
name Version
version'))
                    (Map PackageName Version -> [(PackageName, Version)]
forall k a. Map k a -> [(k, a)]
Map.toList Map PackageName Version
notInSnapshot)
    show (TestSuiteFailure PackageIdentifier
ident Map Text (Maybe ExitCode)
codes Maybe (Path Abs File)
mlogFile ByteString
bs) = [String] -> String
unlines ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ [[String]] -> [String]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ [String
"Test suite failure for package " String -> ShowS
forall a. [a] -> [a] -> [a]
++ PackageIdentifier -> String
packageIdentifierString PackageIdentifier
ident]
        , (((Text, Maybe ExitCode) -> String)
 -> [(Text, Maybe ExitCode)] -> [String])
-> [(Text, Maybe ExitCode)]
-> ((Text, Maybe ExitCode) -> String)
-> [String]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Text, Maybe ExitCode) -> String)
-> [(Text, Maybe ExitCode)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (Map Text (Maybe ExitCode) -> [(Text, Maybe ExitCode)]
forall k a. Map k a -> [(k, a)]
Map.toList Map Text (Maybe ExitCode)
codes) (((Text, Maybe ExitCode) -> String) -> [String])
-> ((Text, Maybe ExitCode) -> String) -> [String]
forall a b. (a -> b) -> a -> b
$ \(Text
name, Maybe ExitCode
mcode) -> [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
            [ String
"    "
            , Text -> String
T.unpack Text
name
            , String
": "
            , case Maybe ExitCode
mcode of
                Maybe ExitCode
Nothing -> String
" executable not found"
                Just ExitCode
ec -> String
" exited with: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ExitCode -> String
forall a. Show a => a -> String
show ExitCode
ec
            ]
        , String -> [String]
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> [String]) -> String -> [String]
forall a b. (a -> b) -> a -> b
$ case Maybe (Path Abs File)
mlogFile of
            Maybe (Path Abs File)
Nothing -> String
"Logs printed to console"
            -- TODO Should we load up the full error output and print it here?
            Just Path Abs File
logFile -> String
"Full log available at " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs File -> String
forall b t. Path b t -> String
toFilePath Path Abs File
logFile
        , if ByteString -> Bool
S.null ByteString
bs
            then []
            else [String
"", String
"", ShowS
doubleIndent ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ OnDecodeError -> ByteString -> Text
decodeUtf8With OnDecodeError
lenientDecode ByteString
bs]
        ]
         where
          indent :: ShowS
indent = (Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhileEnd Char -> Bool
isSpace ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
unlines ([String] -> String) -> (String -> [String]) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS -> [String] -> [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\String
line -> String
"  " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
line) ([String] -> [String])
-> (String -> [String]) -> String -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines
          doubleIndent :: ShowS
doubleIndent = ShowS
indent ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS
indent
    show (TestSuiteTypeUnsupported TestSuiteInterface
interface) =
              String
"Unsupported test suite type: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> TestSuiteInterface -> String
forall a. Show a => a -> String
show TestSuiteInterface
interface
     -- Supressing duplicate output
    show (CabalExitedUnsuccessfully ExitCode
exitCode PackageIdentifier
taskProvides' Path Abs File
execName [String]
fullArgs Maybe (Path Abs File)
logFiles [Text]
bss) =
      Bool
-> ExitCode
-> Maybe PackageIdentifier
-> Path Abs File
-> [String]
-> Maybe (Path Abs File)
-> [Text]
-> String
showBuildError Bool
False ExitCode
exitCode (PackageIdentifier -> Maybe PackageIdentifier
forall a. a -> Maybe a
Just PackageIdentifier
taskProvides') Path Abs File
execName [String]
fullArgs Maybe (Path Abs File)
logFiles [Text]
bss
    show (SetupHsBuildFailure ExitCode
exitCode Maybe PackageIdentifier
mtaskProvides Path Abs File
execName [String]
fullArgs Maybe (Path Abs File)
logFiles [Text]
bss) =
      Bool
-> ExitCode
-> Maybe PackageIdentifier
-> Path Abs File
-> [String]
-> Maybe (Path Abs File)
-> [Text]
-> String
showBuildError Bool
True ExitCode
exitCode Maybe PackageIdentifier
mtaskProvides Path Abs File
execName [String]
fullArgs Maybe (Path Abs File)
logFiles [Text]
bss
    show (ExecutionFailure [SomeException]
es) = String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"\n\n" ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ (SomeException -> String) -> [SomeException] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map SomeException -> String
forall a. Show a => a -> String
show [SomeException]
es
    show (LocalPackageDoesn'tMatchTarget PackageName
name Version
localV Version
requestedV) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ String
"Version for local package "
        , PackageName -> String
packageNameString PackageName
name
        , String
" is "
        , Version -> String
versionString Version
localV
        , String
", but you asked for "
        , Version -> String
versionString Version
requestedV
        , String
" on the command line"
        ]
    show (NoSetupHsFound Path Abs Dir
dir) =
        String
"No Setup.hs or Setup.lhs file found in " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall b t. Path b t -> String
toFilePath Path Abs Dir
dir
    show (InvalidFlagSpecification Set UnusedFlags
unused) = [String] -> String
unlines
        ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ String
"Invalid flag specification:"
        String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (UnusedFlags -> String) -> [UnusedFlags] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map UnusedFlags -> String
go (Set UnusedFlags -> [UnusedFlags]
forall a. Set a -> [a]
Set.toList Set UnusedFlags
unused)
      where
        showFlagSrc :: FlagSource -> String
        showFlagSrc :: FlagSource -> String
showFlagSrc FlagSource
FSCommandLine = String
" (specified on command line)"
        showFlagSrc FlagSource
FSStackYaml = String
" (specified in stack.yaml)"

        go :: UnusedFlags -> String
        go :: UnusedFlags -> String
go (UFNoPackage FlagSource
src PackageName
name) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
            [ String
"- Package '"
            , PackageName -> String
packageNameString PackageName
name
            , String
"' not found"
            , FlagSource -> String
showFlagSrc FlagSource
src
            ]
        go (UFFlagsNotDefined FlagSource
src PackageName
pname Set FlagName
pkgFlags Set FlagName
flags) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
            [ String
"- Package '"
            , String
name
            , String
"' does not define the following flags"
            , FlagSource -> String
showFlagSrc FlagSource
src
            , String
":\n"
            , String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"\n"
                          ((FlagName -> String) -> [FlagName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\FlagName
flag -> String
"  " String -> ShowS
forall a. [a] -> [a] -> [a]
++ FlagName -> String
flagNameString FlagName
flag)
                               (Set FlagName -> [FlagName]
forall a. Set a -> [a]
Set.toList Set FlagName
flags))
            , String
"\n- Flags defined by package '" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
name String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"':\n"
            , String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"\n"
                          ((FlagName -> String) -> [FlagName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\FlagName
flag -> String
"  " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
name String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ FlagName -> String
flagNameString FlagName
flag)
                               (Set FlagName -> [FlagName]
forall a. Set a -> [a]
Set.toList Set FlagName
pkgFlags))
            ]
          where name :: String
name = PackageName -> String
packageNameString PackageName
pname
        go (UFSnapshot PackageName
name) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
            [ String
"- Attempted to set flag on snapshot package "
            , PackageName -> String
packageNameString PackageName
name
            , String
", please add to extra-deps"
            ]
    show (InvalidGhcOptionsSpecification [PackageName]
unused) = [String] -> String
unlines
        ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ String
"Invalid GHC options specification:"
        String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (PackageName -> String) -> [PackageName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map PackageName -> String
showGhcOptionSrc [PackageName]
unused
      where
        showGhcOptionSrc :: PackageName -> String
showGhcOptionSrc PackageName
name = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
            [ String
"- Package '"
            , PackageName -> String
packageNameString PackageName
name
            , String
"' not found"
            ]
    show (TargetParseException [Text
err]) = String
"Error parsing targets: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
err
    show (TargetParseException [Text]
errs) = [String] -> String
unlines
        ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ String
"The following errors occurred while parsing the build targets:"
        String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ((String
"- " String -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> (Text -> String) -> Text -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack) [Text]
errs

    show (SomeTargetsNotBuildable [(PackageName, NamedComponent)]
xs) =
        String
"The following components have 'buildable: False' set in the cabal configuration, and so cannot be targets:\n    " String -> ShowS
forall a. [a] -> [a] -> [a]
++
        Text -> String
T.unpack ([(PackageName, NamedComponent)] -> Text
renderPkgComponents [(PackageName, NamedComponent)]
xs) String -> ShowS
forall a. [a] -> [a] -> [a]
++
        String
"\nTo resolve this, either provide flags such that these components are buildable, or only specify buildable targets."
    show (TestSuiteExeMissing Bool
isSimpleBuildType String
exeName String
pkgName' String
testName) =
        Bool -> ShowS
missingExeError Bool
isSimpleBuildType ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
            [ String
"Test suite executable \""
            , String
exeName
            , String
" not found for "
            , String
pkgName'
            , String
":test:"
            , String
testName
            ]
    show (CabalCopyFailed Bool
isSimpleBuildType String
innerMsg) =
        Bool -> ShowS
missingExeError Bool
isSimpleBuildType ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
            [ String
"'cabal copy' failed.  Error message:\n"
            , String
innerMsg
            , String
"\n"
            ]
    show (ConstructPlanFailed String
msg) = String
msg
    show (LocalPackagesPresent [PackageIdentifier]
locals) = [String] -> String
unlines
      ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ String
"Local packages are not allowed when using the script command. Packages found:"
      String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (PackageIdentifier -> String) -> [PackageIdentifier] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\PackageIdentifier
ident -> String
"- " String -> ShowS
forall a. [a] -> [a] -> [a]
++ PackageIdentifier -> String
packageIdentifierString PackageIdentifier
ident) [PackageIdentifier]
locals
    show (CouldNotLockDistDir Path Abs File
lockFile) = [String] -> String
unlines
      [ String
"Locking the dist directory failed, try to lock file:"
      , String
"  " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs File -> String
forall b t. Path b t -> String
toFilePath Path Abs File
lockFile
      , String
"Maybe you're running another copy of Stack?"
      ]

missingExeError :: Bool -> String -> String
missingExeError :: Bool -> ShowS
missingExeError Bool
isSimpleBuildType String
msg =
    [String] -> String
unlines ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ String
msg String -> [String] -> [String]
forall a. a -> [a] -> [a]
:
        case [String]
possibleCauses of
            [] -> []
            [String
cause] -> [String
"One possible cause of this issue is:\n* " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
cause]
            [String]
_ -> String
"Possible causes of this issue:" String -> [String] -> [String]
forall a. a -> [a] -> [a]
: ShowS -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String
"* " String -> ShowS
forall a. Semigroup a => a -> a -> a
<>) [String]
possibleCauses
  where
    possibleCauses :: [String]
possibleCauses =
        String
"No module named \"Main\". The 'main-is' source file should usually have a header indicating that it's a 'Main' module." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:
        String
"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." String -> [String] -> [String]
forall a. a -> [a] -> [a]
:
        if Bool
isSimpleBuildType
            then []
            else [String
"The Setup.hs file is changing the installation target dir."]

showBuildError
  :: Bool
  -> ExitCode
  -> Maybe PackageIdentifier
  -> Path Abs File
  -> [String]
  -> Maybe (Path Abs File)
  -> [Text]
  -> String
showBuildError :: Bool
-> ExitCode
-> Maybe PackageIdentifier
-> Path Abs File
-> [String]
-> Maybe (Path Abs File)
-> [Text]
-> String
showBuildError Bool
isBuildingSetup ExitCode
exitCode Maybe PackageIdentifier
mtaskProvides Path Abs File
execName [String]
fullArgs Maybe (Path Abs File)
logFiles [Text]
bss =
  let fullCmd :: String
fullCmd = [String] -> String
unwords
              ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ ShowS
dropQuotes (Path Abs File -> String
forall b t. Path b t -> String
toFilePath Path Abs File
execName)
              String -> [String] -> [String]
forall a. a -> [a] -> [a]
: ShowS -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> String
T.unpack (Text -> String) -> (String -> Text) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
showProcessArgDebug) [String]
fullArgs
      logLocations :: String
logLocations = String
-> (Path Abs File -> String) -> Maybe (Path Abs File) -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe String
"" (\Path Abs File
fp -> String
"\n    Logs have been written to: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs File -> String
forall b t. Path b t -> String
toFilePath Path Abs File
fp) Maybe (Path Abs File)
logFiles
  in String
"\n--  While building " String -> ShowS
forall a. [a] -> [a] -> [a]
++
     (case (Bool
isBuildingSetup, Maybe PackageIdentifier
mtaskProvides) of
       (Bool
False, Maybe PackageIdentifier
Nothing) -> ShowS
forall a. HasCallStack => String -> a
error String
"Invariant violated: unexpected case in showBuildError"
       (Bool
False, Just PackageIdentifier
taskProvides') -> String
"package " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
dropQuotes (PackageIdentifier -> String
packageIdentifierString PackageIdentifier
taskProvides')
       (Bool
True, Maybe PackageIdentifier
Nothing) -> String
"simple Setup.hs"
       (Bool
True, Just PackageIdentifier
taskProvides') -> String
"custom Setup.hs for package " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
dropQuotes (PackageIdentifier -> String
packageIdentifierString PackageIdentifier
taskProvides')
     ) String -> ShowS
forall a. [a] -> [a] -> [a]
++
     String
" (scroll up to its section to see the error) using:\n      " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
fullCmd String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++
     String
"    Process exited with code: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ExitCode -> String
forall a. Show a => a -> String
show ExitCode
exitCode String -> ShowS
forall a. [a] -> [a] -> [a]
++
     (if ExitCode
exitCode ExitCode -> ExitCode -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> ExitCode
ExitFailure (-Int
9)
          then String
" (THIS MAY INDICATE OUT OF MEMORY)"
          else String
"") String -> ShowS
forall a. [a] -> [a] -> [a]
++
     String
logLocations String -> ShowS
forall a. [a] -> [a] -> [a]
++
     (if [Text] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Text]
bss
          then String
""
          else String
"\n\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
doubleIndent ((Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack [Text]
bss))
   where
    doubleIndent :: [String] -> String
doubleIndent = (Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
dropWhileEnd Char -> Bool
isSpace ShowS -> ([String] -> String) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> String
unlines ([String] -> String)
-> ([String] -> [String]) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShowS -> [String] -> [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\String
line -> String
"    " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
line)
    dropQuotes :: ShowS
dropQuotes = (Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
filter (Char
'\"' Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=)

instance Exception StackBuildException

----------------------------------------------

-- | Package dependency oracle.
newtype PkgDepsOracle =
    PkgDeps PackageName
    deriving (Int -> PkgDepsOracle -> ShowS
[PkgDepsOracle] -> ShowS
PkgDepsOracle -> String
(Int -> PkgDepsOracle -> ShowS)
-> (PkgDepsOracle -> String)
-> ([PkgDepsOracle] -> ShowS)
-> Show PkgDepsOracle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PkgDepsOracle] -> ShowS
$cshowList :: [PkgDepsOracle] -> ShowS
show :: PkgDepsOracle -> String
$cshow :: PkgDepsOracle -> String
showsPrec :: Int -> PkgDepsOracle -> ShowS
$cshowsPrec :: Int -> PkgDepsOracle -> ShowS
Show,Typeable,PkgDepsOracle -> PkgDepsOracle -> Bool
(PkgDepsOracle -> PkgDepsOracle -> Bool)
-> (PkgDepsOracle -> PkgDepsOracle -> Bool) -> Eq PkgDepsOracle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PkgDepsOracle -> PkgDepsOracle -> Bool
$c/= :: PkgDepsOracle -> PkgDepsOracle -> Bool
== :: PkgDepsOracle -> PkgDepsOracle -> Bool
$c== :: PkgDepsOracle -> PkgDepsOracle -> Bool
Eq,PkgDepsOracle -> ()
(PkgDepsOracle -> ()) -> NFData PkgDepsOracle
forall a. (a -> ()) -> NFData a
rnf :: PkgDepsOracle -> ()
$crnf :: PkgDepsOracle -> ()
NFData)

-- | Stored on disk to know whether the files have changed.
newtype BuildCache = BuildCache
    { BuildCache -> Map String FileCacheInfo
buildCacheTimes :: Map FilePath FileCacheInfo
      -- ^ Modification times of files.
    }
    deriving ((forall x. BuildCache -> Rep BuildCache x)
-> (forall x. Rep BuildCache x -> BuildCache) -> Generic BuildCache
forall x. Rep BuildCache x -> BuildCache
forall x. BuildCache -> Rep BuildCache x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BuildCache x -> BuildCache
$cfrom :: forall x. BuildCache -> Rep BuildCache x
Generic, BuildCache -> BuildCache -> Bool
(BuildCache -> BuildCache -> Bool)
-> (BuildCache -> BuildCache -> Bool) -> Eq BuildCache
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildCache -> BuildCache -> Bool
$c/= :: BuildCache -> BuildCache -> Bool
== :: BuildCache -> BuildCache -> Bool
$c== :: BuildCache -> BuildCache -> Bool
Eq, Int -> BuildCache -> ShowS
[BuildCache] -> ShowS
BuildCache -> String
(Int -> BuildCache -> ShowS)
-> (BuildCache -> String)
-> ([BuildCache] -> ShowS)
-> Show BuildCache
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BuildCache] -> ShowS
$cshowList :: [BuildCache] -> ShowS
show :: BuildCache -> String
$cshow :: BuildCache -> String
showsPrec :: Int -> BuildCache -> ShowS
$cshowsPrec :: Int -> BuildCache -> ShowS
Show, Typeable, [BuildCache] -> Encoding
[BuildCache] -> Value
BuildCache -> Encoding
BuildCache -> Value
(BuildCache -> Value)
-> (BuildCache -> Encoding)
-> ([BuildCache] -> Value)
-> ([BuildCache] -> Encoding)
-> ToJSON BuildCache
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [BuildCache] -> Encoding
$ctoEncodingList :: [BuildCache] -> Encoding
toJSONList :: [BuildCache] -> Value
$ctoJSONList :: [BuildCache] -> Value
toEncoding :: BuildCache -> Encoding
$ctoEncoding :: BuildCache -> Encoding
toJSON :: BuildCache -> Value
$ctoJSON :: BuildCache -> Value
ToJSON, Value -> Parser [BuildCache]
Value -> Parser BuildCache
(Value -> Parser BuildCache)
-> (Value -> Parser [BuildCache]) -> FromJSON BuildCache
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BuildCache]
$cparseJSONList :: Value -> Parser [BuildCache]
parseJSON :: Value -> Parser BuildCache
$cparseJSON :: Value -> Parser BuildCache
FromJSON)
instance NFData BuildCache

-- | Stored on disk to know whether the flags have changed.
data ConfigCache = ConfigCache
    { ConfigCache -> ConfigureOpts
configCacheOpts :: !ConfigureOpts
      -- ^ All options used for this package.
    , ConfigCache -> Set GhcPkgId
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.
    , ConfigCache -> Set ByteString
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.
    , ConfigCache -> Bool
configCacheHaddock :: !Bool
      -- ^ Are haddocks to be built?
    , ConfigCache -> CachePkgSrc
configCachePkgSrc :: !CachePkgSrc
    , ConfigCache -> Text
configCachePathEnvVar :: !Text
    -- ^ Value of the PATH env var, see <https://github.com/commercialhaskell/stack/issues/3138>
    }
    deriving ((forall x. ConfigCache -> Rep ConfigCache x)
-> (forall x. Rep ConfigCache x -> ConfigCache)
-> Generic ConfigCache
forall x. Rep ConfigCache x -> ConfigCache
forall x. ConfigCache -> Rep ConfigCache x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConfigCache x -> ConfigCache
$cfrom :: forall x. ConfigCache -> Rep ConfigCache x
Generic, ConfigCache -> ConfigCache -> Bool
(ConfigCache -> ConfigCache -> Bool)
-> (ConfigCache -> ConfigCache -> Bool) -> Eq ConfigCache
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfigCache -> ConfigCache -> Bool
$c/= :: ConfigCache -> ConfigCache -> Bool
== :: ConfigCache -> ConfigCache -> Bool
$c== :: ConfigCache -> ConfigCache -> Bool
Eq, Int -> ConfigCache -> ShowS
[ConfigCache] -> ShowS
ConfigCache -> String
(Int -> ConfigCache -> ShowS)
-> (ConfigCache -> String)
-> ([ConfigCache] -> ShowS)
-> Show ConfigCache
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfigCache] -> ShowS
$cshowList :: [ConfigCache] -> ShowS
show :: ConfigCache -> String
$cshow :: ConfigCache -> String
showsPrec :: Int -> ConfigCache -> ShowS
$cshowsPrec :: Int -> ConfigCache -> ShowS
Show, Typeable ConfigCache
DataType
Constr
Typeable ConfigCache
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ConfigCache -> c ConfigCache)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ConfigCache)
-> (ConfigCache -> Constr)
-> (ConfigCache -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ConfigCache))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ConfigCache))
-> ((forall b. Data b => b -> b) -> ConfigCache -> ConfigCache)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ConfigCache -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ConfigCache -> r)
-> (forall u. (forall d. Data d => d -> u) -> ConfigCache -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ConfigCache -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache)
-> Data ConfigCache
ConfigCache -> DataType
ConfigCache -> Constr
(forall b. Data b => b -> b) -> ConfigCache -> ConfigCache
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigCache -> c ConfigCache
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigCache
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ConfigCache -> u
forall u. (forall d. Data d => d -> u) -> ConfigCache -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigCache
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigCache -> c ConfigCache
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConfigCache)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigCache)
$cConfigCache :: Constr
$tConfigCache :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
gmapMp :: (forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
gmapM :: (forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
gmapQi :: Int -> (forall d. Data d => d -> u) -> ConfigCache -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ConfigCache -> u
gmapQ :: (forall d. Data d => d -> u) -> ConfigCache -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ConfigCache -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
gmapT :: (forall b. Data b => b -> b) -> ConfigCache -> ConfigCache
$cgmapT :: (forall b. Data b => b -> b) -> ConfigCache -> ConfigCache
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigCache)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigCache)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ConfigCache)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConfigCache)
dataTypeOf :: ConfigCache -> DataType
$cdataTypeOf :: ConfigCache -> DataType
toConstr :: ConfigCache -> Constr
$ctoConstr :: ConfigCache -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigCache
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigCache
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigCache -> c ConfigCache
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigCache -> c ConfigCache
$cp1Data :: Typeable ConfigCache
Data, Typeable)
instance NFData ConfigCache

data CachePkgSrc = CacheSrcUpstream | CacheSrcLocal FilePath
    deriving ((forall x. CachePkgSrc -> Rep CachePkgSrc x)
-> (forall x. Rep CachePkgSrc x -> CachePkgSrc)
-> Generic CachePkgSrc
forall x. Rep CachePkgSrc x -> CachePkgSrc
forall x. CachePkgSrc -> Rep CachePkgSrc x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CachePkgSrc x -> CachePkgSrc
$cfrom :: forall x. CachePkgSrc -> Rep CachePkgSrc x
Generic, CachePkgSrc -> CachePkgSrc -> Bool
(CachePkgSrc -> CachePkgSrc -> Bool)
-> (CachePkgSrc -> CachePkgSrc -> Bool) -> Eq CachePkgSrc
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CachePkgSrc -> CachePkgSrc -> Bool
$c/= :: CachePkgSrc -> CachePkgSrc -> Bool
== :: CachePkgSrc -> CachePkgSrc -> Bool
$c== :: CachePkgSrc -> CachePkgSrc -> Bool
Eq, ReadPrec [CachePkgSrc]
ReadPrec CachePkgSrc
Int -> ReadS CachePkgSrc
ReadS [CachePkgSrc]
(Int -> ReadS CachePkgSrc)
-> ReadS [CachePkgSrc]
-> ReadPrec CachePkgSrc
-> ReadPrec [CachePkgSrc]
-> Read CachePkgSrc
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CachePkgSrc]
$creadListPrec :: ReadPrec [CachePkgSrc]
readPrec :: ReadPrec CachePkgSrc
$creadPrec :: ReadPrec CachePkgSrc
readList :: ReadS [CachePkgSrc]
$creadList :: ReadS [CachePkgSrc]
readsPrec :: Int -> ReadS CachePkgSrc
$creadsPrec :: Int -> ReadS CachePkgSrc
Read, Int -> CachePkgSrc -> ShowS
[CachePkgSrc] -> ShowS
CachePkgSrc -> String
(Int -> CachePkgSrc -> ShowS)
-> (CachePkgSrc -> String)
-> ([CachePkgSrc] -> ShowS)
-> Show CachePkgSrc
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CachePkgSrc] -> ShowS
$cshowList :: [CachePkgSrc] -> ShowS
show :: CachePkgSrc -> String
$cshow :: CachePkgSrc -> String
showsPrec :: Int -> CachePkgSrc -> ShowS
$cshowsPrec :: Int -> CachePkgSrc -> ShowS
Show, Typeable CachePkgSrc
DataType
Constr
Typeable CachePkgSrc
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CachePkgSrc -> c CachePkgSrc)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c CachePkgSrc)
-> (CachePkgSrc -> Constr)
-> (CachePkgSrc -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c CachePkgSrc))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c CachePkgSrc))
-> ((forall b. Data b => b -> b) -> CachePkgSrc -> CachePkgSrc)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r)
-> (forall u. (forall d. Data d => d -> u) -> CachePkgSrc -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> CachePkgSrc -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc)
-> Data CachePkgSrc
CachePkgSrc -> DataType
CachePkgSrc -> Constr
(forall b. Data b => b -> b) -> CachePkgSrc -> CachePkgSrc
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CachePkgSrc -> c CachePkgSrc
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CachePkgSrc
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> CachePkgSrc -> u
forall u. (forall d. Data d => d -> u) -> CachePkgSrc -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CachePkgSrc
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CachePkgSrc -> c CachePkgSrc
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CachePkgSrc)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CachePkgSrc)
$cCacheSrcLocal :: Constr
$cCacheSrcUpstream :: Constr
$tCachePkgSrc :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
gmapMp :: (forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
gmapM :: (forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
gmapQi :: Int -> (forall d. Data d => d -> u) -> CachePkgSrc -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CachePkgSrc -> u
gmapQ :: (forall d. Data d => d -> u) -> CachePkgSrc -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CachePkgSrc -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
gmapT :: (forall b. Data b => b -> b) -> CachePkgSrc -> CachePkgSrc
$cgmapT :: (forall b. Data b => b -> b) -> CachePkgSrc -> CachePkgSrc
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CachePkgSrc)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CachePkgSrc)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c CachePkgSrc)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CachePkgSrc)
dataTypeOf :: CachePkgSrc -> DataType
$cdataTypeOf :: CachePkgSrc -> DataType
toConstr :: CachePkgSrc -> Constr
$ctoConstr :: CachePkgSrc -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CachePkgSrc
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CachePkgSrc
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CachePkgSrc -> c CachePkgSrc
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CachePkgSrc -> c CachePkgSrc
$cp1Data :: Typeable CachePkgSrc
Data, Typeable)
instance NFData CachePkgSrc

instance PersistField CachePkgSrc where
    toPersistValue :: CachePkgSrc -> PersistValue
toPersistValue CachePkgSrc
CacheSrcUpstream = Text -> PersistValue
PersistText Text
"upstream"
    toPersistValue (CacheSrcLocal String
fp) = Text -> PersistValue
PersistText (Text
"local:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack String
fp)
    fromPersistValue :: PersistValue -> Either Text CachePkgSrc
fromPersistValue (PersistText Text
t) = do
        if Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"upstream"
            then CachePkgSrc -> Either Text CachePkgSrc
forall a b. b -> Either a b
Right CachePkgSrc
CacheSrcUpstream
            else case Text -> Text -> Maybe Text
T.stripPrefix Text
"local:" Text
t of
                Just Text
fp -> CachePkgSrc -> Either Text CachePkgSrc
forall a b. b -> Either a b
Right (CachePkgSrc -> Either Text CachePkgSrc)
-> CachePkgSrc -> Either Text CachePkgSrc
forall a b. (a -> b) -> a -> b
$ String -> CachePkgSrc
CacheSrcLocal (Text -> String
T.unpack Text
fp)
                Maybe Text
Nothing -> Text -> Either Text CachePkgSrc
forall a b. a -> Either a b
Left (Text -> Either Text CachePkgSrc)
-> Text -> Either Text CachePkgSrc
forall a b. (a -> b) -> a -> b
$ Text
"Unexpected CachePkgSrc value: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t
    fromPersistValue PersistValue
_ = Text -> Either Text CachePkgSrc
forall a b. a -> Either a b
Left Text
"Unexpected CachePkgSrc type"

instance PersistFieldSql CachePkgSrc where
    sqlType :: Proxy CachePkgSrc -> SqlType
sqlType Proxy CachePkgSrc
_ = SqlType
SqlString

toCachePkgSrc :: PackageSource -> CachePkgSrc
toCachePkgSrc :: PackageSource -> CachePkgSrc
toCachePkgSrc (PSFilePath LocalPackage
lp) = String -> CachePkgSrc
CacheSrcLocal (Path Abs Dir -> String
forall b t. Path b t -> String
toFilePath (Path Abs File -> Path Abs Dir
forall b t. Path b t -> Path b Dir
parent (LocalPackage -> Path Abs File
lpCabalFile LocalPackage
lp)))
toCachePkgSrc PSRemote{} = CachePkgSrc
CacheSrcUpstream

-- | A task to perform when building
data Task = Task
    { Task -> PackageIdentifier
taskProvides        :: !PackageIdentifier -- FIXME turn this into a function on taskType?
    -- ^ the package/version to be built
    , Task -> TaskType
taskType            :: !TaskType
    -- ^ the task type, telling us how to build this
    , Task -> TaskConfigOpts
taskConfigOpts      :: !TaskConfigOpts
    , Task -> Bool
taskBuildHaddock    :: !Bool
    , Task -> Map PackageIdentifier GhcPkgId
taskPresent         :: !(Map PackageIdentifier GhcPkgId)
    -- ^ GhcPkgIds of already-installed dependencies
    , Task -> Bool
taskAllInOne        :: !Bool
    -- ^ indicates that the package can be built in one step
    , Task -> CachePkgSrc
taskCachePkgSrc     :: !CachePkgSrc
    , Task -> Bool
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:
    -- <https://github.com/haskell/cabal/issues/4728#issuecomment-337937673>. 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.
    , Task -> Bool
taskBuildTypeConfig :: !Bool
    -- ^ Is the build type of this package Configure. Check out
    -- ensureConfigureScript in Stack.Build.Execute for the motivation
    }
    deriving Int -> Task -> ShowS
[Task] -> ShowS
Task -> String
(Int -> Task -> ShowS)
-> (Task -> String) -> ([Task] -> ShowS) -> Show Task
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Task] -> ShowS
$cshowList :: [Task] -> ShowS
show :: Task -> String
$cshow :: Task -> String
showsPrec :: Int -> Task -> ShowS
$cshowsPrec :: Int -> Task -> ShowS
Show

-- | Given the IDs of any missing packages, produce the configure options
data TaskConfigOpts = TaskConfigOpts
    { TaskConfigOpts -> Set PackageIdentifier
tcoMissing :: !(Set PackageIdentifier)
      -- ^ Dependencies for which we don't yet have an GhcPkgId
    , TaskConfigOpts -> Map PackageIdentifier GhcPkgId -> ConfigureOpts
tcoOpts    :: !(Map PackageIdentifier GhcPkgId -> ConfigureOpts)
      -- ^ Produce the list of options given the missing @GhcPkgId@s
    }
instance Show TaskConfigOpts where
    show :: TaskConfigOpts -> String
show (TaskConfigOpts Set PackageIdentifier
missing Map PackageIdentifier GhcPkgId -> ConfigureOpts
f) = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ String
"Missing: "
        , Set PackageIdentifier -> String
forall a. Show a => a -> String
show Set PackageIdentifier
missing
        , String
". Without those: "
        , ConfigureOpts -> String
forall a. Show a => a -> String
show (ConfigureOpts -> String) -> ConfigureOpts -> String
forall a b. (a -> b) -> a -> b
$ Map PackageIdentifier GhcPkgId -> ConfigureOpts
f Map PackageIdentifier GhcPkgId
forall k a. Map k a
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 Int -> TaskType -> ShowS
[TaskType] -> ShowS
TaskType -> String
(Int -> TaskType -> ShowS)
-> (TaskType -> String) -> ([TaskType] -> ShowS) -> Show TaskType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TaskType] -> ShowS
$cshowList :: [TaskType] -> ShowS
show :: TaskType -> String
$cshow :: TaskType -> String
showsPrec :: Int -> TaskType -> ShowS
$cshowsPrec :: Int -> TaskType -> ShowS
Show

data IsMutable
    = Mutable
    | Immutable
    deriving (IsMutable -> IsMutable -> Bool
(IsMutable -> IsMutable -> Bool)
-> (IsMutable -> IsMutable -> Bool) -> Eq IsMutable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IsMutable -> IsMutable -> Bool
$c/= :: IsMutable -> IsMutable -> Bool
== :: IsMutable -> IsMutable -> Bool
$c== :: IsMutable -> IsMutable -> Bool
Eq, Int -> IsMutable -> ShowS
[IsMutable] -> ShowS
IsMutable -> String
(Int -> IsMutable -> ShowS)
-> (IsMutable -> String)
-> ([IsMutable] -> ShowS)
-> Show IsMutable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IsMutable] -> ShowS
$cshowList :: [IsMutable] -> ShowS
show :: IsMutable -> String
$cshow :: IsMutable -> String
showsPrec :: Int -> IsMutable -> ShowS
$cshowsPrec :: Int -> IsMutable -> ShowS
Show)

instance Semigroup IsMutable where
    IsMutable
Mutable <> :: IsMutable -> IsMutable -> IsMutable
<> IsMutable
_ = IsMutable
Mutable
    IsMutable
_ <> IsMutable
Mutable = IsMutable
Mutable
    IsMutable
Immutable <> IsMutable
Immutable = IsMutable
Immutable

instance Monoid IsMutable where
    mempty :: IsMutable
mempty = IsMutable
Immutable
    mappend :: IsMutable -> IsMutable -> IsMutable
mappend = IsMutable -> IsMutable -> IsMutable
forall a. Semigroup a => a -> a -> a
(<>)

taskIsTarget :: Task -> Bool
taskIsTarget :: Task -> Bool
taskIsTarget Task
t =
    case Task -> TaskType
taskType Task
t of
        TTLocalMutable LocalPackage
lp -> LocalPackage -> Bool
lpWanted LocalPackage
lp
        TaskType
_ -> Bool
False

taskLocation :: Task -> InstallLocation
taskLocation :: Task -> InstallLocation
taskLocation Task
task =
    case Task -> TaskType
taskType Task
task of
        TTLocalMutable LocalPackage
_ -> InstallLocation
Local
        TTRemotePackage IsMutable
Mutable Package
_ PackageLocationImmutable
_ -> InstallLocation
Local
        TTRemotePackage IsMutable
Immutable Package
_ PackageLocationImmutable
_ -> InstallLocation
Snap

taskTargetIsMutable :: Task -> IsMutable
taskTargetIsMutable :: Task -> IsMutable
taskTargetIsMutable Task
task =
    case Task -> TaskType
taskType Task
task of
        TTLocalMutable LocalPackage
_ -> IsMutable
Mutable
        TTRemotePackage IsMutable
mutable Package
_ PackageLocationImmutable
_ -> IsMutable
mutable

installLocationIsMutable :: InstallLocation -> IsMutable
installLocationIsMutable :: InstallLocation -> IsMutable
installLocationIsMutable InstallLocation
Snap = IsMutable
Immutable
installLocationIsMutable InstallLocation
Local = IsMutable
Mutable

-- | A complete plan of what needs to be built and how to do it
data Plan = Plan
    { Plan -> Map PackageName Task
planTasks :: !(Map PackageName Task)
    , Plan -> Map PackageName Task
planFinals :: !(Map PackageName Task)
    -- ^ Final actions to be taken (test, benchmark, etc)
    , Plan -> Map GhcPkgId (PackageIdentifier, Text)
planUnregisterLocal :: !(Map GhcPkgId (PackageIdentifier, Text))
    -- ^ Text is reason we're unregistering, for display only
    , Plan -> Map Text InstallLocation
planInstallExes :: !(Map Text InstallLocation)
    -- ^ Executables that should be installed after successful building
    }
    deriving Int -> Plan -> ShowS
[Plan] -> ShowS
Plan -> String
(Int -> Plan -> ShowS)
-> (Plan -> String) -> ([Plan] -> ShowS) -> Show Plan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Plan] -> ShowS
$cshowList :: [Plan] -> ShowS
show :: Plan -> String
$cshow :: Plan -> String
showsPrec :: Int -> Plan -> ShowS
$cshowsPrec :: Int -> Plan -> ShowS
Show

-- | Basic information used to calculate what the configure options are
data BaseConfigOpts = BaseConfigOpts
    { BaseConfigOpts -> Path Abs Dir
bcoSnapDB :: !(Path Abs Dir)
    , BaseConfigOpts -> Path Abs Dir
bcoLocalDB :: !(Path Abs Dir)
    , BaseConfigOpts -> Path Abs Dir
bcoSnapInstallRoot :: !(Path Abs Dir)
    , BaseConfigOpts -> Path Abs Dir
bcoLocalInstallRoot :: !(Path Abs Dir)
    , BaseConfigOpts -> BuildOpts
bcoBuildOpts :: !BuildOpts
    , BaseConfigOpts -> BuildOptsCLI
bcoBuildOptsCLI :: !BuildOptsCLI
    , BaseConfigOpts -> [Path Abs Dir]
bcoExtraDBs :: ![Path Abs Dir]
    }
    deriving Int -> BaseConfigOpts -> ShowS
[BaseConfigOpts] -> ShowS
BaseConfigOpts -> String
(Int -> BaseConfigOpts -> ShowS)
-> (BaseConfigOpts -> String)
-> ([BaseConfigOpts] -> ShowS)
-> Show BaseConfigOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BaseConfigOpts] -> ShowS
$cshowList :: [BaseConfigOpts] -> ShowS
show :: BaseConfigOpts -> String
$cshow :: BaseConfigOpts -> String
showsPrec :: Int -> BaseConfigOpts -> ShowS
$cshowsPrec :: Int -> BaseConfigOpts -> ShowS
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 :: EnvConfig
-> BaseConfigOpts
-> Map PackageIdentifier GhcPkgId
-> Bool
-> IsMutable
-> Package
-> ConfigureOpts
configureOpts EnvConfig
econfig BaseConfigOpts
bco Map PackageIdentifier GhcPkgId
deps Bool
isLocal IsMutable
isMutable Package
package = ConfigureOpts :: [String] -> [String] -> ConfigureOpts
ConfigureOpts
    { coDirs :: [String]
coDirs = BaseConfigOpts -> IsMutable -> Package -> [String]
configureOptsDirs BaseConfigOpts
bco IsMutable
isMutable Package
package
    , coNoDirs :: [String]
coNoDirs = EnvConfig
-> BaseConfigOpts
-> Map PackageIdentifier GhcPkgId
-> Bool
-> Package
-> [String]
configureOptsNoDir EnvConfig
econfig BaseConfigOpts
bco Map PackageIdentifier GhcPkgId
deps Bool
isLocal Package
package
    }

-- options set by stack
isStackOpt :: Text -> Bool
isStackOpt :: Text -> Bool
isStackOpt Text
t = (Text -> Bool) -> [Text] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Text -> Text -> Bool
`T.isPrefixOf` Text
t)
    [ Text
"--dependency="
    , Text
"--constraint="
    , Text
"--package-db="
    , Text
"--libdir="
    , Text
"--bindir="
    , Text
"--datadir="
    , Text
"--libexecdir="
    , Text
"--sysconfdir"
    , Text
"--docdir="
    , Text
"--htmldir="
    , Text
"--haddockdir="
    , Text
"--enable-tests"
    , Text
"--enable-benchmarks"
    , Text
"--exact-configuration"
    -- Treat these as causing dirtiness, to resolve
    -- https://github.com/commercialhaskell/stack/issues/2984
    --
    -- , "--enable-library-profiling"
    -- , "--enable-executable-profiling"
    -- , "--enable-profiling"
    ] Bool -> Bool -> Bool
|| Text
t Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"--user"

configureOptsDirs :: BaseConfigOpts
                  -> IsMutable
                  -> Package
                  -> [String]
configureOptsDirs :: BaseConfigOpts -> IsMutable -> Package -> [String]
configureOptsDirs BaseConfigOpts
bco IsMutable
isMutable Package
package = [[String]] -> [String]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
    [ [String
"--user", String
"--package-db=clear", String
"--package-db=global"]
    , (Path Abs Dir -> String) -> [Path Abs Dir] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ((String
"--package-db=" String -> ShowS
forall a. [a] -> [a] -> [a]
++) ShowS -> (Path Abs Dir -> String) -> Path Abs Dir -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep) ([Path Abs Dir] -> [String]) -> [Path Abs Dir] -> [String]
forall a b. (a -> b) -> a -> b
$ case IsMutable
isMutable of
        IsMutable
Immutable -> BaseConfigOpts -> [Path Abs Dir]
bcoExtraDBs BaseConfigOpts
bco [Path Abs Dir] -> [Path Abs Dir] -> [Path Abs Dir]
forall a. [a] -> [a] -> [a]
++ [BaseConfigOpts -> Path Abs Dir
bcoSnapDB BaseConfigOpts
bco]
        IsMutable
Mutable -> BaseConfigOpts -> [Path Abs Dir]
bcoExtraDBs BaseConfigOpts
bco [Path Abs Dir] -> [Path Abs Dir] -> [Path Abs Dir]
forall a. [a] -> [a] -> [a]
++ [BaseConfigOpts -> Path Abs Dir
bcoSnapDB BaseConfigOpts
bco] [Path Abs Dir] -> [Path Abs Dir] -> [Path Abs Dir]
forall a. [a] -> [a] -> [a]
++ [BaseConfigOpts -> Path Abs Dir
bcoLocalDB BaseConfigOpts
bco]
    , [ String
"--libdir=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep (Path Abs Dir
installRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
relDirLib)
      , String
"--bindir=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep (Path Abs Dir
installRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
bindirSuffix)
      , String
"--datadir=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep (Path Abs Dir
installRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
relDirShare)
      , String
"--libexecdir=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep (Path Abs Dir
installRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
relDirLibexec)
      , String
"--sysconfdir=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep (Path Abs Dir
installRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
relDirEtc)
      , String
"--docdir=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep Path Abs Dir
docDir
      , String
"--htmldir=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep Path Abs Dir
docDir
      , String
"--haddockdir=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs Dir -> String
forall loc. Path loc Dir -> String
toFilePathNoTrailingSep Path Abs Dir
docDir]
    ]
  where
    installRoot :: Path Abs Dir
installRoot =
        case IsMutable
isMutable of
            IsMutable
Immutable -> BaseConfigOpts -> Path Abs Dir
bcoSnapInstallRoot BaseConfigOpts
bco
            IsMutable
Mutable -> BaseConfigOpts -> Path Abs Dir
bcoLocalInstallRoot BaseConfigOpts
bco
    docDir :: Path Abs Dir
docDir =
        case Maybe (Path Rel Dir)
pkgVerDir of
            Maybe (Path Rel Dir)
Nothing -> Path Abs Dir
installRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
docDirSuffix
            Just dir -> Path Abs Dir
installRoot Path Abs Dir -> Path Rel Dir -> Path Abs Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
docDirSuffix Path Rel Dir -> Path Rel Dir -> Path Rel Dir
forall b t. Path b Dir -> Path Rel t -> Path b t
</> Path Rel Dir
dir
    pkgVerDir :: Maybe (Path Rel Dir)
pkgVerDir =
        String -> Maybe (Path Rel Dir)
forall (m :: * -> *). MonadThrow m => String -> m (Path Rel Dir)
parseRelDir (PackageIdentifier -> String
packageIdentifierString (PackageName -> Version -> PackageIdentifier
PackageIdentifier (Package -> PackageName
packageName Package
package)
                                                                (Package -> Version
packageVersion Package
package)) String -> ShowS
forall a. [a] -> [a] -> [a]
++
                     [Char
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 :: EnvConfig
-> BaseConfigOpts
-> Map PackageIdentifier GhcPkgId
-> Bool
-> Package
-> [String]
configureOptsNoDir EnvConfig
econfig BaseConfigOpts
bco Map PackageIdentifier GhcPkgId
deps Bool
isLocal Package
package = [[String]] -> [String]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
    [ [String]
depOptions
    , [String
"--enable-library-profiling" | BuildOpts -> Bool
boptsLibProfile BuildOpts
bopts Bool -> Bool -> Bool
|| BuildOpts -> Bool
boptsExeProfile BuildOpts
bopts]
    -- Cabal < 1.21.1 does not support --enable-profiling, use --enable-executable-profiling instead
    , let profFlag :: String
profFlag = String
"--enable-" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [String
"executable-" | Bool -> Bool
not Bool
newerCabal] String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"profiling"
      in [ String
profFlag | BuildOpts -> Bool
boptsExeProfile BuildOpts
bopts Bool -> Bool -> Bool
&& Bool
isLocal]
    , [String
"--enable-split-objs" | BuildOpts -> Bool
boptsSplitObjs BuildOpts
bopts]
    , [String
"--disable-library-stripping" | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ BuildOpts -> Bool
boptsLibStrip BuildOpts
bopts Bool -> Bool -> Bool
|| BuildOpts -> Bool
boptsExeStrip BuildOpts
bopts]
    , [String
"--disable-executable-stripping" | Bool -> Bool
not (BuildOpts -> Bool
boptsExeStrip BuildOpts
bopts) Bool -> Bool -> Bool
&& Bool
isLocal]
    , ((FlagName, Bool) -> String) -> [(FlagName, Bool)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\(FlagName
name,Bool
enabled) ->
                       String
"-f" String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
                       (if Bool
enabled
                           then String
""
                           else String
"-") String -> ShowS
forall a. Semigroup a => a -> a -> a
<>
                       FlagName -> String
flagNameString FlagName
name)
                    (Map FlagName Bool -> [(FlagName, Bool)]
forall k a. Map k a -> [(k, a)]
Map.toList Map FlagName Bool
flags)
    , (Text -> String) -> [Text] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Text -> String
T.unpack ([Text] -> [String]) -> [Text] -> [String]
forall a b. (a -> b) -> a -> b
$ Package -> [Text]
packageCabalConfigOpts Package
package
    , (Text -> [String]) -> [Text] -> [String]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\Text
x -> [WhichCompiler -> String
compilerOptionsCabalFlag WhichCompiler
wc, Text -> String
T.unpack Text
x]) (Package -> [Text]
packageGhcOptions Package
package)
    , ShowS -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String
"--extra-include-dirs=" String -> ShowS
forall a. [a] -> [a] -> [a]
++) (Config -> [String]
configExtraIncludeDirs Config
config)
    , ShowS -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String
"--extra-lib-dirs=" String -> ShowS
forall a. [a] -> [a] -> [a]
++) (Config -> [String]
configExtraLibDirs Config
config)
    , [String]
-> (Path Abs File -> [String]) -> Maybe (Path Abs File) -> [String]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Path Abs File
customGcc -> [String
"--with-gcc=" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Path Abs File -> String
forall b t. Path b t -> String
toFilePath Path Abs File
customGcc]) (Config -> Maybe (Path Abs File)
configOverrideGccPath Config
config)
    , [String
"--exact-configuration"]
    , [String
"--ghc-option=-fhide-source-paths" | Version -> Bool
hideSourcePaths Version
cv]
    ]
  where
    wc :: WhichCompiler
wc = Getting WhichCompiler EnvConfig WhichCompiler
-> EnvConfig -> WhichCompiler
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view (Getting WhichCompiler EnvConfig ActualCompiler
forall env. HasSourceMap env => SimpleGetter env ActualCompiler
actualCompilerVersionLGetting WhichCompiler EnvConfig ActualCompiler
-> ((WhichCompiler -> Const WhichCompiler WhichCompiler)
    -> ActualCompiler -> Const WhichCompiler ActualCompiler)
-> Getting WhichCompiler EnvConfig WhichCompiler
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ActualCompiler -> WhichCompiler)
-> SimpleGetter ActualCompiler WhichCompiler
forall s a. (s -> a) -> SimpleGetter s a
to ActualCompiler -> WhichCompiler
whichCompiler) EnvConfig
econfig
    cv :: Version
cv = Getting Version EnvConfig Version -> EnvConfig -> Version
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view (Getting Version EnvConfig ActualCompiler
forall env. HasSourceMap env => SimpleGetter env ActualCompiler
actualCompilerVersionLGetting Version EnvConfig ActualCompiler
-> ((Version -> Const Version Version)
    -> ActualCompiler -> Const Version ActualCompiler)
-> Getting Version EnvConfig Version
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ActualCompiler -> Version) -> SimpleGetter ActualCompiler Version
forall s a. (s -> a) -> SimpleGetter s a
to ActualCompiler -> Version
getGhcVersion) EnvConfig
econfig

    hideSourcePaths :: Version -> Bool
hideSourcePaths Version
ghcVersion = Version
ghcVersion Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
>= [Int] -> Version
mkVersion [Int
8, Int
2] Bool -> Bool -> Bool
&& Config -> Bool
configHideSourcePaths Config
config

    config :: Config
config = Getting Config EnvConfig Config -> EnvConfig -> Config
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Config EnvConfig Config
forall env. HasConfig env => Lens' env Config
configL EnvConfig
econfig
    bopts :: BuildOpts
bopts = BaseConfigOpts -> BuildOpts
bcoBuildOpts BaseConfigOpts
bco

    newerCabal :: Bool
newerCabal = Getting Version EnvConfig Version -> EnvConfig -> Version
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Version EnvConfig Version
forall env. HasCompiler env => SimpleGetter env Version
cabalVersionL EnvConfig
econfig Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
>= [Int] -> Version
mkVersion [Int
1, Int
22]

    -- Unioning atop defaults is needed so that all flags are specified
    -- with --exact-configuration.
    flags :: Map FlagName Bool
flags = Package -> Map FlagName Bool
packageFlags Package
package Map FlagName Bool -> Map FlagName Bool -> Map FlagName Bool
forall k a. Ord k => Map k a -> Map k a -> Map k a
`Map.union` Package -> Map FlagName Bool
packageDefaultFlags Package
package

    depOptions :: [String]
depOptions = ((PackageIdentifier, GhcPkgId) -> String)
-> [(PackageIdentifier, GhcPkgId)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ((PackageIdentifier -> GhcPkgId -> String)
-> (PackageIdentifier, GhcPkgId) -> String
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry PackageIdentifier -> GhcPkgId -> String
toDepOption) ([(PackageIdentifier, GhcPkgId)] -> [String])
-> [(PackageIdentifier, GhcPkgId)] -> [String]
forall a b. (a -> b) -> a -> b
$ Map PackageIdentifier GhcPkgId -> [(PackageIdentifier, GhcPkgId)]
forall k a. Map k a -> [(k, a)]
Map.toList Map PackageIdentifier GhcPkgId
deps
      where
        toDepOption :: PackageIdentifier -> GhcPkgId -> String
toDepOption = if Bool
newerCabal then PackageIdentifier -> GhcPkgId -> String
toDepOption1_22 else PackageIdentifier -> GhcPkgId -> String
forall p. PackageIdentifier -> p -> String
toDepOption1_18

    toDepOption1_22 :: PackageIdentifier -> GhcPkgId -> String
toDepOption1_22 (PackageIdentifier PackageName
name Version
_) GhcPkgId
gid = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ String
"--dependency="
        , PackageName -> String
packageNameString PackageName
name
        , String
"="
        , GhcPkgId -> String
ghcPkgIdString GhcPkgId
gid
        ]

    toDepOption1_18 :: PackageIdentifier -> p -> String
toDepOption1_18 PackageIdentifier
ident p
_gid = [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ String
"--constraint="
        , PackageName -> String
packageNameString PackageName
name
        , String
"=="
        , Version -> String
versionString Version
version'
        ]
      where
        PackageIdentifier PackageName
name Version
version' = PackageIdentifier
ident

-- | Get set of wanted package names from locals.
wantedLocalPackages :: [LocalPackage] -> Set PackageName
wantedLocalPackages :: [LocalPackage] -> Set PackageName
wantedLocalPackages = [PackageName] -> Set PackageName
forall a. Ord a => [a] -> Set a
Set.fromList ([PackageName] -> Set PackageName)
-> ([LocalPackage] -> [PackageName])
-> [LocalPackage]
-> Set PackageName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LocalPackage -> PackageName) -> [LocalPackage] -> [PackageName]
forall a b. (a -> b) -> [a] -> [b]
map (Package -> PackageName
packageName (Package -> PackageName)
-> (LocalPackage -> Package) -> LocalPackage -> PackageName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalPackage -> Package
lpPackage) ([LocalPackage] -> [PackageName])
-> ([LocalPackage] -> [LocalPackage])
-> [LocalPackage]
-> [PackageName]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (LocalPackage -> Bool) -> [LocalPackage] -> [LocalPackage]
forall a. (a -> Bool) -> [a] -> [a]
filter LocalPackage -> Bool
lpWanted

-- | Configure options to be sent to Setup.hs configure
data ConfigureOpts = ConfigureOpts
    { ConfigureOpts -> [String]
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.
    , ConfigureOpts -> [String]
coNoDirs :: ![String]
    }
    deriving (Int -> ConfigureOpts -> ShowS
[ConfigureOpts] -> ShowS
ConfigureOpts -> String
(Int -> ConfigureOpts -> ShowS)
-> (ConfigureOpts -> String)
-> ([ConfigureOpts] -> ShowS)
-> Show ConfigureOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfigureOpts] -> ShowS
$cshowList :: [ConfigureOpts] -> ShowS
show :: ConfigureOpts -> String
$cshow :: ConfigureOpts -> String
showsPrec :: Int -> ConfigureOpts -> ShowS
$cshowsPrec :: Int -> ConfigureOpts -> ShowS
Show, ConfigureOpts -> ConfigureOpts -> Bool
(ConfigureOpts -> ConfigureOpts -> Bool)
-> (ConfigureOpts -> ConfigureOpts -> Bool) -> Eq ConfigureOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfigureOpts -> ConfigureOpts -> Bool
$c/= :: ConfigureOpts -> ConfigureOpts -> Bool
== :: ConfigureOpts -> ConfigureOpts -> Bool
$c== :: ConfigureOpts -> ConfigureOpts -> Bool
Eq, (forall x. ConfigureOpts -> Rep ConfigureOpts x)
-> (forall x. Rep ConfigureOpts x -> ConfigureOpts)
-> Generic ConfigureOpts
forall x. Rep ConfigureOpts x -> ConfigureOpts
forall x. ConfigureOpts -> Rep ConfigureOpts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConfigureOpts x -> ConfigureOpts
$cfrom :: forall x. ConfigureOpts -> Rep ConfigureOpts x
Generic, Typeable ConfigureOpts
DataType
Constr
Typeable ConfigureOpts
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ConfigureOpts -> c ConfigureOpts)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ConfigureOpts)
-> (ConfigureOpts -> Constr)
-> (ConfigureOpts -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ConfigureOpts))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ConfigureOpts))
-> ((forall b. Data b => b -> b) -> ConfigureOpts -> ConfigureOpts)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ConfigureOpts -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ConfigureOpts -> r)
-> (forall u. (forall d. Data d => d -> u) -> ConfigureOpts -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ConfigureOpts -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts)
-> Data ConfigureOpts
ConfigureOpts -> DataType
ConfigureOpts -> Constr
(forall b. Data b => b -> b) -> ConfigureOpts -> ConfigureOpts
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigureOpts -> c ConfigureOpts
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigureOpts
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ConfigureOpts -> u
forall u. (forall d. Data d => d -> u) -> ConfigureOpts -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigureOpts -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigureOpts -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigureOpts
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigureOpts -> c ConfigureOpts
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConfigureOpts)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigureOpts)
$cConfigureOpts :: Constr
$tConfigureOpts :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts
gmapMp :: (forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts
gmapM :: (forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConfigureOpts -> m ConfigureOpts
gmapQi :: Int -> (forall d. Data d => d -> u) -> ConfigureOpts -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ConfigureOpts -> u
gmapQ :: (forall d. Data d => d -> u) -> ConfigureOpts -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ConfigureOpts -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigureOpts -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigureOpts -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigureOpts -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigureOpts -> r
gmapT :: (forall b. Data b => b -> b) -> ConfigureOpts -> ConfigureOpts
$cgmapT :: (forall b. Data b => b -> b) -> ConfigureOpts -> ConfigureOpts
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigureOpts)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigureOpts)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ConfigureOpts)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConfigureOpts)
dataTypeOf :: ConfigureOpts -> DataType
$cdataTypeOf :: ConfigureOpts -> DataType
toConstr :: ConfigureOpts -> Constr
$ctoConstr :: ConfigureOpts -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigureOpts
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigureOpts
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigureOpts -> c ConfigureOpts
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigureOpts -> c ConfigureOpts
$cp1Data :: Typeable ConfigureOpts
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
    { PrecompiledCache base -> Maybe (Path base File)
pcLibrary :: !(Maybe (Path base File))
    -- ^ .conf file inside the package database
    , PrecompiledCache base -> [Path base File]
pcSubLibs :: ![Path base File]
    -- ^ .conf file inside the package database, for each of the sublibraries
    , PrecompiledCache base -> [Path base File]
pcExes    :: ![Path base File]
    -- ^ Full paths to executables
    }
    deriving (Int -> PrecompiledCache base -> ShowS
[PrecompiledCache base] -> ShowS
PrecompiledCache base -> String
(Int -> PrecompiledCache base -> ShowS)
-> (PrecompiledCache base -> String)
-> ([PrecompiledCache base] -> ShowS)
-> Show (PrecompiledCache base)
forall base. Int -> PrecompiledCache base -> ShowS
forall base. [PrecompiledCache base] -> ShowS
forall base. PrecompiledCache base -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrecompiledCache base] -> ShowS
$cshowList :: forall base. [PrecompiledCache base] -> ShowS
show :: PrecompiledCache base -> String
$cshow :: forall base. PrecompiledCache base -> String
showsPrec :: Int -> PrecompiledCache base -> ShowS
$cshowsPrec :: forall base. Int -> PrecompiledCache base -> ShowS
Show, PrecompiledCache base -> PrecompiledCache base -> Bool
(PrecompiledCache base -> PrecompiledCache base -> Bool)
-> (PrecompiledCache base -> PrecompiledCache base -> Bool)
-> Eq (PrecompiledCache base)
forall base. PrecompiledCache base -> PrecompiledCache base -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrecompiledCache base -> PrecompiledCache base -> Bool
$c/= :: forall base. PrecompiledCache base -> PrecompiledCache base -> Bool
== :: PrecompiledCache base -> PrecompiledCache base -> Bool
$c== :: forall base. PrecompiledCache base -> PrecompiledCache base -> Bool
Eq, (forall x. PrecompiledCache base -> Rep (PrecompiledCache base) x)
-> (forall x.
    Rep (PrecompiledCache base) x -> PrecompiledCache base)
-> Generic (PrecompiledCache base)
forall x. Rep (PrecompiledCache base) x -> PrecompiledCache base
forall x. PrecompiledCache base -> Rep (PrecompiledCache base) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall base x.
Rep (PrecompiledCache base) x -> PrecompiledCache base
forall base x.
PrecompiledCache base -> Rep (PrecompiledCache base) x
$cto :: forall base x.
Rep (PrecompiledCache base) x -> PrecompiledCache base
$cfrom :: forall base x.
PrecompiledCache base -> Rep (PrecompiledCache base) x
Generic, Typeable)
instance NFData (PrecompiledCache Abs)
instance NFData (PrecompiledCache Rel)