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

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

Open
cartazio opened this issue May 12, 2021 · 8 comments
Open

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

cartazio opened this issue May 12, 2021 · 8 comments

Comments

@cartazio
Copy link
Contributor

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

@cartazio
Copy link
Contributor Author

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

@cartazio
Copy link
Contributor Author

loosely related is #3600

@danidiaz
Copy link
Collaborator

danidiaz commented Jun 12, 2021

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.

@fgaz
Copy link
Member

fgaz commented Jun 13, 2021

This is for cabal-install hooks, right?

@cartazio
Copy link
Contributor Author

I believe yes :)

@danidiaz
Copy link
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?

@fgaz
Copy link
Member

fgaz commented Jun 17, 2021

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?

@fgaz fgaz changed the title shell hooks for augmenting how cabal does various actions? shell hooks for augmenting how cabal-install does various actions? Jun 17, 2021
@fgaz fgaz mentioned this issue Nov 18, 2022
10 tasks
@NorfairKing
Copy link

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
Projects
None yet
Development

No branches or pull requests

5 participants