Skip to content

Commit e8c9de7

Browse files
committed
Refactoring in preparation of #11411
This commit includes a series of refactorings that are necessary to solve #11411: - Abstract the Rebuild monad into the MonadRebuild typeclass, introducing the `withRunRebuildInIO` method of MonadRebuild. This allows us to interleave plain `IO` with `MonadRebuild` without necessarily having to use `Rebuild` itself. This is especially important because `Rebuild` also encodes the "current working directory" concern, which is relevant within `cabal-install`, but something we don't want to require within the `Cabal` library. Since the `MonadRebuild` typeclass allows for arbitrary custom monadic state per instance, it can live in the `Cabal` subproject, together with operations defined in terms of the typeclass, while `Rebuild` itself remains in `cabal-install`, using the custom monadic state to cover the "current working directory" concern. - Change the `StateT` part of `Rebuild` into `WriterT`, since we only ever emit additional files from within a Rebuild context; consuming them happens on the outside, so Writer is sufficient. - Provide `MonadRebuild` instances for the existing `Rebuild` type, and for the most minimal type that can satisfy the typeclass, `WriterT [MonitorFilePath] IO`. - Implement most file monitoring / Rebuild actions in terms of `MonadRebuild`, so they can live in `Cabal` (`Distribution.Simple.RebuildMonad`), leaving only `cabal-install` specific things in the existing `cabal-install` module (`Distribution.Client.RebuildMonad`). Specifically, we implement `rerunIfChanged'` in terms of `MonadRebuild` and a custom function for chaining `IO` actions (serially or in parallel, as needed); the existing `rerunIfChanged` and `rerunConcurrentlyIfChanged` functions, which live in `cabal-install`, are now implemented in terms of `rerunIfChanged'`, which lives in `Cabal`). - Move large parts of the `Distribution.Client.FileMonitor` module from `cabal-install` to `Cabal` (as `Distribution.Simple.FileMonitor`); we will be needing these parts to solve #11411 (`Distribution.Client.FileMonitor` still re-exports all of them though). - Move most of the `Distribution.Client.HashValue` module over to `Cabal` (with the exception of TUF-related functions, which are specific to `cabal-install`; again we re-export everything in `cabal-install` to maintain API compatibility). - Move `getFilePathRootDirectory` from `Distribution.Client.Glob` into `Distribution.Simple.FileMonitor.Types` - it has little to do with actual globs, and is only used for file monitoring purposes. - Shuffle some utility functions around to make them accessible where we need them. The big picture with all this is that we want to reuse the existing file monitoring machinery to keep track of build-tool versions alongside generated source files. However, the tracking needs to happen in the `Cabal` library, while file monitoring has so far only been available in `cabal-install`; hence we need to move the required file monitoring code and its dependencies into the `Cabal` library, but without introducing any `cabal-install` specific concerns into `Cabal`, and without breaking API compatibility on the `cabal-install` side. Provide minimal `MonadRebuild` instance
1 parent ca5ddff commit e8c9de7

12 files changed

Lines changed: 1796 additions & 1570 deletions

File tree

Cabal/Cabal.cabal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ library
4242
, Cabal-syntax ^>= 3.17
4343
, array >= 0.4.0.1 && < 0.6
4444
, base >= 4.13 && < 5
45+
, base16-bytestring >= 1.0 && < 1.1
46+
, binary >= 0.7.3 && < 0.9
4547
, bytestring >= 0.10.8 && < 0.13
4648
, containers >= 0.5.8.2 && < 0.9
49+
, cryptohash-sha256 >= 0.11 && < 0.12
4750
, deepseq >= 1.3.0.1 && < 1.7
4851
, directory >= 1.2.7 && < 1.4
4952
, filepath >= 1.4.2 && < 1.6
@@ -121,11 +124,13 @@ library
121124
Distribution.Simple.Compiler
122125
Distribution.Simple.Configure
123126
Distribution.Simple.Errors
127+
Distribution.Simple.FileMonitor
124128
Distribution.Simple.FileMonitor.Types
125129
Distribution.Simple.Flag
126130
Distribution.Simple.GHC
127131
Distribution.Simple.GHCJS
128132
Distribution.Simple.Haddock
133+
Distribution.Simple.HashValue
129134
Distribution.Simple.Glob
130135
Distribution.Simple.Glob.Internal
131136
Distribution.Simple.Hpc
@@ -153,6 +158,7 @@ library
153158
Distribution.Simple.Program.Script
154159
Distribution.Simple.Program.Strip
155160
Distribution.Simple.Program.Types
161+
Distribution.Simple.RebuildMonad
156162
Distribution.Simple.Register
157163
Distribution.Simple.Setup
158164
Distribution.Simple.ShowBuildInfo

0 commit comments

Comments
 (0)