From 56349decc7265993d6338d41def35dd09ed546b3 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Wed, 17 Apr 2024 14:52:06 +1000 Subject: [PATCH] Add pre and post build hooks Run a program (named "preBuildHook") before doing a package build and another program (named "postBuildHook") after the package is built. These two programs simply need to be on the users $PATH variable and are completely generic. Co-authored: Moritz Angermann --- .../Client/ProjectBuilding/UnpackedPackage.hs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs b/cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs index 065334d5c6e..cef3d793f06 100644 --- a/cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs +++ b/cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs @@ -678,7 +678,31 @@ buildAndInstallUnpackedPackage runConfigure PBBuildPhase{runBuild} -> do noticeProgress ProgressBuilding - runBuild + -- run preBuildHook. If it returns with 0, we assume the build was + -- successful. If not, run the build. + code <- + rawSystemExitCode + verbosity + (Just srcdir) + "preBuildHook" + [ (unUnitId $ installedUnitId rpkg) + , (getSymbolicPath srcdir) + , (getSymbolicPath builddir) + ] + `catchIO` (\_ -> return (ExitFailure 10)) + when (code /= ExitSuccess) $ do + runBuild + -- not sure, if we want to care about a failed postBuildHook? + void $ + rawSystemExitCode + verbosity + (Just srcdir) + "postBuildHook" + [ (unUnitId $ installedUnitId rpkg) + , (getSymbolicPath srcdir) + , (getSymbolicPath builddir) + ] + `catchIO` (\_ -> return (ExitFailure 10)) PBHaddockPhase{runHaddock} -> do noticeProgress ProgressHaddock runHaddock