rozbir 0.1.0.0 → 0.1.0.1
raw patch · 8 files changed
+50/−13 lines, 8 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Rozbir.Eval.Types: [envLuaDefined] :: Env -> !Bool
- Rozbir.Eval.Types: Env :: !Map Name [MacroDef] -> !Bool -> Env
+ Rozbir.Eval.Types: Env :: !Map Name [MacroDef] -> !Bool -> !Bool -> Env
Files
- CHANGELOG.md +5/−0
- rozbir.cabal +1/−1
- src/Rozbir/Eval.hs +17/−4
- src/Rozbir/Eval/Types.hs +3/−1
- src/Rozbir/Lint/Core.hs +10/−2
- src/Rozbir/Lint/Rpmlint.hs +8/−5
- test/EvalSpec.hs +5/−0
- test/LintSpec.hs +1/−0
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for rozbir +## 0.1.0.1 -- 11/24/2026++- reword some lint diagnostics+- fix a lua parsing bug+ ## 0.1.0.0 -- 11/24/2026 - first version: lossless spec parser, partial evaluator with a pure
rozbir.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: rozbir-version: 0.1.0.0+version: 0.1.0.1 synopsis: parse, evaluate, edit and lint RPM spec files description: rozbir is a pure library for RPM spec files. it parses them into a
src/Rozbir/Eval.hs view
@@ -94,7 +94,7 @@ -- | an environment with only rpm's built-in macros. 'True' makes it closed, -- meaning system macros are already loaded. newEnv :: Bool -> Env-newEnv closed = L.foldl' build (L.foldl' add (Env Map.empty closed) preludeMacros) buildTimeMacros+newEnv closed = L.foldl' build (L.foldl' add (Env Map.empty closed False) preludeMacros) buildTimeMacros where add env (name, opts, body) = pushDef name (MacroDef opts (BodyRaw body) OriginPrelude 0 False) env build env (name, body) = pushDef name (MacroDef Nothing body OriginPrelude 0 False) env@@ -163,7 +163,7 @@ lookupMacro name | Just b <- builtinNamed name = pure (IsBuiltin b) | otherwise = do- EvalState {esEnv = Env macros closed, esLevel = lvl} <- get+ EvalState {esEnv = Env macros closed luaDefined, esLevel = lvl} <- get pure $ case Map.lookup name macros of Just (m : _) | macroAuto m && lvl > macroLevel m -> NotFound@@ -172,7 +172,9 @@ BodyMaybe r -> Unsure r _ -> Found m _- | closed || isAutoName name || name `elem` closedNames || isKeyword name || any (`T.isPrefixOf` name) closedPrefixes -> NotFound+ | isAutoName name || name `elem` closedNames || isKeyword name || any (`T.isPrefixOf` name) closedPrefixes -> NotFound+ | luaDefined -> Unsure RunsLua+ | closed -> NotFound | otherwise -> Unsure (Undefined name) isKeyword :: Name -> Bool@@ -221,6 +223,7 @@ (envMacros b) ) (envClosed a && envClosed b)+ (envLuaDefined a || envLuaDefined b) where conflict k s1 s2 = let top1 = defined s1@@ -242,11 +245,21 @@ _ -> False luaDefines :: Text -> Eval ()-luaDefines src = mapM_ maybeDefined (luaDefinedNames src)+luaDefines src = do+ when (luaDefinesUnknownNames src) $+ modify' (\s -> s {esEnv = (esEnv s) {envLuaDefined = True}})+ mapM_ maybeDefined (luaDefinedNames src) where maybeDefined n = do lvl <- gets esLevel pushMacro n (MacroDef Nothing (BodyMaybe RunsLua) OriginAuto lvl False)++luaDefinesUnknownNames :: Text -> Bool+luaDefinesUnknownNames src = "require" `T.isInfixOf` src || any (not . literalAfter 10) (T.breakOnAll "rpm.define" src) || any (not . literalAfter 7) (T.breakOnAll "macros[" src)+ where+ literalAfter n (_, rest) = case T.uncons (T.dropWhile (`elem` [' ', '(']) (T.drop n rest)) of+ Just (c, _) -> c == '"' || c == '\''+ Nothing -> False luaDefinedNames :: Text -> [Name] luaDefinedNames src = filter (not . T.null) (defines <> assigns <> indexed)
src/Rozbir/Eval/Types.hs view
@@ -294,7 +294,9 @@ { -- | a stack of definitions per name, newest first envMacros :: !(Map Name [MacroDef]), -- | whether system macros are loaded. if not, unknown names become 'Undefined' holes instead of literal text.- envClosed :: !Bool+ envClosed :: !Bool,+ -- | whether Lua ran that could have defined macros rozbir can't name. if so, unknown names might be defined even in a closed env.+ envLuaDefined :: !Bool } deriving stock (Eq, Show, Generic) deriving anyclass (NFData)
src/Rozbir/Lint/Core.hs view
@@ -9,6 +9,8 @@ import Data.Maybe (mapMaybe) import Data.Text (Text) import Data.Text qualified as T+import Data.Time.Calendar (Day)+import Data.Time.Format (defaultTimeLocale, formatTime) import Rozbir.Changelog (Entry (..), EntryHeader (..)) import Rozbir.Edit (TextEdit (..)) import Rozbir.Eval.Types@@ -205,13 +207,19 @@ nub $ concat [ [diag "changelog-date" sp msg | (sp, msg) <- specChangelogProblems spec]- <> [ diag "changelog-date" (entrySpan e) ("the date isn't a " <> ehWeekday (entryHeader e))+ <> [ diag "changelog-date" (entrySpan e) (formatDay day <> " was a " <> weekdayAbbrev day <> ", not a " <> ehWeekday (entryHeader e)) | e <- specChangelog spec,- Just _ <- [ehDate (entryHeader e)],+ Just day <- [ehDate (entryHeader e)], not (ehWeekdayMatches (entryHeader e)) ] | spec <- firstSpec li ]++formatDay :: Day -> Text+formatDay = T.pack . formatTime defaultTimeLocale "%b %-d %Y"++weekdayAbbrev :: Day -> Text+weekdayAbbrev = T.pack . formatTime defaultTimeLocale "%a" changelogOrder :: LintInput -> [Diagnostic] changelogOrder li =
src/Rozbir/Lint/Rpmlint.hs view
@@ -110,9 +110,12 @@ mixedTabs :: LintInput -> [Diagnostic] mixedTabs li = case (firstWith '\t', firstWith ' ') of- (Just (tl, _), Just (sl, _)) ->- let (later, other, kind) = if posOffset (spanStart (lineSpan tl)) > posOffset (spanStart (lineSpan sl)) then (tl, sl, "tabs") else (sl, tl, "spaces")- in [diag "mixed-tabs-spaces" (lineSpan later) ("this line aligns with " <> kind <> ", but line " <> lineNo other <> " uses the other")]+ (Just (tl, _), Just (sl, _))+ | lineSpan tl == lineSpan sl ->+ [diag "mixed-tabs-spaces" (lineSpan tl) "this line lines up its value with both tabs and spaces"]+ | otherwise ->+ let (later, other, kind, otherKind) = if posOffset (spanStart (lineSpan tl)) > posOffset (spanStart (lineSpan sl)) then (tl, sl, "tabs", "spaces") else (sl, tl, "spaces", "tabs")+ in [diag "mixed-tabs-spaces" (lineSpan later) ("this line lines up its value with " <> kind <> ", but line " <> lineNo other <> " uses " <> otherKind)] _ -> [] where alignment l = case lineBody l of@@ -145,8 +148,8 @@ in if null macros || null vars then [] else- let (minority, word) = if length vars <= length macros then (vars, "$RPM_BUILD_ROOT") else (macros, "%{buildroot}")- in [diag "mixed-buildroot" sp ("the spec mostly uses the other spelling, but this is " <> word) | sp <- take 1 minority]+ let (minority, word, usual) = if length vars <= length macros then (vars, "$RPM_BUILD_ROOT", "%{buildroot}") else (macros, "%{buildroot}", "$RPM_BUILD_ROOT")+ in [diag "mixed-buildroot" sp ("this uses " <> word <> ", but the rest of the spec uses " <> usual) | sp <- take 1 minority] buildrootUsage :: LintInput -> [Diagnostic] buildrootUsage li =
test/EvalSpec.hs view
@@ -46,6 +46,11 @@ it "is opaque about shell and Lua" $ do open ["%(date)"] `shouldBe` opaque RunsShell open ["%{lua: print(1)}"] `shouldBe` opaque RunsLua+ it "can't rule out macros defined by Lua it can't read" $ do+ closed ["%{lua: local go = require \"fedora.srpm.go\" go.meta()}", "%{goname}"] `shouldBe` opaque RunsLua+ closed ["%{lua: rpm.define(name .. \" 1\")}", "%{goname}"] `shouldBe` opaque RunsLua+ it "still leaves undefined macros alone after Lua that only defines literal names" $+ closed ["%{lua: rpm.define(\"a 1\")}", "%{nope}"] `shouldBe` known "%{nope}" it "stops runaway recursion" $ open ["%define a %{a}", "%{a}"] `shouldBe` opaque DepthLimit describe "parametric macros" $ do
test/LintSpec.hs view
@@ -77,6 +77,7 @@ fixes "summary-ended-with-dot" "Summary: A thing.\n" "Summary: A thing\n" catches "make-check-outside-check-section" (withBase ["%build", "make check"]) catches "mixed-tabs-spaces" "Name:\tx\nVersion: 1\n"+ catches "mixed-tabs-spaces" "Name:\t x\n" catches "terra-packager" "Name: x\n" catches "terra-dist-release" "Release: 1\n" fixes "terra-dist-release" "Release: 1\n" "Release: 1%{?dist}\n"