packages feed

hpack 0.3.1 → 0.3.2

raw patch · 4 files changed

+59/−19 lines, 4 files

Files

hpack.cabal view
@@ -3,10 +3,10 @@ -- see: https://github.com/sol/hpack  name:           hpack-version:        0.3.1+version:        0.3.2 synopsis:       An alternative format for Haskell packages-homepage:       https://github.com/sol/hpack#readme-bug-reports:    https://github.com/sol/hpack/issues+homepage:       https://github.com/haskell-tinc/hpack#readme+bug-reports:    https://github.com/haskell-tinc/hpack/issues maintainer:     Simon Hengel <sol@typeful.net> license:        MIT license-file:   LICENSE@@ -15,7 +15,7 @@  source-repository head   type: git-  location: https://github.com/sol/hpack+  location: https://github.com/haskell-tinc/hpack  executable hpack   hs-source-dirs: src, driver
src/Config.hs view
@@ -64,6 +64,7 @@ , librarySectionDependencies :: Maybe (List Dependency) , librarySectionDefaultExtensions :: Maybe (List String) , librarySectionGhcOptions :: Maybe (List GhcOption)+, librarySectionCppOptions :: Maybe (List CppOption) } deriving (Eq, Show, Generic, Data, Typeable)  instance FromJSON LibrarySection where@@ -76,6 +77,7 @@ , executableSectionDependencies :: Maybe (List Dependency) , executableSectionDefaultExtensions :: Maybe (List String) , executableSectionGhcOptions :: Maybe (List GhcOption)+, executableSectionCppOptions :: Maybe (List CppOption) } deriving (Eq, Show, Generic, Data, Typeable)  instance FromJSON ExecutableSection where@@ -100,6 +102,7 @@ , packageConfigDependencies :: Maybe (List Dependency) , packageConfigDefaultExtensions :: Maybe (List String) , packageConfigGhcOptions :: Maybe (List GhcOption)+, packageConfigCppOptions :: Maybe (List CppOption) , packageConfigLibrary :: Maybe (CaptureUnknownFields LibrarySection) , packageConfigExecutables :: Maybe (HashMap String (CaptureUnknownFields ExecutableSection)) , packageConfigTests :: Maybe (HashMap String (CaptureUnknownFields ExecutableSection))@@ -139,6 +142,7 @@  type Dependency = String type GhcOption = String+type CppOption = String  data Package = Package {   packageName :: String@@ -168,6 +172,7 @@ , libraryDependencies :: [[Dependency]] , libraryDefaultExtensions :: [String] , libraryGhcOptions :: [GhcOption]+, libraryCppOptions :: [CppOption] } deriving (Eq, Show)  data Executable = Executable {@@ -178,6 +183,7 @@ , executableDependencies :: [[Dependency]] , executableDefaultExtensions :: [String] , executableGhcOptions :: [GhcOption]+, executableCppOptions :: [CppOption] } deriving (Eq, Show)  mkPackage :: (CaptureUnknownFields PackageConfig) -> IO ([String], Package)@@ -186,7 +192,8 @@       sourceDirs = fromMaybeList packageConfigSourceDirs       defaultExtensions = fromMaybeList packageConfigDefaultExtensions       ghcOptions = fromMaybeList packageConfigGhcOptions-      convert f = f sourceDirs dependencies defaultExtensions ghcOptions+      cppOptions = fromMaybeList packageConfigCppOptions+      convert f = f sourceDirs dependencies defaultExtensions ghcOptions cppOptions    mLibrary <- mapM (convert toLibrary) mLibrarySection   executables <- convert toExecutables mExecutableSections@@ -270,18 +277,19 @@       where         fromGithub = ((++ "/issues") <$> github) -toLibrary :: [FilePath] -> [Dependency] -> [String] -> [GhcOption] -> LibrarySection -> IO Library-toLibrary globalSourceDirs globalDependencies globalDefaultExtensions globalGhcOptions LibrarySection{..} = do+toLibrary :: [FilePath] -> [Dependency] -> [String] -> [GhcOption] -> [CppOption] -> LibrarySection -> IO Library+toLibrary globalSourceDirs globalDependencies globalDefaultExtensions globalGhcOptions globalCppOptions LibrarySection{..} = do   modules <- concat <$> mapM getModules sourceDirs    let (exposedModules, otherModules) = determineModules modules librarySectionExposedModules librarySectionOtherModules -  return (Library sourceDirs exposedModules otherModules dependencies defaultExtensions ghcOptions)+  return (Library sourceDirs exposedModules otherModules dependencies defaultExtensions ghcOptions cppOptions)   where     sourceDirs = globalSourceDirs ++ fromMaybeList librarySectionSourceDirs     dependencies = filter (not . null) [globalDependencies, fromMaybeList librarySectionDependencies]     defaultExtensions = globalDefaultExtensions ++ fromMaybeList librarySectionDefaultExtensions     ghcOptions = globalGhcOptions ++ fromMaybeList librarySectionGhcOptions+    cppOptions = globalCppOptions ++ fromMaybeList librarySectionCppOptions  determineModules :: [String] -> Maybe (List String) -> Maybe (List String) -> ([String], [String]) determineModules modules mExposedModules mOtherModules = case (mExposedModules, mOtherModules) of@@ -301,17 +309,19 @@     toModules :: [[FilePath]] -> [String]     toModules = catMaybes . map toModule -toExecutables :: [FilePath] -> [Dependency] -> [String] -> [GhcOption] -> Maybe (HashMap String ExecutableSection) -> IO [Executable]-toExecutables globalSourceDirs globalDependencies globalDefaultExtensions globalGhcOptions executables = (mapM toExecutable . Map.toList) (fromMaybe mempty executables)+toExecutables :: [FilePath] -> [Dependency] -> [String] -> [GhcOption] -> [CppOption] -> Maybe (HashMap String ExecutableSection) -> IO [Executable]+toExecutables globalSourceDirs globalDependencies globalDefaultExtensions globalGhcOptions globalCppOptions executables =+  (mapM toExecutable . Map.toList) (fromMaybe mempty executables)   where     toExecutable (name, ExecutableSection{..}) = do       modules <- maybe (filterMain . concat <$> mapM getModules sourceDirs) (return . fromList) executableSectionOtherModules-      return $ Executable name executableSectionMain sourceDirs modules dependencies defaultExtensions ghcOptions+      return $ Executable name executableSectionMain sourceDirs modules dependencies defaultExtensions ghcOptions cppOptions       where         dependencies = filter (not . null) [globalDependencies, fromMaybeList executableSectionDependencies]         sourceDirs = globalSourceDirs ++ fromMaybeList executableSectionSourceDirs         defaultExtensions = globalDefaultExtensions ++ fromMaybeList executableSectionDefaultExtensions         ghcOptions = globalGhcOptions ++ fromMaybeList executableSectionGhcOptions+        cppOptions = globalCppOptions ++ fromMaybeList executableSectionCppOptions          filterMain :: [String] -> [String]         filterMain = maybe id (filter . (/=)) (toModule $ splitDirectories executableSectionMain)
src/Run.hs view
@@ -136,6 +136,7 @@   ++ renderDependencies executableDependencies    ++ renderDefaultExtensions executableDefaultExtensions   ++ renderGhcOptions executableGhcOptions+  ++ renderCppOptions executableCppOptions   ++ "  default-language: Haskell2010\n"  renderLibrary :: Library -> String@@ -147,6 +148,7 @@   ++ renderDependencies libraryDependencies   ++ renderDefaultExtensions libraryDefaultExtensions   ++ renderGhcOptions libraryGhcOptions+  ++ renderCppOptions libraryCppOptions   ++ "  default-language: Haskell2010\n"  @@ -175,11 +177,15 @@       | otherwise = "\n    , " ++ intercalate "\n    , " xs ++ "\n"  renderGhcOptions :: [GhcOption] -> String-renderGhcOptions ghcOptions-  | null ghcOptions = ""-  | otherwise = "  ghc-options: " ++ unwords ghcOptions ++ "\n"+renderGhcOptions = renderOptions "ghc-options" +renderCppOptions :: [GhcOption] -> String+renderCppOptions = renderOptions "cpp-options"+ renderDefaultExtensions :: [String] -> String-renderDefaultExtensions defaultExtensions-  | null defaultExtensions = ""-  | otherwise = "  default-extensions: " ++ unwords defaultExtensions ++ "\n"+renderDefaultExtensions = renderOptions "default-extensions"++renderOptions :: String -> [String] -> String+renderOptions field options+  | null options = ""+  | otherwise = "  " ++ field ++ ": " ++ unwords options ++ "\n"
test/ConfigSpec.hs view
@@ -21,10 +21,10 @@ package = Package "foo" "0.0.0" Nothing Nothing Nothing Nothing Nothing Nothing [] [] [] Nothing Nothing [] Nothing Nothing [] []  executable :: String -> String -> Executable-executable name main_ = Executable name main_ [] [] [] [] []+executable name main_ = Executable name main_ [] [] [] [] [] []  library :: Library-library = Library [] [] [] [] [] []+library = Library [] [] [] [] [] [] []  spec :: Spec spec = around_ (inTempDirectoryNamed "foo") $ do@@ -178,6 +178,30 @@         |]       Right (_, c) <- readPackageConfig "package.yml"       packageSourceRepository c `shouldBe` Just "https://github.com/hspec/hspec"++    it "accepts CPP options" $ do+      writeFile "package.yml" [i|+        cpp-options: -DFOO+        library:+          cpp-options: -DLIB++        executables:+          foo:+            main: Main.hs+            cpp-options: -DFOO+++        tests:+          spec:+            main: Spec.hs+            cpp-options: -DTEST+        |]+      Right (_, c) <- readPackageConfig "package.yml"+      c `shouldBe` package {+          packageLibrary = Just library {libraryCppOptions = ["-DFOO", "-DLIB"]}+        , packageExecutables = [(executable "foo" "Main.hs") {executableCppOptions = ["-DFOO", "-DFOO"]}]+        , packageTests = [(executable "spec" "Spec.hs") {executableCppOptions = ["-DFOO", "-DTEST"]}]+        }      context "when reading library section" $ do       it "warns on unknown fields" $ do