Skip to content

Commit

Permalink
Add Distribution.Client.Main
Browse files Browse the repository at this point in the history
This makes it easier to integrate `cabal-install` into other tools.
  • Loading branch information
sol authored and mergify[bot] committed Feb 26, 2023
1 parent c53acf5 commit b54cf39
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
9 changes: 4 additions & 5 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ library
Distribution.Client.InstallSymlink
Distribution.Client.JobControl
Distribution.Client.List
Distribution.Client.Main
Distribution.Client.Manpage
Distribution.Client.ManpageFlags
Distribution.Client.Nix
Expand Down Expand Up @@ -252,9 +253,9 @@ library


executable cabal
import: warnings, base-dep, cabal-dep, cabal-syntax-dep
import: warnings, base-dep
main-is: Main.hs
hs-source-dirs: main
hs-source-dirs: driver
default-language: Haskell2010

ghc-options: -rtsopts -threaded
Expand All @@ -264,9 +265,7 @@ executable cabal
extra-libraries: bsd

build-depends:
cabal-install,
directory,
filepath
cabal-install

-- Small, fast running tests.
--
Expand Down
11 changes: 11 additions & 0 deletions cabal-install/driver/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Main (main) where

import Prelude ()
import Distribution.Client.Compat.Prelude

import System.Environment (getArgs)

import qualified Distribution.Client.Main as Client

main :: IO ()
main = getArgs >>= Client.main
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
-- Portability : portable
--
-- Entry point to the default cabal-install front-end.
--
-- @since 3.10.0.0
-----------------------------------------------------------------------------

module Main (main) where
module Distribution.Client.Main (main) where

import Distribution.Client.Setup
( GlobalFlags(..), globalCommand, withRepoContext
Expand Down Expand Up @@ -160,7 +162,7 @@ import Distribution.Version
( Version, mkVersion, orLaterVersion )

import Distribution.Compat.ResponseFile
import System.Environment (getArgs, getProgName)
import System.Environment (getProgName)
import System.FilePath ( dropExtension, splitExtension
, takeExtension, (</>), (<.>) )
import System.IO ( BufferMode(LineBuffering), hSetBuffering
Expand All @@ -173,8 +175,8 @@ import Control.Exception (AssertionFailed, assert, try)

-- | Entry point
--
main :: IO ()
main = do
main :: [String] -> IO ()
main args = do
installTerminationHandler
-- Enable line buffering so that we can get fast feedback even when piped.
-- This is especially important for CI and build systems.
Expand All @@ -185,7 +187,8 @@ main = do
-- when writing to stderr and stdout.
relaxEncodingErrors stdout
relaxEncodingErrors stderr
(args0, args1) <- break (== "--") <$> getArgs
let (args0, args1) = break (== "--") args

mainWorker =<< (++ args1) <$> expandResponse args0

-- | Check whether assertions are enabled and print a warning in that case.
Expand Down

0 comments on commit b54cf39

Please sign in to comment.