stack2cabal 1.0.13 → 1.0.14
raw patch · 4 files changed
+38/−7 lines, 4 files
Files
- CHANGELOG.md +4/−0
- exe/Main.hs +5/−1
- lib/StackageToHackage/Hackage.hs +28/−5
- stack2cabal.cabal +1/−1
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for stack2cabal +## 1.0.14 -- 2022-09-13++* Add a --no-sort-repos option. #42+ ## 1.0.13 -- 2022-03-06 - Support github field in extra-deps wrt [#39](https://github.com/hasufell/stack2cabal/pull/39), by Fumiaki Kinoshita
exe/Main.hs view
@@ -41,6 +41,7 @@ , output :: Maybe FilePath , inspectRemotes :: Bool , pinGHC :: Bool+ , sortRepos :: Bool , runHpack :: Bool , hackageIndexDate :: Maybe String -- ^ fuzzy date string }@@ -76,6 +77,9 @@ <*> (not <$> switch (long "no-pin-ghc" <> help "Don't pin the GHC version") )+ <*> (not <$> switch+ (long "no-sort-repos" <> help "Don't sort the source repositories")+ ) <*> (not <$> switch (long "no-run-hpack" <> help "Don't run hpack")) <*> optional (strOption@@ -116,7 +120,7 @@ (project, freeze) <- stackToCabal inspectRemotes runHpack inDir stack hack <- extractHack . decodeUtf8 <$> BS.readFile (inDir </> "stack.yaml")- printText <- printProject pinGHC dt project hack+ printText <- printProject pinGHC sortRepos dt project hack -- write files outFile <- case output of
lib/StackageToHackage/Hackage.hs view
@@ -34,8 +34,8 @@ import Control.Monad (forM, when, void) import Control.Monad.Catch (handleIOError) import Data.Hourglass (timePrint, ISO8601_DateAndTime(..), Elapsed)-import Data.List (nub, sort, sortOn)-import Data.List.Extra (nubOrd, nubOrdOn)+import Data.List (nub, sort, sortOn, isSuffixOf, isPrefixOf)+import Data.List.Extra (nubOrd, nubOrdOn, lower, dropPrefix, dropSuffix) import Data.List.NonEmpty (NonEmpty((:|))) import Data.Maybe (fromMaybe, mapMaybe, catMaybes) import Data.Text (Text)@@ -61,7 +61,6 @@ import qualified Data.Text as T import System.Directory (doesFileExist) - -- | Converts a stack.yaml (and list of local packages) to cabal.project and -- cabal.project.freeze. stackToCabal :: Bool -- ^ whether to inspect remotes@@ -86,13 +85,32 @@ let freeze = genFreeze resolver ignore pure (project, freeze) +-- | Extracts username/repo from an all lowercase repository string.+--+-- >>> trimUserRepo "git@github.com:hasufell/stack2cabal.git"+-- "hasufell/stack2cabal"+--+-- >>> trimUserRepo "https://github.com/hasufell/stack2cabal.git"+-- "hasufell/stack2cabal"+trimUserRepo :: String -> String+trimUserRepo s+ | "git@" `isPrefixOf` s = trimUserRepo $ dropPrefix "git@" s+ | "https://" `isPrefixOf` s = trimUserRepo $ dropPrefix "https://" s+ | "github.com" `isPrefixOf` s = trimUserRepo $ dropPrefix "github.com" s+ | "gitlab.com" `isPrefixOf` s = trimUserRepo $ dropPrefix "gitlab.com" s+ | "/" `isPrefixOf` s = trimUserRepo $ dropPrefix "/" s+ | ":" `isPrefixOf` s = trimUserRepo $ dropPrefix ":" s+ | ".git" `isSuffixOf` s = trimUserRepo $ dropSuffix ".git" s+ | otherwise = s printProject :: Bool -- ^ whether to pin GHC+ -> Bool -- ^ whether to sort source-repository-package items -> Maybe Elapsed -- ^ hackage index date to pin -> Project -> Maybe Text -> IO Text-printProject pinGHC indexDate (Project (Ghc ghc) pkgs srcs ghcOpts) hack = do+printProject pinGHC sortRepos indexDate (Project (Ghc ghc) pkgs srcs ghcOpts) hack = do+ ghcOpts' <- printGhcOpts ghcOpts pure $ T.concat $ ["-- Generated by stack2cabal\n\n"]@@ -104,6 +122,11 @@ <> ghcOpts' <> verbatim hack where+ userRepo :: Git -> String+ userRepo Git{repo} = trimUserRepo . lower $ T.unpack repo++ repos = if sortRepos then sortOn userRepo srcs else srcs+ withHackageIndex :: [Text] withHackageIndex | (Just utc) <- indexDate = ["index-state: ", printUTC utc, "\n\n"]@@ -133,7 +156,7 @@ hasTrailingPathSeparator' x = last x == '/' sources :: Text- sources = T.intercalate "\n" (source =<< srcs)+ sources = T.intercalate "\n" (source =<< repos) source :: Git -> [Text] source Git { repo, commit, subdirs } =
stack2cabal.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: stack2cabal-version: 1.0.13+version: 1.0.14 synopsis: Convert stack projects to cabal.project + cabal.project.freeze