Hello community,

here is the log from the commit of package ghc-cabal-doctest for 
openSUSE:Factory checked in at 2018-05-30 12:03:26
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-cabal-doctest (Old)
 and      /work/SRC/openSUSE:Factory/.ghc-cabal-doctest.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "ghc-cabal-doctest"

Wed May 30 12:03:26 2018 rev:4 rq:607761 version:1.0.6

Changes:
--------
--- /work/SRC/openSUSE:Factory/ghc-cabal-doctest/ghc-cabal-doctest.changes      
2017-09-15 21:25:10.458581578 +0200
+++ /work/SRC/openSUSE:Factory/.ghc-cabal-doctest.new/ghc-cabal-doctest.changes 
2018-05-30 12:24:57.327012294 +0200
@@ -1,0 +2,16 @@
+Mon May 14 17:02:11 UTC 2018 - psim...@suse.com
+
+- Update cabal-doctest to version 1.0.6 revision 1.
+  * Hook `haddock` build too. Fixes issue when `haddock` fails, as
+    `Build_doctests` isn't generated.
+
+  * Add a hack so `Build_doctests` module is automatically added to
+    to `other-modules` and `autogen-modules` when compiled with Cabal-2.0.
+    Thanks to that, we don't get warnings because of `-Wmissing-home-modules`.
+
+  * Add support for doctests in executables and (with `Cabal-2.0` or later)
+    internal libraries. Refer to the `README` for more details.
+
+  * Add an explicit `Prelude` import to `Build_doctests`
+
+-------------------------------------------------------------------

Old:
----
  cabal-doctest-1.0.2.tar.gz

New:
----
  cabal-doctest-1.0.6.tar.gz
  cabal-doctest.cabal

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ ghc-cabal-doctest.spec ++++++
--- /var/tmp/diff_new_pack.vtyfmj/_old  2018-05-30 12:24:58.658969242 +0200
+++ /var/tmp/diff_new_pack.vtyfmj/_new  2018-05-30 12:24:58.658969242 +0200
@@ -1,7 +1,7 @@
 #
 # spec file for package ghc-cabal-doctest
 #
-# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -18,13 +18,14 @@
 
 %global pkg_name cabal-doctest
 Name:           ghc-%{pkg_name}
-Version:        1.0.2
+Version:        1.0.6
 Release:        0
 Summary:        A Setup.hs helper for doctests running
 License:        BSD-3-Clause
 Group:          Development/Libraries/Haskell
 URL:            https://hackage.haskell.org/package/%{pkg_name}
 Source0:        
https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz
+Source1:        
https://hackage.haskell.org/package/%{pkg_name}-%{version}/revision/1.cabal#/%{pkg_name}.cabal
 BuildRequires:  ghc-Cabal-devel
 BuildRequires:  ghc-directory-devel
 BuildRequires:  ghc-filepath-devel
@@ -50,6 +51,7 @@
 
 %prep
 %setup -q -n %{pkg_name}-%{version}
+cp -p %{SOURCE1} %{pkg_name}.cabal
 
 %build
 %ghc_lib_build
@@ -64,7 +66,7 @@
 %ghc_pkg_recache
 
 %files -f %{name}.files
-%doc LICENSE
+%license LICENSE
 
 %files devel -f %{name}-devel.files
 %doc ChangeLog.md README.md

