Skip to content
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

Finish off external commands feature #9412

Merged
merged 2 commits into from
Nov 24, 2023

Conversation

mpickering
Copy link
Collaborator

Finish off the external commands feature

* Remove 'CommandDelegate' in favour of abstracting the fallback in
  'commandsRun', there is a new variant 'commdandRunWithFallback' which
  takes a continuation
  - This restores the modularity between the `Cabal` library and
    `cabal-install` as now `Cabal` doesn't need to know anything about
    the external command interface.
  - Fixes #9403
* Set the $CABAL environment variable to the current executable path
  - This allows external commands to be implemented by calling $CABAL,
    which is strongly preferred to linking against the Cabal library as
    there is no easy way to guantee your tool and `cabal-install` link
    against the same `Cabal` library.
  - Fixes #9402
* Pass the name of the argument
  - This allows external commands to be implemented as symlinks to an
    executable, and multiple commands can be interpreted by the same
    executable.
  - Fixes #9405
* `cabal help <cmd>` is interpreted as `cabal-<cmd> --help` for external
  commands.
  - This allows the `help` command to also work for external
  commands and hence they are better integrated into cabal-install.
  - Fixes #9404

The tests are updated to test all these additions.

These features bring the external command interface up to par with the
cargo external command interface.

@mpickering mpickering changed the title Wip/external commands fixes Finish off external commands feature Nov 6, 2023
@mpickering mpickering force-pushed the wip/external-commands-fixes branch from c3b8109 to 02605e9 Compare November 6, 2023 16:59
@yvan-sraka yvan-sraka self-requested a review November 7, 2023 07:50
Copy link
Collaborator

@yvan-sraka yvan-sraka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great to have this feature rewritten in better shape, thanks a lot for that and all the corner cases you spotted and fixed :)

I'm new to Cabal contributors and not sure to understand the point of adding new LICENSE files?

@geekosaur
Copy link
Collaborator

They're added for the tests, which are implemented as full Cabal packages and therefore require license files.

@@ -355,6 +355,28 @@ mainWorker args = do
warnIfAssertionsAreEnabled
action globalFlags
where
delegateToExternal :: [Command Action]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for finding and calling subcommands is now contained solely here (inside cabal-install) rather than leaking into the Cabal library.

-> IO (CommandParse action)
defaultCommandFallback commands' name _cmdArgs = pure $ badCommand commands' name

commandsRunWithFallback
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commandRun is parameterised by a continuation which is used to handle the fallback case in different ways for Cabal and cabal-install.

-> [String]
-> IO (CommandParse Action)
delegateToExternal commands' name cmdArgs = do
mCommand <- findProgramOnSearchPath normal defaultProgramSearchPath ("cabal-" <> name)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this would fix the test failure on windows but it still seems to persist.

@mpickering mpickering force-pushed the wip/external-commands-fixes branch from 2a803aa to ec076de Compare November 9, 2023 13:20
@mpickering
Copy link
Collaborator Author

I have fixed CI now, so this patch is ready to merge.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 9, 2023

I've given @yvan-sraka the Triage authority which, once accepted, will make the review binding for github.

@mpickering: feel free to set a merge label, unless you'd like more reviews, in which case, please set the appropriate label, too.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 23, 2023

It turns out Write permission is needed for reviews to be counted for the 2-review threshold, so I've given this high level of authority to @yvan-sraka. I hope in 2 days this gets auto-merged. (Let me rebase via mergify just in case; edit: especially that CI mandatory tests settings have changed, so this is stuck.)

@Mikolaj
Copy link
Member

Mikolaj commented Nov 23, 2023

@mergify rebase

Copy link
Contributor

mergify bot commented Nov 23, 2023

rebase

✅ Branch has been successfully rebased

@Mikolaj Mikolaj force-pushed the wip/external-commands-fixes branch from ec076de to 1c3bd64 Compare November 23, 2023 12:00
@Mikolaj Mikolaj added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Nov 24, 2023
This adds 4 tests which test the new external commands feature:

* ExternalCommand - Tests the expected usage of external command invoked
  via cabal-install
* ExternalCommandSetup - Tests that the ./Setup interface does not
  support external commands (haskell#9403)
* ExternalCommandEnv - Tests that environment variables are set and
  preserved appropiately  (haskell#9402)
* ExternalCommandHelp - Test that `cabal help <cmd>` is interpreted appropiately (haskell#9404)
* Remove 'CommandDelegate' in favour of abstracting the fallback in
  'commandsRun', there is a new variant 'commdandRunWithFallback' which
  takes a continuation
  - This restores the modularity between the `Cabal` library and
    `cabal-install` as now `Cabal` doesn't need to know anything about
    the external command interface.
  - Fixes haskell#9403
* Set the $CABAL environment variable to the current executable path
  - This allows external commands to be implemented by calling $CABAL,
    which is strongly preferred to linking against the Cabal library as
    there is no easy way to guantee your tool and `cabal-install` link
    against the same `Cabal` library.
  - Fixes haskell#9402
* Pass the name of the argument
  - This allows external commands to be implemented as symlinks to an
    executable, and multiple commands can be interpreted by the same
    executable.
  - Fixes haskell#9405
* `cabal help <cmd>` is interpreted as `cabal-<cmd> --help` for external
  commands.
  - This allows the `help` command to also work for external
  commands and hence they are better integrated into cabal-install.
  - Fixes haskell#9404

The tests are updated to test all these additions.

These features bring the external command interface up to par with the
cargo external command interface.
@Mikolaj Mikolaj force-pushed the wip/external-commands-fixes branch from 1c3bd64 to d8ebb81 Compare November 24, 2023 15:22
@Mikolaj
Copy link
Member

Mikolaj commented Nov 24, 2023

I took the liberty of making up for the admin delays by setting the merge_delay_passed label manually. The PR is ready and reviewed since last week.

@mergify mergify bot merged commit 4f53a2f into haskell:master Nov 24, 2023
30 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cabal-install: cmd/external-cmd merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants