packages feed

stack-all 0.3.1 → 0.4

raw patch · 6 files changed

+120/−57 lines, 6 files

Files

ChangeLog.md view
@@ -1,5 +1,11 @@ # Release history for stack-all +## 0.4 (2022-01-24)+- 'lts' alias can now be used as a commandline version argument+- stack-nightly.yaml is now only used for building nightly+- if creating stack.yaml use latest lts snapshot resolver from snapshot.json+- support aeson-2.0+ ## 0.3.1 (2021-09-06) - newest LTS for a project can now be configured - use cached-json-file for snapshots.json
README.md view
@@ -6,11 +6,10 @@  ## Usage -`stack-all` by default runs `stack build` over-recent Stackage LTS major versions and Nightly-(current default is nightly & LTS 18, 16, 14, 13, 12, 11)+`stack-all` by default runs `stack build` over Stackage Nightly and+LTS major versions (current default is nightly & LTS 18, 16, 14, 13, 12, 11) corresponding to latest major ghc minor versions,-using the stack's `--resolver` option.+with appropriate stack `--resolver` options.  Note that `stack` only works if a `stack.yaml` file exists. If no `stack.yaml` file is found, `stack-all` will create one.@@ -18,22 +17,23 @@ quickly trying to build a package that does not include stack support.  ### Overriding stack.yaml-`stack-all` can use `stack-ltsXX.yaml` files to override the default `stack.yaml`-file for particular LTS major versions. Note that a `stack-ltsXX.yaml` file-will also be used for older LTS major versions until-another `stack-ltsYY.yaml` file is found.+`stack-all` can use `stack-ltsXX.yaml` files to override the default+`stack.yaml` file for particular Stackage major versions.+Note that a `stack-ltsXX.yaml` file will also be used for+older LTS major versions until another `stack-ltsYY.yaml` file is found.+`stack-nightly.yaml` is also supported, but used only for nightly.  For example if you have `stack-lts14.yaml` and `stack-lts12.yaml` files in your project, then `stack.yaml` will be used as normal to build nightly, lts-18 and lts-16, but `stack-lts14.yaml` will be used for building lts-14 and lts-13, and `stack-lts12.yaml` will be used for lts-12, lts-11 (and older).-Since `stack-all` overrides the resolver with `--resolver lts-XX`-the exact minor LTS version specified in the `stack*.yaml` files-doesn't actually matter: `stack-all` always uses the latest minor release of-the LTS major version according to Stackage.+Since `stack-all` overrides the exact resolver with the latest minor snapshot,+the exact minor Stackage version specified in the `stack*.yaml` files+doesn't actually matter: `stack-all` always uses the latest published+minor releases of Stackage major versions. -`stack-ltsXX.yaml` files can be easily prepared using+`stack-ltsXX.yaml` files can be easily created using `stack-all --make-lts ltsXX` (or `-s ltsXX` for short).  (Other versioned stack.yaml filenames like stack-ghc-8.8.yaml@@ -41,6 +41,7 @@  ### Specifying LTS versions You can abbreviate `lts-XX` args to `ltsXX` on the commandline.+`lts` is also accepted and resolved to the latest major LTS version.  There are `--oldest`  and `--newest` options to specify the range of lts versions to build over:@@ -51,8 +52,8 @@ Similarly you can specify the newest LTS version to build from with eg `stack-all -n lts16`. (The default is to build from nightly.) -Alternatively, one can give one or more explicit LTS major versions to build for-as arguments: eg `stack-all lts14` if you only wish to build that version.+Alternatively, one can give one or more explicit LTS major versions to build+for as arguments: eg `stack-all lts14` if you only wish to build that version.  ### Configuring the oldest and/or newest LTS to build You can configure the oldest working LTS major version for your project@@ -70,7 +71,8 @@ `stack-all -c -n lts18` or setting `newest = lts-18`.  ### Running other stack commands-By default `stack-all` just runs the stack `build` command over LTS versions.+By default `stack-all` just runs the stack `build` command over+Stackage major versions.  You can also specify a stack command to run with options on the commandline: eg@@ -87,4 +89,5 @@ You can also build from git source with `stack install` or `cabal install`.  ## Collaboration-The project is hosted at https://github.com/juhp/stack-all under a BSD license.+The project is hosted at https://github.com/juhp/stack-all+under a BSD license.
src/Main.hs view
@@ -79,14 +79,14 @@             then do             -- FIXME take suggested extra-deps into stack.yaml             -- FIXME stack init content too verbose-            unlessM (cmdBool "stack" ["init"]) $-              -- FIXME determine latest stable snapshot automatically-              writeFile "stack.yaml" "resolver: lts-18.8\n"+            unlessM (cmdBool "stack" ["init"]) $ do+              snap <- latestLtsSnapshot+              writeFile "stack.yaml" $ "resolver: " ++ snap ++ "\n"             else error' "no package/project found"      getVersionsCmd :: IO ([MajorVer],[String])     getVersionsCmd = do-      let partitionMajors = swap . partitionEithers . map eitherReadMajor+      let partitionMajors = swap . partitionEithers . map eitherReadMajorAlias           (verlist,cmds) = partitionMajors verscmd       allMajors <- getMajorVers       versions <-@@ -102,7 +102,7 @@                          Nothing -> filter (inRange newestLTS oldestLTS) allMajors             AllVersions -> return allMajors             Oldest ver -> return $ filter (inRange Nightly ver) allMajors-        else return verlist+        else nub <$> mapM resolveMajor verlist       return (versions,if null cmds then ["build"] else cmds)       where         inRange :: MajorVer -> MajorVer -> MajorVer -> Bool@@ -159,35 +159,39 @@ makeStackLTS vers = do   configs <- mapMaybe readStackConf <$> listDirectory "."   forM_ vers $ \ ver -> do+    let newfile = configFile ver     if ver `elem` configs-      then error' $ showConfig ver ++ " already exists!"+      then do+      error' $ newfile ++ " already exists!"       else do       let mcurrentconfig =             listToMaybe $ sort (filter (ver <=) configs)       case mcurrentconfig of-        Nothing -> copyFile "stack.yaml" (showConfig ver)-        Just conf -> copyFile (showConfig conf) (showConfig ver)-      whenJustM (latestSnapshot ver) $ \latest ->-        cmd_ "sed" ["-i", "-e", "s/\\(resolver:\\) .*/\\1 " ++ latest ++ "/", showConfig ver]+        Nothing -> copyFile "stack.yaml" newfile+        Just conf -> do+          let origfile = configFile conf+          copyFile origfile newfile+      whenJustM (latestMajorSnapshot ver) $ \latest ->+        cmd_ "sed" ["-i", "-e", "s/\\(resolver:\\) .*/\\1 " ++ latest ++ "/", newfile] -showConfig :: MajorVer -> FilePath-showConfig sn = "stack-" ++ compactMajor sn <.> "yaml"-  where-    compactMajor :: MajorVer -> String-    compactMajor Nightly = "nightly"-    compactMajor (LTS ver) = "lts" ++ show ver+configFile :: MajorVer -> FilePath+configFile ver = "stack-" ++ showCompact ver <.> "yaml"  stackBuild :: [MajorVer] -> Bool -> Bool -> [String] -> MajorVer -> IO () stackBuild configs keepgoing debug command ver = do-  let config =-        case sort (filter (ver <=) configs) of-          [] -> []-          (cfg:_) -> ["--stack-yaml", showConfig cfg]-  latest <- latestSnapshot ver+  let mcfgver =+        case ver of+          Nightly | Nightly `elem` configs -> Just Nightly+          _ ->+            case sort (filter (ver <=) (delete Nightly configs)) of+              [] -> Nothing+              (cfg:_) -> Just cfg+  latest <- latestMajorSnapshot ver   case latest of     Nothing -> error' $ "no snapshot not found for " ++ showMajor ver     Just minor -> do-      let opts = ["-v" | debug] ++ ["--resolver", minor] ++ config+      let opts = ["-v" | debug] ++ ["--resolver", minor] +++                 maybe [] (\f -> ["--stack-yaml", configFile f]) mcfgver       putStrLn $ "# " ++ minor       if debug         then debugBuild $ opts ++ command
src/MajorVer.hs view
@@ -1,10 +1,12 @@ module MajorVer (   MajorVer(..),-  eitherReadMajor,-  maybeReadMajor,   readCompactMajor,   readMajor,-  showMajor+  showMajor,+  showCompact,+  snapMajorVer,+  MajorVerAlias(..),+  eitherReadMajorAlias   ) where @@ -14,7 +16,6 @@ import Text.Read (readMaybe)  -- FIXME allow specific snapshots?--- FIXME support "lts"? data MajorVer = LTS Int | Nightly   deriving (Eq, Ord) @@ -37,6 +38,7 @@       error' $! "couldn't parse " ++ ver ++ " (expected lts-XX or ltsXX)"  -- readCompactMajor "lts16"+-- Should we support "stack-lts.yaml"? readCompactMajor :: String -> Maybe MajorVer readCompactMajor "nightly" = Just Nightly readCompactMajor ver =@@ -46,12 +48,28 @@       Nothing -> error' $! "couldn't parse compact " ++ ver ++  " (expected ltsXX)"   else Nothing -eitherReadMajor :: String -> Either String MajorVer-eitherReadMajor cs =-  case maybeReadMajor cs of-    Just s -> Right s-    _ -> Left cs- showMajor :: MajorVer -> String showMajor Nightly = "nightly" showMajor (LTS ver) = "lts-" ++ show ver++showCompact :: MajorVer -> String+showCompact = filter (/= '-') . showMajor++snapMajorVer :: String -> MajorVer+snapMajorVer snap =+  case breakOn "." snap of+    (major,_suf) -> readMajor major++---- MajorVerAlias++data MajorVerAlias = LatestLTS | MajorVer MajorVer++maybeReadMajorAlias ::  String -> Maybe MajorVerAlias+maybeReadMajorAlias "lts" = Just LatestLTS+maybeReadMajorAlias v = MajorVer <$> maybeReadMajor v++eitherReadMajorAlias :: String -> Either String MajorVerAlias+eitherReadMajorAlias cs =+  case maybeReadMajorAlias cs of+    Just s -> Right s+    _ -> Left cs
src/Snapshots.hs view
@@ -1,16 +1,25 @@-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE CPP, OverloadedStrings #-}  module Snapshots (   getMajorVers,-  latestSnapshot+  latestMajorSnapshot,+  latestLTS,+  latestLtsSnapshot,+  resolveMajor   ) where  import Data.Aeson import Data.List.Extra-import qualified Data.HashMap.Strict as H+#if MIN_VERSION_aeson(2,0,0)+import Data.Aeson.Key (toText)+import qualified Data.Aeson.KeyMap as M+#else+import qualified Data.HashMap.Lazy as M+#endif import qualified Data.Text as T import Network.HTTP.Query+import SimpleCmd (error') import System.Cached.JSON  import MajorVer@@ -21,12 +30,35 @@ getMajorVers :: IO [MajorVer] getMajorVers = do   obj <- getSnapshots-  return $ reverse . sort $ map (readMajor . T.unpack) (H.keys obj \\ ["lts"]) \\ excludedMajors+  return $ reverse . sort $ map (readMajor . T.unpack . toText) (M.keys obj \\ ["lts"]) \\ excludedMajors+#if !MIN_VERSION_aeson(2,0,0)+  where toText = id+#endif -latestSnapshot :: MajorVer -> IO (Maybe String)-latestSnapshot ver = do+latestMajorSnapshot :: MajorVer -> IO (Maybe String)+latestMajorSnapshot ver = do   lookupKey (T.pack (showMajor ver)) <$> getSnapshots  getSnapshots :: IO Object getSnapshots =   getCachedJSON "stackage-snapshots" "snapshots.json" "http://haddock.stackage.org/snapshots.json" 200++latestLTS :: IO MajorVer+latestLTS = do+  msnap <- lookupKey "lts" <$> getSnapshots+  case msnap of+    Just snap -> return $ snapMajorVer snap+    Nothing -> error' "could not resolve lts major version"++latestLtsSnapshot :: IO String+latestLtsSnapshot = do+  msnap <- resolveMajor LatestLTS >>= latestMajorSnapshot+  case msnap of+    Nothing ->+      error' "failed to determine latest lts snapshot"+    Just snap -> return snap++-- converts 'lts' to actual version+resolveMajor :: MajorVerAlias -> IO MajorVer+resolveMajor LatestLTS = latestLTS+resolveMajor (MajorVer ver) = return ver
stack-all.cabal view
@@ -1,5 +1,5 @@ name:                stack-all-version:             0.3.1+version:             0.4 synopsis:            CLI tool for building across Stackage major versions description:         Build your Haskell project over Stackage major LTS versions.@@ -16,7 +16,7 @@                      ChangeLog.md cabal-version:       1.18 tested-with:         GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5,-                     GHC == 8.8.4, GHC == 8.10.5, GHC == 9.0.1+                     GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2  source-repository head   type:                git