Skip to content

Commit 6867dd5

Browse files
committed
cabal-install: call Cabal in-library
This architectural change ensures that we build packages using Cabal library functions (using a Haskell library interface) instead of going via the command-line interface of Setup.hs, as much as possible. The main changes are in SetupWrapper: the old InternalMethod becomes LibraryMethod, which builds the package by calling Cabal library functions. This is used to build all packages unless build-type: Custom or there is a Cabal library version mismatch which requires us to fall back to compiling Setup.hs and running that. The SelfExec method as well as forceExternalSetupMethod are removed: they no longer have any purpose, as builds can now be carried out concurrently thanks to 7b90583 and edb808a. This change required a bit of GADT trickery to accomodate the fact that configure returns a LocalBuildInfo which must then be passed to subsequent phases, while with the old Setup interface everything returns `IO ()` and communication is done through the filesystem (the local build info file). The new Distribution.Client.InLibrary module contains all the necessary framework for taking information that cabal-install has and invoking Cabal library functions to perform the appropriate action (configure, build, test, bench, ...). Most of these are pretty simple; the main difficulty is with configure as we need to jump to the part of the Cabal configure code that continues after figuring out information about the system (e.g. compiler information, dependency information determined by the solver), to avoid wasting work with Cabal rediscovering things that cabal-install already knows. This required a bit of refactoring in Distribution.Simple.Configure. Packages with 'build-type: Hooks' are now compiled with the in-library method (instead of going via Setup.hs). This is achieved as follows: - The Cabal library provides 'Distribution.Simple.SetupHooks.HooksMain', which exposes `hooksMain :: SetupHooks -> IO ()`. This allows us to turn any definition of `SetupHooks` into an external hooks executable. - The new `hooks-exe` library, which `cabal-install` depends on, provides the logic for communicating with the external hooks executable (using the `CommunicationHandle` functionality from haskell/process#308). This change has been extensively tested by compiling clc-stackage and diffing the differences in LocalBuildInfo (i.e. the output of the configure step).
1 parent e7cf0cb commit 6867dd5

69 files changed

Lines changed: 3267 additions & 1409 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.hlint.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- ignore: {name: "Functor law", within: [Test.Laws]}
3838
- ignore: {name: "Monoid law, left identity", within: [Test.Laws, UnitTests.Distribution.Utils.NubList]}
3939
- ignore: {name: "Monoid law, right identity", within: [Test.Laws, UnitTests.Distribution.Utils.NubList]}
40+
- ignore: {name: "Replace case with maybe", within: [Distribution.Client.InLibrary]}
4041
- ignore: {name: "Use fmap", within: [Distribution.Client.HttpUtils, Distribution.Simple.SrcDist]}
4142

4243
- group:

Cabal/Cabal.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ library
4848
, directory >= 1.2.7 && < 1.4
4949
, filepath >= 1.4.2 && < 1.6
5050
, pretty >= 1.1.1 && < 1.2
51-
-- segfaults on older macOS versions #11465
52-
, process >= 1.2.1.0 && < 1.6.24 || == 1.6.26.0 || >= 1.6.26.2 && < 1.7
51+
, process >= 1.6.20.0 && < 1.6.24 || == 1.6.26.0 || >= 1.6.26.2 && < 1.7
5352
, time >= 1.4.0.1 && < 1.16
5453

5554
if os(windows)
@@ -165,6 +164,7 @@ library
165164
Distribution.Simple.UHC
166165
Distribution.Simple.UserHooks
167166
Distribution.Simple.SetupHooks.Errors
167+
Distribution.Simple.SetupHooks.HooksMain
168168
Distribution.Simple.SetupHooks.Internal
169169
Distribution.Simple.SetupHooks.Rule
170170
Distribution.Simple.Utils

Cabal/src/Distribution/Simple.hs

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ defaultMainWithSetupHooksArgs setupHooks verbHandles =
171171
, hscolourHook = setup_hscolourHook
172172
}
173173
where
174+
preBuildHook =
175+
case SetupHooks.preBuildComponentRules (SetupHooks.buildHooks setupHooks) of
176+
Nothing -> const $ return []
177+
Just pbcRules -> \pbci -> runPreBuildHooks verbHandles pbci pbcRules
178+
postBuildHook =
179+
case SetupHooks.postBuildComponentHook (SetupHooks.buildHooks setupHooks) of
180+
Nothing -> const $ return ()
181+
Just hk -> hk
182+
174183
setup_confHook
175184
:: (GenericPackageDescription, HookedBuildInfo)
176185
-> ConfigFlags
@@ -188,13 +197,14 @@ defaultMainWithSetupHooksArgs setupHooks verbHandles =
188197
-> BuildFlags
189198
-> IO ()
190199
setup_buildHook pkg_descr lbi hooks flags =
191-
build_setupHooks
192-
(SetupHooks.buildHooks setupHooks)
193-
verbHandles
194-
pkg_descr
195-
lbi
196-
flags
197-
(allSuffixHandlers hooks)
200+
void $
201+
build_setupHooks
202+
(preBuildHook, postBuildHook)
203+
verbHandles
204+
pkg_descr
205+
lbi
206+
flags
207+
(allSuffixHandlers hooks)
198208

