Refactor ProjectBuilding into Package Phases
commitf70fc980dca50e7e62c5e803f56d2ef0c9fc7e18
authorRodrigo Mesquita <rodrigo.m.mesquita@gmail.com>
Fri, 15 Dec 2023 12:21:04 +0000 (15 12:21 +0000)
committerRodrigo Mesquita <rodrigo.m.mesquita@gmail.com>
Mon, 8 Jan 2024 15:25:39 +0000 (8 15:25 +0000)
treeec89ce6fbcd17650ed0e020b9b295f1236d66415
parent49e3d183c0a9ac16da8d4afacc6b8a274ee67608
Refactor ProjectBuilding into Package Phases

This refactor of Distribution.Client.ProjectBuilding does the following:

* Moves package file monitoring logic to
  Distribution.Client.ProjectBuilding.PackageFileMonitor

* Moves the `buildInplaceUnpackedPackage` and
  `buildAndInstallUnpackedPackage` with auxiliary functions to
  Distribution.Client.ProjectBuilding.UnpackedPackage

* Refactors the common bits of `buildInplaceUnpackedPackage` and
  `buildAndInstallUnpackedPackage` to remove considerable code
  duplication while simplifying and making both functions more
  structured.

Namely, to better structure build inplace vs build and install, I've
introduced:

* `PackageBuildingPhase` describes the various phases of processing the
  unpacked package both inplace and on install
    * Configure
    * Build
    * Install (copy + register)
    * Test
    * Bench
    * Repl
    * Haddock

* Then, `buildAndRegisterUnpackedPackage` implements the common logic
  between the two functions (such as calls to ./Setup and the order of
  the phases) but delegates the logic specific to each phase to an
  argument function which maps `PackageBuildingPhase` to `IO` actions.

* Now, build inplace and build and install functions are comprised as:
    * A wrapper around `buildAndRegisterUnpackedPackage` which does
      things specific to each before and after the main phases are
      processed
    * A delegate function which maps an action to each package
      processing phase

Fixes #9499
cabal-install/cabal-install.cabal
cabal-install/src/Distribution/Client/ProjectBuilding.hs
cabal-install/src/Distribution/Client/ProjectBuilding/PackageFileMonitor.hs [new file with mode: 0644]
cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs [new file with mode: 0644]