Skip to content

Commit

Permalink
Merge pull request #9966 from sheaf/haddock-tmpFiles
Browse files Browse the repository at this point in the history
Haddock: use buildSettingKeepTempFiles
  • Loading branch information
mergify[bot] authored May 10, 2024
2 parents fd8020f + e35c0dc commit 214acd8
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ buildAndRegisterUnpackedPackage
verbosity
distDirLayout@DistDirLayout{distTempDirectory}
maybe_semaphore
BuildTimeSettings{buildSettingNumJobs}
buildTimeSettings@BuildTimeSettings{buildSettingNumJobs}
registerLock
cacheLock
pkgshared@ElaboratedSharedConfig
Expand Down Expand Up @@ -329,6 +329,7 @@ buildAndRegisterUnpackedPackage
setupHsHaddockFlags
pkg
pkgshared
buildTimeSettings
(commonFlags v)
haddockArgs v =
flip filterHaddockArgs v $
Expand Down
71 changes: 38 additions & 33 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4101,41 +4101,46 @@ setupHsRegisterFlags
setupHsHaddockFlags
:: ElaboratedConfiguredPackage
-> ElaboratedSharedConfig
-> BuildTimeSettings
-> Cabal.CommonSetupFlags
-> Cabal.HaddockFlags
setupHsHaddockFlags (ElaboratedConfiguredPackage{..}) (ElaboratedSharedConfig{..}) common =
Cabal.HaddockFlags
{ haddockCommonFlags = common
, haddockProgramPaths =
case lookupProgram haddockProgram pkgConfigCompilerProgs of
Nothing -> mempty
Just prg ->
[
( programName haddockProgram
, locationPath (programLocation prg)
)
]
, haddockProgramArgs = mempty -- unused, set at configure time
, haddockHoogle = toFlag elabHaddockHoogle
, haddockHtml = toFlag elabHaddockHtml
, haddockHtmlLocation = maybe mempty toFlag elabHaddockHtmlLocation
, haddockForHackage = toFlag elabHaddockForHackage
, haddockForeignLibs = toFlag elabHaddockForeignLibs
, haddockExecutables = toFlag elabHaddockExecutables
, haddockTestSuites = toFlag elabHaddockTestSuites
, haddockBenchmarks = toFlag elabHaddockBenchmarks
, haddockInternal = toFlag elabHaddockInternal
, haddockCss = maybe mempty toFlag elabHaddockCss
, haddockLinkedSource = toFlag elabHaddockLinkedSource
, haddockQuickJump = toFlag elabHaddockQuickJump
, haddockHscolourCss = maybe mempty toFlag elabHaddockHscolourCss
, haddockContents = maybe mempty toFlag elabHaddockContents
, haddockKeepTempFiles = mempty -- TODO: from build settings
, haddockIndex = maybe mempty toFlag elabHaddockIndex
, haddockBaseUrl = maybe mempty toFlag elabHaddockBaseUrl
, haddockLib = maybe mempty toFlag elabHaddockLib
, haddockOutputDir = maybe mempty toFlag elabHaddockOutputDir
}
setupHsHaddockFlags
(ElaboratedConfiguredPackage{..})
(ElaboratedSharedConfig{..})
(BuildTimeSettings{buildSettingKeepTempFiles = keepTmpFiles})
common =
Cabal.HaddockFlags
{ haddockCommonFlags = common
, haddockProgramPaths =
case lookupProgram haddockProgram pkgConfigCompilerProgs of
Nothing -> mempty
Just prg ->
[
( programName haddockProgram
, locationPath (programLocation prg)
)
]
, haddockProgramArgs = mempty -- unused, set at configure time
, haddockHoogle = toFlag elabHaddockHoogle
, haddockHtml = toFlag elabHaddockHtml
, haddockHtmlLocation = maybe mempty toFlag elabHaddockHtmlLocation
, haddockForHackage = toFlag elabHaddockForHackage
, haddockForeignLibs = toFlag elabHaddockForeignLibs
, haddockExecutables = toFlag elabHaddockExecutables
, haddockTestSuites = toFlag elabHaddockTestSuites
, haddockBenchmarks = toFlag elabHaddockBenchmarks
, haddockInternal = toFlag elabHaddockInternal
, haddockCss = maybe mempty toFlag elabHaddockCss
, haddockLinkedSource = toFlag elabHaddockLinkedSource
, haddockQuickJump = toFlag elabHaddockQuickJump
, haddockHscolourCss = maybe mempty toFlag elabHaddockHscolourCss
, haddockContents = maybe mempty toFlag elabHaddockContents
, haddockKeepTempFiles = toFlag keepTmpFiles
, haddockIndex = maybe mempty toFlag elabHaddockIndex
, haddockBaseUrl = maybe mempty toFlag elabHaddockBaseUrl
, haddockLib = maybe mempty toFlag elabHaddockLib
, haddockOutputDir = maybe mempty toFlag elabHaddockOutputDir
}

setupHsHaddockArgs :: ElaboratedConfiguredPackage -> [String]
-- TODO: Does the issue #3335 affects test as well
Expand Down
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/HaddockKeepsTmps/Simple.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Simple where

-- | For hiding needles.
data Haystack = Haystack
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/HaddockKeepsTmps/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

haddock-keep-temp-files: true
20 changes: 20 additions & 0 deletions cabal-testsuite/PackageTests/HaddockKeepsTmps/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{-# LANGUAGE LambdaCase #-}
import Test.Cabal.Prelude
import Distribution.Verbosity
import Distribution.Simple.Glob
import Distribution.Simple.Glob.Internal

-- Test that "cabal haddock" preserves temporary files
-- We use haddock-keep-temp-file: True in the cabal.project.
main = cabalTest $ recordMode DoNotRecord $ do
skipIfWindows

cabal "haddock" []

cwd <- fmap testCurrentDir getTestEnv

(globMatches <$> liftIO (runDirFileGlob silent Nothing cwd (GlobDirRecursive [WildCard, Literal "response", WildCard, Literal "txt"]))) >>= \case
[] -> error "Expecting a response file to exist"
(m:_) ->
-- Assert the matched response file is not empty.
assertFileDoesContain (cwd </> m) "Simple.hs"
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/HaddockKeepsTmps/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: 3.0
name: HaddockKeepsTmps
version: 0.1
license: BSD-3-Clause
author: Rodrigo Mesquita
stability: stable
category: PackageTests
build-type: Simple

library
default-language: Haskell2010
exposed-modules: Simple
build-depends: base

0 comments on commit 214acd8

Please sign in to comment.