From f38daf67730fe31b865528eb972c619857e62a5c Mon Sep 17 00:00:00 2001 From: alexwl Date: Mon, 8 Oct 2018 02:40:18 +0300 Subject: Update cabal-helper to version 0.8.1.2 that supports Cabal (>=1.14 && <1.26 || >=2.0 && <2.5) Building cabal-helper-0.8.1.2 with Stack failed with 'Dependency cycle detected' error. It seems to be https://github.com/commercialhaskell/stack/issues/4265 Stack bug. As a temporary solution I added source code of cabal-helper package to vendor directory and commented out 'build-tool-depends: cabal-helper:cabal-helper-wrapper' line in the cabal-helper.cabal file. --- .../src/CabalHelper/Shared/Common.hs | 150 +++++++++++++++++++++ .../src/CabalHelper/Shared/InterfaceTypes.hs | 81 +++++++++++ .../src/CabalHelper/Shared/Sandbox.hs | 78 +++++++++++ 3 files changed, 309 insertions(+) create mode 100644 vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/Common.hs create mode 100644 vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/InterfaceTypes.hs create mode 100644 vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/Sandbox.hs (limited to 'vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared') diff --git a/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/Common.hs b/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/Common.hs new file mode 100644 index 0000000..a7e7377 --- /dev/null +++ b/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/Common.hs @@ -0,0 +1,150 @@ +-- cabal-helper: Simple interface to Cabal's configuration state +-- Copyright (C) 2015-2018 Daniel Gröber +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +{-| +Module : CabalHelper.Shared.Common +Description : Shared utility functions +License : GPL-3 +-} + +{-# LANGUAGE CPP, DeriveDataTypeable, OverloadedStrings #-} +module CabalHelper.Shared.Common where + +#ifdef MIN_VERSION_Cabal +#undef CH_MIN_VERSION_Cabal +#define CH_MIN_VERSION_Cabal MIN_VERSION_Cabal +#endif + +import Control.Applicative +import Control.Exception as E +import Control.Monad +import Data.Char +import Data.List +import Data.Maybe +import Data.Version +import Data.Typeable +import Data.ByteString (ByteString) +import qualified Data.ByteString as BS +import qualified Data.ByteString.Char8 as BS8 +#if CH_MIN_VERSION_Cabal(2,2,0) +import qualified Distribution.PackageDescription.Parsec as P +#else +import qualified Distribution.PackageDescription.Parse as P +#endif +import System.Environment +import System.IO +import qualified System.Info +import System.Exit +import System.Directory +import System.FilePath +import Text.ParserCombinators.ReadP +import Prelude + +data Panic = Panic String deriving (Typeable, Show) +instance Exception Panic + +panic :: String -> a +panic msg = throw $ Panic msg + +panicIO :: String -> IO a +panicIO msg = throwIO $ Panic msg + +handlePanic :: IO a -> IO a +handlePanic action = + action `E.catch` \(Panic msg) -> errMsg msg >> exitFailure + +errMsg :: String -> IO () +errMsg str = do + prog <- getProgName + hPutStrLn stderr $ prog ++ ": " ++ str + +-- | @getCabalConfigHeader "dist/setup-config"@ returns the cabal version and +-- compiler version +getCabalConfigHeader :: FilePath -> IO (Maybe (Version, (ByteString, Version))) +getCabalConfigHeader file = bracket (openFile file ReadMode) hClose $ \h -> do + parseHeader <$> BS.hGetLine h + +parseHeader :: ByteString -> Maybe (Version, (ByteString, Version)) +parseHeader header = case BS8.words header of + ["Saved", "package", "config", "for", _pkgId , + "written", "by", cabalId, + "using", compId] + -> liftM2 (,) (snd <$> parsePkgId cabalId) (parsePkgId compId) + _ -> Nothing + +parsePkgId :: ByteString -> Maybe (ByteString, Version) +parsePkgId bs = + case BS8.split '-' bs of + [pkg, vers] -> Just (pkg, parseVer $ BS8.unpack vers) + _ -> Nothing + +parseVer :: String -> Version +parseVer vers = runReadP parseVersion vers + +trim :: String -> String +trim = dropWhileEnd isSpace + +majorVer :: Version -> Version +majorVer (Version b _) = Version (take 2 b) [] + +sameMajorVersionAs :: Version -> Version -> Bool +sameMajorVersionAs a b = majorVer a == majorVer b + +runReadP :: ReadP t -> String -> t +runReadP p i = case filter ((=="") . snd) $ readP_to_S p i of + (a,""):[] -> a + _ -> error $ "Error parsing: " ++ show i + +appCacheDir :: IO FilePath +appCacheDir = + ( "cabal-helper") <$> getEnvDefault "XDG_CACHE_HOME" (homeRel cache) + where + -- for GHC 7.4 + lookupEnv' var = do env <- getEnvironment; return (lookup var env) + getEnvDefault var def = lookupEnv' var >>= \m -> case m of Nothing -> def; Just x -> return x + homeRel path = ( path) <$> getHomeDirectory + cache = + case System.Info.os of + "mingw32" -> windowsCache + _ -> unixCache + + windowsCache = "Local Settings" "Cache" + unixCache = ".cache" + +isCabalFile :: FilePath -> Bool +isCabalFile f = takeExtension' f == ".cabal" + +takeExtension' :: FilePath -> String +takeExtension' p = + if takeFileName p == takeExtension p + then "" -- just ".cabal" is not a valid cabal file + else takeExtension p + +replace :: String -> String -> String -> String +replace n r hs' = go "" hs' + where + go acc h + | take (length n) h == n = + reverse acc ++ r ++ drop (length n) h + go acc (h:hs) = go (h:acc) hs + go acc [] = reverse acc + + +#if CH_MIN_VERSION_Cabal(2,2,0) +readPackageDescription = P.readGenericPackageDescription +#else +readPackageDescription = P.readPackageDescription +#endif diff --git a/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/InterfaceTypes.hs b/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/InterfaceTypes.hs new file mode 100644 index 0000000..a108c72 --- /dev/null +++ b/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/InterfaceTypes.hs @@ -0,0 +1,81 @@ +-- cabal-helper: Simple interface to Cabal's configuration state +-- Copyright (C) 2015-2018 Daniel Gröber +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +{-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DefaultSignatures #-} + +{-| +Module : CabalHelper.Shared.InterfaceTypes +Description : Types which are used by c-h library and executable to communicate +License : GPL-3 + +These types are used to communicate between the cabal-helper library and main +executable, using Show/Read. If any types in this module change the major +version must be bumped since this will be exposed in the @Distribution.Helper@ +module. + +The cached executables in @$XDG_CACHE_HOME/cabal-helper@ use the cabal-helper +version (among other things) as a cache key so we don't need to worry about +talking to an old executable. +-} +module CabalHelper.Shared.InterfaceTypes where + +import GHC.Generics +import Data.Version + +data ChResponse + = ChResponseCompList [(ChComponentName, [String])] + | ChResponseEntrypoints [(ChComponentName, ChEntrypoint)] + | ChResponseNeedsBuild [(ChComponentName, NeedsBuildOutput)] + | ChResponseList [String] + | ChResponsePkgDbs [ChPkgDb] + | ChResponseLbi String + | ChResponseVersion String Version + | ChResponseLicenses [(String, [(String, Version)])] + | ChResponseFlags [(String, Bool)] + deriving (Eq, Ord, Read, Show, Generic) + +data ChComponentName = ChSetupHsName + | ChLibName + | ChSubLibName String + | ChFLibName String + | ChExeName String + | ChTestName String + | ChBenchName String + deriving (Eq, Ord, Read, Show, Generic) + +newtype ChModuleName = ChModuleName String + deriving (Eq, Ord, Read, Show, Generic) + +data ChEntrypoint = ChSetupEntrypoint -- ^ Almost like 'ChExeEntrypoint' but + -- @main-is@ could either be @"Setup.hs"@ + -- or @"Setup.lhs"@. Since we don't know + -- where the source directory is you have + -- to find these files. + | ChLibEntrypoint { chExposedModules :: [ChModuleName] + , chOtherModules :: [ChModuleName] + , chSignatures :: [ChModuleName] -- backpack only + } + | ChExeEntrypoint { chMainIs :: FilePath + , chOtherModules :: [ChModuleName] + } deriving (Eq, Ord, Read, Show, Generic) + +data ChPkgDb = ChPkgGlobal + | ChPkgUser + | ChPkgSpecific FilePath + deriving (Eq, Ord, Read, Show, Generic) + +data NeedsBuildOutput = ProduceBuildOutput | NoBuildOutput + deriving (Eq, Ord, Read, Show, Generic) diff --git a/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/Sandbox.hs b/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/Sandbox.hs new file mode 100644 index 0000000..2f3774f --- /dev/null +++ b/vendor/cabal-helper-0.8.1.2/src/CabalHelper/Shared/Sandbox.hs @@ -0,0 +1,78 @@ +-- cabal-helper: Simple interface to Cabal's configuration state +-- Copyright (C) 2015-2017 Daniel Gröber +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +{-| +Module : CabalHelper.Shared.Sandbox +Description : Extracting information from @cabal.sandbox.config@ files +License : GPL-3 +-} + +module CabalHelper.Shared.Sandbox where + +import Control.Applicative +import Data.Char +import Data.Maybe +import Data.List +import Data.Version +import System.FilePath +import System.Directory +import Prelude + +import qualified Data.Traversable as T + +-- | Get the path to the sandbox package-db in a project +getSandboxPkgDb :: FilePath + -- ^ Path to the cabal package root directory (containing the + -- @cabal.sandbox.config@ file) + -> String + -- ^ Cabal build platform, i.e. @buildPlatform@ + -> Version + -- ^ GHC version (@cProjectVersion@ is your friend) + -> IO (Maybe FilePath) +getSandboxPkgDb d platform ghcVer = do + mConf <- T.traverse readFile =<< mightExist (d "cabal.sandbox.config") + return $ fixPkgDbVer <$> (extractSandboxDbDir =<< mConf) + + where + fixPkgDbVer dir = + case takeFileName dir == ghcSandboxPkgDbDir platform ghcVer of + True -> dir + False -> takeDirectory dir ghcSandboxPkgDbDir platform ghcVer + +ghcSandboxPkgDbDir :: String -> Version -> String +ghcSandboxPkgDbDir platform ghcVer = + platform ++ "-ghc-" ++ showVersion ghcVer ++ "-packages.conf.d" + +-- | Extract the sandbox package db directory from the cabal.sandbox.config +-- file. Exception is thrown if the sandbox config file is broken. +extractSandboxDbDir :: String -> Maybe FilePath +extractSandboxDbDir conf = extractValue <$> parse conf + where + key = "package-db:" + keyLen = length key + + parse = listToMaybe . filter (key `isPrefixOf`) . lines + extractValue = CabalHelper.Shared.Sandbox.dropWhileEnd isSpace . dropWhile isSpace . drop keyLen + + +mightExist :: FilePath -> IO (Maybe FilePath) +mightExist f = do + exists <- doesFileExist f + return $ if exists then (Just f) else (Nothing) + +-- dropWhileEnd is not provided prior to base 4.5.0.0. +dropWhileEnd :: (a -> Bool) -> [a] -> [a] +dropWhileEnd p = foldr (\x xs -> if p x && null xs then [] else x : xs) [] -- cgit v1.2.3