module GHC.Unit.Module.Location
( ModLocation(..)
, addBootSuffix
, addBootSuffix_maybe
, addBootSuffixLocn_maybe
, addBootSuffixLocn
, addBootSuffixLocnOut
, removeBootSuffix
)
where
import GHC.Prelude
import GHC.Unit.Types
import GHC.Utils.Outputable
data ModLocation
= ModLocation {
ModLocation -> Maybe FilePath
ml_hs_file :: Maybe FilePath,
ModLocation -> FilePath
ml_hi_file :: FilePath,
ModLocation -> FilePath
ml_dyn_hi_file :: FilePath,
ModLocation -> FilePath
ml_obj_file :: FilePath,
ModLocation -> FilePath
ml_dyn_obj_file :: FilePath,
ModLocation -> FilePath
ml_hie_file :: FilePath
} deriving Int -> ModLocation -> ShowS
[ModLocation] -> ShowS
ModLocation -> FilePath
(Int -> ModLocation -> ShowS)
-> (ModLocation -> FilePath)
-> ([ModLocation] -> ShowS)
-> Show ModLocation
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ModLocation -> ShowS
showsPrec :: Int -> ModLocation -> ShowS
$cshow :: ModLocation -> FilePath
show :: ModLocation -> FilePath
$cshowList :: [ModLocation] -> ShowS
showList :: [ModLocation] -> ShowS
Show
instance Outputable ModLocation where
ppr :: ModLocation -> SDoc
ppr = FilePath -> SDoc
forall doc. IsLine doc => FilePath -> doc
text (FilePath -> SDoc)
-> (ModLocation -> FilePath) -> ModLocation -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModLocation -> FilePath
forall a. Show a => a -> FilePath
show
addBootSuffix :: FilePath -> FilePath
addBootSuffix :: ShowS
addBootSuffix FilePath
path = FilePath
path FilePath -> ShowS
forall a. [a] -> [a] -> [a]
++ FilePath
"-boot"
removeBootSuffix :: FilePath -> FilePath
removeBootSuffix :: ShowS
removeBootSuffix FilePath
"-boot" = []
removeBootSuffix (Char
x:FilePath
xs) = Char
x Char -> ShowS
forall a. a -> [a] -> [a]
: ShowS
removeBootSuffix FilePath
xs
removeBootSuffix [] = ShowS
forall a. HasCallStack => FilePath -> a
error FilePath
"removeBootSuffix: no -boot suffix"
addBootSuffix_maybe :: IsBootInterface -> FilePath -> FilePath
addBootSuffix_maybe :: IsBootInterface -> ShowS
addBootSuffix_maybe IsBootInterface
is_boot FilePath
path = case IsBootInterface
is_boot of
IsBootInterface
IsBoot -> ShowS
addBootSuffix FilePath
path
IsBootInterface
NotBoot -> FilePath
path
addBootSuffixLocn_maybe :: IsBootInterface -> ModLocation -> ModLocation
addBootSuffixLocn_maybe :: IsBootInterface -> ModLocation -> ModLocation
addBootSuffixLocn_maybe IsBootInterface
is_boot ModLocation
locn = case IsBootInterface
is_boot of
IsBootInterface
IsBoot -> ModLocation -> ModLocation
addBootSuffixLocn ModLocation
locn
IsBootInterface
_ -> ModLocation
locn
addBootSuffixLocn :: ModLocation -> ModLocation
addBootSuffixLocn :: ModLocation -> ModLocation
addBootSuffixLocn ModLocation
locn
= ModLocation
locn { ml_hs_file = fmap addBootSuffix (ml_hs_file locn)
, ml_hi_file = addBootSuffix (ml_hi_file locn)
, ml_dyn_hi_file = addBootSuffix (ml_dyn_hi_file locn)
, ml_obj_file = addBootSuffix (ml_obj_file locn)
, ml_dyn_obj_file = addBootSuffix (ml_dyn_obj_file locn)
, ml_hie_file = addBootSuffix (ml_hie_file locn) }
addBootSuffixLocnOut :: ModLocation -> ModLocation
addBootSuffixLocnOut :: ModLocation -> ModLocation
addBootSuffixLocnOut ModLocation
locn
= ModLocation
locn { ml_hi_file = addBootSuffix (ml_hi_file locn)
, ml_dyn_hi_file = addBootSuffix (ml_dyn_hi_file locn)
, ml_obj_file = addBootSuffix (ml_obj_file locn)
, ml_dyn_obj_file = addBootSuffix (ml_dyn_obj_file locn)
, ml_hie_file = addBootSuffix (ml_hie_file locn)
}