1
1
mirror of https://github.com/sol/hpack.git synced 2024-10-04 03:38:00 +03:00

Add ghcjs-options and js-sources

This commit is contained in:
Robert J. Macomber 2017-03-14 20:37:28 -07:00
parent 352a959bc0
commit f13b24ad4d
5 changed files with 116 additions and 3 deletions

View File

@ -74,9 +74,11 @@ These fields are merged with all library, executable, test, and benchmark compon
| `other-extensions` | · | | |
| `ghc-options` | · | | |
| `ghc-prof-options` | · | | |
| `ghcjs-options` | · | | |
| `cpp-options` | · | | |
| `cc-options` | · | | |
| `c-sources` | · | | Accepts [glob patterns](#file-globbing) |
| `js-sources` | · | | Accepts [glob patterns](#file-globbing) |
| `extra-lib-dirs` | · | | |
| `extra-libraries` | · | | |
| `include-dirs` | · | | |

View File

@ -119,7 +119,7 @@ packageDependencies Package{..} = nub . sortBy (comparing (lexicographically . d
++ maybe [] sectionDependencies packageLibrary
section :: a -> Section a
section a = Section a [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] []
section a = Section a [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] []
packageConfig :: FilePath
packageConfig = "package.yaml"
@ -230,9 +230,11 @@ data CommonOptions = CommonOptions {
, commonOptionsOtherExtensions :: Maybe (List String)
, commonOptionsGhcOptions :: Maybe (List GhcOption)
, commonOptionsGhcProfOptions :: Maybe (List GhcProfOption)
, commonOptionsGhcjsOptions :: Maybe (List GhcjsOption)
, commonOptionsCppOptions :: Maybe (List CppOption)
, commonOptionsCcOptions :: Maybe (List CcOption)
, commonOptionsCSources :: Maybe (List FilePath)
, commonOptionsJsSources :: Maybe (List FilePath)
, commonOptionsExtraLibDirs :: Maybe (List FilePath)
, commonOptionsExtraLibraries :: Maybe (List FilePath)
, commonOptionsIncludeDirs :: Maybe (List FilePath)
@ -463,9 +465,11 @@ data Section a = Section {
, sectionOtherExtensions :: [String]
, sectionGhcOptions :: [GhcOption]
, sectionGhcProfOptions :: [GhcProfOption]
, sectionGhcjsOptions :: [GhcjsOption]
, sectionCppOptions :: [CppOption]
, sectionCcOptions :: [CcOption]
, sectionCSources :: [FilePath]
, sectionJsSources :: [FilePath]
, sectionExtraLibDirs :: [FilePath]
, sectionExtraLibraries :: [FilePath]
, sectionIncludeDirs :: [FilePath]
@ -676,12 +680,23 @@ expandCSources dir sect@Section{..} = do
(warnings, files) <- expandGlobs "c-sources" dir sectionCSources
return (warnings, sect {sectionCSources = files})
expandJsSources :: FilePath -> Section a -> IO ([String], Section a)
expandJsSources dir sect@Section{..} = do
(warnings, files) <- expandGlobs "js-sources" dir sectionJsSources
return (warnings, sect {sectionJsSources = files})
expandForeignSources :: FilePath -> Section a -> IO ([String], Section a)
expandForeignSources dir sect = do
(cWarnings, sect') <- expandCSources dir sect
(jsWarnings, sect'') <- expandJsSources dir sect'
return (cWarnings ++ jsWarnings, sect'')
toCustomSetup :: CustomSetupSection -> CustomSetup
toCustomSetup CustomSetupSection{..} = CustomSetup
{ customSetupDependencies = fromMaybeList customSetupSectionDependencies }
toLibrary :: FilePath -> String -> Section global -> Section LibrarySection -> IO ([String], Section Library)
toLibrary dir name globalOptions library = traverse fromLibrarySection sect >>= expandCSources dir
toLibrary dir name globalOptions library = traverse fromLibrarySection sect >>= expandForeignSources dir
where
sect :: Section LibrarySection
sect = mergeSections globalOptions library
@ -698,7 +713,7 @@ toLibrary dir name globalOptions library = traverse fromLibrarySection sect >>=
toExecutables :: FilePath -> Section global -> [(String, Section ExecutableSection)] -> IO ([String], [Section Executable])
toExecutables dir globalOptions executables = do
result <- mapM toExecutable sections >>= mapM (expandCSources dir)
result <- mapM toExecutable sections >>= mapM (expandForeignSources dir)
let (warnings, xs) = unzip result
return (concat warnings, xs)
where
@ -729,9 +744,11 @@ mergeSections globalOptions options
, sectionOtherExtensions = sectionOtherExtensions globalOptions ++ sectionOtherExtensions options
, sectionGhcOptions = sectionGhcOptions globalOptions ++ sectionGhcOptions options
, sectionGhcProfOptions = sectionGhcProfOptions globalOptions ++ sectionGhcProfOptions options
, sectionGhcjsOptions = sectionGhcjsOptions globalOptions ++ sectionGhcjsOptions options
, sectionCppOptions = sectionCppOptions globalOptions ++ sectionCppOptions options
, sectionCcOptions = sectionCcOptions globalOptions ++ sectionCcOptions options
, sectionCSources = sectionCSources globalOptions ++ sectionCSources options
, sectionJsSources = sectionJsSources globalOptions ++ sectionJsSources options
, sectionExtraLibDirs = sectionExtraLibDirs globalOptions ++ sectionExtraLibDirs options
, sectionExtraLibraries = sectionExtraLibraries globalOptions ++ sectionExtraLibraries options
, sectionIncludeDirs = sectionIncludeDirs globalOptions ++ sectionIncludeDirs options
@ -753,9 +770,11 @@ toSection a CommonOptions{..}
, sectionOtherExtensions = fromMaybeList commonOptionsOtherExtensions
, sectionGhcOptions = fromMaybeList commonOptionsGhcOptions
, sectionGhcProfOptions = fromMaybeList commonOptionsGhcProfOptions
, sectionGhcjsOptions = fromMaybeList commonOptionsGhcjsOptions
, sectionCppOptions = fromMaybeList commonOptionsCppOptions
, sectionCcOptions = fromMaybeList commonOptionsCcOptions
, sectionCSources = fromMaybeList commonOptionsCSources
, sectionJsSources = fromMaybeList commonOptionsJsSources
, sectionExtraLibDirs = fromMaybeList commonOptionsExtraLibDirs
, sectionExtraLibraries = fromMaybeList commonOptionsExtraLibraries
, sectionIncludeDirs = fromMaybeList commonOptionsIncludeDirs

View File

@ -222,11 +222,13 @@ renderSection Section{..} = [
, renderOtherExtensions sectionOtherExtensions
, renderGhcOptions sectionGhcOptions
, renderGhcProfOptions sectionGhcProfOptions
, renderGhcjsOptions sectionGhcjsOptions
, renderCppOptions sectionCppOptions
, renderCcOptions sectionCcOptions
, renderDirectories "include-dirs" sectionIncludeDirs
, Field "install-includes" (LineSeparatedList sectionInstallIncludes)
, Field "c-sources" (LineSeparatedList sectionCSources)
, Field "js-sources" (LineSeparatedList sectionJsSources)
, renderDirectories "extra-lib-dirs" sectionExtraLibDirs
, Field "extra-libraries" (LineSeparatedList sectionExtraLibraries)
, renderLdOptions sectionLdOptions
@ -272,6 +274,9 @@ renderGhcOptions = Field "ghc-options" . WordList
renderGhcProfOptions :: [GhcProfOption] -> Element
renderGhcProfOptions = Field "ghc-prof-options" . WordList
renderGhcjsOptions :: [GhcjsOption] -> Element
renderGhcjsOptions = Field "ghcjs-options" . WordList
renderCppOptions :: [CppOption] -> Element
renderCppOptions = Field "cpp-options" . WordList

View File

@ -3,6 +3,7 @@ module Hpack.Util (
List(..)
, GhcOption
, GhcProfOption
, GhcjsOption
, CppOption
, CcOption
, LdOption
@ -54,6 +55,7 @@ instance FromJSON a => FromJSON (List a) where
type GhcOption = String
type GhcProfOption = String
type GhcjsOption = String
type CppOption = String
type CcOption = String
type LdOption = String

View File

@ -116,6 +116,15 @@ spec = do
captureUnknownFieldsValue <$> decodeEither input
`shouldBe` Right (section Empty){sectionCSources = ["foo.c", "bar/*.c"]}
it "accepts js-sources" $ do
let input = [i|
js-sources:
- foo.js
- bar/*.js
|]
captureUnknownFieldsValue <$> decodeEither input
`shouldBe` Right (section Empty){sectionJsSources = ["foo.js", "bar/*.js"]}
it "accepts extra-lib-dirs" $ do
let input = [i|
extra-lib-dirs:
@ -627,6 +636,30 @@ spec = do
}
)
it "accepts ghcjs-options" $ do
withPackageConfig_ [i|
ghcjs-options: -dedupe
library:
ghcjs-options: -ghcjs1
executables:
foo:
main: Main.hs
ghcjs-options: -ghcjs2
tests:
spec:
main: Spec.hs
ghcjs-options: -ghcjs3
|]
(`shouldBe` package {
packageLibrary = Just (section library) {sectionGhcjsOptions = ["-dedupe", "-ghcjs1"]}
, packageExecutables = [(section $ executable "foo" "Main.hs") {sectionGhcjsOptions = ["-dedupe", "-ghcjs2"]}]
, packageTests = [(section $ executable "spec" "Spec.hs") {sectionGhcjsOptions = ["-dedupe", "-ghcjs3"]}]
}
)
it "accepts ld-options" $ do
withPackageConfig_ [i|
library:
@ -795,6 +828,30 @@ spec = do
)
(packageLibrary >>> (`shouldBe` Just (section library) {sectionCSources = ["cbits/bar.c", "cbits/foo.c"]}))
it "accepts js-sources" $ do
withPackageConfig [i|
library:
js-sources:
- jsbits/*.js
|]
(do
touch "jsbits/foo.js"
touch "jsbits/bar.js"
)
(packageLibrary >>> (`shouldBe` Just (section library) {sectionJsSources = ["jsbits/bar.js", "jsbits/foo.js"]}))
it "accepts global js-sources" $ do
withPackageConfig [i|
js-sources:
- jsbits/*.js
library: {}
|]
(do
touch "jsbits/foo.js"
touch "jsbits/bar.js"
)
(packageLibrary >>> (`shouldBe` Just (section library) {sectionJsSources = ["jsbits/bar.js", "jsbits/foo.js"]}))
it "allows to specify exposed" $ do
withPackageConfig_ [i|
library:
@ -1049,6 +1106,34 @@ spec = do
)
(`shouldBe` package {packageExecutables = [(section $ executable "foo" "driver/Main.hs") {sectionCSources = ["cbits/bar.c", "cbits/foo.c"]}]})
it "accepts js-sources" $ do
withPackageConfig [i|
executables:
foo:
main: driver/Main.hs
js-sources:
- jsbits/*.js
|]
(do
touch "jsbits/foo.js"
touch "jsbits/bar.js"
)
(`shouldBe` package {packageExecutables = [(section $ executable "foo" "driver/Main.hs") {sectionJsSources = ["jsbits/bar.js", "jsbits/foo.js"]}]})
it "accepts global js-sources" $ do
withPackageConfig [i|
js-sources:
- jsbits/*.js
executables:
foo:
main: driver/Main.hs
|]
(do
touch "jsbits/foo.js"
touch "jsbits/bar.js"
)
(`shouldBe` package {packageExecutables = [(section $ executable "foo" "driver/Main.hs") {sectionJsSources = ["jsbits/bar.js", "jsbits/foo.js"]}]})
context "when reading test section" $ do
it "warns on unknown fields" $ do
withPackageWarnings_ [i|