++++++ cabal-doctest-1.0.2.tar.gz -> cabal-doctest-1.0.6.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cabal-doctest-1.0.2/ChangeLog.md 
new/cabal-doctest-1.0.6/ChangeLog.md
--- old/cabal-doctest-1.0.2/ChangeLog.md        2017-05-16 15:13:14.000000000 
+0200
+++ new/cabal-doctest-1.0.6/ChangeLog.md        2018-01-28 16:56:55.000000000 
+0100
@@ -1,3 +1,23 @@
+# 1.0.6 -- 2018-01-28
+
+* Hook `haddock` build too. Fixes issue when `haddock` fails, as
+  `Build_doctests` isn't generated.
+
+# 1.0.5 -- 2018-01-26
+
+* Add a hack so `Build_doctests` module is automatically added to
+  to `other-modules` and `autogen-modules` when compiled with Cabal-2.0.
+  Thanks to that, we don't get warnings because of `-Wmissing-home-modules`.
+
+# 1.0.4 -- 2017-12-05
+
+* Add support for doctests in executables and (with `Cabal-2.0` or later)
+  internal libraries. Refer to the `README` for more details.
+
+# 1.0.3 -- 2017-11-02
+
+* Add an explicit `Prelude` import to `Build_doctests`
+
 # 1.0.2 -- 2017-05-16
 
 * Add `defaultMainAutoconfWithDoctests` and `addDoctestsUserHook`.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cabal-doctest-1.0.2/README.md 
new/cabal-doctest-1.0.6/README.md
--- old/cabal-doctest-1.0.2/README.md   2017-05-16 15:13:14.000000000 +0200
+++ new/cabal-doctest-1.0.6/README.md   2018-01-28 16:56:55.000000000 +0100
@@ -5,11 +5,13 @@
 
 A `Setup.hs` helper for running `doctests`.
 
-Example Usage
--------------
+Simple example
+--------------
 
