Skip to content

Commit 07f4dd5

Browse files
committed
Allow build-type Configure to work with Components
When components were introduced, cabal had support for build-type: Configure, which allows to run a `configure` script prior to building the package. Upon the introduction of components, it became obvious that we can't just configure each and every component, as this easily runs into the situation where the `configure` script is run potentially concurrently for all components. However, build-type is a global option for cabal files, and is usually used to produce a <pkg>.buildinfo file. This file is then used to augment the Main Library only. This change now tracks whether or not we are building a component to the setup invocation, and if we do, ignores a build-type: Configure built-type from the package description. For end users who want to depend on package configured values, they will need to set their sub libraries, executables, ... and other components to depend on the main library, and import any configured values from there. For lib:Cabal, which doesn't know about components when configure is invoked, we will continue to execute configure, even though cabal will never use that info.
1 parent 40f56dd commit 07f4dd5

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

cabal-install/src/Distribution/Client/Configure.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ configureSetupScript
300300
, useDependenciesExclusive = not defaultSetupDeps && isJust explicitSetupDeps
301301
, useVersionMacros = not defaultSetupDeps && isJust explicitSetupDeps
302302
, isInteractive = False
303+
, isComponent = False
303304
}
304305
where
305306
-- When we are compiling a legacy setup script without an explicit

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,10 @@ elaborateInstallPlan
18331833
-- Once you've implemented this, swap it for the code below.
18341834
cuz_buildtype =
18351835
case bt of
1836-
PD.Configure -> [CuzBuildType CuzConfigureBuildType]
1836+
PD.Configure -> []
1837+
-- Configure is supported, but we only support configuring the
1838+
-- main library in cabal. Other components will need to depend
1839+
-- on the main library for configured data.
18371840
PD.Custom -> [CuzBuildType CuzCustomBuildType]
18381841
PD.Hooks -> [CuzBuildType CuzHooksBuildType]
18391842
PD.Make -> [CuzBuildType CuzMakeBuildType]
@@ -4028,6 +4031,9 @@ setupHsScriptOptions
40284031
, forceExternalSetupMethod = isParallelBuild
40294032
, setupCacheLock = Just cacheLock
40304033
, isInteractive = False
4034+
, isComponent = case elabPkgOrComp of
4035+
ElabPackage{} -> False
4036+
ElabComponent{} -> True
40314037
}
40324038

40334039
-- | To be used for the input for elaborateInstallPlan.

cabal-install/src/Distribution/Client/SetupWrapper.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ data SetupScriptOptions = SetupScriptOptions
314314
-- ^ Is the task we are going to run an interactive foreground task,
315315
-- or an non-interactive background task? Based on this flag we
316316
-- decide whether or not to delegate ctrl+c to the spawned task
317+
, isComponent :: Bool
318+
-- ^ Let the setup script logic know if it is being run to build a component
319+
-- or a package. This is used to determine if we should use the configure
320+
-- command, if the build-type is 'Configure'. For configure, only the
321+
-- main library has 'configure' support, and thus we can skip running
322+
-- configure for components.
317323
}
318324

319325
defaultSetupScriptOptions :: SetupScriptOptions
@@ -338,6 +344,7 @@ defaultSetupScriptOptions =
338344
, forceExternalSetupMethod = False
339345
, setupCacheLock = Nothing
340346
, isInteractive = False
347+
, isComponent = False
341348
}
342349

343350
workingDir :: SetupScriptOptions -> FilePath
@@ -374,7 +381,9 @@ getSetup verbosity options mpkg = do
374381
(useCabalVersion options)
375382
(orLaterVersion (mkVersion (cabalSpecMinimumLibraryVersion (specVersion pkg))))
376383
}
377-
buildType' = buildType pkg
384+
buildType' = case (buildType pkg, isComponent options) of
385+
(Configure, True) -> Simple
386+
(bt, _) -> bt
378387
(version, method, options'') <-
379388
getSetupMethod verbosity options' pkg buildType'
380389
return

0 commit comments

Comments
 (0)