th-utilities-0.1.0.0: Collection of useful functions for use with Template Haskell

Safe HaskellNone
LanguageHaskell2010

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.

Synopsis

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.

pathRelativeToCabalPackage :: FilePath -> Q FilePath Source

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.

findCabalFile :: FilePath -> IO (Maybe FilePath) Source

Given the path to a file or directory, search parent directories for a .cabal file.