in package replace-prefix i have a main:
root :: FilePath
root = “/home/cmo/src/replace-prefix”
main :: IO ()
main = do
(inp:out:_) ← getArgs
cwd ← getCurrentDirectory
Text.writeFile (root </> “log”) (pack cwd)
s ← Text.readFile inp
Text.writeFile out s
it builds and runs fine. in package test-replace-prefix i have a cabal file with stanzas
executable test-replace-prefix
import: warnings
main-is: Main.hs
– other-modules:
– other-extensions:
build-depends: base ^>=4.18.2.1
, test-replace-prefix
hs-source-dirs: app
default-language: Haskell2010
library
exposed-modules: Root
hs-source-dirs: src
build-tool-depends: replace-prefix:replace-prefix
in package test-replace-prefix i have a Setup.hs
main = defaultMainWithHooks simpleUserHooks
{ hookedPreProcessors =
[ (“phs”, replace-prefix) ]
}
The error message I get is:
Error: .cabal-wrapped: can’t find source for Root in src
in package test-replace-prefix src dir I have a Root.phs which just provides a binding that returns a string
Can anyone help me understand what is happening?
Ok I figured it out. I forgot to set my build-type to custom. Now I just have to understand how to create a preprocessor. I’m looking at Distribution.Simple.PreProcess. I will figure it out tomorrow.
1 Like
The args should be original_filepath, input, output
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-| A preprocessor that registers skeletest in a test suite.
We need to use a preprocessor for Main.hs because GHC plugins don't
seem to support dynamically registering other modules as imports (GHC
already knows what order it's going to compile the modules in, because
plugins run per module).
But GHC's plugin interface is much nicer for inspecting and manipulating
the code. So what we'll do here is:
1. Always register the plugin by adding `{\-# OPTIONS_GHC -fplugin=... #-\}` to
the top of the file. The plugin will then inspect the file to see if it's
a test file or the main file, and if so, process it.
2. If the file is the main file, insert the appropriate imports.
-}
module Main where
This file has been truncated. show original
Awesome! Thank you for pointing out skeletest to me. That’s what I was trying to implement was a way of doing inline specifications.