Skip to content

Commit 242933b

Browse files
9999yearserikd
authored andcommitted
Filter CommonSetupFlags more consistently in UnpackedPackage
In haskell#10292, we will move the `--keep-temp-files` setting into `CommonSetupFlags` and out of `ReplFlags`/`HaddockFlags`. This means that the flag-filtering behavior (which adapts flags from new versions of `cabal-install` to old version of `Cabal`) will need to know which command is being run to provide the correct `CommonSetupFlags`. Therefore, this change adds several new `filterFooFlags` functions to provide this behavior, and removes the `commonFlags` used for all subcommands in `Distribution.Client.ProjectBuilding.UnpackedPackage`.
1 parent a85094a commit 242933b

File tree

2 files changed

+136
-38
lines changed

2 files changed

+136
-38
lines changed

cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ import Distribution.Client.FileMonitor
4444
import Distribution.Client.JobControl
4545
import Distribution.Client.Setup
4646
( CommonSetupFlags
47-
, filterCommonFlags
47+
, filterBenchmarkFlags
48+
, filterBuildFlags
4849
, filterConfigureFlags
50+
, filterCopyFlags
4951
, filterHaddockArgs
5052
, filterHaddockFlags
53+
, filterRegisterFlags
54+
, filterReplFlags
5155
, filterTestFlags
5256
)
5357
import Distribution.Client.SetupWrapper
@@ -272,9 +276,7 @@ buildAndRegisterUnpackedPackage
272276
| otherwise = return ()
273277

274278
mbWorkDir = useWorkingDir scriptOptions
275-
commonFlags v =
276-
flip filterCommonFlags v $
277-
setupHsCommonFlags verbosity mbWorkDir builddir
279+
commonFlags = setupHsCommonFlags verbosity mbWorkDir builddir
278280

279281
configureCommand = Cabal.configureCommand defaultProgramDb
280282
configureFlags v =
@@ -284,19 +286,26 @@ buildAndRegisterUnpackedPackage
284286
plan
285287
rpkg
286288
pkgshared
287-
(commonFlags v)
289+
commonFlags
288290
configureArgs _ = setupHsConfigureArgs pkg
289291

290292
buildCommand = Cabal.buildCommand defaultProgramDb
291-
buildFlags v = setupHsBuildFlags comp_par_strat pkg pkgshared $ commonFlags v
293+
buildFlags v =
294+
flip filterBuildFlags v $
295+
setupHsBuildFlags
296+
comp_par_strat
297+
pkg
298+
pkgshared
299+
commonFlags
292300
buildArgs _ = setupHsBuildArgs pkg
293301

294302
copyFlags destdir v =
295-
setupHsCopyFlags
296-
pkg
297-
pkgshared
298-
(commonFlags v)
299-
destdir
303+
flip filterCopyFlags v $
304+
setupHsCopyFlags
305+
pkg
306+
pkgshared
307+
commonFlags
308+
destdir
300309
-- In theory, we could want to copy less things than those that were
301310
-- built, but instead, we simply copy the targets that were built.
302311
copyArgs = buildArgs
@@ -306,23 +315,25 @@ buildAndRegisterUnpackedPackage
306315
flip filterTestFlags v $
307316
setupHsTestFlags
308317
pkg
309-
(commonFlags v)
318+
commonFlags
310319
testArgs _ = setupHsTestArgs pkg
311320

312321
benchCommand = Cabal.benchmarkCommand
313322
benchFlags v =
314-
setupHsBenchFlags
315-
pkg
316-
pkgshared
317-
(commonFlags v)
323+
flip filterBenchmarkFlags v $
324+
setupHsBenchFlags
325+
pkg
326+
pkgshared
327+
commonFlags
318328
benchArgs _ = setupHsBenchArgs pkg
319329

320330
replCommand = Cabal.replCommand defaultProgramDb
321331
replFlags v =
322-
setupHsReplFlags
323-
pkg
324-
pkgshared
325-
(commonFlags v)
332+
flip filterReplFlags v $
333+
setupHsReplFlags
334+
pkg
335+
pkgshared
336+
commonFlags
326337
replArgs _ = setupHsReplArgs pkg
327338

328339
haddockCommand = Cabal.haddockCommand
@@ -332,7 +343,7 @@ buildAndRegisterUnpackedPackage
332343
pkg
333344
pkgshared
334345
buildTimeSettings
335-
(commonFlags v)
346+
commonFlags
336347
haddockArgs v =
337348
flip filterHaddockArgs v $
338349
setupHsHaddockArgs pkg
@@ -394,11 +405,12 @@ buildAndRegisterUnpackedPackage
394405
distTempDirectory
395406
$ \pkgConfDest -> do
396407
let registerFlags v =
397-
setupHsRegisterFlags
398-
pkg
399-
pkgshared
400-
(commonFlags v)
401-
pkgConfDest
408+
flip filterRegisterFlags v $
409+
setupHsRegisterFlags
410+
pkg
411+
pkgshared
412+
commonFlags
413+
pkgConfDest
402414
setup (Cabal.registerCommand) Cabal.registerCommonFlags (\v -> return (registerFlags v)) (const [])
403415

404416
withLogging :: (Maybe Handle -> IO r) -> IO r

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

