@@ -55,12 +55,12 @@ import Distribution.Simple.CCompiler
5555import Distribution.Simple.Compiler
5656import Distribution.Simple.Errors
5757import Distribution.Simple.LocalBuildInfo
58- import Distribution.Simple.RebuildMonad
5958import qualified Distribution.Simple.PackageIndex as PackageIndex
6059import Distribution.Simple.PreProcess.Types
6160import Distribution.Simple.PreProcess.Unlit
6261import Distribution.Simple.Program
6362import Distribution.Simple.Program.ResponseFile
63+ import Distribution.Simple.RebuildMonad
6464import Distribution.Simple.Test.LibV09
6565import Distribution.Simple.Utils
6666import Distribution.System
@@ -69,8 +69,8 @@ import Distribution.Utils.Path
6969import Distribution.Verbosity
7070import Distribution.Version
7171
72- import Control.Monad.Writer
7372import Control.Monad (sequence )
73+ import Control.Monad.Writer
7474import System.Directory (doesDirectoryExist , doesFileExist )
7575import System.FilePath
7676 ( normalise
@@ -206,11 +206,12 @@ preprocessComponent pd comp lbi clbi isSrcDist verbosity handlers =
206206 BenchmarkUnsupported tt ->
207207 dieWithException verbosity $ NoSupportForPreProcessingBenchmark tt
208208 where
209- orderingFromHandlers :: Verbosity
210- -> [SymbolicPath Pkg (Dir Source )]
211- -> [(Suffix , PreProcessor )]
212- -> [ModuleName ]
213- -> IO [ModuleName ]
209+ orderingFromHandlers
210+ :: Verbosity
211+ -> [SymbolicPath Pkg (Dir Source )]
212+ -> [(Suffix , PreProcessor )]
213+ -> [ModuleName ]
214+ -> IO [ModuleName ]
214215 orderingFromHandlers v d hndlrs mods =
215216 foldM (\ acc (_, pp) -> ppOrdering pp v d acc) mods hndlrs
216217 builtinCSuffixes = map Suffix cSourceExtensions
@@ -341,7 +342,6 @@ preprocessFile mbWorkDir searchLoc buildLoc forSDist baseFile verbosity builtinS
341342 -- look for existing pre-processed source file in the dest dir to
342343 -- see if we really have to re-run the preprocessor.
343344
344- -- ppsrcFileMay <- findFileCwdWithExtension mbWorkDir builtinSuffixes [buildAsSrcLoc] baseFile
345345 (runPreProcessor, key) <- configurePreProcessor pp verbosity
346346 let recompile = liftIO $ do
347347 let destDir = i buildLoc </> takeDirectory srcStem
@@ -350,11 +350,17 @@ preprocessFile mbWorkDir searchLoc buildLoc forSDist baseFile verbosity builtinS
350350 runPreProcessor
351351 (psrcLoc, getSymbolicPath psrcRelFile)
352352 (buildLoc, srcStem <.> " hs" )
353- void . execWriterT $ rerunIfChanged'
354- verbosity
355- (interpretSymbolicPath mbWorkDir (makeSymbolicPath " " ))
356- sequence
357- [(newFileMonitor (interpretSymbolicPath mbWorkDir psrcFile), key, recompile)]
353+ void . execWriterT $
354+ rerunIfChanged'
355+ verbosity
356+ (interpretSymbolicPath mbWorkDir (makeSymbolicPath " " ))
357+ sequence
358+ [
359+ ( newFileMonitor (interpretSymbolicPath mbWorkDir psrcFile)
360+ , key
361+ , recompile
362+ )
363+ ]
358364 where
359365 i = interpretSymbolicPath mbWorkDir -- See Note [Symbolic paths] in Distribution.Utils.Path
360366 buildAsSrcLoc :: SymbolicPath Pkg (Dir Source )
@@ -462,14 +468,16 @@ ppGhcCpp program xHs extraArgs _bi lbi clbi =
462468 ++ [" -o" , outFile, inFile]
463469 ++ extraArgs
464470
465- getProgVersion :: Verbosity
466- -> IO (ConfiguredProgram , Version )
471+ getProgVersion
472+ :: Verbosity
473+ -> IO (ConfiguredProgram , Version )
467474 getProgVersion verbosity = do
468- (prog, version, _) <- requireProgramVersion
469- verbosity
470- program
471- anyVersion
472- (withPrograms lbi)
475+ (prog, version, _) <-
476+ requireProgramVersion
477+ verbosity
478+ program
479+ anyVersion
480+ (withPrograms lbi)
473481 return (prog, version)
474482
475483ppCpphs :: [String ] -> BuildInfo -> LocalBuildInfo -> ComponentLocalBuildInfo -> PreProcessor
@@ -497,8 +505,9 @@ ppCpphs extraArgs _bi lbi clbi =
497505 : [" --include=" ++ u (autogenComponentModulesDir lbi clbi </> makeRelativePathEx cppHeaderName) | cpphsVersion >= mkVersion [1 , 6 ]]
498506 ++ extraArgs
499507
500- getProgVersion :: Verbosity
501- -> IO (ConfiguredProgram , Version )
508+ getProgVersion
509+ :: Verbosity
510+ -> IO (ConfiguredProgram , Version )
502511 getProgVersion verbosity = do
503512 (prog, version, _) <-
504513 requireProgramVersion
@@ -546,17 +555,18 @@ ppHsc2hs bi lbi clbi =
546555 )
547556 else runHsc2hs (prependCrossFlags pureArgs)
548557
549- getProgVersion :: Verbosity
550- -> IO (ConfiguredProgram , ConfiguredProgram , Version )
558+ getProgVersion
559+ :: Verbosity
560+ -> IO (ConfiguredProgram , ConfiguredProgram , Version )
551561 getProgVersion verbosity = do
552- (gccProg, _) <- requireProgram verbosity gccProgram (withPrograms lbi)
553- (hsc2hsProg, hsc2hsVersion, _) <-
554- requireProgramVersion
555- verbosity
556- hsc2hsProgram
557- anyVersion
558- (withPrograms lbi)
559- pure (gccProg, hsc2hsProg, hsc2hsVersion)
562+ (gccProg, _) <- requireProgram verbosity gccProgram (withPrograms lbi)
563+ (hsc2hsProg, hsc2hsVersion, _) <-
564+ requireProgramVersion
565+ verbosity
566+ hsc2hsProgram
567+ anyVersion
568+ (withPrograms lbi)
569+ pure (gccProg, hsc2hsProg, hsc2hsVersion)
560570
561571 -- Returns a list of command line arguments that can either be passed
562572 -- directly, or via a response file.
@@ -725,42 +735,42 @@ ppC2hs bi lbi clbi =
725735 u = interpretSymbolicPathCWD
726736
727737 runPreProcessor
728- (gccProg, c2hsProg, _)
729- (inBaseDir, inRelativeFile)
730- (outBaseDir, outRelativeFile)
731- verbosity = do
732- runProgramCwd verbosity mbWorkDir c2hsProg $
733- -- Options from the current package:
734- [" --cpp=" ++ programPath gccProg, " --cppopts=-E" ]
735- ++ [" --cppopts=" ++ opt | opt <- getCppOptions bi lbi]
736- ++ [" --cppopts=-include" ++ u (autogenComponentModulesDir lbi clbi </> makeRelativePathEx cppHeaderName)]
737- ++ [" --include=" ++ outBaseDir]
738- -- Options from dependent packages
739- ++ [ " --cppopts=" ++ opt
740- | pkg <- pkgs
741- , opt <-
742- [" -I" ++ opt | opt <- Installed. includeDirs pkg]
743- ++ [ opt | opt@ (' -' : c : _) <- Installed. ccOptions pkg,
744- -- c2hs uses the C ABI
745- -- We assume that there are only C sources
746- -- and C++ functions are exported via a C
747- -- interface and wrapped in a C source file.
748- -- Therefore we do not supply C++ flags
749- -- because there will not be C++ sources.
750- --
751- --
752- -- DO NOT add Installed.cxxOptions unless this changes!
753- c `elem` " DIU"
754- ]
755- ]
756- -- TODO: install .chi files for packages, so we can --include
757- -- those dirs here, for the dependencies
758-
759- -- input and output files
760- ++ [ " --output-dir=" ++ outBaseDir
761- , " --output=" ++ outRelativeFile
762- , inBaseDir </> inRelativeFile
763- ]
738+ (gccProg, c2hsProg, _)
739+ (inBaseDir, inRelativeFile)
740+ (outBaseDir, outRelativeFile)
741+ verbosity = do
742+ runProgramCwd verbosity mbWorkDir c2hsProg $
743+ -- Options from the current package:
744+ [" --cpp=" ++ programPath gccProg, " --cppopts=-E" ]
745+ ++ [" --cppopts=" ++ opt | opt <- getCppOptions bi lbi]
746+ ++ [" --cppopts=-include" ++ u (autogenComponentModulesDir lbi clbi </> makeRelativePathEx cppHeaderName)]
747+ ++ [" --include=" ++ outBaseDir]
748+ -- Options from dependent packages
749+ ++ [ " --cppopts=" ++ opt
750+ | pkg <- pkgs
751+ , opt <-
752+ [" -I" ++ opt | opt <- Installed. includeDirs pkg]
753+ ++ [ opt | opt@ (' -' : c : _) <- Installed. ccOptions pkg,
754+ -- c2hs uses the C ABI
755+ -- We assume that there are only C sources
756+ -- and C++ functions are exported via a C
757+ -- interface and wrapped in a C source file.
758+ -- Therefore we do not supply C++ flags
759+ -- because there will not be C++ sources.
760+ --
761+ --
762+ -- DO NOT add Installed.cxxOptions unless this changes!
763+ c `elem` " DIU"
764+ ]
765+ ]
766+ -- TODO: install .chi files for packages, so we can --include
767+ -- those dirs here, for the dependencies
768+
769+ -- input and output files
770+ ++ [ " --output-dir=" ++ outBaseDir
771+ , " --output=" ++ outRelativeFile
772+ , inBaseDir </> inRelativeFile
773+ ]
764774
765775 getProgVersion verbosity = do
766776 (c2hsProg, c2hsVersion, _) <-
@@ -925,13 +935,13 @@ ppSuffixes = map fst
925935-- | Standard preprocessors: c2hs, hsc2hs, happy, alex and cpphs.
926936knownSuffixHandlers :: [PPSuffixHandler ]
927937knownSuffixHandlers =
928- [ (Suffix " chs" , ppC2hs)
929- , (Suffix " hsc" , ppHsc2hs)
930- , (Suffix " x" , ppAlex)
931- , (Suffix " y" , ppHappy)
932- , (Suffix " ly" , ppHappy)
933- , (Suffix " cpphs" , ppCpp)
934- ]
938+ [ (Suffix " chs" , ppC2hs)
939+ , (Suffix " hsc" , ppHsc2hs)
940+ , (Suffix " x" , ppAlex)
941+ , (Suffix " y" , ppHappy)
942+ , (Suffix " ly" , ppHappy)
943+ , (Suffix " cpphs" , ppCpp)
944+ ]
935945
936946-- | Standard preprocessors with possible extra C sources: c2hs, hsc2hs.
937947knownExtrasHandlers :: [PreProcessorExtras ]
0 commit comments