Skip to content

Commit 86a8e2c

Browse files
mergify[bot]9999yearsgeekosaur
authored
Backport #10320: Convert validate.sh to a Haskell script (#10490)
* Convert `validate.sh` to `cabal-validate` Closes #10317. A Haskell script will be easier to maintain and expand than the existing Bash script. This also adds a `--pattern PATTERN` option which lets you filter tests across all test suites. (cherry picked from commit 582a5c7) # Conflicts: # validate.sh * Split `cabal-validate` into modules This disentangles the utility boilerplate from the validation logic, making the `Main.hs` module much easier to read and modify. (cherry picked from commit 43a3975) * cabal-validate: Add Haddock documentation + README (cherry picked from commit e257591) * Remove `ansi-terminal` dependency (cherry picked from commit 96d6ad5) * Use `unlines` in `printConfig` (cherry picked from commit 9f5d90f) * optsParser -> rawOptsParser (cherry picked from commit a10a2a3) * withTiming: take `startTime` explicitly (cherry picked from commit 37cfe85) * Add `cabal-validate` to `format` job (cherry picked from commit 92613f0) * Build test suites explicitly This seems to fix an error where `long-tests` isn't built? (cherry picked from commit d208282) * fixup! Remove `ansi-terminal` dependency (cherry picked from commit bae200a) * fixup! Build test suites explicitly (cherry picked from commit 1900d5e) * fixup! fixup! Build test suites explicitly (cherry picked from commit 30f0faa) * fix pointless validate conflict since it's going away * 3.12 doesn't have Cabal-hooks --------- Co-authored-by: Rebecca Turner <[email protected]> Co-authored-by: brandon s allbery kf8nh <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent f482cd0 commit 86a8e2c

File tree

13 files changed

+1361
-536
lines changed

13 files changed

+1361
-536
lines changed

.github/workflows/format.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ jobs:
1717
Cabal/**/*.hs
1818
Cabal-syntax/**/*.hs
1919
cabal-install/**/*.hs
20+
cabal-validate/**/*.hs

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ init: ## Set up git hooks and ignored revisions
3232

3333
.PHONY: style
3434
style: ## Run the code styler
35-
@fourmolu -q -i Cabal Cabal-syntax cabal-install
35+
@fourmolu -q -i Cabal Cabal-syntax cabal-install cabal-validate
3636

3737
.PHONY: style-modified
3838
style-modified: ## Run the code styler on modified files
39-
@git ls-files --modified Cabal Cabal-syntax cabal-install \
39+
@git ls-files --modified Cabal Cabal-syntax cabal-install cabal-validate \
4040
| grep '.hs$$' | xargs -P $(PROCS) -I {} fourmolu -q -i {}
4141

4242
.PHONY: style-commit
4343
style-commit: ## Run the code styler on the previous commit
44-
@git diff --name-only HEAD $(COMMIT) Cabal Cabal-syntax cabal-install \
44+
@git diff --name-only HEAD $(COMMIT) Cabal Cabal-syntax cabal-install cabal-validate \
4545
| grep '.hs$$' | xargs -P $(PROCS) -I {} fourmolu -q -i {}
4646

4747
.PHONY: whitespace

cabal-validate/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# cabal-validate
2+
3+
`cabal-validate` is a script that builds and tests `Cabal` and `cabal-install`.
4+
`cabal-validate` can be run with `validate.sh` in the repository root;
5+
arguments passed to `validate.sh` will be forwarded to `cabal-validate`.
6+
7+
Notable arguments include:
8+
9+
- `-v`/`--verbose` to display build and test output in real-time, instead of
10+
only if commands fail.
11+
- `-s`/`--step` to run a specific step (e.g. `-s build -s lib-tests` will only
12+
run the `build` and `lib-tests` steps).
13+
- `-p`/`--pattern` to filter tests by a pattern.
14+
15+
## Hacking on cabal-validate
16+
17+
Overview of important modules:
18+
19+
- `Main.hs` encodes all the commands that are run for each step.
20+
- `Cli.hs` parses the CLI arguments and resolves default values from the
21+
environment, like determining which steps are run by default or the `--jobs`
22+
argument to pass to test suites.
23+
- `Step.hs` lists the available steps.

