Skip to content

Commit 517c2ec

Browse files
committed
support for running weeder
1 parent 5e5b27d commit 517c2ec

File tree

7 files changed

+51
-6
lines changed

7 files changed

+51
-6
lines changed

cabal.haskell-ci

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ benchmarks: True
3636
-- Build haddocks. Accepts booleans or version range.
3737
haddock: True
3838

39+
-- Run weeder. Accepts booleans or version range.
40+
-- Expects 'weeder.toml' to live at the repository root,
41+
-- and the '.hie/' directory to be generated in the repository root.
42+
weeder: True
43+
3944
-- Run cabal check
4045
-- cabal-check: True
4146

src/HaskellCI/Auxiliary.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ data Auxiliary = Auxiliary
4949
, anyJobUsesPreviewGHC :: Bool
5050
, runHaddock :: Bool
5151
, haddockFlags :: String
52+
, runWeeder :: Bool
5253
}
5354

5455
auxiliary :: Config -> Project URI Void Package -> JobVersions -> Auxiliary
@@ -84,6 +85,8 @@ auxiliary Config {..} prj JobVersions {..} = Auxiliary {..}
8485
ComponentsAll -> " --haddock-all"
8586
ComponentsLibs -> ""
8687

88+
runWeeder = not (equivVersionRanges C.noVersion cfgWeeder)
89+
8790
extraCabalProjectFields :: FilePath -> [C.PrettyField ()]
8891
extraCabalProjectFields rootdir = buildList $ do
8992
-- generate package fields for URI packages.

src/HaskellCI/Config/Grammar.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ configGrammar = Config
9090
^^^ metahelp "RANGE" "Haddock step"
9191
<*> optionalFieldDef "haddock-components" (field @"cfgHaddockComponents") defaultConfig
9292
^^^ metahelp "all|libs" "Haddock components"
93+
<*> rangeField "weeder" (field @"cfgWeeder") defaultConfig
94+
^^^ metahelp "RANGE" "Weeder step"
9395
<*> rangeField "no-tests-no-benchmarks" (field @"cfgNoTestsNoBench") defaultConfig
9496
^^^ metahelp "RANGE" "Build without tests and benchmarks"
9597
<*> rangeField "unconstrained" (field @"cfgUnconstrainted") defaultConfig

src/HaskellCI/Config/Initial.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ initialConfig = Config
3737
, cfgBenchmarks = anyVersion
3838
, cfgHaddock = anyVersion
3939
, cfgHaddockComponents = ComponentsAll
40+
, cfgWeeder = noVersion
4041
, cfgNoTestsNoBench = anyVersion
4142
, cfgUnconstrainted = anyVersion
4243
, cfgHeadHackage = defaultHeadHackage

src/HaskellCI/Config/Type.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ data Config = Config
4242
, cfgBenchmarks :: !VersionRange
4343
, cfgHaddock :: !VersionRange
4444
, cfgHaddockComponents :: !Components
45+
, cfgWeeder :: !VersionRange
4546
, cfgNoTestsNoBench :: !VersionRange
4647
, cfgUnconstrainted :: !VersionRange
4748
, cfgHeadHackage :: !VersionRange

src/HaskellCI/GitHub.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,15 @@ makeGitHub _argv config@Config {..} gitconfig prj jobs@JobVersions {..} = do
536536
-- disable-documentation disables docs in deps: https://github.com/haskell/cabal/issues/7462
537537
sh_if range $ "$CABAL v2-haddock --disable-documentation" ++ haddockFlags ++ " $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all"
538538

539+
when runWeeder $
540+
let range = RangeGHC /\ Range cfgWeeder in
541+
let ifCond = ghCompilerVersionArithPredicate allVersions range in
542+
for_ pkgs $ \Pkg{pkgName} -> do
543+
githubUsesIf "weeder" "freckle/weeder-action@v2" ifCond $ buildList $ do
544+
item ("ghc-version", ghWrapExpr "matrix.compilerVersion")
545+
item ("weeder-arguments", "--config $GITHUB_WORKSPACE/source/weeder.toml")
546+
item ("working-directory", ghWrapExpr $ ghEnvContext $ pkgNameDirVariable' pkgName)
547+
539548
-- unconstrained build
540549
unless (equivVersionRanges C.noVersion cfgUnconstrainted) $ githubRun "unconstrained build" $ do
541550
let range = Range cfgUnconstrainted
@@ -855,3 +864,13 @@ parseGitHubRepo t =
855864
-- runners support.
856865
ghcRunsOnVer :: String
857866
ghcRunsOnVer = "ubuntu-20.04"
867+
868+
ghWrapExpr :: String -> String
869+
ghWrapExpr expr = "${{ " ++ expr ++ " }}"
870+
871+
ghEnvContext :: String -> String
872+
ghEnvContext = ("env." ++)
873+
874+
ghCompilerVersionArithPredicate :: Set CompilerVersion -> CompilerRange -> String
875+
ghCompilerVersionArithPredicate = compilerVersionPredicateImpl $
876+
freeToArith $ ExprConfig ghWrapExpr ghEnvContext

src/HaskellCI/ShVersionRange.hs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module HaskellCI.ShVersionRange (
22
compilerVersionPredicate,
33
compilerVersionArithPredicate,
4+
compilerVersionPredicateImpl,
5+
freeToArith,
6+
ExprConfig (..),
47
roundDown,
58
) where
69

@@ -21,11 +24,11 @@ import HaskellCI.Compiler
2124
-- >>> import qualified Distribution.Version as C
2225

2326
compilerVersionPredicate :: Set CompilerVersion -> CompilerRange -> String
24-
compilerVersionPredicate = compilerVersionPredicateImpl (toTest . freeToArith) where
27+
compilerVersionPredicate = compilerVersionPredicateImpl (toTest . shFreeToArith) where
2528
toTest expr = "[ " ++ expr ++ " -ne 0 ]"
2629

2730
compilerVersionArithPredicate :: Set CompilerVersion -> CompilerRange -> String
28-
compilerVersionArithPredicate = compilerVersionPredicateImpl freeToArith
31+
compilerVersionArithPredicate = compilerVersionPredicateImpl shFreeToArith
2932

3033
compilerVersionPredicateImpl
3134
:: (Free String -> String)
@@ -197,14 +200,25 @@ roundDown = go S.empty . S.toList where
197200
-- Arithmetic expression
198201
-------------------------------------------------------------------------------
199202

200-
freeToArith :: Free String -> String
201-
freeToArith z
203+
shWrapExpr :: String -> String
204+
shWrapExpr expr = "$((" ++ expr ++ "))"
205+
206+
shFreeToArith :: Free String -> String
207+
shFreeToArith = freeToArith $ ExprConfig shWrapExpr id
208+
209+
data ExprConfig = ExprConfig {
210+
_exprWrap :: String -> String
211+
, _varWrap :: String -> String
212+
}
213+
214+
freeToArith :: ExprConfig -> Free String -> String
215+
freeToArith (ExprConfig exprWrap varWrap) z
202216
| z == top = "1"
203217
| z == bottom = "0"
204-
| otherwise = "$((" ++ go 0 z ++ "))"
218+
| otherwise = exprWrap $ go 0 z
205219
where
206220
go :: Int -> Free String -> String
207-
go _ (Var x) = x
221+
go _ (Var x) = varWrap x
208222
go _ F.Bottom = "1"
209223
go _ F.Top = "0"
210224

0 commit comments

Comments
 (0)