Support monitoring directory recursive globs
In my opinion, the most convenient way to declare a custom preprocessor in pre-build rules (in build-type: Hooks) is to search for files using a file glob, and then monitor the existence of that file glob. In this case, it's particularly convenient to use a directory recursive glob pattern:
myPreBuildRules :: PreBuildComponentInputs -> RulesM ()
myPreBuildRules pbci = do
-- [...]
let glob = GlobDirRecursive [ WildCard, Literal "ppExt" ]
myPpFiles <- liftIO $ for ( hsSourceDirs bi ) $ \ srcDir -> do
let root = interpretSymbolicPath mbWorkDir srcDir
matches <- runDirFileGlob verbosity Nothing root glob
return
[ Location srcDir ( makeRelativePathEx match )
| match <- globMatches matches
]
-- Monitor existence of file glob to handle new input files getting added.
addRuleMonitors [ monitorFileGlobExistence $ RootedGlob FilePathRelative glob ]
This handles searching for all *.ppExt files in source directories, and monitors the addition of any new file.
The problem is that cabal-install currently does not support monitoring directory-recursive globs:
error: Monitoring directory-recursive globs (i.e. ../**/...) is currently unsupported
Implementing this would be a straightforward change to the buildMonitorStateGlobRel function. It would also be beneficial to use that opportunity to think about the exposed file globbing and monitoring API for writers of pre-build rules, as the above code snippet required me to import Distribution.Simple.Glob.Internal (which is thankfully an exposed module of the Cabal library, due to the needs of cabal-install) because the constructors of Glob are not exported from Distribution.Simple.Glob.