stack-all 0.1 → 0.1.1
raw patch · 3 files changed
+35/−18 lines, 3 filesdep ~filepath
Dependency ranges changed: filepath
Files
- ChangeLog.md +5/−1
- Main.hs +28/−15
- stack-all.cabal +2/−2
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for stack-all -## 0.1.0 -- 2020-11-14+## 0.1.1 (2020-12-04)+- fix ordering of stack-lts-*.yaml+- allow --newest to override oldest lts config++## 0.1.0 (2020-11-14) - initial release with --create-config, --debug, --cmd, --newest - VersionSpec: --all-lts, --oldest, and lts args
Main.hs view
@@ -3,6 +3,7 @@ import Control.Monad.Extra import Data.Ini.Config import Data.List.Extra+import Data.Maybe import qualified Data.Text.IO as T import SimpleCmd import SimpleCmdArgs@@ -19,6 +20,15 @@ data Snapshot = LTS Int | Nightly deriving (Eq, Ord) +-- maybeReadSnap "lts16"+readCompactSnap :: String -> Maybe Snapshot+readCompactSnap "nightly" = Just Nightly+readCompactSnap snap =+ if "lts" `isPrefixOf` snap then+ let major = read (dropPrefix "lts" snap) in Just (LTS major)+ else Nothing++-- readSnap "lts-16" readSnap :: String -> Snapshot readSnap "nightly" = Nightly readSnap snap =@@ -46,7 +56,7 @@ error' "no stack.yaml found" simpleCmdArgs (Just version) "Build over Stackage versions" "stack-all builds projects easily across different Stackage versions" $- main' <$>+ run <$> switchWith 'c' "create-config" "Create a project .stack-all file" <*> switchWith 'd' "debug" "Verbose stack build output on error" <*> optional (readSnap <$> strOptionWith 'n' "newest" "lts-MAJOR" "Newest LTS release to build from") <*>@@ -58,8 +68,8 @@ VersionList . map readSnap <$> some (strArg "LTS") <|> flagWith DefaultVersions AllVersions 'a' "all-lts" "Try to build back to LTS 1 even" -main' :: Bool -> Bool -> Maybe Snapshot -> Maybe String -> VersionSpec -> IO ()-main' createConfig debug mnewest mcmd versionSpec = do+run :: Bool -> Bool -> Maybe Snapshot -> Maybe String -> VersionSpec -> IO ()+run createConfig debug mnewest mcmd versionSpec = do if createConfig then case versionSpec of Oldest oldest -> createStackAll oldest@@ -68,17 +78,20 @@ versions <- case versionSpec of DefaultVersions -> do- oldest <- fromMaybeM (return defaultOldest) getOldestLTS- return $ filter (>= oldest) allSnaps+ oldest <- fromMaybeM (return defaultOldest) readOldestLTS+ return $ case mnewest of+ Just newest | newest < oldest -> filter (newest >=) allSnaps+ _ -> filter (>= oldest) allSnaps AllVersions -> return allSnaps Oldest ver -> return $ filter (>= ver) allSnaps VersionList vers -> return vers- configs <- filter isStackConf <$> listDirectory "."+ configs <- mapMaybe readStackConf <$> listDirectory "." let newestFilter = maybe id (filter . (>=)) mnewest mapM_ (stackBuild configs debug mcmd) (newestFilter versions) where- isStackConf :: FilePath -> Bool- isStackConf f = "stack-" `isPrefixOf` f && "yaml" `isExtensionOf` f+ readStackConf :: FilePath -> Maybe Snapshot+ readStackConf f =+ stripPrefix "stack-" f >>= stripSuffix ".yaml" >>= readCompactSnap stackAllFile :: FilePath stackAllFile = ".stack-all"@@ -91,8 +104,8 @@ writeFile stackAllFile $ "[versions]\n# reason comment\noldest = " ++ showSnap snap ++ "\n" -getOldestLTS :: IO (Maybe Snapshot)-getOldestLTS = do+readOldestLTS :: IO (Maybe Snapshot)+readOldestLTS = do haveConfig <- doesFileExist stackAllFile if haveConfig then Just . readSnap <$> readIniConfig stackAllFile rcParser id@@ -108,13 +121,13 @@ ini <- T.readFile inifile return $ either error fn $ parseIniFile ini iniparser -stackBuild :: [FilePath] -> Bool -> Maybe String -> Snapshot -> IO ()+stackBuild :: [Snapshot] -> Bool -> Maybe String -> Snapshot -> IO () stackBuild configs debug mcmd snap = do let command = maybe ["build"] words mcmd config =- case sort (filter (snapConfig <=) configs) of+ case sort (filter (snap <=) configs) of [] -> []- (cfg:_) -> ["--stack-yaml", cfg]+ (cfg:_) -> ["--stack-yaml", showConfig cfg] args = ["-v" | debug] ++ ["--resolver", showSnap snap] ++ config ++ command if debug@@ -122,8 +135,8 @@ else cmd_ "stack" args putStrLn "" where- snapConfig :: FilePath- snapConfig = "stack-" ++ compactSnap snap <.> "yaml"+ showConfig :: Snapshot -> FilePath+ showConfig sn = "stack-" ++ compactSnap sn <.> "yaml" where compactSnap :: Snapshot -> String compactSnap Nightly = "nightly"
stack-all.cabal view
@@ -1,5 +1,5 @@ name: stack-all-version: 0.1+version: 0.1.1 synopsis: CLI tool for building across Stackage major versions description: Build your Haskell project over Stackage major versions.@@ -28,7 +28,7 @@ config-ini, directory, extra >= 1.6.15,- filepath,+ filepath >= 1.4.2, process, simple-cmd >= 0.1.4, simple-cmd-args,