Skip to content

Commit 55b4ed9

Browse files
author
Kobayashi
authored
Pass some haddock flags to dependencies (#8414)
* pass some haddock flags to dependencies * add tests * add changelog * fix whitespace * fix test on MacOS
1 parent d45f3d8 commit 55b4ed9

File tree

16 files changed

+208
-2
lines changed

16 files changed

+208
-2
lines changed

cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,15 @@ commandLineFlagsToProjectConfig globalFlags NixStyleFlags {..} clientInstallFlag
346346
splitConfig pc = (pc
347347
, mempty { packageConfigProgramPaths = packageConfigProgramPaths pc
348348
, packageConfigProgramPathExtra = packageConfigProgramPathExtra pc
349-
, packageConfigDocumentation = packageConfigDocumentation pc })
349+
350+
-- Some flags to haddock should be passed to dependencies
351+
, packageConfigDocumentation = packageConfigDocumentation pc
352+
, packageConfigHaddockHoogle = packageConfigHaddockHoogle pc
353+
, packageConfigHaddockHtml = packageConfigHaddockHtml pc
354+
, packageConfigHaddockInternal = packageConfigHaddockInternal pc
355+
, packageConfigHaddockQuickJump = packageConfigHaddockQuickJump pc
356+
, packageConfigHaddockLinkedSource = packageConfigHaddockLinkedSource pc
357+
})
350358

351359
-- | Convert from the types currently used for the user-wide @~/.cabal/config@
352360
-- file into the 'ProjectConfig' type.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: example
2+
version: 1.0
3+
build-type: Simple
4+
cabal-version: >= 1.10
5+
6+
7+
library
8+
hs-source-dirs: src
9+
exposed-modules: Lib
10+
build-depends: base, indef
11+
default-language: Haskell2010
12+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# cabal v2-update
2+
Downloading the latest package list from test-local-repo
3+
# cabal v2-build
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- sigs-0.1.0.0 (lib) (requires build)
8+
- indef-0.1.0.0 (lib) (requires build)
9+
- example-1.0 (lib) (first run)
10+
Configuring library for sigs-0.1.0.0..
11+
Preprocessing library for sigs-0.1.0.0..
12+
Building library instantiated with Data.Map = <Data.Map>
13+
for sigs-0.1.0.0..
14+
Preprocessing library for sigs-0.1.0.0..
15+
Running Haddock on library instantiated with Data.Map = <Data.Map>
16+
for sigs-0.1.0.0..
17+
Documentation created: dist/doc/html/sigs/sigs.txt
18+
Installing library in <PATH>
19+
Configuring library for indef-0.1.0.0..
20+
Preprocessing library for indef-0.1.0.0..
21+
Building library instantiated with Data.Map = <Data.Map>
22+
for indef-0.1.0.0..
23+
Preprocessing library for indef-0.1.0.0..
24+
Running Haddock on library instantiated with Data.Map = <Data.Map>
25+
for indef-0.1.0.0..
26+
Documentation created: dist/doc/html/indef/indef.txt
27+
Installing library in <PATH>
28+
Configuring library for example-1.0..
29+
Preprocessing library for example-1.0..
30+
Building library instantiated with Data.Map = <Data.Map>
31+
for example-1.0..
32+
Preprocessing library for example-1.0..
33+
Running Haddock on library instantiated with Data.Map = <Data.Map>
34+
for example-1.0..
35+
Documentation created: <ROOT>/hoogle.dist/work/dist/build/<ARCH>/ghc-<GHCVER>/example-1.0/doc/html/example/example.txt
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Test.Cabal.Prelude
2+
3+
main = withShorterPathForNewBuildStore $ \storeDir -> cabalTest $ withRepo "repo" $ do
4+
-- Checks if hoogle txt files are generated.
5+
-- Logs contain something like "Documentation created: dist/doc/html/indef/indef.txt", so we don't need
6+
-- to do extra check
7+
cabalG ["--store-dir=" ++ storeDir] "v2-build"
8+
[ "example"
9+
, "--enable-documentation"
10+
, "--haddock-hoogle"
11+
]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# cabal v2-update
2+
Downloading the latest package list from test-local-repo
3+
# cabal v2-build
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- sigs-0.1.0.0 (lib) (requires build)
8+
- indef-0.1.0.0 (lib) (requires build)
9+
- example-1.0 (lib) (first run)
10+
Configuring library for sigs-0.1.0.0..
11+
Preprocessing library for sigs-0.1.0.0..
12+
Building library instantiated with Data.Map = <Data.Map>
13+
for sigs-0.1.0.0..
14+
Preprocessing library for sigs-0.1.0.0..
15+
Running Haddock on library instantiated with Data.Map = <Data.Map>
16+
for sigs-0.1.0.0..
17+
Documentation created: dist/doc/html/sigs/index.html
18+
Installing library in <PATH>
19+
Configuring library for indef-0.1.0.0..
20+
Preprocessing library for indef-0.1.0.0..
21+
Building library instantiated with Data.Map = <Data.Map>
22+
for indef-0.1.0.0..
23+
Preprocessing library for indef-0.1.0.0..
24+
Running Haddock on library instantiated with Data.Map = <Data.Map>
25+
for indef-0.1.0.0..
26+
Documentation created: dist/doc/html/indef/index.html
27+
Installing library in <PATH>
28+
Configuring library for example-1.0..
29+
Preprocessing library for example-1.0..
30+
Building library instantiated with Data.Map = <Data.Map>
31+
for example-1.0..
32+
Preprocessing library for example-1.0..
33+
Running Haddock on library instantiated with Data.Map = <Data.Map>
34+
for example-1.0..
35+
Documentation created: <ROOT>/quickjump.dist/work/dist/build/<ARCH>/ghc-<GHCVER>/example-1.0/doc/html/example/index.html
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Test.Cabal.Prelude
2+
3+
import System.Directory
4+
import System.FilePath
5+
6+
main = withShorterPathForNewBuildStore $ \storeDir -> cabalTest $ withRepo "repo" $ do
7+
cabalG ["--store-dir=" ++ storeDir] "v2-build"
8+
[ "example"
9+
, "--enable-documentation"
10+
, "--haddock-quickjump"
11+
]
12+
liftIO $ do
13+
libDir <- findDependencyInStore storeDir "indef"
14+
assertFileDoesContain (libDir </> "cabal-hash.txt") "haddock-quickjump: True"
15+
docIndexJsonExists <- doesFileExist (libDir </> "share" </> "doc" </> "html" </> "doc-index.json")
16+
assertBool "doc-index.json doesn't exist, --quickjump is probably not passed to haddock" docIndexJsonExists
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import qualified Data.Map as Map
2+
import Data.Map (Map)
3+
import Foo
4+
main = print $ f (+1) (Map.fromList [(0,1),(2,3)] :: Map Int Int)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: exe
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Simple
7+
cabal-version: 2.0
8+
9+
executable exe
10+
build-depends: base, containers, indef
11+
main-is: Main.hs
12+
default-language: Haskell2010
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Foo where
2+
3+
import Data.Map
4+
5+
-- | A dummy function using 'Map'
6+
f :: (a -> b) -> Map k a -> Map k b
7+
f = fmap
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: indef
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Simple
7+
cabal-version: 2.0
8+
9+
library
10+
build-depends: base, sigs
11+
exposed-modules: Foo
12+
default-language: Haskell2010
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE RoleAnnotations #-}
2+
signature Data.Map where
3+
type role Map nominal representational
4+
data Map k a
5+
instance Functor (Map k)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: sigs
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Simple
7+
cabal-version: 2.0
8+
9+
library
10+
build-depends: base
11+
signatures: Data.Map
12+
default-language: Haskell2010
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Lib where
2+
3+
import Foo
4+
5+
-- | See 'f'
6+
main :: IO ()
7+
main = putStrLn "Hello, Haskell!"

