stack2cabal 1.0.0 → 1.0.1
raw patch · 2 files changed
+25/−8 lines, 2 filesdep +extra
Dependencies added: extra
Files
- exe/Main.hs +23/−7
- stack2cabal.cabal +2/−1
exe/Main.hs view
@@ -2,31 +2,47 @@ {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} +import Control.Monad (filterM)+import Control.Monad.Extra (ifM) import qualified Data.ByteString as BS import qualified Data.List.NonEmpty as NEL import Data.Text.Encoding (encodeUtf8) import Distribution.Types.PackageName (mkPackageName) import Hpack (Force (..), Options (..), defaultOptions, hpackResult,- resultCabalFile, setTarget)+ setTarget) import StackageToHackage.Hackage (printFreeze, printProject, stackToCabal) import StackageToHackage.Stackage (localDirs, readStack)-import System.Directory (getCurrentDirectory)-import System.FilePath (takeBaseName, (</>))+import System.Directory (doesDirectoryExist,+ doesFileExist,+ getCurrentDirectory,+ listDirectory)+import System.FilePath (takeBaseName, takeExtension,+ (</>)) main :: IO () main = do dir <- getCurrentDirectory stack <- readStack =<< BS.readFile (dir </> "stack.yaml") let subs = NEL.toList $ (dir </>) <$> localDirs stack- hResults <- traverse runHpack subs- let ignore = (mkPackageName . takeBaseName . resultCabalFile) <$> hResults+ hpacks <- filterM doesFileExist $ subs+ _ <- traverse runHpack hpacks+ cabals <- concat <$> traverse (globExt ".cabal") subs+ -- we could use the hpack output to figure out which cabal files to use, but+ -- that misses projects that have explicit .cabal files, so just scan.+ let ignore = (mkPackageName . takeBaseName) <$> cabals (project, freeze) <- stackToCabal ignore dir stack BS.writeFile (dir </> "cabal.project") (encodeUtf8 $ printProject project) BS.writeFile (dir </> "cabal.project.freeze") (encodeUtf8 $ printFreeze freeze) where- runHpack sub = hpackResult $ setTarget (sub </> "package.yaml")- (defaultOptions {optionsForce = Force})+ target sub = sub </> "package.yaml"+ opts = defaultOptions {optionsForce = Force}+ runHpack sub = hpackResult $ setTarget (target sub) opts++globExt :: String -> FilePath -> IO [FilePath]+globExt ext path = do+ files <- ifM (doesDirectoryExist path) (listDirectory path) (pure [])+ pure $ filter ((ext ==) . takeExtension) files -- TODO invoke cabal v2-freeze to minimise the freeze file
stack2cabal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: stack2cabal-version: 1.0.0+version: 1.0.1 synopsis: Convert stack projects to cabal.project + cabal.project.freeze license: GPL-3.0-or-later license-file: LICENSE@@ -23,6 +23,7 @@ , bytestring ^>= 0.10.8.2 , Cabal ^>= 2.4.1.0 , directory ^>= 1.3.3.1+ , extra ^>= 1.6.13 , filepath ^>= 1.4.2.1 , hpack == 0.31.1 , text ^>= 1.2.3.1