-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make a trailing colon for stanzas a parse failure
Here's a mistake I make semi-regularly: source-repository-package: type: git location: https://github.com/parsonsmatt/foundation tag: 688c32ccd9a951bc96dd09423a6e6684f091d510 subdir: basement subdir: foundation Cabal treats this as a warning, so it prints: Warning: cabal.project: Unrecognized field 'source-repository-package' on line 52 This is fine (if you already know the mistake you've made, at least!), but it's very easy to miss amidst lots of output. I often re-run `cabal` when I see a ton of output to attempt to get a smaller error message. (Usually it works and I get an error message that's got less "compiling module such and such" noise in it.) However, re-running `cabal` will discard this warning entirely! Let's make it a hard error instead. This is a backwards-compatibility break.
- Loading branch information
Showing
8 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
cabal-testsuite/PackageTests/ProjectConfig/FieldStanzaConfusion/cabal.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# cabal build | ||
Error: [Cabal-7090] | ||
Error parsing project file <ROOT>/cabal.project:4: | ||
'source-repository-package' is a stanza, not a field. Remove the trailing ':' to parse a stanza. |
6 changes: 6 additions & 0 deletions
6
cabal-testsuite/PackageTests/ProjectConfig/FieldStanzaConfusion/cabal.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
packages: . | ||
|
||
-- This is an error; a trailing `:` is syntax for a field, not a stanza! | ||
source-repository-package: | ||
type: git | ||
location: https://github.com/haskell-hvr/Only |
6 changes: 6 additions & 0 deletions
6
cabal-testsuite/PackageTests/ProjectConfig/FieldStanzaConfusion/cabal.test.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Test.Cabal.Prelude | ||
|
||
main = cabalTest $ do | ||
result <- fails $ cabal' "build" [] | ||
assertOutputContains "Error parsing project file" result | ||
assertOutputContains "'source-repository-package' is a stanza, not a field." result |
4 changes: 4 additions & 0 deletions
4
cabal-testsuite/PackageTests/ProjectConfig/FieldStanzaConfusion/src/MyLib.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module MyLib (someFunc) where | ||
|
||
someFunc :: IO () | ||
someFunc = putStrLn "someFunc" |
13 changes: 13 additions & 0 deletions
13
cabal-testsuite/PackageTests/ProjectConfig/FieldStanzaConfusion/test.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cabal-version: 3.0 | ||
name: test | ||
version: 0.1.0.0 | ||
license: NONE | ||
author: [email protected] | ||
maintainer: Rebecca Turner | ||
build-type: Simple | ||
|
||
library | ||
exposed-modules: MyLib | ||
build-depends: base | ||
hs-source-dirs: src | ||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
synopsis: "A trailing colon after a stanza name in `cabal.project` is now an error" | ||
packages: [cabal-install] | ||
prs: 10525 | ||
--- | ||
|
||
It is now a hard error to use a trailing colon after a stanza name in | ||
`cabal.project` or `*.cabal` files: | ||
|
||
``` | ||
packages: . | ||
|
||
source-repository-package: | ||
type: git | ||
location: https://github.com/haskell/cabal | ||
tag: f34aba976a60940295f41b6649674e9568893894 | ||
``` | ||
|
||
``` | ||
$ cabal build | ||
Error parsing project file cabal.project:3: | ||
'source-repository-package' is a stanza, not a field. Remove the trailing ':' to parse a stanza. | ||
``` | ||
|
||
Previously, the warning message was easily ignored and somewhat misleading, as | ||
the difference between a stanza and a field is not immediately obvious to | ||
Haskellers used to config languages like JSON and YAML (which don't distinguish | ||
between fields which have string or list values and stanzas which have nested | ||
fields): | ||
|
||
``` | ||
Warning: cabal.project: Unrecognized field | ||
'source-repository-package' on line 3 | ||
``` |