Commit 9694751a authored by John Ericson's avatar John Ericson
Browse files

Implement "build-tool-depends" in Cabal, and legacy "build-tools" via desugar

parent 6e00f6ac
......@@ -9,10 +9,11 @@ module Distribution.Backpack.ComponentsGraph (
import Distribution.Package
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.LocalBuildInfo
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.Dependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.ExeDependency
import Distribution.Types.UnqualComponentName
import Distribution.Simple.Utils
import Distribution.Compat.Graph (Node(..))
......@@ -55,9 +56,8 @@ toComponentsGraph enabled pkg_descr =
-- The dependencies for the given component
componentDeps component =
[ CExeName toolname
| LegacyExeDependency name _ <- buildTools bi
, let toolname = mkUnqualComponentName name
, toolname `elem` map exeName (executables pkg_descr) ]
| (ExeDependency _ toolname _)
<- getAllInternalToolDependencies pkg_descr bi ]
++ [ if pkgname == packageName pkg_descr
then CLibName
......
......@@ -19,13 +19,14 @@ import Distribution.Compat.Prelude hiding ((<>))
import Distribution.Backpack.Id
import Distribution.Types.Dependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.ExeDependency
import Distribution.Types.IncludeRenaming
import Distribution.Types.Mixin
import Distribution.Types.UnqualComponentName
import Distribution.Types.ComponentInclude
import Distribution.Package
import Distribution.PackageDescription as PD hiding (Flag)
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.Setup as Setup
import Distribution.Simple.LocalBuildInfo
import Distribution.Version
......@@ -169,8 +170,9 @@ toConfiguredComponent pkg_descr this_cid
| otherwise
= Map.toList external_lib_map
exe_deps = [ cid
| LegacyExeDependency name _ <- buildTools bi
, Just cid <- [ Map.lookup (mkUnqualComponentName name) exe_map ] ]
| (ExeDependency _ toolName _)
<- getAllInternalToolDependencies pkg_descr bi
, Just cid <- [ Map.lookup toolName exe_map ] ]
-- | Also computes the 'ComponentId', and sets cc_public if necessary.
-- This is Cabal-only; cabal-install won't use this.
......
......@@ -58,8 +58,9 @@ data LinkedComponent
lc_pkgid :: PackageId,
-- | Corresponds to 'cc_component'.
lc_component :: Component,
-- | Local @build-tools@ dependencies on executables from the
-- same executable. Corresponds to 'cc_internal_build_tools'.
-- | Local @build-tools@ and @build-tool-depends@ dependencies on
-- executables from the same package. Corresponds to
-- 'cc_internal_build_tools'.
lc_internal_build_tools :: [OpenUnitId],
-- | Is this the public library of a package? Corresponds to
-- 'cc_public'.
......
......@@ -603,8 +603,7 @@ checkFields pkg =
internalExeDeps =
[ dep
| bi <- allBuildInfo pkg
, dep <- getAllToolDependencies pkg bi
, isInternal pkg dep
, dep <- getAllInternalToolDependencies pkg bi
]
depInternalLibraryWithExtraVersion =
......
......@@ -30,7 +30,7 @@ import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Types.Dependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.ExeDependency
import Distribution.Types.LocalBuildInfo
import Distribution.Types.TargetInfo
import Distribution.Types.ComponentRequestedSpec
......@@ -59,6 +59,7 @@ import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.Setup
import Distribution.Simple.BuildTarget
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.PreProcess
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program.Types
......@@ -77,7 +78,6 @@ import Distribution.Compat.Graph (IsNode(..))
import Control.Monad
import qualified Data.Set as Set
import Data.List ( intersect )
import System.FilePath ( (</>), (<.>), takeDirectory )
import System.Directory ( getCurrentDirectory )
......@@ -536,14 +536,10 @@ addInternalBuildTools pkg lbi bi progs =
foldr updateProgram progs internalBuildTools
where
internalBuildTools =
[ simpleConfiguredProgram toolName (FoundOnSystem toolLocation)
| toolName <- toolNames
, let toolLocation = buildDir lbi </> toolName </> toolName <.> exeExtension ]
toolNames = intersect buildToolNames internalExeNames
internalExeNames = map (unUnqualComponentName . exeName) (executables pkg)
buildToolNames = map buildToolName (buildTools bi)
where
buildToolName (LegacyExeDependency pname _) = pname
[ simpleConfiguredProgram toolName' (FoundOnSystem toolLocation)
| ExeDependency _ toolName _ <- getAllInternalToolDependencies pkg bi
, let toolName' = unUnqualComponentName toolName
, let toolLocation = buildDir lbi </> toolName' </> toolName' <.> exeExtension ]
-- TODO: build separate libs in separate dirs so that we can build
......
......@@ -77,3 +77,14 @@ getAllToolDependencies pkg bi =
-- conditions.
isInternal :: PackageDescription -> ExeDependency -> Bool
isInternal pkg (ExeDependency n _ _) = n == packageName pkg
-- | Get internal "build-tool-depends", along with internal "build-tools"
--
-- This is a tiny function, but used in a number of places. The same
-- restrictions that apply to `isInternal` also apply to this function.
getAllInternalToolDependencies :: PackageDescription
-> BuildInfo
-> [ExeDependency]
getAllInternalToolDependencies pkg bi =
filter (isInternal pkg) $ getAllToolDependencies pkg bi
......@@ -75,11 +75,13 @@ import Distribution.Types.PackageDescription as PD
import Distribution.PackageDescription.PrettyPrint
import Distribution.PackageDescription.Configuration
import Distribution.PackageDescription.Check hiding (doesFileExist)
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.Program
import Distribution.Simple.Setup as Setup
import Distribution.Simple.BuildTarget
import Distribution.Simple.LocalBuildInfo
import Distribution.Types.Dependency
import Distribution.Types.ExeDependency
import Distribution.Types.LegacyExeDependency
import Distribution.Types.PkgconfigDependency
import Distribution.Types.LocalBuildInfo
......@@ -573,17 +575,11 @@ configure (pkg_descr0', pbi) cfg = do
--
-- TODO: Factor this into a helper package.
let requiredBuildTools =
[ buildTool
| let exeNames = map (unUnqualComponentName . exeName) (executables pkg_descr)
, bi <- enabledBuildInfos pkg_descr enabled
, buildTool@(LegacyExeDependency toolPName reqVer)
<- buildTools bi
, let isInternal =
toolPName `elem` exeNames
-- we assume all internal build-tools are
-- versioned with the package:
&& packageVersion pkg_descr `withinRange` reqVer
, not isInternal ]
[ LegacyExeDependency (unUnqualComponentName eName) versionRange
| bi <- enabledBuildInfos pkg_descr enabled
, buildTool@(ExeDependency _ eName versionRange)
<- getAllToolDependencies pkg_descr bi
, not $ isInternal pkg_descr buildTool ]
programDb' <-
configureAllKnownPrograms (lessVerbose verbosity) programDb
......
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