on 0752bed help sign in
Idris-dev/Setup.hs
177 lines 6.8 kB history raw
1{-# LANGUAGE CPP #-}
2import Control.Monad
3import Data.IORef
5import Distribution.Simple
6import Distribution.Simple.InstallDirs as I
7import Distribution.Simple.LocalBuildInfo as L
8import qualified Distribution.Simple.Setup as S
9import qualified Distribution.Simple.Program as P
10import Distribution.PackageDescription
11import Distribution.Text
13import System.Exit
14import System.FilePath ((</>), splitDirectories)
15import System.Directory
16import qualified System.FilePath.Posix as Px
17import System.Process
18import qualified Data.Text as T
19import qualified Data.Text.IO as TIO
21-- After Idris is built, we need to check and install the prelude and other libs
23make verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "make"
24mvn verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "mvn"
26#ifdef mingw32_HOST_OS
27-- make on mingw32 exepects unix style separators
28(<//>) = (Px.</>)
29idrisCmd local = Px.joinPath $ splitDirectories $
30 ".." <//> buildDir local <//> "idris" <//> "idris"
31rtsDir local = Px.joinPath $ splitDirectories $
32 ".." <//> buildDir local <//> "rts" <//> "libidris_rts"
33#else
34idrisCmd local = ".." </> buildDir local </> "idris" </> "idris"
35rtsDir local = ".." </> buildDir local </> "rts" </> "libidris_rts"
36#endif
38cleanStdLib verbosity
39 = do make verbosity [ "-C", "lib", "clean", "IDRIS=idris" ]
40 make verbosity [ "-C", "effects", "clean", "IDRIS=idris" ]
42cleanJavaLib verbosity
43 = do dirty <- doesDirectoryExist ("java" </> "target")
44 when dirty $ mvn verbosity [ "-f", "java/pom.xml", "clean" ]
45 pomExists <- doesFileExist ("java" </> "pom.xml")
46 when pomExists $ removeFile ("java" </> "pom.xml")
47 execPomExists <- doesFileExist ("java" </> "executable_pom.xml")
48 when pomExists $ removeFile ("java" </> "executable_pom.xml")
50installStdLib pkg local verbosity copy
51 = do let dirs = L.absoluteInstallDirs pkg local copy
52 let idir = datadir dirs
53 let icmd = idrisCmd local
54 putStrLn $ "Installing libraries in " ++ idir
55 make verbosity
56 [ "-C", "lib", "install"
57 , "TARGET=" ++ idir
58 , "IDRIS=" ++ icmd
59 , "RTS=" ++ rtsDir local
60 ]
61 make verbosity
62 [ "-C", "effects", "install"
63 , "TARGET=" ++ idir
64 , "IDRIS=" ++ icmd
65 , "RTS=" ++ rtsDir local
66 ]
67 let idirRts = idir </> "rts"
68 putStrLn $ "Installing run time system in " ++ idirRts
69 make verbosity
70 [ "-C", "rts", "install"
71 , "TARGET=" ++ idirRts
72 , "IDRIS=" ++ icmd
73 , "RTS=" ++ rtsDir local
74 ]
76installJavaLib pkg local verbosity copy version = do
77 let rtsFile = "idris-" ++ display version ++ ".jar"
78 putStrLn $ "Installing java libraries"
79 mvn verbosity [ "install:install-file"
80 , "-Dfile=" ++ ("java" </> "target" </> rtsFile)
81 , "-DgroupId=org.idris-lang"
82 , "-DartifactId=idris"
83 , "-Dversion=" ++ display version
84 , "-Dpackaging=jar"
85 , "-DgeneratePom=True"
86 ]
87 let dir = datadir $ L.absoluteInstallDirs pkg local copy
88 copyFile ("java" </> "executable_pom.xml") (dir </> "executable_pom.xml")
90-- This is a hack. I don't know how to tell cabal that a data file needs
91-- installing but shouldn't be in the distribution. And it won't make the
92-- distribution if it's not there, so instead I just delete
93-- the file after configure.
95removeLibIdris local verbosity
96 = do let icmd = idrisCmd local
97 make verbosity
98 [ "-C", "rts", "clean"
99 , "IDRIS=" ++ icmd
100 ]
102checkStdLib local verbosity
103 = do let icmd = idrisCmd local
104 putStrLn $ "Building libraries..."
105 make verbosity
106 [ "-C", "lib", "check"
107 , "IDRIS=" ++ icmd
108 , "RTS=" ++ rtsDir local
109 ]
110 make verbosity
111 [ "-C", "effects", "check"
112 , "IDRIS=" ++ icmd
113 , "RTS=" ++ rtsDir local
114 ]
115 make verbosity
116 [ "-C", "rts", "check"
117 , "IDRIS=" ++ icmd
118 ]
120buildRTS dir verbosity
121 = do putStrLn "Building RTS..."
122 make verbosity
123 [ "-C", "rts", "build"
124 , "DIST=../" ++ dir
125 ]
127checkJavaLib verbosity = mvn verbosity [ "-f", "java" </> "pom.xml", "package" ]
129javaFlag flags =
130 case lookup (FlagName "java") (S.configConfigurationsFlags flags) of
131 Just True -> True
132 Just False -> False
133 Nothing -> False
135preparePoms version
136 = do pomTemplate <- TIO.readFile ("java" </> "pom_template.xml")
137 TIO.writeFile ("java" </> "pom.xml") (insertVersion pomTemplate)
138 execPomTemplate <- TIO.readFile ("java" </> "executable_pom_template.xml")
139 TIO.writeFile ("java" </> "executable_pom.xml") (insertVersion execPomTemplate)
140 where
141 insertVersion template =
142 T.replace (T.pack "$RTS-VERSION$") (T.pack $ display version) template
144-- Install libraries during both copy and install
145-- See http://hackage.haskell.org/trac/hackage/ticket/718
146main = do
147 defaultMainWithHooks $ simpleUserHooks
148 { postCopy = \ _ flags pkg lbi -> do
149 let verb = S.fromFlag $ S.copyVerbosity flags
150 installStdLib pkg lbi verb
151 (S.fromFlag $ S.copyDest flags)
152 , postInst = \ _ flags pkg lbi -> do
153 let verb = (S.fromFlag $ S.installVerbosity flags)
154 installStdLib pkg lbi verb
155 NoCopyDest
156 when (javaFlag $ configFlags lbi)
157 (installJavaLib pkg
158 lbi
159 verb
160 NoCopyDest
161 (pkgVersion . package $ localPkgDescr lbi)
162 )
163 , postConf = \ _ flags _ lbi -> do
164 removeLibIdris lbi (S.fromFlag $ S.configVerbosity flags)
165 when (javaFlag $ configFlags lbi)
166 (preparePoms . pkgVersion . package $ localPkgDescr lbi)
167 , postClean = \ _ flags _ _ -> do
168 let verb = S.fromFlag $ S.cleanVerbosity flags
169 cleanStdLib verb
170 cleanJavaLib verb
171 , postBuild = \ _ flags _ lbi -> do
172 let verb = S.fromFlag $ S.buildVerbosity flags
173 let distdir = buildDir lbi
174 buildRTS distdir verb
175 checkStdLib lbi verb
176 when (javaFlag $ configFlags lbi) (checkJavaLib verb)
177 }