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

Handle Paths_* module

This commit is contained in:
Simon Hengel 2016-02-05 21:54:09 +08:00
parent 23a6ce1d42
commit bed0794c0a
4 changed files with 22 additions and 12 deletions

View File

@ -38,12 +38,12 @@ library
Hpack.Config
Hpack.Run
Hpack.Yaml
Paths_hpack
other-modules:
Hpack.GenericsUtil
Hpack.Haskell
Hpack.Render
Hpack.Util
Paths_hpack
default-language: Haskell2010
executable hpack

View File

@ -28,7 +28,6 @@ library:
- Hpack.Config
- Hpack.Run
- Hpack.Yaml
- Paths_hpack
executables:
hpack:

View File

@ -26,6 +26,7 @@ module Hpack.Config (
, SourceRepository(..)
#ifdef TEST
, getModules
, determineModules
#endif
) where
@ -291,13 +292,13 @@ data SourceRepository = SourceRepository {
mkPackage :: (CaptureUnknownFields (Section PackageConfig)) -> IO ([String], Package)
mkPackage (CaptureUnknownFields unknownFields globalOptions@Section{sectionData = PackageConfig{..}}) = do
mLibrary <- mapM (toLibrary globalOptions) mLibrarySection
name <- maybe (takeBaseName <$> getCurrentDirectory) return packageConfigName
mLibrary <- mapM (toLibrary name globalOptions) mLibrarySection
executables <- toExecutables globalOptions (map (fmap captureUnknownFieldsValue) executableSections)
tests <- toExecutables globalOptions (map (fmap captureUnknownFieldsValue) testsSections)
benchmarks <- toExecutables globalOptions (map (fmap captureUnknownFieldsValue) benchmarkSections)
name <- maybe (takeBaseName <$> getCurrentDirectory) return packageConfigName
licenseFileExists <- doesFileExist "LICENSE"
missingSourceDirs <- nub . sort <$> filterM (fmap not <$> doesDirectoryExist) (
@ -401,8 +402,8 @@ mkPackage (CaptureUnknownFields unknownFields globalOptions@Section{sectionData
where
fromGithub = (++ "/issues") . sourceRepositoryUrl <$> sourceRepository
toLibrary :: Section global -> Section LibrarySection -> IO (Section Library)
toLibrary globalOptions library = traverse fromLibrarySection sect
toLibrary :: String -> Section global -> Section LibrarySection -> IO (Section Library)
toLibrary name globalOptions library = traverse fromLibrarySection sect
where
sect :: Section LibrarySection
sect = mergeSections globalOptions library
@ -413,7 +414,7 @@ toLibrary globalOptions library = traverse fromLibrarySection sect
fromLibrarySection :: LibrarySection -> IO Library
fromLibrarySection LibrarySection{..} = do
modules <- concat <$> mapM getModules sourceDirs
let (exposedModules, otherModules) = determineModules modules librarySectionExposedModules librarySectionOtherModules
let (exposedModules, otherModules) = determineModules name modules librarySectionExposedModules librarySectionOtherModules
return (Library exposedModules otherModules)
toExecutables :: Section global -> [(String, Section ExecutableSection)] -> IO [Section Executable]
@ -462,13 +463,14 @@ toSection a CommonOptions{..}
cppOptions = fromMaybeList commonOptionsCppOptions
dependencies = fromMaybeList commonOptionsDependencies
determineModules :: [String] -> Maybe (List String) -> Maybe (List String) -> ([String], [String])
determineModules modules mExposedModules mOtherModules = case (mExposedModules, mOtherModules) of
determineModules :: String -> [String] -> Maybe (List String) -> Maybe (List String) -> ([String], [String])
determineModules name modules mExposedModules mOtherModules = case (mExposedModules, mOtherModules) of
(Nothing, Nothing) -> (modules, [])
_ -> (exposedModules, otherModules)
where
otherModules = maybe (modules \\ exposedModules) fromList mOtherModules
otherModules = maybe ((modules \\ exposedModules) ++ pathsModule) fromList mOtherModules
exposedModules = maybe (modules \\ otherModules) fromList mExposedModules
pathsModule = ["Paths_" ++ name] \\ exposedModules
getModules :: FilePath -> IO [String]
getModules src_ = sort <$> do

View File

@ -15,6 +15,7 @@ import Data.Aeson.QQ
import Data.Aeson.Types
import Data.String.Interpolate
import Hpack.Util
import Hpack.Config hiding (package)
import qualified Hpack.Config as Config
@ -102,6 +103,14 @@ spec = do
touch "Setup.hs"
getModules "./." `shouldReturn` ["Foo"]
describe "determineModules" $ do
it "adds the Paths_* module to the other-modules" $ do
determineModules "foo" [] (Just $ List ["Foo"]) Nothing `shouldBe` (["Foo"], ["Paths_foo"])
context "when the Paths_* module is part of the exposed-modules" $ do
it "it does not add the Paths_* module to the other-modules" $ do
determineModules "foo" [] (Just $ List ["Foo", "Paths_foo"]) Nothing `shouldBe` (["Foo", "Paths_foo"], [])
describe "readPackageConfig" $ around_ (inTempDirectoryNamed "foo") $ do
it "warns on unknown fields" $ do
writeFile "package.yaml" [i|
@ -360,7 +369,7 @@ spec = do
touch "src/Foo.hs"
touch "src/Bar.hs"
Right (_, c) <- readPackageConfig "package.yaml"
packageLibrary c `shouldBe` Just (section library{libraryExposedModules = ["Foo"], libraryOtherModules = ["Bar"]}) {sectionSourceDirs = ["src"]}
packageLibrary c `shouldBe` Just (section library{libraryExposedModules = ["Foo"], libraryOtherModules = ["Bar", "Paths_foo"]}) {sectionSourceDirs = ["src"]}
it "allows to specify other-modules" $ do
writeFile "package.yaml" [i|