module Distribution.Utils.Path (
SymbolicPath,
getSymbolicPath,
sameDirectory,
unsafeMakeSymbolicPath,
PackageDir,
SourceDir,
LicenseFile,
IsDir,
) where
import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Parsec
import Distribution.Pretty
import Distribution.Utils.Generic (isAbsoluteOnAnyPlatform)
import qualified Distribution.Compat.CharParsing as P
newtype SymbolicPath from to = SymbolicPath FilePath
deriving (Generic, Show, Read, Eq, Typeable, Data)
instance Binary (SymbolicPath from to)
instance (Typeable from, Typeable to) => Structured (SymbolicPath from to)
instance NFData (SymbolicPath from to) where rnf = genericRnf
getSymbolicPath :: SymbolicPath from to -> FilePath
getSymbolicPath (SymbolicPath p) = p
sameDirectory :: (IsDir from, IsDir to) => SymbolicPath from to
sameDirectory = SymbolicPath "."
unsafeMakeSymbolicPath :: FilePath -> SymbolicPath from to
unsafeMakeSymbolicPath = SymbolicPath
instance Parsec (SymbolicPath from to) where
parsec = do
token <- parsecToken
if null token then P.unexpected "empty FilePath"
else if isAbsoluteOnAnyPlatform token then P.unexpected "absolute FilePath"
else return (SymbolicPath token)
instance Pretty (SymbolicPath from to) where
pretty = showFilePath . getSymbolicPath
class IsDir dir
data PackageDir deriving (Typeable)
data SourceDir deriving (Typeable)
data LicenseFile deriving (Typeable)
deriving instance Data PackageDir
deriving instance Data SourceDir
deriving instance Data LicenseFile
instance IsDir PackageDir
instance IsDir SourceDir