Safe Haskell | None |
---|---|
Language | Haskell2010 |
TH.RelativePaths
Description
This module provides Template Haskell utilities for loading files based on paths relative to the root of your Cabal package.
Normally when building a cabal package, GHC is run with its current directory set at the package's root directory. This allows using relative paths to refer to files. However, this becomes problematic when you want to load modules from multiple projects, such as when using "stack ghci".
This solves the problem by getting the current module's filepath from
TH via location
. It then searches upwards in the directory tree for
a .cabal file, and makes the provided path relative to the folder
it's in.
- qReadFileBS :: FilePath -> Q ByteString
- qReadFileLBS :: FilePath -> Q ByteString
- qReadFileText :: FilePath -> Q Text
- qReadFileLazyText :: FilePath -> Q Text
- qReadFileString :: FilePath -> Q String
- withCabalPackageWorkDir :: Q a -> Q a
- pathRelativeToCabalPackage :: FilePath -> Q FilePath
- findCabalFile :: FilePath -> IO (Maybe FilePath)
Documentation
qReadFileBS :: FilePath -> Q ByteString #
Reads a file as a strict ByteString. The path is specified relative
to the package's root directory, and addDependentfile
is invoked on
the target file.
qReadFileLBS :: FilePath -> Q ByteString #
Reads a file as a lazy ByteString. The path is specified relative
to the package's root directory, and addDependentfile
is invoked on
the target file.
qReadFileText :: FilePath -> Q Text #
Reads a file as a strict Text. The path is specified relative
to the package's root directory, and addDependentfile
is invoked on
the target file.
qReadFileLazyText :: FilePath -> Q Text #
Reads a file as a lazy Text. The path is specified relative
to the package's root directory, and addDependentfile
is invoked on
the target file.
qReadFileString :: FilePath -> Q String #
Reads a file as a String. The path is specified relative
to the package's root directory, and addDependentfile
is invoked on
the target file.
withCabalPackageWorkDir :: Q a -> Q a #
Runs the Q
action, temporarily setting the current working
directory to the root of the cabal package.
pathRelativeToCabalPackage :: FilePath -> Q FilePath #
This utility takes a path that's relative to your package's cabal file, and resolves it to an absolute location.
Note that this utility does _not_ invoke qAddDependentFile
.