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
38 deriving (Eq
, Ord
, Show, Read, Enum
, Bounded
, Data
, Generic
)
40 instance Binary CabalSpecVersion
41 instance Structured CabalSpecVersion
42 instance NFData CabalSpecVersion
where rnf
= genericRnf
44 -- | Show cabal spec version, but not the way in the .cabal files
47 showCabalSpecVersion
:: CabalSpecVersion
-> String
48 showCabalSpecVersion CabalSpecV3_14
= "3.14"
49 showCabalSpecVersion CabalSpecV3_12
= "3.12"
50 showCabalSpecVersion CabalSpecV3_8
= "3.8"
51 showCabalSpecVersion CabalSpecV3_6
= "3.6"
52 showCabalSpecVersion CabalSpecV3_4
= "3.4"
53 showCabalSpecVersion CabalSpecV3_0
= "3.0"
54 showCabalSpecVersion CabalSpecV2_4
= "2.4"
55 showCabalSpecVersion CabalSpecV2_2
= "2.2"
56 showCabalSpecVersion CabalSpecV2_0
= "2.0"
57 showCabalSpecVersion CabalSpecV1_24
= "1.24"
58 showCabalSpecVersion CabalSpecV1_22
= "1.22"
59 showCabalSpecVersion CabalSpecV1_20
= "1.20"
60 showCabalSpecVersion CabalSpecV1_18
= "1.18"
61 showCabalSpecVersion CabalSpecV1_12
= "1.12"
62 showCabalSpecVersion CabalSpecV1_10
= "1.10"
63 showCabalSpecVersion CabalSpecV1_8
= "1.8"
64 showCabalSpecVersion CabalSpecV1_6
= "1.6"
65 showCabalSpecVersion CabalSpecV1_4
= "1.4"
66 showCabalSpecVersion CabalSpecV1_2
= "1.2"
67 showCabalSpecVersion CabalSpecV1_0
= "1.0"
69 cabalSpecLatest
:: CabalSpecVersion
70 cabalSpecLatest
= CabalSpecV3_14
72 -- | Parse 'CabalSpecVersion' from version digits.
74 -- It may fail if for recent versions the version is not exact.
75 cabalSpecFromVersionDigits
:: [Int] -> Maybe CabalSpecVersion
76 cabalSpecFromVersionDigits v
77 | v
== [3, 14] = Just CabalSpecV3_14
78 | v
== [3, 12] = Just CabalSpecV3_12
79 | v
== [3, 8] = Just CabalSpecV3_8
80 | v
== [3, 6] = Just CabalSpecV3_6
81 | v
== [3, 4] = Just CabalSpecV3_4
82 | v
== [3, 0] = Just CabalSpecV3_0
83 | v
== [2, 4] = Just CabalSpecV2_4
84 | v
== [2, 2] = Just CabalSpecV2_2
85 | v
== [2, 0] = Just CabalSpecV2_0
86 | v
>= [1, 25] = Nothing
87 | v
>= [1, 23] = Just CabalSpecV1_24
88 | v
>= [1, 21] = Just CabalSpecV1_22
89 | v
>= [1, 19] = Just CabalSpecV1_20
90 | v
>= [1, 17] = Just CabalSpecV1_18
91 | v
>= [1, 11] = Just CabalSpecV1_12
92 | v
>= [1, 9] = Just CabalSpecV1_10
93 | v
>= [1, 7] = Just CabalSpecV1_8
94 | v
>= [1, 5] = Just CabalSpecV1_6
95 | v
>= [1, 3] = Just CabalSpecV1_4
96 | v
>= [1, 1] = Just CabalSpecV1_2
97 |
otherwise = Just CabalSpecV1_0
100 cabalSpecToVersionDigits
:: CabalSpecVersion
-> [Int]
101 cabalSpecToVersionDigits CabalSpecV3_14
= [3, 14]
102 cabalSpecToVersionDigits CabalSpecV3_12
= [3, 12]
103 cabalSpecToVersionDigits CabalSpecV3_8
= [3, 8]
104 cabalSpecToVersionDigits CabalSpecV3_6
= [3, 6]
105 cabalSpecToVersionDigits CabalSpecV3_4
= [3, 4]
106 cabalSpecToVersionDigits CabalSpecV3_0
= [3, 0]
107 cabalSpecToVersionDigits CabalSpecV2_4
= [2, 4]
108 cabalSpecToVersionDigits CabalSpecV2_2
= [2, 2]
109 cabalSpecToVersionDigits CabalSpecV2_0
= [2, 0]
110 cabalSpecToVersionDigits CabalSpecV1_24
= [1, 24]
111 cabalSpecToVersionDigits CabalSpecV1_22
= [1, 22]
112 cabalSpecToVersionDigits CabalSpecV1_20
= [1, 20]
113 cabalSpecToVersionDigits CabalSpecV1_18
= [1, 18]
114 cabalSpecToVersionDigits CabalSpecV1_12
= [1, 12]
115 cabalSpecToVersionDigits CabalSpecV1_10
= [1, 10]
116 cabalSpecToVersionDigits CabalSpecV1_8
= [1, 8]
117 cabalSpecToVersionDigits CabalSpecV1_6
= [1, 6]
118 cabalSpecToVersionDigits CabalSpecV1_4
= [1, 4]
119 cabalSpecToVersionDigits CabalSpecV1_2
= [1, 2]
120 cabalSpecToVersionDigits CabalSpecV1_0
= [1, 0]
122 -- | What is the minimum Cabal library version which knows how handle
123 -- this spec version.
125 -- /Note:/ this is a point where we could decouple cabal-spec and Cabal
126 -- versions, if we ever want that.
128 -- >>> cabalSpecMinimumLibraryVersion CabalSpecV3_0
131 -- >>> cabalSpecMinimumLibraryVersion CabalSpecV2_4
135 cabalSpecMinimumLibraryVersion
:: CabalSpecVersion
-> [Int]
136 cabalSpecMinimumLibraryVersion CabalSpecV1_0
= [1, 0]
137 cabalSpecMinimumLibraryVersion csv
= case cabalSpecToVersionDigits
(pred csv
) of
141 specHasCommonStanzas
:: CabalSpecVersion
-> HasCommonStanzas
142 specHasCommonStanzas v
=
143 if v
>= CabalSpecV2_2
144 then HasCommonStanzas
147 specHasElif
:: CabalSpecVersion
-> HasElif
149 if v
>= CabalSpecV2_2
153 -------------------------------------------------------------------------------
155 -------------------------------------------------------------------------------
157 -- IDEA: make some kind of tagged booleans?
158 data HasElif
= HasElif | NoElif
161 data HasCommonStanzas
= HasCommonStanzas | NoCommonStanzas
164 data HasGlobstar
= HasGlobstar | NoGlobstar