1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution
.CabalSpecVersion
where
6 import Distribution
.Compat
.Prelude
9 -- | Different Cabal-the-spec versions.
11 -- We branch based on this at least in the parser.
13 = -- | this is older than 'CabalSpecV1_2'
15 |
-- | new syntax (sections)
22 |
-- 1.16 -- 1.14: no changes
37 deriving (Eq
, Ord
, Show, Read, Enum
, Bounded
, Typeable
, Data
, Generic
)
39 instance Binary CabalSpecVersion
40 instance Structured CabalSpecVersion
41 instance NFData CabalSpecVersion
where rnf
= genericRnf
43 -- | Show cabal spec version, but not the way in the .cabal files
46 showCabalSpecVersion
:: CabalSpecVersion
-> String
47 showCabalSpecVersion CabalSpecV3_12
= "3.12"
48 showCabalSpecVersion CabalSpecV3_8
= "3.8"
49 showCabalSpecVersion CabalSpecV3_6
= "3.6"
50 showCabalSpecVersion CabalSpecV3_4
= "3.4"
51 showCabalSpecVersion CabalSpecV3_0
= "3.0"
52 showCabalSpecVersion CabalSpecV2_4
= "2.4"
53 showCabalSpecVersion CabalSpecV2_2
= "2.2"
54 showCabalSpecVersion CabalSpecV2_0
= "2.0"
55 showCabalSpecVersion CabalSpecV1_24
= "1.24"
56 showCabalSpecVersion CabalSpecV1_22
= "1.22"
57 showCabalSpecVersion CabalSpecV1_20
= "1.20"
58 showCabalSpecVersion CabalSpecV1_18
= "1.18"
59 showCabalSpecVersion CabalSpecV1_12
= "1.12"
60 showCabalSpecVersion CabalSpecV1_10
= "1.10"
61 showCabalSpecVersion CabalSpecV1_8
= "1.8"
62 showCabalSpecVersion CabalSpecV1_6
= "1.6"
63 showCabalSpecVersion CabalSpecV1_4
= "1.4"
64 showCabalSpecVersion CabalSpecV1_2
= "1.2"
65 showCabalSpecVersion CabalSpecV1_0
= "1.0"
67 cabalSpecLatest
:: CabalSpecVersion
68 cabalSpecLatest
= CabalSpecV3_12
70 -- | Parse 'CabalSpecVersion' from version digits.
72 -- It may fail if for recent versions the version is not exact.
73 cabalSpecFromVersionDigits
:: [Int] -> Maybe CabalSpecVersion
74 cabalSpecFromVersionDigits v
75 | v
== [3, 12] = Just CabalSpecV3_12
76 | v
== [3, 8] = Just CabalSpecV3_8
77 | v
== [3, 6] = Just CabalSpecV3_6
78 | v
== [3, 4] = Just CabalSpecV3_4
79 | v
== [3, 0] = Just CabalSpecV3_0
80 | v
== [2, 4] = Just CabalSpecV2_4
81 | v
== [2, 2] = Just CabalSpecV2_2
82 | v
== [2, 0] = Just CabalSpecV2_0
83 | v
>= [1, 25] = Nothing
84 | v
>= [1, 23] = Just CabalSpecV1_24
85 | v
>= [1, 21] = Just CabalSpecV1_22
86 | v
>= [1, 19] = Just CabalSpecV1_20
87 | v
>= [1, 17] = Just CabalSpecV1_18
88 | v
>= [1, 11] = Just CabalSpecV1_12
89 | v
>= [1, 9] = Just CabalSpecV1_10
90 | v
>= [1, 7] = Just CabalSpecV1_8
91 | v
>= [1, 5] = Just CabalSpecV1_6
92 | v
>= [1, 3] = Just CabalSpecV1_4
93 | v
>= [1, 1] = Just CabalSpecV1_2
94 |
otherwise = Just CabalSpecV1_0
97 cabalSpecToVersionDigits
:: CabalSpecVersion
-> [Int]
98 cabalSpecToVersionDigits CabalSpecV3_12
= [3, 12]
99 cabalSpecToVersionDigits CabalSpecV3_8
= [3, 8]
100 cabalSpecToVersionDigits CabalSpecV3_6
= [3, 6]
101 cabalSpecToVersionDigits CabalSpecV3_4
= [3, 4]
102 cabalSpecToVersionDigits CabalSpecV3_0
= [3, 0]
103 cabalSpecToVersionDigits CabalSpecV2_4
= [2, 4]
104 cabalSpecToVersionDigits CabalSpecV2_2
= [2, 2]
105 cabalSpecToVersionDigits CabalSpecV2_0
= [2, 0]
106 cabalSpecToVersionDigits CabalSpecV1_24
= [1, 24]
107 cabalSpecToVersionDigits CabalSpecV1_22
= [1, 22]
108 cabalSpecToVersionDigits CabalSpecV1_20
= [1, 20]
109 cabalSpecToVersionDigits CabalSpecV1_18
= [1, 18]
110 cabalSpecToVersionDigits CabalSpecV1_12
= [1, 12]
111 cabalSpecToVersionDigits CabalSpecV1_10
= [1, 10]
112 cabalSpecToVersionDigits CabalSpecV1_8
= [1, 8]
113 cabalSpecToVersionDigits CabalSpecV1_6
= [1, 6]
114 cabalSpecToVersionDigits CabalSpecV1_4
= [1, 4]
115 cabalSpecToVersionDigits CabalSpecV1_2
= [1, 2]
116 cabalSpecToVersionDigits CabalSpecV1_0
= [1, 0]
118 -- | What is the minimum Cabal library version which knows how handle
119 -- this spec version.
121 -- /Note:/ this is a point where we could decouple cabal-spec and Cabal
122 -- versions, if we ever want that.
124 -- >>> cabalSpecMinimumLibraryVersion CabalSpecV3_0
127 -- >>> cabalSpecMinimumLibraryVersion CabalSpecV2_4
131 cabalSpecMinimumLibraryVersion
:: CabalSpecVersion
-> [Int]
132 cabalSpecMinimumLibraryVersion CabalSpecV1_0
= [1, 0]
133 cabalSpecMinimumLibraryVersion csv
= case cabalSpecToVersionDigits
(pred csv
) of
137 specHasCommonStanzas
:: CabalSpecVersion
-> HasCommonStanzas
138 specHasCommonStanzas v
=
139 if v
>= CabalSpecV2_2
140 then HasCommonStanzas
143 specHasElif
:: CabalSpecVersion
-> HasElif
145 if v
>= CabalSpecV2_2
149 -------------------------------------------------------------------------------
151 -------------------------------------------------------------------------------
153 -- IDEA: make some kind of tagged booleans?
154 data HasElif
= HasElif | NoElif
157 data HasCommonStanzas
= HasCommonStanzas | NoCommonStanzas
160 data HasGlobstar
= HasGlobstar | NoGlobstar