mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
Setup.hs: paralell RGL module compilation experiment
For this to have any effect, Setup.hs has to be compiled with -threaded, which cabal-install doesn't do, unfortunately...
This commit is contained in:
38
Setup.hs
38
Setup.hs
@@ -15,6 +15,8 @@ import System.FilePath
|
|||||||
import System.Directory
|
import System.Directory
|
||||||
import System.Process
|
import System.Process
|
||||||
import System.Exit
|
import System.Exit
|
||||||
|
import Control.Concurrent(forkIO)
|
||||||
|
import Control.Concurrent.Chan(newChan,writeChan,readChan)
|
||||||
|
|
||||||
import WebSetup
|
import WebSetup
|
||||||
|
|
||||||
@@ -71,22 +73,22 @@ rglCommands =
|
|||||||
let prelude_src_dir = rgl_src_dir </> "prelude"
|
let prelude_src_dir = rgl_src_dir </> "prelude"
|
||||||
prelude_dst_dir = rgl_dst_dir lbi </> "prelude"
|
prelude_dst_dir = rgl_dst_dir lbi </> "prelude"
|
||||||
createDirectoryIfMissing True prelude_dst_dir
|
createDirectoryIfMissing True prelude_dst_dir
|
||||||
files <- getDirectoryContents prelude_src_dir
|
files <- ls prelude_src_dir
|
||||||
run_gfc pkg lbi (["-s", "--gfo-dir="++prelude_dst_dir] ++ [prelude_src_dir </> file | file <- files, take 1 file /= "."])
|
run_gfc pkg lbi (["-s", "--gfo-dir="++prelude_dst_dir] ++ [prelude_src_dir </> file | file <- files])
|
||||||
, RGLCommand "lang" True $ \modes args pkg lbi -> do
|
, RGLCommand "lang" True $ \modes args pkg lbi -> do
|
||||||
sequence_
|
parallel_
|
||||||
[do mapM_ (gfc1 mode pkg lbi . lang) (optml mode langsLang args)
|
[do mapM_ (gfc1 mode pkg lbi . lang) (optml mode langsLang args)
|
||||||
mapM_ (gfc1 mode pkg lbi . symbol) (optml mode langsAPI args)
|
mapM_ (gfc1 mode pkg lbi . symbol) (optml mode langsAPI args)
|
||||||
| mode <- modes]
|
| mode <- modes]
|
||||||
, RGLCommand "compat" True $ \modes args pkg lbi -> do
|
, RGLCommand "compat" True $ \modes args pkg lbi -> do
|
||||||
mapM_ (gfc modes pkg lbi . compat) (optl langsCompat args)
|
mapM_ (gfc modes pkg lbi . compat) (optl langsCompat args)
|
||||||
, RGLCommand "api" True $ \modes args pkg lbi -> do
|
, RGLCommand "api" True $ \modes args pkg lbi -> do
|
||||||
sequence_
|
parallel_
|
||||||
[do mapM_ (gfc1 mode pkg lbi . try) (optml mode langsAPI args)
|
[do mapM_ (gfc1 mode pkg lbi . try) (optml mode langsAPI args)
|
||||||
mapM_ (gfc1 mode pkg lbi . symbolic) (optml mode langsSymbolic args)
|
mapM_ (gfc1 mode pkg lbi . symbolic) (optml mode langsSymbolic args)
|
||||||
| mode <- modes]
|
| mode <- modes]
|
||||||
, RGLCommand "pgf" False $ \modes args pkg lbi ->
|
, RGLCommand "pgf" False $ \modes args pkg lbi ->
|
||||||
sequence_ [
|
parallel_ [
|
||||||
do let dir = getRGLBuildDir lbi mode
|
do let dir = getRGLBuildDir lbi mode
|
||||||
createDirectoryIfMissing True dir
|
createDirectoryIfMissing True dir
|
||||||
sequence_ [run_gfc pkg lbi ["-s","-make","-name=Lang"++la,
|
sequence_ [run_gfc pkg lbi ["-s","-make","-name=Lang"++la,
|
||||||
@@ -145,17 +147,14 @@ copyRGL args flags pkg lbi = do
|
|||||||
copyAll s from to = do
|
copyAll s from to = do
|
||||||
putStrLn $ "Installing [" ++ s ++ "] " ++ to
|
putStrLn $ "Installing [" ++ s ++ "] " ++ to
|
||||||
createDirectoryIfMissing True to
|
createDirectoryIfMissing True to
|
||||||
files <- fmap (filter (\f -> take 1 f /= ".")) $ getDirectoryContents from
|
mapM_ (\file -> copyFile (from </> file) (to </> file)) =<< ls from
|
||||||
mapM_ (\file -> copyFile (from </> file) (to </> file)) files
|
|
||||||
|
|
||||||
sdistRGL pkg mb_lbi hooks flags = do
|
sdistRGL pkg mb_lbi hooks flags = do
|
||||||
paths <- getRGLFiles rgl_src_dir []
|
paths <- getRGLFiles rgl_src_dir []
|
||||||
let pkg' = pkg{dataFiles=paths}
|
let pkg' = pkg{dataFiles=paths}
|
||||||
sDistHook simpleUserHooks pkg' mb_lbi hooks flags
|
sDistHook simpleUserHooks pkg' mb_lbi hooks flags
|
||||||
where
|
where
|
||||||
getRGLFiles dir paths = do
|
getRGLFiles dir paths = foldM (processFile dir) paths =<< ls dir
|
||||||
files <- getDirectoryContents dir
|
|
||||||
foldM (processFile dir) paths [file | file <- files, file /= "." && file /= ".."]
|
|
||||||
|
|
||||||
processFile dir paths file = do
|
processFile dir paths file = do
|
||||||
let path = dir </> file
|
let path = dir </> file
|
||||||
@@ -171,11 +170,9 @@ testRGL args _ pkg lbi = do
|
|||||||
let paths = case args of
|
let paths = case args of
|
||||||
[] -> ["testsuite"]
|
[] -> ["testsuite"]
|
||||||
paths -> paths
|
paths -> paths
|
||||||
sequence_ [walk path | path <- paths]
|
mapM_ walk paths
|
||||||
where
|
where
|
||||||
walk path = do
|
walk path = mapM_ (walkFile . (path </>)) =<< ls path
|
||||||
files <- getDirectoryContents path
|
|
||||||
sequence_ [walkFile (path </> file) | file <- files, file /= "." && file /= ".."]
|
|
||||||
|
|
||||||
walkFile fpath = do
|
walkFile fpath = do
|
||||||
exists <- doesFileExist fpath
|
exists <- doesFileExist fpath
|
||||||
@@ -279,7 +276,7 @@ langsPGF = langsLang `except` ["Ara","Hin","Ron","Tha"]
|
|||||||
-- languages for which Compatibility exists (to be extended)
|
-- languages for which Compatibility exists (to be extended)
|
||||||
langsCompat = langsLang `only` ["Cat","Eng","Fin","Fre","Ita","Lav","Spa","Swe"]
|
langsCompat = langsLang `only` ["Cat","Eng","Fin","Fre","Ita","Lav","Spa","Swe"]
|
||||||
|
|
||||||
gfc modes pkg lbi file = sequence_ [gfc1 mode pkg lbi file | mode<-modes]
|
gfc modes pkg lbi file = parallel_ [gfc1 mode pkg lbi file | mode<-modes]
|
||||||
gfc1 mode pkg lbi file = do
|
gfc1 mode pkg lbi file = do
|
||||||
let dir = getRGLBuildDir lbi mode
|
let dir = getRGLBuildDir lbi mode
|
||||||
preproc = case mode of
|
preproc = case mode of
|
||||||
@@ -426,3 +423,14 @@ updateFile path new =
|
|||||||
when (Right new/=old) $ seq (either (const 0) length old) $
|
when (Right new/=old) $ seq (either (const 0) length old) $
|
||||||
writeFile path new
|
writeFile path new
|
||||||
|
|
||||||
|
-- | List files, excluding "." and ".."
|
||||||
|
ls path = filter (`notElem` [".",".."]) `fmap` getDirectoryContents path
|
||||||
|
|
||||||
|
|
||||||
|
-- | For parallel RGL module compilation
|
||||||
|
-- Unfortunately, this has no effect unless Setup.hs is compiled with -threaded
|
||||||
|
parallel_ ms = -- sequence_ ms {-
|
||||||
|
do c <- newChan
|
||||||
|
ts <- sequence [ forkIO (m >> writeChan c ()) | m <- ms]
|
||||||
|
sequence_ [readChan c | _ <- ts]
|
||||||
|
--}
|
||||||
Reference in New Issue
Block a user