Lines changed: 98 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ module Distribution.Client.Setup
3535
, defaultConfigExFlags
3636
, buildCommand
3737
, BuildFlags (..)
38+
, filterBuildFlags
3839
, filterTestFlags
3940
, replCommand
41+
, filterReplFlags
4042
, testCommand
4143
, benchmarkCommand
4244
, testOptions
4345
, benchmarkOptions
46+
, filterBenchmarkFlags
4447
, configureExOptions
4548
, reconfigureCommand
4649
, installCommand
@@ -87,7 +90,9 @@ module Distribution.Client.Setup
8790
, haddockCommand
8891
, cleanCommand
8992
, copyCommand
93+
, filterCopyFlags
9094
, registerCommand
95+
, filterRegisterFlags
9196
, liftOptions
9297
, yesNoOpt
9398
) where
@@ -183,7 +188,7 @@ import Distribution.Simple.InstallDirs
183188
)
184189
import Distribution.Simple.Program (ProgramDb, defaultProgramDb)
185190
import Distribution.Simple.Setup
186-
( BenchmarkFlags
191+
( BenchmarkFlags (benchmarkCommonFlags)
187192
, BooleanFlag (..)
188193
, BuildFlags (..)
189194
, CleanFlags (..)
@@ -192,7 +197,7 @@ import Distribution.Simple.Setup
192197
, CopyFlags (..)
193198
, HaddockFlags (..)
194199
, RegisterFlags (..)
195-
, ReplFlags
200+
, ReplFlags (..)
196201
, TestFlags
197202
, boolOpt
198203
, boolOpt'
@@ -1144,6 +1149,21 @@ buildCommand =
11441149
where
11451150
parent = Cabal.buildCommand defaultProgramDb
11461151

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

11491169
-- * Test flags
@@ -1236,6 +1256,21 @@ replCommand =
12361256
where
12371257
parent = Cabal.replCommand defaultProgramDb
12381258

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

12411276
-- * Test command
@@ -1331,6 +1366,21 @@ benchmarkCommand =
13311366
parent = Cabal.benchmarkCommand
13321367
progDb = defaultProgramDb
13331368

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

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

2457+
-- | Given some 'HaddockFlags' for the version of @Cabal@ that
2458+
-- @cabal-install@ was built with, and a target older 'Version' of
2459+
-- @Cabal@ that we want to pass these flags to, convert the
2460+
-- flags into a form that will be accepted by the older
2461+
-- @Setup@ script. Generally speaking, this just means filtering
2462+
-- out flags that the old @Cabal@ library doesn't understand, but
2463+
-- in some cases it may also mean "emulating" a feature using
2464+
-- some more legacy flags.
24072465
filterHaddockFlags :: HaddockFlags -> Version -> HaddockFlags
2408-
filterHaddockFlags flags cabalLibVersion =
2409-
let flags' = filterHaddockFlags' flags cabalLibVersion
2410-
in flags'
2411-
{ haddockCommonFlags =
2412-
filterCommonFlags (haddockCommonFlags flags') cabalLibVersion
2413-
}
2414-
2415-
filterHaddockFlags' :: HaddockFlags -> Version -> HaddockFlags
2416-
filterHaddockFlags' flags cabalLibVersion
2466+
filterHaddockFlags flags cabalLibVersion
24172467
| cabalLibVersion >= mkVersion [2, 3, 0] = flags_latest
24182468
| cabalLibVersion < mkVersion [2, 3, 0] = flags_2_3_0
24192469
| otherwise = flags_latest
24202470
where
2421-
flags_latest = flags
2471+
flags_latest =
2472+
flags
2473+
{ haddockCommonFlags =
2474+
filterCommonFlags (haddockCommonFlags flags) cabalLibVersion
2475+
}
24222476

24232477
flags_2_3_0 =
24242478
flags_latest
@@ -2490,6 +2544,9 @@ testOptions showOrParseArgs =
24902544
| "test-" `isPrefixOf` name = name
24912545
| otherwise = "test-" ++ name
24922546

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

3377+
-- | Given some 'RegisterFlags' for the version of @Cabal@ that
3378+
-- @cabal-install@ was built with, and a target older 'Version' of
3379+
-- @Cabal@ that we want to pass these flags to, convert the
3380+
-- flags into a form that will be accepted by the older
3381+
-- @Setup@ script. Generally speaking, this just means filtering
3382+
-- out flags that the old @Cabal@ library doesn't understand, but
3383+
-- in some cases it may also mean "emulating" a feature using
3384+
-- some more legacy flags.
3385+
filterRegisterFlags :: RegisterFlags -> Version -> RegisterFlags
3386+
filterRegisterFlags flags cabalLibVersion =
3387+
flags
3388+
{ registerCommonFlags =
3389+
filterCommonFlags (registerCommonFlags flags) cabalLibVersion
3390+
}
3391+
3392+
-- | Given some 'CopyFlags' for the version of @Cabal@ that
3393+
-- @cabal-install@ was built with, and a target older 'Version' of
3394+
-- @Cabal@ that we want to pass these flags to, convert the
3395+
-- flags into a form that will be accepted by the older
3396+
-- @Setup@ script. Generally speaking, this just means filtering
3397+
-- out flags that the old @Cabal@ library doesn't understand, but
3398+
-- in some cases it may also mean "emulating" a feature using
3399+
-- some more legacy flags.
3400+
filterCopyFlags :: CopyFlags -> Version -> CopyFlags
3401+
filterCopyFlags flags cabalLibVersion =
3402+
flags
3403+
{ copyCommonFlags = filterCommonFlags (copyCommonFlags flags) cabalLibVersion
3404+
}
3405+
33203406
-- ------------------------------------------------------------
33213407

33223408
-- * ActAsSetup flags

0 commit comments

Comments
 (0)