From 0e2a04a4da948a48e3dad54e794a2ed551c8dcc5 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sat, 30 Mar 2024 23:21:25 +0000 Subject: [PATCH] Re #6540 Temporarily work around Cabal-3.11.0.0 in StackSetupShim.hs --- src/setup-shim/StackSetupShim.hs | 55 ++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/src/setup-shim/StackSetupShim.hs b/src/setup-shim/StackSetupShim.hs index 176ec7525d..c723a6d3f4 100644 --- a/src/setup-shim/StackSetupShim.hs +++ b/src/setup-shim/StackSetupShim.hs @@ -4,18 +4,33 @@ module StackSetupShim where import Main #if defined(MIN_VERSION_Cabal) #if MIN_VERSION_Cabal(3,8,1) -import Distribution.PackageDescription (PackageDescription, emptyHookedBuildInfo) +import Distribution.PackageDescription + ( PackageDescription, emptyHookedBuildInfo ) #else -import "Cabal" Distribution.PackageDescription (PackageDescription, emptyHookedBuildInfo) +import "Cabal" Distribution.PackageDescription + ( PackageDescription, emptyHookedBuildInfo ) #endif #else -import Distribution.PackageDescription (PackageDescription, emptyHookedBuildInfo) +import Distribution.PackageDescription + ( PackageDescription, emptyHookedBuildInfo ) #endif import Distribution.Simple import Distribution.Simple.Build -import Distribution.Simple.Setup (ReplFlags, fromFlag, replDistPref, replVerbosity) -import Distribution.Simple.LocalBuildInfo (LocalBuildInfo) -import System.Environment (getArgs) +import Distribution.Simple.Setup + ( ReplFlags, fromFlag, replDistPref, replVerbosity ) +import Distribution.Simple.LocalBuildInfo ( LocalBuildInfo ) +-- | Temporary, can be removed if initialBuildSteps restored to Cabal's API. +#if defined(MIN_VERSION_Cabal) +#if MIN_VERSION_Cabal(3,11,0) +import Distribution.Simple.LocalBuildInfo + ( ComponentLocalBuildInfo, componentBuildDir + , withAllComponentsInBuildOrder + ) +import Distribution.Simple.Utils ( createDirectoryIfMissingVerbose ) +import Distribution.Verbosity ( Verbosity ) +#endif +#endif +import System.Environment ( getArgs ) mainOverride :: IO () mainOverride = do @@ -39,3 +54,31 @@ stackReplHook pkg_descr lbi hooks flags args = do | otherwise -> fail "Misuse of running Setup.hs with stack-initial-build-steps, expected no arguments" _ -> replHook simpleUserHooks pkg_descr lbi hooks flags args + +-- | Temporary, can be removed if initialBuildSteps restored to Cabal's API. +#if defined(MIN_VERSION_Cabal) +#if MIN_VERSION_Cabal(3,11,0) +-- | Runs 'componentInitialBuildSteps' on every configured component. +initialBuildSteps :: + FilePath -- ^"dist" prefix + -> PackageDescription -- ^mostly information from the .cabal file + -> LocalBuildInfo -- ^Configuration information + -> Verbosity -- ^The verbosity to use + -> IO () +initialBuildSteps distPref pkg_descr lbi verbosity = + withAllComponentsInBuildOrder pkg_descr lbi $ \_comp clbi -> + componentInitialBuildSteps distPref pkg_descr lbi clbi verbosity + +-- | Creates the autogenerated files for a particular configured component. +componentInitialBuildSteps :: + FilePath -- ^"dist" prefix + -> PackageDescription -- ^mostly information from the .cabal file + -> LocalBuildInfo -- ^Configuration information + -> ComponentLocalBuildInfo + -> Verbosity -- ^The verbosity to use + -> IO () +componentInitialBuildSteps _distPref pkg_descr lbi clbi verbosity = do + createDirectoryIfMissingVerbose verbosity True (componentBuildDir lbi clbi) + writeBuiltinAutogenFiles verbosity pkg_descr lbi clbi +#endif +#endif