diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs index 9a311dfcf3b91619a46b4820c2be703f9ad0eeb7..8787e06ee19fd8b7e9a0910898c4b8ba12c345e4 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs @@ -346,7 +346,15 @@ commandLineFlagsToProjectConfig globalFlags NixStyleFlags {..} clientInstallFlag splitConfig pc = (pc , mempty { packageConfigProgramPaths = packageConfigProgramPaths pc , packageConfigProgramPathExtra = packageConfigProgramPathExtra pc - , packageConfigDocumentation = packageConfigDocumentation pc }) + + -- Some flags to haddock should be passed to dependencies + , packageConfigDocumentation = packageConfigDocumentation pc + , packageConfigHaddockHoogle = packageConfigHaddockHoogle pc + , packageConfigHaddockHtml = packageConfigHaddockHtml pc + , packageConfigHaddockInternal = packageConfigHaddockInternal pc + , packageConfigHaddockQuickJump = packageConfigHaddockQuickJump pc + , packageConfigHaddockLinkedSource = packageConfigHaddockLinkedSource pc + }) -- | Convert from the types currently used for the user-wide @~/.cabal/config@ -- file into the 'ProjectConfig' type. diff --git a/cabal-testsuite/PackageTests/HaddockArgs/cabal.project b/cabal-testsuite/PackageTests/HaddockArgs/cabal.project new file mode 100644 index 0000000000000000000000000000000000000000..5356e76f67c76ea1cf221ce38a73edef1002225e --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/cabal.project @@ -0,0 +1 @@ +packages: . \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/HaddockArgs/example.cabal b/cabal-testsuite/PackageTests/HaddockArgs/example.cabal new file mode 100644 index 0000000000000000000000000000000000000000..4d79700909cd16288f9a1cd747f8a815b26276c6 --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/example.cabal @@ -0,0 +1,12 @@ +name: example +version: 1.0 +build-type: Simple +cabal-version: >= 1.10 + + +library + hs-source-dirs: src + exposed-modules: Lib + build-depends: base, indef + default-language: Haskell2010 + diff --git a/cabal-testsuite/PackageTests/HaddockArgs/hoogle.out b/cabal-testsuite/PackageTests/HaddockArgs/hoogle.out new file mode 100644 index 0000000000000000000000000000000000000000..72a4cc8f3c8ea4b8356445bcb41e1e6876c4d2d1 --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/hoogle.out @@ -0,0 +1,35 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-<GHCVER> -O1 +In order, the following will be built: + - sigs-0.1.0.0 (lib) (requires build) + - indef-0.1.0.0 (lib) (requires build) + - example-1.0 (lib) (first run) +Configuring library for sigs-0.1.0.0.. +Preprocessing library for sigs-0.1.0.0.. +Building library instantiated with Data.Map = <Data.Map> +for sigs-0.1.0.0.. +Preprocessing library for sigs-0.1.0.0.. +Running Haddock on library instantiated with Data.Map = <Data.Map> +for sigs-0.1.0.0.. +Documentation created: dist/doc/html/sigs/sigs.txt +Installing library in <PATH> +Configuring library for indef-0.1.0.0.. +Preprocessing library for indef-0.1.0.0.. +Building library instantiated with Data.Map = <Data.Map> +for indef-0.1.0.0.. +Preprocessing library for indef-0.1.0.0.. +Running Haddock on library instantiated with Data.Map = <Data.Map> +for indef-0.1.0.0.. +Documentation created: dist/doc/html/indef/indef.txt +Installing library in <PATH> +Configuring library for example-1.0.. +Preprocessing library for example-1.0.. +Building library instantiated with Data.Map = <Data.Map> +for example-1.0.. +Preprocessing library for example-1.0.. +Running Haddock on library instantiated with Data.Map = <Data.Map> +for example-1.0.. +Documentation created: <ROOT>/hoogle.dist/work/dist/build/<ARCH>/ghc-<GHCVER>/example-1.0/doc/html/example/example.txt diff --git a/cabal-testsuite/PackageTests/HaddockArgs/hoogle.test.hs b/cabal-testsuite/PackageTests/HaddockArgs/hoogle.test.hs new file mode 100644 index 0000000000000000000000000000000000000000..531072e3139d02cc046bc8c9df686f95f74a88cd --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/hoogle.test.hs @@ -0,0 +1,11 @@ +import Test.Cabal.Prelude + +main = withShorterPathForNewBuildStore $ \storeDir -> cabalTest $ withRepo "repo" $ do + -- Checks if hoogle txt files are generated. + -- Logs contain something like "Documentation created: dist/doc/html/indef/indef.txt", so we don't need + -- to do extra check + cabalG ["--store-dir=" ++ storeDir] "v2-build" + [ "example" + , "--enable-documentation" + , "--haddock-hoogle" + ] diff --git a/cabal-testsuite/PackageTests/HaddockArgs/quickjump.out b/cabal-testsuite/PackageTests/HaddockArgs/quickjump.out new file mode 100644 index 0000000000000000000000000000000000000000..3cafb20670e693c91913dc90d91eba41f8c4d7ed --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/quickjump.out @@ -0,0 +1,35 @@ +# cabal v2-update +Downloading the latest package list from test-local-repo +# cabal v2-build +Resolving dependencies... +Build profile: -w ghc-<GHCVER> -O1 +In order, the following will be built: + - sigs-0.1.0.0 (lib) (requires build) + - indef-0.1.0.0 (lib) (requires build) + - example-1.0 (lib) (first run) +Configuring library for sigs-0.1.0.0.. +Preprocessing library for sigs-0.1.0.0.. +Building library instantiated with Data.Map = <Data.Map> +for sigs-0.1.0.0.. +Preprocessing library for sigs-0.1.0.0.. +Running Haddock on library instantiated with Data.Map = <Data.Map> +for sigs-0.1.0.0.. +Documentation created: dist/doc/html/sigs/index.html +Installing library in <PATH> +Configuring library for indef-0.1.0.0.. +Preprocessing library for indef-0.1.0.0.. +Building library instantiated with Data.Map = <Data.Map> +for indef-0.1.0.0.. +Preprocessing library for indef-0.1.0.0.. +Running Haddock on library instantiated with Data.Map = <Data.Map> +for indef-0.1.0.0.. +Documentation created: dist/doc/html/indef/index.html +Installing library in <PATH> +Configuring library for example-1.0.. +Preprocessing library for example-1.0.. +Building library instantiated with Data.Map = <Data.Map> +for example-1.0.. +Preprocessing library for example-1.0.. +Running Haddock on library instantiated with Data.Map = <Data.Map> +for example-1.0.. +Documentation created: <ROOT>/quickjump.dist/work/dist/build/<ARCH>/ghc-<GHCVER>/example-1.0/doc/html/example/index.html \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/HaddockArgs/quickjump.test.hs b/cabal-testsuite/PackageTests/HaddockArgs/quickjump.test.hs new file mode 100644 index 0000000000000000000000000000000000000000..3b8a3281d699076c4ebd9f6f1a29738b838499e3 --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/quickjump.test.hs @@ -0,0 +1,16 @@ +import Test.Cabal.Prelude + +import System.Directory +import System.FilePath + +main = withShorterPathForNewBuildStore $ \storeDir -> cabalTest $ withRepo "repo" $ do + cabalG ["--store-dir=" ++ storeDir] "v2-build" + [ "example" + , "--enable-documentation" + , "--haddock-quickjump" + ] + liftIO $ do + libDir <- findDependencyInStore storeDir "indef" + assertFileDoesContain (libDir </> "cabal-hash.txt") "haddock-quickjump: True" + docIndexJsonExists <- doesFileExist (libDir </> "share" </> "doc" </> "html" </> "doc-index.json") + assertBool "doc-index.json doesn't exist, --quickjump is probably not passed to haddock" docIndexJsonExists diff --git a/cabal-testsuite/PackageTests/HaddockArgs/repo/exe-0.1.0.0/Main.hs b/cabal-testsuite/PackageTests/HaddockArgs/repo/exe-0.1.0.0/Main.hs new file mode 100644 index 0000000000000000000000000000000000000000..e0cb6d02c6e3635f943d460fcb16f4179d6559c2 --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/repo/exe-0.1.0.0/Main.hs @@ -0,0 +1,4 @@ +import qualified Data.Map as Map +import Data.Map (Map) +import Foo +main = print $ f (+1) (Map.fromList [(0,1),(2,3)] :: Map Int Int) diff --git a/cabal-testsuite/PackageTests/HaddockArgs/repo/exe-0.1.0.0/exe.cabal b/cabal-testsuite/PackageTests/HaddockArgs/repo/exe-0.1.0.0/exe.cabal new file mode 100644 index 0000000000000000000000000000000000000000..2896d952e088073dccacaa226b2578060ce702cd --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/repo/exe-0.1.0.0/exe.cabal @@ -0,0 +1,12 @@ +name: exe +version: 0.1.0.0 +license: BSD3 +author: Edward Z. Yang +maintainer: ezyang@cs.stanford.edu +build-type: Simple +cabal-version: 2.0 + +executable exe + build-depends: base, containers, indef + main-is: Main.hs + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/HaddockArgs/repo/indef-0.1.0.0/Foo.hs b/cabal-testsuite/PackageTests/HaddockArgs/repo/indef-0.1.0.0/Foo.hs new file mode 100644 index 0000000000000000000000000000000000000000..527e793e9872ea55a05b45ea6308507833e3029b --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/repo/indef-0.1.0.0/Foo.hs @@ -0,0 +1,7 @@ +module Foo where + +import Data.Map + +-- | A dummy function using 'Map' +f :: (a -> b) -> Map k a -> Map k b +f = fmap diff --git a/cabal-testsuite/PackageTests/HaddockArgs/repo/indef-0.1.0.0/indef.cabal b/cabal-testsuite/PackageTests/HaddockArgs/repo/indef-0.1.0.0/indef.cabal new file mode 100644 index 0000000000000000000000000000000000000000..1281fd7231edea4bf41eb0b9b604080729357bdf --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/repo/indef-0.1.0.0/indef.cabal @@ -0,0 +1,12 @@ +name: indef +version: 0.1.0.0 +license: BSD3 +author: Edward Z. Yang +maintainer: ezyang@cs.stanford.edu +build-type: Simple +cabal-version: 2.0 + +library + build-depends: base, sigs + exposed-modules: Foo + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/HaddockArgs/repo/sigs-0.1.0.0/Data/Map.hsig b/cabal-testsuite/PackageTests/HaddockArgs/repo/sigs-0.1.0.0/Data/Map.hsig new file mode 100644 index 0000000000000000000000000000000000000000..997ec1aa576d7fb5f4070a54644b71d175c627ae --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/repo/sigs-0.1.0.0/Data/Map.hsig @@ -0,0 +1,5 @@ +{-# LANGUAGE RoleAnnotations #-} +signature Data.Map where +type role Map nominal representational +data Map k a +instance Functor (Map k) diff --git a/cabal-testsuite/PackageTests/HaddockArgs/repo/sigs-0.1.0.0/sigs.cabal b/cabal-testsuite/PackageTests/HaddockArgs/repo/sigs-0.1.0.0/sigs.cabal new file mode 100644 index 0000000000000000000000000000000000000000..0d7d1fb50ad66335205201c8533a57af40e9c05f --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/repo/sigs-0.1.0.0/sigs.cabal @@ -0,0 +1,12 @@ +name: sigs +version: 0.1.0.0 +license: BSD3 +author: Edward Z. Yang +maintainer: ezyang@cs.stanford.edu +build-type: Simple +cabal-version: 2.0 + +library + build-depends: base + signatures: Data.Map + default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/HaddockArgs/src/Lib.hs b/cabal-testsuite/PackageTests/HaddockArgs/src/Lib.hs new file mode 100644 index 0000000000000000000000000000000000000000..485d0bd1f757e445ef8acfa40253cd7ded1095ca --- /dev/null +++ b/cabal-testsuite/PackageTests/HaddockArgs/src/Lib.hs @@ -0,0 +1,7 @@ +module Lib where + +import Foo + +-- | See 'f' +main :: IO () +main = putStrLn "Hello, Haskell!" diff --git a/cabal-testsuite/src/Test/Cabal/Prelude.hs b/cabal-testsuite/src/Test/Cabal/Prelude.hs index 2bcd4112617931e61f2b2a663f18842b8e1f3d95..6f8a0a7c51655b4a12f6c89e5a4c254e20d3935c 100644 --- a/cabal-testsuite/src/Test/Cabal/Prelude.hs +++ b/cabal-testsuite/src/Test/Cabal/Prelude.hs @@ -62,7 +62,7 @@ import System.Exit (ExitCode (..)) import System.FilePath ((</>), takeExtensions, takeDrive, takeDirectory, normalise, splitPath, joinPath, splitFileName, (<.>), dropTrailingPathSeparator) import Control.Concurrent (threadDelay) import qualified Data.Char as Char -import System.Directory (getTemporaryDirectory, getCurrentDirectory, canonicalizePath, copyFile, copyFile, doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getDirectoryContents) +import System.Directory (getTemporaryDirectory, getCurrentDirectory, canonicalizePath, copyFile, copyFile, doesDirectoryExist, doesFileExist, createDirectoryIfMissing, getDirectoryContents, listDirectory) import Control.Retry (exponentialBackoff, limitRetriesByCumulativeDelay) import Network.Wait (waitTcpVerbose) @@ -1131,3 +1131,21 @@ withShorterPathForNewBuildStore test = do then takeDrive `fmap` getCurrentDirectory else getTemporaryDirectory withTempDirectory normal tempDir "cabal-test-store" test + +-- | Find where a package locates in the store dir. This works only if there is exactly one 1 ghc version +-- and exactly 1 directory for the given package in the store dir. +findDependencyInStore :: FilePath -- ^store dir + -> String -- ^package name prefix + -> IO FilePath -- ^package dir +findDependencyInStore storeDir pkgName = do + storeDirForGhcVersion <- head <$> listDirectory storeDir + packageDirs <- listDirectory (storeDir </> storeDirForGhcVersion) + -- Ideally, we should call 'hashedInstalledPackageId' from 'Distribution.Client.PackageHash'. + -- But 'PackageHashInputs', especially 'PackageHashConfigInputs', is too hard to construct. + let pkgName' = + if buildOS == OSX + then filter (not . flip elem "aeiou") pkgName + -- simulates the way 'hashedInstalledPackageId' uses to compress package name + else pkgName + let libDir = head $ filter (pkgName' `isPrefixOf`) packageDirs + pure (storeDir </> storeDirForGhcVersion </> libDir) diff --git a/changelog.d/pr-8414 b/changelog.d/pr-8414 new file mode 100644 index 0000000000000000000000000000000000000000..b046cea70e040384232835f9b981943dec651d81 --- /dev/null +++ b/changelog.d/pr-8414 @@ -0,0 +1,11 @@ +synopsis: Pass some haddock flags to dependencies +packages: cabal-install +prs: #8414 +issues: #8104 #395 + +description: { + +- Pass "--haddock-hoogle", "--haddock-html", "--haddock-internal", "--haddock-quickjump", "--haddock-hyperlinked-source" + to all the dependencies if they are specified as command line args + +}