-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.hs
More file actions
executable file
·202 lines (183 loc) · 7.01 KB
/
build.hs
File metadata and controls
executable file
·202 lines (183 loc) · 7.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env stack
-- stack --resolver lts-23.28 script --package=fedora-releases --package=extra --package=simple-cmd --package=simple-cmd-args
import Control.Monad (forM_, unless, when)
import Data.Either (partitionEithers)
import Data.List ((\\))
import Data.Maybe (mapMaybe)
import Data.Tuple (swap)
import Data.Version.Extra
import Distribution.Fedora.Branch (Branch(..), eitherBranch, getActiveBranches,
showBranch)
import SimpleCmd
import SimpleCmdArgs
main =
simpleCmdArgs Nothing "hls builder" "hls copr builds" $
run
<$> switchWith 'n' "dryrun" "Show what would be done only"
<*> switchWith 'l' "local" "Do a local build instead"
<*> (map readArch <$> many (strOptionWith 'a' "arch" "ARCH" "chroot archtectures"))
<*> (partitionBranches <$> many (strArg "BRANCH... GHCMAJOR..."))
-- https://haskell-language-server.readthedocs.io/en/latest/support/ghc-version-support.html
-- minimum listed GHC version: 9.6
-- 9.4 fails to build ghcide (as of 2.12)
defaultGHCs = [GHC, GHC9_14, GHC9_12, GHC9_10, GHC9_8, GHC9_6]
allArchs = [X86_64, AARCH64, PPC64LE]
defaultArchs = [X86_64, AARCH64]
run dryrun local reqarchs (reqbrs,reqghcs) =
if local
then do
unless (null reqbrs) $
error' "can't combine --local with branches"
when (null reqghcs) $
error' "specify at least one ghcver"
-- FIXME doesn't work (branch interferes)
runLocal dryrun reqghcs
else runRemote dryrun reqarchs (reqbrs,reqghcs)
runRemote dryrun reqarchs (reqbrs,reqghcs) = do
branches <-
if null reqbrs
then do
allbrs <- getActiveBranches
-- EPELMinor 10 0
return $ allbrs \\ [EPEL 8, EPELNext 8, EPELNext 9]
else return reqbrs
let ghcs = if null reqghcs then defaultGHCs else reqghcs
frpq = "/usr/bin/frpq"
forM_ branches $ \br -> do
defaultGhcVer <- readVersion <$> cmd frpq ["-q", showBranch br, "--qf=%{version}", "--latest-limit=1", "ghc"]
forM_ ((if br == EPEL 9 then filter (< GHC9_10) else id) ghcs \\ ([{-GHC9_14 | br == EPEL 9-}])) $
\ghc -> do
putChar '\n'
putStrLn $ "#" +-+ showBranch br +-+ showGHCPkg ghc
version <- readVersion <$> cmd frpq ["-q", showBranch br, "--qf=%{version}", "--latest-limit=1", showGHCPkg ghc]
if ghc /= GHC && version == defaultGhcVer
then putStrLn $ "skipping" +-+ showGHCPkg ghc ++ '-' : showVersion version
else do
putStrLn $ showVersion version
when (ghc /= GHC) $ do
let latest = latestGHC ghc
when (version /= latest) $
error' $ showGHCPkg ghc ++ '-' : showVersion version +-+ "is not" +-+ showVersion latest
switchGhcMajor ghc
ghcmajor <- cmd "grep" ["%global ghc_major", specFile]
--putStrLn ghcmajor
-- FIXME check ghcmajor
sed ["s/%global ghc_minor .*/%global ghc_minor " ++ showVersion version ++ "/"]
let archs =
if length reqarchs == 1
then reqarchs
else mapMaybe (maybeGHCArchs br ghc) $
if null reqarchs then defaultArchs else reqarchs
-- 9.4 fails to link for aarch64 with ld.gold: skip unless explicit req
unless (reqarchs == [AARCH64] && ghc == GHC9_4 && ghcs /= [GHC9_4]) $
cmdLog_ "fbrnch" $ "copr" : ["-n" | dryrun] ++ ["--single", "haskell-language-server", showBranch br] ++ map archOpt archs
where
maybeGHCArchs :: Branch -> GHCPKG -> Arch -> Maybe Arch
maybeGHCArchs (EPEL 9) GHC9_4 AARCH64 = Nothing
maybeGHCArchs (EPEL 9) GHC9_6 AARCH64 = Nothing
maybeGHCArchs _ _ arch = Just arch
-- if ghcs == [GHC9_4] && (length ghcs > 1 || then Nothing else Just AARCH64
runLocal dryrun reqghcs =
forM_ reqghcs $ \ghc -> do
putChar '\n'
putStrLn $ "#" +-+ showGHCPkg ghc
version <- readVersion <$> cmd "rpm" ["-q", "--qf=%{version}", showGHCPkg ghc]
putStrLn $ showVersion version
when (ghc /= GHC) $ do
let latest = latestGHC ghc
when (version /= latest) $
error' $ showGHCPkg ghc ++ '-' : showVersion version +-+ "is not" +-+ showVersion latest
switchGhcMajor ghc
ghcmajor <- cmd "grep" ["%global ghc_major", specFile]
--putStrLn ghcmajor
-- FIXME check ghcmajor
sed ["s/%global ghc_minor .*/%global ghc_minor " ++ showVersion version ++ "/"]
when dryrun $ error' "--local does not support --dryrun"
-- FIXME need to unset GHC_PACKAGE_PATH
cmdLog_ "fbrnch" ["local"]
switchGhcMajor :: GHCPKG -> IO ()
switchGhcMajor GHC =
sed ["s/^%global ghc_major .*/#%%global ghc_major 9.6/"]
switchGhcMajor ghc =
sed ["s/#%%global ghc_major/%global ghc_major/",
"s/\\(%global ghc_major \\).*/\\1" ++ showMajor ghc ++ "/"]
specFile = "haskell-language-server.spec"
sed :: [String] -> IO ()
sed edits =
cmd_ "sed" $ ["-i"] ++ map ("--expression=" ++) edits ++ [specFile]
archOpt :: Arch -> String
archOpt arch = "--arch=" ++ showArch arch
-- (from fbrnch Branches) different to fedora-releases
partitionBranches :: [String] -> ([Branch],[GHCPKG])
partitionBranches args =
fmap (map readGHCPkg) . swap . partitionEithers $ map eitherBranch args
data GHCPKG = GHC8_10 | GHC9_0 | GHC9_2 | GHC9_4 | GHC9_6 | GHC9_8 | GHC9_10 | GHC9_12 | GHC9_14 | GHC
deriving (Eq,Ord)
latestGHC :: GHCPKG -> Version
latestGHC GHC9_14 = makeVersion [9,14,1]
latestGHC GHC9_12 = makeVersion [9,12,3]
latestGHC GHC9_10 = makeVersion [9,10,3]
latestGHC GHC9_8 = makeVersion [9,8,4]
latestGHC GHC9_6 = makeVersion [9,6,7]
latestGHC GHC9_4 = makeVersion [9,4,8]
latestGHC GHC9_2 = makeVersion [9,2,8]
latestGHC GHC9_0 = makeVersion [9,0,2]
latestGHC GHC8_10 = makeVersion [8,10,7]
latestGHC GHC = error' "latestGHC not valid for main ghc package"
readGHCPkg :: String -> GHCPKG
readGHCPkg "main" = GHC
readGHCPkg "" = GHC
readGHCPkg "ghc" = GHC
readGHCPkg ('g':'h':'c':ver) = readGHCPkg ver
readGHCPkg ver =
case ver of
"914" -> GHC9_14
"9.14" -> GHC9_14
"912" -> GHC9_12
"9.12" -> GHC9_12
"910" -> GHC9_10
"9.10" -> GHC9_10
"98" -> GHC9_8
"9.8" -> GHC9_8
"96" -> GHC9_6
"9.6" -> GHC9_6
"94" -> GHC9_4
"9.4" -> GHC9_4
"92" -> GHC9_2
"9.2" -> GHC9_2
"90" -> GHC9_0
"9.0" -> GHC9_0
"810" -> GHC8_10
"8.10" -> GHC8_10
_ -> error' $ "unknown GHCVER" +-+ ver
showGHCPkg GHC = "ghc"
showGHCPkg GHC9_14 = "ghc9.14"
showGHCPkg GHC9_12 = "ghc9.12"
showGHCPkg GHC9_10 = "ghc9.10"
showGHCPkg GHC9_8 = "ghc9.8"
showGHCPkg GHC9_6 = "ghc9.6"
showGHCPkg GHC9_4 = "ghc9.4"
showGHCPkg GHC9_2 = "ghc9.2"
showGHCPkg GHC9_0 = "ghc9.0"
showGHCPkg GHC8_10 = "ghc8.10"
showMajor GHC = ""
showMajor GHC9_14 = "9.14"
showMajor GHC9_12 = "9.12"
showMajor GHC9_10 = "9.10"
showMajor GHC9_8 = "9.8"
showMajor GHC9_6 = "9.6"
showMajor GHC9_4 = "9.4"
showMajor GHC9_2 = "9.2"
showMajor GHC9_0 = "9.0"
showMajor GHC8_10 = "8.10"
data Arch = X86_64 | AARCH64 | PPC64LE
deriving Eq
readArch :: String -> Arch
readArch "x86_64" = X86_64
readArch "aarch64" = AARCH64
readArch "ppc64le" = PPC64LE
readArch a = error' $ "unknown arch:" +-+ a
showArch :: Arch -> String
showArch X86_64 = "x86_64"
showArch AARCH64 = "aarch64"
showArch PPC64LE = "ppc64le"