Skip to content

Commit

Permalink
Merge pull request #10128 from alt-romes/wip/romes/disable-build-tool…
Browse files Browse the repository at this point in the history
…-depends

Cabal: Add flag to ignore build tool dependencies
  • Loading branch information
mergify[bot] authored Jun 28, 2024
2 parents a407863 + ef56d72 commit e7657ad
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ md5CheckGenericPackageDescription proxy = md5Check proxy
md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
md5CheckLocalBuildInfo proxy = md5Check proxy
#if MIN_VERSION_base(4,19,0)
0x31b94dc3e61eb01fea1a1c3c73d984ee
0x6809d4d86ae1810f2a032bc90c952b76
#else
0xdc2f5e7a9c696a4e0bd64f02a0140b74
0x9409dca80a2e1522b1c3a39356e9aaef
#endif
50 changes: 27 additions & 23 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -858,29 +858,33 @@ 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 = do
bi <- enabledBuildInfos pkg_descr0 enabled
-- First, we collect any tool dep that we know is external. This is,
-- in practice:
--
-- 1. `build-tools` entries on the whitelist
--
-- 2. `build-tool-depends` that aren't from the current package.
let externBuildToolDeps =
[ LegacyExeDependency (unUnqualComponentName eName) versionRange
| buildTool@(ExeDependency _ eName versionRange) <-
getAllToolDependencies pkg_descr0 bi
, not $ isInternal pkg_descr0 buildTool
]
-- Second, we collect any build-tools entry we don't know how to
-- desugar. We'll never have any idea how to build them, so we just
-- hope they are already on the PATH.
let unknownBuildTools =
[ buildTool
| buildTool <- buildTools bi
, Nothing == desugarBuildTool pkg_descr0 buildTool
]
externBuildToolDeps ++ unknownBuildTools
let requiredBuildTools
-- If --ignore-build-tools is set, no build tool is required:
| fromFlagOrDefault False $ configIgnoreBuildTools cfg =
[]
| otherwise = do
bi <- enabledBuildInfos pkg_descr0 enabled
-- First, we collect any tool dep that we know is external. This is,
-- in practice:
--
-- 1. `build-tools` entries on the whitelist
--
-- 2. `build-tool-depends` that aren't from the current package.
let externBuildToolDeps =
[ LegacyExeDependency (unUnqualComponentName eName) versionRange
| buildTool@(ExeDependency _ eName versionRange) <-
getAllToolDependencies pkg_descr0 bi
, not $ isInternal pkg_descr0 buildTool
]
-- Second, we collect any build-tools entry we don't know how to
-- desugar. We'll never have any idea how to build them, so we just
-- hope they are already on the PATH.
let unknownBuildTools =
[ buildTool
| buildTool <- buildTools bi
, Nothing == desugarBuildTool pkg_descr0 buildTool
]
externBuildToolDeps ++ unknownBuildTools

programDb1 <-
configureAllKnownPrograms (lessVerbose verbosity) programDb0
Expand Down
15 changes: 15 additions & 0 deletions Cabal/src/Distribution/Simple/Setup/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ data ConfigFlags = ConfigFlags
-- testsuites run with @--enable-coverage@. Notably, this list must exclude
-- indefinite libraries and instantiations because HPC does not support
-- backpack (Nov. 2023).
, configIgnoreBuildTools :: Flag Bool
-- ^ When this flag is set, all tools declared in `build-tool`s and
-- `build-tool-depends` will be ignored. This allows a Cabal package with
-- build-tool-dependencies to be built even if the tool is not found.
}
deriving (Generic, Read, Show, Typeable)

Expand Down Expand Up @@ -322,7 +326,9 @@ instance Eq ConfigFlags where
&& equal configDebugInfo
&& equal configDumpBuildInfo
&& equal configUseResponseFiles
&& equal configAllowDependingOnPrivateLibs
&& equal configCoverageFor
&& equal configIgnoreBuildTools
where
equal f = on (==) f a b

Expand Down Expand Up @@ -866,6 +872,15 @@ configureOptions showOrParseArgs =
(Flag . (: []) . fromString)
(fmap prettyShow . fromFlagOrDefault [])
)
, option
""
["ignore-build-tools"]
( "Ignore build tool dependencies. "
++ "If set, declared build tools needn't be found for compilation to proceed."
)
configIgnoreBuildTools
(\v flags -> flags{configIgnoreBuildTools = v})
trueArg
]
where
liftInstallDirs =
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ instance Semigroup SavedConfig where
, configAllowDependingOnPrivateLibs =
combine configAllowDependingOnPrivateLibs
, configCoverageFor = combine configCoverageFor
, configIgnoreBuildTools = combine configIgnoreBuildTools
}
where
combine = combine' savedConfigureFlags
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ convertToLegacyAllPackageConfig
, configDumpBuildInfo = mempty
, configAllowDependingOnPrivateLibs = mempty
, configCoverageFor = mempty
, configIgnoreBuildTools = mempty
}

haddockFlags =
Expand Down Expand Up @@ -1191,6 +1192,7 @@ convertToLegacyPerPackageConfig PackageConfig{..} =
, configDumpBuildInfo = packageConfigDumpBuildInfo
, configAllowDependingOnPrivateLibs = mempty
, configCoverageFor = mempty
, configIgnoreBuildTools = mempty
}

installFlags =
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4047,6 +4047,7 @@ setupHsConfigureFlags
configPrograms_ = mempty -- never use, shouldn't exist
configUseResponseFiles = mempty
configAllowDependingOnPrivateLibs = Flag $ not $ libraryVisibilitySupported pkgConfigCompiler
configIgnoreBuildTools = mempty

cidToGivenComponent :: ConfiguredId -> GivenComponent
cidToGivenComponent (ConfiguredId srcid mb_cn cid) = GivenComponent (packageName srcid) ln cid
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ filterConfigureFlags' flags cabalLibVersion
flags_latest
{ -- Building profiled shared libraries
configProfShared = NoFlag
, configIgnoreBuildTools = NoFlag
}

flags_3_11_0 =
Expand Down
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/IgnoreBuildTools/Hello.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Main where

a :: String
a = "0000"

main :: IO ()
main = putStrLn a
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/IgnoreBuildTools/client.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cabal-version: 3.0
name: client
version: 0.1.0.0
license: MIT
category: Testing
build-type: Simple

executable hello-world
main-is: Hello.hs
build-depends: base
build-tool-depends: pre-proc:zero-to-one, another:non-existent
-- build-tools: somethingnonexists
default-language: Haskell2010
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/IgnoreBuildTools/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Setup configure
Configuring client-0.1.0.0...
# Setup build
Preprocessing executable 'hello-world' for client-0.1.0.0...
Building executable 'hello-world' for client-0.1.0.0...
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/IgnoreBuildTools/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude
-- Test --ignore-build-tools ignores build-tools and build-tool-depends
main = setupTest $ do
setup "configure" ["--ignore-build-tools"]
setup "build" []
12 changes: 12 additions & 0 deletions changelog.d/pr-10128
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
synopsis: Add flag ignore-build-tools
packages: Cabal
prs: #10128

description: {

- Adds flag --ignore-build-tools which allows a user to ignore the tool
dependencies declared in build-tool-depends. For general use, this flag
should never be needed, but it may be useful for packagers.

}

0 comments on commit e7657ad

Please sign in to comment.