Skip to content

Commit a61f7f7

Browse files
authored
Merge pull request #4260 from Ericson2314/build-tools-path
Unknown build-tools are looked up on the PATH -- fix and test
2 parents 6d993e2 + d4102dc commit a61f7f7

File tree

16 files changed

+89
-27
lines changed

16 files changed

+89
-27
lines changed

Cabal/Distribution/Backpack/ComponentsGraph.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
-- | See <https://github.com/ezyang/ghc-proposals/blob/backpack/proposals/0000-backpack.rst>
2-
32
module Distribution.Backpack.ComponentsGraph (
43
ComponentsGraph,
54
dispComponentsGraph,
65
toComponentsGraph,
76
componentCycleMsg
87
) where
98

9+
import Prelude ()
10+
import Distribution.Compat.Prelude
11+
1012
import Distribution.Package
1113
import Distribution.PackageDescription as PD hiding (Flag)
1214
import Distribution.Simple.BuildToolDepends
1315
import Distribution.Simple.LocalBuildInfo
1416
import Distribution.Types.ComponentRequestedSpec
1517
import Distribution.Types.Dependency
16-
import Distribution.Types.ExeDependency
1718
import Distribution.Types.UnqualComponentName
18-
import Distribution.Simple.Utils
1919
import Distribution.Compat.Graph (Node(..))
2020
import qualified Distribution.Compat.Graph as Graph
2121

@@ -55,9 +55,7 @@ toComponentsGraph enabled pkg_descr =
5555
where
5656
-- The dependencies for the given component
5757
componentDeps component =
58-
[ CExeName toolname
59-
| (ExeDependency _ toolname _)
60-
<- getAllInternalToolDependencies pkg_descr bi ]
58+
(CExeName <$> getAllInternalToolDependencies pkg_descr bi)
6159

