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

Filter CommonSetupFlags more consistently in UnpackedPackage #10395

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ import Distribution.Client.FileMonitor
import Distribution.Client.JobControl
import Distribution.Client.Setup
( CommonSetupFlags
, filterCommonFlags
, filterBenchmarkFlags
, filterBuildFlags
, filterConfigureFlags
, filterCopyFlags
, filterHaddockArgs
, filterHaddockFlags
, filterRegisterFlags
, filterReplFlags
, filterTestFlags
)
import Distribution.Client.SetupWrapper
Expand Down Expand Up @@ -272,9 +276,7 @@ buildAndRegisterUnpackedPackage
| otherwise = return ()

mbWorkDir = useWorkingDir scriptOptions
commonFlags v =
flip filterCommonFlags v $
setupHsCommonFlags verbosity mbWorkDir builddir
commonFlags = setupHsCommonFlags verbosity mbWorkDir builddir

configureCommand = Cabal.configureCommand defaultProgramDb
configureFlags v =
Expand All @@ -284,19 +286,26 @@ buildAndRegisterUnpackedPackage
plan
rpkg
pkgshared
(commonFlags v)
commonFlags
configureArgs _ = setupHsConfigureArgs pkg

buildCommand = Cabal.buildCommand defaultProgramDb
buildFlags v = setupHsBuildFlags comp_par_strat pkg pkgshared $ commonFlags v
buildFlags v =
flip filterBuildFlags v $
setupHsBuildFlags
comp_par_strat
pkg
pkgshared
commonFlags
buildArgs _ = setupHsBuildArgs pkg

copyFlags destdir v =
setupHsCopyFlags
pkg
pkgshared
(commonFlags v)
destdir
flip filterCopyFlags v $
setupHsCopyFlags
pkg
pkgshared
commonFlags
destdir
-- In theory, we could want to copy less things than those that were
-- built, but instead, we simply copy the targets that were built.
copyArgs = buildArgs
Expand All @@ -306,23 +315,25 @@ buildAndRegisterUnpackedPackage
flip filterTestFlags v $
setupHsTestFlags
pkg
(commonFlags v)
commonFlags
testArgs _ = setupHsTestArgs pkg

benchCommand = Cabal.benchmarkCommand
benchFlags v =
setupHsBenchFlags
pkg
pkgshared
(commonFlags v)
flip filterBenchmarkFlags v $
setupHsBenchFlags
pkg
pkgshared
commonFlags
benchArgs _ = setupHsBenchArgs pkg

replCommand = Cabal.replCommand defaultProgramDb
replFlags v =
setupHsReplFlags
pkg
pkgshared
(commonFlags v)
flip filterReplFlags v $
setupHsReplFlags
pkg
pkgshared
commonFlags
replArgs _ = setupHsReplArgs pkg

haddockCommand = Cabal.haddockCommand
Expand All @@ -332,7 +343,7 @@ buildAndRegisterUnpackedPackage
pkg
pkgshared
buildTimeSettings
(commonFlags v)
commonFlags
haddockArgs v =
flip filterHaddockArgs v $
setupHsHaddockArgs pkg
Expand Down Expand Up @@ -394,11 +405,12 @@ buildAndRegisterUnpackedPackage
distTempDirectory
$ \pkgConfDest -> do
let registerFlags v =
setupHsRegisterFlags
pkg
pkgshared
(commonFlags v)
pkgConfDest
flip filterRegisterFlags v $
setupHsRegisterFlags
pkg
pkgshared
commonFlags
pkgConfDest
setup (Cabal.registerCommand) Cabal.registerCommonFlags (\v -> return (registerFlags v)) (const [])