cabal-validate/cabal-validate.cabal

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cabal-version: 3.0
2+
name: cabal-validate
3+
version: 1.0.0
4+
copyright: 2024-2024, Cabal Development Team (see AUTHORS file)
5+
license: BSD-3-Clause
6+
author: Cabal Development Team <[email protected]>
7+
synopsis: An internal tool for building and testing the Cabal package manager
8+
build-type: Simple
9+
10+
common common
11+
ghc-options: -Wall
12+
13+
if impl(ghc <9.6)
14+
-- Pattern exhaustiveness checker is not as good, misses a case.
15+
ghc-options: -Wno-incomplete-patterns
16+
17+
default-language: Haskell2010
18+
default-extensions:
19+
OverloadedStrings
20+
, TypeApplications
21+
22+
executable cabal-validate
23+
import: common
24+
ghc-options: -O -threaded -rtsopts -with-rtsopts=-N
25+
26+
main-is: Main.hs
27+
hs-source-dirs: src
28+
29+
other-modules:
30+
, ANSI
31+
, Cli
32+
, ClockUtil
33+
, OutputUtil
34+
, ProcessUtil
35+
, Step
36+
37+
build-depends:
38+
, base >=4 && <5
39+
, bytestring >=0.11 && <1
40+
, containers >=0.6 && <1
41+
, directory >=1.0 && <2
42+
, filepath >=1 && <2
43+
, optparse-applicative >=0.18 && <1
44+
, terminal-size >=0.3 && <1
45+
, text >=2 && <3
46+
, time >=1 && <2
47+
, typed-process >=0.2 && <1

cabal-validate/src/ANSI.hs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
-- | ANSI escape sequences.
2+
--
3+
-- This is a stripped-down version of the parts of the @ansi-terminal@ package
4+
-- we use.
5+
--
6+
-- See: <https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797>
7+
module ANSI
8+
( SGR (..)
9+
, setSGR
10+
) where
11+
12+
-- | Render a single numeric SGR sequence.
13+
rawSGR :: Int -> String
14+
rawSGR code = "\x1b[" <> show code <> "m"
15+
16+
-- | Render a series of `SGR` escape sequences.
17+
setSGR :: [SGR] -> String
18+
setSGR = concat . map renderSGR
19+
20+
-- | All of the SGR sequences we want to use.
21+
data SGR
22+
= Reset
23+
| Bold
24+
| Dim
25+
| Italic
26+
| Underline
27+
| Black
28+
| Red
29+
| Green
30+
| Yellow
31+
| Blue
32+
| Magenta
33+
| Cyan
34+
| White
35+
| Default
36+
| OnBlack
37+
| OnRed
38+
| OnGreen
39+
| OnYellow
40+
| OnBlue
41+
| OnMagenta
42+
| OnCyan
43+
| OnWhite
44+
| OnDefault
45+
| BrightBlack
46+
| BrightRed
47+
| BrightGreen
48+
| BrightYellow
49+
| BrightBlue
50+
| BrightMagenta
51+
| BrightCyan
52+
| BrightWhite
53+
| OnBrightBlack
54+
| OnBrightRed
55+
| OnBrightGreen
56+
| OnBrightYellow
57+
| OnBrightBlue
58+
| OnBrightMagenta
59+
| OnBrightCyan
60+
| OnBrightWhite
61+
deriving (Show)
62+
63+
-- Render a single `SGR` sequence.
64+
renderSGR :: SGR -> String
65+
renderSGR code =
66+
case code of
67+
Reset -> rawSGR 0
68+
Bold -> rawSGR 1
69+
Dim -> rawSGR 2
70+
Italic -> rawSGR 3
71+
Underline -> rawSGR 4
72+
Black -> rawSGR 30
73+
Red -> rawSGR 31
74+
Green -> rawSGR 32
75+
Yellow -> rawSGR 33
76+
Blue -> rawSGR 34
77+
Magenta -> rawSGR 35
78+
Cyan -> rawSGR 36
79+
White -> rawSGR 37
80+
Default -> rawSGR 39
81+
OnBlack -> rawSGR 40
82+
OnRed -> rawSGR 41
83+
OnGreen -> rawSGR 42
84+
OnYellow -> rawSGR 43
85+
OnBlue -> rawSGR 44
86+
OnMagenta -> rawSGR 45
87+
OnCyan -> rawSGR 46
88+
OnWhite -> rawSGR 47
89+
OnDefault -> rawSGR 49
90+
BrightBlack -> rawSGR 90
91+
BrightRed -> rawSGR 91
92+
BrightGreen -> rawSGR 92
93+
BrightYellow -> rawSGR 93
94+
BrightBlue -> rawSGR 94
95+
BrightMagenta -> rawSGR 95
96+
BrightCyan -> rawSGR 96
97+
BrightWhite -> rawSGR 97
98+
OnBrightBlack -> rawSGR 100
99+
OnBrightRed -> rawSGR 101
100+
OnBrightGreen -> rawSGR 102
101+
OnBrightYellow -> rawSGR 103
102+
OnBrightBlue -> rawSGR 104
103+
OnBrightMagenta -> rawSGR 105
104+
OnBrightCyan -> rawSGR 106
105+
OnBrightWhite -> rawSGR 107

0 commit comments

Comments
 (0)