Skip to content

cabal haddock: imply dependencies, but gentler, i.e. don't override config/project settings #11002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ library
Distribution.Client.Types
Distribution.Client.Types.AllowNewer
Distribution.Client.Types.BuildResults
Distribution.Client.Types.CurrentCommand
Distribution.Client.Types.ConfiguredId
Distribution.Client.Types.ConfiguredPackage
Distribution.Client.Types.Credentials
Expand Down
5 changes: 1 addition & 4 deletions cabal-install/src/Distribution/Client/CmdHaddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Distribution.Client.ProjectPlanning
)
import Distribution.Client.Setup
( GlobalFlags
, InstallFlags (..)
)
import Distribution.Client.TargetProblem
( TargetProblem (..)
Expand Down Expand Up @@ -150,9 +149,7 @@ haddockAction relFlags targetStrings globalFlags = do

let
verbosity = cfgVerbosity normal flags
installDoc = fromFlagOrDefault True (installDocumentation installFlags)
flags' = flags{installFlags = installFlags{installDocumentation = Flag installDoc}}
cliConfig = commandLineFlagsToProjectConfig globalFlags flags' mempty -- ClientInstallFlags, not needed here
cliConfig = commandLineFlagsToProjectConfig globalFlags flags mempty -- ClientInstallFlags, not needed here
projCtx <- establishProjectBaseContext verbosity cliConfig HaddockCommand

let relBaseCtx@ProjectBaseContext{projectConfig = relProjectConfig}
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ regenerateHaddockIndex
| otherwise = return ()
where
haddockIndexFileIsRequested =
fromFlag (installDocumentation installFlags)
fromFlagOrDefault False (installDocumentation installFlags)
&& isJust (flagToMaybe (installHaddockIndex installFlags))

-- We want to regenerate the index if some new documentation was actually
Expand Down Expand Up @@ -1889,7 +1889,7 @@ installUnpackedPackage

buildFlags vers =
emptyBuildFlags{buildCommonFlags = commonFlags vers}
shouldHaddock = fromFlag (installDocumentation installFlags)
shouldHaddock = fromFlagOrDefault False (installDocumentation installFlags)
haddockFlags' vers =
haddockFlags{haddockCommonFlags = commonFlags vers}
testsEnabled =
Expand Down
9 changes: 3 additions & 6 deletions cabal-install/src/Distribution/Client/ProjectOrchestration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ import Distribution.Client.TargetSelector
, reportTargetSelectorProblems
)
import Distribution.Client.Types
( DocsResult (..)
( CurrentCommand (..)
, DocsResult (..)
, GenericReadyPackage (..)
, PackageLocation (..)
, PackageSpecifier (..)
Expand Down Expand Up @@ -230,11 +231,6 @@ import System.Posix.Signals (sigKILL, sigSEGV)

#endif

-- | Tracks what command is being executed, because we need to hide this somewhere
-- for cases that need special handling (usually for error reporting).
data CurrentCommand = InstallCommand | HaddockCommand | BuildCommand | ReplCommand | OtherCommand
deriving (Show, Eq)

-- | This holds the context of a project prior to solving: the content of the
-- @cabal.project@, @cabal/config@ and all the local package @.cabal@ files.
data ProjectBaseContext = ProjectBaseContext
Expand Down Expand Up @@ -286,6 +282,7 @@ establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentComma
httpTransport
distDirLayout
cliConfig
currentCommand

let ProjectConfigBuildOnly
{ projectConfigLogsDir
Expand Down
15 changes: 13 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ rebuildProjectConfig
-> HttpTransport
-> DistDirLayout
-> ProjectConfig
-> CurrentCommand
-> IO
( ProjectConfig
, [PackageSpecifier UnresolvedSourcePackage]
Expand All @@ -368,7 +369,8 @@ rebuildProjectConfig
, distProjectCacheDirectory
, distProjectFile
}
cliConfig = do
cliConfig
currentCommand = do
progsearchpath <- liftIO $ getSystemSearchPath

let fileMonitorProjectConfig = newFileMonitor (distProjectCacheFile "config")
Expand Down Expand Up @@ -415,14 +417,23 @@ rebuildProjectConfig
notice (verboseStderr verbosity) . render . vcat $
text "Configuration is affected by the following files:" : configfiles

return (projectConfig <> cliConfig, localPackages)
return (commandDefaults currentCommand <> projectConfig <> cliConfig, localPackages)
where
ProjectConfigShared{projectConfigHcFlavor, projectConfigHcPath, projectConfigHcPkg, projectConfigIgnoreProject, projectConfigConfigFile} =
projectConfigShared cliConfig

PackageConfig{packageConfigProgramPaths, packageConfigProgramPathExtra} =
projectConfigLocalPackages cliConfig

-- Some commands may require special defaults
commandDefaults HaddockCommand =
-- `cabal haddock` emplies --enable-documentation, #7462
mempty
{ projectConfigAllPackages = mempty{packageConfigDocumentation = pure True}
, projectConfigLocalPackages = mempty{packageConfigDocumentation = pure True}
}
commandDefaults _ = mempty

-- Read the cabal.project (or implicit config) and combine it with
-- arguments from the command line
--
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,7 @@ instance Binary InstallFlags
defaultInstallFlags :: InstallFlags
defaultInstallFlags =
InstallFlags
{ installDocumentation = Flag False
{ installDocumentation = mempty
, installHaddockIndex = Flag docIndexFile
, installDest = Flag Cabal.NoCopyDest
, installDryRun = Flag False
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
-- Various common data types for the entire cabal-install system
module Distribution.Client.Types
( module Distribution.Client.Types.AllowNewer
, module Distribution.Client.Types.CurrentCommand
, module Distribution.Client.Types.ConfiguredId
, module Distribution.Client.Types.ConfiguredPackage
, module Distribution.Client.Types.BuildResults
Expand All @@ -33,6 +34,7 @@ import Distribution.Client.Types.AllowNewer
import Distribution.Client.Types.BuildResults
import Distribution.Client.Types.ConfiguredId
import Distribution.Client.Types.ConfiguredPackage
import Distribution.Client.Types.CurrentCommand
import Distribution.Client.Types.PackageLocation
import Distribution.Client.Types.PackageSpecifier
import Distribution.Client.Types.ReadyPackage
Expand Down
6 changes: 6 additions & 0 deletions cabal-install/src/Distribution/Client/Types/CurrentCommand.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Distribution.Client.Types.CurrentCommand where

-- | Tracks what command is being executed, because we need to hide this somewhere
-- for cases that need special handling (usually for error reporting).
data CurrentCommand = InstallCommand | HaddockCommand | BuildCommand | ReplCommand | OtherCommand
deriving (Show, Eq)
4 changes: 3 additions & 1 deletion cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import Distribution.Client.Targets
, UserConstraintScope (UserAnyQualifier)
)
import Distribution.Client.Types
( PackageLocation (..)
( CurrentCommand (..)
, PackageLocation (..)
, PackageSpecifier (..)
, UnresolvedSourcePackage
)
Expand Down Expand Up @@ -2186,6 +2187,7 @@ configureProject testdir cliConfig = do
httpTransport
distDirLayout
cliConfig
OtherCommand

let buildSettings =
resolveBuildTimeSettings
Expand Down
Loading