Skip to content

Cabal library: allow setting the logging handle #11077

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sheaf
Copy link
Collaborator

@sheaf sheaf commented Jul 17, 2025

Template Α: This PR modifies behaviour or interface.

The goal of this patch is to allow the logging handle to be set when calling Cabal library functions, without having to spawn a separate process and redirect handles. This allows Cabal library functions to be called in a concurrent setting without spawning separate processes.

To achieve this, this PR modifies Verbosity as follows:

  1. The old Verbosity datatype becomes VerbosityFlags. This is what gets passed in the command-line interface, e.g. when running a Setup executable.
  2. The new Verbosity datatype contains VerbosityFlags together with VerbosityHandles, which specify where to redirect stdout/stderr.

Crucially, this allows us to get rid of the

  isJust (useLoggingHandle options)

condition in getSetupMethod, which forced us to use the cabal-install "act as setup" mechanism instead of directly calling Cabal library functions.

Several additional changes have been made in relation to the VerbosityFlags data type (which, recall, is what Verbosity used to be):

  1. The Ord instance of VerbosityFlags has been removed.
    Comparing verbosity levels is now done through the Ord instance on VerbosityLevel, via verbosityLevel :: Verbosity -> VerbosityLevel.
  2. The Eq instance of VerbosityFlags now takes into account all the fields, and not only the verbosity level.
  3. The Enum and Bounded instances of VerbosityFlags have been removed.
    Users are again encouraged to go through VerbosityLevel instead.

In addition, the modifyVerbosity function has been removed. It allowed arbitrarily changing the verbosity level, which is undesirable in general (e.g. in practice one wants the "silent" verbosity level to remain "silent").
There was only one use site, which was rewritten to use the new makeVerbose function which increases the "normal" verbosity level to "verbose" and leaves other verbosity levels unchanged.


@sheaf sheaf force-pushed the wip/verbosity-handle branch 6 times, most recently from 0b6b552 to 4ed7d13 Compare July 17, 2025 15:52
@mpickering
Copy link
Collaborator

It does occur to me, that the next step after this PR is to use a proper logging framework (ie. a contravariant logger) within the Cabal library.

That would be even more general than the VerbosityHandles approach in this MR.

@sheaf sheaf force-pushed the wip/verbosity-handle branch 4 times, most recently from 3253ca2 to 4f85396 Compare July 18, 2025 14:02
@geekosaur
Copy link
Collaborator

The problem with using a logging framework is bootstrapping.

@sheaf sheaf force-pushed the wip/verbosity-handle branch 2 times, most recently from 30af75a to cb24b34 Compare July 21, 2025 09:01
@mpickering
Copy link
Collaborator

The problem with using a logging framework is bootstrapping.

It seems that you could add a single-file implementation of a logging library which Cabal could use if it was desired. Perhaps not ideal, but also not the end of the world.

@sheaf sheaf force-pushed the wip/verbosity-handle branch 8 times, most recently from 5ba03ea to afd8839 Compare July 21, 2025 15:03
@sheaf
Copy link
Collaborator Author

sheaf commented Jul 21, 2025

I have added a changelog entry under pr-11077, which goes over the user-facing changes and gives some advice about migrating.

The goal of this patch is to allow the logging handle to be set when
calling Cabal library functions, without having to spawn a separate
process and redirect handles. This allows Cabal library functions to
be called in a concurrent setting without spawning separate processes.

To achieve this, this commit modifies Verbosity as follows:

  1. The old Verbosity datatype becomes VerbosityFlags. This is what
     gets passed in the command-line interface, e.g. when running a
     Setup executable.
  2. The new Verbosity datatype contains VerbosityFlags together with
     VerbosityHandles, which specify where to redirect stdout/stderr.

Crucially, this allows us to get rid of the

  isJust (useLoggingHandle options)

condition in 'getSetupMethod', which forced us to use the cabal-install
"act as setup" mechanism instead of directly calling Cabal library
functions.

Fixes #9987
@sheaf sheaf force-pushed the wip/verbosity-handle branch from afd8839 to 489fb11 Compare July 21, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants