You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cabal-install: don't pass exe name to external commands
Previously the executable name of the external command was passed to external commands as the
first argument.
This behaviour was adapated from cargo which does this because of reasons that are internal
to rust that do not affect GHC Haskell, and are even orthogonal to patterns that see common use in
Haskell.
Additionally, it complicates the 'simple' case which is what we should optimize for when building
such a feature.
The previous use case (one executable that serves multiple external subcommands) is still possible
by the following means:
- using a wrapper around the executable
- using a symlink and check argv[0] in the executable
Resolves#10275
synopsis: don't pass exe name to external commands
3
+
packages: [cabal-install]
4
+
prs: 11232
5
+
issues: [10275]
6
+
significance: significant
7
+
---
8
+
9
+
Previously the executable name of the external command was passed to external commands as the first argument.
10
+
11
+
This behaviour was adapted from cargo which does this because of reasons that are internal to rust that do not affect GHC Haskell, and are even orthogonal to patterns that see common use in Haskell.
12
+
13
+
Additionally, it complicates the 'simple' case which is what we should optimize for when building such a feature - with this change, for any executable `cabal-foo` in your search-path, `cabal foo` will be a valid invocation of that command.
14
+
15
+
The previous use case (one executable that serves multiple external subcommands) is still possible by the following means:
16
+
17
+
- using a wrapper around the executable
18
+
- using a symlink and check argv\[0\] in the executable
Copy file name to clipboardExpand all lines: doc/external-commands.rst
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,19 +3,27 @@ External Commands
3
3
4
4
``cabal-install`` provides a system for external commands, akin to the ones used by tools like ``git`` or ``cargo``.
5
5
6
-
If you execute ``cabal <cmd>``, ``cabal-install`` will search the path for an executable named ``cabal-<cmd>`` and execute it. The name of the command is passed as the first argument and
7
-
the remaining arguments are passed afterwards. An error will be thrown in case the custom command is not found. The exit code of cabal when calling an external command is the same as the exit code
6
+
If you execute ``cabal <cmd>``, ``cabal-install`` will search the path for an executable named ``cabal-<cmd>`` and execute it. An error will be thrown in case the custom command is not found. The exit code of cabal when calling an external command is the same as the exit code
8
7
of the command.
9
8
10
-
The ``$CABAL`` environment variable is set to the path of the ``cabal-install`` executable
9
+
The name of the command is *not* passed as the first argument as it is done in cargo, instead you will have to figure out the name via `argv[0]` as
10
+
is the case in e.g. `git`.
11
+
12
+
The ``$CABAL_EXTERNAL_COMMAND`` environment variable is set to the path of the ``cabal-install`` executable
11
13
which invoked the subcommand.
12
14
13
15
It is strongly recommended that you implement your custom commands by calling the
14
-
CLI via the ``$CABAL`` variable rather than linking against the ``Cabal`` library.
16
+
CLI via the ``$CABAL_EXTERNAL_COMMAND`` variable rather than linking against the ``Cabal`` library.
15
17
There is no guarantee that the subcommand will link against the same version of the
16
18
``Cabal`` library as ``cabal-install`` so it would lead to unexpected results and
17
19
incompatibilities.
18
20
21
+
Historically, the `cabal-install` binary would pass the name of the executable which it is trying to invoke via the external command feature as
22
+
the first argument to the executable itself. The main difference was that ``$CABAL_EXTERNAL_COMMAND`` was called ``$CABAL``, which means that
23
+
you can stay compatible with both versions, depending on which variable is set.
24
+
25
+
Mind that if you were implementing external commands previously, you will not need to skip the first argument (the executable name) anymore.
26
+
19
27
``cabal-install`` can also display the help message of the external command.
20
28
When ``cabal help <cmd>`` is invoked, then ``cabal-<cmd> <cmd> --help`` will be called so
0 commit comments