cabal-testsuite/src/Test/Cabal/Prelude.hs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import System.Exit (ExitCode (..))
6262
import System.FilePath ((</>), takeExtensions, takeDrive, takeDirectory, normalise, splitPath, joinPath, splitFileName, (<.>), dropTrailingPathSeparator)
6363
import Control.Concurrent (threadDelay)
6464
import qualified Data.Char as Char
65-
import System.Directory (getTemporaryDirectory, getCurrentDirectory, canonicalizePath, copyFile, copyFile, doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getDirectoryContents)
65+
import System.Directory (getTemporaryDirectory, getCurrentDirectory, canonicalizePath, copyFile, copyFile, doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getDirectoryContents, listDirectory)
6666
import Control.Retry (exponentialBackoff, limitRetriesByCumulativeDelay)
6767
import Network.Wait (waitTcpVerbose)
6868

@@ -1131,3 +1131,21 @@ withShorterPathForNewBuildStore test = do
11311131
then takeDrive `fmap` getCurrentDirectory
11321132
else getTemporaryDirectory
11331133
withTempDirectory normal tempDir "cabal-test-store" test
1134+
1135+
-- | Find where a package locates in the store dir. This works only if there is exactly one 1 ghc version
1136+
-- and exactly 1 directory for the given package in the store dir.
1137+
findDependencyInStore :: FilePath -- ^store dir
1138+
-> String -- ^package name prefix
1139+
-> IO FilePath -- ^package dir
1140+
findDependencyInStore storeDir pkgName = do
1141+
storeDirForGhcVersion <- head <$> listDirectory storeDir
1142+
packageDirs <- listDirectory (storeDir </> storeDirForGhcVersion)
1143+
-- Ideally, we should call 'hashedInstalledPackageId' from 'Distribution.Client.PackageHash'.
1144+
-- But 'PackageHashInputs', especially 'PackageHashConfigInputs', is too hard to construct.
1145+
let pkgName' =
1146+
if buildOS == OSX
1147+
then filter (not . flip elem "aeiou") pkgName
1148+
-- simulates the way 'hashedInstalledPackageId' uses to compress package name
1149+
else pkgName
1150+
let libDir = head $ filter (pkgName' `isPrefixOf`) packageDirs
1151+
pure (storeDir </> storeDirForGhcVersion </> libDir)

changelog.d/pr-8414

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
synopsis: Pass some haddock flags to dependencies
2+
packages: cabal-install
3+
prs: #8414
4+
issues: #8104 #395
5+
6+
description: {
7+
8+
- Pass "--haddock-hoogle", "--haddock-html", "--haddock-internal", "--haddock-quickjump", "--haddock-hyperlinked-source"
9+
to all the dependencies if they are specified as command line args
10+
11+
}

0 commit comments

Comments
 (0)