-
Notifications
You must be signed in to change notification settings - Fork 723
cabal-install: do not pass the executable name to cabal external commands #11232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MangoIV
wants to merge
1
commit into
haskell:master
Choose a base branch
from
MangoIV:mangoiv/change-subcommands
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| --- | ||||||
| synopsis: don't pass exe name to external commands | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| packages: [cabal-install] | ||||||
| prs: 11232 | ||||||
| issues: [10275] | ||||||
| significance: significant | ||||||
| --- | ||||||
|
|
||||||
| Previously the executable name of the external command was passed to external commands as the first argument. | ||||||
|
|
||||||
| 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. | ||||||
|
|
||||||
| 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. | ||||||
|
|
||||||
| 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 | ||||||
|
|
||||||
| Additionally, the variable `$CABAL` that was set by `cabal-install` was renamed to `CABAL_EXTERNAL_CABAL_PATH`. This has two reasons: | ||||||
| 1. it makes migration easier for users of the external command feature that were previously expecting the name of the executable | ||||||
| to appear in `argv[1]` | ||||||
| 2. it does not unnecessarily pollute the environment variable namespace as it turns out some other tools have been and are already | ||||||
| using this name, historically | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,19 +3,27 @@ External Commands | |||||
|
|
||||||
| ``cabal-install`` provides a system for external commands, akin to the ones used by tools like ``git`` or ``cargo``. | ||||||
|
|
||||||
| 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 | ||||||
| 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 | ||||||
| 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 | ||||||
| of the command. | ||||||
|
|
||||||
| The ``$CABAL`` environment variable is set to the path of the ``cabal-install`` executable | ||||||
| The name of the command is *not* passed as the first argument as is done in cargo, instead you will have to figure out the name via `argv[0]` as | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| is the case in e.g. `git`. | ||||||
|
|
||||||
| The ``$CABAL_EXTERNAL_CABAL_PATH`` environment variable is set to the path of the ``cabal-install`` executable | ||||||
| which invoked the subcommand. | ||||||
|
|
||||||
| It is strongly recommended that you implement your custom commands by calling the | ||||||
| CLI via the ``$CABAL`` variable rather than linking against the ``Cabal`` library. | ||||||
| CLI via the ``$CABAL_EXTERNAL_CABAL_PATH`` variable rather than linking against the ``Cabal`` library. | ||||||
| There is no guarantee that the subcommand will link against the same version of the | ||||||
| ``Cabal`` library as ``cabal-install`` so it would lead to unexpected results and | ||||||
| incompatibilities. | ||||||
|
|
||||||
| Historically, the `cabal-install` binary would pass the name of the executable which it is trying to invoke via the external command feature as | ||||||
| the first argument to the executable itself. The main difference was that ``$CABAL_EXTERNAL_CABAL_PATH`` was called ``$CABAL``, which means that | ||||||
| you can stay compatible with both versions, depending on which variable is set. | ||||||
|
|
||||||
| Mind that if you were implementing external commands previously, you will not need to skip the first argument (the executable name) anymore. | ||||||
|
|
||||||
| ``cabal-install`` can also display the help message of the external command. | ||||||
| When ``cabal help <cmd>`` is invoked, then ``cabal-<cmd> <cmd> --help`` will be called so | ||||||
| your external command can display a help message. | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.