simple-cabal (empty) → 0.0.0
raw patch · 6 files changed
+274/−0 lines, 6 filesdep +Cabaldep +basedep +directorysetup-changed
Dependencies added: Cabal, base, directory, filepath
Files
- CHANGELOG.md +6/−0
- LICENSE +29/−0
- README.md +19/−0
- Setup.hs +2/−0
- simple-cabal.cabal +36/−0
- src/SimpleCabal.hs +182/−0
+ CHANGELOG.md view
@@ -0,0 +1,6 @@+# Changelog++`simple-cabal` uses [PVP Versioning](https://pvp.haskell.org)++## 0.0.0+* Initially version, mostly taken from cabal-rpm PackageUtils.hs
+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2019, Jens Petersen+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright notice,+ this list of conditions and the following disclaimer in the documentation+ and/or other materials provided with the distribution.++3. Neither the name of the copyright holder nor the names of its+ contributors may be used to endorse or promote products derived from+ this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,19 @@+# simple-cabal++[](https://hackage.haskell.org/package/simple-cabal)+[](LICENSE)+[](http://stackage.org/lts/package/simple-cabal)+[](http://stackage.org/nightly/package/simple-cabal)+[](https://travis-ci.org/juhp/simple-cabal)++A small compatibility wrapper over Cabal (builds for ghc 7 and 8).++```+pkgid <- getPackageId+putStrLn $ showPkgId pkgid+```++```+cabalfile <- findCabalFile+genPkgDesc <- readGenericPackageDescription normal cabalfile+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ simple-cabal.cabal view
@@ -0,0 +1,36 @@+cabal-version: 2.0+name: simple-cabal+version: 0.0.0+synopsis: Cabal file wrapper library+description: Cabal compatibility layer for reading and+ parsing .cabal files+homepage: https://github.com/juhp/simple-cabal+bug-reports: https://github.com/juhp/simple-cabal/issues+license: BSD3+license-file: LICENSE+author: Jens Petersen+maintainer: juhpetersen@gmail.com+copyright: 2019 Jens Petersen+category: Distribution+build-type: Simple+extra-doc-files: README.md+ , CHANGELOG.md+tested-with: GHC == 8.6.5++source-repository head+ type: git+ location: https://github.com/juhp/simple-cabal.git++library+ hs-source-dirs: src+ exposed-modules: SimpleCabal+ ++ build-depends: base < 5,+ Cabal,+ directory,+ filepath++ ghc-options: -Wall++ default-language: Haskell2010
+ src/SimpleCabal.hs view
@@ -0,0 +1,182 @@+{-# LANGUAGE CPP #-}++module SimpleCabal+ ( findCabalFile+ , finalPackageDescription+ , getPackageId+ , normal+ , PackageDescription (..)+ , PackageIdentifier (..)+ , packageName, packageVersion+ , readGenericPackageDescription+ , showPkgId+ ) where++#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,0))+#else+import Control.Applicative ((<$>))+#endif++import Distribution.Compiler+import Distribution.Package (PackageIdentifier (..),+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,22,0)+ unPackageName+#else+ PackageName (..)+#endif+ )+import Distribution.PackageDescription + (PackageDescription (..),+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+ FlagName, +#else+ FlagName (..),+#endif+ GenericPackageDescription(packageDescription),+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,2,0)+ mkFlagAssignment+#endif+ )+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+import Distribution.PackageDescription.Configuration (finalizePD)+import Distribution.Types.ComponentRequestedSpec (defaultComponentRequestedSpec)+#else+import Distribution.PackageDescription.Configuration (finalizePackageDescription)+#endif+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,2,0)+import Distribution.PackageDescription.Parsec (readGenericPackageDescription)+#elif defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+import Distribution.PackageDescription.Parse (readGenericPackageDescription)+#else+import Distribution.PackageDescription.Parse (readPackageDescription)+#endif++import Distribution.Simple.Compiler (+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,22,0)+ compilerInfo+#else+ Compiler (..)+#endif+ )+import Distribution.Simple.Configure (+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,18,0)+ configCompilerEx+#else+ configCompiler+#endif+ )+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+import Distribution.Simple.Program (defaultProgramDb)+#else+import Distribution.Simple.Program (defaultProgramConfiguration)+#endif+import Distribution.System (Platform (..), buildArch, buildOS)+import Distribution.Verbosity (normal)++#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,2,0)+import Distribution.Pretty (prettyShow)+#else+import qualified Distribution.Version (showVersion, Version)+#endif+#else+import qualified Data.Version (+ showVersion,+#if (defined(MIN_VERSION_base) && MIN_VERSION_base(4,8,0))+ Version,+#else+ Version(..)+#endif+ )+#endif++import System.Directory (getDirectoryContents)+import System.FilePath (takeExtension)++type Flags = [(FlagName, Bool)]++findCabalFile :: IO FilePath+findCabalFile = do+ allCabals <- filesWithExtension "." ".cabal"+ case allCabals of+ [file] -> return file+ [] -> error "No .cabal file found"+ _ -> error "More than one .cabal file found!"+ where+ filesWithExtension :: FilePath -> String -> IO [FilePath]+ filesWithExtension dir ext =+ filter (\ f -> takeExtension f == ext) <$> getDirectoryContents dir++getPackageId :: IO PackageIdentifier+getPackageId = do+ gpd <- findCabalFile >>= readGenericPackageDescription normal+ return $ package $ packageDescription gpd++#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+#else+readGenericPackageDescription = readPackageDescription+#endif++finalPackageDescription :: Flags -> FilePath+ -> IO PackageDescription+finalPackageDescription flags cabalfile = do+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+#else+ let defaultProgramDb = defaultProgramConfiguration+#endif+ genPkgDesc <- readGenericPackageDescription normal cabalfile+ compiler <- do+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,18,0)+ (compiler, _, _) <- configCompilerEx+#else+ (compiler, _) <- configCompiler+#endif+ (Just GHC) Nothing Nothing defaultProgramDb normal+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,22,0)+ return (compilerInfo compiler)+#else+ return (compilerId compiler)+#endif+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,2,0)+#else+ let mkFlagAssignment = id+#endif+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+ let finalizePackageDescription flags' = finalizePD flags' defaultComponentRequestedSpec+#endif+ let final =+ finalizePackageDescription (mkFlagAssignment flags)+ (const True) (Platform buildArch buildOS)+ compiler+ [] genPkgDesc+ case final of+ Left e -> error $ "finalize failed: " ++ show e+ Right res -> return $ fst res++#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(1,22,0)+#else+unPackageName :: PackageName -> String+unPackageName (PackageName n) = n+#endif++packageName :: PackageIdentifier -> String+packageName = unPackageName . pkgName++packageVersion :: PackageIdentifier -> String+packageVersion = prettyShow . pkgVersion++#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,2,0)+#else+#if defined(MIN_VERSION_Cabal) && MIN_VERSION_Cabal(2,0,0)+prettyShow :: Distribution.Version.Version -> String+prettyShow = Distribution.Version.showVersion+#else+prettyShow :: Data.Version.Version -> String+prettyShow = Data.Version.showVersion+#endif+#endif++showPkgId :: PackageIdentifier -> String+showPkgId pkgid =+ packageName pkgid ++ "-" ++ packageVersion pkgid+