From f84087adad28084c64f6bbdba8c325e40167b959 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 27 Sep 2024 16:30:48 -0700 Subject: [PATCH] haddock-project: add CommonSetupFlags --- .../src/Distribution/Simple/Setup/Haddock.hs | 273 +++++++++--------- .../Distribution/Client/CmdHaddockProject.hs | 114 ++++---- .../src/Distribution/Client/Config.hs | 2 +- .../Client/ProjectConfig/Legacy.hs | 4 +- cabal-install/tests/IntegrationTests2.hs | 9 +- 5 files changed, 204 insertions(+), 198 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Setup/Haddock.hs b/Cabal/src/Distribution/Simple/Setup/Haddock.hs index aee2210d907..7e8df14cfa1 100644 --- a/Cabal/src/Distribution/Simple/Setup/Haddock.hs +++ b/Cabal/src/Distribution/Simple/Setup/Haddock.hs @@ -413,7 +413,8 @@ data Visibility = Visible | Hidden deriving (Eq, Show) data HaddockProjectFlags = HaddockProjectFlags - { haddockProjectHackage :: Flag Bool + { haddockProjectCommonFlags :: !CommonSetupFlags + , haddockProjectHackage :: Flag Bool -- ^ a shortcut option which builds documentation linked to hackage. It implies: -- * `--html-location='https://hackage.haskell.org/package/$prg-$version/docs' -- * `--quickjump` @@ -457,7 +458,8 @@ data HaddockProjectFlags = HaddockProjectFlags defaultHaddockProjectFlags :: HaddockProjectFlags defaultHaddockProjectFlags = HaddockProjectFlags - { haddockProjectHackage = Flag False + { haddockProjectCommonFlags = defaultCommonSetupFlags + , haddockProjectHackage = Flag False , haddockProjectDir = Flag "./haddocks" , haddockProjectPrologue = NoFlag , haddockProjectTestSuites = Flag False @@ -517,140 +519,141 @@ haddockProjectCommand = emptyProgramDb haddockProjectOptions :: ShowOrParseArgs -> [OptionField HaddockProjectFlags] -haddockProjectOptions _showOrParseArgs = - [ option - "" - ["hackage"] - ( concat - [ "A short-cut option to build documentation linked to hackage." - ] - ) - haddockProjectHackage - (\v flags -> flags{haddockProjectHackage = v}) - trueArg - , option - "" - ["output"] - "Output directory" - haddockProjectDir - (\v flags -> flags{haddockProjectDir = v}) - (optArg' "DIRECTORY" maybeToFlag (fmap Just . flagToList)) - , option - "" - ["prologue"] - "File path to a prologue file in haddock format" - haddockProjectPrologue - (\v flags -> flags{haddockProjectPrologue = v}) - (optArg' "PATH" maybeToFlag (fmap Just . flagToList)) - , option - "" - ["hoogle"] - "Generate a hoogle database" - haddockProjectHoogle - (\v flags -> flags{haddockProjectHoogle = v}) - trueArg - , option - "" - ["html-location"] - "Location of HTML documentation for pre-requisite packages" - haddockProjectHtmlLocation - (\v flags -> flags{haddockProjectHtmlLocation = v}) - (reqArgFlag "URL") - , option - "" - ["executables"] - "Run haddock for Executables targets" - haddockProjectExecutables - (\v flags -> flags{haddockProjectExecutables = v}) - trueArg - , option - "" - ["tests"] - "Run haddock for Test Suite targets" - haddockProjectTestSuites - (\v flags -> flags{haddockProjectTestSuites = v}) - trueArg - , option - "" - ["benchmarks"] - "Run haddock for Benchmark targets" - haddockProjectBenchmarks - (\v flags -> flags{haddockProjectBenchmarks = v}) - trueArg - , option - "" - ["foreign-libraries"] - "Run haddock for Foreign Library targets" - haddockProjectForeignLibs - (\v flags -> flags{haddockProjectForeignLibs = v}) - trueArg - , option - "" - ["all", "haddock-all"] - "Run haddock for all targets" - ( \f -> - allFlags - [ haddockProjectExecutables f - , haddockProjectTestSuites f - , haddockProjectBenchmarks f - , haddockProjectForeignLibs f +haddockProjectOptions showOrParseArgs = + withCommonSetupOptions + haddockProjectCommonFlags + (\c f -> f{haddockProjectCommonFlags = c}) + showOrParseArgs + [ option + "" + ["hackage"] + ( concat + [ "A short-cut option to build documentation linked to hackage." ] - ) - ( \v flags -> - flags - { haddockProjectExecutables = v - , haddockProjectTestSuites = v - , haddockProjectBenchmarks = v - , haddockProjectForeignLibs = v - } - ) - trueArg - , option - "" - ["internal"] - "Run haddock for internal modules and include all symbols" - haddockProjectInternal - (\v flags -> flags{haddockProjectInternal = v}) - trueArg - , option - "" - ["css"] - "Use PATH as the haddock stylesheet" - haddockProjectCss - (\v flags -> flags{haddockProjectCss = v}) - (reqArgFlag "PATH") - , option - "" - ["hscolour-css"] - "Use PATH as the HsColour stylesheet" - haddockProjectHscolourCss - (\v flags -> flags{haddockProjectHscolourCss = v}) - (reqArgFlag "PATH") - , option - "" - ["keep-temp-files"] - "Keep temporary files" - haddockProjectKeepTempFiles - (\b flags -> flags{haddockProjectKeepTempFiles = b}) - trueArg - , optionVerbosity - haddockProjectVerbosity - (\v flags -> flags{haddockProjectVerbosity = v}) - , option - "" - ["resources-dir"] - "location of Haddocks static / auxiliary files" - haddockProjectResourcesDir - (\v flags -> flags{haddockProjectResourcesDir = v}) - (reqArgFlag "DIR") - , option - "" - ["use-unicode"] - "Pass --use-unicode option to haddock" - haddockProjectUseUnicode - (\v flags -> flags{haddockProjectUseUnicode = v}) - trueArg - ] + ) + haddockProjectHackage + (\v flags -> flags{haddockProjectHackage = v}) + trueArg + , option + "" + ["output"] + "Output directory" + haddockProjectDir + (\v flags -> flags{haddockProjectDir = v}) + (optArg' "DIRECTORY" maybeToFlag (fmap Just . flagToList)) + , option + "" + ["prologue"] + "File path to a prologue file in haddock format" + haddockProjectPrologue + (\v flags -> flags{haddockProjectPrologue = v}) + (optArg' "PATH" maybeToFlag (fmap Just . flagToList)) + , option + "" + ["hoogle"] + "Generate a hoogle database" + haddockProjectHoogle + (\v flags -> flags{haddockProjectHoogle = v}) + trueArg + , option + "" + ["html-location"] + "Location of HTML documentation for pre-requisite packages" + haddockProjectHtmlLocation + (\v flags -> flags{haddockProjectHtmlLocation = v}) + (reqArgFlag "URL") + , option + "" + ["executables"] + "Run haddock for Executables targets" + haddockProjectExecutables + (\v flags -> flags{haddockProjectExecutables = v}) + trueArg + , option + "" + ["tests"] + "Run haddock for Test Suite targets" + haddockProjectTestSuites + (\v flags -> flags{haddockProjectTestSuites = v}) + trueArg + , option + "" + ["benchmarks"] + "Run haddock for Benchmark targets" + haddockProjectBenchmarks + (\v flags -> flags{haddockProjectBenchmarks = v}) + trueArg + , option + "" + ["foreign-libraries"] + "Run haddock for Foreign Library targets" + haddockProjectForeignLibs + (\v flags -> flags{haddockProjectForeignLibs = v}) + trueArg + , option + "" + ["all", "haddock-all"] + "Run haddock for all targets" + ( \f -> + allFlags + [ haddockProjectExecutables f + , haddockProjectTestSuites f + , haddockProjectBenchmarks f + , haddockProjectForeignLibs f + ] + ) + ( \v flags -> + flags + { haddockProjectExecutables = v + , haddockProjectTestSuites = v + , haddockProjectBenchmarks = v + , haddockProjectForeignLibs = v + } + ) + trueArg + , option + "" + ["internal"] + "Run haddock for internal modules and include all symbols" + haddockProjectInternal + (\v flags -> flags{haddockProjectInternal = v}) + trueArg + , option + "" + ["css"] + "Use PATH as the haddock stylesheet" + haddockProjectCss + (\v flags -> flags{haddockProjectCss = v}) + (reqArgFlag "PATH") + , option + "" + ["hscolour-css"] + "Use PATH as the HsColour stylesheet" + haddockProjectHscolourCss + (\v flags -> flags{haddockProjectHscolourCss = v}) + (reqArgFlag "PATH") + , option + "" + ["keep-temp-files"] + "Keep temporary files" + haddockProjectKeepTempFiles + (\b flags -> flags{haddockProjectKeepTempFiles = b}) + trueArg + , option + "" + ["resources-dir"] + "location of Haddocks static / auxiliary files" + haddockProjectResourcesDir + (\v flags -> flags{haddockProjectResourcesDir = v}) + (reqArgFlag "DIR") + , option + "" + ["use-unicode"] + "Pass --use-unicode option to haddock" + haddockProjectUseUnicode + (\v flags -> flags{haddockProjectUseUnicode = v}) + trueArg + ] emptyHaddockProjectFlags :: HaddockProjectFlags emptyHaddockProjectFlags = mempty diff --git a/cabal-install/src/Distribution/Client/CmdHaddockProject.hs b/cabal-install/src/Distribution/Client/CmdHaddockProject.hs index f632e8b7caa..ca8330b3b8d 100644 --- a/cabal-install/src/Distribution/Client/CmdHaddockProject.hs +++ b/cabal-install/src/Distribution/Client/CmdHaddockProject.hs @@ -85,7 +85,6 @@ import Distribution.Simple.Setup , HaddockProjectFlags (..) , HaddockTarget (..) , Visibility (..) - , defaultCommonSetupFlags , defaultHaddockFlags , haddockProjectCommand ) @@ -119,62 +118,6 @@ haddockProjectAction flags _extraArgs globalFlags = do warn verbosity "haddock-project command is experimental, it might break in the future" - -- build all packages with appropriate haddock flags - let commonFlags = - defaultCommonSetupFlags - { setupVerbosity = haddockProjectVerbosity flags - } - haddockFlags = - defaultHaddockFlags - { haddockCommonFlags = commonFlags - , haddockHtml = Flag True - , -- one can either use `--haddock-base-url` or - -- `--haddock-html-location`. - haddockBaseUrl = - if localStyle - then Flag ".." - else NoFlag - , haddockProgramPaths = haddockProjectProgramPaths flags - , haddockProgramArgs = haddockProjectProgramArgs flags - , haddockHtmlLocation = - if fromFlagOrDefault False (haddockProjectHackage flags) - then Flag "https://hackage.haskell.org/package/$pkg-$version/docs" - else haddockProjectHtmlLocation flags - , haddockHoogle = haddockProjectHoogle flags - , haddockExecutables = haddockProjectExecutables flags - , haddockTestSuites = haddockProjectTestSuites flags - , haddockBenchmarks = haddockProjectBenchmarks flags - , haddockForeignLibs = haddockProjectForeignLibs flags - , haddockInternal = haddockProjectInternal flags - , haddockCss = haddockProjectCss flags - , haddockLinkedSource = Flag True - , haddockQuickJump = Flag True - , haddockHscolourCss = haddockProjectHscolourCss flags - , haddockContents = - if localStyle - then Flag (toPathTemplate "../index.html") - else NoFlag - , haddockIndex = - if localStyle - then Flag (toPathTemplate "../doc-index.html") - else NoFlag - , haddockKeepTempFiles = haddockProjectKeepTempFiles flags - , haddockResourcesDir = haddockProjectResourcesDir flags - , haddockUseUnicode = haddockProjectUseUnicode flags - -- NOTE: we don't pass `haddockOutputDir`. If we do, we'll need to - -- make sure `InstalledPackageInfo` contains the right path to - -- haddock interfaces. Instead we build documentation inside - -- `dist-newstyle` directory and copy it to the output directory. - } - nixFlags = - (commandDefaultFlags CmdHaddock.haddockCommand) - { NixStyleOptions.haddockFlags = haddockFlags - , NixStyleOptions.configFlags = - (NixStyleOptions.configFlags (commandDefaultFlags CmdBuild.buildCommand)) - { configCommonFlags = commonFlags - } - } - -- -- Construct the build plan and infer the list of packages which haddocks -- we need. @@ -409,7 +352,62 @@ haddockProjectAction flags _extraArgs globalFlags = do Nothing flags' where - verbosity = fromFlagOrDefault normal (haddockProjectVerbosity flags) + -- build all packages with appropriate haddock flags + commonFlags = haddockProjectCommonFlags flags + + verbosity = fromFlagOrDefault normal (setupVerbosity commonFlags) + + haddockFlags = + defaultHaddockFlags + { haddockCommonFlags = commonFlags + , haddockHtml = Flag True + , -- one can either use `--haddock-base-url` or + -- `--haddock-html-location`. + haddockBaseUrl = + if localStyle + then Flag ".." + else NoFlag + , haddockProgramPaths = haddockProjectProgramPaths flags + , haddockProgramArgs = haddockProjectProgramArgs flags + , haddockHtmlLocation = + if fromFlagOrDefault False (haddockProjectHackage flags) + then Flag "https://hackage.haskell.org/package/$pkg-$version/docs" + else haddockProjectHtmlLocation flags + , haddockHoogle = haddockProjectHoogle flags + , haddockExecutables = haddockProjectExecutables flags + , haddockTestSuites = haddockProjectTestSuites flags + , haddockBenchmarks = haddockProjectBenchmarks flags + , haddockForeignLibs = haddockProjectForeignLibs flags + , haddockInternal = haddockProjectInternal flags + , haddockCss = haddockProjectCss flags + , haddockLinkedSource = Flag True + , haddockQuickJump = Flag True + , haddockHscolourCss = haddockProjectHscolourCss flags + , haddockContents = + if localStyle + then Flag (toPathTemplate "../index.html") + else NoFlag + , haddockIndex = + if localStyle + then Flag (toPathTemplate "../doc-index.html") + else NoFlag + , haddockKeepTempFiles = haddockProjectKeepTempFiles flags + , haddockResourcesDir = haddockProjectResourcesDir flags + , haddockUseUnicode = haddockProjectUseUnicode flags + -- NOTE: we don't pass `haddockOutputDir`. If we do, we'll need to + -- make sure `InstalledPackageInfo` contains the right path to + -- haddock interfaces. Instead we build documentation inside + -- `dist-newstyle` directory and copy it to the output directory. + } + + nixFlags = + (commandDefaultFlags CmdHaddock.haddockCommand) + { NixStyleOptions.haddockFlags = haddockFlags + , NixStyleOptions.configFlags = + (NixStyleOptions.configFlags (commandDefaultFlags CmdBuild.buildCommand)) + { configCommonFlags = commonFlags + } + } -- Build a self contained directory which contains haddocks of all -- transitive dependencies; or depend on `--haddocks-html-location` to diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index f7b01512ca4..c837db7bb08 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -1844,7 +1844,7 @@ haddockFlagsFields = , name `notElem` exclusions ] where - exclusions = ["verbose", "builddir", "for-hackage"] + exclusions = ["verbose", "builddir", "cabal-file", "for-hackage"] -- | Fields for the 'init' section. initFlagsFields :: [FieldDescr IT.InitFlags] diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs index a4191325f8b..7ed13df1232 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs @@ -862,8 +862,8 @@ convertLegacyBuildOnlyFlags installFlags clientInstallFlags haddockFlags - _ - _ = + _testFlags + _benchmarkFlags = ProjectConfigBuildOnly{..} where projectConfigClientInstallFlags = clientInstallFlags diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index 22c7da0c37f..113b025e280 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -49,7 +49,7 @@ import qualified Distribution.Client.CmdListBin as CmdListBin import Distribution.Package import Distribution.PackageDescription import Distribution.InstalledPackageInfo (InstalledPackageInfo) -import Distribution.Simple.Setup (toFlag, HaddockFlags(..), defaultHaddockFlags) +import Distribution.Simple.Setup (toFlag, CommonSetupFlags(..), HaddockFlags(..), defaultHaddockFlags, defaultCommonSetupFlags) import Distribution.Client.Setup (globalCommand) import Distribution.Client.Config (loadConfig, SavedConfig(savedGlobalFlags), createDefaultConfigFile) import Distribution.Simple.Compiler @@ -2289,7 +2289,12 @@ testHaddockProjectDependencies config = do cleanHaddockProject testdir withCurrentDirectory dir $ do CmdHaddockProject.haddockProjectAction - defaultHaddockProjectFlags { haddockProjectVerbosity = Flag verbosity } + defaultHaddockProjectFlags + { haddockProjectCommonFlags = + defaultCommonSetupFlags + { setupVerbosity = Flag verbosity + } + } ["all"] defaultGlobalFlags { globalStoreDir = Flag "store" }