199209
setup_copyHook
200210
:: PackageDescription
@@ -229,14 +239,15 @@ defaultMainWithSetupHooksArgs setupHooks verbHandles =
229239
-> [String]
230240
-> IO ()
231241
setup_replHook pkg_descr lbi hooks flags args =
232-
repl_setupHooks
233-
(SetupHooks.buildHooks setupHooks)
234-
verbHandles
235-
pkg_descr
236-
lbi
237-
flags
238-
(allSuffixHandlers hooks)
239-
args
242+
void $
243+
repl_setupHooks
244+
preBuildHook
245+
verbHandles
246+
pkg_descr
247+
lbi
248+
flags
249+
(allSuffixHandlers hooks)
250+
args
240251

241252
setup_haddockHook
242253
:: PackageDescription
@@ -245,13 +256,14 @@ defaultMainWithSetupHooksArgs setupHooks verbHandles =
245256
-> HaddockFlags
246257
-> IO ()
247258
setup_haddockHook pkg_descr lbi hooks flags =
248-
haddock_setupHooks
249-
(SetupHooks.buildHooks setupHooks)
250-
verbHandles
251-
pkg_descr
252-
lbi
253-
(allSuffixHandlers hooks)
254-
flags
259+
void $
260+
haddock_setupHooks
261+
preBuildHook
262+
verbHandles
263+
pkg_descr
264+
lbi
265+
(allSuffixHandlers hooks)
266+
flags
255267

256268
setup_hscolourHook
257269
:: PackageDescription
@@ -260,13 +272,14 @@ defaultMainWithSetupHooksArgs setupHooks verbHandles =
260272
-> HscolourFlags
261273
-> IO ()
262274
setup_hscolourHook pkg_descr lbi hooks flags =
263-
hscolour_setupHooks
264-
(SetupHooks.buildHooks setupHooks)
265-
verbHandles
266-
pkg_descr
267-
lbi
268-
(allSuffixHandlers hooks)
269-
flags
275+
void $
276+
hscolour_setupHooks
277+
preBuildHook
278+
verbHandles
279+
pkg_descr
280+
lbi
281+
(allSuffixHandlers hooks)
282+
flags
270283

271284
-- | A customizable version of 'defaultMain'.
272285
defaultMainWithHooks :: UserHooks -> IO ()
@@ -930,12 +943,16 @@ simpleUserHooksWithHandles verbHandles =
930943
, testHook = defaultTestHook verbHandles
931944
, benchHook = defaultBenchHook verbHandles
932945
, cleanHook = \p _ _ f -> clean verbHandles p f
933-
, hscolourHook = \p l h f -> hscolour_setupHooks SetupHooks.noBuildHooks verbHandles p l (allSuffixHandlers h) f
934-
, haddockHook = \p l h f -> haddock_setupHooks SetupHooks.noBuildHooks verbHandles p l (allSuffixHandlers h) f
946+
, hscolourHook = \p l h f -> void $ hscolour_setupHooks noBuildHooks verbHandles p l (allSuffixHandlers h) f
947+
, haddockHook = \p l h f -> void $ haddock_setupHooks noBuildHooks verbHandles p l (allSuffixHandlers h) f
935948
, regHook = defaultRegHook verbHandles
936949
, unregHook = \p l _ f -> unregisterWithHandles verbHandles p l f
937950
}
938951
where
952+
noBuildHooks pbci@(SetupHooks.PreBuildComponentInputs{SetupHooks.localBuildInfo = lbi}) =
953+
builtinPreBuildHooks
954+
(buildType (localPkgDescr lbi))
955+
pbci
939956
finalChecks _args flags pkg_descr lbi =
940957
checkForeignDeps pkg_descr lbi (modifyVerbosityFlags lessVerbose verbosity)
941958
where
@@ -1155,13 +1172,14 @@ defaultBuildHook
11551172
-> BuildFlags
11561173
-> IO ()
11571174
defaultBuildHook verbHandles pkg_descr localbuildinfo hooks flags =
1158-
build_setupHooks
1159-
SetupHooks.noBuildHooks
1160-
verbHandles
1161-
pkg_descr
1162-
localbuildinfo
1163-
flags
1164-
(allSuffixHandlers hooks)
1175+
void $
1176+
build_setupHooks
1177+
(builtinPreBuildHooks (buildType pkg_descr), const $ pure ())
1178+
verbHandles
1179+
pkg_descr
1180+
localbuildinfo
1181+
flags
1182+
(allSuffixHandlers hooks)
11651183

11661184
defaultReplHook
11671185
:: VerbosityHandles
@@ -1172,14 +1190,15 @@ defaultReplHook
11721190
-> [String]
11731191
-> IO ()
11741192
defaultReplHook verbHandles pkg_descr localbuildinfo hooks flags args =
1175-
repl_setupHooks
1176-
SetupHooks.noBuildHooks
1177-
verbHandles
1178-
pkg_descr
1179-
localbuildinfo
1180-
flags
1181-
(allSuffixHandlers hooks)
1182-
args
1193+
void $
1194+
repl_setupHooks
1195+
(builtinPreBuildHooks (buildType pkg_descr))
1196+
verbHandles
1197+
pkg_descr
1198+
localbuildinfo
1199+
flags
1200+
(allSuffixHandlers hooks)
1201+
args
11831202

11841203
defaultRegHook
11851204
:: VerbosityHandles

0 commit comments

Comments
 (0)