Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cabal-install/src/Distribution/Client/DistDirLayout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Distribution.Client.DistDirLayout
DistDirLayout (..)
, DistDirParams (..)
, defaultDistDirLayout
, distProjectFileMain

-- * 'ProjectRoot'
, ProjectRoot (..)
Expand Down Expand Up @@ -316,3 +317,8 @@ mkCabalDirLayout mstoreDir mlogDir = do
cabalLogsDirectory <-
maybe defaultLogsDir pure mlogDir
pure $ CabalDirLayout{..}

-- | Given the 'DistDirLayout''s distProjectFile function, returns the
-- main project file (i.e. cabal.project).
distProjectFileMain :: (String -> FilePath) -> FilePath
distProjectFileMain f = f ""
9 changes: 9 additions & 0 deletions cabal-install/src/Distribution/Client/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ data CabalInstallException
| LegacyAndParsecParseResultsDiffer FilePath String String
| CabalFileParseFailure CabalFileParseError
| ProjectConfigParseFailure ProjectConfigParseError
| ProjectConfigNoPackages FilePath
deriving (Show)

exceptionCodeCabalInstall :: CabalInstallException -> Int
Expand Down Expand Up @@ -348,6 +349,7 @@ exceptionCodeCabalInstall e = case e of
LegacyAndParsecParseResultsDiffer{} -> 7165
CabalFileParseFailure{} -> 7166
ProjectConfigParseFailure{} -> 7167
ProjectConfigNoPackages{} -> 7168

exceptionMessageCabalInstall :: CabalInstallException -> String
exceptionMessageCabalInstall e = case e of
Expand Down Expand Up @@ -885,6 +887,13 @@ exceptionMessageCabalInstall e = case e of
renderCabalFileParseError cbfError
ProjectConfigParseFailure pcfError ->
renderProjectConfigParseError pcfError
ProjectConfigNoPackages configPath ->
concat
[ "The project config '"
, configPath
, "' requires at least one of the fields 'packages' "
, "or 'optional-packages', but neither was specified."
]

instance Exception (VerboseException CabalInstallException) where
displayException :: VerboseException CabalInstallException -> [Char]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentComma
projectConfig

-- https://github.com/haskell/cabal/issues/6013
-- https://github.com/haskell/cabal/issues/7401
let projPath = distProjectFileMain (distProjectFile distDirLayout)
when (null (projectPackages projectConfig) && null (projectPackagesOptional projectConfig)) $
warn verbosity "There are no packages or optional-packages in the project"
dieWithException verbosity (ProjectConfigNoPackages projPath)