-See [https://github.com/phadej/cabal-doctest/tree/master/example] for an
-example package. (Note that the example requires `Cabal-1.24` or later, but
+For most use cases—a `.cabal` file with a single library containing
+doctests—adapting the simple example located
+[here](https://github.com/phadej/cabal-doctest/tree/master/simple-example)
+will be sufficient. (Note that this example requires `Cabal-1.24` or later, but
 you can relax this bound safely, although running doctests won't be supported
 on versions of `Cabal` older than 1.24.)
 
@@ -57,6 +59,81 @@
     args = flags ++ pkgs ++ module_sources
 ```
 
+Example with multiple .cabal components
+---------------------------------------
+
+`cabal-doctest` also supports more exotic use cases where a `.cabal` file
+contains more components with doctests than just the main library, including:
+
+* Doctests in executables
+* Doctests in Internal libraries (if using `Cabal-2.0` or later)
+
+Unlike the simple example shown above, these examples involve _named_
+components. You don't need to change the `Setup.hs` script to support
+this use case. However, in this scenario `Build_doctests` will generate extra
+copies of the `flags`, `pkgs`, and `module_sources` values for each additional
+named component.
+
+Simplest approach is to use `x-doctest-components` field, for example
+```
+x-doctest-components: lib lib:internal exe:example
+```
+
+In that case, the testdrive is general:
+
+```haskell
+module Main where
+
+import Build_doctests (Component (..), components)
+import Data.Foldable (for_)
+import Test.DocTest (doctest)
+
+main :: IO ()
+main = for_ components $ \(Component name flags pkgs sources) -> do
+    print name
+    putStrLn "----------------------------------------"
+    let args = flags ++ pkgs ++ sources
+    for_ args putStrLn
+    doctest args
+```
+
+There's also a more explicit approach: if you have an executable named `foo`,
+then separate values named `flags_exe_foo`, `pkgs_exe_foo`, and 
`module_sources_exe_foo` will
+be generated in `Build_doctests`. If the name has hyphens in it
+(e.g., `my-exe`), then `cabal-doctest` will convert those hyphens to
+underscores (e.g., you'd get `flags_my_exe`, `pkgs_my_exe`, and
+`module_sources_my_exe`).
+Internal library `bar` values will have a `_lib_bar` suffix.
+
+An example testsuite driver for this use case might look like this:
+
+```haskell
+module Main where
+
+import Build_doctests
+       (flags,            pkgs,            module_sources,
+        flags_exe_my_exe, pkgs_exe_my_exe, module_sources_exe_my_exe)
+import Data.Foldable (traverse_)
+import Test.DocTest
+
+main :: IO ()
+main = do
+    -- doctests for library
+    traverse_ putStrLn libArgs
+    doctest libArgs
+
+    -- doctests for executable
+    traverse_ putStrLn exeArgs
+    doctest exeArgs
+  where
+    libArgs = flags            ++ pkgs            ++ module_sources
+    exeArgs = flags_exe_my_exe ++ pkgs_exe_my_exe ++ module_sources_exe_my_exe
+```
+
+See
+[this 
example](https://github.com/phadej/cabal-doctest/tree/master/multiple-components-example)
+for more details.
+
 Additional configuration
 ------------------------
 
@@ -72,7 +149,7 @@
   x-doctest-modules: Servant.Utils.LinksSpec
 
   ...
- ```
+```
 
 * `x-doctest-options` Additional arguments passed into `doctest` command.
 * `x-doctest-modules` Additional modules to `doctest`. May be useful if you
@@ -82,6 +159,20 @@
 Notes
 -----
 
+* Recent versions of `Cabal` (for instance, 2.0) can choose to build a
+  package's `doctest` test suite _before_ the library. However, in order for
+  `cabal-doctest` to work correctly, the library _must_ be built first, as
+  `doctest` relies on the presence of generated files that are only created
+  when the library is built. See
+  [#19](https://github.com/phadej/cabal-doctest/issues/19).
+
+  A hacky workaround for this problem is to depend on the library itself in a
+  `doctests` test suite. See
+  [the simple example's .cabal 
file](https://github.com/phadej/cabal-doctest/blob/master/simple-example/simple-example.cabal)
+  for a demonstration. (This assumes that the test suite has the ability to
+  read build artifacts from the library, a separate build component. In
+  practice, this assumption holds, which is why this library works at all.)
+
 * `custom-setup` section is supported starting from `cabal-install-1.24`.
   For older `cabal-install's` you have to install custom setup dependencies
   manually.
@@ -94,11 +185,6 @@
   about adding `cabal doctest` command. After that command is implemented,
   this library will be deprecated.
 
-* If your library contains `cbits`, you might need to depend on the library
-  itself in `doctests` test-suite. We aren't sure whether this a bug or not.
-  See [#5 issue](https://github.com/phadej/cabal-doctest/issues/5) for longer
-  explanation.
-
 * You can use `x-doctest-options` field in `test-suite doctests` to
   pass additional flags to the `doctest`.
 
@@ -109,6 +195,32 @@
   might fail with weird errors (ambigious module errors). Workaround is
   to move sources under `src/` or some non-top-level directory.
 
+* `extensions:` field isn't supported. Upgrade your `.cabal` file to use at 
least
+  `cabal-version: >= 1.10` and use `default-extensions` or `other-extensions`.
+
+* If you use QuickCheck properties (`prop>`) in your doctests,
+  the `test-suite doctest` should depend on `QuickCheck` and 
`template-haskell`.
+  This is a little HACK: These dependencies aren't needed to build the
+  `doctests` test-suite executable.  However, as we let `Cabal` resolve
+  dependencies, we can pass the resolved (and installed!) package identifiers 
to
+  to the `doctest` command.  This way, `QuickCheck` and `template-haskell` are
+  available to `doctest`, otherwise you'll get errors like:
+
+```
+    Variable not in scope:
+      mkName
+        :: [Char]
+           -> template-haskell-2.11.1.0:Language.Haskell.TH.Syntax.Name
+```
+
+or
+
+```
+    Variable not in scope:
+      polyQuickCheck
+        :: Language.Haskell.TH.Syntax.Name -> Language.Haskell.TH.Lib.ExpQ
+```
+
 Copyright
 ---------
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/cabal-doctest-1.0.2/cabal-doctest.cabal 
new/cabal-doctest-1.0.6/cabal-doctest.cabal
--- old/cabal-doctest-1.0.2/cabal-doctest.cabal 2017-05-16 15:13:14.000000000 
+0200
+++ new/cabal-doctest-1.0.6/cabal-doctest.cabal 2018-01-28 16:56:55.000000000 
+0100
@@ -1,5 +1,5 @@
 name:                cabal-doctest
-version:             1.0.2
+version:             1.0.6
 synopsis:            A Setup.hs helper for doctests running
 description:
   Currently (beginning of 2017), there isn't @cabal doctest@
@@ -27,7 +27,7 @@
   GHC==7.8.4,
   GHC==7.10.3,
   GHC==8.0.2,
-  GHC==8.2.1
+  GHC==8.2.2
 
 source-repository head
   type:     git
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/cabal-doctest-1.0.2/src/Distribution/Extra/Doctest.hs 
new/cabal-doctest-1.0.6/src/Distribution/Extra/Doctest.hs
--- old/cabal-doctest-1.0.2/src/Distribution/Extra/Doctest.hs   2017-05-16 
15:13:14.000000000 +0200
+++ new/cabal-doctest-1.0.6/src/Distribution/Extra/Doctest.hs   2018-01-28 
16:56:55.000000000 +0100
@@ -48,14 +48,25 @@
        (when)
 import Data.List
        (nub)
+import Data.Maybe
+       (maybeToList, mapMaybe)
 import Data.String
        (fromString)
+import qualified Data.Foldable as F
+       (for_)
+import qualified Data.Traversable as T
+       (traverse)
+import qualified Distribution.ModuleName as ModuleName
+       (fromString)
+import Distribution.ModuleName
+       (ModuleName)
 import Distribution.Package
        (InstalledPackageId)
 import Distribution.Package
        (Package (..), PackageId, packageVersion)
 import Distribution.PackageDescription
-       (BuildInfo (..), Library (..), PackageDescription (), TestSuite (..))
+       (BuildInfo (..), Executable (..), Library (..), 
GenericPackageDescription,
+       PackageDescription (), TestSuite (..))
 import Distribution.Simple
        (UserHooks (..), autoconfUserHooks, defaultMainWithHooks, 
simpleUserHooks)
 import Distribution.Simple.BuildPaths
@@ -64,15 +75,17 @@
        (PackageDB (..), showCompilerId)
 import Distribution.Simple.LocalBuildInfo
        (ComponentLocalBuildInfo (componentPackageDeps), LocalBuildInfo (),
-       compiler, withLibLBI, withPackageDB, withTestLBI)
+       compiler, withExeLBI, withLibLBI, withPackageDB, withTestLBI)
 import Distribution.Simple.Setup
-       (BuildFlags (buildDistPref, buildVerbosity), fromFlag)
+       (BuildFlags (buildDistPref, buildVerbosity), HaddockFlags 
(haddockDistPref, haddockVerbosity), fromFlag, emptyBuildFlags)
 import Distribution.Simple.Utils
-       (createDirectoryIfMissingVerbose, rewriteFile)
+       (createDirectoryIfMissingVerbose, findFile, rewriteFile)
 import Distribution.Text
        (display, simpleParse)
 import System.FilePath
-       ((</>))
+       ((</>), (<.>), dropExtension)
+
+import Data.IORef (newIORef, modifyIORef, readIORef)
 
 #if MIN_VERSION_Cabal(1,25,0)
 import Distribution.Simple.BuildPaths
@@ -81,6 +94,14 @@
 #if MIN_VERSION_Cabal(2,0,0)
 import Distribution.Types.MungedPackageId
        (MungedPackageId)
+import Distribution.Types.UnqualComponentName
+       (unUnqualComponentName)
+
+-- For amendGPD
+import Distribution.Types.GenericPackageDescription
+       (GenericPackageDescription (condTestSuites))
+import Distribution.PackageDescription
+       (CondTree (..))
 #endif
 
 #if MIN_VERSION_directory(1,2,2)
@@ -135,10 +156,44 @@
 addDoctestsUserHook :: String -> UserHooks -> UserHooks
 addDoctestsUserHook testsuiteName uh = uh
     { buildHook = \pkg lbi hooks flags -> do
-       generateBuildModule testsuiteName flags pkg lbi
-       buildHook uh pkg lbi hooks flags
+        generateBuildModule testsuiteName flags pkg lbi
+        buildHook uh pkg lbi hooks flags
+    -- We use confHook to add "Build_Doctests" to otherModules and 
autogenModules.
+    --
+    -- We cannot use HookedBuildInfo as it let's alter only the library and 
executables.
+    , confHook = \(gpd, hbi) flags ->
+        confHook uh (amendGPD testsuiteName gpd, hbi) flags
+    , haddockHook = \pkg lbi hooks flags -> do
+        generateBuildModule testsuiteName (haddockToBuildFlags flags) pkg lbi
+        haddockHook uh pkg lbi hooks flags
     }
 
+-- | Convert only flags used by 'generateBuildModule'.
+haddockToBuildFlags :: HaddockFlags -> BuildFlags
+haddockToBuildFlags f = emptyBuildFlags
+    { buildVerbosity = haddockVerbosity f
+    , buildDistPref  = haddockDistPref f
+    }
+
+data Name = NameLib (Maybe String) | NameExe String deriving (Eq, Show)
+
+nameToString :: Name -> String
+nameToString n = case n of
+  NameLib x -> maybe "" (("_lib_" ++) . map fixchar) x
+  NameExe x -> "_exe_" ++ map fixchar x
+  where
+    -- Taken from Cabal:
+    -- 
https://github.com/haskell/cabal/blob/20de0bfea72145ba1c37e3f500cee5258cc18e51/Cabal/Distribution/Simple/Build/Macros.hs#L156-L158
+    --
+    -- Needed to fix component names with hyphens in them, as hyphens aren't
+    -- allowed in Haskell identifier names.
+    fixchar :: Char -> Char
+    fixchar '-' = '_'
+    fixchar c   = c
+
+data Component = Component Name [String] [String] [String]
+  deriving Show
+
 -- | Generate a build module for the test suite.
 --
 -- @
@@ -165,87 +220,161 @@
   let dbStack = withPackageDB lbi ++ [ SpecificPackageDB $ distPref </> 
"package.conf.inplace" ]
   let dbFlags = "-hide-all-packages" : packageDbArgs dbStack
 
-  withLibLBI pkg lbi $ \lib libcfg -> do
-    let libBI = libBuildInfo lib
-
-    -- modules
-    let modules = exposedModules lib ++ otherModules libBI
-    -- it seems that doctest is happy to take in module names, not actual 
files!
-    let module_sources = modules
-
-    -- We need the directory with library's cabal_macros.h!
+  withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == fromString 
testSuiteName) $ do
 #if MIN_VERSION_Cabal(1,25,0)
-    let libAutogenDir = autogenComponentModulesDir lbi libcfg
+    let testAutogenDir = autogenComponentModulesDir lbi suitecfg
 #else
-    let libAutogenDir = autogenModulesDir lbi
+    let testAutogenDir = autogenModulesDir lbi
 #endif
 
-    -- Lib sources and includes
-    iArgs' <- mapM (fmap ("-i"++) . makeAbsolute)
-        $ libAutogenDir            -- autogenerated files
-        : (distPref ++ "/build")   -- preprocessed files (.hsc -> .hs); 
"build" is hardcoded in Cabal.
-        : hsSourceDirs libBI
-    includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs libBI
-    -- We clear all includes, so the CWD isn't used.
-    let iArgs = "-i" : iArgs'
-
-    -- default-extensions
-    let extensionArgs = map (("-X"++) . display) $ defaultExtensions libBI
-
-    -- CPP includes, i.e. include cabal_macros.h
-    let cppFlags = map ("-optP"++) $
-            [ "-include", libAutogenDir ++ "/cabal_macros.h" ]
-            ++ cppOptions libBI
-
-    withTestLBI pkg lbi $ \suite suitecfg -> when (testName suite == 
fromString testSuiteName) $ do
-      let testBI = testBuildInfo suite
-
-      -- TODO: `words` is not proper parser (no support for quotes)
-      let additionalFlags = maybe [] words
-            $ lookup "x-doctest-options"
-            $ customFieldsBI testBI
-
-      let additionalModules = maybe [] words
-            $ lookup "x-doctest-modules"
-            $ customFieldsBI testBI
-
-      let additionalDirs' = maybe [] words
-            $ lookup "x-doctest-source-dirs"
-            $ customFieldsBI testBI
-      additionalDirs <- mapM (fmap ("-i" ++) . makeAbsolute) additionalDirs'
+    createDirectoryIfMissingVerbose verbosity True testAutogenDir
 
+    let buildDoctestsFile = testAutogenDir </> "Build_doctests.hs"
 
-      -- get and create autogen dir
+    -- First, we create the autogen'd module Build_doctests.
+    -- Initially populate Build_doctests with a simple preamble.
+    writeFile buildDoctestsFile $ unlines
+      [ "module Build_doctests where"
+      , ""
+      , "import Prelude"
+      , ""
+      , "data Name = NameLib (Maybe String) | NameExe String deriving (Eq, 
Show)"
+      , "data Component = Component Name [String] [String] [String] deriving 
(Eq, Show)"
+      , ""
+      ]
+
+    -- we cannot traverse, only traverse_
+    -- so we use IORef to collect components
+    componentsRef <- newIORef []
+
+    let testBI = testBuildInfo suite
+
+    -- TODO: `words` is not proper parser (no support for quotes)
+    let additionalFlags = maybe [] words
+          $ lookup "x-doctest-options"
+          $ customFieldsBI testBI
+
+    let additionalModules = maybe [] words
+          $ lookup "x-doctest-modules"
+          $ customFieldsBI testBI
+
+    let additionalDirs' = maybe [] words
+          $ lookup "x-doctest-source-dirs"
+          $ customFieldsBI testBI
+
+    additionalDirs <- mapM (fmap ("-i" ++) . makeAbsolute) additionalDirs'
+
+    -- Next, for each component (library or executable), we get to 
Build_doctests
+    -- the sets of flags needed to run doctest on that component.
+    let getBuildDoctests withCompLBI mbCompName compExposedModules compMainIs 
compBuildInfo =
+         withCompLBI pkg lbi $ \comp compCfg -> do
+           let compBI = compBuildInfo comp
+
+           -- modules
+           let modules = compExposedModules comp ++ otherModules compBI
+           -- it seems that doctest is happy to take in module names, not 
actual files!
+           let module_sources = modules
+
+           -- We need the directory with the component's cabal_macros.h!
 #if MIN_VERSION_Cabal(1,25,0)
-      let testAutogenDir = autogenComponentModulesDir lbi suitecfg
+           let compAutogenDir = autogenComponentModulesDir lbi compCfg
 #else
-      let testAutogenDir = autogenModulesDir lbi
+           let compAutogenDir = autogenModulesDir lbi
 #endif
-      createDirectoryIfMissingVerbose verbosity True testAutogenDir
 
-      -- write autogen'd file
-      rewriteFile (testAutogenDir </> "Build_doctests.hs") $ unlines
-        [ "module Build_doctests where"
-        , ""
-        -- -package-id etc. flags
-        , "pkgs :: [String]"
-        , "pkgs = " ++ (show $ formatDeps $ testDeps libcfg suitecfg)
-        , ""
-        , "flags :: [String]"
-        , "flags = " ++ show (concat
-          [ iArgs
-          , additionalDirs
-          , includeArgs
-          , dbFlags
-          , cppFlags
-          , extensionArgs
-          , additionalFlags
-          ])
-        , ""
-        , "module_sources :: [String]"
-        , "module_sources = " ++ show (map display module_sources ++ 
additionalModules)
-        ]
+           -- Lib sources and includes
+           iArgsNoPrefix
+              <- mapM makeAbsolute
+               $ compAutogenDir           -- autogenerated files
+               : (distPref ++ "/build")   -- preprocessed files (.hsc -> .hs); 
"build" is hardcoded in Cabal.
+               : hsSourceDirs compBI
+           includeArgs <- mapM (fmap ("-I"++) . makeAbsolute) $ includeDirs 
compBI
+           -- We clear all includes, so the CWD isn't used.
+           let iArgs' = map ("-i"++) iArgsNoPrefix
+               iArgs  = "-i" : iArgs'
+
+           -- default-extensions
+           let extensionArgs = map (("-X"++) . display) $ defaultExtensions 
compBI
+
+           -- CPP includes, i.e. include cabal_macros.h
+           let cppFlags = map ("-optP"++) $
+                   [ "-include", compAutogenDir ++ "/cabal_macros.h" ]
+                   ++ cppOptions compBI
+
+           -- Unlike other modules, the main-is module of an executable is not
+           -- guaranteed to share a module name with its filepath name. That 
is,
+           -- even though the main-is module is named Main, its filepath might
+           -- actually be Something.hs. To account for this possibility, we 
simply
+           -- pass the full path to the main-is module instead.
+           mainIsPath <- T.traverse (findFile iArgsNoPrefix) (compMainIs comp)
+
+           let all_sources = map display module_sources
+                             ++ additionalModules
+                             ++ maybeToList mainIsPath
+
+           let component = Component
+                (mbCompName comp)
+                (formatDeps $ testDeps compCfg suitecfg)
+                (concat
+                  [ iArgs
+                  , additionalDirs
+                  , includeArgs
+                  , dbFlags
+                  , cppFlags
+                  , extensionArgs
+                  , additionalFlags
+                  ])
+                all_sources
+
+           -- modify IORef, append component
+           modifyIORef componentsRef (\cs -> cs ++ [component])
+
+    -- For now, we only check for doctests in libraries and executables.
+    getBuildDoctests withLibLBI mbLibraryName           exposedModules (const 
Nothing)     libBuildInfo
+    getBuildDoctests withExeLBI (NameExe . executableName) (const [])     
(Just . modulePath) buildInfo
+
+    components <- readIORef componentsRef
+    F.for_ components $ \(Component name pkgs flags sources) -> do
+       let compSuffix          = nameToString name
+           pkgs_comp           = "pkgs"           ++ compSuffix
+           flags_comp          = "flags"          ++ compSuffix
+           module_sources_comp = "module_sources" ++ compSuffix
+
+       -- write autogen'd file
+       appendFile buildDoctestsFile $ unlines
+         [ -- -package-id etc. flags
+           pkgs_comp ++ " :: [String]"
+         , pkgs_comp ++ " = " ++ show pkgs
+         , ""
+         , flags_comp ++ " :: [String]"
+         , flags_comp ++ " = " ++ show flags
+         , ""
+         , module_sources_comp ++ " :: [String]"
+         , module_sources_comp ++ " = " ++ show sources
+         , ""
+         ]
+
+    -- write enabled components, i.e. x-doctest-components
+    -- if none enabled, pick library
+    let enabledComponents = maybe [NameLib Nothing] (mapMaybe 
parseComponentName . words)
+           $ lookup "x-doctest-components"
+           $ customFieldsBI testBI
+
+    let components' =
+         filter (\(Component n _ _ _) -> n `elem` enabledComponents) components
+    appendFile buildDoctestsFile $ unlines
+      [ "-- " ++ show enabledComponents
+      , "components :: [Component]"
+      , "components = " ++ show components'
+      ]
+
   where
+    parseComponentName :: String -> Maybe Name
+    parseComponentName "lib"                       = Just (NameLib Nothing)
+    parseComponentName ('l' : 'i' : 'b' : ':' : x) = Just (NameLib (Just x))
+    parseComponentName ('e' : 'x' : 'e' : ':' : x) = Just (NameExe x)
+    parseComponentName _ = Nothing
+
     -- we do this check in Setup, as then doctests don't need to depend on 
Cabal
     isOldCompiler = maybe False id $ do
       a <- simpleParse $ showCompilerId $ compiler lbi
@@ -302,6 +431,23 @@
        isSpecific (SpecificPackageDB _) = True
        isSpecific _                     = False
 
+    mbLibraryName :: Library -> Name
+#if MIN_VERSION_Cabal(2,0,0)
+    -- Cabal-2.0 introduced internal libraries, which are named.
+    mbLibraryName = NameLib . fmap unUnqualComponentName . libName
+#else
+    -- Before that, there was only ever at most one library per
+    -- .cabal file, which has no name.
+    mbLibraryName _ = NameLib Nothing
+#endif
+
+    executableName :: Executable -> String
+#if MIN_VERSION_Cabal(2,0,0)
+    executableName = unUnqualComponentName . exeName
+#else
+    executableName = exeName
+#endif
+
 -- | In compat settings it's better to omit the type-signature
 testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo
 #if MIN_VERSION_Cabal(2,0,0)
@@ -310,3 +456,41 @@
          -> [(InstalledPackageId, PackageId)]
 #endif
 testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys
+
+amendGPD
+    :: String -- ^ doctests test-suite name
+    -> GenericPackageDescription
+    -> GenericPackageDescription
+#if !(MIN_VERSION_Cabal(2,0,0))
+amendGPD _ = id
+#else
+amendGPD testSuiteName gpd = gpd
+    { condTestSuites = map f (condTestSuites gpd)
+    }
+  where
+    f (name, condTree)
+        | name == fromString testSuiteName = (name, condTree')
+        | otherwise                        = (name, condTree)
+      where
+        -- I miss 'lens'
+        testSuite = condTreeData condTree
+        bi = testBuildInfo testSuite
+        om = otherModules bi
+        am = autogenModules bi
+
+        -- Cons the module to both other-modules and autogen-modules.
+        -- At the moment, cabal-spec-2.0 and cabal-spec-2.2 don't have
+        -- "all autogen-modules are other-modules if they aren't 
exposed-modules"
+        -- rule. Hopefully cabal-spec-3.0 will have.
+        --
+        -- Note: we `nub`, because it's unclear if that's ok to have duplicate
+        -- modules in the lists.
+        om' = nub $ mn : om
+        am' = nub $ mn : am
+
+        mn = fromString "Build_doctests"
+
+        bi' = bi { otherModules = om', autogenModules = am' }
+        testSuite' = testSuite { testBuildInfo = bi' }
+        condTree' = condTree { condTreeData = testSuite' }
+#endif

