Cabal does not re-run the custom preprocessor when the source file is changed

Hello,

I’m currently building a custom preprocessor I would like to integrate with Cabal build. At the moment I have the following module that I use in my Setup.hs:

module CfgTypedCabal (mainWithCfgTyped) where

import Distribution.Simple
import Distribution.Types.BuildInfo (BuildInfo)
import Distribution.Types.LocalBuildInfo (LocalBuildInfo)
import Distribution.Types.ComponentLocalBuildInfo (ComponentLocalBuildInfo)
import Distribution.Simple.PreProcess (PreProcessor (..), mkSimplePreProcessor)
import System.Process

mainWithCfgTyped :: IO ()
mainWithCfgTyped = defaultMainWithHooks hooks

hooks :: UserHooks
hooks = simpleUserHooks
  { hookedPreProcessors = ("ny", ppCustom) : hookedPreProcessors simpleUserHooks
  }

ppCustom :: BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor
ppCustom _ _ _ =
  PreProcessor {
    ppOrdering = \_ _ -> pure,
    platformIndependent = True,
    runPreProcessor = mkSimplePreProcessor $ \inFile outFile _ ->
      do
        input <- readFile inFile
        output <- readProcess "preprocessor" [] input
        writeFile outFile output
  }

The problem I have right now is that Cabal does not re-run the preprocessor when I change the source (in this case a file with ny extension) based on which the code is generated. Does anyone know how to fix this issue?

Have you added those files to your extra-source-files?

Files listed here are tracked by cabal build; changes in these files cause (partial) rebuilds.

1 Like

Looks like the problem got fixed just by updating to the latest Cabal available on GHCup, but I will keep extra-source-files in mind as well if the problem is to reappear, thanks!