Skip to content

Commit

Permalink
Refactored the build inside Setup.hs and the various Makefiles.
Browse files Browse the repository at this point in the history
* Refactored the Setup.hs script into a much simpler layout.
* Simplified the idris.cabal file, alphabetizing the modules,
  build dependencies, simplifying the indentation, standardizing the
  flags, and normalizing the formatting of lists.
* Fixed a bug in the generation of the executable_pom.xml file for
  the Java backend.
  • Loading branch information
Gabe McArthur committed Sep 24, 2013
1 parent bef8dce commit c7cf1f0
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 236 deletions.
273 changes: 135 additions & 138 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,158 +20,155 @@ import qualified Data.Text.IO as TIO

-- After Idris is built, we need to check and install the prelude and other libs

make verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "make"
-- -----------------------------------------------------------------------------
-- Idris Command Path

#ifdef mingw32_HOST_OS
-- make on mingw32 exepects unix style separators
#ifdef mingw32_HOST_OS
(<//>) = (Px.</>)
idrisCmd local = Px.joinPath $ splitDirectories $
".." <//> buildDir local <//> "idris" <//> "idris"
rtsDir local = Px.joinPath $ splitDirectories $
".." <//> buildDir local <//> "rts" <//> "libidris_rts"
idrisCmd local = Px.joinPath $ splitDirectories $ ".." <//> buildDir local <//> "idris" <//> "idris"
#else
idrisCmd local = ".." </> buildDir local </> "idris" </> "idris"
rtsDir local = ".." </> buildDir local </> "rts" </> "libidris_rts"
#endif

cleanStdLib verbosity
= do make verbosity [ "-C", "lib", "clean", "IDRIS=idris" ]
make verbosity [ "-C", "effects", "clean", "IDRIS=idris" ]
make verbosity [ "-C", "javascript", "clean", "IDRIS=idris" ]

cleanJavaPom verbosity
= do execPomExists <- doesFileExist ("java" </> "executable_pom.xml")
when execPomExists $ removeFile ("java" </> "executable_pom.xml")

cleanLLVMLib verbosity = make verbosity ["-C", "llvm", "clean"]

installStdLib pkg local withoutEffects verbosity copy
= do let dirs = L.absoluteInstallDirs pkg local copy
let idir = datadir dirs
let icmd = idrisCmd local
putStrLn $ "Installing libraries in " ++ idir
make verbosity
[ "-C", "lib", "install"
, "TARGET=" ++ idir
, "IDRIS=" ++ icmd
]
unless withoutEffects $
make verbosity
[ "-C", "effects", "install"
, "TARGET=" ++ idir
, "IDRIS=" ++ icmd
]
make verbosity
[ "-C", "javascript", "install"
, "TARGET=" ++ idir
, "IDRIS=" ++ icmd
]
let idirRts = idir </> "rts"
putStrLn $ "Installing run time system in " ++ idirRts
make verbosity
[ "-C", "rts", "install"
, "TARGET=" ++ idirRts
, "IDRIS=" ++ icmd
]

installLLVMLib verbosity pkg local copy =
let idir = datadir $ L.absoluteInstallDirs pkg local copy in
make verbosity ["-C", "llvm", "install", "TARGET=" ++ idir </> "llvm"]

buildLLVMLib verbosity = make verbosity ["-C", "llvm", "all"]

installJavaPom pkg local verbosity copy version = do
putStrLn $ "Installing java pom template"
let dir = datadir $ L.absoluteInstallDirs pkg local copy
copyFile ("java" </> "executable_pom.xml") (dir </> "executable_pom.xml")

-- This is a hack. I don't know how to tell cabal that a data file needs
-- installing but shouldn't be in the distribution. And it won't make the
-- distribution if it's not there, so instead I just delete
-- the file after configure.

removeLibIdris local verbosity
= do let icmd = idrisCmd local
make verbosity
[ "-C", "rts", "clean"
, "IDRIS=" ++ icmd
]

checkStdLib local withoutEffects verbosity
= do let icmd = idrisCmd local
putStrLn $ "Building libraries..."
make verbosity
[ "-C", "lib", "check"
, "IDRIS=" ++ icmd
]
unless withoutEffects $
make verbosity
[ "-C", "effects", "check"
, "IDRIS=" ++ icmd
]
make verbosity
[ "-C", "javascript", "check"
, "IDRIS=" ++ icmd
]
make verbosity
[ "-C", "rts", "check"
, "IDRIS=" ++ icmd
]

llvmFlag flags =
-- -----------------------------------------------------------------------------
-- Make Commands

make verbosity =
P.runProgramInvocation verbosity . P.simpleProgramInvocation "make"

-- -----------------------------------------------------------------------------
-- Flags

usesLLVM :: S.ConfigFlags -> Bool
usesLLVM flags =
case lookup (FlagName "llvm") (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> True

noEffectsFlag flags =
case lookup (FlagName "noeffects") (S.configConfigurationsFlags flags) of
usesEffects :: S.ConfigFlags -> Bool
usesEffects flags =
case lookup (FlagName "effects") (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> False

preparePoms version
= do execPomTemplate <- TIO.readFile ("java" </> "executable_pom_template.xml")
TIO.writeFile ("java" </> "executable_pom.xml") (insertVersion execPomTemplate)
where
insertVersion template =
T.replace (T.pack "$RTS-VERSION$") (T.pack $ display version) template
Nothing -> True

-- -----------------------------------------------------------------------------
-- Clean

idrisClean _ flags _ _ = do
cleanStdLib
cleanLLVM
cleanJava
where
verbosity = S.fromFlag $ S.cleanVerbosity flags

cleanStdLib = do
makeClean "lib"
makeClean "effects"
makeClean "javascript"

cleanJava = do
execPomExists <- doesFileExist ("java" </> "executable_pom.xml")
when execPomExists $ removeFile ("java" </> "executable_pom.xml")

cleanLLVM = makeClean "llvm"

makeClean dir = make verbosity [ "-C", dir, "clean", "IDRIS=idris" ]


-- -----------------------------------------------------------------------------
-- Configure

idrisConfigure _ flags _ local = do
configureRTS
configureJava
where
verbosity = S.fromFlag $ S.configVerbosity flags
version = pkgVersion . package $ localPkgDescr local

-- This is a hack. I don't know how to tell cabal that a data file needs
-- installing but shouldn't be in the distribution. And it won't make the
-- distribution if it's not there, so instead I just delete
-- the file after configure.
configureRTS = make verbosity ["-C", "rts", "clean"]

configureJava = do
execPomTemplate <- TIO.readFile ("java" </> "executable_pom_template.xml")
TIO.writeFile ("java" </> "executable_pom.xml") (insertVersion execPomTemplate)
where
insertVersion = T.replace (T.pack "$RTS-VERSION$") (T.pack $ display version)

-- -----------------------------------------------------------------------------
-- Build

idrisBuild _ flags _ local = do
buildStdLib
buildRTS
when (usesLLVM $ configFlags local) buildLLVM
where
verbosity = S.fromFlag $ S.buildVerbosity flags

buildStdLib = do
putStrLn "Building libraries..."
makeBuild "lib"
when (usesEffects $ configFlags local) $ makeBuild "effects"
makeBuild "javascript"
where
makeBuild dir = make verbosity [ "-C", dir, "build" , "IDRIS=" ++ idrisCmd local]

buildRTS = make verbosity ["-C", "rts", "build"]

buildLLVM = make verbosity ["-C", "llvm", "build"]

-- -----------------------------------------------------------------------------
-- Copy/Install

idrisInstall verbosity copy pkg local = do
installStdLib
installRTS
installJava
when (usesLLVM $ configFlags local) installLLVM
where
target = datadir $ L.absoluteInstallDirs pkg local copy

installStdLib = do
putStrLn $ "Installing libraries in " ++ target
makeInstall "lib" target
when (usesEffects $ configFlags local) $ makeInstall "effects" target
makeInstall "javascript" target

installRTS = do
let target' = target </> "rts"
putStrLn $ "Installing run time system in " ++ target'
makeInstall "rts" target'

installJava = do
putStrLn $ "Installing java pom template in " ++ target
copyFile ("java" </> "executable_pom.xml") (target </> "executable_pom.xml")

installLLVM = do
let target' = target </> "llvm"
putStrLn $ "Installing LLVM library in " ++ target
makeInstall "llvm" target

makeInstall src target =
make verbosity [ "-C", src, "install" , "TARGET=" ++ target, "IDRIS=" ++ idrisCmd local]

-- -----------------------------------------------------------------------------
-- Main

-- Install libraries during both copy and install
-- See http://hackage.haskell.org/trac/hackage/ticket/718
main = do
defaultMainWithHooks $ simpleUserHooks
{ postCopy = \ _ flags pkg lbi -> do
let verb = S.fromFlag $ S.copyVerbosity flags
let withoutEffects = noEffectsFlag $ configFlags lbi
installStdLib pkg lbi withoutEffects verb
(S.fromFlag $ S.copyDest flags)
installJavaPom pkg lbi verb
(S.fromFlag $ S.copyDest flags)
(pkgVersion . package $ localPkgDescr lbi)
when (llvmFlag $ configFlags lbi)
(installLLVMLib verb pkg lbi (S.fromFlag $ S.copyDest flags))
, postInst = \ _ flags pkg lbi -> do
let verb = (S.fromFlag $ S.installVerbosity flags)
let withoutEffects = noEffectsFlag $ configFlags lbi
installStdLib pkg lbi withoutEffects verb
NoCopyDest
installJavaPom pkg lbi verb
NoCopyDest
(pkgVersion . package $ localPkgDescr lbi)
when (llvmFlag $ configFlags lbi)
(installLLVMLib verb pkg lbi NoCopyDest)
, postConf = \ _ flags _ lbi -> do
removeLibIdris lbi (S.fromFlag $ S.configVerbosity flags)
preparePoms . pkgVersion . package $ localPkgDescr lbi
, postClean = \ _ flags _ _ -> do
let verb = S.fromFlag $ S.cleanVerbosity flags
cleanStdLib verb
cleanLLVMLib verb
cleanJavaPom verb
, postBuild = \ _ flags _ lbi -> do
let verb = S.fromFlag $ S.buildVerbosity flags
when (llvmFlag $ configFlags lbi) (buildLLVMLib verb)
let withoutEffects = noEffectsFlag $ configFlags lbi
checkStdLib lbi withoutEffects verb
}
main = defaultMainWithHooks $ simpleUserHooks
{ postClean = idrisClean
, postConf = idrisConfigure
, postBuild = idrisBuild
, postCopy = \_ flags pkg local ->
idrisInstall (S.fromFlag $ S.copyVerbosity flags)
(S.fromFlag $ S.copyDest flags) pkg local
, postInst = \_ flags pkg local ->
idrisInstall (S.fromFlag $ S.installVerbosity flags)
NoCopyDest pkg local
}
9 changes: 5 additions & 4 deletions effects/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
IDRIS := idris

check: .PHONY
build: .PHONY
$(IDRIS) --build effects.ipkg

recheck: clean check
clean: .PHONY
$(IDRIS) --clean effects.ipkg

install:
$(IDRIS) --install effects.ipkg

clean: .PHONY
$(IDRIS) --clean effects.ipkg
rebuild: clean build

.PHONY:
Loading

0 comments on commit c7cf1f0

Please sign in to comment.