forked from agda/agda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup.hs
71 lines (61 loc) · 2.39 KB
/
Setup.hs
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
{-# LANGUAGE CPP #-}
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.Simple.BuildPaths (exeExtension)
import Distribution.PackageDescription
-- ASR (2018-07-20): GHC 7.10 does not support the macro
-- @MIN_VERSION_Cabal@.
#if __GLASGOW_HASKELL__ > 710
#if MIN_VERSION_Cabal(2,3,0)
import Distribution.System ( buildPlatform )
#endif
#endif
import System.FilePath
import System.FilePath.Find
import System.Process
import System.Exit
main = defaultMainWithHooks hooks
hooks = simpleUserHooks { regHook = checkAgdaPrimitiveAndRegister }
builtins :: FilePath -> IO [FilePath]
builtins = find always (extension ==? ".agda")
agdaExeExtension :: String
-- ASR (2018-07-20): GHC 7.10 does not support the macro
-- @MIN_VERSION_Cabal@.
#if __GLASGOW_HASKELL__ > 710
#if MIN_VERSION_Cabal(2,3,0)
agdaExeExtension = exeExtension buildPlatform
#else
agdaExeExtension = exeExtension
#endif
#else
agdaExeExtension = exeExtension
#endif
checkAgdaPrimitive :: PackageDescription -> LocalBuildInfo -> RegisterFlags -> IO ()
-- ASR (2018-12-23): This fun run twice using Cabal < 2.0.0.0. Because
-- GHC 7.10 does not support the macro @MIN_VERSION_Cabal@, I only
-- could avoid the second run of this function on GHC > 7.10. See
-- Issue #3444.
#if __GLASGOW_HASKELL__ > 710
#if !MIN_VERSION_Cabal(2,0,0)
checkAgdaPrimitive pkg info flags | regGenPkgConf flags /= NoFlag = return () -- Gets run twice, only do this the second time
#endif
#endif
checkAgdaPrimitive pkg info flags = do
let dirs = absoluteInstallDirs pkg info NoCopyDest
agda = buildDir info </> "agda" </> "agda" <.> agdaExeExtension
auxDir = datadir dirs </> "lib" </> "prim" </> "Agda"
prim = auxDir </> "Primitive" <.> "agda"
checkPrim file = do
ok <- rawSystem agda [file, "-v0"]
case ok of
ExitSuccess -> return ()
ExitFailure _ -> putStrLn $ "WARNING: Failed to typecheck " ++ file ++ "!"
putStrLn "Generating Agda library interface files..."
checkPrim prim
auxBuiltins <- builtins (auxDir </> "Builtin")
mapM_ checkPrim auxBuiltins
checkAgdaPrimitiveAndRegister :: PackageDescription -> LocalBuildInfo -> UserHooks -> RegisterFlags -> IO ()
checkAgdaPrimitiveAndRegister pkg info hooks flags = do
checkAgdaPrimitive pkg info flags
regHook simpleUserHooks pkg info hooks flags -- This actually does something useful