From 633d08146ab38770251b5921e2051bca16e94a72 Mon Sep 17 00:00:00 2001
From: Andrea Bedini <andrea.bedini@tweag.io>
Date: Thu, 25 Jan 2024 18:48:01 +0800
Subject: [PATCH] Create setupWrapperNew for ProjectBuilding

---
 .../Client/ProjectBuilding/UnpackedPackage.hs |  6 +++---
 .../src/Distribution/Client/SetupWrapper.hs   | 21 +++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs b/cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs
index 157d0fa09a4..edbc037fc6a 100644
--- a/cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs
+++ b/cabal-install/src/Distribution/Client/ProjectBuilding/UnpackedPackage.hs
@@ -47,7 +47,7 @@ import Distribution.Client.Setup
   , filterHaddockFlags
   , filterTestFlags
   )
-import Distribution.Client.SetupWrapper
+import Distribution.Client.SetupWrapper (SetupScriptOptions (..), setupWrapperNew)
 import Distribution.Client.SourceFiles
 import Distribution.Client.SrcDist (allPackageSourceFiles)
 import qualified Distribution.Client.Tar as Tar
@@ -342,7 +342,7 @@ buildAndRegisterUnpackedPackage
         -> IO ()
       setup cmd flags args =
         withLogging $ \mLogFileHandle ->
-          setupWrapper
+          setupWrapperNew
             verbosity
             scriptOptions
               { useLoggingHandle = mLogFileHandle
@@ -362,7 +362,7 @@ buildAndRegisterUnpackedPackage
         -> (Version -> [String])
         -> IO ()
       setupInteractive cmd flags args =
-        setupWrapper
+        setupWrapperNew
           verbosity
           scriptOptions{isInteractive = True}
           (Just (elabPkgDescription pkg))
diff --git a/cabal-install/src/Distribution/Client/SetupWrapper.hs b/cabal-install/src/Distribution/Client/SetupWrapper.hs
index eba9b833d9d..8359c8938b3 100644
--- a/cabal-install/src/Distribution/Client/SetupWrapper.hs
+++ b/cabal-install/src/Distribution/Client/SetupWrapper.hs
@@ -26,6 +26,7 @@ module Distribution.Client.SetupWrapper
   , setupWrapper
   , SetupScriptOptions (..)
   , defaultSetupScriptOptions
+  , setupWrapperNew
   ) where
 
 import Distribution.Client.Compat.Prelude
@@ -505,6 +506,26 @@ setupWrapper verbosity options mpkg cmd flags extraArgs = do
     (flags $ setupVersion setup)
     (extraArgs $ setupVersion setup)
 
+-- | Configure a 'Setup' and run a command in one step. The command flags
+-- may depend on the Cabal library version in use.
+setupWrapperNew
+  :: Verbosity
+  -> SetupScriptOptions
+  -> Maybe PackageDescription
+  -> CommandUI flags
+  -> (Version -> flags)
+  -- ^ produce command flags given the Cabal library version
+  -> (Version -> [String])
+  -> IO ()
+setupWrapperNew verbosity options mpkg cmd flags extraArgs = do
+  setup <- getSetup verbosity options mpkg
+  runSetupCommand
+    verbosity
+    setup
+    cmd
+    (flags $ setupVersion setup)
+    (extraArgs $ setupVersion setup)
+
 -- ------------------------------------------------------------
 
 -- * Internal SetupMethod