Commit 3db6e93e authored by Robert Henderson's avatar Robert Henderson
Browse files

Code cleanup: removed duplicated versions of 'showFlagValue'.

parent 98e84342
......@@ -93,6 +93,7 @@ module Distribution.PackageDescription (
Flag(..), emptyFlag,
FlagName, mkFlagName, unFlagName,
FlagAssignment,
showFlagValue,
dispFlagAssignment, parseFlagAssignment,
CondTree(..), ConfVar(..), Condition(..),
cNot, cAnd, cOr,
......
......@@ -12,6 +12,7 @@ module Distribution.Types.GenericPackageDescription (
mkFlagName,
unFlagName,
FlagAssignment,
showFlagValue,
dispFlagAssignment,
parseFlagAssignment,
ConfVar(..),
......@@ -123,13 +124,14 @@ instance Binary FlagName
--
type FlagAssignment = [(FlagName, Bool)]
-- | String representation of a flag-value pair.
showFlagValue :: (FlagName, Bool) -> String
showFlagValue (f, True) = '+' : unFlagName f
showFlagValue (f, False) = '-' : unFlagName f
-- | Pretty-prints a flag assignment.
dispFlagAssignment :: FlagAssignment -> Disp.Doc
dispFlagAssignment = Disp.hsep . map dispFlagValue
where
dispFlagValue (f, True) = Disp.char '+' <<>> dispFlagName f
dispFlagValue (f, False) = Disp.char '-' <<>> dispFlagName f
dispFlagName = Disp.text . unFlagName
dispFlagAssignment = Disp.hsep . map (Disp.text . showFlagValue)
-- | Parses a flag assignment.
parseFlagAssignment :: Parse.ReadP r FlagAssignment
......
......@@ -150,7 +150,7 @@ import Distribution.Types.Dependency
import qualified Distribution.PackageDescription as PackageDescription
import Distribution.PackageDescription
( PackageDescription, GenericPackageDescription(..), Flag(..)
, unFlagName, FlagAssignment )
, FlagAssignment, showFlagValue )
import Distribution.PackageDescription.Configuration
( finalizePD )
import Distribution.ParseUtils
......@@ -701,9 +701,6 @@ printPlan dryRun verbosity plan sourcePkgDb = case plan of
showFlagAssignment :: FlagAssignment -> String
showFlagAssignment = concatMap ((' ' :) . showFlagValue)
showFlagValue (f, True) = '+' : showFlagName f
showFlagValue (f, False) = '-' : showFlagName f
showFlagName = unFlagName
change (OnlyInLeft pkgid) = display pkgid ++ " removed"
change (InBoth pkgid pkgid') = display pkgid ++ " -> "
......
......@@ -35,7 +35,7 @@ import Distribution.Package
import Distribution.System
( Platform, OS(Windows), buildOS )
import Distribution.PackageDescription
( unFlagName, FlagAssignment )
( FlagAssignment, showFlagValue )
import Distribution.Simple.Compiler
( CompilerId, OptimisationLevel(..), DebugInfoLevel(..)
, ProfDetailLevel(..), showProfDetailLevel )
......@@ -262,10 +262,7 @@ renderPackageHashInputs PackageHashInputs{
| value == def = Nothing
| otherwise = entry key format value
showFlagAssignment = unwords . map showEntry . sortBy (compare `on` fst)
where
showEntry (fname, False) = '-' : unFlagName fname
showEntry (fname, True) = '+' : unFlagName fname
showFlagAssignment = unwords . map showFlagValue . sortBy (compare `on` fst)
-----------------------------------------------
-- The specific choice of hash implementation
......
......@@ -77,8 +77,7 @@ import Distribution.Solver.Types.OptionalStanza
import Distribution.Package
hiding (InstalledPackageId, installedPackageId)
import qualified Distribution.PackageDescription as PD
import Distribution.PackageDescription (FlagAssignment)
import Distribution.PackageDescription (FlagAssignment, showFlagValue)
import Distribution.Simple.Setup (HaddockFlags)
import qualified Distribution.Simple.Setup as Setup
import Distribution.Simple.Command (commandShowOptions)
......@@ -570,12 +569,8 @@ printPlan verbosity
= " (" ++ intercalate ", " [ showComponentTarget (packageId elab) t | t <- elabBuildTargets elab ]
++ ")"
-- TODO: [code cleanup] this should be a proper function in a proper place
showFlagAssignment :: FlagAssignment -> String
showFlagAssignment = concatMap ((' ' :) . showFlagValue)
showFlagValue (f, True) = '+' : showFlagName f
showFlagValue (f, False) = '-' : showFlagName f
showFlagName = PD.unFlagName
showConfigureFlags elab =
let fullConfigureFlags
......
......@@ -82,8 +82,7 @@ showQSNBool :: QSN -> Bool -> String
showQSNBool qsn@(SN pi _f) b = showPI pi ++ ":" ++ showSBool qsn b
showFBool :: FN qpn -> Bool -> String
showFBool (FN _ f) True = "+" ++ unFlag f
showFBool (FN _ f) False = "-" ++ unFlag f
showFBool (FN _ f) v = showFlagValue (f, v)
showSBool :: SN qpn -> Bool -> String
showSBool (SN _ s) True = "*" ++ unStanza s
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment