Skip to content

Commit

Permalink
Remove Internal SetupMethod
Browse files Browse the repository at this point in the history
This SetupMethod is no longer used; it is replaced by the InLibrary
SetupMethod which directly calls Cabal library functions instead of
going through defaultMain.
  • Loading branch information
sheaf authored and alt-romes committed Oct 25, 2024
1 parent 261d345 commit 7a59305
Showing 1 changed file with 1 addition and 40 deletions.
41 changes: 1 addition & 40 deletions cabal-install/src/Distribution/Client/SetupWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import Prelude ()

import qualified Distribution.Backpack as Backpack
import Distribution.CabalSpecVersion (cabalSpecMinimumLibraryVersion)
import qualified Distribution.Make as Make
import Distribution.Package
( ComponentId
, PackageId
Expand All @@ -65,7 +64,6 @@ import Distribution.PackageDescription
, buildType
, specVersion
)
import qualified Distribution.Simple as Simple
import Distribution.Simple.Build.Macros
( generatePackageVersionMacros
)
Expand Down Expand Up @@ -121,9 +119,6 @@ import Distribution.Client.Utils
, makeRelativeToDirS
, moreRecentFile
, tryCanonicalizePath
, withEnv
, withEnvOverrides
, withExtraPathEnv
)
#ifdef mingw32_HOST_OS
import Distribution.Client.Utils
Expand Down Expand Up @@ -285,8 +280,6 @@ data ASetup = forall kind. ASetup ( Setup kind )

-- | @SetupMethod@ represents one of the methods used to run Cabal commands.
data SetupMethod (kind :: SetupKind) where
-- | run Cabal commands through @cabal@ in the current process
InternalMethod :: SetupMethod GeneralSetup
-- | Directly use Cabal library functions, bypassing the Setup
-- mechanism entirely.
LibraryMethod :: SetupMethod InLibrary
Expand Down Expand Up @@ -511,7 +504,6 @@ withSetupMethod verbosity options pkg buildType' allowInLibrary with
with <$> getExternalSetupMethod verbosity options pkg buildType'

runSetupMethod :: WithCallStack (SetupMethod GeneralSetup -> SetupRunner UseGeneralSetup)
runSetupMethod InternalMethod = internalSetupMethod
runSetupMethod (ExternalMethod path) = externalSetupMethod path
runSetupMethod SelfExecMethod = selfExecSetupMethod

Expand Down Expand Up @@ -696,46 +688,15 @@ setupWrapper verbosity options mpkg cmd getCommonFlags getFlags getExtraArgs wra
SRegisterPhase -> InLibrary.register flags lbi extraArgs
NotInLibrary ->
error "internal error: NotInLibrary argument but getSetup chose InLibrary"
InternalMethod -> notInLibraryMethod
ExternalMethod {} -> notInLibraryMethod
SelfExecMethod -> notInLibraryMethod

-- ------------------------------------------------------------

-- * Internal SetupMethod
-- * 'invoke' function

-- ------------------------------------------------------------

-- | Run a Setup script by directly invoking the @Cabal@ library.
internalSetupMethod :: SetupRunner UseGeneralSetup
internalSetupMethod verbosity options bt args NotInLibrary = do
info verbosity $
"Using internal setup method with build-type "
++ show bt
++ " and args:\n "
++ show args
-- NB: we do not set the working directory of the process here, because
-- we will instead pass the -working-dir flag when invoking the Setup script.
-- Note that the Setup script is guaranteed to support this flag, because
-- the logic in 'withSetupMethod' guarantees we have an up-to-date Cabal version.
--
-- In the future, it would be desirable to also stop relying on the following
-- pieces of process-global state, as this would allow us to use this internal
-- setup method in concurrent contexts.
withEnv "HASKELL_DIST_DIR" (getSymbolicPath $ useDistPref options) $
withExtraPathEnv (useExtraPathEnv options) $
withEnvOverrides (useExtraEnvOverrides options) $
buildTypeAction bt args

buildTypeAction :: BuildType -> ([String] -> IO ())
buildTypeAction Simple = Simple.defaultMainArgs
buildTypeAction Configure =
Simple.defaultMainWithSetupHooksArgs
Simple.autoconfSetupHooks
buildTypeAction Make = Make.defaultMainArgs
buildTypeAction Hooks = error "buildTypeAction Hooks"
buildTypeAction Custom = error "buildTypeAction Custom"

invoke :: Verbosity -> FilePath -> [String] -> SetupScriptOptions -> IO ()
invoke verbosity path args options = do
info verbosity $ unwords (path : args)
Expand Down

0 comments on commit 7a59305

Please sign in to comment.