Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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.
Synopsis
- 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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
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 Source #
Runs the Q
action, temporarily setting the current working
directory to the root of the cabal package.