@@ -33,52 +33,49 @@ module Distribution.PackageDescription.Check (
33
33
checkPackageFileNames ,
34
34
) where
35
35
36
- import Prelude ()
37
36
import Distribution.Compat.Prelude
37
+ import Prelude ()
38
38
39
- import Distribution.PackageDescription
40
- import Distribution.PackageDescription.Configuration
41
- import qualified Distribution.Compat.DList as DList
39
+ import Control.Monad ( mapM )
40
+ import Data.List ( group )
41
+ import Distribution.Compat.Lens
42
42
import Distribution.Compiler
43
- import Distribution.System
44
43
import Distribution.License
45
- import Distribution.Simple.BuildPaths (autogenPathsModuleName )
44
+ import Distribution.Package
45
+ import Distribution.PackageDescription
46
+ import Distribution.PackageDescription.Configuration
47
+ import Distribution.Pretty (prettyShow )
48
+ import Distribution.Simple.BuildPaths (autogenPathsModuleName )
46
49
import Distribution.Simple.BuildToolDepends
47
50
import Distribution.Simple.CCompiler
51
+ import Distribution.Simple.Utils hiding (findPackageDesc , notice )
52
+ import Distribution.System
53
+ import Distribution.Text
48
54
import Distribution.Types.ComponentRequestedSpec
49
55
import Distribution.Types.CondTree
50
- import Distribution.Types.Dependency
51
- import Distribution.Types.ExeDependency
52
- import Distribution.Types.PackageName
53
56
import Distribution.Types.ExecutableScope
57
+ import Distribution.Types.ExeDependency
54
58
import Distribution.Types.UnqualComponentName
55
- import Distribution.Simple. Utils hiding ( findPackageDesc , notice )
59
+ import Distribution.Utils.Generic ( isAscii )
56
60
import Distribution.Version
57
- import Distribution.Package
58
- import Distribution.Text
59
- import Distribution.Utils.Generic (isAscii )
60
61
import Language.Haskell.Extension
62
+ import System.FilePath
63
+ (splitDirectories , splitExtension , splitPath , takeExtension , takeFileName , (<.>) , (</>) )
61
64
62
- import Control.Monad (mapM )
63
- import qualified Data.ByteString.Lazy as BS
64
- import Data.List (group )
65
- import qualified System.Directory as System
66
- ( doesFileExist , doesDirectoryExist )
67
- import qualified Data.Map as Map
65
+ import qualified Data.ByteString.Lazy as BS
66
+ import qualified Data.Map as Map
67
+ import qualified Distribution.Compat.DList as DList
68
+ import qualified Distribution.SPDX as SPDX
69
+ import qualified System.Directory as System
68
70
69
- import qualified System.Directory (getDirectoryContents )
70
- import System.FilePath
71
- ( (</>) , (<.>) , takeExtension , takeFileName , splitDirectories
72
- , splitPath , splitExtension )
73
- import System.FilePath.Windows as FilePath.Windows
74
- ( isValid )
71
+ import qualified System.Directory (getDirectoryContents )
72
+ import qualified System.FilePath.Windows as FilePath.Windows (isValid )
75
73
76
74
import qualified Data.Set as Set
77
75
78
- import Distribution.Compat.Lens
79
- import qualified Distribution.Types.BuildInfo.Lens as L
80
- import qualified Distribution.Types.PackageDescription.Lens as L
76
+ import qualified Distribution.Types.BuildInfo.Lens as L
81
77
import qualified Distribution.Types.GenericPackageDescription.Lens as L
78
+ import qualified Distribution.Types.PackageDescription.Lens as L
82
79
83
80
-- | Results of some kind of failed package check.
84
81
--
@@ -649,41 +646,59 @@ checkFields pkg =
649
646
650
647
651
648
checkLicense :: PackageDescription -> [PackageCheck ]
652
- checkLicense pkg =
653
- catMaybes [
649
+ checkLicense pkg = case licenseRaw pkg of
650
+ Right l -> checkOldLicense pkg l
651
+ Left l -> checkNewLicense pkg l
652
+
653
+ checkNewLicense :: PackageDescription -> SPDX. License -> [PackageCheck ]
654
+ checkNewLicense _pkg lic = catMaybes
655
+ [ check (lic == SPDX. NONE ) $
656
+ PackageDistInexcusable
657
+ " The 'license' field is missing or is NONE."
658
+ ]
654
659
655
- check (license pkg == UnspecifiedLicense ) $
660
+ checkOldLicense :: PackageDescription -> License -> [PackageCheck ]
661
+ checkOldLicense pkg lic = catMaybes
662
+ [ check (lic == UnspecifiedLicense ) $
656
663
PackageDistInexcusable
657
664
" The 'license' field is missing."
658
665
659
- , check (license pkg == AllRightsReserved ) $
666
+ , check (lic == AllRightsReserved ) $
660
667
PackageDistSuspicious
661
668
" The 'license' is AllRightsReserved. Is that really what you want?"
662
- , case license pkg of
669
+
670
+ , checkVersion [1 ,4 ] (lic `notElem` compatLicenses) $
671
+ PackageDistInexcusable $
672
+ " Unfortunately the license " ++ quote (prettyShow (license pkg))
673
+ ++ " messes up the parser in earlier Cabal versions so you need to "
674
+ ++ " specify 'cabal-version: >= 1.4'. Alternatively if you require "
675
+ ++ " compatibility with earlier Cabal versions then use 'OtherLicense'."
676
+
677
+ , case lic of
663
678
UnknownLicense l -> Just $
664
679
PackageBuildWarning $
665
680
quote (" license: " ++ l) ++ " is not a recognised license. The "
666
681
++ " known licenses are: "
667
682
++ commaSep (map display knownLicenses)
668
683
_ -> Nothing
669
684
670
- , check (license pkg == BSD4 ) $
685
+ , check (lic == BSD4 ) $
671
686
PackageDistSuspicious $
672
687
" Using 'license: BSD4' is almost always a misunderstanding. 'BSD4' "
673
688
++ " refers to the old 4-clause BSD license with the advertising "
674
689
++ " clause. 'BSD3' refers the new 3-clause BSD license."
675
690
676
- , case unknownLicenseVersion (license pkg ) of
691
+ , case unknownLicenseVersion (lic ) of
677
692
Just knownVersions -> Just $
678
693
PackageDistSuspicious $
679
- " 'license: " ++ display (license pkg ) ++ " ' is not a known "
694
+ " 'license: " ++ display (lic ) ++ " ' is not a known "
680
695
++ " version of that license. The known versions are "
681
696
++ commaSep (map display knownVersions)
682
697
++ " . If this is not a mistake and you think it should be a known "
683
698
++ " version then please file a ticket."
684
699
_ -> Nothing
685
700
686
- , check (license pkg `notElem` [ AllRightsReserved
701
+ , check (lic `notElem` [ AllRightsReserved
687
702
, UnspecifiedLicense , PublicDomain ]
688
703
-- AllRightsReserved and PublicDomain are not strictly
689
704
-- licenses so don't need license files.
@@ -705,6 +720,15 @@ checkLicense pkg =
705
720
where knownVersions = [ v' | Apache (Just v') <- knownLicenses ]
706
721
unknownLicenseVersion _ = Nothing
707
722
723
+ checkVersion :: [Int ] -> Bool -> PackageCheck -> Maybe PackageCheck
724
+ checkVersion ver cond pc
725
+ | specVersion pkg >= mkVersion ver = Nothing
726
+ | otherwise = check cond pc
727
+
728
+ compatLicenses = [ GPL Nothing , LGPL Nothing , AGPL Nothing , BSD3 , BSD4
729
+ , PublicDomain , AllRightsReserved
730
+ , UnspecifiedLicense , OtherLicense ]
731
+
708
732
checkSourceRepos :: PackageDescription -> [PackageCheck ]
709
733
checkSourceRepos pkg =
710
734
catMaybes $ concat [[
@@ -1228,7 +1252,7 @@ checkCabalVersion pkg =
1228
1252
PackageDistInexcusable $
1229
1253
" The use of 'virtual-modules' requires the package "
1230
1254
++ " to specify at least 'cabal-version: >= 2.1'."
1231
-
1255
+
1232
1256
-- check use of "tested-with: GHC (>= 1.0 && < 1.4) || >=1.8 " syntax
1233
1257
, checkVersion [1 ,8 ] (not (null testedWithVersionRangeExpressions)) $
1234
1258
PackageDistInexcusable $
@@ -1275,14 +1299,6 @@ checkCabalVersion pkg =
1275
1299
++ " Unfortunately it messes up the parser in earlier Cabal versions "
1276
1300
++ " so you need to specify 'cabal-version: >= 1.6'."
1277
1301
1278
- -- check for new licenses
1279
- , checkVersion [1 ,4 ] (license pkg `notElem` compatLicenses) $
1280
- PackageDistInexcusable $
1281
- " Unfortunately the license " ++ quote (display (license pkg))
1282
- ++ " messes up the parser in earlier Cabal versions so you need to "
1283
- ++ " specify 'cabal-version: >= 1.4'. Alternatively if you require "
1284
- ++ " compatibility with earlier Cabal versions then use 'OtherLicense'."
1285
-
1286
1302
-- check for new language extensions
1287
1303
, checkVersion [1 ,2 ,3 ] (not (null mentionedExtensionsThatNeedCabal12)) $
1288
1304
PackageDistInexcusable $
@@ -1428,10 +1444,6 @@ checkCabalVersion pkg =
1428
1444
(orLaterVersion v) (earlierVersion (majorUpperBound v))
1429
1445
embed vr = embedVersionRange vr
1430
1446
1431
- compatLicenses = [ GPL Nothing , LGPL Nothing , AGPL Nothing , BSD3 , BSD4
1432
- , PublicDomain , AllRightsReserved
1433
- , UnspecifiedLicense , OtherLicense ]
1434
-
1435
1447
mentionedExtensions = [ ext | bi <- allBuildInfo pkg
1436
1448
, ext <- allExtensions bi ]
1437
1449
mentionedExtensionsThatNeedCabal12 =
0 commit comments