Merge pull request #10525 from 9999years/field-stanza-names
[cabal.git] / cabal-install / src / Distribution / Client / Setup.hs
blob446bbbedaab9d2b76fca4764a9410fb38d71bcd7
1 {-# LANGUAGE DeriveGeneric #-}
2 {-# LANGUAGE LambdaCase #-}
3 {-# LANGUAGE RankNTypes #-}
4 {-# LANGUAGE RecordWildCards #-}
5 {-# LANGUAGE ScopedTypeVariables #-}
7 -----------------------------------------------------------------------------
9 -----------------------------------------------------------------------------
11 -- |
12 -- Module : Distribution.Client.Setup
13 -- Copyright : (c) David Himmelstrup 2005
14 -- License : BSD-like
16 -- Maintainer : lemmih@gmail.com
17 -- Stability : provisional
18 -- Portability : portable
19 module Distribution.Client.Setup
20 ( globalCommand
21 , GlobalFlags (..)
22 , defaultGlobalFlags
23 , RepoContext (..)
24 , withRepoContext
25 , configureCommand
26 , CommonSetupFlags (..)
27 , ConfigFlags (..)
28 , configureOptions
29 , filterCommonFlags
30 , filterConfigureFlags
31 , configPackageDB'
32 , configCompilerAux'
33 , configureExCommand
34 , ConfigExFlags (..)
35 , defaultConfigExFlags
36 , buildCommand
37 , BuildFlags (..)
38 , filterBuildFlags
39 , filterTestFlags
40 , replCommand
41 , filterReplFlags
42 , testCommand
43 , benchmarkCommand
44 , testOptions
45 , benchmarkOptions
46 , filterBenchmarkFlags
47 , configureExOptions
48 , reconfigureCommand
49 , installCommand
50 , InstallFlags (..)
51 , installOptions
52 , defaultInstallFlags
53 , filterHaddockArgs
54 , filterHaddockFlags
55 , haddockOptions
56 , defaultSolver
57 , defaultMaxBackjumps
58 , listCommand
59 , ListFlags (..)
60 , listNeedsCompiler
61 , UpdateFlags (..)
62 , defaultUpdateFlags
63 , infoCommand
64 , InfoFlags (..)
65 , fetchCommand
66 , FetchFlags (..)
67 , freezeCommand
68 , FreezeFlags (..)
69 , genBoundsCommand
70 , getCommand
71 , unpackCommand
72 , GetFlags (..)
73 , checkCommand
74 , CheckFlags (..)
75 , formatCommand
76 , uploadCommand
77 , UploadFlags (..)
78 , IsCandidate (..)
79 , reportCommand
80 , ReportFlags (..)
81 , runCommand
82 , initCommand
83 , initOptions
84 , IT.InitFlags (..)
85 , actAsSetupCommand
86 , ActAsSetupFlags (..)
87 , userConfigCommand
88 , UserConfigFlags (..)
89 , manpageCommand
90 , haddockCommand
91 , cleanCommand
92 , copyCommand
93 , filterCopyFlags
94 , registerCommand
95 , filterRegisterFlags
96 , liftOptions
97 , yesNoOpt
98 ) where
100 import Distribution.Client.Compat.Prelude hiding (get)
101 import Prelude ()
103 import Distribution.Client.Types.AllowNewer (AllowNewer (..), AllowOlder (..), RelaxDeps (..))
104 import Distribution.Client.Types.Credentials (Password (..), Token (..), Username (..))
105 import Distribution.Client.Types.Repo (LocalRepo (..), RemoteRepo (..))
106 import Distribution.Client.Types.WriteGhcEnvironmentFilesPolicy
108 import Distribution.Client.BuildReports.Types
109 ( ReportLevel (..)
111 import Distribution.Client.Dependency.Types
112 ( PreSolver (..)
114 import Distribution.Client.IndexUtils.ActiveRepos
115 ( ActiveRepos
117 import Distribution.Client.IndexUtils.IndexState
118 ( TotalIndexState
119 , headTotalIndexState
121 import qualified Distribution.Client.Init.Defaults as IT
122 import qualified Distribution.Client.Init.Types as IT
123 import Distribution.Client.Targets
124 ( UserConstraint
125 , readUserConstraint
127 import Distribution.Deprecated.ParseUtils (parseSpaceList, parseTokenQ)
128 import Distribution.Deprecated.ReadP (readP_to_E)
129 import Distribution.Utils.NubList
130 ( NubList
131 , fromNubList
132 , toNubList
135 import Distribution.Solver.Types.ConstraintSource
136 import Distribution.Solver.Types.Settings
138 import Distribution.Client.GlobalFlags
139 ( GlobalFlags (..)
140 , RepoContext (..)
141 , defaultGlobalFlags
142 , withRepoContext
144 import Distribution.Client.ManpageFlags (ManpageFlags, defaultManpageFlags, manpageOptions)
145 import qualified Distribution.Compat.CharParsing as P
146 import Distribution.FieldGrammar.Newtypes (SpecVersion (..))
147 import Distribution.PackageDescription
148 ( BuildType (..)
149 , Dependency
150 , LibraryName (..)
151 , RepoKind (..)
153 import Distribution.PackageDescription.Check (CheckExplanationIDString)
154 import Distribution.Parsec
155 ( parsecCommaList
157 import Distribution.ReadE
158 ( ReadE (..)
159 , parsecToReadE
160 , parsecToReadEErr
161 , succeedReadE
162 , unexpectMsgString
164 import Distribution.Simple.Command hiding (boolOpt, boolOpt')
165 import qualified Distribution.Simple.Command as Command
166 import Distribution.Simple.Compiler (Compiler, PackageDB, PackageDBStack)
167 import Distribution.Simple.Configure
168 ( computeEffectiveProfiling
169 , configCompilerAuxEx
170 , interpretPackageDbFlags
172 import Distribution.Simple.Flag
173 ( Flag (..)
174 , flagElim
175 , flagToList
176 , flagToMaybe
177 , fromFlagOrDefault
178 , maybeToFlag
179 , mergeListFlag
180 , toFlag
182 import Distribution.Simple.InstallDirs
183 ( InstallDirs (..)
184 , PathTemplate
185 , combinePathTemplate
186 , fromPathTemplate
187 , toPathTemplate
189 import Distribution.Simple.Program (ProgramDb, defaultProgramDb)
190 import Distribution.Simple.Setup
191 ( BenchmarkFlags (benchmarkCommonFlags)
192 , BooleanFlag (..)
193 , BuildFlags (..)
194 , CleanFlags (..)
195 , CommonSetupFlags (..)
196 , ConfigFlags (..)
197 , CopyFlags (..)
198 , HaddockFlags (..)
199 , RegisterFlags (..)
200 , ReplFlags (..)
201 , TestFlags
202 , boolOpt
203 , boolOpt'
204 , falseArg
205 , optionVerbosity
206 , readPackageDbList
207 , showPackageDbList
208 , testCommonFlags
209 , trueArg
211 import qualified Distribution.Simple.Setup as Cabal
212 import Distribution.Simple.Utils
213 ( wrapText
215 import Distribution.System (Platform)
216 import Distribution.Types.GivenComponent
217 ( GivenComponent (..)
218 , PromisedComponent (..)
220 import Distribution.Types.PackageId
221 import Distribution.Types.PackageVersionConstraint
222 ( PackageVersionConstraint (..)
224 import Distribution.Types.UnqualComponentName
225 ( unqualComponentNameToPackageName
227 import Distribution.Verbosity
228 ( lessVerbose
229 , normal
230 , verboseNoFlags
231 , verboseNoTimestamp
233 import Distribution.Version
234 ( Version
235 , mkVersion
236 , nullVersion
239 import Control.Exception
240 ( assert
242 import Data.List
243 ( deleteFirstsBy
245 import System.FilePath
246 ( (</>)
249 globalCommand :: [Command action] -> CommandUI GlobalFlags
250 globalCommand commands =
251 CommandUI
252 { commandName = ""
253 , commandSynopsis =
254 "Command line interface to the Haskell Cabal infrastructure."
255 , commandUsage = \pname ->
256 "See http://www.haskell.org/cabal/ for more information.\n"
257 ++ "\n"
258 ++ "Usage: "
259 ++ pname
260 ++ " [GLOBAL FLAGS] [COMMAND [FLAGS]]\n"
261 , commandDescription = Just $ \pname ->
263 commands' = commands ++ [commandAddAction helpCommandUI undefined]
264 cmdDescs = getNormalCommandDescriptions commands'
265 -- if new commands are added, we want them to appear even if they
266 -- are not included in the custom listing below. Thus, we calculate
267 -- the `otherCmds` list and append it under the `other` category.
268 -- Alternatively, a new testcase could be added that ensures that
269 -- the set of commands listed here is equal to the set of commands
270 -- that are actually available.
271 otherCmds =
272 deleteFirstsBy
273 (==)
274 (map fst cmdDescs)
275 [ "help"
276 , "update"
277 , "install"
278 , "fetch"
279 , "list"
280 , "info"
281 , "user-config"
282 , "get"
283 , "unpack"
284 , "init"
285 , "configure"
286 , "build"
287 , "clean"
288 , "run"
289 , "repl"
290 , "test"
291 , "bench"
292 , "check"
293 , "sdist"
294 , "upload"
295 , "report"
296 , "freeze"
297 , "gen-bounds"
298 , "outdated"
299 , "haddock"
300 , "haddock-project"
301 , "hscolour"
302 , "exec"
303 , "path"
304 , "new-build"
305 , "new-configure"
306 , "new-repl"
307 , "new-freeze"
308 , "new-run"
309 , "new-test"
310 , "new-bench"
311 , "new-haddock"
312 , "new-exec"
313 , "new-update"
314 , "new-install"
315 , "new-clean"
316 , "new-sdist"
317 , "new-haddock-project"
318 , "list-bin"
319 , -- v1 commands, stateful style
320 "v1-build"
321 , "v1-configure"
322 , "v1-repl"
323 , "v1-freeze"
324 , "v1-run"
325 , "v1-test"
326 , "v1-bench"
327 , "v1-haddock"
328 , "v1-exec"
329 , "v1-update"
330 , "v1-install"
331 , "v1-clean"
332 , "v1-sdist"
333 , "v1-doctest"
334 , "v1-copy"
335 , "v1-register"
336 , "v1-reconfigure"
337 , -- v2 commands, nix-style
338 "v2-build"
339 , "v2-configure"
340 , "v2-repl"
341 , "v2-freeze"
342 , "v2-run"
343 , "v2-test"
344 , "v2-bench"
345 , "v2-haddock"
346 , "v2-haddock-project"
347 , "v2-exec"
348 , "v2-update"
349 , "v2-install"
350 , "v2-clean"
351 , "v2-sdist"
353 maxlen = maximum $ [length name | (name, _) <- cmdDescs]
354 align str = str ++ replicate (maxlen - length str) ' '
355 startGroup n = " [" ++ n ++ "]"
356 par = ""
357 addCmd n = case lookup n cmdDescs of
358 Nothing -> ""
359 Just d -> " " ++ align n ++ " " ++ d
361 "Commands:\n"
362 ++ unlines
363 ( [ startGroup "global"
364 , addCmd "user-config"
365 , addCmd "help"
366 , par
367 , startGroup "package database"
368 , addCmd "update"
369 , addCmd "list"
370 , addCmd "info"
371 , par
372 , startGroup "initialization and download"
373 , addCmd "init"
374 , addCmd "fetch"
375 , addCmd "get"
376 , par
377 , startGroup "project configuration"
378 , addCmd "configure"
379 , addCmd "freeze"
380 , addCmd "gen-bounds"
381 , addCmd "outdated"
382 , addCmd "path"
383 , par
384 , startGroup "project building and installing"
385 , addCmd "build"
386 , addCmd "install"
387 , addCmd "haddock"
388 , addCmd "haddock-project"
389 , addCmd "clean"
390 , par
391 , startGroup "running and testing"
392 , addCmd "list-bin"
393 , addCmd "repl"
394 , addCmd "run"
395 , addCmd "bench"
396 , addCmd "test"
397 , addCmd "exec"
398 , par
399 , startGroup "sanity checks and shipping"
400 , addCmd "check"
401 , addCmd "sdist"
402 , addCmd "upload"
403 , addCmd "report"
404 , par
405 , startGroup "deprecated"
406 , addCmd "unpack"
407 , addCmd "hscolour"
408 , par
409 , startGroup "new-style projects (forwards-compatible aliases)"
410 , addCmd "v2-build"
411 , addCmd "v2-configure"
412 , addCmd "v2-repl"
413 , addCmd "v2-run"
414 , addCmd "v2-test"
415 , addCmd "v2-bench"
416 , addCmd "v2-freeze"
417 , addCmd "v2-haddock"
418 , addCmd "v2-exec"
419 , addCmd "v2-update"
420 , addCmd "v2-install"
421 , addCmd "v2-clean"
422 , addCmd "v2-sdist"
423 , par
424 , startGroup "legacy command aliases"
425 , addCmd "v1-build"
426 , addCmd "v1-configure"
427 , addCmd "v1-repl"
428 , addCmd "v1-run"
429 , addCmd "v1-test"
430 , addCmd "v1-bench"
431 , addCmd "v1-freeze"
432 , addCmd "v1-haddock"
433 , addCmd "v1-install"
434 , addCmd "v1-clean"
435 , addCmd "v1-copy"
436 , addCmd "v1-register"
437 , addCmd "v1-reconfigure"
439 ++ if null otherCmds
440 then []
441 else
443 : startGroup "other"
444 : [addCmd n | n <- otherCmds]
446 ++ "\n"
447 ++ "For more information about a command use:\n"
448 ++ " "
449 ++ pname
450 ++ " COMMAND --help\n"
451 ++ "or "
452 ++ pname
453 ++ " help COMMAND\n"
454 ++ "\n"
455 ++ "To install Cabal packages from hackage use:\n"
456 ++ " "
457 ++ pname
458 ++ " install foo [--dry-run]\n"
459 ++ "\n"
460 ++ "Occasionally you need to update the list of available packages:\n"
461 ++ " "
462 ++ pname
463 ++ " update\n"
464 , commandNotes = Nothing
465 , commandDefaultFlags = mempty
466 , commandOptions = args
468 where
469 args :: ShowOrParseArgs -> [OptionField GlobalFlags]
470 args ShowArgs = argsShown
471 args ParseArgs = argsShown ++ argsNotShown
473 -- arguments we want to show in the help
474 argsShown :: [OptionField GlobalFlags]
475 argsShown =
476 [ option
477 ['V']
478 ["version"]
479 "Print version information"
480 globalVersion
481 (\v flags -> flags{globalVersion = v})
482 trueArg
483 , option
485 ["numeric-version"]
486 "Print just the version number"
487 globalNumericVersion
488 (\v flags -> flags{globalNumericVersion = v})
489 trueArg
490 , option
492 ["config-file"]
493 "Set an alternate location for the config file"
494 globalConfigFile
495 (\v flags -> flags{globalConfigFile = v})
496 (reqArgFlag "FILE")
497 , option
499 ["ignore-expiry"]
500 "Ignore expiry dates on signed metadata (use only in exceptional circumstances)"
501 globalIgnoreExpiry
502 (\v flags -> flags{globalIgnoreExpiry = v})
503 trueArg
504 , option
506 ["http-transport"]
507 "Set a transport for http(s) requests. Accepts 'curl', 'wget', 'powershell', and 'plain-http'. (default: 'curl')"
508 globalHttpTransport
509 (\v flags -> flags{globalHttpTransport = v})
510 (reqArgFlag "HttpTransport")
511 , multiOption
512 "nix"
513 globalNix
514 (\v flags -> flags{globalNix = v})
515 [ optArg'
516 "(True or False)"
517 (maybeToFlag . (readMaybe =<<))
518 ( \case
519 Flag True -> [Just "enable"]
520 Flag False -> [Just "disable"]
521 NoFlag -> []
524 ["nix"] -- Must be empty because we need to return PP.empty from viewAsFieldDescr
525 "[DEPRECATED] Nix integration: run commands through nix-shell if a 'shell.nix' file exists (default is False)"
526 , noArg
527 (Flag True)
529 ["enable-nix"]
530 "[DEPRECATED] Enable Nix integration: run commands through nix-shell if a 'shell.nix' file exists"
531 , noArg
532 (Flag False)
534 ["disable-nix"]
535 "[DEPRECATED] Disable Nix integration"
537 , option
539 ["store-dir", "storedir"]
540 "The location of the build store"
541 globalStoreDir
542 (\v flags -> flags{globalStoreDir = v})
543 (reqArgFlag "DIR")
544 , option
546 ["active-repositories"]
547 "The active package repositories (set to ':none' to disable all repositories)"
548 globalActiveRepos
549 (\v flags -> flags{globalActiveRepos = v})
550 ( reqArg
551 "REPOS"
552 ( parsecToReadE
553 (\err -> "Error parsing active-repositories: " ++ err)
554 (toFlag `fmap` parsec)
556 (map prettyShow . flagToList)
560 -- arguments we don't want shown in the help
561 -- the remote repo flags are not useful compared to the more general "active-repositories" flag.
562 -- the global logs directory was only used in v1, while in v2 we have specific project config logs dirs
563 -- default-user-config is support for a relatively obscure workflow for v1-freeze.
564 argsNotShown :: [OptionField GlobalFlags]
565 argsNotShown =
566 [ option
568 ["remote-repo"]
569 "The name and url for a remote repository"
570 globalRemoteRepos
571 (\v flags -> flags{globalRemoteRepos = v})
572 (reqArg' "NAME:URL" (toNubList . maybeToList . readRemoteRepo) (map showRemoteRepo . fromNubList))
573 , option
575 ["local-no-index-repo"]
576 "The name and a path for a local no-index repository"
577 globalLocalNoIndexRepos
578 (\v flags -> flags{globalLocalNoIndexRepos = v})
579 (reqArg' "NAME:PATH" (toNubList . maybeToList . readLocalRepo) (map showLocalRepo . fromNubList))
580 , option
582 ["remote-repo-cache"]
583 "The location where downloads from all remote repos are cached"
584 globalCacheDir
585 (\v flags -> flags{globalCacheDir = v})
586 (reqArgFlag "DIR")
587 , option
589 ["logs-dir", "logsdir"]
590 "The location to put log files"
591 globalLogsDir
592 (\v flags -> flags{globalLogsDir = v})
593 (reqArgFlag "DIR")
594 , option
596 ["default-user-config"]
597 "Set a location for a cabal.config file for projects without their own cabal.config freeze file."
598 globalConstraintsFile
599 (\v flags -> flags{globalConstraintsFile = v})
600 (reqArgFlag "FILE")
603 -- ------------------------------------------------------------
605 -- * Config flags
607 -- ------------------------------------------------------------
609 configureCommand :: CommandUI ConfigFlags
610 configureCommand =
612 { commandName = "configure"
613 , commandDefaultFlags = mempty
614 , commandDescription = Just $ \_ ->
615 wrapText $
616 "Configure how the package is built by setting "
617 ++ "package (and other) flags.\n"
618 ++ "\n"
619 ++ "The configuration affects several other commands, "
620 ++ "including v1-build, v1-test, v1-bench, v1-run, v1-repl.\n"
621 , commandUsage = \pname ->
622 "Usage: " ++ pname ++ " v1-configure [FLAGS]\n"
623 , commandNotes = Just $ \pname ->
624 (Cabal.programFlagsDescription defaultProgramDb ++ "\n")
625 ++ "Examples:\n"
626 ++ " "
627 ++ pname
628 ++ " v1-configure\n"
629 ++ " Configure with defaults;\n"
630 ++ " "
631 ++ pname
632 ++ " v1-configure --enable-tests -fcustomflag\n"
633 ++ " Configure building package including tests,\n"
634 ++ " with some package-specific flag.\n"
636 where
637 c = Cabal.configureCommand defaultProgramDb
639 configureOptions :: ShowOrParseArgs -> [OptionField ConfigFlags]
640 configureOptions = commandOptions configureCommand
642 filterCommonFlags :: CommonSetupFlags -> Version -> CommonSetupFlags
643 filterCommonFlags flags cabalLibVersion
644 -- NB: we expect the latest version to be the most common case,
645 -- so test it first.
646 | cabalLibVersion >= mkVersion [3, 13, 0] = flags_latest
647 | cabalLibVersion < mkVersion [1, 2, 5] = flags_1_2_5
648 | cabalLibVersion < mkVersion [2, 1, 0] = flags_2_1_0
649 | cabalLibVersion < mkVersion [3, 13, 0] = flags_3_13_0
650 | otherwise = error "the impossible just happened" -- see first guard
651 where
652 flags_latest = flags
653 flags_3_13_0 =
654 flags_latest
655 { -- Cabal < 3.13 does not support the --working-dir flag.
656 setupWorkingDir = NoFlag
657 , -- Or the --keep-temp-files flag.
658 setupKeepTempFiles = NoFlag
660 flags_2_1_0 =
661 flags_3_13_0
662 { -- Cabal < 2.1 doesn't know about -v +timestamp modifier
663 setupVerbosity = fmap verboseNoTimestamp (setupVerbosity flags_3_13_0)
665 flags_1_2_5 =
666 flags_2_1_0
667 { -- Cabal < 1.25 doesn't have extended verbosity syntax
668 setupVerbosity =
669 fmap verboseNoFlags (setupVerbosity flags_2_1_0)
672 -- | Given some 'ConfigFlags' for the version of Cabal that
673 -- cabal-install was built with, and a target older 'Version' of
674 -- Cabal that we want to pass these flags to, convert the
675 -- flags into a form that will be accepted by the older
676 -- Setup script. Generally speaking, this just means filtering
677 -- out flags that the old Cabal library doesn't understand, but
678 -- in some cases it may also mean "emulating" a feature using
679 -- some more legacy flags.
680 filterConfigureFlags :: ConfigFlags -> Version -> ConfigFlags
681 filterConfigureFlags flags cabalLibVersion =
682 let flags' = filterConfigureFlags' flags cabalLibVersion
683 in flags'
684 { configCommonFlags =
685 filterCommonFlags (configCommonFlags flags') cabalLibVersion
688 filterConfigureFlags' :: ConfigFlags -> Version -> ConfigFlags
689 filterConfigureFlags' flags cabalLibVersion
690 -- NB: we expect the latest version to be the most common case,
691 -- so test it first.
692 | cabalLibVersion >= mkVersion [3, 13, 0] = flags_latest
693 -- The naming convention is that flags_version gives flags with
694 -- all flags *introduced* in version eliminated.
695 -- It is NOT the latest version of Cabal library that
696 -- these flags work for; version of introduction is a more
697 -- natural metric.
698 | cabalLibVersion < mkVersion [1, 3, 10] = flags_1_3_10
699 | cabalLibVersion < mkVersion [1, 10, 0] = flags_1_10_0
700 | cabalLibVersion < mkVersion [1, 12, 0] = flags_1_12_0
701 | cabalLibVersion < mkVersion [1, 14, 0] = flags_1_14_0
702 | cabalLibVersion < mkVersion [1, 18, 0] = flags_1_18_0
703 | cabalLibVersion < mkVersion [1, 19, 1] = flags_1_19_1
704 | cabalLibVersion < mkVersion [1, 19, 2] = flags_1_19_2
705 | cabalLibVersion < mkVersion [1, 21, 1] = flags_1_21_1
706 | cabalLibVersion < mkVersion [1, 22, 0] = flags_1_22_0
707 | cabalLibVersion < mkVersion [1, 22, 1] = flags_1_22_1
708 | cabalLibVersion < mkVersion [1, 23, 0] = flags_1_23_0
709 | cabalLibVersion < mkVersion [1, 25, 0] = flags_1_25_0
710 | cabalLibVersion < mkVersion [2, 1, 0] = flags_2_1_0
711 | cabalLibVersion < mkVersion [2, 5, 0] = flags_2_5_0
712 | cabalLibVersion < mkVersion [3, 7, 0] = flags_3_7_0
713 | cabalLibVersion < mkVersion [3, 11, 0] = flags_3_11_0
714 | cabalLibVersion < mkVersion [3, 13, 0] = flags_3_13_0
715 | otherwise = error "the impossible just happened" -- see first guard
716 where
717 flags_latest =
718 flags
719 { -- Cabal >= 1.19.1 uses '--dependency' and does not need '--constraint'.
720 -- Note: this is not in the wrong place. configConstraints gets
721 -- repopulated in flags_1_19_1 but it needs to be set to empty for
722 -- newer versions first.
723 configConstraints = []
726 flags_3_13_0 =
727 let scrubVersion pc =
729 { promisedComponentPackage =
730 (promisedComponentPackage pc){pkgVersion = nullVersion}
732 in -- Earlier Cabal versions don't understand about ..
733 flags_latest
734 { -- Building profiled shared libraries
735 configProfShared = NoFlag
736 , configIgnoreBuildTools = NoFlag
737 , -- Older versions of Cabal don't include the package version in the
738 -- --promised-dependency flag, by setting the version to nullVersion,
739 -- it won't be printed.
740 configPromisedDependencies =
741 map scrubVersion (configPromisedDependencies flags)
744 flags_3_11_0 =
745 flags_3_13_0
746 { -- It's too late to convert configPromisedDependencies to anything
747 -- meaningful, so we just assert that it's empty.
748 -- We add a Cabal>=3.11 constraint before solving when multi-repl is
749 -- enabled, so this should never trigger.
750 configPromisedDependencies = assert (null $ configPromisedDependencies flags) []
751 , -- Cabal < 3.11 does not understand '--coverage-for', which is OK
752 -- because previous versions of Cabal using coverage implied
753 -- whole-package builds (cuz_coverage), and determine the path to
754 -- libraries mix dirs from the testsuite root with a small hack.
755 configCoverageFor = NoFlag
758 flags_3_7_0 =
759 flags_3_11_0
760 { -- Cabal < 3.7 does not know about --extra-lib-dirs-static
761 configExtraLibDirsStatic = []
762 , -- Cabal < 3.7 does not understand '--enable-build-info' or '--disable-build-info'
763 configDumpBuildInfo = NoFlag
766 flags_2_5_0 =
767 flags_3_7_0
768 { -- Cabal < 2.5 does not understand --dependency=pkg:component=cid
769 -- (public sublibraries), so we convert it to the legacy
770 -- --dependency=pkg_or_internal_component=cid
771 configDependencies =
772 let convertToLegacyInternalDep (GivenComponent _ (LSubLibName cn) cid) =
773 Just $
774 GivenComponent
775 (unqualComponentNameToPackageName cn)
776 LMainLibName
778 convertToLegacyInternalDep (GivenComponent pn LMainLibName cid) =
779 Just $ GivenComponent pn LMainLibName cid
780 in catMaybes $ convertToLegacyInternalDep <$> configDependencies flags
781 , -- Cabal < 2.5 doesn't know about '--allow-depending-on-private-libs'.
782 configAllowDependingOnPrivateLibs = NoFlag
783 , -- Cabal < 2.5 doesn't know about '--enable/disable-executable-static'.
784 configFullyStaticExe = NoFlag
787 flags_2_1_0 =
788 flags_2_5_0
789 { -- Cabal < 2.1 doesn't know about --<enable|disable>-static
790 configStaticLib = NoFlag
791 , configSplitSections = NoFlag
794 flags_1_25_0 =
795 flags_2_1_0
796 { -- Cabal < 1.25.0 doesn't know about --dynlibdir.
797 configInstallDirs = configInstallDirs_1_25_0
798 , -- Cabal < 1.25 doesn't support --deterministic
799 configDeterministic = mempty
801 configInstallDirs_1_25_0 =
802 let dirs = configInstallDirs flags
803 in dirs
804 { dynlibdir = NoFlag
805 , libexecsubdir = NoFlag
806 , libexecdir =
807 maybeToFlag $
808 combinePathTemplate
809 <$> flagToMaybe (libexecdir dirs)
810 <*> flagToMaybe (libexecsubdir dirs)
812 -- Cabal < 1.23 doesn't know about '--profiling-detail'.
813 -- Cabal < 1.23 has a hacked up version of 'enable-profiling'
814 -- which we shouldn't use.
815 (tryLibProfiling, _tryLibProfilingShared, tryExeProfiling) = computeEffectiveProfiling flags
816 flags_1_23_0 =
817 flags_1_25_0
818 { configProfDetail = NoFlag
819 , configProfLibDetail = NoFlag
820 , configIPID = NoFlag
821 , configProf = NoFlag
822 , configProfExe = Flag tryExeProfiling
823 , configProfLib = Flag tryLibProfiling
826 -- Cabal == 1.22.0.* had a discontinuity (see #5946 or e9a8d48a3adce34d)
827 -- due to temporary amnesia of the --*-executable-profiling flags
828 flags_1_22_1 =
829 flags_1_23_0
830 { configDebugInfo = NoFlag
831 , configProfExe = NoFlag
834 -- Cabal < 1.22 doesn't know about '--disable-debug-info'.
835 flags_1_22_0 = flags_1_23_0{configDebugInfo = NoFlag}
837 -- Cabal < 1.21.1 doesn't know about 'disable-relocatable'
838 -- Cabal < 1.21.1 doesn't know about 'enable-profiling'
839 -- (but we already dealt with it in flags_1_23_0)
840 flags_1_21_1 =
841 flags_1_22_0
842 { configRelocatable = NoFlag
843 , configCoverage = NoFlag
844 , configLibCoverage = configCoverage flags
846 -- Cabal < 1.19.2 doesn't know about '--exact-configuration' and
847 -- '--enable-library-stripping'.
848 flags_1_19_2 =
849 flags_1_21_1
850 { configExactConfiguration = NoFlag
851 , configStripLibs = NoFlag
853 -- Cabal < 1.19.1 uses '--constraint' instead of '--dependency'.
854 flags_1_19_1 =
855 flags_1_19_2
856 { configDependencies = []
857 , configConstraints = configConstraints flags
859 -- Cabal < 1.18.0 doesn't know about --extra-prog-path and --sysconfdir.
860 flags_1_18_0 =
861 flags_1_19_1
862 { configProgramPathExtra = toNubList []
863 , configInstallDirs = configInstallDirs_1_18_0
865 configInstallDirs_1_18_0 = (configInstallDirs flags_1_19_1){sysconfdir = NoFlag}
866 -- Cabal < 1.14.0 doesn't know about '--disable-benchmarks'.
867 flags_1_14_0 = flags_1_18_0{configBenchmarks = NoFlag}
868 -- Cabal < 1.12.0 doesn't know about '--enable/disable-executable-dynamic'
869 -- and '--enable/disable-library-coverage'.
870 flags_1_12_0 =
871 flags_1_14_0
872 { configLibCoverage = NoFlag
873 , configDynExe = NoFlag
875 -- Cabal < 1.10.0 doesn't know about '--disable-tests'.
876 flags_1_10_0 = flags_1_12_0{configTests = NoFlag}
877 -- Cabal < 1.3.10 does not grok the '--constraints' flag.
878 flags_1_3_10 = flags_1_10_0{configConstraints = []}
880 -- | Get the package database settings from 'ConfigFlags', accounting for
881 -- @--package-db@ and @--user@ flags.
882 configPackageDB' :: ConfigFlags -> PackageDBStack
883 configPackageDB' cfg =
884 interpretPackageDbFlags userInstall (configPackageDBs cfg)
885 where
886 userInstall = Cabal.fromFlagOrDefault True (configUserInstall cfg)
888 -- | Configure the compiler, but reduce verbosity during this step.
889 configCompilerAux' :: ConfigFlags -> IO (Compiler, Platform, ProgramDb)
890 configCompilerAux' configFlags = do
891 let commonFlags = configCommonFlags configFlags
892 configCompilerAuxEx
893 configFlags
894 { -- FIXME: make configCompilerAux use a sensible verbosity
895 configCommonFlags =
896 commonFlags
897 { setupVerbosity = fmap lessVerbose (setupVerbosity commonFlags)
901 -- ------------------------------------------------------------
903 -- * Config extra flags
905 -- ------------------------------------------------------------
907 -- | cabal configure takes some extra flags beyond runghc Setup configure
908 data ConfigExFlags = ConfigExFlags
909 { configCabalVersion :: Flag Version
910 , configAppend :: Flag Bool
911 , configBackup :: Flag Bool
912 , configExConstraints :: [(UserConstraint, ConstraintSource)]
913 , configPreferences :: [PackageVersionConstraint]
914 , configSolver :: Flag PreSolver
915 , configAllowNewer :: Maybe AllowNewer
916 , configAllowOlder :: Maybe AllowOlder
917 , configWriteGhcEnvironmentFilesPolicy
918 :: Flag WriteGhcEnvironmentFilesPolicy
920 deriving (Eq, Show, Generic)
922 defaultConfigExFlags :: ConfigExFlags
923 defaultConfigExFlags = mempty{configSolver = Flag defaultSolver}
925 configureExCommand :: CommandUI (ConfigFlags, ConfigExFlags)
926 configureExCommand =
927 configureCommand
928 { commandDefaultFlags = (mempty, defaultConfigExFlags)
929 , commandOptions = \showOrParseArgs ->
930 liftOptions
932 setFst
933 ( filter
934 ( (`notElem` ["constraint", "dependency", "promised-dependency", "exact-configuration"])
935 . optionName
937 $ configureOptions showOrParseArgs
939 ++ liftOptions
941 setSnd
942 (configureExOptions showOrParseArgs ConstraintSourceCommandlineFlag)
944 where
945 setFst a (_, b) = (a, b)
946 setSnd b (a, _) = (a, b)
948 configureExOptions
949 :: ShowOrParseArgs
950 -> ConstraintSource
951 -> [OptionField ConfigExFlags]
952 configureExOptions _showOrParseArgs src =
953 [ option
955 ["cabal-lib-version"]
956 ( "Select which version of the Cabal lib to use to build packages "
957 ++ "(useful for testing)."
959 configCabalVersion
960 (\v flags -> flags{configCabalVersion = v})
961 ( reqArg
962 "VERSION"
963 ( parsecToReadE
964 ("Cannot parse cabal lib version: " ++)
965 (fmap toFlag parsec)
967 (map prettyShow . flagToList)
969 , option
971 ["append"]
972 "appending the new config to the old config file"
973 configAppend
974 (\v flags -> flags{configAppend = v})
975 (boolOpt [] [])
976 , option
978 ["backup"]
979 "the backup of the config file before any alterations"
980 configBackup
981 (\v flags -> flags{configBackup = v})
982 (boolOpt [] [])
983 , option
985 ["constraint"]
986 "Specify constraints on a package (version, installed/source, flags)"
987 configExConstraints
988 (\v flags -> flags{configExConstraints = v})
989 ( reqArg
990 "CONSTRAINT"
991 ((\x -> [(x, src)]) `fmap` ReadE readUserConstraint)
992 (map $ prettyShow . fst)
994 , option
996 ["preference"]
997 "Specify preferences (soft constraints) on the version of a package"
998 configPreferences
999 (\v flags -> flags{configPreferences = v})
1000 ( reqArg
1001 "CONSTRAINT"
1002 ( parsecToReadE
1003 (const "dependency expected")
1004 (fmap (\x -> [x]) parsec)
1006 (map prettyShow)
1008 , optionSolver configSolver (\v flags -> flags{configSolver = v})
1009 , option
1011 ["allow-older"]
1012 ("Ignore lower bounds in all dependencies or DEPS")
1013 (fmap unAllowOlder . configAllowOlder)
1014 (\v flags -> flags{configAllowOlder = fmap AllowOlder v})
1015 ( optArg
1016 "DEPS"
1017 (parsecToReadEErr unexpectMsgString relaxDepsParser)
1018 (show RelaxDepsAll, Just RelaxDepsAll)
1019 relaxDepsPrinter
1021 , option
1023 ["allow-newer"]
1024 ("Ignore upper bounds in all dependencies or DEPS")
1025 (fmap unAllowNewer . configAllowNewer)
1026 (\v flags -> flags{configAllowNewer = fmap AllowNewer v})
1027 ( optArg
1028 "DEPS"
1029 (parsecToReadEErr unexpectMsgString relaxDepsParser)
1030 (show RelaxDepsAll, Just RelaxDepsAll)
1031 relaxDepsPrinter
1033 , option
1035 ["write-ghc-environment-files"]
1036 ( "Whether to create a .ghc.environment file after a successful build"
1037 ++ " (v2-build only)"
1039 configWriteGhcEnvironmentFilesPolicy
1040 (\v flags -> flags{configWriteGhcEnvironmentFilesPolicy = v})
1041 ( reqArg
1042 "always|never|ghc8.4.4+"
1043 writeGhcEnvironmentFilesPolicyParser
1044 writeGhcEnvironmentFilesPolicyPrinter
1048 writeGhcEnvironmentFilesPolicyParser :: ReadE (Flag WriteGhcEnvironmentFilesPolicy)
1049 writeGhcEnvironmentFilesPolicyParser = ReadE $ \case
1050 "always" -> Right $ Flag AlwaysWriteGhcEnvironmentFiles
1051 "never" -> Right $ Flag NeverWriteGhcEnvironmentFiles
1052 "ghc8.4.4+" -> Right $ Flag WriteGhcEnvironmentFilesOnlyForGhc844AndNewer
1053 policy ->
1054 Left $
1055 "Cannot parse the GHC environment file write policy '"
1056 <> policy
1057 <> "'"
1059 writeGhcEnvironmentFilesPolicyPrinter
1060 :: Flag WriteGhcEnvironmentFilesPolicy -> [String]
1061 writeGhcEnvironmentFilesPolicyPrinter = \case
1062 (Flag AlwaysWriteGhcEnvironmentFiles) -> ["always"]
1063 (Flag NeverWriteGhcEnvironmentFiles) -> ["never"]
1064 (Flag WriteGhcEnvironmentFilesOnlyForGhc844AndNewer) -> ["ghc8.4.4+"]
1065 NoFlag -> []
1067 relaxDepsParser :: CabalParsing m => m (Maybe RelaxDeps)
1068 relaxDepsParser = do
1069 rs <- P.sepBy parsec (P.char ',')
1070 if null rs
1071 then
1072 fail $
1073 "empty argument list is not allowed. "
1074 ++ "Note: use --allow-newer without the equals sign to permit all "
1075 ++ "packages to use newer versions."
1076 else return . Just . RelaxDepsSome . toList $ rs
1078 relaxDepsPrinter :: (Maybe RelaxDeps) -> [Maybe String]
1079 relaxDepsPrinter Nothing = []
1080 relaxDepsPrinter (Just RelaxDepsAll) = [Nothing]
1081 relaxDepsPrinter (Just (RelaxDepsSome pkgs)) = map (Just . prettyShow) $ pkgs
1083 instance Monoid ConfigExFlags where
1084 mempty = gmempty
1085 mappend = (<>)
1087 instance Semigroup ConfigExFlags where
1088 (<>) = gmappend
1090 reconfigureCommand :: CommandUI (ConfigFlags, ConfigExFlags)
1091 reconfigureCommand =
1092 configureExCommand
1093 { commandName = "reconfigure"
1094 , commandSynopsis = "Reconfigure the package if necessary."
1095 , commandDescription = Just $ \pname ->
1096 wrapText $
1097 "Run `configure` with the most recently used flags, or append FLAGS "
1098 ++ "to the most recently used configuration. "
1099 ++ "Accepts the same flags as `"
1100 ++ pname
1101 ++ " v1-configure'. "
1102 ++ "If the package has never been configured, the default flags are "
1103 ++ "used."
1104 , commandNotes = Just $ \pname ->
1105 "Examples:\n"
1106 ++ " "
1107 ++ pname
1108 ++ " v1-reconfigure\n"
1109 ++ " Configure with the most recently used flags.\n"
1110 ++ " "
1111 ++ pname
1112 ++ " v1-reconfigure -w PATH\n"
1113 ++ " Reconfigure with the most recently used flags,\n"
1114 ++ " but use the compiler at PATH.\n\n"
1115 , commandUsage = usageAlternatives "v1-reconfigure" ["[FLAGS]"]
1116 , commandDefaultFlags = mempty
1119 -- ------------------------------------------------------------
1121 -- * Build flags
1123 -- ------------------------------------------------------------
1125 buildCommand :: CommandUI BuildFlags
1126 buildCommand =
1127 parent
1128 { commandName = "build"
1129 , commandDescription = Just $ \_ ->
1130 wrapText $
1131 "Components encompass executables, tests, and benchmarks.\n"
1132 ++ "\n"
1133 ++ "Affected by configuration options, see `v1-configure`.\n"
1134 , commandDefaultFlags = commandDefaultFlags parent
1135 , commandUsage =
1136 usageAlternatives "v1-build" $
1137 ["[FLAGS]", "COMPONENTS [FLAGS]"]
1138 , commandOptions = commandOptions parent
1139 , commandNotes = Just $ \pname ->
1140 "Examples:\n"
1141 ++ " "
1142 ++ pname
1143 ++ " v1-build "
1144 ++ " All the components in the package\n"
1145 ++ " "
1146 ++ pname
1147 ++ " v1-build foo "
1148 ++ " A component (i.e. lib, exe, test suite)\n\n"
1149 ++ Cabal.programFlagsDescription defaultProgramDb
1151 where
1152 parent = Cabal.buildCommand defaultProgramDb
1154 -- | Given some 'BuildFlags' for the version of @Cabal@ that
1155 -- @cabal-install@ was built with, and a target older 'Version' of
1156 -- @Cabal@ that we want to pass these flags to, convert the
1157 -- flags into a form that will be accepted by the older
1158 -- @Setup@ script. Generally speaking, this just means filtering
1159 -- out flags that the old @Cabal@ library doesn't understand, but
1160 -- in some cases it may also mean "emulating" a feature using
1161 -- some more legacy flags.
1162 filterBuildFlags :: BuildFlags -> Version -> BuildFlags
1163 filterBuildFlags flags cabalLibVersion =
1164 flags
1165 { buildCommonFlags =
1166 filterCommonFlags (buildCommonFlags flags) cabalLibVersion
1169 -- ------------------------------------------------------------
1171 -- * Test flags
1173 -- ------------------------------------------------------------
1175 -- | Given some 'TestFlags' for the version of Cabal that
1176 -- cabal-install was built with, and a target older 'Version' of
1177 -- Cabal that we want to pass these flags to, convert the
1178 -- flags into a form that will be accepted by the older
1179 -- Setup script. Generally speaking, this just means filtering
1180 -- out flags that the old Cabal library doesn't understand, but
1181 -- in some cases it may also mean "emulating" a feature using
1182 -- some more legacy flags.
1183 filterTestFlags :: TestFlags -> Version -> TestFlags
1184 filterTestFlags flags cabalLibVersion =
1185 let flags' = filterTestFlags' flags cabalLibVersion
1186 in flags'
1187 { testCommonFlags =
1188 filterCommonFlags (testCommonFlags flags') cabalLibVersion
1191 filterTestFlags' :: TestFlags -> Version -> TestFlags
1192 filterTestFlags' flags cabalLibVersion
1193 -- NB: we expect the latest version to be the most common case,
1194 -- so test it first.
1195 | cabalLibVersion >= mkVersion [3, 0, 0] = flags_latest
1196 -- The naming convention is that flags_version gives flags with
1197 -- all flags *introduced* in version eliminated.
1198 -- It is NOT the latest version of Cabal library that
1199 -- these flags work for; version of introduction is a more
1200 -- natural metric.
1201 | cabalLibVersion < mkVersion [3, 0, 0] = flags_3_0_0
1202 | otherwise = error "the impossible just happened" -- see first guard
1203 where
1204 flags_latest = flags
1205 flags_3_0_0 =
1206 flags_latest
1207 { -- Cabal < 3.0 doesn't know about --test-wrapper
1208 Cabal.testWrapper = NoFlag
1211 -- ------------------------------------------------------------
1213 -- * Repl command
1215 -- ------------------------------------------------------------
1217 replCommand :: CommandUI ReplFlags
1218 replCommand =
1219 parent
1220 { commandName = "repl"
1221 , commandDescription = Just $ \pname ->
1222 wrapText $
1223 "If the current directory contains no package, ignores COMPONENT "
1224 ++ "parameters and opens an interactive interpreter session;\n"
1225 ++ "\n"
1226 ++ "Otherwise, (re)configures with the given or default flags, and "
1227 ++ "loads the interpreter with the relevant modules. For executables, "
1228 ++ "tests and benchmarks, loads the main module (and its "
1229 ++ "dependencies); for libraries all exposed/other modules.\n"
1230 ++ "\n"
1231 ++ "The default component is the library itself, or the executable "
1232 ++ "if that is the only component.\n"
1233 ++ "\n"
1234 ++ "Support for loading specific modules is planned but not "
1235 ++ "implemented yet. For certain scenarios, `"
1236 ++ pname
1237 ++ " v1-exec -- ghci :l Foo` may be used instead. Note that `v1-exec` will "
1238 ++ "not (re)configure and you will have to specify the location of "
1239 ++ "other modules, if required.\n"
1240 , commandUsage = \pname -> "Usage: " ++ pname ++ " v1-repl [COMPONENT] [FLAGS]\n"
1241 , commandDefaultFlags = commandDefaultFlags parent
1242 , commandOptions = commandOptions parent
1243 , commandNotes = Just $ \pname ->
1244 "Examples:\n"
1245 ++ " "
1246 ++ pname
1247 ++ " v1-repl "
1248 ++ " The first component in the package\n"
1249 ++ " "
1250 ++ pname
1251 ++ " v1-repl foo "
1252 ++ " A named component (i.e. lib, exe, test suite)\n"
1253 ++ " "
1254 ++ pname
1255 ++ " v1-repl --ghc-options=\"-lstdc++\""
1256 ++ " Specifying flags for interpreter\n"
1258 where
1259 parent = Cabal.replCommand defaultProgramDb
1261 -- | Given some 'ReplFlags' for the version of @Cabal@ that
1262 -- @cabal-install@ was built with, and a target older 'Version' of
1263 -- @Cabal@ that we want to pass these flags to, convert the
1264 -- flags into a form that will be accepted by the older
1265 -- @Setup@ script. Generally speaking, this just means filtering
1266 -- out flags that the old @Cabal@ library doesn't understand, but
1267 -- in some cases it may also mean "emulating" a feature using
1268 -- some more legacy flags.
1269 filterReplFlags :: ReplFlags -> Version -> ReplFlags
1270 filterReplFlags flags cabalLibVersion =
1271 flags
1272 { replCommonFlags =
1273 (filterCommonFlags (replCommonFlags flags) cabalLibVersion)
1274 { -- `cabal repl` knew about `--keep-temp-files` before other commands did.
1275 setupKeepTempFiles = setupKeepTempFiles (replCommonFlags flags)
1279 -- ------------------------------------------------------------
1281 -- * Test command
1283 -- ------------------------------------------------------------
1285 testCommand :: CommandUI (BuildFlags, TestFlags)
1286 testCommand =
1287 parent
1288 { commandName = "test"
1289 , commandDescription = Just $ \pname ->
1290 wrapText $
1291 "If necessary (re)configures with `--enable-tests` flag and builds"
1292 ++ " the test suite.\n"
1293 ++ "\n"
1294 ++ "Remember that the tests' dependencies must be installed if there"
1295 ++ " are additional ones; e.g. with `"
1296 ++ pname
1297 ++ " v1-install --only-dependencies --enable-tests`.\n"
1298 ++ "\n"
1299 ++ "By defining UserHooks in a custom Setup.hs, the package can"
1300 ++ " define actions to be executed before and after running tests.\n"
1301 , commandUsage =
1302 usageAlternatives
1303 "v1-test"
1304 ["[FLAGS]", "TESTCOMPONENTS [FLAGS]"]
1305 , commandDefaultFlags = (Cabal.defaultBuildFlags, commandDefaultFlags parent)
1306 , commandOptions =
1307 \showOrParseArgs ->
1308 liftOptions
1309 get1
1310 set1
1311 (Cabal.buildOptions progDb showOrParseArgs)
1312 ++ liftOptions
1313 get2
1314 set2
1315 (commandOptions parent showOrParseArgs)
1317 where
1318 get1 (a, _) = a
1319 set1 a (_, b) = (a, b)
1320 get2 (_, b) = b
1321 set2 b (a, _) = (a, b)
1323 parent = Cabal.testCommand
1324 progDb = defaultProgramDb
1326 -- ------------------------------------------------------------
1328 -- * Bench command
1330 -- ------------------------------------------------------------
1332 benchmarkCommand :: CommandUI (BuildFlags, BenchmarkFlags)
1333 benchmarkCommand =
1334 parent
1335 { commandName = "bench"
1336 , commandUsage =
1337 usageAlternatives
1338 "v1-bench"
1339 ["[FLAGS]", "BENCHCOMPONENTS [FLAGS]"]
1340 , commandDescription = Just $ \pname ->
1341 wrapText $
1342 "If necessary (re)configures with `--enable-benchmarks` flag and"
1343 ++ " builds the benchmarks.\n"
1344 ++ "\n"
1345 ++ "Remember that the benchmarks' dependencies must be installed if"
1346 ++ " there are additional ones; e.g. with `"
1347 ++ pname
1348 ++ " v1-install --only-dependencies --enable-benchmarks`.\n"
1349 ++ "\n"
1350 ++ "By defining UserHooks in a custom Setup.hs, the package can"
1351 ++ " define actions to be executed before and after running"
1352 ++ " benchmarks.\n"
1353 , commandDefaultFlags = (Cabal.defaultBuildFlags, commandDefaultFlags parent)
1354 , commandOptions =
1355 \showOrParseArgs ->
1356 liftOptions
1357 get1
1358 set1
1359 (Cabal.buildOptions progDb showOrParseArgs)
1360 ++ liftOptions
1361 get2
1362 set2
1363 (commandOptions parent showOrParseArgs)
1365 where
1366 get1 (a, _) = a
1367 set1 a (_, b) = (a, b)
1368 get2 (_, b) = b
1369 set2 b (a, _) = (a, b)
1371 parent = Cabal.benchmarkCommand
1372 progDb = defaultProgramDb
1374 -- | Given some 'BenchmarkFlags' for the version of @Cabal@ that
1375 -- @cabal-install@ was built with, and a target older 'Version' of
1376 -- @Cabal@ that we want to pass these flags to, convert the
1377 -- flags into a form that will be accepted by the older
1378 -- @Setup@ script. Generally speaking, this just means filtering
1379 -- out flags that the old @Cabal@ library doesn't understand, but
1380 -- in some cases it may also mean "emulating" a feature using
1381 -- some more legacy flags.
1382 filterBenchmarkFlags :: BenchmarkFlags -> Version -> BenchmarkFlags
1383 filterBenchmarkFlags flags cabalLibVersion =
1384 flags
1385 { benchmarkCommonFlags =
1386 filterCommonFlags (benchmarkCommonFlags flags) cabalLibVersion
1389 -- ------------------------------------------------------------
1391 -- * Fetch command
1393 -- ------------------------------------------------------------
1395 data FetchFlags = FetchFlags
1396 { -- fetchOutput :: Flag FilePath,
1397 fetchDeps :: Flag Bool
1398 , fetchDryRun :: Flag Bool
1399 , fetchSolver :: Flag PreSolver
1400 , fetchMaxBackjumps :: Flag Int
1401 , fetchReorderGoals :: Flag ReorderGoals
1402 , fetchCountConflicts :: Flag CountConflicts
1403 , fetchFineGrainedConflicts :: Flag FineGrainedConflicts
1404 , fetchMinimizeConflictSet :: Flag MinimizeConflictSet
1405 , fetchIndependentGoals :: Flag IndependentGoals
1406 , fetchPreferOldest :: Flag PreferOldest
1407 , fetchShadowPkgs :: Flag ShadowPkgs
1408 , fetchStrongFlags :: Flag StrongFlags
1409 , fetchAllowBootLibInstalls :: Flag AllowBootLibInstalls
1410 , fetchOnlyConstrained :: Flag OnlyConstrained
1411 , fetchTests :: Flag Bool
1412 , fetchBenchmarks :: Flag Bool
1413 , fetchVerbosity :: Flag Verbosity
1416 defaultFetchFlags :: FetchFlags
1417 defaultFetchFlags =
1418 FetchFlags
1419 { -- fetchOutput = mempty,
1420 fetchDeps = toFlag True
1421 , fetchDryRun = toFlag False
1422 , fetchSolver = Flag defaultSolver
1423 , fetchMaxBackjumps = Flag defaultMaxBackjumps
1424 , fetchReorderGoals = Flag (ReorderGoals False)
1425 , fetchCountConflicts = Flag (CountConflicts True)
1426 , fetchFineGrainedConflicts = Flag (FineGrainedConflicts True)
1427 , fetchMinimizeConflictSet = Flag (MinimizeConflictSet False)
1428 , fetchIndependentGoals = Flag (IndependentGoals False)
1429 , fetchPreferOldest = Flag (PreferOldest False)
1430 , fetchShadowPkgs = Flag (ShadowPkgs False)
1431 , fetchStrongFlags = Flag (StrongFlags False)
1432 , fetchAllowBootLibInstalls = Flag (AllowBootLibInstalls False)
1433 , fetchOnlyConstrained = Flag OnlyConstrainedNone
1434 , fetchTests = toFlag False
1435 , fetchBenchmarks = toFlag False
1436 , fetchVerbosity = toFlag normal
1439 fetchCommand :: CommandUI FetchFlags
1440 fetchCommand =
1441 CommandUI
1442 { commandName = "fetch"
1443 , commandSynopsis = "Downloads packages for later installation."
1444 , commandUsage =
1445 usageAlternatives
1446 "fetch"
1447 [ "[FLAGS] PACKAGES"
1449 , commandDescription = Just $ \_ ->
1450 "Note that it currently is not possible to fetch the dependencies for a\n"
1451 ++ "package in the current directory.\n"
1452 , commandNotes = Nothing
1453 , commandDefaultFlags = defaultFetchFlags
1454 , commandOptions = \showOrParseArgs ->
1455 [ optionVerbosity fetchVerbosity (\v flags -> flags{fetchVerbosity = v})
1456 , -- , option "o" ["output"]
1457 -- "Put the package(s) somewhere specific rather than the usual cache."
1458 -- fetchOutput (\v flags -> flags { fetchOutput = v })
1459 -- (reqArgFlag "PATH")
1461 option
1463 ["dependencies", "deps"]
1464 "Resolve and fetch dependencies (default)"
1465 fetchDeps
1466 (\v flags -> flags{fetchDeps = v})
1467 trueArg
1468 , option
1470 ["no-dependencies", "no-deps"]
1471 "Ignore dependencies"
1472 fetchDeps
1473 (\v flags -> flags{fetchDeps = v})
1474 falseArg
1475 , option
1477 ["dry-run"]
1478 "Do not install anything, only print what would be installed."
1479 fetchDryRun
1480 (\v flags -> flags{fetchDryRun = v})
1481 trueArg
1482 , option
1484 ["tests"]
1485 "dependency checking and compilation for test suites listed in the package description file."
1486 fetchTests
1487 (\v flags -> flags{fetchTests = v})
1488 (boolOpt [] [])
1489 , option
1491 ["benchmarks"]
1492 "dependency checking and compilation for benchmarks listed in the package description file."
1493 fetchBenchmarks
1494 (\v flags -> flags{fetchBenchmarks = v})
1495 (boolOpt [] [])
1497 ++ optionSolver fetchSolver (\v flags -> flags{fetchSolver = v})
1498 : optionSolverFlags
1499 showOrParseArgs
1500 fetchMaxBackjumps
1501 (\v flags -> flags{fetchMaxBackjumps = v})
1502 fetchReorderGoals
1503 (\v flags -> flags{fetchReorderGoals = v})
1504 fetchCountConflicts
1505 (\v flags -> flags{fetchCountConflicts = v})
1506 fetchFineGrainedConflicts
1507 (\v flags -> flags{fetchFineGrainedConflicts = v})
1508 fetchMinimizeConflictSet
1509 (\v flags -> flags{fetchMinimizeConflictSet = v})
1510 fetchIndependentGoals
1511 (\v flags -> flags{fetchIndependentGoals = v})
1512 fetchPreferOldest
1513 (\v flags -> flags{fetchPreferOldest = v})
1514 fetchShadowPkgs
1515 (\v flags -> flags{fetchShadowPkgs = v})
1516 fetchStrongFlags
1517 (\v flags -> flags{fetchStrongFlags = v})
1518 fetchAllowBootLibInstalls
1519 (\v flags -> flags{fetchAllowBootLibInstalls = v})
1520 fetchOnlyConstrained
1521 (\v flags -> flags{fetchOnlyConstrained = v})
1524 -- ------------------------------------------------------------
1526 -- * Freeze command
1528 -- ------------------------------------------------------------
1530 data FreezeFlags = FreezeFlags
1531 { freezeDryRun :: Flag Bool
1532 , freezeTests :: Flag Bool
1533 , freezeBenchmarks :: Flag Bool
1534 , freezeSolver :: Flag PreSolver
1535 , freezeMaxBackjumps :: Flag Int
1536 , freezeReorderGoals :: Flag ReorderGoals
1537 , freezeCountConflicts :: Flag CountConflicts
1538 , freezeFineGrainedConflicts :: Flag FineGrainedConflicts
1539 , freezeMinimizeConflictSet :: Flag MinimizeConflictSet
1540 , freezeIndependentGoals :: Flag IndependentGoals
1541 , freezePreferOldest :: Flag PreferOldest
1542 , freezeShadowPkgs :: Flag ShadowPkgs
1543 , freezeStrongFlags :: Flag StrongFlags
1544 , freezeAllowBootLibInstalls :: Flag AllowBootLibInstalls
1545 , freezeOnlyConstrained :: Flag OnlyConstrained
1546 , freezeVerbosity :: Flag Verbosity
1549 defaultFreezeFlags :: FreezeFlags
1550 defaultFreezeFlags =
1551 FreezeFlags
1552 { freezeDryRun = toFlag False
1553 , freezeTests = toFlag False
1554 , freezeBenchmarks = toFlag False
1555 , freezeSolver = Flag defaultSolver
1556 , freezeMaxBackjumps = Flag defaultMaxBackjumps
1557 , freezeReorderGoals = Flag (ReorderGoals False)
1558 , freezeCountConflicts = Flag (CountConflicts True)
1559 , freezeFineGrainedConflicts = Flag (FineGrainedConflicts True)
1560 , freezeMinimizeConflictSet = Flag (MinimizeConflictSet False)
1561 , freezeIndependentGoals = Flag (IndependentGoals False)
1562 , freezePreferOldest = Flag (PreferOldest False)
1563 , freezeShadowPkgs = Flag (ShadowPkgs False)
1564 , freezeStrongFlags = Flag (StrongFlags False)
1565 , freezeAllowBootLibInstalls = Flag (AllowBootLibInstalls False)
1566 , freezeOnlyConstrained = Flag OnlyConstrainedNone
1567 , freezeVerbosity = toFlag normal
1570 freezeCommand :: CommandUI FreezeFlags
1571 freezeCommand =
1572 CommandUI
1573 { commandName = "freeze"
1574 , commandSynopsis = "Freeze dependencies."
1575 , commandDescription = Just $ \_ ->
1576 wrapText $
1577 "Calculates a valid set of dependencies and their exact versions. "
1578 ++ "If successful, saves the result to the file `cabal.config`.\n"
1579 ++ "\n"
1580 ++ "The package versions specified in `cabal.config` will be used for "
1581 ++ "any future installs.\n"
1582 ++ "\n"
1583 ++ "An existing `cabal.config` is ignored and overwritten.\n"
1584 , commandNotes = Nothing
1585 , commandUsage = usageFlags "freeze"
1586 , commandDefaultFlags = defaultFreezeFlags
1587 , commandOptions = \showOrParseArgs ->
1588 [ optionVerbosity
1589 freezeVerbosity
1590 (\v flags -> flags{freezeVerbosity = v})
1591 , option
1593 ["dry-run"]
1594 "Do not freeze anything, only print what would be frozen"
1595 freezeDryRun
1596 (\v flags -> flags{freezeDryRun = v})
1597 trueArg
1598 , option
1600 ["tests"]
1601 ( "freezing of the dependencies of any tests suites "
1602 ++ "in the package description file."
1604 freezeTests
1605 (\v flags -> flags{freezeTests = v})
1606 (boolOpt [] [])
1607 , option
1609 ["benchmarks"]
1610 ( "freezing of the dependencies of any benchmarks suites "
1611 ++ "in the package description file."
1613 freezeBenchmarks
1614 (\v flags -> flags{freezeBenchmarks = v})
1615 (boolOpt [] [])
1617 ++ optionSolver
1618 freezeSolver
1619 (\v flags -> flags{freezeSolver = v})
1620 : optionSolverFlags
1621 showOrParseArgs
1622 freezeMaxBackjumps
1623 (\v flags -> flags{freezeMaxBackjumps = v})
1624 freezeReorderGoals
1625 (\v flags -> flags{freezeReorderGoals = v})
1626 freezeCountConflicts
1627 (\v flags -> flags{freezeCountConflicts = v})
1628 freezeFineGrainedConflicts
1629 (\v flags -> flags{freezeFineGrainedConflicts = v})
1630 freezeMinimizeConflictSet
1631 (\v flags -> flags{freezeMinimizeConflictSet = v})
1632 freezeIndependentGoals
1633 (\v flags -> flags{freezeIndependentGoals = v})
1634 freezePreferOldest
1635 (\v flags -> flags{freezePreferOldest = v})
1636 freezeShadowPkgs
1637 (\v flags -> flags{freezeShadowPkgs = v})
1638 freezeStrongFlags
1639 (\v flags -> flags{freezeStrongFlags = v})
1640 freezeAllowBootLibInstalls
1641 (\v flags -> flags{freezeAllowBootLibInstalls = v})
1642 freezeOnlyConstrained
1643 (\v flags -> flags{freezeOnlyConstrained = v})
1646 -- ------------------------------------------------------------
1648 -- * 'gen-bounds' command
1650 -- ------------------------------------------------------------
1652 genBoundsCommand :: CommandUI FreezeFlags
1653 genBoundsCommand =
1654 CommandUI
1655 { commandName = "gen-bounds"
1656 , commandSynopsis = "Generate dependency bounds."
1657 , commandDescription = Just $ \_ ->
1658 wrapText $
1659 "Generates bounds for all dependencies that do not currently have them. "
1660 ++ "Generated bounds are printed to stdout. "
1661 ++ "You can then paste them into your .cabal file.\n"
1662 ++ "\n"
1663 , commandNotes = Nothing
1664 , commandUsage = usageFlags "gen-bounds"
1665 , commandDefaultFlags = defaultFreezeFlags
1666 , commandOptions = \_ ->
1667 [ optionVerbosity freezeVerbosity (\v flags -> flags{freezeVerbosity = v})
1671 -- ------------------------------------------------------------
1672 -- Check command
1673 -- ------------------------------------------------------------
1675 data CheckFlags = CheckFlags
1676 { checkVerbosity :: Flag Verbosity
1677 , checkIgnore :: [CheckExplanationIDString]
1679 deriving (Show, Typeable)
1681 defaultCheckFlags :: CheckFlags
1682 defaultCheckFlags =
1683 CheckFlags
1684 { checkVerbosity = Flag normal
1685 , checkIgnore = []
1688 checkCommand :: CommandUI CheckFlags
1689 checkCommand =
1690 CommandUI
1691 { commandName = "check"
1692 , commandSynopsis = "Check the package for common mistakes."
1693 , commandDescription = Just $ \_ ->
1694 wrapText $
1695 "Expects a .cabal package file in the current directory.\n"
1696 ++ "\n"
1697 ++ "Some checks correspond to the requirements to packages on Hackage. "
1698 ++ "If no `Error` is reported, Hackage should accept the "
1699 ++ "package. If errors are present, `check` exits with 1 and Hackage "
1700 ++ "will refuse the package.\n"
1701 , commandNotes = Nothing
1702 , commandUsage = usageFlags "check"
1703 , commandDefaultFlags = defaultCheckFlags
1704 , commandOptions = checkOptions'
1707 checkOptions' :: ShowOrParseArgs -> [OptionField CheckFlags]
1708 checkOptions' _showOrParseArgs =
1709 [ optionVerbosity
1710 checkVerbosity
1711 (\v flags -> flags{checkVerbosity = v})
1712 , option
1713 ['i']
1714 ["ignore"]
1715 "ignore a specific warning (e.g. --ignore=missing-upper-bounds)"
1716 checkIgnore
1717 (\v c -> c{checkIgnore = v ++ checkIgnore c})
1718 (reqArg' "WARNING" (: []) (const []))
1721 -- ------------------------------------------------------------
1723 -- * Update command
1725 -- ------------------------------------------------------------
1727 data UpdateFlags = UpdateFlags
1728 { updateVerbosity :: Flag Verbosity
1729 , updateIndexState :: Flag TotalIndexState
1731 deriving (Generic)
1733 defaultUpdateFlags :: UpdateFlags
1734 defaultUpdateFlags =
1735 UpdateFlags
1736 { updateVerbosity = toFlag normal
1737 , updateIndexState = toFlag headTotalIndexState
1740 -- ------------------------------------------------------------
1742 -- * Other commands
1744 -- ------------------------------------------------------------
1746 cleanCommand :: CommandUI CleanFlags
1747 cleanCommand =
1748 Cabal.cleanCommand
1749 { commandUsage = \pname ->
1750 "Usage: " ++ pname ++ " v1-clean [FLAGS]\n"
1753 formatCommand :: CommandUI (Flag Verbosity)
1754 formatCommand =
1755 CommandUI
1756 { commandName = "format"
1757 , commandSynopsis = "Reformat the .cabal file using the standard style."
1758 , commandDescription = Nothing
1759 , commandNotes = Nothing
1760 , commandUsage = usageAlternatives "format" ["[FILE]"]
1761 , commandDefaultFlags = toFlag normal
1762 , commandOptions = \_ -> []
1765 manpageCommand :: CommandUI ManpageFlags
1766 manpageCommand =
1767 CommandUI
1768 { commandName = "man"
1769 , commandSynopsis = "Outputs manpage source."
1770 , commandDescription = Just $ \_ ->
1771 "Output manpage source to STDOUT.\n"
1772 , commandNotes = Nothing
1773 , commandUsage = usageFlags "man"
1774 , commandDefaultFlags = defaultManpageFlags
1775 , commandOptions = manpageOptions
1778 runCommand :: CommandUI BuildFlags
1779 runCommand =
1780 CommandUI
1781 { commandName = "run"
1782 , commandSynopsis = "Builds and runs an executable."
1783 , commandDescription = Just $ \pname ->
1784 wrapText $
1785 "Builds and then runs the specified executable. If no executable is "
1786 ++ "specified, but the package contains just one executable, that one "
1787 ++ "is built and executed.\n"
1788 ++ "\n"
1789 ++ "Use `"
1790 ++ pname
1791 ++ " v1-test --show-details=streaming` to run a "
1792 ++ "test-suite and get its full output.\n"
1793 , commandNotes = Just $ \pname ->
1794 "Examples:\n"
1795 ++ " "
1796 ++ pname
1797 ++ " v1-run\n"
1798 ++ " Run the only executable in the current package;\n"
1799 ++ " "
1800 ++ pname
1801 ++ " v1-run foo -- --fooflag\n"
1802 ++ " Works similar to `./foo --fooflag`.\n"
1803 , commandUsage =
1804 usageAlternatives
1805 "v1-run"
1806 ["[FLAGS] [EXECUTABLE] [-- EXECUTABLE_FLAGS]"]
1807 , commandDefaultFlags = mempty
1808 , commandOptions = commandOptions parent
1810 where
1811 parent = Cabal.buildCommand defaultProgramDb
1813 -- ------------------------------------------------------------
1815 -- * Report flags
1817 -- ------------------------------------------------------------
1819 data ReportFlags = ReportFlags
1820 { reportToken :: Flag Token
1821 , reportUsername :: Flag Username
1822 , reportPassword :: Flag Password
1823 , reportVerbosity :: Flag Verbosity
1825 deriving (Generic)
1827 defaultReportFlags :: ReportFlags
1828 defaultReportFlags =
1829 ReportFlags
1830 { reportToken = mempty
1831 , reportUsername = mempty
1832 , reportPassword = mempty
1833 , reportVerbosity = toFlag normal
1836 reportCommand :: CommandUI ReportFlags
1837 reportCommand =
1838 CommandUI
1839 { commandName = "report"
1840 , commandSynopsis = "Upload build reports to a remote server."
1841 , commandDescription = Nothing
1842 , commandNotes = Just $ \_ ->
1843 "You can store your Hackage login in the ~/.config/cabal/config file\n"
1844 ++ "(the %APPDATA%\\cabal\\config file on Windows)\n"
1845 , commandUsage = usageAlternatives "report" ["[FLAGS]"]
1846 , commandDefaultFlags = defaultReportFlags
1847 , commandOptions = \_ ->
1848 [ optionVerbosity reportVerbosity (\v flags -> flags{reportVerbosity = v})
1849 , option
1850 ['t']
1851 ["token"]
1852 "Hackage authentication Token."
1853 reportToken
1854 (\v flags -> flags{reportToken = v})
1855 ( reqArg'
1856 "TOKEN"
1857 (toFlag . Token)
1858 (flagToList . fmap unToken)
1860 , option
1861 ['u']
1862 ["username"]
1863 "Hackage username."
1864 reportUsername
1865 (\v flags -> flags{reportUsername = v})
1866 ( reqArg'
1867 "USERNAME"
1868 (toFlag . Username)
1869 (flagToList . fmap unUsername)
1871 , option
1872 ['p']
1873 ["password"]
1874 "Hackage password."
1875 reportPassword
1876 (\v flags -> flags{reportPassword = v})
1877 ( reqArg'
1878 "PASSWORD"
1879 (toFlag . Password)
1880 (flagToList . fmap unPassword)
1885 instance Monoid ReportFlags where
1886 mempty = gmempty
1887 mappend = (<>)
1889 instance Semigroup ReportFlags where
1890 (<>) = gmappend
1892 -- ------------------------------------------------------------
1894 -- * Get flags
1896 -- ------------------------------------------------------------
1898 data GetFlags = GetFlags
1899 { getDestDir :: Flag FilePath
1900 , getOnlyPkgDescr :: Flag Bool
1901 , getPristine :: Flag Bool
1902 , getIndexState :: Flag TotalIndexState
1903 , getActiveRepos :: Flag ActiveRepos
1904 , getSourceRepository :: Flag (Maybe RepoKind)
1905 , getVerbosity :: Flag Verbosity
1907 deriving (Generic)
1909 defaultGetFlags :: GetFlags
1910 defaultGetFlags =
1911 GetFlags
1912 { getDestDir = mempty
1913 , getOnlyPkgDescr = mempty
1914 , getPristine = mempty
1915 , getIndexState = mempty
1916 , getActiveRepos = mempty
1917 , getSourceRepository = mempty
1918 , getVerbosity = toFlag normal
1921 getCommand :: CommandUI GetFlags
1922 getCommand =
1923 CommandUI
1924 { commandName = "get"
1925 , commandSynopsis = "Download/Extract a package's source code (repository)."
1926 , commandDescription = Just $ \_ -> wrapText $ unlines descriptionOfGetCommand
1927 , commandNotes = Just $ \pname -> unlines $ notesOfGetCommand "get" pname
1928 , commandUsage = usagePackages "get"
1929 , commandDefaultFlags = defaultGetFlags
1930 , commandOptions = \_ ->
1931 [ optionVerbosity getVerbosity (\v flags -> flags{getVerbosity = v})
1932 , option
1934 ["destdir"]
1935 "Where to place the package source, defaults to the current directory."
1936 getDestDir
1937 (\v flags -> flags{getDestDir = v})
1938 (reqArgFlag "PATH")
1939 , option
1941 ["source-repository"]
1942 "Copy the package's source repository (ie git clone, darcs get, etc as appropriate)."
1943 getSourceRepository
1944 (\v flags -> flags{getSourceRepository = v})
1945 ( optArg
1946 "[head|this|...]"
1947 ( parsecToReadE
1948 (const "invalid source-repository")
1949 (fmap (toFlag . Just) parsec)
1951 ("", Flag Nothing)
1952 (map (fmap show) . flagToList)
1954 , option
1956 ["index-state"]
1957 ( "Use source package index state as it existed at a previous time. "
1958 ++ "Accepts unix-timestamps (e.g. '@1474732068'), ISO8601 UTC timestamps "
1959 ++ "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD' (default: 'HEAD'). "
1960 ++ "This determines which package versions are available as well as "
1961 ++ ".cabal file revision is selected (unless --pristine is used)."
1963 getIndexState
1964 (\v flags -> flags{getIndexState = v})
1965 ( reqArg
1966 "STATE"
1967 ( parsecToReadE
1968 ( const $
1969 "index-state must be a "
1970 ++ "unix-timestamps (e.g. '@1474732068'), "
1971 ++ "a ISO8601 UTC timestamp "
1972 ++ "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD'"
1974 (toFlag `fmap` parsec)
1976 (flagToList . fmap prettyShow)
1978 , option
1980 ["only-package-description"]
1981 "Unpack only the package description file."
1982 getOnlyPkgDescr
1983 (\v flags -> flags{getOnlyPkgDescr = v})
1984 trueArg
1985 , option
1987 ["package-description-only"]
1988 "A synonym for --only-package-description."
1989 getOnlyPkgDescr
1990 (\v flags -> flags{getOnlyPkgDescr = v})
1991 trueArg
1992 , option
1994 ["pristine"]
1995 ( "Unpack the original pristine tarball, rather than updating the "
1996 ++ ".cabal file with the latest revision from the package archive."
1998 getPristine
1999 (\v flags -> flags{getPristine = v})
2000 trueArg
2004 -- | List of lines describing command @get@.
2005 descriptionOfGetCommand :: [String]
2006 descriptionOfGetCommand =
2007 [ "Creates a local copy of a package's source code. By default it gets the source"
2008 , "tarball and unpacks it in a local subdirectory. Alternatively, with -s it will"
2009 , "get the code from the source repository specified by the package."
2012 -- | Notes for the command @get@.
2013 notesOfGetCommand
2014 :: String
2015 -- ^ Either @"get"@ or @"unpack"@.
2016 -> String
2017 -- ^ E.g. @"cabal"@.
2018 -> [String]
2019 -- ^ List of lines.
2020 notesOfGetCommand cmd pname =
2021 [ "Examples:"
2022 , " " ++ unwords [pname, cmd, "hlint"]
2023 , " Download the latest stable version of hlint;"
2024 , " " ++ unwords [pname, cmd, "lens --source-repository=head"]
2025 , " Download the source repository of lens (i.e. git clone from github)."
2028 -- 'cabal unpack' is a deprecated alias for 'cabal get'.
2029 unpackCommand :: CommandUI GetFlags
2030 unpackCommand =
2031 getCommand
2032 { commandName = "unpack"
2033 , commandSynopsis = synopsis
2034 , commandNotes = Just $ \pname ->
2035 unlines $
2036 notesOfGetCommand "unpack" pname
2037 , commandUsage = usagePackages "unpack"
2039 where
2040 synopsis = "Deprecated alias for 'get'."
2042 instance Monoid GetFlags where
2043 mempty = gmempty
2044 mappend = (<>)
2046 instance Semigroup GetFlags where
2047 (<>) = gmappend
2049 -- ------------------------------------------------------------
2051 -- * List flags
2053 -- ------------------------------------------------------------
2055 data ListFlags = ListFlags
2056 { listInstalled :: Flag Bool
2057 , listSimpleOutput :: Flag Bool
2058 , listCaseInsensitive :: Flag Bool
2059 , listVerbosity :: Flag Verbosity
2060 , listPackageDBs :: [Maybe PackageDB]
2061 , listHcPath :: Flag FilePath
2063 deriving (Generic)
2065 defaultListFlags :: ListFlags
2066 defaultListFlags =
2067 ListFlags
2068 { listInstalled = Flag False
2069 , listSimpleOutput = Flag False
2070 , listCaseInsensitive = Flag True
2071 , listVerbosity = toFlag normal
2072 , listPackageDBs = []
2073 , listHcPath = mempty
2076 listCommand :: CommandUI ListFlags
2077 listCommand =
2078 CommandUI
2079 { commandName = "list"
2080 , commandSynopsis = "List packages matching a search string."
2081 , commandDescription = Just $ \_ ->
2082 wrapText $
2083 "List all packages, or all packages matching one of the search"
2084 ++ " strings.\n"
2085 ++ "\n"
2086 ++ "Use the package database specified with --package-db. "
2087 ++ "If not specified, use the user package database.\n"
2088 , commandNotes = Just $ \pname ->
2089 "Examples:\n"
2090 ++ " "
2091 ++ pname
2092 ++ " list pandoc\n"
2093 ++ " Will find pandoc, pandoc-citeproc, pandoc-lens, ...\n"
2094 , commandUsage =
2095 usageAlternatives
2096 "list"
2097 [ "[FLAGS]"
2098 , "[FLAGS] STRINGS"
2100 , commandDefaultFlags = defaultListFlags
2101 , commandOptions = const listOptions
2104 listOptions :: [OptionField ListFlags]
2105 listOptions =
2106 [ optionVerbosity listVerbosity (\v flags -> flags{listVerbosity = v})
2107 , option
2109 ["installed"]
2110 "Only print installed packages"
2111 listInstalled
2112 (\v flags -> flags{listInstalled = v})
2113 trueArg
2114 , option
2116 ["simple-output"]
2117 "Print in a easy-to-parse format"
2118 listSimpleOutput
2119 (\v flags -> flags{listSimpleOutput = v})
2120 trueArg
2121 , option
2122 ['i']
2123 ["ignore-case"]
2124 "Ignore case distinctions"
2125 listCaseInsensitive
2126 (\v flags -> flags{listCaseInsensitive = v})
2127 (boolOpt' (['i'], ["ignore-case"]) (['I'], ["strict-case"]))
2128 , option
2130 ["package-db"]
2131 ( "Append the given package database to the list of package"
2132 ++ " databases used (to satisfy dependencies and register into)."
2133 ++ " May be a specific file, 'global' or 'user'. The initial list"
2134 ++ " is ['global'], ['global', 'user'],"
2135 ++ " depending on context. Use 'clear' to reset the list to empty."
2136 ++ " See the user guide for details."
2138 listPackageDBs
2139 (\v flags -> flags{listPackageDBs = v})
2140 (reqArg' "DB" readPackageDbList showPackageDbList)
2141 , option
2143 ["with-compiler"]
2144 "give the path to a particular compiler"
2145 listHcPath
2146 (\v flags -> flags{listHcPath = v})
2147 (reqArgFlag "PATH")
2150 listNeedsCompiler :: ListFlags -> Bool
2151 listNeedsCompiler f =
2152 flagElim False (const True) (listHcPath f)
2153 || fromFlagOrDefault False (listInstalled f)
2155 instance Monoid ListFlags where
2156 mempty = gmempty
2157 mappend = (<>)
2159 instance Semigroup ListFlags where
2160 (<>) = gmappend
2162 -- ------------------------------------------------------------
2164 -- * Info flags
2166 -- ------------------------------------------------------------
2168 data InfoFlags = InfoFlags
2169 { infoVerbosity :: Flag Verbosity
2170 , infoPackageDBs :: [Maybe PackageDB]
2172 deriving (Generic)
2174 defaultInfoFlags :: InfoFlags
2175 defaultInfoFlags =
2176 InfoFlags
2177 { infoVerbosity = toFlag normal
2178 , infoPackageDBs = []
2181 infoCommand :: CommandUI InfoFlags
2182 infoCommand =
2183 CommandUI
2184 { commandName = "info"
2185 , commandSynopsis = "Display detailed information about a particular package."
2186 , commandDescription = Just $ \_ ->
2187 wrapText $
2188 "Use the package database specified with --package-db. "
2189 ++ "If not specified, use the user package database.\n"
2190 , commandNotes = Nothing
2191 , commandUsage = usageAlternatives "info" ["[FLAGS] PACKAGES"]
2192 , commandDefaultFlags = defaultInfoFlags
2193 , commandOptions = \_ ->
2194 [ optionVerbosity infoVerbosity (\v flags -> flags{infoVerbosity = v})
2195 , option
2197 ["package-db"]
2198 ( "Append the given package database to the list of package"
2199 ++ " databases used (to satisfy dependencies and register into)."
2200 ++ " May be a specific file, 'global' or 'user'. The initial list"
2201 ++ " is ['global'], ['global', 'user'],"
2202 ++ " depending on context. Use 'clear' to reset the list to empty."
2203 ++ " See the user guide for details."
2205 infoPackageDBs
2206 (\v flags -> flags{infoPackageDBs = v})
2207 (reqArg' "DB" readPackageDbList showPackageDbList)
2211 instance Monoid InfoFlags where
2212 mempty = gmempty
2213 mappend = (<>)
2215 instance Semigroup InfoFlags where
2216 (<>) = gmappend
2218 -- ------------------------------------------------------------
2220 -- * Install flags
2222 -- ------------------------------------------------------------
2224 -- | Install takes the same flags as configure along with a few extras.
2225 data InstallFlags = InstallFlags
2226 { installDocumentation :: Flag Bool
2227 , installHaddockIndex :: Flag PathTemplate
2228 , installDest :: Flag Cabal.CopyDest
2229 , installDryRun :: Flag Bool
2230 , installOnlyDownload :: Flag Bool
2231 , installMaxBackjumps :: Flag Int
2232 , installReorderGoals :: Flag ReorderGoals
2233 , installCountConflicts :: Flag CountConflicts
2234 , installFineGrainedConflicts :: Flag FineGrainedConflicts
2235 , installMinimizeConflictSet :: Flag MinimizeConflictSet
2236 , installIndependentGoals :: Flag IndependentGoals
2237 , installPreferOldest :: Flag PreferOldest
2238 , installShadowPkgs :: Flag ShadowPkgs
2239 , installStrongFlags :: Flag StrongFlags
2240 , installAllowBootLibInstalls :: Flag AllowBootLibInstalls
2241 , installOnlyConstrained :: Flag OnlyConstrained
2242 , installReinstall :: Flag Bool
2243 , installAvoidReinstalls :: Flag AvoidReinstalls
2244 , installOverrideReinstall :: Flag Bool
2245 , installUpgradeDeps :: Flag Bool
2246 , installOnly :: Flag Bool
2247 , installOnlyDeps :: Flag Bool
2248 , installIndexState :: Flag TotalIndexState
2249 , installRootCmd :: Flag String
2250 , installSummaryFile :: NubList PathTemplate
2251 , installLogFile :: Flag PathTemplate
2252 , installBuildReports :: Flag ReportLevel
2253 , installReportPlanningFailure :: Flag Bool
2254 , -- Note: symlink-bindir is no longer used by v2-install and can be removed
2255 -- when removing v1 commands
2256 installSymlinkBinDir :: Flag FilePath
2257 , installPerComponent :: Flag Bool
2258 , installNumJobs :: Flag (Maybe Int)
2259 , installUseSemaphore :: Flag Bool
2260 , installKeepGoing :: Flag Bool
2261 , installRunTests :: Flag Bool
2262 , installOfflineMode :: Flag Bool
2264 deriving (Eq, Show, Generic)
2266 instance Binary InstallFlags
2268 defaultInstallFlags :: InstallFlags
2269 defaultInstallFlags =
2270 InstallFlags
2271 { installDocumentation = Flag False
2272 , installHaddockIndex = Flag docIndexFile
2273 , installDest = Flag Cabal.NoCopyDest
2274 , installDryRun = Flag False
2275 , installOnlyDownload = Flag False
2276 , installMaxBackjumps = Flag defaultMaxBackjumps
2277 , installReorderGoals = Flag (ReorderGoals False)
2278 , installCountConflicts = Flag (CountConflicts True)
2279 , installFineGrainedConflicts = Flag (FineGrainedConflicts True)
2280 , installMinimizeConflictSet = Flag (MinimizeConflictSet False)
2281 , installIndependentGoals = Flag (IndependentGoals False)
2282 , installPreferOldest = Flag (PreferOldest False)
2283 , installShadowPkgs = Flag (ShadowPkgs False)
2284 , installStrongFlags = Flag (StrongFlags False)
2285 , installAllowBootLibInstalls = Flag (AllowBootLibInstalls False)
2286 , installOnlyConstrained = Flag OnlyConstrainedNone
2287 , installReinstall = Flag False
2288 , installAvoidReinstalls = Flag (AvoidReinstalls False)
2289 , installOverrideReinstall = Flag False
2290 , installUpgradeDeps = Flag False
2291 , installOnly = Flag False
2292 , installOnlyDeps = Flag False
2293 , installIndexState = mempty
2294 , installRootCmd = mempty
2295 , installSummaryFile = mempty
2296 , installLogFile = mempty
2297 , installBuildReports = Flag NoReports
2298 , installReportPlanningFailure = Flag False
2299 , installSymlinkBinDir = mempty
2300 , installPerComponent = Flag True
2301 , installNumJobs = mempty
2302 , installUseSemaphore = Flag False
2303 , installKeepGoing = Flag False
2304 , installRunTests = mempty
2305 , installOfflineMode = Flag False
2307 where
2308 docIndexFile =
2309 toPathTemplate
2310 ( "$datadir"
2311 </> "doc"
2312 </> "$arch-$os-$compiler"
2313 </> "index.html"
2316 defaultMaxBackjumps :: Int
2317 defaultMaxBackjumps = 4000
2319 defaultSolver :: PreSolver
2320 defaultSolver = AlwaysModular
2322 allSolvers :: String
2323 allSolvers = intercalate ", " (map prettyShow ([minBound .. maxBound] :: [PreSolver]))
2325 installCommand
2326 :: CommandUI
2327 ( ConfigFlags
2328 , ConfigExFlags
2329 , InstallFlags
2330 , HaddockFlags
2331 , TestFlags
2332 , BenchmarkFlags
2334 installCommand =
2335 CommandUI
2336 { commandName = "install"
2337 , commandSynopsis = "Install packages."
2338 , commandUsage =
2339 usageAlternatives
2340 "v1-install"
2341 [ "[FLAGS]"
2342 , "[FLAGS] PACKAGES"
2344 , commandDescription = Just $ \_ ->
2345 wrapText $
2346 "Installs one or more packages. By default, the installed package"
2347 ++ " will be registered in the user's package database."
2348 ++ "\n"
2349 ++ "If PACKAGES are specified, downloads and installs those packages."
2350 ++ " Otherwise, install the package in the current directory (and/or its"
2351 ++ " dependencies) (there must be exactly one .cabal file in the current"
2352 ++ " directory).\n"
2353 ++ "\n"
2354 ++ "The flags to `v1-install` are saved and"
2355 ++ " affect future commands such as `v1-build` and `v1-repl`. See the help for"
2356 ++ " `v1-configure` for a list of commands being affected.\n"
2357 ++ "\n"
2358 ++ "Installed executables will by default"
2359 ++ " be put into `~/.local/bin/`."
2360 ++ " If you want installed executable to be available globally, make"
2361 ++ " sure that the PATH environment variable contains that directory.\n"
2362 ++ "\n"
2363 , commandNotes = Just $ \pname ->
2364 ( case commandNotes $
2365 Cabal.configureCommand defaultProgramDb of
2366 Just desc -> desc pname ++ "\n"
2367 Nothing -> ""
2369 ++ "Examples:\n"
2370 ++ " "
2371 ++ pname
2372 ++ " v1-install "
2373 ++ " Package in the current directory\n"
2374 ++ " "
2375 ++ pname
2376 ++ " v1-install foo "
2377 ++ " Package from the hackage server\n"
2378 ++ " "
2379 ++ pname
2380 ++ " v1-install foo-1.0 "
2381 ++ " Specific version of a package\n"
2382 ++ " "
2383 ++ pname
2384 ++ " v1-install 'foo < 2' "
2385 ++ " Constrained package version\n"
2386 ++ " "
2387 ++ pname
2388 ++ " v1-install haddock --bindir=$HOME/hask-bin/ --datadir=$HOME/hask-data/\n"
2389 ++ " "
2390 ++ (map (const ' ') pname)
2391 ++ " "
2392 ++ " Change installation destination\n"
2393 , commandDefaultFlags = (mempty, mempty, mempty, mempty, mempty, mempty)
2394 , commandOptions = \showOrParseArgs ->
2395 liftOptions
2396 get1
2397 set1
2398 -- Note: [Hidden Flags]
2399 -- hide "constraint", "dependency", "promised-dependency" and
2400 -- "exact-configuration" from the configure options.
2401 ( filter
2402 ( ( `notElem`
2403 [ "constraint"
2404 , "dependency"
2405 , "promised-dependency"
2406 , "exact-configuration"
2409 . optionName
2411 $ configureOptions showOrParseArgs
2413 ++ liftOptions get2 set2 (configureExOptions showOrParseArgs ConstraintSourceCommandlineFlag)
2414 ++ liftOptions
2415 get3
2416 set3
2417 -- hide "target-package-db" flag from the
2418 -- install options.
2419 ( filter
2420 ( (`notElem` ["target-package-db"])
2421 . optionName
2423 $ installOptions showOrParseArgs
2425 ++ liftOptions get4 set4 (haddockOptions showOrParseArgs)
2426 ++ liftOptions get5 set5 (testOptions showOrParseArgs)
2427 ++ liftOptions get6 set6 (benchmarkOptions showOrParseArgs)
2429 where
2430 get1 (a, _, _, _, _, _) = a
2431 set1 a (_, b, c, d, e, f) = (a, b, c, d, e, f)
2432 get2 (_, b, _, _, _, _) = b
2433 set2 b (a, _, c, d, e, f) = (a, b, c, d, e, f)
2434 get3 (_, _, c, _, _, _) = c
2435 set3 c (a, b, _, d, e, f) = (a, b, c, d, e, f)
2436 get4 (_, _, _, d, _, _) = d
2437 set4 d (a, b, c, _, e, f) = (a, b, c, d, e, f)
2438 get5 (_, _, _, _, e, _) = e
2439 set5 e (a, b, c, d, _, f) = (a, b, c, d, e, f)
2440 get6 (_, _, _, _, _, f) = f
2441 set6 f (a, b, c, d, e, _) = (a, b, c, d, e, f)
2443 haddockCommand :: CommandUI HaddockFlags
2444 haddockCommand =
2445 Cabal.haddockCommand
2446 { commandUsage =
2447 usageAlternatives "v1-haddock" $
2448 ["[FLAGS]", "COMPONENTS [FLAGS]"]
2451 filterHaddockArgs :: [String] -> Version -> [String]
2452 filterHaddockArgs args cabalLibVersion
2453 | cabalLibVersion >= mkVersion [2, 3, 0] = args_latest
2454 | cabalLibVersion < mkVersion [2, 3, 0] = args_2_3_0
2455 | otherwise = args_latest
2456 where
2457 args_latest = args
2459 -- Cabal < 2.3 doesn't know about per-component haddock
2460 args_2_3_0 = []
2462 -- | Given some 'HaddockFlags' for the version of @Cabal@ that
2463 -- @cabal-install@ was built with, and a target older 'Version' of
2464 -- @Cabal@ that we want to pass these flags to, convert the
2465 -- flags into a form that will be accepted by the older
2466 -- @Setup@ script. Generally speaking, this just means filtering
2467 -- out flags that the old @Cabal@ library doesn't understand, but
2468 -- in some cases it may also mean "emulating" a feature using
2469 -- some more legacy flags.
2470 filterHaddockFlags :: HaddockFlags -> Version -> HaddockFlags
2471 filterHaddockFlags flags cabalLibVersion
2472 | cabalLibVersion >= mkVersion [2, 3, 0] = flags_latest
2473 | cabalLibVersion < mkVersion [2, 3, 0] = flags_2_3_0
2474 | otherwise = flags_latest
2475 where
2476 flags_latest =
2477 flags
2478 { haddockCommonFlags =
2479 (filterCommonFlags (haddockCommonFlags flags) cabalLibVersion)
2480 { -- `cabal haddock` knew about `--keep-temp-files` before other commands did.
2481 setupKeepTempFiles = setupKeepTempFiles (haddockCommonFlags flags)
2485 flags_2_3_0 =
2486 flags_latest
2487 { -- Cabal < 2.3 doesn't know about per-component haddock
2488 haddockCommonFlags =
2489 (haddockCommonFlags flags_latest)
2490 { setupTargets = []
2494 haddockOptions :: ShowOrParseArgs -> [OptionField HaddockFlags]
2495 haddockOptions showOrParseArgs =
2496 [ opt
2497 { optionName = "haddock-" ++ name
2498 , optionDescr =
2499 [ fmapOptFlags (\(_, lflags) -> ([], map ("haddock-" ++) lflags)) descr
2500 | descr <- optionDescr opt
2503 | opt <- commandOptions Cabal.haddockCommand showOrParseArgs
2504 , let name = optionName opt
2505 , name
2506 `elem` [ "hoogle"
2507 , "html"
2508 , "html-location"
2509 , "executables"
2510 , "tests"
2511 , "benchmarks"
2512 , "all"
2513 , "internal"
2514 , "css"
2515 , "hyperlink-source"
2516 , "quickjump"
2517 , "hscolour-css"
2518 , "contents-location"
2519 , "use-index"
2520 , "for-hackage"
2521 , "base-url"
2522 , "resources-dir"
2523 , "output-dir"
2524 , "use-unicode"
2528 testOptions :: ShowOrParseArgs -> [OptionField TestFlags]
2529 testOptions showOrParseArgs =
2530 [ opt
2531 { optionName = prefixTest name
2532 , optionDescr =
2533 [ fmapOptFlags (\(_, lflags) -> ([], map prefixTest lflags)) descr
2534 | descr <- optionDescr opt
2537 | opt <- commandOptions Cabal.testCommand showOrParseArgs
2538 , let name = optionName opt
2539 , name
2540 `elem` [ "log"
2541 , "machine-log"
2542 , "show-details"
2543 , "keep-tix-files"
2544 , "fail-when-no-test-suites"
2545 , "test-options"
2546 , "test-option"
2547 , "test-wrapper"
2550 where
2551 prefixTest name
2552 | "test-" `isPrefixOf` name = name
2553 | otherwise = "test-" ++ name
2555 -- | Options for the @bench@ command.
2557 -- Not to be confused with the @benchmarkOptions@ field of the `BenchmarkFlags` record!
2558 benchmarkOptions :: ShowOrParseArgs -> [OptionField BenchmarkFlags]
2559 benchmarkOptions showOrParseArgs =
2560 [ opt
2561 { optionName = prefixBenchmark name
2562 , optionDescr =
2563 [ fmapOptFlags (\(_, lflags) -> ([], map prefixBenchmark lflags)) descr
2564 | descr <- optionDescr opt
2567 | opt <- commandOptions Cabal.benchmarkCommand showOrParseArgs
2568 , let name = optionName opt
2569 , name `elem` ["benchmark-options", "benchmark-option"]
2571 where
2572 prefixBenchmark name
2573 | "benchmark-" `isPrefixOf` name = name
2574 | otherwise = "benchmark-" ++ name
2576 fmapOptFlags :: (OptFlags -> OptFlags) -> OptDescr a -> OptDescr a
2577 fmapOptFlags modify (ReqArg d f p r w) = ReqArg d (modify f) p r w
2578 fmapOptFlags modify (OptArg d f p r i w) = OptArg d (modify f) p r i w
2579 fmapOptFlags modify (ChoiceOpt xs) = ChoiceOpt [(d, modify f, i, w) | (d, f, i, w) <- xs]
2580 fmapOptFlags modify (BoolOpt d f1 f2 r w) = BoolOpt d (modify f1) (modify f2) r w
2582 installOptions :: ShowOrParseArgs -> [OptionField InstallFlags]
2583 installOptions showOrParseArgs =
2584 [ option
2586 ["documentation"]
2587 "building of documentation"
2588 installDocumentation
2589 (\v flags -> flags{installDocumentation = v})
2590 (boolOpt [] [])
2591 , option
2593 ["doc-index-file"]
2594 "A central index of haddock API documentation (template cannot use $pkgid)"
2595 installHaddockIndex
2596 (\v flags -> flags{installHaddockIndex = v})
2597 ( reqArg'
2598 "TEMPLATE"
2599 (toFlag . toPathTemplate)
2600 (flagToList . fmap fromPathTemplate)
2602 , option
2604 ["dry-run"]
2605 "Do not install anything, only print what would be installed."
2606 installDryRun
2607 (\v flags -> flags{installDryRun = v})
2608 trueArg
2609 , option
2611 ["only-download"]
2612 "Do not build anything, only fetch the packages."
2613 installOnlyDownload
2614 (\v flags -> flags{installOnlyDownload = v})
2615 trueArg
2616 , option
2618 ["target-package-db"]
2619 "package database to install into. Required when using ${pkgroot} prefix."
2620 installDest
2621 (\v flags -> flags{installDest = v})
2622 ( reqArg
2623 "DATABASE"
2624 (succeedReadE (Flag . Cabal.CopyToDb))
2625 (\f -> case f of Flag (Cabal.CopyToDb p) -> [p]; _ -> [])
2628 ++ optionSolverFlags
2629 showOrParseArgs
2630 installMaxBackjumps
2631 (\v flags -> flags{installMaxBackjumps = v})
2632 installReorderGoals
2633 (\v flags -> flags{installReorderGoals = v})
2634 installCountConflicts
2635 (\v flags -> flags{installCountConflicts = v})
2636 installFineGrainedConflicts
2637 (\v flags -> flags{installFineGrainedConflicts = v})
2638 installMinimizeConflictSet
2639 (\v flags -> flags{installMinimizeConflictSet = v})
2640 installIndependentGoals
2641 (\v flags -> flags{installIndependentGoals = v})
2642 installPreferOldest
2643 (\v flags -> flags{installPreferOldest = v})
2644 installShadowPkgs
2645 (\v flags -> flags{installShadowPkgs = v})
2646 installStrongFlags
2647 (\v flags -> flags{installStrongFlags = v})
2648 installAllowBootLibInstalls
2649 (\v flags -> flags{installAllowBootLibInstalls = v})
2650 installOnlyConstrained
2651 (\v flags -> flags{installOnlyConstrained = v})
2652 ++ [ option
2654 ["reinstall"]
2655 "Install even if it means installing the same version again."
2656 installReinstall
2657 (\v flags -> flags{installReinstall = v})
2658 (yesNoOpt showOrParseArgs)
2659 , option
2661 ["avoid-reinstalls"]
2662 "Do not select versions that would destructively overwrite installed packages."
2663 (fmap asBool . installAvoidReinstalls)
2664 (\v flags -> flags{installAvoidReinstalls = fmap AvoidReinstalls v})
2665 (yesNoOpt showOrParseArgs)
2666 , option
2668 ["force-reinstalls"]
2669 "Reinstall packages even if they will most likely break other installed packages."
2670 installOverrideReinstall
2671 (\v flags -> flags{installOverrideReinstall = v})
2672 (yesNoOpt showOrParseArgs)
2673 , option
2675 ["upgrade-dependencies"]
2676 "Pick the latest version for all dependencies, rather than trying to pick an installed version."
2677 installUpgradeDeps
2678 (\v flags -> flags{installUpgradeDeps = v})
2679 (yesNoOpt showOrParseArgs)
2680 , option
2682 ["only-dependencies"]
2683 "Install only the dependencies necessary to build the given packages"
2684 installOnlyDeps
2685 (\v flags -> flags{installOnlyDeps = v})
2686 (yesNoOpt showOrParseArgs)
2687 , option
2689 ["dependencies-only"]
2690 "A synonym for --only-dependencies"
2691 installOnlyDeps
2692 (\v flags -> flags{installOnlyDeps = v})
2693 (yesNoOpt showOrParseArgs)
2694 , option
2696 ["index-state"]
2697 ( "Use source package index state as it existed at a previous time. "
2698 ++ "Accepts unix-timestamps (e.g. '@1474732068'), ISO8601 UTC timestamps "
2699 ++ "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD' (default: 'HEAD')."
2701 installIndexState
2702 (\v flags -> flags{installIndexState = v})
2703 ( reqArg
2704 "STATE"
2705 ( parsecToReadE
2706 ( const $
2707 "index-state must be a "
2708 ++ "unix-timestamps (e.g. '@1474732068'), "
2709 ++ "a ISO8601 UTC timestamp "
2710 ++ "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD'"
2712 (toFlag `fmap` parsec)
2714 (flagToList . fmap prettyShow)
2716 , option
2718 ["root-cmd"]
2719 "(No longer supported, do not use.)"
2720 installRootCmd
2721 (\v flags -> flags{installRootCmd = v})
2722 (reqArg' "COMMAND" toFlag flagToList)
2723 , option
2725 ["symlink-bindir"]
2726 "Add symlinks to installed executables into this directory."
2727 installSymlinkBinDir
2728 (\v flags -> flags{installSymlinkBinDir = v})
2729 (reqArgFlag "DIR")
2730 , option
2732 ["build-summary"]
2733 "Save build summaries to file (name template can use $pkgid, $compiler, $os, $arch)"
2734 installSummaryFile
2735 (\v flags -> flags{installSummaryFile = v})
2736 (reqArg' "TEMPLATE" (\x -> toNubList [toPathTemplate x]) (map fromPathTemplate . fromNubList))
2737 , option
2739 ["build-log"]
2740 "Log all builds to file (name template can use $pkgid, $compiler, $os, $arch)"
2741 installLogFile
2742 (\v flags -> flags{installLogFile = v})
2743 ( reqArg'
2744 "TEMPLATE"
2745 (toFlag . toPathTemplate)
2746 (flagToList . fmap fromPathTemplate)
2748 , option
2750 ["remote-build-reporting"]
2751 "Generate build reports to send to a remote server (none, anonymous or detailed)."
2752 installBuildReports
2753 (\v flags -> flags{installBuildReports = v})
2754 ( reqArg
2755 "LEVEL"
2756 ( parsecToReadE
2757 ( const $
2758 "report level must be 'none', "
2759 ++ "'anonymous' or 'detailed'"
2761 (toFlag `fmap` parsec)
2763 (flagToList . fmap prettyShow)
2765 , option
2767 ["report-planning-failure"]
2768 "Generate build reports when the dependency solver fails. This is used by the Hackage build bot."
2769 installReportPlanningFailure
2770 (\v flags -> flags{installReportPlanningFailure = v})
2771 trueArg
2772 , option
2774 ["per-component"]
2775 "Per-component builds when possible"
2776 installPerComponent
2777 (\v flags -> flags{installPerComponent = v})
2778 (boolOpt [] [])
2779 , option
2781 ["run-tests"]
2782 "Run package test suites during installation."
2783 installRunTests
2784 (\v flags -> flags{installRunTests = v})
2785 trueArg
2786 , option
2788 ["semaphore"]
2789 "Use a semaphore so GHC can compile components in parallel"
2790 installUseSemaphore
2791 (\v flags -> flags{installUseSemaphore = v})
2792 (yesNoOpt showOrParseArgs)
2793 , optionNumJobs
2794 installNumJobs
2795 (\v flags -> flags{installNumJobs = v})
2796 , option
2798 ["keep-going"]
2799 "After a build failure, continue to build other unaffected packages."
2800 installKeepGoing
2801 (\v flags -> flags{installKeepGoing = v})
2802 trueArg
2803 , option
2805 ["offline"]
2806 "Don't download packages from the Internet."
2807 installOfflineMode
2808 (\v flags -> flags{installOfflineMode = v})
2809 (yesNoOpt showOrParseArgs)
2811 ++ case showOrParseArgs of -- TODO: remove when "cabal install"
2812 -- avoids
2813 ParseArgs ->
2814 [ option
2816 ["only"]
2817 "Only installs the package in the current directory."
2818 installOnly
2819 (\v flags -> flags{installOnly = v})
2820 trueArg
2822 _ -> []
2824 optionNumJobs
2825 :: (flags -> Flag (Maybe Int))
2826 -> (Flag (Maybe Int) -> flags -> flags)
2827 -> OptionField flags
2828 optionNumJobs get set =
2829 option
2831 ["jobs"]
2832 "Run NUM jobs simultaneously (or '$ncpus' if no NUM is given)."
2835 ( optArg
2836 "NUM"
2837 (fmap Flag numJobsParser)
2838 ("", Flag Nothing)
2839 (map (Just . maybe "$ncpus" show) . flagToList)
2841 where
2842 numJobsParser :: ReadE (Maybe Int)
2843 numJobsParser = ReadE $ \s ->
2844 case s of
2845 "$ncpus" -> Right Nothing
2846 _ -> case reads s of
2847 [(n, "")]
2848 | n < 1 -> Left "The number of jobs should be 1 or more."
2849 | otherwise -> Right (Just n)
2850 _ -> Left "The jobs value should be a number or '$ncpus'"
2852 instance Monoid InstallFlags where
2853 mempty = gmempty
2854 mappend = (<>)
2856 instance Semigroup InstallFlags where
2857 (<>) = gmappend
2859 -- ------------------------------------------------------------
2861 -- * Upload flags
2863 -- ------------------------------------------------------------
2865 -- | Is this a candidate package or a package to be published?
2866 data IsCandidate = IsCandidate | IsPublished
2867 deriving (Eq)
2869 data UploadFlags = UploadFlags
2870 { uploadCandidate :: Flag IsCandidate
2871 , uploadDoc :: Flag Bool
2872 , uploadToken :: Flag Token
2873 , uploadUsername :: Flag Username
2874 , uploadPassword :: Flag Password
2875 , uploadPasswordCmd :: Flag [String]
2876 , uploadVerbosity :: Flag Verbosity
2878 deriving (Generic)
2880 defaultUploadFlags :: UploadFlags
2881 defaultUploadFlags =
2882 UploadFlags
2883 { uploadCandidate = toFlag IsCandidate
2884 , uploadDoc = toFlag False
2885 , uploadToken = mempty
2886 , uploadUsername = mempty
2887 , uploadPassword = mempty
2888 , uploadPasswordCmd = mempty
2889 , uploadVerbosity = toFlag normal
2892 uploadCommand :: CommandUI UploadFlags
2893 uploadCommand =
2894 CommandUI
2895 { commandName = "upload"
2896 , commandSynopsis = "Uploads source packages or documentation to Hackage."
2897 , commandDescription = Nothing
2898 , commandNotes = Just $ \_ ->
2899 "You can store your Hackage login in the ~/.config/cabal/config file\n"
2900 ++ "(the %APPDATA%\\cabal\\config file on Windows)\n"
2901 ++ relevantConfigValuesText ["token", "username", "password", "password-command"]
2902 , commandUsage = \pname ->
2903 "Usage: " ++ pname ++ " upload [FLAGS] TARFILES\n"
2904 , commandDefaultFlags = defaultUploadFlags
2905 , commandOptions = \_ ->
2906 [ optionVerbosity
2907 uploadVerbosity
2908 (\v flags -> flags{uploadVerbosity = v})
2909 , option
2911 ["publish"]
2912 "Publish the package instead of uploading it as a candidate."
2913 uploadCandidate
2914 (\v flags -> flags{uploadCandidate = v})
2915 (noArg (Flag IsPublished))
2916 , option
2917 ['d']
2918 ["documentation"]
2919 ( "Upload documentation instead of a source package. "
2920 ++ "By default, this uploads documentation for a package candidate. "
2921 ++ "To upload documentation for "
2922 ++ "a published package, combine with --publish."
2924 uploadDoc
2925 (\v flags -> flags{uploadDoc = v})
2926 trueArg
2927 , option
2928 ['t']
2929 ["token"]
2930 "Hackage authentication token."
2931 uploadToken
2932 (\v flags -> flags{uploadToken = v})
2933 ( reqArg'
2934 "TOKEN"
2935 (toFlag . Token)
2936 (flagToList . fmap unToken)
2938 , option
2939 ['u']
2940 ["username"]
2941 "Hackage username."
2942 uploadUsername
2943 (\v flags -> flags{uploadUsername = v})
2944 ( reqArg'
2945 "USERNAME"
2946 (toFlag . Username)
2947 (flagToList . fmap unUsername)
2949 , option
2950 ['p']
2951 ["password"]
2952 "Hackage password."
2953 uploadPassword
2954 (\v flags -> flags{uploadPassword = v})
2955 ( reqArg'
2956 "PASSWORD"
2957 (toFlag . Password)
2958 (flagToList . fmap unPassword)
2960 , option
2961 ['P']
2962 ["password-command"]
2963 "Command to get Hackage password."
2964 uploadPasswordCmd
2965 (\v flags -> flags{uploadPasswordCmd = v})
2966 ( reqArg
2967 "COMMAND"
2968 ( readP_to_E
2969 ("Cannot parse command: " ++)
2970 (Flag <$> parseSpaceList parseTokenQ)
2972 (flagElim [] (pure . unwords . fmap show))
2977 instance Monoid UploadFlags where
2978 mempty = gmempty
2979 mappend = (<>)
2981 instance Semigroup UploadFlags where
2982 (<>) = gmappend
2984 -- ------------------------------------------------------------
2986 -- * Init flags
2988 -- ------------------------------------------------------------
2990 initCommand :: CommandUI IT.InitFlags
2991 initCommand =
2992 CommandUI
2993 { commandName = "init"
2994 , commandSynopsis = "Create a new cabal package."
2995 , commandDescription = Just $ \_ ->
2996 wrapText $
2997 "Create a .cabal, CHANGELOG.md, minimal initial Haskell code and optionally a LICENSE file.\n"
2998 ++ "\n"
2999 ++ "Calling init with no arguments runs interactive mode, "
3000 ++ "which will try to guess as much as possible and prompt you for the rest.\n"
3001 ++ "Non-interactive mode can be invoked by the -n/--non-interactive flag, "
3002 ++ "which will let you specify the options via flags and will use the defaults for the rest.\n"
3003 ++ "It is also possible to call init with a single argument, which denotes the project's desired "
3004 ++ "root directory.\n"
3005 , commandNotes = Nothing
3006 , commandUsage = \pname ->
3007 "Usage: " ++ pname ++ " init [PROJECT ROOT] [FLAGS]\n"
3008 , commandDefaultFlags = IT.defaultInitFlags
3009 , commandOptions = initOptions
3012 initOptions :: ShowOrParseArgs -> [OptionField IT.InitFlags]
3013 initOptions _ =
3014 [ option
3015 ['i']
3016 ["interactive"]
3017 "interactive mode."
3018 IT.interactive
3019 (\v flags -> flags{IT.interactive = v})
3020 (boolOpt' (['i'], ["interactive"]) (['n'], ["non-interactive"]))
3021 , option
3022 ['q']
3023 ["quiet"]
3024 "Do not generate log messages to stdout."
3025 IT.quiet
3026 (\v flags -> flags{IT.quiet = v})
3027 trueArg
3028 , option
3030 ["no-comments"]
3031 "Do not generate explanatory comments in the .cabal file."
3032 IT.noComments
3033 (\v flags -> flags{IT.noComments = v})
3034 trueArg
3035 , option
3036 ['m']
3037 ["minimal"]
3038 "Generate a minimal .cabal file, that is, do not include extra empty fields. Also implies --no-comments."
3039 IT.minimal
3040 (\v flags -> flags{IT.minimal = v})
3041 trueArg
3042 , option
3044 ["overwrite"]
3045 "Overwrite any existing .cabal, LICENSE, or Setup.hs files without warning."
3046 IT.overwrite
3047 (\v flags -> flags{IT.overwrite = v})
3048 trueArg
3049 , option
3051 ["package-dir", "packagedir"]
3052 "Root directory of the package (default = current directory)."
3053 IT.packageDir
3054 (\v flags -> flags{IT.packageDir = v})
3055 (reqArgFlag "DIRECTORY")
3056 , option
3057 ['p']
3058 ["package-name"]
3059 "Name of the Cabal package to create."
3060 IT.packageName
3061 (\v flags -> flags{IT.packageName = v})
3062 ( reqArg
3063 "PACKAGE"
3064 ( parsecToReadE
3065 ("Cannot parse package name: " ++)
3066 (toFlag `fmap` parsec)
3068 (flagToList . fmap prettyShow)
3070 , option
3072 ["version"]
3073 "Initial version of the package."
3074 IT.version
3075 (\v flags -> flags{IT.version = v})
3076 ( reqArg
3077 "VERSION"
3078 ( parsecToReadE
3079 ("Cannot parse package version: " ++)
3080 (toFlag `fmap` parsec)
3082 (flagToList . fmap prettyShow)
3084 , option
3086 ["cabal-version"]
3087 "Version of the Cabal specification."
3088 IT.cabalVersion
3089 (\v flags -> flags{IT.cabalVersion = v})
3090 ( reqArg
3091 "CABALSPECVERSION"
3092 ( parsecToReadE
3093 ("Cannot parse Cabal specification version: " ++)
3094 (fmap (toFlag . getSpecVersion) parsec)
3096 (flagToList . fmap (prettyShow . SpecVersion))
3098 , option
3099 ['l']
3100 ["license"]
3101 "Project license."
3102 IT.license
3103 (\v flags -> flags{IT.license = v})
3104 ( reqArg
3105 "LICENSE"
3106 ( parsecToReadE
3107 ("Cannot parse license: " ++)
3108 (toFlag `fmap` parsec)
3110 (flagToList . fmap prettyShow)
3112 , option
3113 ['a']
3114 ["author"]
3115 "Name of the project's author."
3116 IT.author
3117 (\v flags -> flags{IT.author = v})
3118 (reqArgFlag "NAME")
3119 , option
3120 ['e']
3121 ["email"]
3122 "Email address of the maintainer."
3123 IT.email
3124 (\v flags -> flags{IT.email = v})
3125 (reqArgFlag "EMAIL")
3126 , option
3127 ['u']
3128 ["homepage"]
3129 "Project homepage and/or repository."
3130 IT.homepage
3131 (\v flags -> flags{IT.homepage = v})
3132 (reqArgFlag "URL")
3133 , option
3134 ['s']
3135 ["synopsis"]
3136 "Short project synopsis."
3137 IT.synopsis
3138 (\v flags -> flags{IT.synopsis = v})
3139 (reqArgFlag "TEXT")
3140 , option
3141 ['c']
3142 ["category"]
3143 "Project category."
3144 IT.category
3145 (\v flags -> flags{IT.category = v})
3146 (reqArgFlag "CATEGORY")
3147 , option
3148 ['x']
3149 ["extra-source-file"]
3150 "Extra source file to be distributed with tarball."
3151 IT.extraSrc
3152 (\v flags -> flags{IT.extraSrc = mergeListFlag (IT.extraSrc flags) v})
3153 ( reqArg'
3154 "FILE"
3155 (Flag . (: []))
3156 (fromFlagOrDefault [])
3158 , option
3160 ["extra-doc-file"]
3161 "Extra doc file to be distributed with tarball."
3162 IT.extraDoc
3163 (\v flags -> flags{IT.extraDoc = mergeListFlag (IT.extraDoc flags) v})
3164 (reqArg' "FILE" (Flag . (: [])) (fromFlagOrDefault []))
3165 , option
3167 ["lib", "is-library"]
3168 "Build a library."
3169 IT.packageType
3170 (\v flags -> flags{IT.packageType = v})
3171 (noArg (Flag IT.Library))
3172 , option
3174 ["exe", "is-executable"]
3175 "Build an executable."
3176 IT.packageType
3177 (\v flags -> flags{IT.packageType = v})
3178 (noArg (Flag IT.Executable))
3179 , option
3181 ["libandexe", "is-libandexe"]
3182 "Build a library and an executable."
3183 IT.packageType
3184 (\v flags -> flags{IT.packageType = v})
3185 (noArg (Flag IT.LibraryAndExecutable))
3186 , option
3188 ["tests"]
3189 "Generate a test suite, standalone or for a library."
3190 IT.initializeTestSuite
3191 (\v flags -> flags{IT.initializeTestSuite = v})
3192 trueArg
3193 , option
3195 ["test-dir"]
3196 "Directory containing tests."
3197 IT.testDirs
3198 ( \v flags ->
3199 flags{IT.testDirs = mergeListFlag (IT.testDirs flags) v}
3201 ( reqArg'
3202 "DIR"
3203 (Flag . (: []))
3204 (fromFlagOrDefault [])
3206 , option
3208 ["simple"]
3209 "Create a simple project with sensible defaults."
3210 IT.simpleProject
3211 (\v flags -> flags{IT.simpleProject = v})
3212 trueArg
3213 , option
3215 ["main-is"]
3216 "Specify the main module."
3217 IT.mainIs
3218 (\v flags -> flags{IT.mainIs = v})
3219 (reqArgFlag "FILE")
3220 , option
3222 ["language"]
3223 "Specify the default language."
3224 IT.language
3225 (\v flags -> flags{IT.language = v})
3226 ( reqArg
3227 "LANGUAGE"
3228 ( parsecToReadE
3229 ("Cannot parse language: " ++)
3230 (toFlag `fmap` parsec)
3232 (flagToList . fmap prettyShow)
3234 , option
3235 ['o']
3236 ["expose-module"]
3237 "Export a module from the package."
3238 IT.exposedModules
3239 ( \v flags ->
3240 flags
3241 { IT.exposedModules =
3242 mergeListFlag (IT.exposedModules flags) v
3245 ( reqArg
3246 "MODULE"
3247 ( parsecToReadE
3248 ("Cannot parse module name: " ++)
3249 (Flag . (: []) <$> parsec)
3251 (flagElim [] (fmap prettyShow))
3253 , option
3255 ["extension"]
3256 "Use a LANGUAGE extension (in the other-extensions field)."
3257 IT.otherExts
3258 ( \v flags ->
3259 flags
3260 { IT.otherExts =
3261 mergeListFlag (IT.otherExts flags) v
3264 ( reqArg
3265 "EXTENSION"
3266 ( parsecToReadE
3267 ("Cannot parse extension: " ++)
3268 (Flag . (: []) <$> parsec)
3270 (flagElim [] (fmap prettyShow))
3272 , option
3273 ['d']
3274 ["dependency"]
3275 "Package dependencies. Permits comma separated list of dependencies."
3276 IT.dependencies
3277 ( \v flags ->
3278 flags
3279 { IT.dependencies =
3280 mergeListFlag (IT.dependencies flags) v
3283 ( reqArg
3284 "DEPENDENCIES"
3285 (fmap Flag dependenciesReadE)
3286 (fmap prettyShow . fromFlagOrDefault [])
3288 , option
3290 ["application-dir"]
3291 "Directory containing package application executable."
3292 IT.applicationDirs
3293 ( \v flags ->
3294 flags
3295 { IT.applicationDirs =
3296 mergeListFlag (IT.applicationDirs flags) v
3299 ( reqArg'
3300 "DIR"
3301 (Flag . (: []))
3302 (fromFlagOrDefault [])
3304 , option
3306 ["source-dir", "sourcedir"]
3307 "Directory containing package library source."
3308 IT.sourceDirs
3309 ( \v flags ->
3310 flags
3311 { IT.sourceDirs =
3312 mergeListFlag (IT.sourceDirs flags) v
3315 ( reqArg'
3316 "DIR"
3317 (Flag . (: []))
3318 (fromFlagOrDefault [])
3320 , option
3322 ["build-tool"]
3323 "Required external build tool."
3324 IT.buildTools
3325 ( \v flags ->
3326 flags
3327 { IT.buildTools =
3328 mergeListFlag (IT.buildTools flags) v
3331 ( reqArg'
3332 "TOOL"
3333 (Flag . (: []))
3334 (fromFlagOrDefault [])
3336 , option
3338 ["with-compiler"]
3339 "give the path to a particular compiler. For 'init', this flag is used \
3340 \to set the bounds inferred for the 'base' package."
3341 IT.initHcPath
3342 (\v flags -> flags{IT.initHcPath = v})
3343 (reqArgFlag "PATH")
3344 , optionVerbosity IT.initVerbosity (\v flags -> flags{IT.initVerbosity = v})
3346 where
3347 dependenciesReadE :: ReadE [Dependency]
3348 dependenciesReadE =
3349 parsecToReadE
3350 ("Cannot parse dependencies: " ++)
3351 (parsecCommaList parsec)
3353 -- ------------------------------------------------------------
3355 -- * Copy and Register
3357 -- ------------------------------------------------------------
3359 copyCommand :: CommandUI CopyFlags
3360 copyCommand =
3361 Cabal.copyCommand
3362 { commandNotes = Just $ \pname ->
3363 "Examples:\n"
3364 ++ " "
3365 ++ pname
3366 ++ " v1-copy "
3367 ++ " All the components in the package\n"
3368 ++ " "
3369 ++ pname
3370 ++ " v1-copy foo "
3371 ++ " A component (i.e. lib, exe, test suite)"
3372 , commandUsage =
3373 usageAlternatives "v1-copy" $
3374 [ "[FLAGS]"
3375 , "COMPONENTS [FLAGS]"
3379 registerCommand :: CommandUI RegisterFlags
3380 registerCommand =
3381 Cabal.registerCommand
3382 { commandUsage = \pname -> "Usage: " ++ pname ++ " v1-register [FLAGS]\n"
3385 -- | Given some 'RegisterFlags' for the version of @Cabal@ that
3386 -- @cabal-install@ was built with, and a target older 'Version' of
3387 -- @Cabal@ that we want to pass these flags to, convert the
3388 -- flags into a form that will be accepted by the older
3389 -- @Setup@ script. Generally speaking, this just means filtering
3390 -- out flags that the old @Cabal@ library doesn't understand, but
3391 -- in some cases it may also mean "emulating" a feature using
3392 -- some more legacy flags.
3393 filterRegisterFlags :: RegisterFlags -> Version -> RegisterFlags
3394 filterRegisterFlags flags cabalLibVersion =
3395 flags
3396 { registerCommonFlags =
3397 filterCommonFlags (registerCommonFlags flags) cabalLibVersion
3400 -- | Given some 'CopyFlags' for the version of @Cabal@ that
3401 -- @cabal-install@ was built with, and a target older 'Version' of
3402 -- @Cabal@ that we want to pass these flags to, convert the
3403 -- flags into a form that will be accepted by the older
3404 -- @Setup@ script. Generally speaking, this just means filtering
3405 -- out flags that the old @Cabal@ library doesn't understand, but
3406 -- in some cases it may also mean "emulating" a feature using
3407 -- some more legacy flags.
3408 filterCopyFlags :: CopyFlags -> Version -> CopyFlags
3409 filterCopyFlags flags cabalLibVersion =
3410 flags
3411 { copyCommonFlags = filterCommonFlags (copyCommonFlags flags) cabalLibVersion
3414 -- ------------------------------------------------------------
3416 -- * ActAsSetup flags
3418 -- ------------------------------------------------------------
3420 data ActAsSetupFlags = ActAsSetupFlags
3421 { actAsSetupBuildType :: Flag BuildType
3423 deriving (Generic)
3425 defaultActAsSetupFlags :: ActAsSetupFlags
3426 defaultActAsSetupFlags =
3427 ActAsSetupFlags
3428 { actAsSetupBuildType = toFlag Simple
3431 actAsSetupCommand :: CommandUI ActAsSetupFlags
3432 actAsSetupCommand =
3433 CommandUI
3434 { commandName = "act-as-setup"
3435 , commandSynopsis = "Run as-if this was a Setup.hs"
3436 , commandDescription = Nothing
3437 , commandNotes = Nothing
3438 , commandUsage = \pname ->
3439 "Usage: " ++ pname ++ " act-as-setup\n"
3440 , commandDefaultFlags = defaultActAsSetupFlags
3441 , commandOptions = \_ ->
3442 [ option
3444 ["build-type"]
3445 "Use the given build type."
3446 actAsSetupBuildType
3447 (\v flags -> flags{actAsSetupBuildType = v})
3448 ( reqArg
3449 "BUILD-TYPE"
3450 ( parsecToReadE
3451 ("Cannot parse build type: " ++)
3452 (fmap toFlag parsec)
3454 (map prettyShow . flagToList)
3459 instance Monoid ActAsSetupFlags where
3460 mempty = gmempty
3461 mappend = (<>)
3463 instance Semigroup ActAsSetupFlags where
3464 (<>) = gmappend
3466 -- ------------------------------------------------------------
3468 -- * UserConfig flags
3470 -- ------------------------------------------------------------
3472 data UserConfigFlags = UserConfigFlags
3473 { userConfigVerbosity :: Flag Verbosity
3474 , userConfigForce :: Flag Bool
3475 , userConfigAppendLines :: Flag [String]
3477 deriving (Generic)
3479 instance Monoid UserConfigFlags where
3480 mempty =
3481 UserConfigFlags
3482 { userConfigVerbosity = toFlag normal
3483 , userConfigForce = toFlag False
3484 , userConfigAppendLines = toFlag []
3486 mappend = (<>)
3488 instance Semigroup UserConfigFlags where
3489 (<>) = gmappend
3491 userConfigCommand :: CommandUI UserConfigFlags
3492 userConfigCommand =
3493 CommandUI
3494 { commandName = "user-config"
3495 , commandSynopsis = "Display and update the user's global cabal configuration."
3496 , commandDescription = Just $ \_ ->
3497 wrapText $
3498 "When upgrading cabal, the set of configuration keys and their default"
3499 ++ " values may change. This command provides means to merge the existing"
3500 ++ " config in ~/.config/cabal/config"
3501 ++ " (i.e. all bindings that are actually defined and not commented out)"
3502 ++ " and the default config of the new version.\n"
3503 ++ "\n"
3504 ++ "init: Creates a new config file at either ~/.config/cabal/config or as"
3505 ++ " specified by --config-file, if given. An existing file won't be "
3506 ++ " overwritten unless -f or --force is given.\n"
3507 ++ "diff: Shows a pseudo-diff of the user's ~/.config/cabal/config file and"
3508 ++ " the default configuration that would be created by cabal if the"
3509 ++ " config file did not exist.\n"
3510 ++ "update: Applies the pseudo-diff to the configuration that would be"
3511 ++ " created by default, and write the result back to ~/.config/cabal/config."
3512 , commandNotes = Nothing
3513 , commandUsage = usageAlternatives "user-config" ["init", "diff", "update"]
3514 , commandDefaultFlags = mempty
3515 , commandOptions = \_ ->
3516 [ optionVerbosity userConfigVerbosity (\v flags -> flags{userConfigVerbosity = v})
3517 , option
3518 ['f']
3519 ["force"]
3520 "Overwrite the config file if it already exists."
3521 userConfigForce
3522 (\v flags -> flags{userConfigForce = v})
3523 trueArg
3524 , option
3525 ['a']
3526 ["augment"]
3527 "Additional setting to augment the config file (replacing a previous setting if it existed)."
3528 userConfigAppendLines
3529 ( \v flags ->
3530 flags
3531 { userConfigAppendLines =
3532 Flag $ concat (flagToList (userConfigAppendLines flags) ++ flagToList v)
3535 (reqArg' "CONFIGLINE" (Flag . (: [])) (fromMaybe [] . flagToMaybe))
3539 -- ------------------------------------------------------------
3541 -- * GetOpt Utils
3543 -- ------------------------------------------------------------
3545 reqArgFlag
3546 :: ArgPlaceHolder
3547 -> MkOptDescr (b -> Flag String) (Flag String -> b -> b) b
3548 reqArgFlag ad = reqArg ad (succeedReadE Flag) flagToList
3550 liftOptions
3551 :: (b -> a)
3552 -> (a -> b -> b)
3553 -> [OptionField a]
3554 -> [OptionField b]
3555 liftOptions get set = map (liftOption get set)
3557 yesNoOpt :: ShowOrParseArgs -> MkOptDescr (b -> Flag Bool) (Flag Bool -> b -> b) b
3558 yesNoOpt ShowArgs sf lf = trueArg sf lf
3559 yesNoOpt _ sf lf = Command.boolOpt' flagToMaybe Flag (sf, lf) ([], map ("no-" ++) lf) sf lf
3561 optionSolver
3562 :: (flags -> Flag PreSolver)
3563 -> (Flag PreSolver -> flags -> flags)
3564 -> OptionField flags
3565 optionSolver get set =
3566 option
3568 ["solver"]
3569 ("Select dependency solver to use (default: " ++ prettyShow defaultSolver ++ "). Choices: " ++ allSolvers ++ ".")
3572 ( reqArg
3573 "SOLVER"
3574 ( parsecToReadE
3575 (const $ "solver must be one of: " ++ allSolvers)
3576 (toFlag `fmap` parsec)
3578 (flagToList . fmap prettyShow)
3581 optionSolverFlags
3582 :: ShowOrParseArgs
3583 -> (flags -> Flag Int)
3584 -> (Flag Int -> flags -> flags)
3585 -> (flags -> Flag ReorderGoals)
3586 -> (Flag ReorderGoals -> flags -> flags)
3587 -> (flags -> Flag CountConflicts)
3588 -> (Flag CountConflicts -> flags -> flags)
3589 -> (flags -> Flag FineGrainedConflicts)
3590 -> (Flag FineGrainedConflicts -> flags -> flags)
3591 -> (flags -> Flag MinimizeConflictSet)
3592 -> (Flag MinimizeConflictSet -> flags -> flags)
3593 -> (flags -> Flag IndependentGoals)
3594 -> (Flag IndependentGoals -> flags -> flags)
3595 -> (flags -> Flag PreferOldest)
3596 -> (Flag PreferOldest -> flags -> flags)
3597 -> (flags -> Flag ShadowPkgs)
3598 -> (Flag ShadowPkgs -> flags -> flags)
3599 -> (flags -> Flag StrongFlags)
3600 -> (Flag StrongFlags -> flags -> flags)
3601 -> (flags -> Flag AllowBootLibInstalls)
3602 -> (Flag AllowBootLibInstalls -> flags -> flags)
3603 -> (flags -> Flag OnlyConstrained)
3604 -> (Flag OnlyConstrained -> flags -> flags)
3605 -> [OptionField flags]
3606 optionSolverFlags
3607 showOrParseArgs
3608 getmbj
3609 setmbj
3610 getrg
3611 setrg
3612 getcc
3613 setcc
3614 getfgc
3615 setfgc
3616 getmc
3617 setmc
3618 getig
3619 setig
3620 getpo
3621 setpo
3622 getsip
3623 setsip
3624 getstrfl
3625 setstrfl
3626 getib
3627 setib
3628 getoc
3629 setoc =
3630 [ option
3632 ["max-backjumps"]
3633 ("Maximum number of backjumps allowed while solving (default: " ++ show defaultMaxBackjumps ++ "). Use a negative number to enable unlimited backtracking. Use 0 to disable backtracking completely.")
3634 getmbj
3635 setmbj
3636 ( reqArg
3637 "NUM"
3638 (parsecToReadE ("Cannot parse number: " ++) (fmap toFlag P.signedIntegral))
3639 (map show . flagToList)
3641 , option
3643 ["reorder-goals"]
3644 "Try to reorder goals according to certain heuristics. Slows things down on average, but may make backtracking faster for some packages."
3645 (fmap asBool . getrg)
3646 (setrg . fmap ReorderGoals)
3647 (yesNoOpt showOrParseArgs)
3648 , option
3650 ["count-conflicts"]
3651 "Try to speed up solving by preferring goals that are involved in a lot of conflicts (default)."
3652 (fmap asBool . getcc)
3653 (setcc . fmap CountConflicts)
3654 (yesNoOpt showOrParseArgs)
3655 , option
3657 ["fine-grained-conflicts"]
3658 "Skip a version of a package if it does not resolve the conflicts encountered in the last version, as a solver optimization (default)."
3659 (fmap asBool . getfgc)
3660 (setfgc . fmap FineGrainedConflicts)
3661 (yesNoOpt showOrParseArgs)
3662 , option
3664 ["minimize-conflict-set"]
3665 ( "When there is no solution, try to improve the error message by finding "
3666 ++ "a minimal conflict set (default: false). May increase run time "
3667 ++ "significantly."
3669 (fmap asBool . getmc)
3670 (setmc . fmap MinimizeConflictSet)
3671 (yesNoOpt showOrParseArgs)
3672 , option
3674 ["independent-goals"]
3675 "Treat several goals on the command line as independent. If several goals depend on the same package, different versions can be chosen."
3676 (fmap asBool . getig)
3677 (setig . fmap IndependentGoals)
3678 (yesNoOpt showOrParseArgs)
3679 , option
3681 ["prefer-oldest"]
3682 "Prefer the oldest (instead of the latest) versions of packages available. Useful to determine lower bounds in the build-depends section."
3683 (fmap asBool . getpo)
3684 (setpo . fmap PreferOldest)
3685 (yesNoOpt showOrParseArgs)
3686 , option
3688 ["shadow-installed-packages"]
3689 "If multiple package instances of the same version are installed, treat all but one as shadowed."
3690 (fmap asBool . getsip)
3691 (setsip . fmap ShadowPkgs)
3692 (yesNoOpt showOrParseArgs)
3693 , option
3695 ["strong-flags"]
3696 "Do not defer flag choices (this used to be the default in cabal-install <= 1.20)."
3697 (fmap asBool . getstrfl)
3698 (setstrfl . fmap StrongFlags)
3699 (yesNoOpt showOrParseArgs)
3700 , option
3702 ["allow-boot-library-installs"]
3703 "Allow cabal to install base, ghc-prim, integer-simple, integer-gmp, and template-haskell."
3704 (fmap asBool . getib)
3705 (setib . fmap AllowBootLibInstalls)
3706 (yesNoOpt showOrParseArgs)
3707 , option
3709 ["reject-unconstrained-dependencies"]
3710 "Require these packages to have constraints on them if they are to be selected (default: none)."
3711 getoc
3712 setoc
3713 ( reqArg
3714 "none|all"
3715 ( parsecToReadE
3716 (const "reject-unconstrained-dependencies must be 'none' or 'all'")
3717 (toFlag `fmap` parsec)
3719 (flagToList . fmap prettyShow)
3723 usagePackages :: String -> String -> String
3724 usagePackages name pname =
3725 "Usage: " ++ pname ++ " " ++ name ++ " [PACKAGES]\n"
3727 usageFlags :: String -> String -> String
3728 usageFlags name pname =
3729 "Usage: " ++ pname ++ " " ++ name ++ " [FLAGS]\n"
3731 -- ------------------------------------------------------------
3733 -- * Repo helpers
3735 -- ------------------------------------------------------------
3737 showRemoteRepo :: RemoteRepo -> String
3738 showRemoteRepo = prettyShow
3740 readRemoteRepo :: String -> Maybe RemoteRepo
3741 readRemoteRepo = simpleParsec
3743 showLocalRepo :: LocalRepo -> String
3744 showLocalRepo = prettyShow
3746 readLocalRepo :: String -> Maybe LocalRepo
3747 readLocalRepo = simpleParsec
3749 -- ------------------------------------------------------------
3751 -- * Helpers for Documentation
3753 -- ------------------------------------------------------------
3755 relevantConfigValuesText :: [String] -> String
3756 relevantConfigValuesText vs =
3757 "Relevant global configuration keys:\n"
3758 ++ concat [" " ++ v ++ "\n" | v <- vs]