++++++ cabal-doctest.cabal ++++++
name:                cabal-doctest
version:             1.0.6
x-revision:          1
synopsis:            A Setup.hs helper for doctests running
description:
  Currently (beginning of 2017), there isn't @cabal doctest@
  command. Yet, to properly work doctest needs plenty of configuration.
  This library provides the common bits for writing custom Setup.hs

  See <https://github.com/haskell/cabal/issues/2327 Cabal/2327> for the progress
  of @cabal doctest@, i.e. whether this library is obsolete.

homepage:            https://github.com/phadej/cabal-doctest
license:             BSD3
license-file:        LICENSE
author:              Oleg Grenrus <oleg.gren...@iki.fi>
maintainer:          Oleg Grenrus <oleg.gren...@iki.fi>
copyright:           (c) 2017 Oleg Grenrus
category:            Distribution
build-type:          Simple
cabal-version:       >=1.10
extra-source-files:  ChangeLog.md README.md
tested-with:
  GHC==7.0.4,
  GHC==7.2.2,
  GHC==7.4.2,
  GHC==7.6.3,
  GHC==7.8.4,
  GHC==7.10.3,
  GHC==8.0.2,
  GHC==8.2.2,
  GHC==8.4.1

source-repository head
  type:     git
  location: https://github.com/phadej/cabal-doctest

library
  exposed-modules:     Distribution.Extra.Doctest
  other-modules:
  other-extensions:
  build-depends:
    base >=4.3 && <4.12,
    Cabal >= 1.10 && <2.3,
    filepath,
    directory
  hs-source-dirs:      src
  default-language:    Haskell2010

Reply via email to