Commit 1915a903 authored by Moritz Angermann's avatar Moritz Angermann
Browse files

Adds doctest-ghc(js)-options:

parent 8eb82cdf
......@@ -78,6 +78,7 @@ module Distribution.PackageDescription (
allExtensions,
usedExtensions,
hcOptions,
hcDoctestOptions,
hcProfOptions,
hcSharedOptions,
......
......@@ -520,6 +520,11 @@ binfoFieldDescrs =
options (const id)
, optsField "nhc98-options" NHC
options (const id)
, optsField "doctest-ghc-options" GHC
doctestOptions (\path binfo -> binfo{doctestOptions=path})
, optsField "doctest-ghcjs-options" GHCJS
doctestOptions (\path binfo -> binfo{doctestOptions=path})
]
storeXFieldsBI :: UnrecFieldParser BuildInfo
......
......@@ -524,6 +524,11 @@ binfoFieldDescrs =
options (const id)
, optsField "nhc98-options" NHC
options (const id)
, optsField "doctest-ghc-options" GHC
doctestOptions (\path binfo -> binfo{doctestOptions=path})
, optsField "doctest-ghcjs-options" GHCJS
doctestOptions (\path binfo -> binfo{doctestOptions=path})
]
{-
......
......@@ -108,6 +108,18 @@ componentGhcOptions verbosity lbi bi clbi odir =
"doctest only supports GHC and GHCJS"
in f verbosity lbi bi clbi odir
-- componentDoctestGhcOptions :: Verbosity -> LocalBuildInfo
-- -> BuildInfo -> ComponentLocalBuildInfo -> FilePath
-- -> GhcOptions
-- componentDoctestGhcOptions verbosity lbi bi clbi odir =
-- let f = case compilerFlavor (compiler lbi) of
-- GHC -> GHC.componentDoctestGhcOptions
-- GHCJS -> GHCJS.componentDoctestGhcOptions
-- _ -> error $
-- "Distribution.Simple.Doctest.componentDoctestGhcOptions:" ++
-- "doctest only support GHC and GHCJS"
-- in f verbosity lbi bi clbi odir
mkDoctestArgs :: Verbosity
-> FilePath
-> LocalBuildInfo
......@@ -119,6 +131,9 @@ mkDoctestArgs verbosity tmp lbi clbi inFiles bi = do
let vanillaOpts = (componentGhcOptions normal lbi bi clbi (buildDir lbi))
{ ghcOptOptimisation = mempty
, ghcOptWarnMissingHomeModules = mempty
-- clear out ghc-options: these are likely not meant for doctest.
-- If so, should be explicitly specified via doctest-ghc-options: again.
, ghcOptExtra = mempty
, ghcOptCabal = toFlag False
, ghcOptObjDir = toFlag tmp
......@@ -139,6 +154,7 @@ mkDoctestArgs verbosity tmp lbi clbi inFiles bi = do
ghcVersion <- maybe (die' verbosity "Compiler has no GHC version")
return
(compilerCompatVersion GHC (compiler lbi))
return $ DoctestArgs
{ argTargets = inFiles
, argGhcOptions = toFlag (opts, ghcVersion)
......@@ -172,7 +188,8 @@ renderArgs _verbosity comp platform args k = do
[ pure "--no-magic" -- disable doctests automagic discovery heuristics
, pure "-fdiagnostics-color=never" -- disable ghc's color diagnostics.
, [ opt | (opts, _ghcVer) <- flagToList (argGhcOptions args)
, opt <- renderGhcOptions comp platform opts ]
, opt <- renderGhcOptions comp platform opts
<> fromNubListR (ghcOptDoctest opts) ]
]
-- ------------------------------------------------------------------------------
......
......@@ -344,6 +344,7 @@ componentGhcOptions verbosity implInfo lbi bi clbi odir =
ghcOptOptimisation = toGhcOptimisation (withOptimization lbi),
ghcOptDebugInfo = toGhcDebugInfo (withDebugInfo lbi),
ghcOptExtra = toNubListR $ hcOptions GHC bi,
ghcOptDoctest = toNubListR $ hcDoctestOptions GHC bi,
ghcOptExtraPath = toNubListR $ exe_paths,
ghcOptLanguage = toFlag (fromMaybe Haskell98 (defaultLanguage bi)),
-- Unsupported extensions have already been checked by configure
......
......@@ -47,6 +47,10 @@ data GhcOptions = GhcOptions {
-- override other stuff.
ghcOptExtra :: NubListR String,
-- | Any options to pass to ghc through doctest. These go at the end and hence
-- override other stuff. Note: cabal doctest will ignore @ghcOptExtra@.
ghcOptDoctest :: NubListR String,
-- | Extra default flags to pass directly to ghc. These go at the beginning
-- and so can be overridden by other stuff.
ghcOptExtraDefault :: NubListR String,
......
......@@ -1419,7 +1419,7 @@ doctestCommand = CommandUI
"Usage: " ++ pname ++ " doctest [FLAGS]\n"
, commandDefaultFlags = defaultDoctestFlags
, commandOptions = \showOrParseArgs ->
doctestOptions showOrParseArgs
doctestCmdOptions showOrParseArgs
++ programDbPaths progDb ParseArgs
doctestProgramPaths (\v flags -> flags { doctestProgramPaths = v })
++ programDbOption progDb showOrParseArgs
......@@ -1432,8 +1432,8 @@ doctestCommand = CommandUI
$ addKnownProgram ghcProgram
$ emptyProgramDb
doctestOptions :: ShowOrParseArgs -> [OptionField DoctestFlags]
doctestOptions showOrParseArgs =
doctestCmdOptions :: ShowOrParseArgs -> [OptionField DoctestFlags]
doctestCmdOptions showOrParseArgs =
[optionVerbosity doctestVerbosity
(\v flags -> flags { doctestVerbosity = v })
,optionDistPref
......
......@@ -10,6 +10,7 @@ module Distribution.Types.BuildInfo (
usedExtensions,
hcOptions,
hcDoctestOptions,
hcProfOptions,
hcSharedOptions,
) where
......@@ -74,6 +75,7 @@ data BuildInfo = BuildInfo {
options :: [(CompilerFlavor,[String])],
profOptions :: [(CompilerFlavor,[String])],
sharedOptions :: [(CompilerFlavor,[String])],
doctestOptions :: [(CompilerFlavor,[String])],
customFieldsBI :: [(String,String)], -- ^Custom fields starting
-- with x-, stored in a
-- simple assoc-list.
......@@ -112,6 +114,7 @@ instance Monoid BuildInfo where
includes = [],
installIncludes = [],
options = [],
doctestOptions = [],
profOptions = [],
sharedOptions = [],
customFieldsBI = [],
......@@ -148,6 +151,7 @@ instance Semigroup BuildInfo where
includes = combineNub includes,
installIncludes = combineNub installIncludes,
options = combine options,
doctestOptions = combine doctestOptions,
profOptions = combine profOptions,
sharedOptions = combine sharedOptions,
customFieldsBI = combine customFieldsBI,
......@@ -184,6 +188,9 @@ usedExtensions bi = oldExtensions bi
hcOptions :: CompilerFlavor -> BuildInfo -> [String]
hcOptions = lookupHcOptions options
hcDoctestOptions :: CompilerFlavor -> BuildInfo -> [String]
hcDoctestOptions = lookupHcOptions doctestOptions
hcProfOptions :: CompilerFlavor -> BuildInfo -> [String]
hcProfOptions = lookupHcOptions profOptions
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment