Commit 41c20806 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Split useDependenciesExclusive behaviour into two independent options

The useDependenciesExclusive in the SetupWrapper controls two bits of
behaviour: if the deps given for building the Setup.hs are the only
ones allowed, and if we should make version cpp macros available when
building the Setup.hs. Currently we either want both behaviours or
neither behaviour. We want them in the case that a package declares a
custom setup with explicit dependencies.

It makes sense however to have one behaviour without the other. In
particular it makes sense if we want to implement a policy where we
supply default dependencies for older packages that have custom setup
scripts but don't specify any deps. In this case we want to make the
default deps exclusive, but we don't want to use the version macros,
because those ought to be reserved for packages that are doing the right
thing and opting-in to the new world of explicitly specified setup deps.

So this patch splits the behaviour into two controls, but still uses
both together so there's no change in behaviour yet.
parent c7606c93
......@@ -201,6 +201,7 @@ configureSetupScript packageDBs
-- Therefore, for now, we just leave this blank.
, useDependencies = fromMaybe [] explicitSetupDeps
, useDependenciesExclusive = isJust explicitSetupDeps
, useVersionMacros = isJust explicitSetupDeps
}
where
-- When we are compiling a legacy setup script without an explicit
......
......@@ -145,6 +145,12 @@ data SetupScriptOptions = SetupScriptOptions {
-- constraint" that we had previously for Setup scripts).
useDependenciesExclusive :: Bool,
-- | Should we build the Setup.hs with CPP version macros available?
-- We turn this on when we have a setup stanza in .cabal that declares
-- explicit setup dependencies.
--
useVersionMacros :: Bool,
-- Used only by 'cabal clean' on Windows.
--
-- Note: win32 clean hack
......@@ -180,6 +186,7 @@ defaultSetupScriptOptions = SetupScriptOptions {
usePackageIndex = Nothing,
useDependencies = [],
useDependenciesExclusive = False,
useVersionMacros = False,
useProgramConfig = emptyProgramConfiguration,
useDistPref = defaultDistPref,
useLoggingHandle = Nothing,
......@@ -551,13 +558,19 @@ externalSetupMethod verbosity options pkg bt mkargs = do
cabalDep = maybe [] (\ipkgid -> [(ipkgid, cabalPkgid)])
maybeCabalLibInstalledPkgId
-- We do a few things differently once packages opt-in and declare
-- a custom-settup stanza. In particular we then enforce the deps
-- specified, but also let the Setup.hs use the version macros.
newPedanticDeps = useDependenciesExclusive options'
selectedDeps
| newPedanticDeps = useDependencies options'
| otherwise = useDependencies options' ++ cabalDep
-- With 'useDependenciesExclusive' we enforce the deps specified,
-- so only the given ones can be used. Otherwise we allow the use
-- of packages in the ambient environment, and add on a dep on the
-- Cabal library.
--
-- With 'useVersionMacros' we use a version CPP macros .h file.
--
-- Both of these options should be enabled for packages that have
-- opted-in and declared a custom-settup stanza.
--
selectedDeps | useDependenciesExclusive options'
= useDependencies options'
| otherwise = useDependencies options' ++ cabalDep
addRenaming (ipid, pid) = (ipid, pid, defaultRenaming)
cppMacrosFile = setupDir </> "setup_macros.h"
ghcOptions = mempty {
......@@ -570,15 +583,15 @@ externalSetupMethod verbosity options pkg bt mkargs = do
, ghcOptSourcePathClear = Flag True
, ghcOptSourcePath = toNubListR [workingDir]
, ghcOptPackageDBs = usePackageDB options''
, ghcOptHideAllPackages = Flag newPedanticDeps
, ghcOptCabal = Flag newPedanticDeps
, ghcOptHideAllPackages = Flag (useDependenciesExclusive options')
, ghcOptCabal = Flag (useDependenciesExclusive options')
, ghcOptPackages = toNubListR $ map addRenaming selectedDeps
, ghcOptCppIncludes = toNubListR [ cppMacrosFile
| newPedanticDeps ]
| useVersionMacros options' ]
, ghcOptExtra = toNubListR extraOpts
}
let ghcCmdLine = renderGhcOptions compiler ghcOptions
when newPedanticDeps $
when (useVersionMacros options') $
rewriteFile cppMacrosFile (generatePackageVersionMacros
[ pid | (_ipid, pid) <- selectedDeps ])
case useLoggingHandle options of
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment