Skip to content

Commit 0d382b1

Browse files
ffaf1mergify[bot]
authored andcommitted
Reimplement cabal check (#8427)
* Fix Semigroup target instance When two target names are the same, `mappend`ing them should not error but just pick the first name. * Add `desugarBuildToolSimple` * Reimplement cabal check * Reorder test output * Fix autogen modules tests .cabal files * Add a number of tests * Add test for #7423 i.e. Do not warn on -O2 if under off-by-default package configuration flag conditional. * Add a regression for: * Add another -WErrr test This is to make sure we do *not* report it if it is under a user, off-by-default flag. * Add test for non manual user flags. * Add “absolute path in extra-lib-dirs” test * Add if/else test * Add “dircheck on abspath” check * Add Package version internal test * Add PackageVersionsStraddle test * Add changelog for #8427 * Integrate various reviews * Integrate Artem’s review (review) Clarify `combineNames` documentation By explaining the way it operates (working if the two names are equal or one is empty) and renaming the function from `combineName` to `combineNames`. (review) Use guards instead of if/then/else (review) Match inside argument list (review) Replace “white” with “allow” (review) Fix typo in comment (review) Fix typo in Check module documentation (review) Harmonise indentation for `data` decls First field goes in a new line than the data constructor, so we have more space. (review) Rename `Prim` module to `Types` (review) Add checkPackageFilesGPD `checkPackageFiles` — which works on PD — was used to perform IO. We introduce a function that does the same thing but works on GPD (which is more principled). `checkPackageFiles` cannot just be removed, since it is part of the interface of Distribution.PackageDescription.Check. Deprecation can be planned once “new check” is up and running. * Integrate Andreas’ review (review) Add named section to missing upper bound check “miss upper bound” checks will now list target type and name (“On executable 'myexe', these packages miss upper bounds”) for easier fixing by the user. (review) remove `cabal gen-bounds` suggestion Reasonable as `cabal gen-bounds` is stricter than `cabal check`, see #8427 (comment) Once `gen-bounds` behaves in line with `check` we can readd the suggestion. (review) Do not warn on shared bounds When a target which depends on an internal library shares some dependencies with the latter, do not warn on upper bounds. An example is clearer library build-depends: text < 5 ⁝ build-depends: myPackage, ← no warning, internal text, ← no warning, shared bound monadacme ← warning! * Integrate Artem’s review /II (review) Split Check.hs Check.hs has been split in multiple file, each une sub 1000 lines: Check 857 lines Check.Common 147 lines Check.Conditional 204 lines Check.Monad 352 lines Check.Paths 387 lines Check.Target 765 lines Check.Warning 865 lines Migration guide: - Check GPD/PD checks plus work-tree checks. - Check.Common common types and functions that are *not* part of monadic checking setup. - Check.Conditional checks on CondTree and related matter (variables, duplicate modules). - Check.Monad Backbone of the checks, monadic inter- face and related functions. - Check.Paths Checks on files, directories, globs. - Check.Target Checks on realised targets (libraries, executables, benchmarks, testsuites). - Check.Warning Datatypes and strings for warnings and severities. (review) remove useless section header (review) Fix typo (review) Add warnings documentation (list) For each warning, we document constructor/brief description in the manual. This might not be much useful as not but it will come handy when introducing `--ignore=WARN` and similar flags. * (review Andreas) Clarify CheckExplanation comment Whoever modifies `CheckExplanation` data constructors needs to be aware that the documentation in doc/cabal-commands.rst has to be updated too. * Move internal Check modules to `other-modules` No need to expose Distribution.PackageDescription.Check.* to the world. API for checking, for cabal-install and other tools, should be in Distribution.PackageDescription.Check. * Make fourmolu happy Cabal codebase has now a formatter/style standard (see #8950). “Ravioli ravioli, give me the formuoli” * Do not check for OptO in scripts See #8963 for reason and clarification requests. * Remove useless PackageId parameter It is now in the Reader part of CheckM monad. * Do not check PVP on internal targets Internal: testsuite, benchmark. See #8361. * Make hlint happy * Fix #9122 When checking internal version ranges, we need to make sure we are not mistaking a libraries with the same name but from different packages. See #9132. * Fix grammar neither…nor, completing what done in #9162 * Integrate Brandon’s review: grammar * Remove unnecessary `-fvia-C` check Brandon’s review/II. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent cede294 commit 0d382b1

File tree

74 files changed

+4697
-3212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4697
-3212
lines changed

Cabal-syntax/src/Distribution/Types/Benchmark.hs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,12 @@ instance Monoid Benchmark where
4848
instance Semigroup Benchmark where
4949
a <> b =
5050
Benchmark
51-
{ benchmarkName = combine' benchmarkName
51+
{ benchmarkName = combineNames a b benchmarkName "benchmark"
5252
, benchmarkInterface = combine benchmarkInterface
5353
, benchmarkBuildInfo = combine benchmarkBuildInfo
5454
}
5555
where
5656
combine field = field a `mappend` field b
57-
combine' field = case ( unUnqualComponentName $ field a
58-
, unUnqualComponentName $ field b
59-
) of
60-
("", _) -> field b
61-
(_, "") -> field a
62-
(x, y) ->
63-
error $
64-
"Ambiguous values for test field: '"
65-
++ x
66-
++ "' and '"
67-
++ y
68-
++ "'"
6957

7058
emptyBenchmark :: Benchmark
7159
emptyBenchmark = mempty

Cabal-syntax/src/Distribution/Types/Executable.hs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,13 @@ instance Monoid Executable where
4040
instance Semigroup Executable where
4141
a <> b =
4242
Executable
43-
{ exeName = combine' exeName
43+
{ exeName = combineNames a b exeName "executable"
4444
, modulePath = combine modulePath
4545
, exeScope = combine exeScope
4646
, buildInfo = combine buildInfo
4747
}
4848
where
4949
combine field = field a `mappend` field b
50-
combine' field = case ( unUnqualComponentName $ field a
51-
, unUnqualComponentName $ field b
52-
) of
53-
("", _) -> field b
54-
(_, "") -> field a
55-
(x, y) ->
56-
error $
57-
"Ambiguous values for executable field: '"
58-
++ x
59-
++ "' and '"
60-
++ y
61-
++ "'"
6250

6351
emptyExecutable :: Executable
6452
emptyExecutable = mempty

Cabal-syntax/src/Distribution/Types/ForeignLib.hs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ instance NFData ForeignLib where rnf = genericRnf
140140
instance Semigroup ForeignLib where
141141
a <> b =
142142
ForeignLib
143-
{ foreignLibName = combine' foreignLibName
143+
{ foreignLibName = combineNames a b foreignLibName "foreign library"
144144
, foreignLibType = combine foreignLibType
145145
, foreignLibOptions = combine foreignLibOptions
146146
, foreignLibBuildInfo = combine foreignLibBuildInfo
@@ -150,18 +150,6 @@ instance Semigroup ForeignLib where
150150
}
151151
where
152152
combine field = field a `mappend` field b
153-
combine' field = case ( unUnqualComponentName $ field a
154-
, unUnqualComponentName $ field b
155-
) of
156-
("", _) -> field b
157-
(_, "") -> field a
158-
(x, y) ->
159-
error $
160-
"Ambiguous values for executable field: '"
161-
++ x
162-
++ "' and '"
163-
++ y
164-
++ "'"
165153
combine'' field = field b
166154

167155
instance Monoid ForeignLib where

Cabal-syntax/src/Distribution/Types/TestSuite.hs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,13 @@ instance Monoid TestSuite where
5151
instance Semigroup TestSuite where
5252
a <> b =
5353
TestSuite
54-
{ testName = combine' testName
54+
{ testName = combineNames a b testName "test"
5555
, testInterface = combine testInterface
5656
, testBuildInfo = combine testBuildInfo
5757
, testCodeGenerators = combine testCodeGenerators
5858
}
5959
where
6060
combine field = field a `mappend` field b
61-
combine' field = case ( unUnqualComponentName $ field a
62-
, unUnqualComponentName $ field b
63-
) of
64-
("", _) -> field b
65-
(_, "") -> field a
66-
(x, y) ->
67-
error $
68-
"Ambiguous values for test field: '"
69-
++ x
70-
++ "' and '"
71-
++ y
72-
++ "'"
7361

7462
emptyTestSuite :: TestSuite
7563
emptyTestSuite = mempty

Cabal-syntax/src/Distribution/Types/UnqualComponentName.hs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ module Distribution.Types.UnqualComponentName
99
, mkUnqualComponentName
1010
, packageNameToUnqualComponentName
1111
, unqualComponentNameToPackageName
12+
, combineNames
1213
) where
1314