withLogging :: (Maybe Handle -> IO r) -> IO r
Expand Down
110 changes: 98 additions & 12 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ module Distribution.Client.Setup
, defaultConfigExFlags
, buildCommand
, BuildFlags (..)
, filterBuildFlags
, filterTestFlags
, replCommand
, filterReplFlags
, testCommand
, benchmarkCommand
, testOptions
, benchmarkOptions
, filterBenchmarkFlags
, configureExOptions
, reconfigureCommand
, installCommand
Expand Down Expand Up @@ -87,7 +90,9 @@ module Distribution.Client.Setup
, haddockCommand
, cleanCommand
, copyCommand
, filterCopyFlags
, registerCommand
, filterRegisterFlags
, liftOptions
, yesNoOpt
) where
Expand Down Expand Up @@ -183,7 +188,7 @@ import Distribution.Simple.InstallDirs
)
import Distribution.Simple.Program (ProgramDb, defaultProgramDb)
import Distribution.Simple.Setup
( BenchmarkFlags
( BenchmarkFlags (benchmarkCommonFlags)
, BooleanFlag (..)
, BuildFlags (..)
, CleanFlags (..)
Expand All @@ -192,7 +197,7 @@ import Distribution.Simple.Setup
, CopyFlags (..)
, HaddockFlags (..)
, RegisterFlags (..)
, ReplFlags
, ReplFlags (..)
, TestFlags
, boolOpt
, boolOpt'
Expand Down Expand Up @@ -1144,6 +1149,21 @@ buildCommand =
where
parent = Cabal.buildCommand defaultProgramDb

-- | Given some 'BuildFlags' for the version of @Cabal@ that
-- @cabal-install@ was built with, and a target older 'Version' of
-- @Cabal@ that we want to pass these flags to, convert the
-- flags into a form that will be accepted by the older
-- @Setup@ script. Generally speaking, this just means filtering
-- out flags that the old @Cabal@ library doesn't understand, but
-- in some cases it may also mean "emulating" a feature using
-- some more legacy flags.
filterBuildFlags :: BuildFlags -> Version -> BuildFlags
filterBuildFlags flags cabalLibVersion =
flags
{ buildCommonFlags =
filterCommonFlags (buildCommonFlags flags) cabalLibVersion
}

-- ------------------------------------------------------------

-- * Test flags
Expand Down Expand Up @@ -1236,6 +1256,21 @@ replCommand =
where
parent = Cabal.replCommand defaultProgramDb

-- | Given some 'ReplFlags' for the version of @Cabal@ that
-- @cabal-install@ was built with, and a target older 'Version' of
-- @Cabal@ that we want to pass these flags to, convert the
-- flags into a form that will be accepted by the older
-- @Setup@ script. Generally speaking, this just means filtering
-- out flags that the old @Cabal@ library doesn't understand, but
-- in some cases it may also mean "emulating" a feature using
-- some more legacy flags.
filterReplFlags :: ReplFlags -> Version -> ReplFlags
filterReplFlags flags cabalLibVersion =
flags
{ replCommonFlags =
filterCommonFlags (replCommonFlags flags) cabalLibVersion
}

-- ------------------------------------------------------------

-- * Test command
Expand Down Expand Up @@ -1331,6 +1366,21 @@ benchmarkCommand =
parent = Cabal.benchmarkCommand
progDb = defaultProgramDb

-- | Given some 'BenchmarkFlags' for the version of @Cabal@ that
-- @cabal-install@ was built with, and a target older 'Version' of
-- @Cabal@ that we want to pass these flags to, convert the
-- flags into a form that will be accepted by the older
-- @Setup@ script. Generally speaking, this just means filtering
-- out flags that the old @Cabal@ library doesn't understand, but
-- in some cases it may also mean "emulating" a feature using
-- some more legacy flags.
filterBenchmarkFlags :: BenchmarkFlags -> Version -> BenchmarkFlags
filterBenchmarkFlags flags cabalLibVersion =
flags
{ benchmarkCommonFlags =
filterCommonFlags (benchmarkCommonFlags flags) cabalLibVersion
}

-- ------------------------------------------------------------

-- * Fetch command
Expand Down Expand Up @@ -2404,21 +2454,25 @@ filterHaddockArgs args cabalLibVersion
-- Cabal < 2.3 doesn't know about per-component haddock
args_2_3_0 = []

-- | Given some 'HaddockFlags' for the version of @Cabal@ that
-- @cabal-install@ was built with, and a target older 'Version' of
-- @Cabal@ that we want to pass these flags to, convert the
-- flags into a form that will be accepted by the older
-- @Setup@ script. Generally speaking, this just means filtering
-- out flags that the old @Cabal@ library doesn't understand, but
-- in some cases it may also mean "emulating" a feature using
-- some more legacy flags.
filterHaddockFlags :: HaddockFlags -> Version -> HaddockFlags
filterHaddockFlags flags cabalLibVersion =
let flags' = filterHaddockFlags' flags cabalLibVersion
in flags'
{ haddockCommonFlags =
filterCommonFlags (haddockCommonFlags flags') cabalLibVersion
}

filterHaddockFlags' :: HaddockFlags -> Version -> HaddockFlags
filterHaddockFlags' flags cabalLibVersion
filterHaddockFlags flags cabalLibVersion
| cabalLibVersion >= mkVersion [2, 3, 0] = flags_latest
| cabalLibVersion < mkVersion [2, 3, 0] = flags_2_3_0
| otherwise = flags_latest
where
flags_latest = flags
flags_latest =
flags
{ haddockCommonFlags =
filterCommonFlags (haddockCommonFlags flags) cabalLibVersion
}

flags_2_3_0 =
flags_latest
Expand Down Expand Up @@ -2490,6 +2544,9 @@ testOptions showOrParseArgs =
| "test-" `isPrefixOf` name = name
| otherwise = "test-" ++ name

-- | Options for the @bench@ command.
--
-- Not to be confused with the @benchmarkOptions@ field of the `BenchmarkFlags` record!
benchmarkOptions :: ShowOrParseArgs -> [OptionField BenchmarkFlags]
benchmarkOptions showOrParseArgs =
[ opt
Expand Down Expand Up @@ -3317,6 +3374,35 @@ registerCommand =
{ commandUsage = \pname -> "Usage: " ++ pname ++ " v1-register [FLAGS]\n"
}

-- | Given some 'RegisterFlags' for the version of @Cabal@ that
-- @cabal-install@ was built with, and a target older 'Version' of
-- @Cabal@ that we want to pass these flags to, convert the
-- flags into a form that will be accepted by the older
-- @Setup@ script. Generally speaking, this just means filtering
-- out flags that the old @Cabal@ library doesn't understand, but
-- in some cases it may also mean "emulating" a feature using
-- some more legacy flags.
filterRegisterFlags :: RegisterFlags -> Version -> RegisterFlags
filterRegisterFlags flags cabalLibVersion =
flags
{ registerCommonFlags =
filterCommonFlags (registerCommonFlags flags) cabalLibVersion
}

-- | Given some 'CopyFlags' for the version of @Cabal@ that
-- @cabal-install@ was built with, and a target older 'Version' of
-- @Cabal@ that we want to pass these flags to, convert the
-- flags into a form that will be accepted by the older
-- @Setup@ script. Generally speaking, this just means filtering
-- out flags that the old @Cabal@ library doesn't understand, but
-- in some cases it may also mean "emulating" a feature using
-- some more legacy flags.
filterCopyFlags :: CopyFlags -> Version -> CopyFlags
filterCopyFlags flags cabalLibVersion =
flags
{ copyCommonFlags = filterCommonFlags (copyCommonFlags flags) cabalLibVersion
}

-- ------------------------------------------------------------

-- * ActAsSetup flags
Expand Down
Loading