cabal init -i should sanitize suggested package name (fix #8404) (#8561)
[cabal.git] / cabal-install / src / Distribution / Client / Setup.hs
blobb4653f977b6de0ea5f95f2ebcb79e8194a3778d2
1 {-# LANGUAGE ScopedTypeVariables #-}
2 {-# LANGUAGE RecordWildCards #-}
3 {-# LANGUAGE RankNTypes #-}
4 {-# LANGUAGE DeriveGeneric #-}
5 {-# LANGUAGE LambdaCase #-}
6 -----------------------------------------------------------------------------
7 -- |
8 -- Module : Distribution.Client.Setup
9 -- Copyright : (c) David Himmelstrup 2005
10 -- License : BSD-like
12 -- Maintainer : lemmih@gmail.com
13 -- Stability : provisional
14 -- Portability : portable
17 -----------------------------------------------------------------------------
18 module Distribution.Client.Setup
19 ( globalCommand, GlobalFlags(..), defaultGlobalFlags
20 , RepoContext(..), withRepoContext
21 , configureCommand, ConfigFlags(..), configureOptions, filterConfigureFlags
22 , configPackageDB', configCompilerAux'
23 , configureExCommand, ConfigExFlags(..), defaultConfigExFlags
24 , buildCommand, BuildFlags(..)
25 , filterTestFlags
26 , replCommand, testCommand, benchmarkCommand, testOptions, benchmarkOptions
27 , configureExOptions, reconfigureCommand
28 , installCommand, InstallFlags(..), installOptions, defaultInstallFlags
29 , filterHaddockArgs, filterHaddockFlags, haddockOptions
30 , defaultSolver, defaultMaxBackjumps
31 , listCommand, ListFlags(..), listNeedsCompiler
32 ,UpdateFlags(..), defaultUpdateFlags
33 , infoCommand, InfoFlags(..)
34 , fetchCommand, FetchFlags(..)
35 , freezeCommand, FreezeFlags(..)
36 , genBoundsCommand
37 , getCommand, unpackCommand, GetFlags(..)
38 , checkCommand
39 , formatCommand
40 , uploadCommand, UploadFlags(..), IsCandidate(..)
41 , reportCommand, ReportFlags(..)
42 , runCommand
43 , initCommand, initOptions, IT.InitFlags(..)
44 , actAsSetupCommand, ActAsSetupFlags(..)
45 , userConfigCommand, UserConfigFlags(..)
46 , manpageCommand
47 , haddockCommand
48 , cleanCommand
49 , copyCommand
50 , registerCommand
52 , liftOptions
53 , yesNoOpt
54 ) where
56 import Prelude ()
57 import Distribution.Client.Compat.Prelude hiding (get)
59 import Distribution.Client.Types.Credentials (Username (..), Password (..))
60 import Distribution.Client.Types.Repo (RemoteRepo(..), LocalRepo (..))
61 import Distribution.Client.Types.AllowNewer (AllowNewer(..), AllowOlder(..), RelaxDeps(..))
62 import Distribution.Client.Types.WriteGhcEnvironmentFilesPolicy
64 import Distribution.Client.BuildReports.Types
65 ( ReportLevel(..) )
66 import Distribution.Client.Dependency.Types
67 ( PreSolver(..) )
68 import Distribution.Client.IndexUtils.ActiveRepos
69 ( ActiveRepos )
70 import Distribution.Client.IndexUtils.IndexState
71 ( TotalIndexState, headTotalIndexState )
72 import qualified Distribution.Client.Init.Types as IT
73 import qualified Distribution.Client.Init.Defaults as IT
74 import Distribution.Client.Targets
75 ( UserConstraint, readUserConstraint )
76 import Distribution.Utils.NubList
77 ( NubList, toNubList, fromNubList)
79 import Distribution.Solver.Types.ConstraintSource
80 import Distribution.Solver.Types.Settings
82 import Distribution.Simple.Compiler ( Compiler, PackageDB, PackageDBStack )
83 import Distribution.Simple.Program (ProgramDb, defaultProgramDb)
84 import Distribution.Simple.Command hiding (boolOpt, boolOpt')
85 import qualified Distribution.Simple.Command as Command
86 import Distribution.Simple.Configure
87 ( configCompilerAuxEx, interpretPackageDbFlags, computeEffectiveProfiling )
88 import qualified Distribution.Simple.Setup as Cabal
89 import Distribution.Simple.Flag
90 ( Flag(..), toFlag, flagToMaybe, flagToList, maybeToFlag
91 , flagElim, fromFlagOrDefault
93 import Distribution.Simple.Setup
94 ( ConfigFlags(..), BuildFlags(..), ReplFlags
95 , TestFlags, BenchmarkFlags
96 , HaddockFlags(..)
97 , CleanFlags(..)
98 , CopyFlags(..), RegisterFlags(..)
99 , readPackageDbList, showPackageDbList
100 , BooleanFlag(..), optionVerbosity
101 , boolOpt, boolOpt', trueArg, falseArg
102 , optionNumJobs )
103 import Distribution.Simple.InstallDirs
104 ( PathTemplate, InstallDirs(..)
105 , toPathTemplate, fromPathTemplate, combinePathTemplate )
106 import Distribution.Version
107 ( Version, mkVersion )
108 import Distribution.Types.GivenComponent
109 ( GivenComponent(..) )
110 import Distribution.Types.PackageVersionConstraint
111 ( PackageVersionConstraint(..) )
112 import Distribution.Types.UnqualComponentName
113 ( unqualComponentNameToPackageName )
114 import Distribution.PackageDescription
115 ( BuildType(..), RepoKind(..), LibraryName(..) )
116 import Distribution.System ( Platform )
117 import Distribution.ReadE
118 ( ReadE(..), succeedReadE, parsecToReadE, parsecToReadEErr, unexpectMsgString )
119 import qualified Distribution.Compat.CharParsing as P
120 import Distribution.Verbosity
121 ( lessVerbose, normal, verboseNoFlags, verboseNoTimestamp )
122 import Distribution.Simple.Utils
123 ( wrapText )
124 import Distribution.Client.GlobalFlags
125 ( GlobalFlags(..), defaultGlobalFlags
126 , RepoContext(..), withRepoContext
128 import Distribution.Client.ManpageFlags (ManpageFlags, defaultManpageFlags, manpageOptions)
129 import Distribution.FieldGrammar.Newtypes (SpecVersion (..))
131 import Data.List
132 ( deleteFirstsBy )
133 import System.FilePath
134 ( (</>) )
136 globalCommand :: [Command action] -> CommandUI GlobalFlags
137 globalCommand commands = CommandUI {
138 commandName = "",
139 commandSynopsis =
140 "Command line interface to the Haskell Cabal infrastructure.",
141 commandUsage = \pname ->
142 "See http://www.haskell.org/cabal/ for more information.\n"
143 ++ "\n"
144 ++ "Usage: " ++ pname ++ " [GLOBAL FLAGS] [COMMAND [FLAGS]]\n",
145 commandDescription = Just $ \pname ->
147 commands' = commands ++ [commandAddAction helpCommandUI undefined]
148 cmdDescs = getNormalCommandDescriptions commands'
149 -- if new commands are added, we want them to appear even if they
150 -- are not included in the custom listing below. Thus, we calculate
151 -- the `otherCmds` list and append it under the `other` category.
152 -- Alternatively, a new testcase could be added that ensures that
153 -- the set of commands listed here is equal to the set of commands
154 -- that are actually available.
155 otherCmds = deleteFirstsBy (==) (map fst cmdDescs)
156 [ "help"
157 , "update"
158 , "install"
159 , "fetch"
160 , "list"
161 , "info"
162 , "user-config"
163 , "get"
164 , "unpack"
165 , "init"
166 , "configure"
167 , "build"
168 , "clean"
169 , "run"
170 , "repl"
171 , "test"
172 , "bench"
173 , "check"
174 , "sdist"
175 , "upload"
176 , "report"
177 , "freeze"
178 , "gen-bounds"
179 , "outdated"
180 , "haddock"
181 , "hscolour"
182 , "exec"
183 , "new-build"
184 , "new-configure"
185 , "new-repl"
186 , "new-freeze"
187 , "new-run"
188 , "new-test"
189 , "new-bench"
190 , "new-haddock"
191 , "new-exec"
192 , "new-update"
193 , "new-install"
194 , "new-clean"
195 , "new-sdist"
196 , "list-bin"
197 -- v1 commands, stateful style
198 , "v1-build"
199 , "v1-configure"
200 , "v1-repl"
201 , "v1-freeze"
202 , "v1-run"
203 , "v1-test"
204 , "v1-bench"
205 , "v1-haddock"
206 , "v1-exec"
207 , "v1-update"
208 , "v1-install"
209 , "v1-clean"
210 , "v1-sdist"
211 , "v1-doctest"
212 , "v1-copy"
213 , "v1-register"
214 , "v1-reconfigure"
215 -- v2 commands, nix-style
216 , "v2-build"
217 , "v2-configure"
218 , "v2-repl"
219 , "v2-freeze"
220 , "v2-run"
221 , "v2-test"
222 , "v2-bench"
223 , "v2-haddock"
224 , "v2-exec"
225 , "v2-update"
226 , "v2-install"
227 , "v2-clean"
228 , "v2-sdist"
230 maxlen = maximum $ [length name | (name, _) <- cmdDescs]
231 align str = str ++ replicate (maxlen - length str) ' '
232 startGroup n = " ["++n++"]"
233 par = ""
234 addCmd n = case lookup n cmdDescs of
235 Nothing -> ""
236 Just d -> " " ++ align n ++ " " ++ d
238 "Commands:\n"
239 ++ unlines (
240 [ startGroup "global"
241 , addCmd "user-config"
242 , addCmd "help"
243 , par
244 , startGroup "package database"
245 , addCmd "update"
246 , addCmd "list"
247 , addCmd "info"
248 , par
249 , startGroup "initialization and download"
250 , addCmd "init"
251 , addCmd "fetch"
252 , addCmd "get"
253 , par
254 , startGroup "project configuration"
255 , addCmd "configure"
256 , addCmd "freeze"
257 , addCmd "gen-bounds"
258 , addCmd "outdated"
259 , par
260 , startGroup "project building and installing"
261 , addCmd "build"
262 , addCmd "install"
263 , addCmd "haddock"
264 , addCmd "haddock-project"
265 , addCmd "clean"
266 , par
267 , startGroup "running and testing"
268 , addCmd "list-bin"
269 , addCmd "repl"
270 , addCmd "run"
271 , addCmd "bench"
272 , addCmd "test"
273 , addCmd "exec"
274 , par
275 , startGroup "sanity checks and shipping"
276 , addCmd "check"
277 , addCmd "sdist"
278 , addCmd "upload"
279 , addCmd "report"
280 , par
281 , startGroup "deprecated"
282 , addCmd "unpack"
283 , addCmd "hscolour"
284 , par
285 , startGroup "new-style projects (forwards-compatible aliases)"
286 , addCmd "v2-build"
287 , addCmd "v2-configure"
288 , addCmd "v2-repl"
289 , addCmd "v2-run"
290 , addCmd "v2-test"
291 , addCmd "v2-bench"
292 , addCmd "v2-freeze"
293 , addCmd "v2-haddock"
294 , addCmd "v2-exec"
295 , addCmd "v2-update"
296 , addCmd "v2-install"
297 , addCmd "v2-clean"
298 , addCmd "v2-sdist"
299 , par
300 , startGroup "legacy command aliases"
301 , addCmd "v1-build"
302 , addCmd "v1-configure"
303 , addCmd "v1-repl"
304 , addCmd "v1-run"
305 , addCmd "v1-test"
306 , addCmd "v1-bench"
307 , addCmd "v1-freeze"
308 , addCmd "v1-haddock"
309 , addCmd "v1-install"
310 , addCmd "v1-clean"
311 , addCmd "v1-copy"
312 , addCmd "v1-register"
313 , addCmd "v1-reconfigure"
314 ] ++ if null otherCmds then [] else par
315 :startGroup "other"
316 :[addCmd n | n <- otherCmds])
317 ++ "\n"
318 ++ "For more information about a command use:\n"
319 ++ " " ++ pname ++ " COMMAND --help\n"
320 ++ "or " ++ pname ++ " help COMMAND\n"
321 ++ "\n"
322 ++ "To install Cabal packages from hackage use:\n"
323 ++ " " ++ pname ++ " install foo [--dry-run]\n"
324 ++ "\n"
325 ++ "Occasionally you need to update the list of available packages:\n"
326 ++ " " ++ pname ++ " update\n",
327 commandNotes = Nothing,
328 commandDefaultFlags = mempty,
329 commandOptions = args
331 where
332 args :: ShowOrParseArgs -> [OptionField GlobalFlags]
333 args ShowArgs = argsShown
334 args ParseArgs = argsShown ++ argsNotShown
336 -- arguments we want to show in the help
337 argsShown :: [OptionField GlobalFlags]
338 argsShown = [
339 option ['V'] ["version"]
340 "Print version information"
341 globalVersion (\v flags -> flags { globalVersion = v })
342 trueArg
344 ,option [] ["numeric-version"]
345 "Print just the version number"
346 globalNumericVersion (\v flags -> flags { globalNumericVersion = v })
347 trueArg
349 ,option [] ["config-file"]
350 "Set an alternate location for the config file"
351 globalConfigFile (\v flags -> flags { globalConfigFile = v })
352 (reqArgFlag "FILE")
354 ,option [] ["ignore-expiry"]
355 "Ignore expiry dates on signed metadata (use only in exceptional circumstances)"
356 globalIgnoreExpiry (\v flags -> flags { globalIgnoreExpiry = v })
357 trueArg
359 ,option [] ["http-transport"]
360 "Set a transport for http(s) requests. Accepts 'curl', 'wget', 'powershell', and 'plain-http'. (default: 'curl')"
361 globalHttpTransport (\v flags -> flags { globalHttpTransport = v })
362 (reqArgFlag "HttpTransport")
364 ,multiOption "nix"
365 globalNix (\v flags -> flags { globalNix = v })
367 optArg' "(True or False)" (maybeToFlag . (readMaybe =<<)) (\case
368 Flag True -> [Just "enable"]
369 Flag False -> [Just "disable"]
370 NoFlag -> [Just "disable"]) "" ["nix"]
371 "Nix integration: run commands through nix-shell if a 'shell.nix' file exists (default is False)",
372 noArg (Flag True) [] ["enable-nix"]
373 "Enable Nix integration: run commands through nix-shell if a 'shell.nix' file exists",
374 noArg (Flag False) [] ["disable-nix"]
375 "Disable Nix integration"
378 ,option [] ["store-dir", "storedir"]
379 "The location of the build store"
380 globalStoreDir (\v flags -> flags { globalStoreDir = v })
381 (reqArgFlag "DIR")
383 , option [] ["active-repositories"]
384 "The active package repositories (set to ':none' to disable all repositories)"
385 globalActiveRepos (\v flags -> flags { globalActiveRepos = v })
386 (reqArg "REPOS" (parsecToReadE (\err -> "Error parsing active-repositories: " ++ err)
387 (toFlag `fmap` parsec))
388 (map prettyShow . flagToList))
391 -- arguments we don't want shown in the help
392 -- the remote repo flags are not useful compared to the more general "active-repositories" flag.
393 -- the global logs directory was only used in v1, while in v2 we have specific project config logs dirs
394 -- default-user-config is support for a relatively obscure workflow for v1-freeze.
395 argsNotShown :: [OptionField GlobalFlags]
396 argsNotShown = [
397 option [] ["remote-repo"]
398 "The name and url for a remote repository"
399 globalRemoteRepos (\v flags -> flags { globalRemoteRepos = v })
400 (reqArg' "NAME:URL" (toNubList . maybeToList . readRemoteRepo) (map showRemoteRepo . fromNubList))
402 ,option [] ["local-no-index-repo"]
403 "The name and a path for a local no-index repository"
404 globalLocalNoIndexRepos (\v flags -> flags { globalLocalNoIndexRepos = v })
405 (reqArg' "NAME:PATH" (toNubList . maybeToList . readLocalRepo) (map showLocalRepo . fromNubList))
407 ,option [] ["remote-repo-cache"]
408 "The location where downloads from all remote repos are cached"
409 globalCacheDir (\v flags -> flags { globalCacheDir = v })
410 (reqArgFlag "DIR")
412 ,option [] ["logs-dir", "logsdir"]
413 "The location to put log files"
414 globalLogsDir (\v flags -> flags { globalLogsDir = v })
415 (reqArgFlag "DIR")
417 ,option [] ["default-user-config"]
418 "Set a location for a cabal.config file for projects without their own cabal.config freeze file."
419 globalConstraintsFile (\v flags -> flags {globalConstraintsFile = v})
420 (reqArgFlag "FILE")
423 -- ------------------------------------------------------------
424 -- * Config flags
425 -- ------------------------------------------------------------
427 configureCommand :: CommandUI ConfigFlags
428 configureCommand = c
429 { commandName = "configure"
430 , commandDefaultFlags = mempty
431 , commandDescription = Just $ \_ -> wrapText $
432 "Configure how the package is built by setting "
433 ++ "package (and other) flags.\n"
434 ++ "\n"
435 ++ "The configuration affects several other commands, "
436 ++ "including v1-build, v1-test, v1-bench, v1-run, v1-repl.\n"
437 , commandUsage = \pname ->
438 "Usage: " ++ pname ++ " v1-configure [FLAGS]\n"
439 , commandNotes = Just $ \pname ->
440 (Cabal.programFlagsDescription defaultProgramDb ++ "\n")
441 ++ "Examples:\n"
442 ++ " " ++ pname ++ " v1-configure\n"
443 ++ " Configure with defaults;\n"
444 ++ " " ++ pname ++ " v1-configure --enable-tests -fcustomflag\n"
445 ++ " Configure building package including tests,\n"
446 ++ " with some package-specific flag.\n"
448 where
449 c = Cabal.configureCommand defaultProgramDb
451 configureOptions :: ShowOrParseArgs -> [OptionField ConfigFlags]
452 configureOptions = commandOptions configureCommand
454 -- | Given some 'ConfigFlags' for the version of Cabal that
455 -- cabal-install was built with, and a target older 'Version' of
456 -- Cabal that we want to pass these flags to, convert the
457 -- flags into a form that will be accepted by the older
458 -- Setup script. Generally speaking, this just means filtering
459 -- out flags that the old Cabal library doesn't understand, but
460 -- in some cases it may also mean "emulating" a feature using
461 -- some more legacy flags.
462 filterConfigureFlags :: ConfigFlags -> Version -> ConfigFlags
463 filterConfigureFlags flags cabalLibVersion
464 -- NB: we expect the latest version to be the most common case,
465 -- so test it first.
466 | cabalLibVersion >= mkVersion [3,7,0] = flags_latest
467 -- The naming convention is that flags_version gives flags with
468 -- all flags *introduced* in version eliminated.
469 -- It is NOT the latest version of Cabal library that
470 -- these flags work for; version of introduction is a more
471 -- natural metric.
472 | cabalLibVersion < mkVersion [1,3,10] = flags_1_3_10
473 | cabalLibVersion < mkVersion [1,10,0] = flags_1_10_0
474 | cabalLibVersion < mkVersion [1,12,0] = flags_1_12_0
475 | cabalLibVersion < mkVersion [1,14,0] = flags_1_14_0
476 | cabalLibVersion < mkVersion [1,18,0] = flags_1_18_0
477 | cabalLibVersion < mkVersion [1,19,1] = flags_1_19_1
478 | cabalLibVersion < mkVersion [1,19,2] = flags_1_19_2
479 | cabalLibVersion < mkVersion [1,21,1] = flags_1_21_1
480 | cabalLibVersion < mkVersion [1,22,0] = flags_1_22_0
481 | cabalLibVersion < mkVersion [1,22,1] = flags_1_22_1
482 | cabalLibVersion < mkVersion [1,23,0] = flags_1_23_0
483 | cabalLibVersion < mkVersion [1,25,0] = flags_1_25_0
484 | cabalLibVersion < mkVersion [2,1,0] = flags_2_1_0
485 | cabalLibVersion < mkVersion [2,5,0] = flags_2_5_0
486 | cabalLibVersion < mkVersion [3,7,0] = flags_3_7_0
487 | otherwise = error "the impossible just happened" -- see first guard
488 where
489 flags_latest = flags {
490 -- Cabal >= 1.19.1 uses '--dependency' and does not need '--constraint'.
491 -- Note: this is not in the wrong place. configConstraints gets
492 -- repopulated in flags_1_19_1 but it needs to be set to empty for
493 -- newer versions first.
494 configConstraints = []
497 flags_3_7_0 = flags_latest {
498 -- Cabal < 3.7 does not know about --extra-lib-dirs-static
499 configExtraLibDirsStatic = [],
501 -- Cabal < 3.7 does not understand '--enable-build-info' or '--disable-build-info'
502 configDumpBuildInfo = NoFlag
505 flags_2_5_0 = flags_3_7_0 {
506 -- Cabal < 2.5 does not understand --dependency=pkg:component=cid
507 -- (public sublibraries), so we convert it to the legacy
508 -- --dependency=pkg_or_internal_compoent=cid
509 configDependencies =
510 let convertToLegacyInternalDep (GivenComponent _ (LSubLibName cn) cid) =
511 Just $ GivenComponent
512 (unqualComponentNameToPackageName cn)
513 LMainLibName
515 convertToLegacyInternalDep (GivenComponent pn LMainLibName cid) =
516 Just $ GivenComponent pn LMainLibName cid
517 in catMaybes $ convertToLegacyInternalDep <$> configDependencies flags
518 -- Cabal < 2.5 doesn't know about '--allow-depending-on-private-libs'.
519 , configAllowDependingOnPrivateLibs = NoFlag
520 -- Cabal < 2.5 doesn't know about '--enable/disable-executable-static'.
521 , configFullyStaticExe = NoFlag
524 flags_2_1_0 = flags_2_5_0 {
525 -- Cabal < 2.1 doesn't know about -v +timestamp modifier
526 configVerbosity = fmap verboseNoTimestamp (configVerbosity flags_latest)
527 -- Cabal < 2.1 doesn't know about --<enable|disable>-static
528 , configStaticLib = NoFlag
529 , configSplitSections = NoFlag
532 flags_1_25_0 = flags_2_1_0 {
533 -- Cabal < 1.25.0 doesn't know about --dynlibdir.
534 configInstallDirs = configInstallDirs_1_25_0,
535 -- Cabal < 1.25 doesn't have extended verbosity syntax
536 configVerbosity = fmap verboseNoFlags (configVerbosity flags_2_1_0),
537 -- Cabal < 1.25 doesn't support --deterministic
538 configDeterministic = mempty
540 configInstallDirs_1_25_0 = let dirs = configInstallDirs flags in
541 dirs { dynlibdir = NoFlag
542 , libexecsubdir = NoFlag
543 , libexecdir = maybeToFlag $
544 combinePathTemplate <$> flagToMaybe (libexecdir dirs)
545 <*> flagToMaybe (libexecsubdir dirs)
547 -- Cabal < 1.23 doesn't know about '--profiling-detail'.
548 -- Cabal < 1.23 has a hacked up version of 'enable-profiling'
549 -- which we shouldn't use.
550 (tryLibProfiling, tryExeProfiling) = computeEffectiveProfiling flags
551 flags_1_23_0 = flags_1_25_0 { configProfDetail = NoFlag
552 , configProfLibDetail = NoFlag
553 , configIPID = NoFlag
554 , configProf = NoFlag
555 , configProfExe = Flag tryExeProfiling
556 , configProfLib = Flag tryLibProfiling
559 -- Cabal == 1.22.0.* had a discontinuity (see #5946 or e9a8d48a3adce34d)
560 -- due to temporary amnesia of the --*-executable-profiling flags
561 flags_1_22_1 = flags_1_23_0 { configDebugInfo = NoFlag
562 , configProfExe = NoFlag
565 -- Cabal < 1.22 doesn't know about '--disable-debug-info'.
566 flags_1_22_0 = flags_1_23_0 { configDebugInfo = NoFlag }
568 -- Cabal < 1.21.1 doesn't know about 'disable-relocatable'
569 -- Cabal < 1.21.1 doesn't know about 'enable-profiling'
570 -- (but we already dealt with it in flags_1_23_0)
571 flags_1_21_1 =
572 flags_1_22_0 { configRelocatable = NoFlag
573 , configCoverage = NoFlag
574 , configLibCoverage = configCoverage flags
576 -- Cabal < 1.19.2 doesn't know about '--exact-configuration' and
577 -- '--enable-library-stripping'.
578 flags_1_19_2 = flags_1_21_1 { configExactConfiguration = NoFlag
579 , configStripLibs = NoFlag }
580 -- Cabal < 1.19.1 uses '--constraint' instead of '--dependency'.
581 flags_1_19_1 = flags_1_19_2 { configDependencies = []
582 , configConstraints = configConstraints flags }
583 -- Cabal < 1.18.0 doesn't know about --extra-prog-path and --sysconfdir.
584 flags_1_18_0 = flags_1_19_1 { configProgramPathExtra = toNubList []
585 , configInstallDirs = configInstallDirs_1_18_0}
586 configInstallDirs_1_18_0 = (configInstallDirs flags_1_19_1) { sysconfdir = NoFlag }
587 -- Cabal < 1.14.0 doesn't know about '--disable-benchmarks'.
588 flags_1_14_0 = flags_1_18_0 { configBenchmarks = NoFlag }
589 -- Cabal < 1.12.0 doesn't know about '--enable/disable-executable-dynamic'
590 -- and '--enable/disable-library-coverage'.
591 flags_1_12_0 = flags_1_14_0 { configLibCoverage = NoFlag
592 , configDynExe = NoFlag }
593 -- Cabal < 1.10.0 doesn't know about '--disable-tests'.
594 flags_1_10_0 = flags_1_12_0 { configTests = NoFlag }
595 -- Cabal < 1.3.10 does not grok the '--constraints' flag.
596 flags_1_3_10 = flags_1_10_0 { configConstraints = [] }
598 -- | Get the package database settings from 'ConfigFlags', accounting for
599 -- @--package-db@ and @--user@ flags.
600 configPackageDB' :: ConfigFlags -> PackageDBStack
601 configPackageDB' cfg =
602 interpretPackageDbFlags userInstall (configPackageDBs cfg)
603 where
604 userInstall = Cabal.fromFlagOrDefault True (configUserInstall cfg)
606 -- | Configure the compiler, but reduce verbosity during this step.
607 configCompilerAux' :: ConfigFlags -> IO (Compiler, Platform, ProgramDb)
608 configCompilerAux' configFlags =
609 configCompilerAuxEx configFlags
610 --FIXME: make configCompilerAux use a sensible verbosity
611 { configVerbosity = fmap lessVerbose (configVerbosity configFlags) }
613 -- ------------------------------------------------------------
614 -- * Config extra flags
615 -- ------------------------------------------------------------
617 -- | cabal configure takes some extra flags beyond runghc Setup configure
619 data ConfigExFlags = ConfigExFlags {
620 configCabalVersion :: Flag Version,
621 configAppend :: Flag Bool,
622 configBackup :: Flag Bool,
623 configExConstraints :: [(UserConstraint, ConstraintSource)],
624 configPreferences :: [PackageVersionConstraint],
625 configSolver :: Flag PreSolver,
626 configAllowNewer :: Maybe AllowNewer,
627 configAllowOlder :: Maybe AllowOlder,
628 configWriteGhcEnvironmentFilesPolicy
629 :: Flag WriteGhcEnvironmentFilesPolicy
631 deriving (Eq, Show, Generic)
633 defaultConfigExFlags :: ConfigExFlags
634 defaultConfigExFlags = mempty { configSolver = Flag defaultSolver }
636 configureExCommand :: CommandUI (ConfigFlags, ConfigExFlags)
637 configureExCommand = configureCommand {
638 commandDefaultFlags = (mempty, defaultConfigExFlags),
639 commandOptions = \showOrParseArgs ->
640 liftOptions fst setFst
641 (filter ((`notElem` ["constraint", "dependency", "exact-configuration"])
642 . optionName) $ configureOptions showOrParseArgs)
643 ++ liftOptions snd setSnd
644 (configureExOptions showOrParseArgs ConstraintSourceCommandlineFlag)
646 where
647 setFst a (_,b) = (a,b)
648 setSnd b (a,_) = (a,b)
650 configureExOptions :: ShowOrParseArgs
651 -> ConstraintSource
652 -> [OptionField ConfigExFlags]
653 configureExOptions _showOrParseArgs src =
654 [ option [] ["cabal-lib-version"]
655 ("Select which version of the Cabal lib to use to build packages "
656 ++ "(useful for testing).")
657 configCabalVersion (\v flags -> flags { configCabalVersion = v })
658 (reqArg "VERSION" (parsecToReadE ("Cannot parse cabal lib version: "++)
659 (fmap toFlag parsec))
660 (map prettyShow. flagToList))
661 , option "" ["append"]
662 "appending the new config to the old config file"
663 configAppend (\v flags -> flags { configAppend = v })
664 (boolOpt [] [])
665 , option "" ["backup"]
666 "the backup of the config file before any alterations"
667 configBackup (\v flags -> flags { configBackup = v })
668 (boolOpt [] [])
669 , option "c" ["constraint"]
670 "Specify constraints on a package (version, installed/source, flags)"
671 configExConstraints (\v flags -> flags { configExConstraints = v })
672 (reqArg "CONSTRAINT"
673 ((\x -> [(x, src)]) `fmap` ReadE readUserConstraint)
674 (map $ prettyShow . fst))
676 , option [] ["preference"]
677 "Specify preferences (soft constraints) on the version of a package"
678 configPreferences (\v flags -> flags { configPreferences = v })
679 (reqArg "CONSTRAINT"
680 (parsecToReadE (const "dependency expected")
681 (fmap (\x -> [x]) parsec))
682 (map prettyShow))
684 , optionSolver configSolver (\v flags -> flags { configSolver = v })
686 , option [] ["allow-older"]
687 ("Ignore lower bounds in all dependencies or DEPS")
688 (fmap unAllowOlder . configAllowOlder)
689 (\v flags -> flags { configAllowOlder = fmap AllowOlder v})
690 (optArg "DEPS"
691 (parsecToReadEErr unexpectMsgString relaxDepsParser)
692 (Just RelaxDepsAll) relaxDepsPrinter)
694 , option [] ["allow-newer"]
695 ("Ignore upper bounds in all dependencies or DEPS")
696 (fmap unAllowNewer . configAllowNewer)
697 (\v flags -> flags { configAllowNewer = fmap AllowNewer v})
698 (optArg "DEPS"
699 (parsecToReadEErr unexpectMsgString relaxDepsParser)
700 (Just RelaxDepsAll) relaxDepsPrinter)
702 , option [] ["write-ghc-environment-files"]
703 ("Whether to create a .ghc.environment file after a successful build"
704 ++ " (v2-build only)")
705 configWriteGhcEnvironmentFilesPolicy
706 (\v flags -> flags { configWriteGhcEnvironmentFilesPolicy = v})
707 (reqArg "always|never|ghc8.4.4+"
708 writeGhcEnvironmentFilesPolicyParser
709 writeGhcEnvironmentFilesPolicyPrinter)
713 writeGhcEnvironmentFilesPolicyParser :: ReadE (Flag WriteGhcEnvironmentFilesPolicy)
714 writeGhcEnvironmentFilesPolicyParser = ReadE $ \case
715 "always" -> Right $ Flag AlwaysWriteGhcEnvironmentFiles
716 "never" -> Right $ Flag NeverWriteGhcEnvironmentFiles
717 "ghc8.4.4+" -> Right $ Flag WriteGhcEnvironmentFilesOnlyForGhc844AndNewer
718 policy -> Left $ "Cannot parse the GHC environment file write policy '"
719 <> policy <> "'"
721 writeGhcEnvironmentFilesPolicyPrinter
722 :: Flag WriteGhcEnvironmentFilesPolicy -> [String]
723 writeGhcEnvironmentFilesPolicyPrinter = \case
724 (Flag AlwaysWriteGhcEnvironmentFiles) -> ["always"]
725 (Flag NeverWriteGhcEnvironmentFiles) -> ["never"]
726 (Flag WriteGhcEnvironmentFilesOnlyForGhc844AndNewer) -> ["ghc8.4.4+"]
727 NoFlag -> []
730 relaxDepsParser :: CabalParsing m => m (Maybe RelaxDeps)
731 relaxDepsParser = do
732 rs <- P.sepBy parsec (P.char ',')
733 if null rs
734 then fail $ "empty argument list is not allowed. "
735 ++ "Note: use --allow-newer without the equals sign to permit all "
736 ++ "packages to use newer versions."
737 else return . Just . RelaxDepsSome . toList $ rs
739 relaxDepsPrinter :: (Maybe RelaxDeps) -> [Maybe String]
740 relaxDepsPrinter Nothing = []
741 relaxDepsPrinter (Just RelaxDepsAll) = [Nothing]
742 relaxDepsPrinter (Just (RelaxDepsSome pkgs)) = map (Just . prettyShow) $ pkgs
745 instance Monoid ConfigExFlags where
746 mempty = gmempty
747 mappend = (<>)
749 instance Semigroup ConfigExFlags where
750 (<>) = gmappend
752 reconfigureCommand :: CommandUI (ConfigFlags, ConfigExFlags)
753 reconfigureCommand
754 = configureExCommand
755 { commandName = "reconfigure"
756 , commandSynopsis = "Reconfigure the package if necessary."
757 , commandDescription = Just $ \pname -> wrapText $
758 "Run `configure` with the most recently used flags, or append FLAGS "
759 ++ "to the most recently used configuration. "
760 ++ "Accepts the same flags as `" ++ pname ++ " v1-configure'. "
761 ++ "If the package has never been configured, the default flags are "
762 ++ "used."
763 , commandNotes = Just $ \pname ->
764 "Examples:\n"
765 ++ " " ++ pname ++ " v1-reconfigure\n"
766 ++ " Configure with the most recently used flags.\n"
767 ++ " " ++ pname ++ " v1-reconfigure -w PATH\n"
768 ++ " Reconfigure with the most recently used flags,\n"
769 ++ " but use the compiler at PATH.\n\n"
770 , commandUsage = usageAlternatives "v1-reconfigure" [ "[FLAGS]" ]
771 , commandDefaultFlags = mempty
774 -- ------------------------------------------------------------
775 -- * Build flags
776 -- ------------------------------------------------------------
778 buildCommand :: CommandUI BuildFlags
779 buildCommand = parent {
780 commandName = "build",
781 commandDescription = Just $ \_ -> wrapText $
782 "Components encompass executables, tests, and benchmarks.\n"
783 ++ "\n"
784 ++ "Affected by configuration options, see `v1-configure`.\n",
785 commandDefaultFlags = commandDefaultFlags parent,
786 commandUsage = usageAlternatives "v1-build" $
787 [ "[FLAGS]", "COMPONENTS [FLAGS]" ],
788 commandOptions = commandOptions parent
789 , commandNotes = Just $ \pname ->
790 "Examples:\n"
791 ++ " " ++ pname ++ " v1-build "
792 ++ " All the components in the package\n"
793 ++ " " ++ pname ++ " v1-build foo "
794 ++ " A component (i.e. lib, exe, test suite)\n\n"
795 ++ Cabal.programFlagsDescription defaultProgramDb
797 where
798 parent = Cabal.buildCommand defaultProgramDb
800 -- ------------------------------------------------------------
801 -- * Test flags
802 -- ------------------------------------------------------------
804 -- | Given some 'TestFlags' for the version of Cabal that
805 -- cabal-install was built with, and a target older 'Version' of
806 -- Cabal that we want to pass these flags to, convert the
807 -- flags into a form that will be accepted by the older
808 -- Setup script. Generally speaking, this just means filtering
809 -- out flags that the old Cabal library doesn't understand, but
810 -- in some cases it may also mean "emulating" a feature using
811 -- some more legacy flags.
812 filterTestFlags :: TestFlags -> Version -> TestFlags
813 filterTestFlags flags cabalLibVersion
814 -- NB: we expect the latest version to be the most common case,
815 -- so test it first.
816 | cabalLibVersion >= mkVersion [3,0,0] = flags_latest
817 -- The naming convention is that flags_version gives flags with
818 -- all flags *introduced* in version eliminated.
819 -- It is NOT the latest version of Cabal library that
820 -- these flags work for; version of introduction is a more
821 -- natural metric.
822 | cabalLibVersion < mkVersion [3,0,0] = flags_3_0_0
823 | otherwise = error "the impossible just happened" -- see first guard
824 where
825 flags_latest = flags
826 flags_3_0_0 = flags_latest {
827 -- Cabal < 3.0 doesn't know about --test-wrapper
828 Cabal.testWrapper = NoFlag
831 -- ------------------------------------------------------------
832 -- * Repl command
833 -- ------------------------------------------------------------
835 replCommand :: CommandUI ReplFlags
836 replCommand = parent {
837 commandName = "repl",
838 commandDescription = Just $ \pname -> wrapText $
839 "If the current directory contains no package, ignores COMPONENT "
840 ++ "parameters and opens an interactive interpreter session;\n"
841 ++ "\n"
842 ++ "Otherwise, (re)configures with the given or default flags, and "
843 ++ "loads the interpreter with the relevant modules. For executables, "
844 ++ "tests and benchmarks, loads the main module (and its "
845 ++ "dependencies); for libraries all exposed/other modules.\n"
846 ++ "\n"
847 ++ "The default component is the library itself, or the executable "
848 ++ "if that is the only component.\n"
849 ++ "\n"
850 ++ "Support for loading specific modules is planned but not "
851 ++ "implemented yet. For certain scenarios, `" ++ pname
852 ++ " v1-exec -- ghci :l Foo` may be used instead. Note that `v1-exec` will "
853 ++ "not (re)configure and you will have to specify the location of "
854 ++ "other modules, if required.\n",
855 commandUsage = \pname -> "Usage: " ++ pname ++ " v1-repl [COMPONENT] [FLAGS]\n",
856 commandDefaultFlags = commandDefaultFlags parent,
857 commandOptions = commandOptions parent,
858 commandNotes = Just $ \pname ->
859 "Examples:\n"
860 ++ " " ++ pname ++ " v1-repl "
861 ++ " The first component in the package\n"
862 ++ " " ++ pname ++ " v1-repl foo "
863 ++ " A named component (i.e. lib, exe, test suite)\n"
864 ++ " " ++ pname ++ " v1-repl --ghc-options=\"-lstdc++\""
865 ++ " Specifying flags for interpreter\n"
867 where
868 parent = Cabal.replCommand defaultProgramDb
870 -- ------------------------------------------------------------
871 -- * Test command
872 -- ------------------------------------------------------------
874 testCommand :: CommandUI (BuildFlags, TestFlags)
875 testCommand = parent {
876 commandName = "test",
877 commandDescription = Just $ \pname -> wrapText $
878 "If necessary (re)configures with `--enable-tests` flag and builds"
879 ++ " the test suite.\n"
880 ++ "\n"
881 ++ "Remember that the tests' dependencies must be installed if there"
882 ++ " are additional ones; e.g. with `" ++ pname
883 ++ " v1-install --only-dependencies --enable-tests`.\n"
884 ++ "\n"
885 ++ "By defining UserHooks in a custom Setup.hs, the package can"
886 ++ " define actions to be executed before and after running tests.\n",
887 commandUsage = usageAlternatives "v1-test"
888 [ "[FLAGS]", "TESTCOMPONENTS [FLAGS]" ],
889 commandDefaultFlags = (Cabal.defaultBuildFlags, commandDefaultFlags parent),
890 commandOptions =
891 \showOrParseArgs -> liftOptions get1 set1
892 (Cabal.buildOptions progDb showOrParseArgs)
894 liftOptions get2 set2
895 (commandOptions parent showOrParseArgs)
897 where
898 get1 (a,_) = a; set1 a (_,b) = (a,b)
899 get2 (_,b) = b; set2 b (a,_) = (a,b)
901 parent = Cabal.testCommand
902 progDb = defaultProgramDb
904 -- ------------------------------------------------------------
905 -- * Bench command
906 -- ------------------------------------------------------------
908 benchmarkCommand :: CommandUI (BuildFlags, BenchmarkFlags)
909 benchmarkCommand = parent {
910 commandName = "bench",
911 commandUsage = usageAlternatives "v1-bench"
912 [ "[FLAGS]", "BENCHCOMPONENTS [FLAGS]" ],
913 commandDescription = Just $ \pname -> wrapText $
914 "If necessary (re)configures with `--enable-benchmarks` flag and"
915 ++ " builds the benchmarks.\n"
916 ++ "\n"
917 ++ "Remember that the benchmarks' dependencies must be installed if"
918 ++ " there are additional ones; e.g. with `" ++ pname
919 ++ " v1-install --only-dependencies --enable-benchmarks`.\n"
920 ++ "\n"
921 ++ "By defining UserHooks in a custom Setup.hs, the package can"
922 ++ " define actions to be executed before and after running"
923 ++ " benchmarks.\n",
924 commandDefaultFlags = (Cabal.defaultBuildFlags, commandDefaultFlags parent),
925 commandOptions =
926 \showOrParseArgs -> liftOptions get1 set1
927 (Cabal.buildOptions progDb showOrParseArgs)
929 liftOptions get2 set2
930 (commandOptions parent showOrParseArgs)
932 where
933 get1 (a,_) = a; set1 a (_,b) = (a,b)
934 get2 (_,b) = b; set2 b (a,_) = (a,b)
936 parent = Cabal.benchmarkCommand
937 progDb = defaultProgramDb
939 -- ------------------------------------------------------------
940 -- * Fetch command
941 -- ------------------------------------------------------------
943 data FetchFlags = FetchFlags {
944 -- fetchOutput :: Flag FilePath,
945 fetchDeps :: Flag Bool,
946 fetchDryRun :: Flag Bool,
947 fetchSolver :: Flag PreSolver,
948 fetchMaxBackjumps :: Flag Int,
949 fetchReorderGoals :: Flag ReorderGoals,
950 fetchCountConflicts :: Flag CountConflicts,
951 fetchFineGrainedConflicts :: Flag FineGrainedConflicts,
952 fetchMinimizeConflictSet :: Flag MinimizeConflictSet,
953 fetchIndependentGoals :: Flag IndependentGoals,
954 fetchPreferOldest :: Flag PreferOldest,
955 fetchShadowPkgs :: Flag ShadowPkgs,
956 fetchStrongFlags :: Flag StrongFlags,
957 fetchAllowBootLibInstalls :: Flag AllowBootLibInstalls,
958 fetchOnlyConstrained :: Flag OnlyConstrained,
959 fetchTests :: Flag Bool,
960 fetchBenchmarks :: Flag Bool,
961 fetchVerbosity :: Flag Verbosity
964 defaultFetchFlags :: FetchFlags
965 defaultFetchFlags = FetchFlags {
966 -- fetchOutput = mempty,
967 fetchDeps = toFlag True,
968 fetchDryRun = toFlag False,
969 fetchSolver = Flag defaultSolver,
970 fetchMaxBackjumps = Flag defaultMaxBackjumps,
971 fetchReorderGoals = Flag (ReorderGoals False),
972 fetchCountConflicts = Flag (CountConflicts True),
973 fetchFineGrainedConflicts = Flag (FineGrainedConflicts True),
974 fetchMinimizeConflictSet = Flag (MinimizeConflictSet False),
975 fetchIndependentGoals = Flag (IndependentGoals False),
976 fetchPreferOldest = Flag (PreferOldest False),
977 fetchShadowPkgs = Flag (ShadowPkgs False),
978 fetchStrongFlags = Flag (StrongFlags False),
979 fetchAllowBootLibInstalls = Flag (AllowBootLibInstalls False),
980 fetchOnlyConstrained = Flag OnlyConstrainedNone,
981 fetchTests = toFlag False,
982 fetchBenchmarks = toFlag False,
983 fetchVerbosity = toFlag normal
986 fetchCommand :: CommandUI FetchFlags
987 fetchCommand = CommandUI {
988 commandName = "fetch",
989 commandSynopsis = "Downloads packages for later installation.",
990 commandUsage = usageAlternatives "fetch" [ "[FLAGS] PACKAGES"
992 commandDescription = Just $ \_ ->
993 "Note that it currently is not possible to fetch the dependencies for a\n"
994 ++ "package in the current directory.\n",
995 commandNotes = Nothing,
996 commandDefaultFlags = defaultFetchFlags,
997 commandOptions = \ showOrParseArgs -> [
998 optionVerbosity fetchVerbosity (\v flags -> flags { fetchVerbosity = v })
1000 -- , option "o" ["output"]
1001 -- "Put the package(s) somewhere specific rather than the usual cache."
1002 -- fetchOutput (\v flags -> flags { fetchOutput = v })
1003 -- (reqArgFlag "PATH")
1005 , option [] ["dependencies", "deps"]
1006 "Resolve and fetch dependencies (default)"
1007 fetchDeps (\v flags -> flags { fetchDeps = v })
1008 trueArg
1010 , option [] ["no-dependencies", "no-deps"]
1011 "Ignore dependencies"
1012 fetchDeps (\v flags -> flags { fetchDeps = v })
1013 falseArg
1015 , option [] ["dry-run"]
1016 "Do not install anything, only print what would be installed."
1017 fetchDryRun (\v flags -> flags { fetchDryRun = v })
1018 trueArg
1020 , option "" ["tests"]
1021 "dependency checking and compilation for test suites listed in the package description file."
1022 fetchTests (\v flags -> flags { fetchTests = v })
1023 (boolOpt [] [])
1025 , option "" ["benchmarks"]
1026 "dependency checking and compilation for benchmarks listed in the package description file."
1027 fetchBenchmarks (\v flags -> flags { fetchBenchmarks = v })
1028 (boolOpt [] [])
1030 ] ++
1032 optionSolver fetchSolver (\v flags -> flags { fetchSolver = v }) :
1033 optionSolverFlags showOrParseArgs
1034 fetchMaxBackjumps (\v flags -> flags { fetchMaxBackjumps = v })
1035 fetchReorderGoals (\v flags -> flags { fetchReorderGoals = v })
1036 fetchCountConflicts (\v flags -> flags { fetchCountConflicts = v })
1037 fetchFineGrainedConflicts (\v flags -> flags { fetchFineGrainedConflicts = v })
1038 fetchMinimizeConflictSet (\v flags -> flags { fetchMinimizeConflictSet = v })
1039 fetchIndependentGoals (\v flags -> flags { fetchIndependentGoals = v })
1040 fetchPreferOldest (\v flags -> flags { fetchPreferOldest = v })
1041 fetchShadowPkgs (\v flags -> flags { fetchShadowPkgs = v })
1042 fetchStrongFlags (\v flags -> flags { fetchStrongFlags = v })
1043 fetchAllowBootLibInstalls (\v flags -> flags { fetchAllowBootLibInstalls = v })
1044 fetchOnlyConstrained (\v flags -> flags { fetchOnlyConstrained = v })
1048 -- ------------------------------------------------------------
1049 -- * Freeze command
1050 -- ------------------------------------------------------------
1052 data FreezeFlags = FreezeFlags {
1053 freezeDryRun :: Flag Bool,
1054 freezeTests :: Flag Bool,
1055 freezeBenchmarks :: Flag Bool,
1056 freezeSolver :: Flag PreSolver,
1057 freezeMaxBackjumps :: Flag Int,
1058 freezeReorderGoals :: Flag ReorderGoals,
1059 freezeCountConflicts :: Flag CountConflicts,
1060 freezeFineGrainedConflicts :: Flag FineGrainedConflicts,
1061 freezeMinimizeConflictSet :: Flag MinimizeConflictSet,
1062 freezeIndependentGoals :: Flag IndependentGoals,
1063 freezePreferOldest :: Flag PreferOldest,
1064 freezeShadowPkgs :: Flag ShadowPkgs,
1065 freezeStrongFlags :: Flag StrongFlags,
1066 freezeAllowBootLibInstalls :: Flag AllowBootLibInstalls,
1067 freezeOnlyConstrained :: Flag OnlyConstrained,
1068 freezeVerbosity :: Flag Verbosity
1071 defaultFreezeFlags :: FreezeFlags
1072 defaultFreezeFlags = FreezeFlags {
1073 freezeDryRun = toFlag False,
1074 freezeTests = toFlag False,
1075 freezeBenchmarks = toFlag False,
1076 freezeSolver = Flag defaultSolver,
1077 freezeMaxBackjumps = Flag defaultMaxBackjumps,
1078 freezeReorderGoals = Flag (ReorderGoals False),
1079 freezeCountConflicts = Flag (CountConflicts True),
1080 freezeFineGrainedConflicts = Flag (FineGrainedConflicts True),
1081 freezeMinimizeConflictSet = Flag (MinimizeConflictSet False),
1082 freezeIndependentGoals = Flag (IndependentGoals False),
1083 freezePreferOldest = Flag (PreferOldest False),
1084 freezeShadowPkgs = Flag (ShadowPkgs False),
1085 freezeStrongFlags = Flag (StrongFlags False),
1086 freezeAllowBootLibInstalls = Flag (AllowBootLibInstalls False),
1087 freezeOnlyConstrained = Flag OnlyConstrainedNone,
1088 freezeVerbosity = toFlag normal
1091 freezeCommand :: CommandUI FreezeFlags
1092 freezeCommand = CommandUI {
1093 commandName = "freeze",
1094 commandSynopsis = "Freeze dependencies.",
1095 commandDescription = Just $ \_ -> wrapText $
1096 "Calculates a valid set of dependencies and their exact versions. "
1097 ++ "If successful, saves the result to the file `cabal.config`.\n"
1098 ++ "\n"
1099 ++ "The package versions specified in `cabal.config` will be used for "
1100 ++ "any future installs.\n"
1101 ++ "\n"
1102 ++ "An existing `cabal.config` is ignored and overwritten.\n",
1103 commandNotes = Nothing,
1104 commandUsage = usageFlags "freeze",
1105 commandDefaultFlags = defaultFreezeFlags,
1106 commandOptions = \ showOrParseArgs -> [
1107 optionVerbosity freezeVerbosity
1108 (\v flags -> flags { freezeVerbosity = v })
1110 , option [] ["dry-run"]
1111 "Do not freeze anything, only print what would be frozen"
1112 freezeDryRun (\v flags -> flags { freezeDryRun = v })
1113 trueArg
1115 , option [] ["tests"]
1116 ("freezing of the dependencies of any tests suites "
1117 ++ "in the package description file.")
1118 freezeTests (\v flags -> flags { freezeTests = v })
1119 (boolOpt [] [])
1121 , option [] ["benchmarks"]
1122 ("freezing of the dependencies of any benchmarks suites "
1123 ++ "in the package description file.")
1124 freezeBenchmarks (\v flags -> flags { freezeBenchmarks = v })
1125 (boolOpt [] [])
1127 ] ++
1129 optionSolver
1130 freezeSolver (\v flags -> flags { freezeSolver = v }):
1131 optionSolverFlags showOrParseArgs
1132 freezeMaxBackjumps (\v flags -> flags { freezeMaxBackjumps = v })
1133 freezeReorderGoals (\v flags -> flags { freezeReorderGoals = v })
1134 freezeCountConflicts (\v flags -> flags { freezeCountConflicts = v })
1135 freezeFineGrainedConflicts (\v flags -> flags { freezeFineGrainedConflicts = v })
1136 freezeMinimizeConflictSet (\v flags -> flags { freezeMinimizeConflictSet = v })
1137 freezeIndependentGoals (\v flags -> flags { freezeIndependentGoals = v })
1138 freezePreferOldest (\v flags -> flags { freezePreferOldest = v })
1139 freezeShadowPkgs (\v flags -> flags { freezeShadowPkgs = v })
1140 freezeStrongFlags (\v flags -> flags { freezeStrongFlags = v })
1141 freezeAllowBootLibInstalls (\v flags -> flags { freezeAllowBootLibInstalls = v })
1142 freezeOnlyConstrained (\v flags -> flags { freezeOnlyConstrained = v })
1146 -- ------------------------------------------------------------
1147 -- * 'gen-bounds' command
1148 -- ------------------------------------------------------------
1150 genBoundsCommand :: CommandUI FreezeFlags
1151 genBoundsCommand = CommandUI {
1152 commandName = "gen-bounds",
1153 commandSynopsis = "Generate dependency bounds.",
1154 commandDescription = Just $ \_ -> wrapText $
1155 "Generates bounds for all dependencies that do not currently have them. "
1156 ++ "Generated bounds are printed to stdout. "
1157 ++ "You can then paste them into your .cabal file.\n"
1158 ++ "\n",
1159 commandNotes = Nothing,
1160 commandUsage = usageFlags "gen-bounds",
1161 commandDefaultFlags = defaultFreezeFlags,
1162 commandOptions = \ _ -> [
1163 optionVerbosity freezeVerbosity (\v flags -> flags { freezeVerbosity = v })
1167 -- ------------------------------------------------------------
1168 -- * Update command
1169 -- ------------------------------------------------------------
1171 data UpdateFlags
1172 = UpdateFlags {
1173 updateVerbosity :: Flag Verbosity,
1174 updateIndexState :: Flag TotalIndexState
1175 } deriving Generic
1177 defaultUpdateFlags :: UpdateFlags
1178 defaultUpdateFlags
1179 = UpdateFlags {
1180 updateVerbosity = toFlag normal,
1181 updateIndexState = toFlag headTotalIndexState
1184 -- ------------------------------------------------------------
1185 -- * Other commands
1186 -- ------------------------------------------------------------
1188 cleanCommand :: CommandUI CleanFlags
1189 cleanCommand = Cabal.cleanCommand
1190 { commandUsage = \pname ->
1191 "Usage: " ++ pname ++ " v1-clean [FLAGS]\n"
1194 checkCommand :: CommandUI (Flag Verbosity)
1195 checkCommand = CommandUI {
1196 commandName = "check",
1197 commandSynopsis = "Check the package for common mistakes.",
1198 commandDescription = Just $ \_ -> wrapText $
1199 "Expects a .cabal package file in the current directory.\n"
1200 ++ "\n"
1201 ++ "The checks correspond to the requirements to packages on Hackage. "
1202 ++ "If no errors and warnings are reported, Hackage will accept this "
1203 ++ "package.\n",
1204 commandNotes = Nothing,
1205 commandUsage = usageFlags "check",
1206 commandDefaultFlags = toFlag normal,
1207 commandOptions = \_ -> [optionVerbosity id const]
1210 formatCommand :: CommandUI (Flag Verbosity)
1211 formatCommand = CommandUI {
1212 commandName = "format",
1213 commandSynopsis = "Reformat the .cabal file using the standard style.",
1214 commandDescription = Nothing,
1215 commandNotes = Nothing,
1216 commandUsage = usageAlternatives "format" ["[FILE]"],
1217 commandDefaultFlags = toFlag normal,
1218 commandOptions = \_ -> []
1221 manpageCommand :: CommandUI ManpageFlags
1222 manpageCommand = CommandUI {
1223 commandName = "man",
1224 commandSynopsis = "Outputs manpage source.",
1225 commandDescription = Just $ \_ ->
1226 "Output manpage source to STDOUT.\n",
1227 commandNotes = Nothing,
1228 commandUsage = usageFlags "man",
1229 commandDefaultFlags = defaultManpageFlags,
1230 commandOptions = manpageOptions
1233 runCommand :: CommandUI BuildFlags
1234 runCommand = CommandUI {
1235 commandName = "run",
1236 commandSynopsis = "Builds and runs an executable.",
1237 commandDescription = Just $ \pname -> wrapText $
1238 "Builds and then runs the specified executable. If no executable is "
1239 ++ "specified, but the package contains just one executable, that one "
1240 ++ "is built and executed.\n"
1241 ++ "\n"
1242 ++ "Use `" ++ pname ++ " v1-test --show-details=streaming` to run a "
1243 ++ "test-suite and get its full output.\n",
1244 commandNotes = Just $ \pname ->
1245 "Examples:\n"
1246 ++ " " ++ pname ++ " v1-run\n"
1247 ++ " Run the only executable in the current package;\n"
1248 ++ " " ++ pname ++ " v1-run foo -- --fooflag\n"
1249 ++ " Works similar to `./foo --fooflag`.\n",
1250 commandUsage = usageAlternatives "v1-run"
1251 ["[FLAGS] [EXECUTABLE] [-- EXECUTABLE_FLAGS]"],
1252 commandDefaultFlags = mempty,
1253 commandOptions = commandOptions parent
1255 where
1256 parent = Cabal.buildCommand defaultProgramDb
1258 -- ------------------------------------------------------------
1259 -- * Report flags
1260 -- ------------------------------------------------------------
1262 data ReportFlags = ReportFlags {
1263 reportUsername :: Flag Username,
1264 reportPassword :: Flag Password,
1265 reportVerbosity :: Flag Verbosity
1266 } deriving Generic
1268 defaultReportFlags :: ReportFlags
1269 defaultReportFlags = ReportFlags {
1270 reportUsername = mempty,
1271 reportPassword = mempty,
1272 reportVerbosity = toFlag normal
1275 reportCommand :: CommandUI ReportFlags
1276 reportCommand = CommandUI {
1277 commandName = "report",
1278 commandSynopsis = "Upload build reports to a remote server.",
1279 commandDescription = Nothing,
1280 commandNotes = Just $ \_ ->
1281 "You can store your Hackage login in the ~/.config/cabal/config file\n",
1282 commandUsage = usageAlternatives "report" ["[FLAGS]"],
1283 commandDefaultFlags = defaultReportFlags,
1284 commandOptions = \_ ->
1285 [optionVerbosity reportVerbosity (\v flags -> flags { reportVerbosity = v })
1287 ,option ['u'] ["username"]
1288 "Hackage username."
1289 reportUsername (\v flags -> flags { reportUsername = v })
1290 (reqArg' "USERNAME" (toFlag . Username)
1291 (flagToList . fmap unUsername))
1293 ,option ['p'] ["password"]
1294 "Hackage password."
1295 reportPassword (\v flags -> flags { reportPassword = v })
1296 (reqArg' "PASSWORD" (toFlag . Password)
1297 (flagToList . fmap unPassword))
1301 instance Monoid ReportFlags where
1302 mempty = gmempty
1303 mappend = (<>)
1305 instance Semigroup ReportFlags where
1306 (<>) = gmappend
1308 -- ------------------------------------------------------------
1309 -- * Get flags
1310 -- ------------------------------------------------------------
1312 data GetFlags = GetFlags {
1313 getDestDir :: Flag FilePath,
1314 getOnlyPkgDescr :: Flag Bool,
1315 getPristine :: Flag Bool,
1316 getIndexState :: Flag TotalIndexState,
1317 getActiveRepos :: Flag ActiveRepos,
1318 getSourceRepository :: Flag (Maybe RepoKind),
1319 getVerbosity :: Flag Verbosity
1320 } deriving Generic
1322 defaultGetFlags :: GetFlags
1323 defaultGetFlags = GetFlags {
1324 getDestDir = mempty,
1325 getOnlyPkgDescr = mempty,
1326 getPristine = mempty,
1327 getIndexState = mempty,
1328 getActiveRepos = mempty,
1329 getSourceRepository = mempty,
1330 getVerbosity = toFlag normal
1333 getCommand :: CommandUI GetFlags
1334 getCommand = CommandUI {
1335 commandName = "get",
1336 commandSynopsis = "Download/Extract a package's source code (repository).",
1337 commandDescription = Just $ \_ -> wrapText $ unlines descriptionOfGetCommand,
1338 commandNotes = Just $ \pname -> unlines $ notesOfGetCommand "get" pname,
1339 commandUsage = usagePackages "get",
1340 commandDefaultFlags = defaultGetFlags,
1341 commandOptions = \_ -> [
1342 optionVerbosity getVerbosity (\v flags -> flags { getVerbosity = v })
1344 ,option "d" ["destdir"]
1345 "Where to place the package source, defaults to the current directory."
1346 getDestDir (\v flags -> flags { getDestDir = v })
1347 (reqArgFlag "PATH")
1349 ,option "s" ["source-repository"]
1350 "Copy the package's source repository (ie git clone, darcs get, etc as appropriate)."
1351 getSourceRepository (\v flags -> flags { getSourceRepository = v })
1352 (optArg "[head|this|...]" (parsecToReadE (const "invalid source-repository")
1353 (fmap (toFlag . Just) parsec))
1354 (Flag Nothing)
1355 (map (fmap show) . flagToList))
1357 , option [] ["index-state"]
1358 ("Use source package index state as it existed at a previous time. " ++
1359 "Accepts unix-timestamps (e.g. '@1474732068'), ISO8601 UTC timestamps " ++
1360 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD' (default: 'HEAD'). " ++
1361 "This determines which package versions are available as well as " ++
1362 ".cabal file revision is selected (unless --pristine is used).")
1363 getIndexState (\v flags -> flags { getIndexState = v })
1364 (reqArg "STATE" (parsecToReadE (const $ "index-state must be a " ++
1365 "unix-timestamps (e.g. '@1474732068'), " ++
1366 "a ISO8601 UTC timestamp " ++
1367 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD'")
1368 (toFlag `fmap` parsec))
1369 (flagToList . fmap prettyShow))
1371 , option [] ["only-package-description"]
1372 "Unpack only the package description file."
1373 getOnlyPkgDescr (\v flags -> flags { getOnlyPkgDescr = v })
1374 trueArg
1376 , option [] ["package-description-only"]
1377 "A synonym for --only-package-description."
1378 getOnlyPkgDescr (\v flags -> flags { getOnlyPkgDescr = v })
1379 trueArg
1381 , option [] ["pristine"]
1382 ("Unpack the original pristine tarball, rather than updating the "
1383 ++ ".cabal file with the latest revision from the package archive.")
1384 getPristine (\v flags -> flags { getPristine = v })
1385 trueArg
1389 -- | List of lines describing command @get@.
1390 descriptionOfGetCommand :: [String]
1391 descriptionOfGetCommand =
1392 [ "Creates a local copy of a package's source code. By default it gets the source"
1393 , "tarball and unpacks it in a local subdirectory. Alternatively, with -s it will"
1394 , "get the code from the source repository specified by the package."
1397 -- | Notes for the command @get@.
1398 notesOfGetCommand
1399 :: String -- ^ Either @"get"@ or @"unpack"@.
1400 -> String -- ^ E.g. @"cabal"@.
1401 -> [String] -- ^ List of lines.
1402 notesOfGetCommand cmd pname =
1403 [ "Examples:"
1404 , " " ++ unwords [ pname, cmd, "hlint" ]
1405 , " Download the latest stable version of hlint;"
1406 , " " ++ unwords [ pname, cmd, "lens --source-repository=head" ]
1407 , " Download the source repository of lens (i.e. git clone from github)."
1410 -- 'cabal unpack' is a deprecated alias for 'cabal get'.
1411 unpackCommand :: CommandUI GetFlags
1412 unpackCommand = getCommand
1413 { commandName = "unpack"
1414 , commandSynopsis = synopsis
1415 , commandNotes = Just $ \ pname -> unlines $
1416 notesOfGetCommand "unpack" pname
1417 , commandUsage = usagePackages "unpack"
1419 where
1420 synopsis = "Deprecated alias for 'get'."
1422 instance Monoid GetFlags where
1423 mempty = gmempty
1424 mappend = (<>)
1426 instance Semigroup GetFlags where
1427 (<>) = gmappend
1429 -- ------------------------------------------------------------
1430 -- * List flags
1431 -- ------------------------------------------------------------
1433 data ListFlags = ListFlags
1434 { listInstalled :: Flag Bool
1435 , listSimpleOutput :: Flag Bool
1436 , listCaseInsensitive :: Flag Bool
1437 , listVerbosity :: Flag Verbosity
1438 , listPackageDBs :: [Maybe PackageDB]
1439 , listHcPath :: Flag FilePath
1441 deriving Generic
1443 defaultListFlags :: ListFlags
1444 defaultListFlags = ListFlags
1445 { listInstalled = Flag False
1446 , listSimpleOutput = Flag False
1447 , listCaseInsensitive = Flag True
1448 , listVerbosity = toFlag normal
1449 , listPackageDBs = []
1450 , listHcPath = mempty
1453 listCommand :: CommandUI ListFlags
1454 listCommand = CommandUI {
1455 commandName = "list",
1456 commandSynopsis = "List packages matching a search string.",
1457 commandDescription = Just $ \_ -> wrapText $
1458 "List all packages, or all packages matching one of the search"
1459 ++ " strings.\n"
1460 ++ "\n"
1461 ++ "Use the package database specified with --package-db. "
1462 ++ "If not specified, use the user package database.\n",
1463 commandNotes = Just $ \pname ->
1464 "Examples:\n"
1465 ++ " " ++ pname ++ " list pandoc\n"
1466 ++ " Will find pandoc, pandoc-citeproc, pandoc-lens, ...\n",
1467 commandUsage = usageAlternatives "list" [ "[FLAGS]"
1468 , "[FLAGS] STRINGS"],
1469 commandDefaultFlags = defaultListFlags,
1470 commandOptions = const listOptions
1473 listOptions :: [OptionField ListFlags]
1474 listOptions =
1475 [ optionVerbosity listVerbosity (\v flags -> flags { listVerbosity = v })
1477 , option [] ["installed"]
1478 "Only print installed packages"
1479 listInstalled (\v flags -> flags { listInstalled = v })
1480 trueArg
1482 , option [] ["simple-output"]
1483 "Print in a easy-to-parse format"
1484 listSimpleOutput (\v flags -> flags { listSimpleOutput = v })
1485 trueArg
1486 , option ['i'] ["ignore-case"]
1487 "Ignore case distinctions"
1488 listCaseInsensitive (\v flags -> flags { listCaseInsensitive = v })
1489 (boolOpt' (['i'], ["ignore-case"]) (['I'], ["strict-case"]))
1491 , option "" ["package-db"]
1492 ( "Append the given package database to the list of package"
1493 ++ " databases used (to satisfy dependencies and register into)."
1494 ++ " May be a specific file, 'global' or 'user'. The initial list"
1495 ++ " is ['global'], ['global', 'user'],"
1496 ++ " depending on context. Use 'clear' to reset the list to empty."
1497 ++ " See the user guide for details.")
1498 listPackageDBs (\v flags -> flags { listPackageDBs = v })
1499 (reqArg' "DB" readPackageDbList showPackageDbList)
1501 , option "w" ["with-compiler"]
1502 "give the path to a particular compiler"
1503 listHcPath (\v flags -> flags { listHcPath = v })
1504 (reqArgFlag "PATH")
1507 listNeedsCompiler :: ListFlags -> Bool
1508 listNeedsCompiler f =
1509 flagElim False (const True) (listHcPath f)
1510 || fromFlagOrDefault False (listInstalled f)
1512 instance Monoid ListFlags where
1513 mempty = gmempty
1514 mappend = (<>)
1516 instance Semigroup ListFlags where
1517 (<>) = gmappend
1519 -- ------------------------------------------------------------
1520 -- * Info flags
1521 -- ------------------------------------------------------------
1523 data InfoFlags = InfoFlags {
1524 infoVerbosity :: Flag Verbosity,
1525 infoPackageDBs :: [Maybe PackageDB]
1526 } deriving Generic
1528 defaultInfoFlags :: InfoFlags
1529 defaultInfoFlags = InfoFlags {
1530 infoVerbosity = toFlag normal,
1531 infoPackageDBs = []
1534 infoCommand :: CommandUI InfoFlags
1535 infoCommand = CommandUI {
1536 commandName = "info",
1537 commandSynopsis = "Display detailed information about a particular package.",
1538 commandDescription = Just $ \_ -> wrapText $
1539 "Use the package database specified with --package-db. "
1540 ++ "If not specified, use the user package database.\n",
1541 commandNotes = Nothing,
1542 commandUsage = usageAlternatives "info" ["[FLAGS] PACKAGES"],
1543 commandDefaultFlags = defaultInfoFlags,
1544 commandOptions = \_ -> [
1545 optionVerbosity infoVerbosity (\v flags -> flags { infoVerbosity = v })
1547 , option "" ["package-db"]
1548 ( "Append the given package database to the list of package"
1549 ++ " databases used (to satisfy dependencies and register into)."
1550 ++ " May be a specific file, 'global' or 'user'. The initial list"
1551 ++ " is ['global'], ['global', 'user'],"
1552 ++ " depending on context. Use 'clear' to reset the list to empty."
1553 ++ " See the user guide for details.")
1554 infoPackageDBs (\v flags -> flags { infoPackageDBs = v })
1555 (reqArg' "DB" readPackageDbList showPackageDbList)
1560 instance Monoid InfoFlags where
1561 mempty = gmempty
1562 mappend = (<>)
1564 instance Semigroup InfoFlags where
1565 (<>) = gmappend
1567 -- ------------------------------------------------------------
1568 -- * Install flags
1569 -- ------------------------------------------------------------
1571 -- | Install takes the same flags as configure along with a few extras.
1573 data InstallFlags = InstallFlags {
1574 installDocumentation :: Flag Bool,
1575 installHaddockIndex :: Flag PathTemplate,
1576 installDest :: Flag Cabal.CopyDest,
1577 installDryRun :: Flag Bool,
1578 installOnlyDownload :: Flag Bool,
1579 installMaxBackjumps :: Flag Int,
1580 installReorderGoals :: Flag ReorderGoals,
1581 installCountConflicts :: Flag CountConflicts,
1582 installFineGrainedConflicts :: Flag FineGrainedConflicts,
1583 installMinimizeConflictSet :: Flag MinimizeConflictSet,
1584 installIndependentGoals :: Flag IndependentGoals,
1585 installPreferOldest :: Flag PreferOldest,
1586 installShadowPkgs :: Flag ShadowPkgs,
1587 installStrongFlags :: Flag StrongFlags,
1588 installAllowBootLibInstalls :: Flag AllowBootLibInstalls,
1589 installOnlyConstrained :: Flag OnlyConstrained,
1590 installReinstall :: Flag Bool,
1591 installAvoidReinstalls :: Flag AvoidReinstalls,
1592 installOverrideReinstall :: Flag Bool,
1593 installUpgradeDeps :: Flag Bool,
1594 installOnly :: Flag Bool,
1595 installOnlyDeps :: Flag Bool,
1596 installIndexState :: Flag TotalIndexState,
1597 installRootCmd :: Flag String,
1598 installSummaryFile :: NubList PathTemplate,
1599 installLogFile :: Flag PathTemplate,
1600 installBuildReports :: Flag ReportLevel,
1601 installReportPlanningFailure :: Flag Bool,
1602 -- Note: symlink-bindir is no longer used by v2-install and can be removed
1603 -- when removing v1 commands
1604 installSymlinkBinDir :: Flag FilePath,
1605 installPerComponent :: Flag Bool,
1606 installNumJobs :: Flag (Maybe Int),
1607 installKeepGoing :: Flag Bool,
1608 installRunTests :: Flag Bool,
1609 installOfflineMode :: Flag Bool
1611 deriving (Eq, Show, Generic)
1613 instance Binary InstallFlags
1615 defaultInstallFlags :: InstallFlags
1616 defaultInstallFlags = InstallFlags {
1617 installDocumentation = Flag False,
1618 installHaddockIndex = Flag docIndexFile,
1619 installDest = Flag Cabal.NoCopyDest,
1620 installDryRun = Flag False,
1621 installOnlyDownload = Flag False,
1622 installMaxBackjumps = Flag defaultMaxBackjumps,
1623 installReorderGoals = Flag (ReorderGoals False),
1624 installCountConflicts = Flag (CountConflicts True),
1625 installFineGrainedConflicts = Flag (FineGrainedConflicts True),
1626 installMinimizeConflictSet = Flag (MinimizeConflictSet False),
1627 installIndependentGoals= Flag (IndependentGoals False),
1628 installPreferOldest = Flag (PreferOldest False),
1629 installShadowPkgs = Flag (ShadowPkgs False),
1630 installStrongFlags = Flag (StrongFlags False),
1631 installAllowBootLibInstalls = Flag (AllowBootLibInstalls False),
1632 installOnlyConstrained = Flag OnlyConstrainedNone,
1633 installReinstall = Flag False,
1634 installAvoidReinstalls = Flag (AvoidReinstalls False),
1635 installOverrideReinstall = Flag False,
1636 installUpgradeDeps = Flag False,
1637 installOnly = Flag False,
1638 installOnlyDeps = Flag False,
1639 installIndexState = mempty,
1640 installRootCmd = mempty,
1641 installSummaryFile = mempty,
1642 installLogFile = mempty,
1643 installBuildReports = Flag NoReports,
1644 installReportPlanningFailure = Flag False,
1645 installSymlinkBinDir = mempty,
1646 installPerComponent = Flag True,
1647 installNumJobs = mempty,
1648 installKeepGoing = Flag False,
1649 installRunTests = mempty,
1650 installOfflineMode = Flag False
1652 where
1653 docIndexFile = toPathTemplate ("$datadir" </> "doc"
1654 </> "$arch-$os-$compiler" </> "index.html")
1656 defaultMaxBackjumps :: Int
1657 defaultMaxBackjumps = 4000
1659 defaultSolver :: PreSolver
1660 defaultSolver = AlwaysModular
1662 allSolvers :: String
1663 allSolvers = intercalate ", " (map prettyShow ([minBound .. maxBound] :: [PreSolver]))
1665 installCommand :: CommandUI ( ConfigFlags, ConfigExFlags, InstallFlags
1666 , HaddockFlags, TestFlags, BenchmarkFlags
1668 installCommand = CommandUI {
1669 commandName = "install",
1670 commandSynopsis = "Install packages.",
1671 commandUsage = usageAlternatives "v1-install" [ "[FLAGS]"
1672 , "[FLAGS] PACKAGES"
1674 commandDescription = Just $ \_ -> wrapText $
1675 "Installs one or more packages. By default, the installed package"
1676 ++ " will be registered in the user's package database."
1677 ++ "\n"
1678 ++ "If PACKAGES are specified, downloads and installs those packages."
1679 ++ " Otherwise, install the package in the current directory (and/or its"
1680 ++ " dependencies) (there must be exactly one .cabal file in the current"
1681 ++ " directory).\n"
1682 ++ "\n"
1683 ++ "The flags to `v1-install` are saved and"
1684 ++ " affect future commands such as `v1-build` and `v1-repl`. See the help for"
1685 ++ " `v1-configure` for a list of commands being affected.\n"
1686 ++ "\n"
1687 ++ "Installed executables will by default"
1688 ++ " be put into `~/.local/bin/`."
1689 ++ " If you want installed executable to be available globally, make"
1690 ++ " sure that the PATH environment variable contains that directory.\n"
1691 ++ "\n",
1692 commandNotes = Just $ \pname ->
1693 ( case commandNotes
1694 $ Cabal.configureCommand defaultProgramDb
1695 of Just desc -> desc pname ++ "\n"
1696 Nothing -> ""
1698 ++ "Examples:\n"
1699 ++ " " ++ pname ++ " v1-install "
1700 ++ " Package in the current directory\n"
1701 ++ " " ++ pname ++ " v1-install foo "
1702 ++ " Package from the hackage server\n"
1703 ++ " " ++ pname ++ " v1-install foo-1.0 "
1704 ++ " Specific version of a package\n"
1705 ++ " " ++ pname ++ " v1-install 'foo < 2' "
1706 ++ " Constrained package version\n"
1707 ++ " " ++ pname ++ " v1-install haddock --bindir=$HOME/hask-bin/ --datadir=$HOME/hask-data/\n"
1708 ++ " " ++ (map (const ' ') pname)
1709 ++ " "
1710 ++ " Change installation destination\n",
1711 commandDefaultFlags = (mempty, mempty, mempty, mempty, mempty, mempty),
1712 commandOptions = \showOrParseArgs ->
1713 liftOptions get1 set1
1714 -- Note: [Hidden Flags]
1715 -- hide "constraint", "dependency", and
1716 -- "exact-configuration" from the configure options.
1717 (filter ((`notElem` ["constraint", "dependency"
1718 , "exact-configuration"])
1719 . optionName) $
1720 configureOptions showOrParseArgs)
1721 ++ liftOptions get2 set2 (configureExOptions showOrParseArgs ConstraintSourceCommandlineFlag)
1722 ++ liftOptions get3 set3
1723 -- hide "target-package-db" flag from the
1724 -- install options.
1725 (filter ((`notElem` ["target-package-db"])
1726 . optionName) $
1727 installOptions showOrParseArgs)
1728 ++ liftOptions get4 set4 (haddockOptions showOrParseArgs)
1729 ++ liftOptions get5 set5 (testOptions showOrParseArgs)
1730 ++ liftOptions get6 set6 (benchmarkOptions showOrParseArgs)
1732 where
1733 get1 (a,_,_,_,_,_) = a; set1 a (_,b,c,d,e,f) = (a,b,c,d,e,f)
1734 get2 (_,b,_,_,_,_) = b; set2 b (a,_,c,d,e,f) = (a,b,c,d,e,f)
1735 get3 (_,_,c,_,_,_) = c; set3 c (a,b,_,d,e,f) = (a,b,c,d,e,f)
1736 get4 (_,_,_,d,_,_) = d; set4 d (a,b,c,_,e,f) = (a,b,c,d,e,f)
1737 get5 (_,_,_,_,e,_) = e; set5 e (a,b,c,d,_,f) = (a,b,c,d,e,f)
1738 get6 (_,_,_,_,_,f) = f; set6 f (a,b,c,d,e,_) = (a,b,c,d,e,f)
1740 haddockCommand :: CommandUI HaddockFlags
1741 haddockCommand = Cabal.haddockCommand
1742 { commandUsage = usageAlternatives "v1-haddock" $
1743 [ "[FLAGS]", "COMPONENTS [FLAGS]" ]
1746 filterHaddockArgs :: [String] -> Version -> [String]
1747 filterHaddockArgs args cabalLibVersion
1748 | cabalLibVersion >= mkVersion [2,3,0] = args_latest
1749 | cabalLibVersion < mkVersion [2,3,0] = args_2_3_0
1750 | otherwise = args_latest
1751 where
1752 args_latest = args
1754 -- Cabal < 2.3 doesn't know about per-component haddock
1755 args_2_3_0 = []
1757 filterHaddockFlags :: HaddockFlags -> Version -> HaddockFlags
1758 filterHaddockFlags flags cabalLibVersion
1759 | cabalLibVersion >= mkVersion [2,3,0] = flags_latest
1760 | cabalLibVersion < mkVersion [2,3,0] = flags_2_3_0
1761 | otherwise = flags_latest
1762 where
1763 flags_latest = flags
1765 flags_2_3_0 = flags_latest {
1766 -- Cabal < 2.3 doesn't know about per-component haddock
1767 haddockArgs = []
1770 haddockOptions :: ShowOrParseArgs -> [OptionField HaddockFlags]
1771 haddockOptions showOrParseArgs
1772 = [ opt { optionName = "haddock-" ++ name,
1773 optionDescr = [ fmapOptFlags (\(_, lflags) -> ([], map ("haddock-" ++) lflags)) descr
1774 | descr <- optionDescr opt] }
1775 | opt <- commandOptions Cabal.haddockCommand showOrParseArgs
1776 , let name = optionName opt
1777 , name `elem` ["hoogle", "html", "html-location"
1778 ,"executables", "tests", "benchmarks", "all", "internal", "css"
1779 ,"hyperlink-source", "quickjump", "hscolour-css"
1780 ,"contents-location", "use-index", "for-hackage", "base-url", "lib"]
1783 testOptions :: ShowOrParseArgs -> [OptionField TestFlags]
1784 testOptions showOrParseArgs
1785 = [ opt { optionName = prefixTest name,
1786 optionDescr = [ fmapOptFlags (\(_, lflags) -> ([], map prefixTest lflags)) descr
1787 | descr <- optionDescr opt] }
1788 | opt <- commandOptions Cabal.testCommand showOrParseArgs
1789 , let name = optionName opt
1790 , name `elem` ["log", "machine-log", "show-details", "keep-tix-files"
1791 ,"fail-when-no-test-suites", "test-options", "test-option"
1792 ,"test-wrapper"]
1794 where
1795 prefixTest name | "test-" `isPrefixOf` name = name
1796 | otherwise = "test-" ++ name
1798 benchmarkOptions :: ShowOrParseArgs -> [OptionField BenchmarkFlags]
1799 benchmarkOptions showOrParseArgs
1800 = [ opt { optionName = prefixBenchmark name,
1801 optionDescr = [ fmapOptFlags (\(_, lflags) -> ([], map prefixBenchmark lflags)) descr
1802 | descr <- optionDescr opt] }
1803 | opt <- commandOptions Cabal.benchmarkCommand showOrParseArgs
1804 , let name = optionName opt
1805 , name `elem` ["benchmark-options", "benchmark-option"]
1807 where
1808 prefixBenchmark name | "benchmark-" `isPrefixOf` name = name
1809 | otherwise = "benchmark-" ++ name
1811 fmapOptFlags :: (OptFlags -> OptFlags) -> OptDescr a -> OptDescr a
1812 fmapOptFlags modify (ReqArg d f p r w) = ReqArg d (modify f) p r w
1813 fmapOptFlags modify (OptArg d f p r i w) = OptArg d (modify f) p r i w
1814 fmapOptFlags modify (ChoiceOpt xs) = ChoiceOpt [(d, modify f, i, w) | (d, f, i, w) <- xs]
1815 fmapOptFlags modify (BoolOpt d f1 f2 r w) = BoolOpt d (modify f1) (modify f2) r w
1817 installOptions :: ShowOrParseArgs -> [OptionField InstallFlags]
1818 installOptions showOrParseArgs =
1819 [ option "" ["documentation"]
1820 "building of documentation"
1821 installDocumentation (\v flags -> flags { installDocumentation = v })
1822 (boolOpt [] [])
1824 , option [] ["doc-index-file"]
1825 "A central index of haddock API documentation (template cannot use $pkgid)"
1826 installHaddockIndex (\v flags -> flags { installHaddockIndex = v })
1827 (reqArg' "TEMPLATE" (toFlag.toPathTemplate)
1828 (flagToList . fmap fromPathTemplate))
1830 , option [] ["dry-run"]
1831 "Do not install anything, only print what would be installed."
1832 installDryRun (\v flags -> flags { installDryRun = v })
1833 trueArg
1835 , option [] ["only-download"]
1836 "Do not build anything, only fetch the packages."
1837 installOnlyDownload (\v flags -> flags { installOnlyDownload = v })
1838 trueArg
1840 , option "" ["target-package-db"]
1841 "package database to install into. Required when using ${pkgroot} prefix."
1842 installDest (\v flags -> flags { installDest = v })
1843 (reqArg "DATABASE" (succeedReadE (Flag . Cabal.CopyToDb))
1844 (\f -> case f of Flag (Cabal.CopyToDb p) -> [p]; _ -> []))
1845 ] ++
1847 optionSolverFlags showOrParseArgs
1848 installMaxBackjumps (\v flags -> flags { installMaxBackjumps = v })
1849 installReorderGoals (\v flags -> flags { installReorderGoals = v })
1850 installCountConflicts (\v flags -> flags { installCountConflicts = v })
1851 installFineGrainedConflicts (\v flags -> flags { installFineGrainedConflicts = v })
1852 installMinimizeConflictSet (\v flags -> flags { installMinimizeConflictSet = v })
1853 installIndependentGoals (\v flags -> flags { installIndependentGoals = v })
1854 installPreferOldest (\v flags -> flags { installPreferOldest = v })
1855 installShadowPkgs (\v flags -> flags { installShadowPkgs = v })
1856 installStrongFlags (\v flags -> flags { installStrongFlags = v })
1857 installAllowBootLibInstalls (\v flags -> flags { installAllowBootLibInstalls = v })
1858 installOnlyConstrained (\v flags -> flags { installOnlyConstrained = v }) ++
1860 [ option [] ["reinstall"]
1861 "Install even if it means installing the same version again."
1862 installReinstall (\v flags -> flags { installReinstall = v })
1863 (yesNoOpt showOrParseArgs)
1865 , option [] ["avoid-reinstalls"]
1866 "Do not select versions that would destructively overwrite installed packages."
1867 (fmap asBool . installAvoidReinstalls)
1868 (\v flags -> flags { installAvoidReinstalls = fmap AvoidReinstalls v })
1869 (yesNoOpt showOrParseArgs)
1871 , option [] ["force-reinstalls"]
1872 "Reinstall packages even if they will most likely break other installed packages."
1873 installOverrideReinstall (\v flags -> flags { installOverrideReinstall = v })
1874 (yesNoOpt showOrParseArgs)
1876 , option [] ["upgrade-dependencies"]
1877 "Pick the latest version for all dependencies, rather than trying to pick an installed version."
1878 installUpgradeDeps (\v flags -> flags { installUpgradeDeps = v })
1879 (yesNoOpt showOrParseArgs)
1881 , option [] ["only-dependencies"]
1882 "Install only the dependencies necessary to build the given packages"
1883 installOnlyDeps (\v flags -> flags { installOnlyDeps = v })
1884 (yesNoOpt showOrParseArgs)
1886 , option [] ["dependencies-only"]
1887 "A synonym for --only-dependencies"
1888 installOnlyDeps (\v flags -> flags { installOnlyDeps = v })
1889 (yesNoOpt showOrParseArgs)
1891 , option [] ["index-state"]
1892 ("Use source package index state as it existed at a previous time. " ++
1893 "Accepts unix-timestamps (e.g. '@1474732068'), ISO8601 UTC timestamps " ++
1894 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD' (default: 'HEAD').")
1895 installIndexState (\v flags -> flags { installIndexState = v })
1896 (reqArg "STATE" (parsecToReadE (const $ "index-state must be a " ++
1897 "unix-timestamps (e.g. '@1474732068'), " ++
1898 "a ISO8601 UTC timestamp " ++
1899 "(e.g. '2016-09-24T17:47:48Z'), or 'HEAD'")
1900 (toFlag `fmap` parsec))
1901 (flagToList . fmap prettyShow))
1903 , option [] ["root-cmd"]
1904 "(No longer supported, do not use.)"
1905 installRootCmd (\v flags -> flags { installRootCmd = v })
1906 (reqArg' "COMMAND" toFlag flagToList)
1908 , option [] ["symlink-bindir"]
1909 "Add symlinks to installed executables into this directory."
1910 installSymlinkBinDir (\v flags -> flags { installSymlinkBinDir = v })
1911 (reqArgFlag "DIR")
1913 , option [] ["build-summary"]
1914 "Save build summaries to file (name template can use $pkgid, $compiler, $os, $arch)"
1915 installSummaryFile (\v flags -> flags { installSummaryFile = v })
1916 (reqArg' "TEMPLATE" (\x -> toNubList [toPathTemplate x]) (map fromPathTemplate . fromNubList))
1918 , option [] ["build-log"]
1919 "Log all builds to file (name template can use $pkgid, $compiler, $os, $arch)"
1920 installLogFile (\v flags -> flags { installLogFile = v })
1921 (reqArg' "TEMPLATE" (toFlag.toPathTemplate)
1922 (flagToList . fmap fromPathTemplate))
1924 , option [] ["remote-build-reporting"]
1925 "Generate build reports to send to a remote server (none, anonymous or detailed)."
1926 installBuildReports (\v flags -> flags { installBuildReports = v })
1927 (reqArg "LEVEL" (parsecToReadE (const $ "report level must be 'none', "
1928 ++ "'anonymous' or 'detailed'")
1929 (toFlag `fmap` parsec))
1930 (flagToList . fmap prettyShow))
1932 , option [] ["report-planning-failure"]
1933 "Generate build reports when the dependency solver fails. This is used by the Hackage build bot."
1934 installReportPlanningFailure (\v flags -> flags { installReportPlanningFailure = v })
1935 trueArg
1937 , option "" ["per-component"]
1938 "Per-component builds when possible"
1939 installPerComponent (\v flags -> flags { installPerComponent = v })
1940 (boolOpt [] [])
1942 , option [] ["run-tests"]
1943 "Run package test suites during installation."
1944 installRunTests (\v flags -> flags { installRunTests = v })
1945 trueArg
1947 , optionNumJobs
1948 installNumJobs (\v flags -> flags { installNumJobs = v })
1950 , option [] ["keep-going"]
1951 "After a build failure, continue to build other unaffected packages."
1952 installKeepGoing (\v flags -> flags { installKeepGoing = v })
1953 trueArg
1955 , option [] ["offline"]
1956 "Don't download packages from the Internet."
1957 installOfflineMode (\v flags -> flags { installOfflineMode = v })
1958 (yesNoOpt showOrParseArgs)
1960 ] ++ case showOrParseArgs of -- TODO: remove when "cabal install"
1961 -- avoids
1962 ParseArgs ->
1963 [ option [] ["only"]
1964 "Only installs the package in the current directory."
1965 installOnly (\v flags -> flags { installOnly = v })
1966 trueArg ]
1967 _ -> []
1970 instance Monoid InstallFlags where
1971 mempty = gmempty
1972 mappend = (<>)
1974 instance Semigroup InstallFlags where
1975 (<>) = gmappend
1977 -- ------------------------------------------------------------
1978 -- * Upload flags
1979 -- ------------------------------------------------------------
1981 -- | Is this a candidate package or a package to be published?
1982 data IsCandidate = IsCandidate | IsPublished
1983 deriving Eq
1985 data UploadFlags = UploadFlags {
1986 uploadCandidate :: Flag IsCandidate,
1987 uploadDoc :: Flag Bool,
1988 uploadUsername :: Flag Username,
1989 uploadPassword :: Flag Password,
1990 uploadPasswordCmd :: Flag [String],
1991 uploadVerbosity :: Flag Verbosity
1992 } deriving Generic
1994 defaultUploadFlags :: UploadFlags
1995 defaultUploadFlags = UploadFlags {
1996 uploadCandidate = toFlag IsCandidate,
1997 uploadDoc = toFlag False,
1998 uploadUsername = mempty,
1999 uploadPassword = mempty,
2000 uploadPasswordCmd = mempty,
2001 uploadVerbosity = toFlag normal
2004 uploadCommand :: CommandUI UploadFlags
2005 uploadCommand = CommandUI {
2006 commandName = "upload",
2007 commandSynopsis = "Uploads source packages or documentation to Hackage.",
2008 commandDescription = Nothing,
2009 commandNotes = Just $ \_ ->
2010 "You can store your Hackage login in the ~/.config/cabal/config file\n"
2011 ++ relevantConfigValuesText ["username", "password", "password-command"],
2012 commandUsage = \pname ->
2013 "Usage: " ++ pname ++ " upload [FLAGS] TARFILES\n",
2014 commandDefaultFlags = defaultUploadFlags,
2015 commandOptions = \_ ->
2016 [optionVerbosity uploadVerbosity
2017 (\v flags -> flags { uploadVerbosity = v })
2019 ,option [] ["publish"]
2020 "Publish the package instead of uploading it as a candidate."
2021 uploadCandidate (\v flags -> flags { uploadCandidate = v })
2022 (noArg (Flag IsPublished))
2024 ,option ['d'] ["documentation"]
2025 ("Upload documentation instead of a source package. "
2026 ++ "By default, this uploads documentation for a package candidate. "
2027 ++ "To upload documentation for "
2028 ++ "a published package, combine with --publish.")
2029 uploadDoc (\v flags -> flags { uploadDoc = v })
2030 trueArg
2032 ,option ['u'] ["username"]
2033 "Hackage username."
2034 uploadUsername (\v flags -> flags { uploadUsername = v })
2035 (reqArg' "USERNAME" (toFlag . Username)
2036 (flagToList . fmap unUsername))
2038 ,option ['p'] ["password"]
2039 "Hackage password."
2040 uploadPassword (\v flags -> flags { uploadPassword = v })
2041 (reqArg' "PASSWORD" (toFlag . Password)
2042 (flagToList . fmap unPassword))
2044 ,option ['P'] ["password-command"]
2045 "Command to get Hackage password."
2046 uploadPasswordCmd (\v flags -> flags { uploadPasswordCmd = v })
2047 (reqArg' "PASSWORD" (Flag . words) (fromMaybe [] . flagToMaybe))
2051 instance Monoid UploadFlags where
2052 mempty = gmempty
2053 mappend = (<>)
2055 instance Semigroup UploadFlags where
2056 (<>) = gmappend
2058 -- ------------------------------------------------------------
2059 -- * Init flags
2060 -- ------------------------------------------------------------
2062 initCommand :: CommandUI IT.InitFlags
2063 initCommand = CommandUI {
2064 commandName = "init",
2065 commandSynopsis = "Create a new cabal package.",
2066 commandDescription = Just $ \_ -> wrapText $
2067 "Create a .cabal, CHANGELOG.md, minimal initial Haskell code and optionally a LICENSE file.\n"
2068 ++ "\n"
2069 ++ "Calling init with no arguments runs interactive mode, "
2070 ++ "which will try to guess as much as possible and prompt you for the rest.\n"
2071 ++ "Non-interactive mode can be invoked by the -n/--non-interactive flag, "
2072 ++ "which will let you specify the options via flags and will use the defaults for the rest.\n"
2073 ++ "It is also possible to call init with a single argument, which denotes the project's desired "
2074 ++ "root directory.\n",
2075 commandNotes = Nothing,
2076 commandUsage = \pname ->
2077 "Usage: " ++ pname ++ " init [PROJECT ROOT] [FLAGS]\n",
2078 commandDefaultFlags = IT.defaultInitFlags,
2079 commandOptions = initOptions
2082 initOptions :: ShowOrParseArgs -> [OptionField IT.InitFlags]
2083 initOptions _ =
2084 [ option ['i'] ["interactive"]
2085 "interactive mode."
2086 IT.interactive (\v flags -> flags { IT.interactive = v })
2087 (boolOpt' (['i'], ["interactive"]) (['n'], ["non-interactive"]))
2089 , option ['q'] ["quiet"]
2090 "Do not generate log messages to stdout."
2091 IT.quiet (\v flags -> flags { IT.quiet = v })
2092 trueArg
2094 , option [] ["no-comments"]
2095 "Do not generate explanatory comments in the .cabal file."
2096 IT.noComments (\v flags -> flags { IT.noComments = v })
2097 trueArg
2099 , option ['m'] ["minimal"]
2100 "Generate a minimal .cabal file, that is, do not include extra empty fields. Also implies --no-comments."
2101 IT.minimal (\v flags -> flags { IT.minimal = v })
2102 trueArg
2104 , option [] ["overwrite"]
2105 "Overwrite any existing .cabal, LICENSE, or Setup.hs files without warning."
2106 IT.overwrite (\v flags -> flags { IT.overwrite = v })
2107 trueArg
2109 , option [] ["package-dir", "packagedir"]
2110 "Root directory of the package (default = current directory)."
2111 IT.packageDir (\v flags -> flags { IT.packageDir = v })
2112 (reqArgFlag "DIRECTORY")
2114 , option ['p'] ["package-name"]
2115 "Name of the Cabal package to create."
2116 IT.packageName (\v flags -> flags { IT.packageName = v })
2117 (reqArg "PACKAGE" (parsecToReadE ("Cannot parse package name: "++)
2118 (toFlag `fmap` parsec))
2119 (flagToList . fmap prettyShow))
2121 , option [] ["version"]
2122 "Initial version of the package."
2123 IT.version (\v flags -> flags { IT.version = v })
2124 (reqArg "VERSION" (parsecToReadE ("Cannot parse package version: "++)
2125 (toFlag `fmap` parsec))
2126 (flagToList . fmap prettyShow))
2128 , option [] ["cabal-version"]
2129 "Version of the Cabal specification."
2130 IT.cabalVersion (\v flags -> flags { IT.cabalVersion = v })
2131 (reqArg "CABALSPECVERSION" (parsecToReadE ("Cannot parse Cabal specification version: "++)
2132 (fmap (toFlag . getSpecVersion) parsec))
2133 (flagToList . fmap (prettyShow . SpecVersion)))
2135 , option ['l'] ["license"]
2136 "Project license."
2137 IT.license (\v flags -> flags { IT.license = v })
2138 (reqArg "LICENSE" (parsecToReadE ("Cannot parse license: "++)
2139 (toFlag `fmap` parsec))
2140 (flagToList . fmap prettyShow))
2142 , option ['a'] ["author"]
2143 "Name of the project's author."
2144 IT.author (\v flags -> flags { IT.author = v })
2145 (reqArgFlag "NAME")
2147 , option ['e'] ["email"]
2148 "Email address of the maintainer."
2149 IT.email (\v flags -> flags { IT.email = v })
2150 (reqArgFlag "EMAIL")
2152 , option ['u'] ["homepage"]
2153 "Project homepage and/or repository."
2154 IT.homepage (\v flags -> flags { IT.homepage = v })
2155 (reqArgFlag "URL")
2157 , option ['s'] ["synopsis"]
2158 "Short project synopsis."
2159 IT.synopsis (\v flags -> flags { IT.synopsis = v })
2160 (reqArgFlag "TEXT")
2162 , option ['c'] ["category"]
2163 "Project category."
2164 IT.category (\v flags -> flags { IT.category = v })
2165 (reqArgFlag "CATEGORY")
2167 , option ['x'] ["extra-source-file"]
2168 "Extra source file to be distributed with tarball."
2169 IT.extraSrc (\v flags -> flags { IT.extraSrc = v })
2170 (reqArg' "FILE" (Flag . (:[]))
2171 (fromFlagOrDefault []))
2172 , option [] ["extra-doc-file"]
2173 "Extra doc file to be distributed with tarball."
2174 IT.extraDoc (\v flags -> flags { IT.extraDoc = v })
2175 (reqArg' "FILE" (Flag . (:[])) (fromFlagOrDefault []))
2177 , option [] ["lib", "is-library"]
2178 "Build a library."
2179 IT.packageType (\v flags -> flags { IT.packageType = v })
2180 (noArg (Flag IT.Library))
2182 , option [] ["exe", "is-executable"]
2183 "Build an executable."
2184 IT.packageType
2185 (\v flags -> flags { IT.packageType = v })
2186 (noArg (Flag IT.Executable))
2188 , option [] ["libandexe", "is-libandexe"]
2189 "Build a library and an executable."
2190 IT.packageType
2191 (\v flags -> flags { IT.packageType = v })
2192 (noArg (Flag IT.LibraryAndExecutable))
2194 , option [] ["tests"]
2195 "Generate a test suite, standalone or for a library."
2196 IT.initializeTestSuite
2197 (\v flags -> flags { IT.initializeTestSuite = v })
2198 trueArg
2200 , option [] ["test-dir"]
2201 "Directory containing tests."
2202 IT.testDirs (\v flags -> flags { IT.testDirs = v })
2203 (reqArg' "DIR" (Flag . (:[]))
2204 (fromFlagOrDefault []))
2206 , option [] ["simple"]
2207 "Create a simple project with sensible defaults."
2208 IT.simpleProject
2209 (\v flags -> flags { IT.simpleProject = v })
2210 trueArg
2212 , option [] ["main-is"]
2213 "Specify the main module."
2214 IT.mainIs
2215 (\v flags -> flags { IT.mainIs = v })
2216 (reqArgFlag "FILE")
2218 , option [] ["language"]
2219 "Specify the default language."
2220 IT.language
2221 (\v flags -> flags { IT.language = v })
2222 (reqArg "LANGUAGE" (parsecToReadE ("Cannot parse language: "++)
2223 (toFlag `fmap` parsec))
2224 (flagToList . fmap prettyShow))
2226 , option ['o'] ["expose-module"]
2227 "Export a module from the package."
2228 IT.exposedModules
2229 (\v flags -> flags { IT.exposedModules = v })
2230 (reqArg "MODULE" (parsecToReadE ("Cannot parse module name: "++)
2231 (Flag . (:[]) <$> parsec))
2232 (flagElim [] (fmap prettyShow)))
2234 , option [] ["extension"]
2235 "Use a LANGUAGE extension (in the other-extensions field)."
2236 IT.otherExts
2237 (\v flags -> flags { IT.otherExts = v })
2238 (reqArg "EXTENSION" (parsecToReadE ("Cannot parse extension: "++)
2239 (Flag . (:[]) <$> parsec))
2240 (flagElim [] (fmap prettyShow)))
2242 , option ['d'] ["dependency"]
2243 "Package dependency."
2244 IT.dependencies (\v flags -> flags { IT.dependencies = v })
2245 (reqArg "PACKAGE" (parsecToReadE ("Cannot parse dependency: "++)
2246 (Flag . (:[]) <$> parsec))
2247 (flagElim [] (fmap prettyShow)))
2249 , option [] ["application-dir"]
2250 "Directory containing package application executable."
2251 IT.applicationDirs (\v flags -> flags { IT.applicationDirs = v})
2252 (reqArg' "DIR" (Flag . (:[]))
2253 (fromFlagOrDefault []))
2255 , option [] ["source-dir", "sourcedir"]
2256 "Directory containing package library source."
2257 IT.sourceDirs (\v flags -> flags { IT.sourceDirs = v })
2258 (reqArg' "DIR" (Flag. (:[]))
2259 (fromFlagOrDefault []))
2261 , option [] ["build-tool"]
2262 "Required external build tool."
2263 IT.buildTools (\v flags -> flags { IT.buildTools = v })
2264 (reqArg' "TOOL" (Flag . (:[]))
2265 (fromFlagOrDefault []))
2267 , option "w" ["with-compiler"]
2268 "give the path to a particular compiler. For 'init', this flag is used \
2269 \to set the bounds inferred for the 'base' package."
2270 IT.initHcPath (\v flags -> flags { IT.initHcPath = v })
2271 (reqArgFlag "PATH")
2273 , optionVerbosity IT.initVerbosity (\v flags -> flags { IT.initVerbosity = v })
2276 -- ------------------------------------------------------------
2277 -- * Copy and Register
2278 -- ------------------------------------------------------------
2280 copyCommand :: CommandUI CopyFlags
2281 copyCommand = Cabal.copyCommand
2282 { commandNotes = Just $ \pname ->
2283 "Examples:\n"
2284 ++ " " ++ pname ++ " v1-copy "
2285 ++ " All the components in the package\n"
2286 ++ " " ++ pname ++ " v1-copy foo "
2287 ++ " A component (i.e. lib, exe, test suite)"
2288 , commandUsage = usageAlternatives "v1-copy" $
2289 [ "[FLAGS]"
2290 , "COMPONENTS [FLAGS]"
2294 registerCommand :: CommandUI RegisterFlags
2295 registerCommand = Cabal.registerCommand
2296 { commandUsage = \pname -> "Usage: " ++ pname ++ " v1-register [FLAGS]\n" }
2298 -- ------------------------------------------------------------
2299 -- * ActAsSetup flags
2300 -- ------------------------------------------------------------
2302 data ActAsSetupFlags = ActAsSetupFlags {
2303 actAsSetupBuildType :: Flag BuildType
2304 } deriving Generic
2306 defaultActAsSetupFlags :: ActAsSetupFlags
2307 defaultActAsSetupFlags = ActAsSetupFlags {
2308 actAsSetupBuildType = toFlag Simple
2311 actAsSetupCommand :: CommandUI ActAsSetupFlags
2312 actAsSetupCommand = CommandUI {
2313 commandName = "act-as-setup",
2314 commandSynopsis = "Run as-if this was a Setup.hs",
2315 commandDescription = Nothing,
2316 commandNotes = Nothing,
2317 commandUsage = \pname ->
2318 "Usage: " ++ pname ++ " act-as-setup\n",
2319 commandDefaultFlags = defaultActAsSetupFlags,
2320 commandOptions = \_ ->
2321 [option "" ["build-type"]
2322 "Use the given build type."
2323 actAsSetupBuildType (\v flags -> flags { actAsSetupBuildType = v })
2324 (reqArg "BUILD-TYPE" (parsecToReadE ("Cannot parse build type: "++)
2325 (fmap toFlag parsec))
2326 (map prettyShow . flagToList))
2330 instance Monoid ActAsSetupFlags where
2331 mempty = gmempty
2332 mappend = (<>)
2334 instance Semigroup ActAsSetupFlags where
2335 (<>) = gmappend
2337 -- ------------------------------------------------------------
2338 -- * UserConfig flags
2339 -- ------------------------------------------------------------
2341 data UserConfigFlags = UserConfigFlags {
2342 userConfigVerbosity :: Flag Verbosity,
2343 userConfigForce :: Flag Bool,
2344 userConfigAppendLines :: Flag [String]
2345 } deriving Generic
2347 instance Monoid UserConfigFlags where
2348 mempty = UserConfigFlags {
2349 userConfigVerbosity = toFlag normal,
2350 userConfigForce = toFlag False,
2351 userConfigAppendLines = toFlag []
2353 mappend = (<>)
2355 instance Semigroup UserConfigFlags where
2356 (<>) = gmappend
2358 userConfigCommand :: CommandUI UserConfigFlags
2359 userConfigCommand = CommandUI {
2360 commandName = "user-config",
2361 commandSynopsis = "Display and update the user's global cabal configuration.",
2362 commandDescription = Just $ \_ -> wrapText $
2363 "When upgrading cabal, the set of configuration keys and their default"
2364 ++ " values may change. This command provides means to merge the existing"
2365 ++ " config in ~/.config/cabal/config"
2366 ++ " (i.e. all bindings that are actually defined and not commented out)"
2367 ++ " and the default config of the new version.\n"
2368 ++ "\n"
2369 ++ "init: Creates a new config file at either ~/.config/cabal/config or as"
2370 ++ " specified by --config-file, if given. An existing file won't be "
2371 ++ " overwritten unless -f or --force is given.\n"
2372 ++ "diff: Shows a pseudo-diff of the user's ~/.config/cabal/config file and"
2373 ++ " the default configuration that would be created by cabal if the"
2374 ++ " config file did not exist.\n"
2375 ++ "update: Applies the pseudo-diff to the configuration that would be"
2376 ++ " created by default, and write the result back to ~/.config/cabal/config.",
2378 commandNotes = Nothing,
2379 commandUsage = usageAlternatives "user-config" ["init", "diff", "update"],
2380 commandDefaultFlags = mempty,
2381 commandOptions = \ _ -> [
2382 optionVerbosity userConfigVerbosity (\v flags -> flags { userConfigVerbosity = v })
2383 , option ['f'] ["force"]
2384 "Overwrite the config file if it already exists."
2385 userConfigForce (\v flags -> flags { userConfigForce = v })
2386 trueArg
2387 , option ['a'] ["augment"]
2388 "Additional setting to augment the config file (replacing a previous setting if it existed)."
2389 userConfigAppendLines (\v flags -> flags
2390 {userConfigAppendLines =
2391 Flag $ concat (flagToList (userConfigAppendLines flags) ++ flagToList v)})
2392 (reqArg' "CONFIGLINE" (Flag . (:[])) (fromMaybe [] . flagToMaybe))
2397 -- ------------------------------------------------------------
2398 -- * GetOpt Utils
2399 -- ------------------------------------------------------------
2401 reqArgFlag :: ArgPlaceHolder ->
2402 MkOptDescr (b -> Flag String) (Flag String -> b -> b) b
2403 reqArgFlag ad = reqArg ad (succeedReadE Flag) flagToList
2405 liftOptions :: (b -> a) -> (a -> b -> b)
2406 -> [OptionField a] -> [OptionField b]
2407 liftOptions get set = map (liftOption get set)
2409 yesNoOpt :: ShowOrParseArgs -> MkOptDescr (b -> Flag Bool) (Flag Bool -> b -> b) b
2410 yesNoOpt ShowArgs sf lf = trueArg sf lf
2411 yesNoOpt _ sf lf = Command.boolOpt' flagToMaybe Flag (sf, lf) ([], map ("no-" ++) lf) sf lf
2413 optionSolver :: (flags -> Flag PreSolver)
2414 -> (Flag PreSolver -> flags -> flags)
2415 -> OptionField flags
2416 optionSolver get set =
2417 option [] ["solver"]
2418 ("Select dependency solver to use (default: " ++ prettyShow defaultSolver ++ "). Choices: " ++ allSolvers ++ ".")
2419 get set
2420 (reqArg "SOLVER" (parsecToReadE (const $ "solver must be one of: " ++ allSolvers)
2421 (toFlag `fmap` parsec))
2422 (flagToList . fmap prettyShow))
2424 optionSolverFlags :: ShowOrParseArgs
2425 -> (flags -> Flag Int ) -> (Flag Int -> flags -> flags)
2426 -> (flags -> Flag ReorderGoals) -> (Flag ReorderGoals -> flags -> flags)
2427 -> (flags -> Flag CountConflicts) -> (Flag CountConflicts -> flags -> flags)
2428 -> (flags -> Flag FineGrainedConflicts) -> (Flag FineGrainedConflicts -> flags -> flags)
2429 -> (flags -> Flag MinimizeConflictSet) -> (Flag MinimizeConflictSet -> flags -> flags)
2430 -> (flags -> Flag IndependentGoals) -> (Flag IndependentGoals -> flags -> flags)
2431 -> (flags -> Flag PreferOldest) -> (Flag PreferOldest -> flags -> flags)
2432 -> (flags -> Flag ShadowPkgs) -> (Flag ShadowPkgs -> flags -> flags)
2433 -> (flags -> Flag StrongFlags) -> (Flag StrongFlags -> flags -> flags)
2434 -> (flags -> Flag AllowBootLibInstalls) -> (Flag AllowBootLibInstalls -> flags -> flags)
2435 -> (flags -> Flag OnlyConstrained) -> (Flag OnlyConstrained -> flags -> flags)
2436 -> [OptionField flags]
2437 optionSolverFlags showOrParseArgs getmbj setmbj getrg setrg getcc setcc
2438 getfgc setfgc getmc setmc getig setig getpo setpo getsip setsip
2439 getstrfl setstrfl getib setib getoc setoc =
2440 [ option [] ["max-backjumps"]
2441 ("Maximum number of backjumps allowed while solving (default: " ++ show defaultMaxBackjumps ++ "). Use a negative number to enable unlimited backtracking. Use 0 to disable backtracking completely.")
2442 getmbj setmbj
2443 (reqArg "NUM" (parsecToReadE ("Cannot parse number: "++) (fmap toFlag P.signedIntegral))
2444 (map show . flagToList))
2445 , option [] ["reorder-goals"]
2446 "Try to reorder goals according to certain heuristics. Slows things down on average, but may make backtracking faster for some packages."
2447 (fmap asBool . getrg)
2448 (setrg . fmap ReorderGoals)
2449 (yesNoOpt showOrParseArgs)
2450 , option [] ["count-conflicts"]
2451 "Try to speed up solving by preferring goals that are involved in a lot of conflicts (default)."
2452 (fmap asBool . getcc)
2453 (setcc . fmap CountConflicts)
2454 (yesNoOpt showOrParseArgs)
2455 , option [] ["fine-grained-conflicts"]
2456 "Skip a version of a package if it does not resolve the conflicts encountered in the last version, as a solver optimization (default)."
2457 (fmap asBool . getfgc)
2458 (setfgc . fmap FineGrainedConflicts)
2459 (yesNoOpt showOrParseArgs)
2460 , option [] ["minimize-conflict-set"]
2461 ("When there is no solution, try to improve the error message by finding "
2462 ++ "a minimal conflict set (default: false). May increase run time "
2463 ++ "significantly.")
2464 (fmap asBool . getmc)
2465 (setmc . fmap MinimizeConflictSet)
2466 (yesNoOpt showOrParseArgs)
2467 , option [] ["independent-goals"]
2468 "Treat several goals on the command line as independent. If several goals depend on the same package, different versions can be chosen."
2469 (fmap asBool . getig)
2470 (setig . fmap IndependentGoals)
2471 (yesNoOpt showOrParseArgs)
2472 , option [] ["prefer-oldest"]
2473 "Prefer the oldest (instead of the latest) versions of packages available. Useful to determine lower bounds in the build-depends section."
2474 (fmap asBool . getpo)
2475 (setpo . fmap PreferOldest)
2476 (yesNoOpt showOrParseArgs)
2477 , option [] ["shadow-installed-packages"]
2478 "If multiple package instances of the same version are installed, treat all but one as shadowed."
2479 (fmap asBool . getsip)
2480 (setsip . fmap ShadowPkgs)
2481 (yesNoOpt showOrParseArgs)
2482 , option [] ["strong-flags"]
2483 "Do not defer flag choices (this used to be the default in cabal-install <= 1.20)."
2484 (fmap asBool . getstrfl)
2485 (setstrfl . fmap StrongFlags)
2486 (yesNoOpt showOrParseArgs)
2487 , option [] ["allow-boot-library-installs"]
2488 "Allow cabal to install base, ghc-prim, integer-simple, integer-gmp, and template-haskell."
2489 (fmap asBool . getib)
2490 (setib . fmap AllowBootLibInstalls)
2491 (yesNoOpt showOrParseArgs)
2492 , option [] ["reject-unconstrained-dependencies"]
2493 "Require these packages to have constraints on them if they are to be selected (default: none)."
2494 getoc
2495 setoc
2496 (reqArg "none|all"
2497 (parsecToReadE
2498 (const "reject-unconstrained-dependencies must be 'none' or 'all'")
2499 (toFlag `fmap` parsec))
2500 (flagToList . fmap prettyShow))
2504 usagePackages :: String -> String -> String
2505 usagePackages name pname =
2506 "Usage: " ++ pname ++ " " ++ name ++ " [PACKAGES]\n"
2508 usageFlags :: String -> String -> String
2509 usageFlags name pname =
2510 "Usage: " ++ pname ++ " " ++ name ++ " [FLAGS]\n"
2512 -- ------------------------------------------------------------
2513 -- * Repo helpers
2514 -- ------------------------------------------------------------
2516 showRemoteRepo :: RemoteRepo -> String
2517 showRemoteRepo = prettyShow
2519 readRemoteRepo :: String -> Maybe RemoteRepo
2520 readRemoteRepo = simpleParsec
2522 showLocalRepo :: LocalRepo -> String
2523 showLocalRepo = prettyShow
2525 readLocalRepo :: String -> Maybe LocalRepo
2526 readLocalRepo = simpleParsec
2528 -- ------------------------------------------------------------
2529 -- * Helpers for Documentation
2530 -- ------------------------------------------------------------
2532 relevantConfigValuesText :: [String] -> String
2533 relevantConfigValuesText vs =
2534 "Relevant global configuration keys:\n"
2535 ++ concat [" " ++ v ++ "\n" |v <- vs]