hpack 0.5.4 → 0.6.0
raw patch · 8 files changed
+89/−46 lines, 8 filesnew-uploaderPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Hpack.Config: getModules :: FilePath -> IO [String]
- Hpack.Run: formatDescription :: Int -> String -> String
- Hpack.Run: renderSourceRepository :: SourceRepository -> Element
+ Hpack.Config: instance Selector S1_0_18PackageConfig
+ Hpack.Config: package :: String -> String -> Package
+ Hpack.Config: packageTestedWith :: Package -> Maybe String
+ Hpack.Run: LeadingCommas :: CommaStyle
+ Hpack.Run: RenderSettings :: Int -> CommaStyle -> RenderSettings
+ Hpack.Run: TrailingCommas :: CommaStyle
+ Hpack.Run: data CommaStyle
+ Hpack.Run: data RenderSettings
+ Hpack.Run: defaultRenderSettings :: RenderSettings
+ Hpack.Run: renderSettingsCommaStyle :: RenderSettings -> CommaStyle
+ Hpack.Run: renderSettingsIndentation :: RenderSettings -> Int
+ Hpack.Yaml: decodeYaml :: FromJSON a => FilePath -> IO (Either String a)
- Hpack.Config: Package :: String -> String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> [String] -> [String] -> [String] -> Maybe String -> Maybe FilePath -> [FilePath] -> [FilePath] -> Maybe SourceRepository -> Maybe (Section Library) -> [Section Executable] -> [Section Executable] -> Package
+ Hpack.Config: Package :: String -> String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> Maybe String -> [String] -> [String] -> [String] -> Maybe String -> Maybe FilePath -> Maybe String -> [FilePath] -> [FilePath] -> Maybe SourceRepository -> Maybe (Section Library) -> [Section Executable] -> [Section Executable] -> Package
Files
- driver/Main.hs +32/−18
- hpack.cabal +6/−2
- src/Hpack/Config.hs +17/−16
- src/Hpack/Run.hs +10/−4
- src/Hpack/Util.hs +3/−2
- src/Hpack/Yaml.hs +16/−0
- test/Hpack/ConfigSpec.hs +4/−3
- test/Hpack/RunSpec.hs +1/−1
driver/Main.hs view
@@ -2,14 +2,16 @@ import Prelude () import Prelude.Compat-import Control.Monad.Compat++import Control.DeepSeq import Control.Exception-import System.IO-import System.IO.Error+import Control.Monad.Compat import Data.List.Compat import Data.Version (showVersion)-import Control.DeepSeq import System.Environment+import System.Exit+import System.IO+import System.IO.Error import Paths_hpack (version) import Hpack.Config@@ -29,17 +31,29 @@ main :: IO () main = do args <- getArgs- if "--version" `elem` args- then putStrLn programVersion- else do- (warnings, name, new) <- run- forM_ warnings $ \warning -> hPutStrLn stderr ("WARNING: " ++ warning)- old <- force . either (const Nothing) (Just . stripHeader) <$> tryJust (guard . isDoesNotExistError) (readFile name)- if (old == Just (lines new)) then do- putStrLn (name ++ " is up-to-date")- else do- (writeFile name $ header ++ new)- putStrLn ("generated " ++ name)- where- stripHeader :: String -> [String]- stripHeader = dropWhile null . dropWhile ("--" `isPrefixOf`) . lines+ case args of+ ["--version"] -> putStrLn programVersion+ ["--silent"] -> hpack False+ [] -> hpack True+ _ -> do+ hPutStrLn stderr "Usage: hpack [ --version | --silent ]"+ exitFailure++hpack :: Bool -> IO ()+hpack verbose = do+ (warnings, name, new) <- run+ forM_ warnings $ \warning -> hPutStrLn stderr ("WARNING: " ++ warning)+ old <- force . either (const Nothing) (Just . stripHeader) <$> tryJust (guard . isDoesNotExistError) (readFile name)+ if (old == Just (lines new)) then do+ output (name ++ " is up-to-date")+ else do+ (writeFile name $ header ++ new)+ output ("generated " ++ name)+ where+ stripHeader :: String -> [String]+ stripHeader = dropWhile null . dropWhile ("--" `isPrefixOf`) . lines++ output :: String -> IO ()+ output message+ | verbose = putStrLn message+ | otherwise = return ()
hpack.cabal view
@@ -1,10 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.5.3.+-- This file has been generated from package.yaml by hpack version 0.5.4. -- -- see: https://github.com/sol/hpack name: hpack-version: 0.5.4+version: 0.6.0 synopsis: An alternative format for Haskell packages+category: Development homepage: https://github.com/sol/hpack#readme bug-reports: https://github.com/sol/hpack/issues maintainer: Simon Hengel <sol@typeful.net>@@ -35,6 +36,7 @@ exposed-modules: Hpack.Config Hpack.Run+ Hpack.Yaml other-modules: Hpack.GenericsUtil Hpack.Haskell@@ -68,6 +70,7 @@ test , src ghc-options: -Wall+ cpp-options: -DTEST build-depends: aeson >= 0.8 , base >= 4.7 && < 5@@ -97,4 +100,5 @@ Hpack.Render Hpack.Run Hpack.Util+ Hpack.Yaml default-language: Haskell2010
src/Hpack/Config.hs view
@@ -7,9 +7,11 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE CPP #-} module Hpack.Config ( packageConfig , readPackageConfig+, package , Package(..) , Dependency(..) , GitRef(..)@@ -19,9 +21,9 @@ , Library(..) , Executable(..) , SourceRepository(..)---- exported for testing+#ifdef TEST , getModules+#endif ) where import Control.Applicative@@ -30,22 +32,25 @@ import Data.Data import Data.HashMap.Lazy (HashMap) import qualified Data.HashMap.Lazy as Map-import Data.Ord import Data.List (nub, (\\), sortBy) import Data.Maybe+import Data.Ord import Data.String import Data.Text (Text) import qualified Data.Text as T-import Data.Yaml import GHC.Generics import Prelude () import Prelude.Compat import System.Directory import System.FilePath -import Hpack.Util import Hpack.GenericsUtil+import Hpack.Util+import Hpack.Yaml +package :: String -> String -> Package+package name version = Package name version Nothing Nothing Nothing Nothing Nothing Nothing [] [] [] Nothing Nothing Nothing [] [] Nothing Nothing [] []+ packageConfig :: FilePath packageConfig = "package.yaml" @@ -129,6 +134,7 @@ , packageConfigMaintainer :: Maybe (List String) , packageConfigCopyright :: Maybe (List String) , packageConfigLicense :: Maybe String+, packageConfigTestedWith :: Maybe String , packageConfigExtraSourceFiles :: Maybe (List FilePath) , packageConfigDataFiles :: Maybe (List FilePath) , packageConfigGithub :: Maybe Text@@ -167,15 +173,8 @@ readPackageConfig :: FilePath -> IO (Either String ([String], Package)) readPackageConfig file = do- config <- decodeFileEither file- either (return . Left . errToString) (fmap Right . mkPackage) config- where- errToString err = file ++ case err of- AesonException e -> ": " ++ e- InvalidYaml (Just (YamlException s)) -> ": " ++ s- InvalidYaml (Just (YamlParseException{..})) -> ":" ++ show yamlLine ++ ":" ++ show yamlColumn ++ ": " ++ yamlProblem ++ " " ++ yamlContext- where YamlMark{..} = yamlProblemMark- _ -> ": " ++ show err+ config <- decodeYaml file+ either (return . Left) (fmap Right . mkPackage) config data Dependency = Dependency { dependencyName :: String@@ -229,6 +228,7 @@ , packageCopyright :: [String] , packageLicense :: Maybe String , packageLicenseFile :: Maybe FilePath+, packageTestedWith :: Maybe String , packageExtraSourceFiles :: [FilePath] , packageDataFiles :: [FilePath] , packageSourceRepository :: Maybe SourceRepository@@ -290,7 +290,7 @@ (dataFilesWarnings, dataFiles) <- expandGlobs (fromMaybeList packageConfigDataFiles) - let package = Package {+ let pkg = Package { packageName = name , packageVersion = fromMaybe "0.0.0" packageConfigVersion , packageSynopsis = packageConfigSynopsis@@ -304,6 +304,7 @@ , packageCopyright = fromMaybeList packageConfigCopyright , packageLicense = packageConfigLicense , packageLicenseFile = guard licenseFileExists >> Just "LICENSE"+ , packageTestedWith = packageConfigTestedWith , packageExtraSourceFiles = extraSourceFiles , packageDataFiles = dataFiles , packageSourceRepository = sourceRepository@@ -321,7 +322,7 @@ ++ extraSourceFilesWarnings ++ dataFilesWarnings - return (warnings, package)+ return (warnings, pkg) where executableSections :: [(String, CaptureUnknownFields (Section ExecutableSection))] executableSections = toList packageConfigExecutables
src/Hpack/Run.hs view
@@ -2,12 +2,17 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE CPP #-} module Hpack.Run ( run--- exported for testing , renderPackage+, RenderSettings(..)+, CommaStyle(..)+, defaultRenderSettings+#ifdef TEST , renderSourceRepository , formatDescription+#endif ) where import Prelude ()@@ -27,14 +32,14 @@ run = do mPackage <- readPackageConfig packageConfig case mPackage of- Right (warnings, package) -> do- let cabalFile = packageName package ++ ".cabal"+ Right (warnings, pkg) -> do+ let cabalFile = packageName pkg ++ ".cabal" old <- tryReadFile cabalFile let alignment = fromMaybe 16 (old >>= sniffAlignment) settings = maybe defaultRenderSettings sniffRenderSettings old- output = renderPackage settings alignment (maybe [] extractFieldOrderHint old) package+ output = renderPackage settings alignment (maybe [] extractFieldOrderHint old) pkg return (warnings, cabalFile, output) Left err -> die err @@ -98,6 +103,7 @@ , ("copyright", formatList packageCopyright) , ("license", packageLicense) , ("license-file", packageLicenseFile)+ , ("tested-with", packageTestedWith) , ("build-type", Just "Simple") , ("cabal-version", Just ">= 1.10") ]
src/Hpack/Util.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE CPP #-} module Hpack.Util ( List(..) , GhcOption@@ -11,9 +12,9 @@ , expandGlobs , sort , lexicographically---- exported for testing+#ifdef TEST , splitField+#endif ) where import Control.Applicative
+ src/Hpack/Yaml.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE RecordWildCards #-}+module Hpack.Yaml where++import Data.Yaml++decodeYaml :: FromJSON a => FilePath -> IO (Either String a)+decodeYaml file = do+ result <- decodeFileEither file+ return $ either (Left . errToString) Right result+ where+ errToString err = file ++ case err of+ AesonException e -> ": " ++ e+ InvalidYaml (Just (YamlException s)) -> ": " ++ s+ InvalidYaml (Just (YamlParseException{..})) -> ":" ++ show yamlLine ++ ":" ++ show yamlColumn ++ ": " ++ yamlProblem ++ " " ++ yamlContext+ where YamlMark{..} = yamlProblemMark+ _ -> ": " ++ show err
test/Hpack/ConfigSpec.hs view
@@ -12,14 +12,15 @@ import Helper -import Data.Aeson.Types import Data.Aeson.QQ+import Data.Aeson.Types import Data.String.Interpolate -import Hpack.Config+import Hpack.Config hiding (package)+import qualified Hpack.Config as Config package :: Package-package = Package "foo" "0.0.0" Nothing Nothing Nothing Nothing Nothing Nothing [] [] [] Nothing Nothing [] [] Nothing Nothing [] []+package = Config.package "foo" "0.0.0" executable :: String -> String -> Executable executable name main_ = Executable name main_ []
test/Hpack/RunSpec.hs view
@@ -5,7 +5,7 @@ import Data.List import Hpack.ConfigSpec hiding (spec)-import Hpack.Config+import Hpack.Config hiding (package) import Hpack.Render import Hpack.Run