Skip to content
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

Fix/build tool depends repeats 10758 #10764

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
53 changes: 51 additions & 2 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
Expand Down Expand Up @@ -129,7 +130,8 @@ import qualified Data.ByteString as BS
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy.Char8 as BLC8
import Data.List
( intersect
( groupBy
, intersect
, stripPrefix
, (\\)
)
Expand Down Expand Up @@ -172,10 +174,15 @@ import qualified System.Info
import Text.PrettyPrint
( Doc
, char
, colon
, hsep
, int
, nest
, parens
, quotes
, renderStyle
, text
, vcat
, ($+$)
)

Expand Down Expand Up @@ -858,7 +865,7 @@ configurePackage cfg lbc0 pkg_descr00 flags enabled comp platform programDb0 pac
-- right before calling configurePackage?

-- Configure certain external build tools, see below for which ones.
let requiredBuildTools
let rawRequiredBuildTools
-- If --ignore-build-tools is set, no build tool is required:
| fromFlagOrDefault False $ configIgnoreBuildTools cfg =
[]
Expand Down Expand Up @@ -886,6 +893,20 @@ configurePackage cfg lbc0 pkg_descr00 flags enabled comp platform programDb0 pac
]
externBuildToolDeps ++ unknownBuildTools

let (requiredBuildTools, dups) = deduplicateBuildTools rawRequiredBuildTools

for_ dups $ \case
(_, []) -> return ()
(merged, ds@(dup : _)) ->
noticeDoc verbosity $
vcat
[ (text "As the build tool" <+> quotes (text $ nameOf dup) <+> "was specified more than once") <> colon
, nest 2 $ vcat [char '-' <+> versionOfDoc d | d <- ds]
, (text "We'll use the effective intersection of these" <+> int (length ds) <+> "version ranges") <> colon
, nest 2 $ char '-' <+> versionOfDoc merged
, text "Please specify build tool dependencies only once."
]

programDb1 <-
configureAllKnownPrograms (lessVerbose verbosity) programDb0
>>= configureRequiredPrograms verbosity requiredBuildTools
Expand Down Expand Up @@ -935,6 +956,34 @@ configurePackage cfg lbc0 pkg_descr00 flags enabled comp platform programDb0 pac

return (lbc, pbd)

nameOf :: LegacyExeDependency -> String
nameOf (LegacyExeDependency n _) = n

versionOf :: LegacyExeDependency -> VersionRange
versionOf (LegacyExeDependency _ v) = v

versionOfDoc :: LegacyExeDependency -> Doc
versionOfDoc (LegacyExeDependency _ v) =
if v == anyVersion
then text (prettyShow v) <+> parens (text "any version")
else text $ prettyShow v

-- | Any duplicates in the list has their version range merged by intersection.
-- The second list has the build tool with its merged version range and its list
-- of duplicates.
deduplicateBuildTools :: [LegacyExeDependency] -> ([LegacyExeDependency], [(LegacyExeDependency, [LegacyExeDependency])])
deduplicateBuildTools xs =
catMaybes
<$> unzip
[ (merged, if length gs == 1 then Nothing else Just (merged, gs))
| gs@(g : _) <- groupBy ((==) `on` nameOf) (sortBy (comparing nameOf) xs)
, let merged = LegacyExeDependency (nameOf g) (mergeVersions (ordNub . filter (/= anyVersion) $ versionOf <$> gs))
]
where
mergeVersions :: [VersionRange] -> VersionRange
mergeVersions [] = anyVersion
mergeVersions (v : vs) = foldr intersectVersionRanges v vs
ffaf1 marked this conversation as resolved.
Show resolved Hide resolved

finalizeAndConfigurePackage
:: ConfigFlags
-> LBC.LocalBuildConfig
Expand Down
Loading