Skip to content

Commit 7e5dd02

Browse files
authored
Merge pull request #11574 from tbidne/tbidne/7401
Require cabal.project packages and/or optional-packages field
2 parents 120dda6 + 4f517b4 commit 7e5dd02

38 files changed

Lines changed: 243 additions & 5 deletions

File tree

cabal-install/src/Distribution/Client/DistDirLayout.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Distribution.Client.DistDirLayout
99
DistDirLayout (..)
1010
, DistDirParams (..)
1111
, defaultDistDirLayout
12+
, distProjectFileMain
1213

1314
-- * 'ProjectRoot'
1415
, ProjectRoot (..)
@@ -316,3 +317,8 @@ mkCabalDirLayout mstoreDir mlogDir = do
316317
cabalLogsDirectory <-
317318
maybe defaultLogsDir pure mlogDir
318319
pure $ CabalDirLayout{..}
320+
321+
-- | Given the 'DistDirLayout''s distProjectFile function, returns the
322+
-- main project file (i.e. cabal.project).
323+
distProjectFileMain :: (String -> FilePath) -> FilePath
324+
distProjectFileMain f = f ""

cabal-install/src/Distribution/Client/Errors.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ data CabalInstallException
192192
| LegacyAndParsecParseResultsDiffer FilePath String String
193193
| CabalFileParseFailure CabalFileParseError
194194
| ProjectConfigParseFailure ProjectConfigParseError
195+
| ProjectConfigNoPackages FilePath
195196
deriving (Show)
196197

197198
exceptionCodeCabalInstall :: CabalInstallException -> Int
@@ -348,6 +349,7 @@ exceptionCodeCabalInstall e = case e of
348349
LegacyAndParsecParseResultsDiffer{} -> 7165
349350
CabalFileParseFailure{} -> 7166
350351
ProjectConfigParseFailure{} -> 7167
352+
ProjectConfigNoPackages{} -> 7168
351353

352354
exceptionMessageCabalInstall :: CabalInstallException -> String
353355
exceptionMessageCabalInstall e = case e of
@@ -885,6 +887,13 @@ exceptionMessageCabalInstall e = case e of
885887
renderCabalFileParseError cbfError
886888
ProjectConfigParseFailure pcfError ->
887889
renderProjectConfigParseError pcfError
890+
ProjectConfigNoPackages configPath ->
891+
concat
892+
[ "The project config '"
893+
, configPath
894+
, "' requires at least one of the fields 'packages' "
895+
, "or 'optional-packages', but neither was specified."
896+
]
888897

889898
instance Exception (VerboseException CabalInstallException) where
890899
displayException :: VerboseException CabalInstallException -> [Char]

cabal-install/src/Distribution/Client/ProjectOrchestration.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,10 @@ establishProjectBaseContextWithRoot verbosity cliConfig projectRoot currentComma
307307
projectConfig
308308

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

313315
return
314316
ProjectBaseContext

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ rebuildProjectConfig
379379
configPath <- getConfigFilePath verbosity projectConfigConfigFile
380380
return
381381
( configPath
382-
, distProjectFile ""
382+
, distProjectFileMain distProjectFile
383383
, (projectConfigHcFlavor, projectConfigHcPath, projectConfigHcPkg)
384384
, projectConfigProjectFileParser
385385
, progsearchpath
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
ignore-project: False
22
optimization: 2
3+
4+
packages: .
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cabal-version: 3.0
2+
3+
-- Required by ./cabal.project, due to cabal.project requiring a valid
4+
-- packages or optional-packages field.
5+
6+
name: main
7+
version: 0.1
8+
build-type: Simple
9+
category: Test
10+
maintainer: Dummy
11+
synopsis: Dummy
12+
description: Dummy
13+
license: BSD-3-Clause
14+
15+
library
16+
build-depends: base
17+
default-language: Haskell2010
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# cabal v2-build
2+
Error: [Cabal-7136]
3+
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.
4+
5+
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.
6+
7+
# cabal v2-build
8+
Error: [Cabal-7136]
9+
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.
10+
11+
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.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
fails $ cabal "v2-build" ["--dry-run"]
5+
fails $ cabal "v2-build" ["--dry-run", "all"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# cabal v2-build
2+
# cabal v2-build
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .

0 commit comments

Comments
 (0)