6260
++ [ if pkgname == packageName pkg_descr
6361
then CLibName

Cabal/Distribution/Backpack/ConfiguredComponent.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import Distribution.Compat.Prelude hiding ((<>))
1919
import Distribution.Backpack.Id
2020

2121
import Distribution.Types.Dependency
22-
import Distribution.Types.ExeDependency
2322
import Distribution.Types.IncludeRenaming
2423
import Distribution.Types.Mixin
2524
import Distribution.Types.UnqualComponentName
@@ -170,8 +169,7 @@ toConfiguredComponent pkg_descr this_cid
170169
| otherwise
171170
= Map.toList external_lib_map
172171
exe_deps = [ cid
173-
| (ExeDependency _ toolName _)
174-
<- getAllInternalToolDependencies pkg_descr bi
172+
| toolName <- getAllInternalToolDependencies pkg_descr bi
175173
, Just cid <- [ Map.lookup toolName exe_map ] ]
176174

177175
-- | Also computes the 'ComponentId', and sets cc_public if necessary.

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ checkFields pkg =
603603
internalExeDeps =
604604
[ dep
605605
| bi <- allBuildInfo pkg
606-
, dep <- getAllInternalToolDependencies pkg bi
606+
, dep <- getAllToolDependencies pkg bi
607+
, isInternal pkg dep
607608
]
608609

609610
depInternalLibraryWithExtraVersion =

Cabal/Distribution/Simple/Build.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import Prelude ()
3030
import Distribution.Compat.Prelude
3131

3232
import Distribution.Types.Dependency
33-
import Distribution.Types.ExeDependency
3433
import Distribution.Types.LocalBuildInfo
3534
import Distribution.Types.TargetInfo
3635
import Distribution.Types.ComponentRequestedSpec
@@ -537,7 +536,7 @@ addInternalBuildTools pkg lbi bi progs =
537536
where
538537
internalBuildTools =
539538
[ simpleConfiguredProgram toolName' (FoundOnSystem toolLocation)
540-
| ExeDependency _ toolName _ <- getAllInternalToolDependencies pkg bi
539+
| toolName <- getAllInternalToolDependencies pkg bi
541540
, let toolName' = unUnqualComponentName toolName
542541
, let toolLocation = buildDir lbi </> toolName' </> toolName' <.> exeExtension ]
543542

Cabal/Distribution/Simple/BuildToolDepends.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
-- the functions contained to access those fields directly.
66
module Distribution.Simple.BuildToolDepends where
77

8-
import Data.Maybe
8+
import Prelude ()
9+
import Distribution.Compat.Prelude
10+
911
import qualified Data.Map as Map
1012

1113
import Distribution.Package
@@ -86,6 +88,9 @@ isInternal pkg (ExeDependency n _ _) = n == packageName pkg
8688
-- restrictions that apply to `isInternal` also apply to this function.
8789
getAllInternalToolDependencies :: PackageDescription
8890
-> BuildInfo
89-
-> [ExeDependency]
91+
-> [UnqualComponentName]
9092
getAllInternalToolDependencies pkg bi =
91-
filter (isInternal pkg) $ getAllToolDependencies pkg bi
93+
[ toolname
94+
| dep@(ExeDependency _ toolname _) <- getAllToolDependencies pkg bi
95+
, isInternal pkg dep
96+
]

Cabal/Distribution/Simple/Configure.hs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -570,16 +570,28 @@ configure (pkg_descr0', pbi) cfg = do
570570
die $ "Cannot build some foreign libraries: "
571571
++ intercalate "," unsupportedFLibs
572572

573-
-- Configure known/required programs & external build tools.
574-
-- Exclude build-tool deps on "internal" exes in the same package
575-
--
576-
-- TODO: Factor this into a helper package.
577-
let requiredBuildTools =
578-
[ LegacyExeDependency (unUnqualComponentName eName) versionRange
579-
| bi <- enabledBuildInfos pkg_descr enabled
580-
, buildTool@(ExeDependency _ eName versionRange)
581-
<- getAllToolDependencies pkg_descr bi
582-
, not $ isInternal pkg_descr buildTool ]
573+
-- Configure certain external build tools, see below for which ones.
574+
let requiredBuildTools = do
575+
bi <- enabledBuildInfos pkg_descr enabled
576+
-- First, we collect any tool dep that we know is external. This is,
577+
-- in practice:
578+
--
579+
-- 1. `build-tools` entries on the whitelist
580+
--
581+
-- 2. `build-tool-depends` that aren't from the current package.
582+
let externBuildToolDeps =
583+
[ LegacyExeDependency (unUnqualComponentName eName) versionRange
584+
| buildTool@(ExeDependency _ eName versionRange)
585+
<- getAllToolDependencies pkg_descr bi
586+
, not $ isInternal pkg_descr buildTool ]
587+
-- Second, we collect any build-tools entry we don't know how to
588+
-- desugar. We'll never have any idea how to build them, so we just
589+
-- hope they are already on the PATH.
590+
let unknownBuildTools =
591+
[ buildTool
592+
| buildTool <- buildTools bi
593+
, Nothing == desugarBuildTool pkg_descr buildTool ]
594+
externBuildToolDeps ++ unknownBuildTools
583595

584596
programDb' <-
585597
configureAllKnownPrograms (lessVerbose verbosity) programDb
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# OPTIONS_GHC -F -pgmF my-foreign-preprocessor #-}
2+
module A where
3+
4+
a :: String
5+
a = "0000"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: build-tools-path-foreign
2+
version: 0.1.0.0
3+
synopsis: Checks unknown build-tools are drawn from PATH
4+
license: BSD3
5+
category: Testing
6+
build-type: Simple
7+
cabal-version: >=1.10
8+
9+
library
10+
exposed-modules: A
11+
build-depends: base
12+
build-tools: my-foreign-preprocessor
13+
-- ^ Note the unknown dependency.
14+
default-language: Haskell2010
15+
16+
executable hello-world
17+
main-is: Hello.hs
18+
build-depends: base, build-tools-path-foreign
19+
default-language: Haskell2010
20+
hs-source-dirs: hello
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
3+
sed -e 's/0/1/g' < $2 > $3
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Test.Cabal.Prelude
2+
3+
import Control.Applicative ((<$>))
4+
import Control.Monad.IO.Class
5+
import System.Environment
6+
7+
-- Test PATH-munging
8+
-- TODO: Enable this test on Windows
9+
main = setupAndCabalTest $ do
10+
skipIf =<< isWindows
11+
path <- liftIO $ getEnv "PATH"
12+
cwd <- testCurrentDir <$> getTestEnv
13+
r <- withEnv [("PATH", Just $ cwd ++ ":" ++ path)] $ setup_build []
14+
runExe' "hello-world" []
15+
>>= assertOutputContains "1111"

cabal-testsuite/PackageTests/BuildToolsPath/build-tools-path.cabal renamed to cabal-testsuite/PackageTests/BuildToolsPathInternal/build-tools-path-internal.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build-tools-path
1+
name: build-tools-path-internal
22
version: 0.1.0.0
33
synopsis: Checks build-tools are put in PATH
44
license: BSD3
@@ -20,6 +20,6 @@ library
2020

2121
executable hello-world
2222
main-is: Hello.hs
23-
build-depends: base, build-tools-path
23+
build-depends: base, build-tools-path-internal
2424
default-language: Haskell2010
2525
hs-source-dirs: hello
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import A
4+
5+
main :: IO ()
6+
main = putStrLn a

0 commit comments

Comments
 (0)