Skip to content

Commit

Permalink
Add cfgVerbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Dec 29, 2024
1 parent d735bdc commit 7dc0a25
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 86 deletions.
14 changes: 4 additions & 10 deletions cabal-install/src/Distribution/Client/CmdBench.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE RecordWildCards #-}

-- | cabal-install CLI command: bench
module Distribution.Client.CmdBench
( -- * The @bench@ CLI and action
Expand Down Expand Up @@ -29,13 +27,13 @@ import Distribution.Client.CmdErrorMessages
import Distribution.Client.Errors
import Distribution.Client.NixStyleOptions
( NixStyleFlags (..)
, cfgVerbosity
, defaultNixStyleFlags
, nixStyleOptions
)
import Distribution.Client.ProjectOrchestration
import Distribution.Client.Setup
( ConfigFlags (..)
, GlobalFlags
( GlobalFlags
)
import Distribution.Client.TargetProblem
( TargetProblem (..)
Expand All @@ -47,10 +45,6 @@ import Distribution.Simple.Command
( CommandUI (..)
, usageAlternatives
)
import Distribution.Simple.Flag
( fromFlagOrDefault
)
import Distribution.Simple.Setup (CommonSetupFlags (..))
import Distribution.Simple.Utils
( dieWithException
, warn
Expand Down Expand Up @@ -111,7 +105,7 @@ benchCommand =
-- For more details on how this works, see the module
-- "Distribution.Client.ProjectOrchestration"
benchAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO ()
benchAction flags@NixStyleFlags{..} targetStrings globalFlags = do
benchAction flags targetStrings globalFlags = do
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand

targetSelectors <-
Expand Down Expand Up @@ -151,7 +145,7 @@ benchAction flags@NixStyleFlags{..} targetStrings globalFlags = do
buildOutcomes <- runProjectBuildPhase verbosity baseCtx buildCtx
runProjectPostBuildPhase verbosity baseCtx buildCtx buildOutcomes
where
verbosity = fromFlagOrDefault normal (setupVerbosity $ configCommonFlags configFlags)
verbosity = cfgVerbosity normal flags
cliConfig =
commandLineFlagsToProjectConfig
globalFlags
Expand Down
13 changes: 5 additions & 8 deletions cabal-install/src/Distribution/Client/CmdBuild.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE RecordWildCards #-}

-- | cabal-install CLI command: build
module Distribution.Client.CmdBuild
( -- * The @build@ CLI and action
Expand Down Expand Up @@ -30,6 +28,7 @@ import qualified Data.Map as Map
import Distribution.Client.Errors
import Distribution.Client.NixStyleOptions
( NixStyleFlags (..)
, cfgVerbosity
, defaultNixStyleFlags
, nixStyleOptions
)
Expand All @@ -40,17 +39,15 @@ import Distribution.Client.ScriptUtils
, withContextAndSelectors
)
import Distribution.Client.Setup
( CommonSetupFlags (..)
, ConfigFlags (..)
, GlobalFlags
( GlobalFlags
, yesNoOpt
)
import Distribution.Simple.Command
( CommandUI (..)
, option
, usageAlternatives
)
import Distribution.Simple.Flag (Flag (..), fromFlag, fromFlagOrDefault, toFlag)
import Distribution.Simple.Flag (Flag (..), fromFlag, toFlag)
import Distribution.Simple.Utils
( dieWithException
, wrapText
Expand Down Expand Up @@ -134,7 +131,7 @@ defaultBuildFlags =
-- For more details on how this works, see the module
-- "Distribution.Client.ProjectOrchestration"
buildAction :: NixStyleFlags BuildFlags -> [String] -> GlobalFlags -> IO ()
buildAction flags@NixStyleFlags{extraFlags = buildFlags, ..} targetStrings globalFlags =
buildAction flags@NixStyleFlags{extraFlags = buildFlags} targetStrings globalFlags =
withContextAndSelectors verbosity RejectNoTargets Nothing flags targetStrings globalFlags BuildCommand $ \targetCtx ctx targetSelectors -> do
-- TODO: This flags defaults business is ugly
let onlyConfigure =
Expand Down Expand Up @@ -185,7 +182,7 @@ buildAction flags@NixStyleFlags{extraFlags = buildFlags, ..} targetStrings globa
buildOutcomes <- runProjectBuildPhase verbosity baseCtx buildCtx
runProjectPostBuildPhase verbosity baseCtx buildCtx buildOutcomes
where
verbosity = fromFlagOrDefault normal (setupVerbosity $ configCommonFlags configFlags)
verbosity = cfgVerbosity normal flags

-- | This defines what a 'TargetSelector' means for the @bench@ command.
-- It selects the 'AvailableTarget's that the 'TargetSelector' refers to,
Expand Down
9 changes: 4 additions & 5 deletions cabal-install/src/Distribution/Client/CmdConfigure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ import Distribution.Client.ProjectFlags
)
import Distribution.Client.ProjectOrchestration
import Distribution.Simple.Flag
import Distribution.Simple.Setup (CommonSetupFlags (..))

import Distribution.Client.NixStyleOptions
( NixStyleFlags (..)
, cfgVerbosity
, defaultNixStyleFlags
, nixStyleOptions
)
import Distribution.Client.Setup
( ConfigExFlags (..)
, ConfigFlags (..)
, GlobalFlags
)
import Distribution.Verbosity
Expand Down Expand Up @@ -117,14 +116,14 @@ configureCommand =
-- For more details on how this works, see the module
-- "Distribution.Client.ProjectOrchestration"
configureAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO ()
configureAction flags@NixStyleFlags{..} extraArgs globalFlags = do
configureAction flags extraArgs globalFlags = do
(baseCtx, projConfig) <- configureAction' flags extraArgs globalFlags

if shouldNotWriteFile baseCtx
then notice v "Config file not written due to flag(s)."
else writeProjectLocalExtraConfig (distDirLayout baseCtx) projConfig
where
v = fromFlagOrDefault normal (setupVerbosity $ configCommonFlags configFlags)
v = cfgVerbosity normal flags

configureAction' :: NixStyleFlags () -> [String] -> GlobalFlags -> IO (ProjectBaseContext, ProjectConfig)
configureAction' flags@NixStyleFlags{..} _extraArgs globalFlags = do
Expand Down Expand Up @@ -165,7 +164,7 @@ configureAction' flags@NixStyleFlags{..} _extraArgs globalFlags = do
return (baseCtx, conf <> cliConfig)
else return (baseCtx, cliConfig)
where
v = fromFlagOrDefault normal (setupVerbosity $ configCommonFlags configFlags)
v = cfgVerbosity normal flags
cliConfig =
commandLineFlagsToProjectConfig
globalFlags
Expand Down
12 changes: 4 additions & 8 deletions cabal-install/src/Distribution/Client/CmdExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Distribution.Client.InstallPlan
)
import Distribution.Client.NixStyleOptions
( NixStyleFlags (..)
, cfgVerbosity
, defaultNixStyleFlags
, nixStyleOptions
)
Expand Down Expand Up @@ -58,15 +59,11 @@ import Distribution.Client.ProjectPlanning.Types
( dataDirsEnvironmentForPlan
)
import Distribution.Client.Setup
( ConfigFlags (configCommonFlags)
, GlobalFlags
( GlobalFlags
)
import Distribution.Simple.Command
( CommandUI (..)
)
import Distribution.Simple.Flag
( fromFlagOrDefault
)
import Distribution.Simple.GHC
( GhcImplInfo (supportsPkgEnvFiles)
, getImplInfo
Expand All @@ -87,7 +84,6 @@ import Distribution.Simple.Program.Run
( programInvocation
, runProgramInvocation
)
import Distribution.Simple.Setup (CommonSetupFlags (..))
import Distribution.Simple.Utils
( createDirectoryIfMissingVerbose
, dieWithException
Expand Down Expand Up @@ -144,7 +140,7 @@ execCommand =
}

execAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO ()
execAction flags@NixStyleFlags{..} extraArgs globalFlags = do
execAction flags extraArgs globalFlags = do
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand

-- To set up the environment, we'd like to select the libraries in our
Expand Down Expand Up @@ -226,7 +222,7 @@ execAction flags@NixStyleFlags{..} extraArgs globalFlags = do
then notice verbosity "Running of executable suppressed by flag(s)"
else runProgramInvocation verbosity invocation
where
verbosity = fromFlagOrDefault normal (setupVerbosity $ configCommonFlags configFlags)
verbosity = cfgVerbosity normal flags
cliConfig =
commandLineFlagsToProjectConfig
globalFlags
Expand Down
12 changes: 5 additions & 7 deletions cabal-install/src/Distribution/Client/CmdFreeze.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}

-- | cabal-install CLI command: freeze
module Distribution.Client.CmdFreeze
Expand All @@ -17,6 +16,7 @@ import Distribution.Client.IndexUtils (ActiveRepos, TotalIndexState, filterSkipp
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.NixStyleOptions
( NixStyleFlags (..)
, cfgVerbosity
, defaultNixStyleFlags
, nixStyleOptions
)
Expand All @@ -40,9 +40,7 @@ import Distribution.Solver.Types.PackageConstraint
)

import Distribution.Client.Setup
( CommonSetupFlags (setupVerbosity)
, ConfigFlags (..)
, GlobalFlags
( GlobalFlags
)
import Distribution.Package
( PackageName
Expand All @@ -53,7 +51,7 @@ import Distribution.PackageDescription
( FlagAssignment
, nullFlagAssignment
)
import Distribution.Simple.Flag (Flag (..), fromFlagOrDefault)
import Distribution.Simple.Flag (Flag (..))
import Distribution.Simple.Utils
( dieWithException
, notice
Expand Down Expand Up @@ -125,7 +123,7 @@ freezeCommand =
-- For more details on how this works, see the module
-- "Distribution.Client.ProjectOrchestration"
freezeAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO ()
freezeAction flags@NixStyleFlags{..} extraArgs globalFlags = do
freezeAction flags extraArgs globalFlags = do
unless (null extraArgs) $
dieWithException verbosity $
FreezeAction extraArgs
Expand Down Expand Up @@ -160,7 +158,7 @@ freezeAction flags@NixStyleFlags{..} extraArgs globalFlags = do
notice verbosity $
"Wrote freeze file: " ++ (distProjectFile distDirLayout "freeze")
where
verbosity = fromFlagOrDefault normal (setupVerbosity $ configCommonFlags configFlags)
verbosity = cfgVerbosity normal flags
cliConfig =
commandLineFlagsToProjectConfig
globalFlags
Expand Down
7 changes: 3 additions & 4 deletions cabal-install/src/Distribution/Client/CmdHaddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Prelude ()
import Distribution.Client.CmdErrorMessages
import Distribution.Client.NixStyleOptions
( NixStyleFlags (..)
, cfgVerbosity
, defaultNixStyleFlags
, nixStyleOptions
)
Expand All @@ -31,9 +32,7 @@ import Distribution.Client.ProjectPlanning
( ElaboratedSharedConfig (..)
)
import Distribution.Client.Setup
( CommonSetupFlags (..)
, ConfigFlags (..)
, GlobalFlags
( GlobalFlags
, InstallFlags (..)
)
import Distribution.Client.TargetProblem
Expand Down Expand Up @@ -149,7 +148,7 @@ haddockAction relFlags targetStrings globalFlags = do
flags@NixStyleFlags{..} <- mkFlagsAbsolute relFlags

let
verbosity = fromFlagOrDefault normal (setupVerbosity $ configCommonFlags configFlags)
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
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import Distribution.Client.InstallSymlink
)
import Distribution.Client.NixStyleOptions
( NixStyleFlags (..)
, cfgVerbosity
, defaultNixStyleFlags
, nixStyleOptions
)
Expand Down Expand Up @@ -97,8 +98,7 @@ import Distribution.Client.RebuildMonad
( runRebuild
)
import Distribution.Client.Setup
( CommonSetupFlags (..)
, ConfigFlags (..)
( ConfigFlags (..)
, GlobalFlags (..)
, InstallFlags (..)
)
Expand Down Expand Up @@ -543,7 +543,7 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project
traverseInstall (installCheckUnitExes InstallCheckInstall) installCfg
where
configFlags' = disableTestsBenchsByDefault . ignoreProgramAffixes $ configFlags
verbosity = fromFlagOrDefault normal (setupVerbosity $ configCommonFlags configFlags')
verbosity = cfgVerbosity normal flags
ignoreProject = flagIgnoreProject projectFlags
cliConfig =
commandLineFlagsToProjectConfig
Expand Down
14 changes: 7 additions & 7 deletions cabal-install/src/Distribution/Client/CmdListBin.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Distribution.Client.CmdListBin
( listbinCommand
Expand Down Expand Up @@ -30,10 +29,12 @@ import Distribution.Client.CmdErrorMessages
import Distribution.Client.DistDirLayout (DistDirLayout (..))
import Distribution.Client.NixStyleOptions
( NixStyleFlags (..)
, cfgVerbosity
, defaultNixStyleFlags
, nixStyleOptions
)
import Distribution.Client.ProjectOrchestration
import Distribution.Client.ProjectOrchestration hiding (distDirLayout, targetsMap)
import qualified Distribution.Client.ProjectOrchestration as Orchestration (distDirLayout, targetsMap)
import Distribution.Client.ProjectPlanning.Types
import Distribution.Client.ScriptUtils
( AcceptNoTargets (..)
Expand All @@ -46,7 +47,6 @@ import Distribution.Client.Setup (GlobalFlags (..))
import Distribution.Client.TargetProblem (TargetProblem (..))
import Distribution.Simple.BuildPaths (dllExtension, exeExtension)
import Distribution.Simple.Command (CommandUI (..))
import Distribution.Simple.Setup (configCommonFlags, fromFlagOrDefault, setupVerbosity)
import Distribution.Simple.Utils (dieWithException, withOutputMarker, wrapText)
import Distribution.System (Platform)
import Distribution.Types.ComponentName (showComponentName)
Expand Down Expand Up @@ -86,7 +86,7 @@ listbinCommand =
-------------------------------------------------------------------------------

listbinAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO ()
listbinAction flags@NixStyleFlags{..} args globalFlags = do
listbinAction flags args globalFlags = do
-- fail early if multiple target selectors specified
target <- case args of
[] -> dieWithException verbosity NoTargetProvided
Expand Down Expand Up @@ -140,7 +140,7 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
singleComponentOrElse
( dieWithException verbosity ThisIsABug
)
$ targetsMap buildCtx
$ Orchestration.targetsMap buildCtx

printPlan verbosity baseCtx buildCtx

Expand All @@ -150,7 +150,7 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
return $
IP.foldPlanPackage
(const []) -- IPI don't have executables
(elaboratedPackage (distDirLayout baseCtx) (elaboratedShared buildCtx) selectedComponent)
(elaboratedPackage (Orchestration.distDirLayout baseCtx) (elaboratedShared buildCtx) selectedComponent)
gpp

case binfiles of
Expand All @@ -170,7 +170,7 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
_ -> dieWithException verbosity MultipleTargetsFound
where
defaultVerbosity = verboseStderr silent
verbosity = fromFlagOrDefault defaultVerbosity (setupVerbosity $ configCommonFlags configFlags)
verbosity = cfgVerbosity defaultVerbosity flags

-- this is copied from
elaboratedPackage
Expand Down
Loading

0 comments on commit 7dc0a25

Please sign in to comment.