From ea85fca73e0ad506414222834985469be2fa13de Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sat, 14 Oct 2023 16:27:54 +0100 Subject: [PATCH] Fix #5210 Don't refer to index.html when Haddock will not create it --- Cabal/src/Distribution/Simple/Haddock.hs | 9 ++++++++- .../HaddockOutput/HaddockForHackageCmdOutput/A/A.cabal | 10 ++++++++++ .../HaddockOutput/HaddockForHackageCmdOutput/A/A.hs | 6 ++++++ .../HaddockOutput/HaddockForHackageCmdOutput/cabal.out | 10 ++++++++++ .../HaddockForHackageCmdOutput/cabal.project | 1 + .../HaddockForHackageCmdOutput/cabal.test.hs | 7 +++++++ changelog.d/pr-9332 | 4 ++++ 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/A/A.cabal create mode 100644 cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/A/A.hs create mode 100644 cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.out create mode 100644 cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.project create mode 100644 cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.test.hs create mode 100644 changelog.d/pr-9332 diff --git a/Cabal/src/Distribution/Simple/Haddock.hs b/Cabal/src/Distribution/Simple/Haddock.hs index 784894325cb..f06824b24a9 100644 --- a/Cabal/src/Distribution/Simple/Haddock.hs +++ b/Cabal/src/Distribution/Simple/Haddock.hs @@ -821,6 +821,13 @@ renderArgs verbosity tmpFileOpts version comp platform args k = do else k (renderedArgs, result) where outputDir = (unDir $ argOutputDir args) + isNotArgContents = isNothing (flagToMaybe $ argContents args) + isNotArgIndex = isNothing (flagToMaybe $ argIndex args) + isArgGenIndex = fromFlagOrDefault False (argGenIndex args) + -- Haddock, when generating HTML, does not generate an index if the options + -- --use-contents or --use-index are passed to it. See + -- https://haskell-haddock.readthedocs.io/en/latest/invoking.html#cmdoption-use-contents + isIndexGenerated = isArgGenIndex && isNotArgContents && isNotArgIndex result = intercalate ", " . map @@ -828,7 +835,7 @@ renderArgs verbosity tmpFileOpts version comp platform args k = do outputDir case o of Html - | fromFlagOrDefault False (argGenIndex args) -> + | isIndexGenerated -> "index.html" Html | otherwise -> diff --git a/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/A/A.cabal b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/A/A.cabal new file mode 100644 index 00000000000..6808223d511 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/A/A.cabal @@ -0,0 +1,10 @@ +cabal-version: 3.6 +name: A +synopsis: A minimal test package for testing haddock. +version: 0.0.0 + +library + build-depends: base + default-language: Haskell2010 + exposed-modules: A + hs-source-dirs: . diff --git a/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/A/A.hs b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/A/A.hs new file mode 100644 index 00000000000..d34efe10291 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/A/A.hs @@ -0,0 +1,6 @@ +-- | A minimal test module for testing haddock. +module A (a) where + +-- | a is zero. +a :: Int +a = 0 diff --git a/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.out b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.out new file mode 100644 index 00000000000..e17593a966c --- /dev/null +++ b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.out @@ -0,0 +1,10 @@ +# cabal haddock +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - A-0.0.0 (lib) (first run) +Configuring library for A-0.0.0... +Preprocessing library for A-0.0.0... +Running Haddock on library for A-0.0.0... +Documentation created: /cabal.dist/work/dist/build//ghc-/A-0.0.0/doc/html/A-0.0.0-docs/, /cabal.dist/work/dist/build//ghc-/A-0.0.0/doc/html/A-0.0.0-docs/A.txt +Documentation tarball created: /cabal.dist/work/./dist/A-0.0.0-docs.tar.gz diff --git a/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.project b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.project new file mode 100644 index 00000000000..421457f944c --- /dev/null +++ b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.project @@ -0,0 +1 @@ +packages: A diff --git a/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.test.hs b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.test.hs new file mode 100644 index 00000000000..00fcfe4b28e --- /dev/null +++ b/cabal-testsuite/PackageTests/NewHaddock/HaddockOutput/HaddockForHackageCmdOutput/cabal.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude + +-- Test that `cabal haddock --haddock-for-hackage` does not report that it +-- creates an `index.html` file. +main = cabalTest $ do + r <- cabal' "haddock" ["--haddock-for-hackage", "A"] + assertOutputDoesNotContain "index.html" r diff --git a/changelog.d/pr-9332 b/changelog.d/pr-9332 new file mode 100644 index 00000000000..c5d4c3d4ac4 --- /dev/null +++ b/changelog.d/pr-9332 @@ -0,0 +1,4 @@ +synopsis: Don't report `index.html` file as created, if not created by Haddock +packages: Cabal cabal-install +prs: #9332 +issues: #5120