1415
import Distribution.Compat.Prelude
1516
import Distribution.Utils.ShortText
16-
import Prelude ()
17+
import Prelude as P (null)
1718

1819
import Distribution.Parsec
1920
import Distribution.Pretty
@@ -105,3 +106,33 @@ packageNameToUnqualComponentName = UnqualComponentName . unPackageNameST
105106
-- @since 2.0.0.2
106107
unqualComponentNameToPackageName :: UnqualComponentName -> PackageName
107108
unqualComponentNameToPackageName = mkPackageNameST . unUnqualComponentNameST
109+
110+
-- | Combine names in targets if one name is empty or both names are equal
111+
-- (partial function).
112+
-- Useful in 'Semigroup' and similar instances.
113+
combineNames
114+
:: a
115+
-> a
116+
-> (a -> UnqualComponentName)
117+
-> String
118+
-> UnqualComponentName
119+
combineNames a b tacc tt
120+
-- One empty or the same.
121+
| P.null unb
122+
|| una == unb =
123+
na
124+
| P.null una = nb
125+
-- Both non-empty, different.
126+
| otherwise =
127+
error $
128+
"Ambiguous values for "
129+
++ tt
130+
++ " field: '"
131+
++ una
132+
++ "' and '"
133+
++ unb
134+
++ "'"
135+
where
136+
(na, nb) = (tacc a, tacc b)
137+
una = unUnqualComponentName na
138+
unb = unUnqualComponentName nb