return
ProjectBaseContext
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ rebuildProjectConfig
configPath <- getConfigFilePath verbosity projectConfigConfigFile
return
( configPath
, distProjectFile ""
, distProjectFileMain distProjectFile
, (projectConfigHcFlavor, projectConfigHcPath, projectConfigHcPkg)
, projectConfigProjectFileParser
, progsearchpath
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/tests/fixtures/configure/cabal.project
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ignore-project: False
optimization: 2

packages: .
17 changes: 17 additions & 0 deletions cabal-install/tests/fixtures/configure/dummy.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cabal-version: 3.0

-- Required by ./cabal.project, due to cabal.project requiring a valid
-- packages or optional-packages field.

name: main
version: 0.1
build-type: Simple
category: Test
maintainer: Dummy
synopsis: Dummy
description: Dummy
license: BSD-3-Clause

library
build-depends: base
default-language: Haskell2010
11 changes: 11 additions & 0 deletions cabal-testsuite/PackageTests/ProjectPackages/Empty/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# cabal v2-build
Error: [Cabal-7136]
There is no <pkgname>.cabal package file or cabal.project file. To build packages locally you need at minimum a <pkgname>.cabal file. You can use 'cabal init' to create one.

For non-trivial projects you will also want a cabal.project file in the root directory of your project. This file lists the packages in your project and all other build configuration. See the Cabal user guide for full details.

# cabal v2-build
Error: [Cabal-7136]
There is no <pkgname>.cabal package file or cabal.project file. To build packages locally you need at minimum a <pkgname>.cabal file. You can use 'cabal init' to create one.

For non-trivial projects you will also want a cabal.project file in the root directory of your project. This file lists the packages in your project and all other build configuration. See the Cabal user guide for full details.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
fails $ cabal "v2-build" ["--dry-run"]
fails $ cabal "v2-build" ["--dry-run", "all"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal v2-build
# cabal v2-build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude

main = cabalTest $ do
let expected = "- The package directory '.' does not contain any .cabal file."
r1 <- fails $ cabal' "v2-build" ["--dry-run"]
assertOutputContains expected r1

r2 <- fails $ cabal' "v2-build" ["--dry-run", "all"]
assertOutputContains expected r2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- main-0.1 (lib) (first run)

# cabal v2-build
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- main-0.1 (lib) (first run)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- empty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
cabal "v2-build" ["--dry-run"]
cabal "v2-build" ["--dry-run", "all"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cabal-version: 3.0

name: main
version: 0.1
build-type: Simple
category: Test
maintainer: Joe
synopsis: Test input
description: Test input
license: BSD-3-Clause

library
build-depends: base
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-build
Error: [Cabal-7168]
The project config '<ROOT>/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.

# cabal v2-build
Error: [Cabal-7168]
The project config '<ROOT>/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- empty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
fails $ cabal "v2-build" ["--dry-run"]
fails $ cabal "v2-build" ["--dry-run", "all"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cabal-version: 3.0

name: main
version: 0.1
build-type: Simple
category: Test
maintainer: Joe
synopsis: Test input
description: Test input
license: BSD-3-Clause

library
build-depends: base
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-build
Error: [Cabal-7168]
The project config '<ROOT>/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.

# cabal v2-build
Error: [Cabal-7168]
The project config '<ROOT>/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
fails $ cabal "v2-build" ["--dry-run"]
fails $ cabal "v2-build" ["--dry-run", "all"]
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/ProjectPackages/NoField/main.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cabal-version: 3.0

name: main
version: 0.1
build-type: Simple
category: Test
maintainer: Joe
synopsis: Test input
description: Test input
license: BSD-3-Clause

library
build-depends: base
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-build
Error: [Cabal-7168]
The project config '<ROOT>/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.

# cabal v2-build
Error: [Cabal-7168]
The project config '<ROOT>/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
fails $ cabal "v2-build" ["--dry-run"]
fails $ cabal "v2-build" ["--dry-run", "all"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cabal v2-build
Error: [Cabal-7168]
The project config '<ROOT>/dir/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.

# cabal v2-build
Error: [Cabal-7168]
The project config '<ROOT>/dir/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
fails $ cabal "v2-build" ["--dry-run", "--project-file", "dir/cabal.project"]
fails $ cabal "v2-build" ["--dry-run", "--project-file", "dir/cabal.project", "all"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cabal-version: 3.0

name: main
version: 0.1
build-type: Simple
category: Test
maintainer: Joe
synopsis: Test input
description: Test input
license: BSD-3-Clause

library
build-depends: base
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# cabal v2-build
Configuration is affected by cabal.project at '<GBLTMPDIR>'.
Error: [Cabal-7168]
The project config '<ROOT>/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.

# cabal v2-build
Configuration is affected by cabal.project at '<GBLTMPDIR>'.
Error: [Cabal-7168]
The project config '<ROOT>/cabal.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ withDirectory "./dir" $ do
fails $ cabal "v2-build" ["--dry-run"]
fails $ cabal "v2-build" ["--dry-run", "all"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cabal-version: 3.0

name: main
version: 0.1
build-type: Simple
category: Test
maintainer: Joe
synopsis: Test input
description: Test input
license: BSD-3-Clause

library
build-depends: base
default-language: Haskell2010
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ Please pick a single [package:][ctype:]component (or all) as target for the REPL
- pkg-two
# checking repl command with an 'empty.project' with no packages
# cabal repl
Warning: There are no packages or optional-packages in the project
Error: [Cabal-7076]
There are no packages in 'empty.project'. Please add a package to the project and pick a single [package:][ctype:]component (or all) as target for the REPL command.
Error: [Cabal-7168]
The project config '<ROOT>/empty.project' requires at least one of the fields 'packages' or 'optional-packages', but neither was specified.
# checking repl command with a missing 'missing.project'
# cabal repl
# checking repl command with a missing 'missing.project'
Expand Down
20 changes: 20 additions & 0 deletions changelog.d/pr-11574
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
synopsis: Require cabal.project packages and/or optional-packages field.
packages: cabal-install
prs: #11574
issues: #7401
significance:

description: {

Currently, if a cabal.project file is present and the `packages` and
`optional-packages` fields do not exist, a warning will be issued, and
cabal will fail with a different, potentially misleading error message:

"There is no <pkgname>.cabal package file or cabal.project file..."

This changes it so that the prior warning is now an error, hence will cause
cabal to fail before the misleading error is given. That at least one of
these fields is required is already specified in the docs, hence this is not
a specification change.

}
Loading