Skip to content

shell hooks for augmenting how cabal-install does various actions? #7394

Open

Description

@cartazio

maybe theres a ticket about this, but i was talking with @hasufell about cabal and he mentioned that in old discussions with HVR, there was the idea of making it easier to glue cabal into a overall toolchain if there were the sort of shell hooks a la git-hooks or https://paludis.exherbo.org/configuration/hooks.html

with example application for example being:
and then you could hook into phases of like pre_configure and invoke ghcup automatically, installing the requested project ghc version

at the moment, i think cabal's pre/post-$FOO (for some value of FOO) hooks are only supported as haskell function call backs, which hits a different point in the ease of scripting tradeoffs

Activity

  1. cartazio commented on May 12, 2021

    @cartazio
    ContributorAuthor

    there may already be a tracking ticket related to this, but i'm not super familiar with older tickets ;)

  2. cartazio commented on May 12, 2021

    @cartazio
    ContributorAuthor

    loosely related is #3600

  3. danidiaz commented on Jun 12, 2021

    @danidiaz
    Collaborator

    One possible way of supporting hooks is by extending the experimental branch described here.

    In that branch, functions like runProjectPreBuildPhase and freezeAction have been wrapped in newtypes.

    Potential "hooks" that added behavior to those functions (shell invocations, logging, and so on) could be defined as functions RunProjectPreBuildPhase -> RunProjectPreBuildPhase or FreezeAction -> FreezeAction, respectively. And they could be applied to the original functions here, in the so-called "composition context". If the hooks needed to allocate some resources of their own, it could also be done there.

  4. fgaz commented on Jun 13, 2021

    @fgaz
    Member

    This is for cabal-install hooks, right?

  5. cartazio commented on Jun 13, 2021

    @cartazio
    ContributorAuthor

    I believe yes :)

  6. danidiaz commented on Jun 15, 2021

    @danidiaz
    Collaborator

    A proof-of-concept of how cabal-install script hooks could work is here.

    In the cabal project we wish to compile, the following folder structure should exist:

    cabal.hooks/
    └── before_pre_build.sh
    

    cabal-install ignores the hooks by default; hook handling is enabled through an environment variable, like this:

    $ CABAL_INSTALL_INSTRUMENTATIONS=hooks cabal build all
    

    The before_pre_build.sh script is passed the value of the following cabal.project setting as an argument:

    with-compiler: ghc-8.10.2
    

    An example of before_pre_build.sh that calls ghcup:

    #!/bin/bash
    IFS='-'
    read -a ghcversion <<< "$1"
    echo ${ghcversion[1]}
    ghcup install  ${ghcversion[0]} ${ghcversion[1]}
    

    The hook-handling code is in Distribution.Client.Instrumentation.Hooks.

    There's no need of course for all the fancy inversion of control used in this example: cabal-install hook management could be integrated in the runProjectPreBuildPhase function itself, although perhaps that would complicate its code a little.

    One thing to consider is what subset of the configuration information available at the pre-build phase should be passed to the script—and in what manner. Passing everything as script parameters might not be a good idea if we pass a lot of things, many of them optional. Perhaps we could write values to the script's stdin?

  7. fgaz commented on Jun 17, 2021

    @fgaz
    Member

    One thing to consider is what subset of the configuration information available at the pre-build phase should be passed to the script—and in what manner. Passing everything as script parameters might not be a good idea if we pass a lot of things, many of them optional. Perhaps we could write values to the script's stdin?

    what about environment variables?

  8. changed the title [-]shell hooks for augmenting how cabal does various actions?[/-] [+]shell hooks for augmenting how cabal-install does various actions?[/+] on Jun 17, 2021
  9. NorfairKing commented on Apr 23, 2023

    @NorfairKing

    What's the status of the implementation of issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions