For a quite involved custom Setup
library, I need to manipulate source file location directories:
- I need to read out
hsSourceDirs
and then read files from those directories, both directly fromSetup.hs
and also indirectly by passing the filenames as string arguments to external programs - I need to inject new directories containing generated source files into
hsSourceDirs
The problem I am facing is that the type of hsSourceDirs
is [SymbolicPath PackageDir SourceDir]
, and I just can’t get my head around how to manipulate these SymbolicPath
s. Looking at Distribution.Utils.Path
, the datatype SymbolicPath from to
is exported abstractly only, and the combinators available are:
getSymbolicPath :: SymbolicPath from to -> FilePath
, marked as “avoid using this in new code”sameDirectory :: _ => SymbolicPath from to
unsafeMakeSymbolicPath :: FilePath -> SymbolicPath from to
This leaves me with the only choice of converting immediately from SymbolicPath PackageDir SourceDir
into FilePath
using getSymbolicPath
(that apparently I’m not supposed to be using), doing all file access in terms of that FilePath
, and then producing a new FilePath
starting from e.g. buildDir
, using FilePath
combinators like </>
, ending with a call to unsafeMakeSymbolicPath
. This doesn’t feel ideal.
Is there a way to, instead:
-
Get, perhaps in
IO
, perhaps using whatever Cabal context is available in a customSetup.hs
, the physicalFilePath
from aSymbolicPath PackageDir SourceDir
-
Create, perhaps in
IO
, perhaps using whatever Cabal context is available in a customSetup.hs
, a newSymbolicPath
that points to a new subdirectory (either named explicitly by me, or generated randomly afresh by Cabal) under the build directory
?