From 50424c28017c0eb9304888e8cfde12fe4342816f Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 12 Jul 2020 22:29:50 +0200 Subject: [PATCH] Allow to build with tar-bytestring on e.g. 32bit --- .gitlab/script/ghcup_release.sh | 2 +- app/ghcup/BrickMain.hs | 21 ++++++++++++++++++++- app/ghcup/Main.hs | 8 ++++++++ ghcup.cabal | 26 +++++++++++++++++++++++--- lib/GHCup.hs | 10 ++++++++++ lib/GHCup/Utils.hs | 22 +++++++++++++++++++++- 6 files changed, 83 insertions(+), 6 deletions(-) diff --git a/.gitlab/script/ghcup_release.sh b/.gitlab/script/ghcup_release.sh index 402fbe4..da0d839 100755 --- a/.gitlab/script/ghcup_release.sh +++ b/.gitlab/script/ghcup_release.sh @@ -17,7 +17,7 @@ ecabal update if [ "${OS}" = "LINUX" ] ; then if [ "${BIT}" = "32" ] ; then - ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections -optl-static' + ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections -optl-static' -ftui -ftar else ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections -optl-static' -ftui fi diff --git a/app/ghcup/BrickMain.hs b/app/ghcup/BrickMain.hs index 7a6ab8a..a8d8840 100644 --- a/app/ghcup/BrickMain.hs +++ b/app/ghcup/BrickMain.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TypeApplications #-} @@ -19,7 +20,9 @@ import Brick.Widgets.Border import Brick.Widgets.Border.Style import Brick.Widgets.Center import Brick.Widgets.List +#if !defined(TAR) import Codec.Archive +#endif import Control.Exception.Safe import Control.Monad.Logger import Control.Monad.Reader @@ -196,7 +199,23 @@ install' AppState {..} (_, ListResult {..}) = do . flip runReaderT settings . runResourceT . runE - @'[AlreadyInstalled, UnknownArchive, ArchiveResult, DistroNotFound, FileDoesNotExistError, CopyError, NoCompatibleArch, NoDownload, NotInstalled, NoCompatiblePlatform, BuildFailed, TagNotFound, DigestError, DownloadFailed, NoUpdate] + @'[AlreadyInstalled + , UnknownArchive +#if !defined(TAR) + , ArchiveResult +#endif + , DistroNotFound + , FileDoesNotExistError + , CopyError + , NoCompatibleArch + , NoDownload + , NotInstalled + , NoCompatiblePlatform + , BuildFailed + , TagNotFound + , DigestError + , DownloadFailed + , NoUpdate] (run $ do case lTool of diff --git a/app/ghcup/Main.hs b/app/ghcup/Main.hs index 1206013..68d73fb 100644 --- a/app/ghcup/Main.hs +++ b/app/ghcup/Main.hs @@ -28,7 +28,9 @@ import GHCup.Utils.Prelude import GHCup.Utils.String.QQ import GHCup.Version +#if !defined(TAR) import Codec.Archive +#endif import Control.Exception.Safe #if !MIN_VERSION_base(4,13,0) import Control.Monad.Fail ( MonadFail ) @@ -909,7 +911,9 @@ Report bugs at |] . runE @'[ AlreadyInstalled , UnknownArchive +#if !defined(TAR) , ArchiveResult +#endif , DistroNotFound , FileDoesNotExistError , CopyError @@ -969,7 +973,9 @@ Report bugs at |] , NotFoundInPATH , PatchFailed , UnknownArchive +#if !defined(TAR) , ArchiveResult +#endif ] let runCompileCabal = @@ -989,7 +995,9 @@ Report bugs at |] , NotInstalled , PatchFailed , UnknownArchive +#if !defined(TAR) , ArchiveResult +#endif ] let runUpgrade = diff --git a/ghcup.cabal b/ghcup.cabal index 0b890a9..5e18790 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -31,6 +31,11 @@ flag internal-downloader default: False manual: True +flag tar + description: Use tar-bytestring instead of libarchive + default: False + manual: True + common HsOpenSSL build-depends: HsOpenSSL >=0.11.4.18 @@ -169,6 +174,9 @@ common table-layout common template-haskell build-depends: template-haskell >=2.7 +common tar-bytestring + build-depends: tar-bytestring >=0.6.3.1 + common terminal-progress-bar build-depends: terminal-progress-bar >=0.4.1 @@ -253,7 +261,6 @@ library , hpath-filepath , hpath-io , hpath-posix - , libarchive , lzma , megaparsec , monad-logger @@ -315,13 +322,21 @@ library if flag(internal-downloader) import: - , HsOpenSSL + HsOpenSSL , http-io-streams , io-streams , terminal-progress-bar exposed-modules: GHCup.Download.IOStreams cpp-options: -DINTERNAL_DOWNLOADER + if flag(tar) + import: + tar-bytestring + cpp-options: -DTAR + else + import: + libarchive + executable ghcup import: config @@ -331,7 +346,6 @@ executable ghcup , haskus-utils-variant , hpath , hpath-io - , libarchive , megaparsec , monad-logger , mtl @@ -368,6 +382,12 @@ executable ghcup other-modules: BrickMain cpp-options: -DBRICK + if flag(tar) + cpp-options: -DTAR + else + import: + libarchive + executable ghcup-gen import: config diff --git a/lib/GHCup.hs b/lib/GHCup.hs index 3e46466..80d46ea 100644 --- a/lib/GHCup.hs +++ b/lib/GHCup.hs @@ -27,7 +27,9 @@ import GHCup.Utils.String.QQ import GHCup.Utils.Version.QQ import GHCup.Version +#if !defined(TAR) import Codec.Archive ( ArchiveResult ) +#endif import Control.Applicative import Control.Exception.Safe import Control.Monad @@ -97,7 +99,9 @@ installGHCBin :: ( MonadFail m , NoDownload , NotInstalled , UnknownArchive +#if !defined(TAR) , ArchiveResult +#endif ] m () @@ -167,7 +171,9 @@ installCabalBin :: ( MonadMask m , NoDownload , NotInstalled , UnknownArchive +#if !defined(TAR) , ArchiveResult +#endif ] m () @@ -613,7 +619,9 @@ compileGHC :: ( MonadMask m , NotFoundInPATH , PatchFailed , UnknownArchive +#if !defined(TAR) , ArchiveResult +#endif ] m () @@ -792,7 +800,9 @@ compileCabal :: ( MonadReader Settings m , NotInstalled , PatchFailed , UnknownArchive +#if !defined(TAR) , ArchiveResult +#endif ] m () diff --git a/lib/GHCup/Utils.hs b/lib/GHCup/Utils.hs index cabea40..e137b63 100644 --- a/lib/GHCup/Utils.hs +++ b/lib/GHCup/Utils.hs @@ -24,7 +24,9 @@ import GHCup.Utils.MegaParsec import GHCup.Utils.Prelude import GHCup.Utils.String.QQ +#if !defined(TAR) import Codec.Archive +#endif import Control.Applicative import Control.Exception.Safe import Control.Monad @@ -59,13 +61,18 @@ import System.Posix.Files.ByteString ( readSymbolicLink ) import Text.Regex.Posix import URI.ByteString +#if defined(TAR) +import qualified Codec.Archive.Tar as Tar +#endif import qualified Codec.Compression.BZip as BZip import qualified Codec.Compression.GZip as GZip import qualified Codec.Compression.Lzma as Lzma import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.Map.Strict as Map +#if !defined(TAR) import qualified Data.Text as T +#endif import qualified Data.Text.Encoding as E import qualified Text.Megaparsec as MP @@ -312,17 +319,30 @@ getLatestGHCFor major' minor' dls = do unpackToDir :: (MonadLogger m, MonadIO m, MonadThrow m) => Path Abs -- ^ destination dir -> Path Abs -- ^ archive path - -> Excepts '[UnknownArchive, ArchiveResult] m () + -> Excepts '[UnknownArchive +#if !defined(TAR) + , ArchiveResult +#endif + ] m () unpackToDir dest av = do fp <- (decUTF8Safe . toFilePath) <$> basename av let dfp = decUTF8Safe . toFilePath $ dest lift $ $(logInfo) [i|Unpacking: #{fp} to #{dfp}|] fn <- toFilePath <$> basename av +#if defined(TAR) + let untar :: MonadIO m => BL.ByteString -> Excepts '[] m () + untar = liftIO . Tar.unpack (toFilePath dest) . Tar.read +#else let untar :: MonadIO m => BL.ByteString -> Excepts '[ArchiveResult] m () untar = lEM . liftIO . runArchiveM . unpackToDirLazy (T.unpack . decUTF8Safe . toFilePath $ dest) +#endif +#if defined(TAR) + rf :: MonadIO m => Path Abs -> Excepts '[] m BL.ByteString +#else rf :: MonadIO m => Path Abs -> Excepts '[ArchiveResult] m BL.ByteString +#endif rf = liftIO . readFile -- extract, depending on file extension