packages feed

oglyad 0.1.6.0 → 0.1.7.0

raw patch · 11 files changed

+183/−127 lines, 11 filesdep +rozbir

Dependencies added: rozbir

Files

CHANGELOG.md view
@@ -1,5 +1,19 @@ # changelog +## 0.1.7.0++- specs are evaluated with rozbir first, which needs no rpmspec and runs no+  spec code. specs that run real commands or Lua still go through rpmspec.+  over terrapkg/packages and tuatara, rozbir answers 2405 of 2461 specs and+  agrees with rpmspec on all of them. `--rozbir shadow` checks that on a checkout,+  and `--rozbir off` goes back to rpmspec only+- the macros an update.rhai has to set now follow `%global` chains, so+  `Version: %{ver}` with `%global ver %{major}.%{minor}` counts `major` too+- `Oglyad.Version` takes EVR and rpmvercmp from rozbir+- an update.rhai that only sets `%global ver` (or `version`) is replayed on+  the spec with rozbir, so drift compares the whole Version it would produce,+  like `1.3^20261101git`, instead of assuming Version is just `%{ver}`+ ## 0.1.6.0  - new `submodules` check (`-u`): update.rhai scripts that call
README.md view
@@ -208,7 +208,11 @@ checks are `Snapshot -> Package -> [Finding]` and never do IO, so each one is tested with a fake `Snapshot` in `test/Spec.hs`. -- **specs** are evaluated with `rpmspec`+- **specs** are evaluated with [rozbir](https://github.com/terrapkg/rozbir),+  which expands macros without running anything. specs it can't finish+  (`%(...)`, `%{lua:...}`) fall back to `rpmspec`. `--rozbir shadow` runs+  both and notes every spec where they disagree, and `--rozbir off` always+  runs `rpmspec` - **update.rhai** is lexed and pattern-matched, not run. it follows `let`   bindings into `rpm.version(...)` / `rpm.global("ver", ...)` and recognizes   the andax helpers (`gh`, `pypi`, `crates`, `gitlab`, ...)@@ -238,7 +242,9 @@ ## security  `rpmspec` runs the shell code in specs (`%(...)`, `%{lua:...}`), so running-oglyad on a checkout means running that checkout's code as you. child+oglyad on a checkout means running that checkout's code as you. rozbir+answers for about 98% of specs without running anything, so only the rest go+through rpmspec. child processes get an allowlisted environment, so `GITHUB_TOKEN` and other secrets in oglyad's environment never reach them, but code running as your user can still read your files.
app/Main.hs view
@@ -26,6 +26,7 @@ import Oglyad.Report (Format (..), ReleaseInfo (..), Report (..), render) import Oglyad.Source.Cache (loadJson, saveJson) import Oglyad.Source.Monorepo (pruneTrees)+import Oglyad.Source.Rozbir (parseRozbirMode) import Oglyad.Types import Options.Applicative import System.Directory (doesDirectoryExist)@@ -106,6 +107,7 @@   cfgUpstream <- switch (long "upstream" <> short 'u' <> help "query upstream APIs for version drift")   cacheHours <- option auto (long "cache-hours" <> metavar "N" <> value (6 :: Int) <> showDefault <> help "reuse upstream answers younger than this, 0 to always refetch")   jobs <- optional (option auto (long "jobs" <> short 'j' <> metavar "N" <> help "parallel jobs (default: number of cores)"))+  cfgRozbir <- option (eitherReader parseRozbirMode) (long "rozbir" <> metavar "MODE" <> value RozbirFirst <> help "how specs get evaluated: first asks rozbir and only runs rpmspec for specs it can't finish (the default), shadow runs both and reports where they differ, off always runs rpmspec")   pure $ \ConfigInputs {ciDistro = distro, ciRelease = rel, ..} ->     Config       { cfgGitHubToken = ciGitHubToken,
oglyad.cabal view
@@ -1,6 +1,6 @@ cabal-version:   3.0 name:            oglyad-version:         0.1.6.0+version:         0.1.7.0 synopsis:        repository metadata and health checker for Terra description:   oglyad checks a terrapkg/packages checkout against Terra's published@@ -77,6 +77,7 @@     Oglyad.Source.Monorepo     Oglyad.Source.Repodata     Oglyad.Source.Rhai+    Oglyad.Source.Rozbir     Oglyad.Source.RhaiEval     Oglyad.Source.Upstream     Oglyad.Types@@ -97,6 +98,7 @@     , http-client-tls      >=0.3.6 && <0.5     , http-types           >=0.12.4 && <0.13     , megaparsec           >=9.5 && <9.9+    , rozbir               >=0.1 && <0.2     , mtl                  >=2.3.1 && <2.4     , typed-process        >=0.2.11 && <0.3     , vector               >=0.13.1 && <0.14
src/Oglyad/Collect.hs view
@@ -6,13 +6,14 @@ import Control.Applicative ((<|>)) import Control.Concurrent.Async (concurrently) import Control.Concurrent.MVar (withMVar)-import Control.Monad (forM, join)+import Control.Exception (IOException, try)+import Control.Monad (forM, join, when) import Control.Monad.Reader (ask, asks, liftIO, runReaderT) import Data.Either (partitionEithers) import Data.List (nub, partition) import Data.Map.Strict (Map) import Data.Map.Strict qualified as Map-import Data.Maybe (fromMaybe, isJust, isNothing, mapMaybe)+import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing, mapMaybe) import Data.Text (Text) import Data.Text qualified as T import Data.Time (NominalDiffTime, UTCTime, diffUTCTime, getCurrentTime, nominalDay)@@ -23,8 +24,10 @@ import Oglyad.Source.Repodata (fetchRepo) import Oglyad.Source.Rhai (parseUpdateRhaiWith, tokenize, tracksSubmodules) import Oglyad.Source.RhaiEval (Simulated (..), simulateVersion)+import Oglyad.Source.Rozbir (Mismatch (..), evaluateSpec, mismatches, newEvaluator, versionAfterGlobal) import Oglyad.Source.Upstream (latestVersion) import Oglyad.Types+import Rozbir.IO (readSpecText) import System.Directory (findExecutable, makeAbsolute) import System.FilePath ((</>)) import System.Info qualified@@ -89,7 +92,7 @@   ((upErrs, fromApis), (andaErrs, fromAnda)) <-     liftIO $       concurrently-        (runReaderT (withUpstreams now pkgs) env)+        (runReaderT (withUpstreams now root pkgs) env)         (runReaderT (maybe (pure ([], id)) (\r -> withAnda r now pkgs) root) env)   pure (upErrs <> andaErrs, fromAnda . fromApis) @@ -126,16 +129,20 @@   -- without rpmspec, cached evaluations still work. everything else is   -- skipped and reported once, rather than as one error per package   hasRpmspec <- liftIO (isJust <$> findExecutable "rpmspec")+  evaluator <- liftIO (newEvaluator cfgRozbir)   inSlot <- processSlot   results <- forConcurrentlyN cfgConcurrency keyed $ \(key, d) -> liftIO $ do     case (Map.lookup key cache, pdSpec d) of       (Just cached, _) -> pure (Evaluated key d cached)       (Nothing, Just spec)-        | hasRpmspec -> Evaluated key d <$> inSlot (querySpec cfgMacros (root </> spec))+        | hasRpmspec || cfgRozbir == RozbirFirst -> Evaluated key d <$> inSlot (evaluateSpec evaluator cfgMacros (root </> spec))         | otherwise -> pure Skipped       (Nothing, Nothing) -> pure (NoSpec d)   -- keep only entries for packages that still exist, so the file can't grow forever   liftIO (saveJson cacheFile (Map.fromList [(k, i) | Evaluated k _ i <- results]))+  shadowed <- liftIO (mismatches evaluator)+  mapM_ (\Mismatch {..} -> note ("rozbir disagrees with rpmspec on " <> mmSpec <> ": " <> T.unpack mmRozbir <> " vs " <> T.unpack mmRpmspec)) shadowed+  when (cfgRozbir == RozbirShadow) (note ("rozbir shadow mode: " <> show (length shadowed) <> " mismatches"))   let skipped = length [() | Skipped <- results]       missing =         [ collectErr "rpmspec" ("rpmspec not found, install rpm-build. skipped " <> T.pack (show skipped) <> " specs with no cached result")@@ -206,8 +213,8 @@ -- | crates.io allows one request a second, so its lookups run in their own -- serial queue next to everything else. inside the shared job pool, a cluster -- of crates packages would hold every slot while waiting their turn-withUpstreams :: UTCTime -> [Package] -> App ([Finding], Package -> Package)-withUpstreams now pkgs = do+withUpstreams :: UTCTime -> Maybe FilePath -> [Package] -> App ([Finding], Package -> Package)+withUpstreams now root pkgs = do   cfg@Config {..} <- asks envConfig   cache <- liftIO (fromMaybe Map.empty <$> loadJson "upstream.json") :: App UpstreamCache   let wanted = [p | p <- pkgs, Just src <- [pkgUpstream p], lookable src]@@ -244,6 +251,17 @@               }           ]   saveSharedCache "upstream.json" now new+  specTexts <-+    liftIO . fmap (Map.fromList . catMaybes) $+      forM [(pkgPath p, r </> sp) | Just r <- [root], p <- wanted, Just sp <- [pkgSpecPath p]] $ \(path, file) ->+        either (\(_ :: IOException) -> Nothing) (\t -> Just (path, t)) <$> try (readSpecText file)+  let replay p v = case (pkgUpstream p, pkgRhai p) of+        (Just src, Just script) -> case simulateVersion src v script of+          Sets v' -> Just v'+          SetsGlobal key v' -> Just (fromMaybe v' (Map.lookup (pkgPath p) specTexts >>= versionAfterGlobal cfgMacros key v'))+          NoUpdate -> Nothing+          CantTell -> Just v+        _ -> Just v   pure     ( rateErr,       \p -> case Map.lookup (pkgPath p) byPath of@@ -255,14 +273,6 @@     )   where     cacheKey src = T.pack (show src)-    -- run the script's guards and edits over the raw value, so a tag the-    -- script would skip (or crop) doesn't show up as drift-    replay p v = case (pkgUpstream p, pkgRhai p) of-      (Just src, Just script) -> case simulateVersion src v script of-        Sets v' -> Just v'-        NoUpdate -> Nothing-        CantTell -> Just v-      _ -> Just v     lookable = \case       CommitTracked -> False       NoVersion -> False@@ -302,6 +312,7 @@           note ("running anda update for " <> show (length wanted) <> " scripts that need anda, " <> show (length wanted - length misses) <> " cached")           env <- ask           inSlot <- processSlot+          evaluator <- liftIO (newEvaluator cfgRozbir)           r <- liftIO $ withScratchCopy root $ \copy ->             projectNames copy >>= \case               Left e -> pure (Left e)@@ -313,7 +324,7 @@                         Left e -> pure (Left e)                         Right events ->                           either (Left . ("rpmspec failed on the updated spec: " <>)) (\i -> Right (evrVersion (siEVR i), events))-                            <$> querySpec cfgMacros (copy </> spec)+                            <$> evaluateSpec evaluator cfgMacros (copy </> spec)                     _ -> pure (Left "anda doesn't list this project")           pure $ case join r of             Left e -> ([(collectErr "anda" e) {fSeverity = Warn}], Map.empty)
src/Oglyad/Source/Monorepo.hs view
@@ -21,7 +21,7 @@ import Data.Aeson (FromJSON, ToJSON) import Data.ByteString qualified as BS import Data.ByteString.Base16 qualified as B16-import Data.Char (isAlphaNum, isSpace)+import Data.Char (isSpace) import Data.List (sort) import Data.List qualified as List import Data.Map.Strict (Map)@@ -38,6 +38,7 @@ import Oglyad.Process (run) import Oglyad.Source.Cache (cacheDir) import Oglyad.Version (EVR, parseEVR)+import Rozbir qualified import System.Directory (createDirectory, createDirectoryIfMissing, doesDirectoryExist, doesFileExist, getModificationTime, getSymbolicLinkTarget, listDirectory, pathIsSymbolicLink, removeFile, removePathForcibly, renameDirectory, setModificationTime) import System.FilePath (takeDirectory, takeExtension, (</>)) import System.IO (hClose, openBinaryTempFile)@@ -110,19 +111,14 @@ -- | read from the raw text, since rpmspec would expand away the macros an -- update.rhai has to set to change the version versionMacros :: Text -> Maybe [Text]-versionMacros spec = case [T.strip v | l <- T.lines spec, Just v <- [stripTag l]] of-  v : _ -> Just (names v)-  [] -> Nothing+versionMacros spec+  | any isVersionTag (Rozbir.treeLines tree) = Just (Rozbir.versionInputs tree)+  | otherwise = Nothing   where-    stripTag l = case T.breakOn ":" l of-      (tag, rest) | T.toLower (T.strip tag) == "version", not (T.null rest) -> Just (T.drop 1 rest)-      _ -> Nothing-    names t = case T.breakOn "%" t of-      (_, "") -> []-      (_, rest) ->-        let after = T.dropWhile (`elem` ("{?!" :: String)) (T.drop 1 rest)-            (name, more) = T.span (\c -> isAlphaNum c || c == '_') after-         in [name | not (T.null name)] <> names more+    tree = Rozbir.parse spec+    isVersionTag l = case Rozbir.lineBody l of+      Rozbir.Tag t -> T.toLower (Rozbir.tagName t) == "version"+      _ -> False  -- | not a real HCL parser, but good enough for the flat labels and rpm -- blocks anda uses
src/Oglyad/Source/RhaiEval.hs view
@@ -9,7 +9,6 @@   ) where -import Control.Applicative ((<|>)) import Data.Char (isAlphaNum, isDigit) import Data.Map.Strict (Map) import Data.Map.Strict qualified as Map@@ -23,6 +22,7 @@  data Simulated   = Sets Text+  | SetsGlobal Text Text   | -- | `anda update` wouldn't touch the spec for this upstream value     NoUpdate   | CantTell@@ -44,7 +44,10 @@           Left GiveUp -> CantTell   _ -> CantTell   where-    outcome env = maybe NoUpdate Sets (envVersion env <|> envGlobal env)+    outcome env = case (envVersion env, envGlobal env) of+      (Just v, _) -> Sets v+      (Nothing, Just (key, v)) -> SetsGlobal key v+      (Nothing, Nothing) -> NoUpdate  data Value = VStr Text | VNum Int | VBool Bool | VArr [Value] | VUnit   deriving stock (Eq, Show)@@ -67,7 +70,7 @@  -- | rpm.version wins over rpm.global("ver", ...), since some scripts set the -- global to the raw tag and Version to a cleaned-up spelling of it-data VersionTarget = RpmVersion | RpmGlobal+data VersionTarget = RpmVersion | RpmGlobal Text   deriving stock (Show)  data Stmt@@ -148,7 +151,7 @@     | f `elem` ["global", "define"],       key `elem` ["ver", "version"],       Just [a] <- finalCallArgs r ->-        SetVersion RpmGlobal a+        SetVersion (RpmGlobal key) a   TIdent "rpm" : TSym '.' : TIdent "f" : TSym '=' : t : _ | t /= TSym '=' -> RewritesSpec   TIdent "rpm" : _ -> Ignored   TIdent "print" : _ -> Ignored@@ -296,7 +299,7 @@   { -- | Nothing is a value we can't know, like another helper's result     envVars :: Map Text (Maybe Value),     envVersion :: Maybe Text,-    envGlobal :: Maybe Text+    envGlobal :: Maybe (Text, Text)   }  emptyEnv :: Env@@ -336,7 +339,7 @@       SetVersion target e -> case eval ctx env e of         Right (VStr t) -> Right $ case target of           RpmVersion -> env {envVersion = Just t}-          RpmGlobal -> env {envGlobal = Just t}+          RpmGlobal key -> env {envGlobal = Just (key, t)}         Left Throw -> Left (Thrown env)         _ -> Left GiveUp       If c yes no -> case eval ctx env c of
+ src/Oglyad/Source/Rozbir.hs view
@@ -0,0 +1,91 @@+module Oglyad.Source.Rozbir+  ( Evaluator,+    Mismatch (..),+    parseRozbirMode,+    newEvaluator,+    evaluateSpec,+    mismatches,+    versionAfterGlobal,+  )+where++import Control.Exception (SomeException, try)+import Data.IORef (IORef, atomicModifyIORef', newIORef, readIORef)+import Data.Map.Strict qualified as Map+import Data.Text (Text)+import Data.Text qualified as T+import Oglyad.Source.Monorepo (SpecInfo (..), querySpec)+import Oglyad.Types (RozbirMode (..))+import Oglyad.Version (renderEVR)+import Rozbir (ResolveOptions (..), Resolved (..), Target (..), evr, name, newEnv, parse, resolve, resolveWith, version)+import Rozbir.Edit (apply, setMacro)+import Rozbir.Eval (Env)+import Rozbir.IO (loadSystemMacros, readSpec, resolveIncludes)+import System.FilePath (takeDirectory)+import System.Info qualified++data Evaluator = Evaluator+  { evMode :: RozbirMode,+    evEnv :: Env,+    evMismatches :: IORef [Mismatch]+  }++data Mismatch = Mismatch+  { mmSpec :: FilePath,+    mmRozbir :: Text,+    mmRpmspec :: Text+  }+  deriving stock (Eq, Show)++parseRozbirMode :: String -> Either String RozbirMode+parseRozbirMode = \case+  "off" -> Right RozbirOff+  "shadow" -> Right RozbirShadow+  "first" -> Right RozbirFirst+  other -> Left ("unknown rozbir mode " <> other <> ", use off, shadow or first")++newEvaluator :: RozbirMode -> IO Evaluator+newEvaluator mode = do+  env <- if mode == RozbirOff then pure (newEnv True) else loadSystemMacros (Just (T.pack System.Info.arch))+  Evaluator mode env <$> newIORef []++viaRozbir :: Env -> [(Text, Maybe Text)] -> FilePath -> IO (Maybe SpecInfo)+viaRozbir env macros spec = do+  r <- try $ do+    tree <- readSpec spec+    includes <- resolveIncludes spec tree+    let target = Target (Just (T.pack System.Info.arch)) (Just "linux") (macros <> [("_sourcedir", Just (T.pack (takeDirectory spec)))])+        resolved = resolveWith (ResolveOptions env target includes) tree+    pure $ case (name resolved, evr resolved) of+      (Resolved n, Resolved e) -> Just (SpecInfo n e)+      _ -> Nothing+  pure (either (\(_ :: SomeException) -> Nothing) id r)++evaluateSpec :: Evaluator -> [(Text, Maybe Text)] -> FilePath -> IO (Either Text SpecInfo)+evaluateSpec Evaluator {..} macros spec = case evMode of+  RozbirOff -> querySpec macros spec+  RozbirFirst -> viaRozbir evEnv macros spec >>= maybe (querySpec macros spec) (pure . Right)+  RozbirShadow -> do+    theirs <- querySpec macros spec+    ours <- viaRozbir evEnv macros spec+    case (ours, theirs) of+      (Just o, Right t)+        | o /= t ->+            atomicModifyIORef' evMismatches (\ms -> (Mismatch spec (describe o) (describe t) : ms, ()))+      _ -> pure ()+    pure theirs+  where+    describe SpecInfo {..} = siName <> " " <> renderEVR siEVR++mismatches :: Evaluator -> IO [Mismatch]+mismatches ev = reverse . Map.elems . Map.fromList . map (\m -> (mmSpec m, m)) <$> readIORef (evMismatches ev)++versionAfterGlobal :: [(Text, Maybe Text)] -> Text -> Text -> Text -> Maybe Text+versionAfterGlobal macros key value spec = case setMacro key value (parse spec) of+  Left _ -> Nothing+  Right edits ->+    let tree = parse (apply edits spec)+        target = Target (Just (T.pack System.Info.arch)) (Just "linux") macros+     in case version (resolve (newEnv False) target tree) of+          Resolved v -> Just v+          Unresolved _ -> Nothing
src/Oglyad/Types.hs view
@@ -10,6 +10,7 @@     finding,     Snapshot (..),     Config (..),+    RozbirMode (..),     repoUrl,     Check,   )@@ -153,6 +154,9 @@       fReleases = []     } +data RozbirMode = RozbirOff | RozbirShadow | RozbirFirst+  deriving stock (Eq, Show)+ data Config = Config   { cfgMonorepo :: FilePath,     cfgRoot :: FilePath,@@ -178,7 +182,8 @@     -- says, so checking several releases asks each upstream once     cfgRunStart :: UTCTime,     cfgConcurrency :: Int,-    cfgGitHubToken :: Maybe Text+    cfgGitHubToken :: Maybe Text,+    cfgRozbir :: RozbirMode   }   deriving stock (Show) 
src/Oglyad/Version.hs view
@@ -1,5 +1,3 @@--- | ports rpmio/rpmvercmp.c from rpm-software-management/rpm, tested--- against its tests/rpmvercmp.at module Oglyad.Version   ( EVR (..),     parseEVR,@@ -11,95 +9,13 @@   ) where -import Data.Aeson (FromJSON, ToJSON)-import Data.Char (isAlphaNum, isAsciiLower, isAsciiUpper, isDigit)+import Data.Char (isAlphaNum, isDigit) import Data.List (minimumBy) import Data.Maybe (fromMaybe) import Data.Ord (comparing) import Data.Text (Text) import Data.Text qualified as T-import GHC.Generics (Generic)-import Text.Read (readMaybe)---- | 'Eq' is structural but 'Ord' goes through rpmvercmp, so "1.05" and "1.5"--- compare EQ while being /=. build-lag relies on that, since any textual--- difference between git and the repo is worth reporting-data EVR = EVR-  { evrEpoch :: !Int,-    evrVersion :: !Text,-    evrRelease :: !Text-  }-  deriving stock (Eq, Show, Generic)-  deriving anyclass (ToJSON, FromJSON)--instance Ord EVR where-  compare = compareEVR--parseEVR :: Text -> Maybe EVR-parseEVR raw = do-  let (epochPart, rest) = case T.breakOn ":" raw of-        (vr, "") -> ("0", vr)-        (e, r) -> (e, T.drop 1 r)-  epoch <- if epochPart == "(none)" then Just 0 else readMaybe (T.unpack epochPart)-  -- versions can't contain dashes, so the release starts after the last one-  let (verDash, rel) = T.breakOnEnd "-" rest-  ver <- T.stripSuffix "-" verDash-  if T.null ver || T.null rel then Nothing else Just (EVR epoch ver rel)--renderEVR :: EVR -> Text-renderEVR (EVR 0 v r) = v <> "-" <> r-renderEVR (EVR e v r) = T.pack (show e) <> ":" <> v <> "-" <> r--compareEVR :: EVR -> EVR -> Ordering-compareEVR (EVR e1 v1 r1) (EVR e2 v2 r2) =-  compare e1 e2 <> rpmvercmp v1 v2 <> rpmvercmp r1 r2---- | a line-by-line port of rpmvercmp.c------   * anything that isn't an ascii letter, digit, '~' or '^' is a separator---   * '~' sorts before everything, even the end of the string (1.0~rc1 < 1.0)---   * '^' sorts after the end of the string but before anything else---     (1.0 < 1.0^git1 < 1.0.1)---   * otherwise compare segment by segment, where a segment is a run of---     digits or a run of letters. numbers beat letters, numbers compare---     numerically, letters compare lexically---   * when one side runs out, the side with stuff left is newer-rpmvercmp :: Text -> Text -> Ordering-rpmvercmp a b-  | a == b = EQ-  | otherwise = go a b-  where-    go one0 two0-      | T.null one0 && T.null two0 = EQ-      | otherwise =-          let one = T.dropWhile isSep one0-              two = T.dropWhile isSep two0-           in case (T.uncons one, T.uncons two) of-                (Just ('~', one'), Just ('~', two')) -> go one' two'-                (Just ('~', _), _) -> LT-                (_, Just ('~', _)) -> GT-                (Just ('^', one'), Just ('^', two')) -> go one' two'-                (Nothing, Just ('^', _)) -> LT-                (Just ('^', _), Nothing) -> GT-                (Just ('^', _), Just _) -> LT-                (Just _, Just ('^', _)) -> GT-                (Nothing, Nothing) -> EQ-                (Just _, Nothing) -> GT-                (Nothing, Just _) -> LT-                (Just (c, _), Just _)-                  | isDigit c -> segment True (T.span isDigit one) (T.span isDigit two)-                  | otherwise -> segment False (T.span isAlpha one) (T.span isAlpha two)--    segment isNum (seg1, rest1) (seg2, rest2)-      | T.null seg2 = if isNum then GT else LT-      | isNum =-          let n1 = T.dropWhile (== '0') seg1-              n2 = T.dropWhile (== '0') seg2-           in compare (T.length n1) (T.length n2) <> compare n1 n2 <> go rest1 rest2-      | otherwise = compare seg1 seg2 <> go rest1 rest2--    isAlpha c = isAsciiLower c || isAsciiUpper c-    isSep c = not (isDigit c || isAlpha c || c == '~' || c == '^')+import Rozbir.Version (EVR (..), compareEVR, parseEVR, renderEVR, rpmvercmp)  -- | turn an upstream tag (or a sloppy spec Version) into something -- rpmvercmp can compare. starts from what anda's rpm.version() does (trim,
test/Spec.hs view
@@ -29,6 +29,7 @@ import Oglyad.Source.Repodata (RpmEntry (..), decompressAndParse, fetchRepo, latestBySource, parseMetalink, parsePrimary, srpmName) import Oglyad.Source.Rhai (parseUpdateRhai, parseUpdateRhaiWith, tracksSubmodules) import Oglyad.Source.RhaiEval (Simulated (..), simulateVersion)+import Oglyad.Source.Rozbir (versionAfterGlobal) import Oglyad.Source.Upstream (isSemver) import Oglyad.Types import Oglyad.Version@@ -170,7 +171,7 @@       sim "v0.0.17-beta-release" script `shouldBe` Sets "0.0.17~beta"     it "treats rpm.changed() as true and follows truncate" $ do       let script = "rpm.global(\"commit\", gh_commit(\"a/b\"));\nif rpm.changed() {\n    rpm.release();\n    let v = gh(\"a/b\");\n    v.truncate(6);\n    v.crop(1);\n    rpm.global(\"ver\", v);\n}"-      sim "v1.0.1-iot-arl-twl-asl-v6.12" script `shouldBe` Sets "1.0.1"+      sim "v1.0.1-iot-arl-twl-asl-v6.12" script `shouldBe` SetsGlobal "ver" "1.0.1"     it "gives up on scripts that rewrite the spec through rpm.f" $       sim "v1.2.3" "let v = gh(\"a/b\");\nrpm.f = sub(`(?m)^Version:.*$`, \"Version: \" + v, rpm.f);" `shouldBe` CantTell     it "knows a script that never sets Version won't update" $@@ -345,13 +346,21 @@       UnparsedRhai.check snapshot unknown {pkgUpdBranch = False} `shouldBe` []       map fCheck (UnparsedRhai.check rawhide unknown {pkgUpdBranch = False}) `shouldBe` ["unparsed-rhai"] +  describe "versionAfterGlobal" $ do+    it "reads Version after setting the global" $+      versionAfterGlobal [] "ver" "1.3" "%global ver 1.2\n%global commit_date 20261101\nName: x\nVersion: %{ver}^%{commit_date}git\n" `shouldBe` Just "1.3^20261101git"+    it "gives up when the global isn't there" $+      versionAfterGlobal [] "ver" "1.3" "Name: x\nVersion: 1.2\n" `shouldBe` Nothing+   describe "versionMacros" $ do     it "finds %name, %{name} and %{?name}" $-      versionMacros "Name: x\nVersion:  %{?fedora:%{fedora}}%{?rhel:%{rhel}}\n" `shouldBe` Just ["fedora", "fedora", "rhel", "rhel"]+      versionMacros "Name: x\nVersion:  %{?fedora:%{fedora}}%{?rhel:%{rhel}}\n" `shouldBe` Just ["fedora", "rhel"]     it "finds macros inside shell expansions" $       versionMacros "%global tag cli-v0.3.0\nVersion: %(echo %tag | sed 's/^cli-v//')\n" `shouldBe` Just ["tag"]     it "is Nothing without a Version: line" $       versionMacros "Name: x\n" `shouldBe` Nothing+    it "follows %global chains" $+      versionMacros "%global major 1\n%global ver %{major}.2\nVersion: %{ver}\n" `shouldBe` Just ["ver", "major"]      it "falls back to Unknown" $       parseUpdateRhai "let x = get(\"https://example.com\").json();\nrpm.version(x.version);" `shouldSatisfy` isUnknown@@ -779,7 +788,8 @@             cfgCacheFor = 0,             cfgRunStart = now,             cfgConcurrency = 1,-            cfgGitHubToken = Nothing+            cfgGitHubToken = Nothing,+            cfgRozbir = RozbirOff           },       snapHead = Nothing,       snapIgnoreLabels = Map.empty