git.iko.soy/typeable/cabal2nix
on master help sign in
Merge pull request #403 from qrilka/3-way-hpack

Add option for disabling hpack completely

commitfa34dbb7e311dffc4de887b80371384591a43dba authorPeter Simons <simons@cryp.to> dateWed 30 Jan 2019, 08:52 (8 years ago) parent45bf2470ccca6d
2 files changed+35−19
src/Cabal2nix.hs+9−2 src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+26−17
src/Cabal2nix.hs+9−2
@@ -46,7 +46,7 @@ data Options = Options
4646 , optMaintainer :: [String]
4747--, optPlatform :: [String] -- TODO: fix command line handling of platforms
4848 , optHaddock :: Bool
49− , optHpack :: Bool
49+ , optHpack :: HpackUse
5050 , optDoCheck :: Bool
5151 , optJailbreak :: Bool
5252 , optDoBenchmark :: Bool
@@ -74,7 +74,14 @@ options = Options
7474 <*> many (strOption $ long "maintainer" <> metavar "MAINTAINER" <> help "maintainer of this package (may be specified multiple times)")
7575-- <*> many (strOption $ long "platform" <> metavar "PLATFORM" <> help "supported build platforms (may be specified multiple times)")
7676 <*> flag True False (long "no-haddock" <> help "don't run Haddock when building this package")
77− <*> switch (long "hpack" <> help "run hpack before configuring this package (only non-hackage packages)")
77+ <*>
78+ (
79+ flag' ForceHpack (long "hpack" <> help "run hpack before configuring this package (only non-hackage packages)")
80+ <|>
81+ flag' NoHpack (long "no-hpack" <> help "disable hpack run and use only cabal disregarding package.yaml existence")
82+ <|>
83+ pure PackageYamlHpack
84+ )
7885 <*> flag True False (long "no-check" <> help "don't run regression test suites of this package")
7986 <*> switch (long "jailbreak" <> help "disregard version restrictions on build inputs")
8087 <*> switch (long "benchmark" <> help "enable benchmarks for this package")
src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+26−17
@@ -1,5 +1,5 @@
11module Distribution.Nixpkgs.Haskell.PackageSourceSpec
2− ( Package(..), getPackage, getPackage', loadHackageDB, sourceFromHackage
2+ ( HpackUse(..), Package(..), getPackage, getPackage', loadHackageDB, sourceFromHackage
33 ) where
44
55import qualified Control.Exception as Exception
@@ -32,6 +32,11 @@ import System.IO
3232import qualified Data.Text as T
3333import qualified Data.Text.Encoding as T
3434
35+data HpackUse
36+ = ForceHpack
37+ | PackageYamlHpack
38+ | NoHpack
39+
3540data Package = Package
3641 { pkgSource :: DerivationSource
3742 , pkgRanHpack :: Bool -- ^ If hpack generated a new cabal file
@@ -39,8 +44,8 @@ data Package = Package
3944 }
4045 deriving (Show)
4146
42−getPackage :: Bool
43− -- ^ Whether hpack should regenerate the cabal file.
47+getPackage :: HpackUse
48+ -- ^ the way hpack should be used.
4449 -> Bool
4550 -- ^ Whether to fetch submodules if fetching from git
4651 -> Maybe FilePath
@@ -52,8 +57,8 @@ getPackage :: Bool
5257getPackage optHpack optSubmodules optHackageDB optHackageSnapshot =
5358 getPackage' optHpack optSubmodules (loadHackageDB optHackageDB optHackageSnapshot)
5459
55−getPackage' :: Bool
56− -- ^ Whether hpack should regenerate the cabal file.
60+getPackage' :: HpackUse
61+ -- ^ the way hpack should be used.
5762 -> Bool
5863 -- ^ Whether to fetch submodules if fetching from git
5964 -> IO DB.HackageDB
@@ -63,8 +68,8 @@ getPackage' optHpack optSubmodules hackageDB source = do
6368 (derivSource, ranHpack, pkgDesc) <- fetchOrFromDB optHpack optSubmodules hackageDB source
6469 (\s -> Package s ranHpack pkgDesc) <$> maybe (sourceFromHackage (sourceHash source) (showPackageIdentifier pkgDesc) $ sourceCabalDir source) return derivSource
6570
66−fetchOrFromDB :: Bool
67− -- ^ Whether hpack should regenerate the cabal file
71+fetchOrFromDB :: HpackUse
72+ -- ^ the way hpack should be used
6873 -> Bool
6974 -- ^ Whether to fetch submodules if fetching from git
7075 -> IO DB.HackageDB
@@ -175,7 +180,7 @@ showPackageIdentifier pkgDesc = name ++ "-" ++ display version where
175180 name = Cabal.unPackageName (Cabal.packageName pkgId)
176181 version = Cabal.packageVersion pkgId
177182
178−cabalFromPath :: Bool -- ^ Whether hpack should regenerate the cabal file
183+cabalFromPath :: HpackUse -- ^ the way hpack should be used
179184 -> FilePath -> MaybeT IO (Bool, Bool, Cabal.GenericPackageDescription)
180185cabalFromPath optHpack path = do
181186 d <- liftIO $ doesDirectoryExist path
@@ -185,21 +190,25 @@ cabalFromPath optHpack path = do
185190 return (d, ranHpack, pkg)
186191 else (,,) d False <$> cabalFromFile False path
187192
188−cabalFromDirectory :: Bool -- ^ Whether hpack should regenerate the cabal file
193+cabalFromDirectory :: HpackUse -- ^ the way hpack should be used
189194 -> FilePath -> MaybeT IO (Bool, Cabal.GenericPackageDescription)
190−cabalFromDirectory True dir = hpackDirectory dir
191−cabalFromDirectory False dir = do
195+cabalFromDirectory ForceHpack dir = hpackDirectory dir
196+cabalFromDirectory NoHpack dir = onlyCabalFromDirectory dir "*** No .cabal file was found. Exiting."
197+cabalFromDirectory PackageYamlHpack dir = do
192198 useHpack <- liftIO $ doesFileExist (dir </> "package.yaml")
193199 if useHpack
194200 then do
195201 liftIO $ hPutStrLn stderr "*** found package.yaml. Using hpack..."
196202 hpackDirectory dir
197− else do
198− cabals <- liftIO $ getDirectoryContents dir >>= filterM doesFileExist . map (dir </>) . filter (".cabal" `isSuffixOf`)
199− case cabals of
200− [] -> fail "*** Found neither a .cabal file nor package.yaml. Exiting."
201− [cabalFile] -> (,) False <$> cabalFromFile True cabalFile
202− _ -> liftIO $ fail ("*** found more than one cabal file (" ++ show cabals ++ "). Exiting.")
203+ else onlyCabalFromDirectory dir "*** Found neither a .cabal file nor package.yaml. Exiting."
204+
205+onlyCabalFromDirectory :: FilePath -> String -> MaybeT IO (Bool, Cabal.GenericPackageDescription)
206+onlyCabalFromDirectory dir errMsg = do
207+ cabals <- liftIO $ getDirectoryContents dir >>= filterM doesFileExist . map (dir </>) . filter (".cabal" `isSuffixOf`)
208+ case cabals of
209+ [] -> fail errMsg
210+ [cabalFile] -> (,) False <$> cabalFromFile True cabalFile
211+ _ -> liftIO $ fail ("*** found more than one cabal file (" ++ show cabals ++ "). Exiting.")
203212
204213handleIO :: (Exception.IOException -> IO a) -> IO a -> IO a
205214handleIO = Exception.handle