Cabal-tests/tests/CheckTests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ checkTest fp = cabalGoldenTest fp correct $ do
7171
-- Note: parser warnings are reported by `cabal check`, but not by
7272
-- D.PD.Check functionality.
7373
unlines (map (showPWarning fp) ws) ++
74-
unlines (map show (checkPackage gpd Nothing))
74+
unlines (map show (checkPackage gpd))
7575
Left (_, errs) -> unlines $ map (("ERROR: " ++) . showPError fp) $ NE.toList errs
7676
where
7777
input = "tests" </> "ParserTests" </> "regressions" </> fp

Cabal-tests/tests/HackageTests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ parseCheckTest fpath bs = do
196196
Parsec.parseGenericPackageDescription bs
197197
case parsec of
198198
Right gpd -> do
199-
let checks = checkPackage gpd Nothing
199+
let checks = checkPackage gpd
200200
let w [] = 0
201201
w _ = 1
202202

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
These packages miss upper bounds:
1+
On library, these packages miss upper bounds:
2+
- somelib
23
- alphalib
34
- betalib
45
- deltalib
5-
- somelib
6-
Please add them, using `cabal gen-bounds` for suggestions. For more information see: https://pvp.haskell.org/
6+
Please add them. There is more information at https://pvp.haskell.org/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
In the 'extra-source-files' field: invalid file glob 'foo/blah-*.hs'. Wildcards '*' may only totally replace the file's base name, not only parts of it.
21
In the 'extra-source-files' field: invalid file glob 'foo/*/bar'. A wildcard '**' is only allowed as the final parent directory. Stars must not otherwise appear in the parent directories.
2+
In the 'extra-source-files' field: invalid file glob 'foo/blah-*.hs'. Wildcards '*' may only totally replace the file's base name, not only parts of it.

Cabal-tests/tests/ParserTests/regressions/decreasing-indentation.cabal

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Flag UseBinary
2424
Description: Use the binary package for serializing keys.
2525

2626
Library
27-
build-depends: base >= 3
27+
build-depends: base < 3
2828
if flag(UseBinary)
2929
build-depends: binary <10
3030
CPP-Options: -DUSE_BINARY
@@ -34,7 +34,7 @@ Library
3434
exposed-modules: Codec.Crypto.RSA
3535

3636
Executable test_rsa
37-
build-depends: base >= 3
37+
build-depends: base < 3
3838
CPP-Options: -DRSA_TEST
3939
Main-Is: Test.hs
4040
Other-Modules: Codec.Crypto.RSA
@@ -52,7 +52,7 @@ Executable warnings
5252

5353
-- Increasing indentation is also possible if we use braces to delimit field contents.
5454
Executable warnings2
55-
build-depends: { base <5 }
55+
build-depends: { base < 5 }
5656
main-is: { warnings2.hs }
5757
Other-Modules: FooBar
5858

@@ -62,9 +62,9 @@ flag splitBase
6262

6363
Executable warnings3
6464
if flag(splitBase)
65-
build-depends: base >= 3
65+
build-depends: base < 3
6666
else
67-
build-depends: base < 3
67+
build-depends: base < 5
6868

6969
Main-Is: warnings3.hs
7070
Other-Modules:

0 commit comments

Comments
 (0)