Skip to content

Commit 517455a

Browse files
committed
Deduplicate allow-newer logic to Ghclibgen
1 parent 76e2f53 commit 517455a

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

CI.hs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import System.IO.Extra
2020
import System.IO.Unsafe
2121
import System.Process.Extra
2222
import System.Time.Extra
23+
import Ghclibgen (allowNewerProjectLines, mkAllowNewerFlags)
2324

2425
main :: IO ()
2526
main = do
@@ -36,18 +37,6 @@ main = do
3637
version <- buildDists ghcFlavor noGhcCheckout noBuilds versionSuffix allowNewerFlags allowNewerSpecs
3738
putStrLn version
3839

39-
mkAllowNewerFlags :: [String] -> String
40-
mkAllowNewerFlags xs =
41-
let render = unwords . map (\s -> "--allow-newer=" ++ s)
42-
def = ""
43-
in case xs of
44-
[] -> if null def then "" else " " ++ def
45-
_ -> " " ++ render xs
46-
47-
allowNewerProjectLines :: [String] -> [String]
48-
allowNewerProjectLines [] = []
49-
allowNewerProjectLines xs = ["allow-newer: " ++ intercalate ", " xs]
50-
5140
data Options = Options
5241
{ ghcFlavor :: GhcFlavor,
5342
noGhcCheckout :: Bool,
@@ -412,7 +401,7 @@ buildDists ghcFlavor noGhcCheckout noBuilds versionSuffix allowNewerFlags allowN
412401
system_ $ "cabal build exe:ghc-lib-gen" ++ allowNewerFlags
413402
system_ $ "cabal run exe:ghc-lib-gen" ++ allowNewerFlags
414403
++ " -- ghc ../patches --ghc-lib-parser "
415-
++ ghcFlavorArg ++ " " ++ cppOpts ghcFlavor ++allowNewerFlags
404+
++ ghcFlavorArg ++ " " ++ cppOpts ghcFlavor ++ allowNewerFlags
416405

417406
patchVersion version "ghc/ghc-lib-parser.cabal"
418407
mkTarball pkg_ghclib_parser
@@ -478,11 +467,11 @@ buildDists ghcFlavor noGhcCheckout noBuilds versionSuffix allowNewerFlags allowN
478467

479468
system_ $ "cd examples/ghc-lib-test-mini-hlint && cabal test " ++
480469
"--project-dir ../.. --test-show-details direct " ++
481-
("--test-options \"--color always --test-command ../../ghc-lib-test-mini-hlint " ++ ghcFlavorArg ++ "\"")
470+
"--test-options \"--color always --test-command ../../ghc-lib-test-mini-hlint " ++ ghcFlavorArg ++ "\""
482471

483472
system_ $ "cd examples/ghc-lib-test-mini-compile && cabal test " ++
484473
"--project-dir ../.. --test-show-details direct " ++
485-
("--test-options \"--color always --test-command ../../ghc-lib-test-mini-compile " ++ ghcFlavorArg ++ "\"")
474+
"--test-options \"--color always --test-command ../../ghc-lib-test-mini-compile " ++ ghcFlavorArg ++ "\""
486475

487476
system_ "cabal -v0 exec -- ghc -ignore-dot-ghci -package=ghc-lib-parser -e \"print 1\""
488477
system_ "cabal -v0 exec -- ghc -ignore-dot-ghci -package=ghc-lib -e \"print 1\""

ghc-lib-gen.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ executable ghc-lib-build-tool
6060
else
6161
build-tool-depends: alex:alex, happy:happy < 2.0
6262
build-depends:
63-
directory, filepath, time, extra, optparse-applicative
63+
directory, filepath, time, extra, optparse-applicative, ghc-lib-gen
6464
if flag(semaphore-compat)
6565
build-depends: semaphore-compat
6666
main-is: CI.hs

ghc-lib-gen/src/Ghclibgen.hs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ module Ghclibgen
4242
generateGhcLibCabal,
4343
generateGhcLibParserCabal,
4444
setupModuleDepsPlaceholders,
45+
mkAllowNewerFlags,
46+
allowNewerProjectLines,
4547
)
4648
where
4749

@@ -1742,10 +1744,7 @@ generatePrerequisites ghcFlavor allowNewerSpecs = do
17421744
system_ "bash -c \"./configure --enable-tarballs-autodownload\""
17431745
withCurrentDirectory "hadrian" $ do
17441746

1745-
let defaultAllowNewer = []
1746-
effectiveAllowNewer =
1747-
if null allowNewerSpecs then defaultAllowNewer else allowNewerSpecs
1748-
allowNewerArgs = concatMap (\s -> ["--allow-newer=" ++ s]) effectiveAllowNewer
1747+
let allowNewerArgs = mkAllowNewerFlagsList allowNewerSpecs
17491748

17501749
system_ . unwords . join $
17511750
[ ["cabal", "build", "exe:hadrian", "--ghc-options=-j"]
@@ -1826,3 +1825,14 @@ genPlaceholderModules = loop
18261825
contents <- listDirectory fp
18271826
mapM_ (loop . (fp </>)) contents
18281827
else when (takeExtension fp `elem` [".x", ".y", ".hsc"]) $ genPlaceholderModule fp
1828+
1829+
mkAllowNewerFlags :: [String] -> String
1830+
mkAllowNewerFlags [] = ""
1831+
mkAllowNewerFlags xs = " " ++ unwords (mkAllowNewerFlagsList xs)
1832+
1833+
mkAllowNewerFlagsList :: [String] -> [String]
1834+
mkAllowNewerFlagsList = map ("--allow-newer=" ++)
1835+
1836+
allowNewerProjectLines :: [String] -> [String]
1837+
allowNewerProjectLines [] = []
1838+
allowNewerProjectLines xs = ["allow-newer: " ++ intercalate ", " xs]

0 commit comments

Comments
 (0)