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

Cabal: Add flag to ignore build tool dependencies (backport #10128) #10159

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
md5CheckLocalBuildInfo proxy = md5Check proxy
#if MIN_VERSION_base(4,19,0)
<<<<<<< HEAD
0x1be858ee00c3e2d4be5331d5f07bfdf7
#else
0x8a5431ab053f8f48c15b303444fa2c39
=======

Check failure on line 48 in Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `=======' ▫︎ Found: " 0x8a5431ab053f8f48c15b303444fa2c39\n> =======\n 0x6809d4d86ae1810f2a032bc90c952b76\n"

Check failure on line 48 in Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `=======' ▫︎ Found: " 0x8a5431ab053f8f48c15b303444fa2c39\n> =======\n 0x6809d4d86ae1810f2a032bc90c952b76\n"
0x6809d4d86ae1810f2a032bc90c952b76
#else
0x9409dca80a2e1522b1c3a39356e9aaef
>>>>>>> ef56d7257 (Cabal: Add flag to ignore build tool dependencies)
#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 @@ -725,29 +725,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 @@ -226,6 +226,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 @@ -294,7 +298,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 @@ -851,6 +857,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 @@ -533,6 +533,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 @@ -1093,6 +1093,7 @@ convertToLegacyAllPackageConfig
, configDumpBuildInfo = mempty
, configAllowDependingOnPrivateLibs = mempty
, configCoverageFor = mempty
, configIgnoreBuildTools = mempty
}

haddockFlags =
Expand Down Expand Up @@ -1170,6 +1171,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 @@ -3938,6 +3938,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
11 changes: 11 additions & 0 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,17 @@
configConstraints = []
}

<<<<<<< HEAD

Check failure on line 675 in cabal-install/src/Distribution/Client/Setup.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `<<<<<<<' ▫︎ Found: " }\n \n> <<<<<<< HEAD\n =======\n flags_3_13_0 =\n"

Check failure on line 675 in cabal-install/src/Distribution/Client/Setup.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `<<<<<<<' ▫︎ Found: " }\n \n> <<<<<<< HEAD\n =======\n flags_3_13_0 =\n"
=======
flags_3_13_0 =
-- Earlier Cabal versions don't understand about ..
flags_latest
{ -- Building profiled shared libraries
configProfShared = NoFlag
, configIgnoreBuildTools = NoFlag
}

>>>>>>> ef56d7257 (Cabal: Add flag to ignore build tool dependencies)
flags_3_11_0 =
flags_latest
{ -- It's too late to convert configPromisedDependencies to anything
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.

}

Loading