Skip to content

Commit 51e1817

Browse files
tomsmedinggeekosaurmergify[bot]
authored
Clarify splitting/passing behaviour for --*-option(s) arguments (#10792)
* Clarify splitting/passing behaviour for --*-option(s) arguments * Further clarify precise quote parsing behaviour of --*-options options * Use OPTS, not FLAG, for --repl-options * Fix typo * Fix formatting * Use clearer notation for single and double quotes in docs This handles geekosaur's review. * Minor wording change in docs Co-authored-by: brandon s allbery kf8nh <[email protected]> --------- Co-authored-by: brandon s allbery kf8nh <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent df9a83a commit 51e1817

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

Cabal/src/Distribution/Simple/Setup/Benchmark.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ benchmarkOptions' showOrParseArgs =
118118
[]
119119
["benchmark-options"]
120120
( "give extra options to benchmark executables "
121-
++ "(name templates can use $pkgid, $compiler, "
121+
++ "(split on spaces, use \"\" to prevent splitting; "
122+
++ "name templates can use $pkgid, $compiler, "
122123
++ "$os, $arch, $benchmark)"
123124
)
124125
benchmarkOptions
@@ -132,7 +133,7 @@ benchmarkOptions' showOrParseArgs =
132133
[]
133134
["benchmark-option"]
134135
( "give extra option to benchmark executables "
135-
++ "(no need to quote options containing spaces, "
136+
++ "(passed directly as a single argument; "
136137
++ "name template can use $pkgid, $compiler, "
137138
++ "$os, $arch, $benchmark)"
138139
)

Cabal/src/Distribution/Simple/Setup/Common.hs

+7-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ programDbOption progDb showOrParseArgs get set =
275275
[prog ++ "-option"]
276276
( "give an extra option to "
277277
++ prog
278-
++ " (no need to quote options containing spaces)"
278+
++ " (passed directly to "
279+
++ prog
280+
++ " as a single argument)"
279281
)
280282
get
281283
set
@@ -312,7 +314,10 @@ programDbOptions progDb showOrParseArgs get set =
312314
option
313315
""
314316
[prog ++ "-options"]
315-
("give extra options to " ++ prog)
317+
( "give extra options to "
318+
++ prog
319+
++ " (split on spaces, use \"\" to prevent splitting)"
320+
)
316321
get
317322
set
318323
(reqArg' "OPTS" (\args -> [(prog, splitArgs args)]) (const []))

Cabal/src/Distribution/Simple/Setup/Test.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ testOptions' showOrParseArgs =
245245
[]
246246
["test-options"]
247247
( "give extra options to test executables "
248-
++ "(name templates can use $pkgid, $compiler, "
248+
++ "(split on spaces, use \"\" to prevent splitting; "
249+
++ "name templates can use $pkgid, $compiler, "
249250
++ "$os, $arch, $test-suite)"
250251
)
251252
testOptions
@@ -259,7 +260,7 @@ testOptions' showOrParseArgs =
259260
[]
260261
["test-option"]
261262
( "give extra option to test executables "
262-
++ "(no need to quote options containing spaces, "
263+
++ "(passed directly as a single argument; "
263264
++ "name template can use $pkgid, $compiler, "
264265
++ "$os, $arch, $test-suite)"
265266
)

doc/cabal-commands.rst

+9-5
Original file line numberDiff line numberDiff line change
@@ -1060,13 +1060,17 @@ Examples:
10601060
Configuration flags can be specified on the command line and these extend the project
10611061
configuration from the 'cabal.project', 'cabal.project.local' and other files.
10621062

1063-
.. option:: --repl-options=FLAG
1063+
.. option:: --repl-options=OPTS
10641064

10651065
To avoid ``ghci``-specific flags from triggering unneeded global rebuilds, these
1066-
flags are stripped from the internal configuration. As a result,
1067-
``--ghc-options`` will no longer (reliably) work to pass flags to ``ghci`` (or
1068-
other REPLs). Instead, you should use the ``--repl-options`` flag to
1069-
specify these options to the invoked REPL.
1066+
flags are stripped from the internal configuration when using
1067+
``--ghc-option`` or ``--ghc-options``. As a result, ``--ghc-options`` will
1068+
not (reliably) work to pass flags to ``ghci`` (or other REPLs).
1069+
``--repl-options`` bypasses this and allows you to specify options to the
1070+
invoked REPL without influencing the build configuration for other packages.
1071+
1072+
Note: ``--repl-options`` does not accept double quotes (``""``) to pass options
1073+
containing spaces to the REPL.
10701074

10711075
.. option:: --repl-no-load
10721076

doc/setup-commands.rst

+20-8
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,31 @@ files of a package:
210210
to Cabal can be used in place of *prog*. For example:
211211
``--alex-options="--template=mytemplatedir/"``. The *options* is
212212
split into program options based on spaces. Any options containing
213-
embedded spaced need to be quoted, for example
214-
``--foo-options='--bar="C:\Program File\Bar"'``. As an alternative
215-
that takes only one option at a time but avoids the need to quote,
216-
use :option:`--PROG-option` instead.
213+
embedded spaces need to be quoted with double quotes (``""``), for example
214+
``--foo-options='--bar="C:\Program Files\Bar"'``. (The single quotes
215+
(``''``) are for your shell, the ``"double"`` quotes are passed to Cabal.)
216+
For an alternative that takes only one option at a time but avoids the need
217+
to quote, use :option:`--PROG-option` instead.
218+
219+
Note: if *prog* is ``ghc``, then options that do not affect build
220+
artifacts, such as warning flags, are dropped. This is because
221+
``--ghc-options`` applies to GHC for the entire build plan, not just the
222+
current package, and recompiling the entire dependency tree is probably
223+
unintended. If you want to apply some options to ``cabal repl`` only, pass
224+
``--repl-options`` to ``cabal repl``.
217225

218226
.. option:: --PROG-option=OPT
219227

220-
Specify a single additional option to the program *prog*. For
228+
Specify a single additional option to the program *prog*. The option is
229+
passed to *prog* as a single argument, without any splitting. For
221230
passing an option that contains embedded spaces, such as a file name
222231
with embedded spaces, using this rather than :option:`--PROG-options`
223232
means you do not need an additional level of quoting. Of course if you
224233
are using a command shell you may still need to quote, for example
225-
``--foo-options="--bar=C:\Program File\Bar"``.
234+
``--foo-options="--bar=C:\Program Files\Bar"``.
235+
236+
The same note regarding dropping flags as for :option:`--PROG-options`
237+
applies to ``--PROG-option`` as well.
226238

227239
All of the options passed with either :option:`--PROG-options`
228240
or :option:`--PROG-option` are passed in the order they were
@@ -1443,11 +1455,11 @@ Flags for repl:
14431455

14441456
.. option:: --PROG-option=OPT
14451457

1446-
Give an extra option to PROG (no need to quote options containing spaces).
1458+
Give an extra option to PROG (passed directly to PROG as a single argument).
14471459

14481460
.. option:: --PROG-options=OPTS
14491461

1450-
Give extra options to PROG.
1462+
Give extra options to PROG (split on spaces, use "" to prevent splitting).
14511463

14521464
.. option:: --repl-no-load
14531465

0 commit comments

Comments
 (0)