1
0
forked from GitHub/gf-rgl
This commit is contained in:
Krasimir Angelov
2018-11-28 13:57:39 +01:00
51 changed files with 2275 additions and 1252 deletions

View File

@@ -2,19 +2,20 @@
-- | Main build script for RGL
import Data.List (find,isPrefixOf,isSuffixOf,(\\),unfoldr)
import Data.List (find,isPrefixOf,isSuffixOf,(\\))
import Data.Maybe (catMaybes)
import System.IO (hPutStrLn,stderr)
import System.IO.Error (catchIOError)
import System.Exit (ExitCode(..),exitFailure)
import System.Environment (getArgs,lookupEnv)
import System.Process (rawSystem)
import System.FilePath ((</>)) -- ,takeFileName,addExtension,dropExtension)
import System.FilePath ((</>),splitSearchPath) -- ,takeFileName,addExtension,dropExtension)
import System.Directory (createDirectoryIfMissing,copyFile,getDirectoryContents,removeDirectoryRecursive,findFile)
#if __GLASGOW_HASKELL__>=800
import System.Directory (getModificationTime,setModificationTime)
#endif
import Control.Monad (when,unless)
import Config
main :: IO ()
main = do
@@ -118,7 +119,7 @@ mkInfo = do
-- Look for install location in a few different places
let mflag = getFlag destination_flag args
mbuilt <- catchIOError (readFile "../gf-core/DATA_DIR" >>= \d -> return (Just (d </> "lib"))) (\e -> return Nothing)
menvar <- lookupEnv "GF_LIB_PATH"
menvar <- lookupEnv "GF_LIB_PATH" >>= return . fmap (head . splitSearchPath)
let
inst_dir =
case catMaybes [mflag,menvar,mbuilt] of
@@ -347,57 +348,6 @@ verbose_switch_short = "-v"
getFlag :: String -> [String] -> Maybe String
getFlag flag args = fmap (drop (length flag)) $ find (isPrefixOf flag) args
-------------------------------------------------------------------------------
-- Languages of the RGL
-- | Path to language config file
configFile :: FilePath
configFile = "languages.csv"
-- | Information about a language
data LangInfo = LangInfo
{ langCode :: String -- ^ 3-letter ISO 639-2/B code
, langDir :: String -- ^ directory name
, langFunctor :: Maybe String -- ^ functor (not used)
, langUnlexer :: Maybe String -- ^ decoding for postprocessing linearizations
, langPresent :: Bool
, langAll :: Bool
, langTry :: Bool
, langSymbolic :: Bool
, langCompatibility :: Bool
} deriving (Show,Eq)
-- | Load language information from config file
loadLangs :: IO [LangInfo]
loadLangs = do
lns <- readFile configFile >>= return . lines
mapM mkLangInfo (tail lns)
where
maybeBit bits n = if length bits >= (n+1) && length (bits !! n) > 0 then Just (bits !! n) else Nothing
boolBit bits n def = if length bits >= (n+1) && length (bits !! n) > 0 then (if def then bits !! n /= "n" else bits !! n == "y") else def
mkLangInfo s =
let bits = separateBy ',' s in
if length bits < 2
then die $ "Invalid entry in " ++ configFile ++ ": " ++ s
else return $ LangInfo
{ langCode = bits !! 0
, langDir = bits !! 1
, langFunctor = maybeBit bits 2
, langUnlexer = maybeBit bits 3
, langPresent = boolBit bits 4 False
, langAll = boolBit bits 5 True
, langTry = boolBit bits 6 True
, langSymbolic = boolBit bits 7 True
, langCompatibility = boolBit bits 8 False
}
-- | Separate a string on a character
-- Source: https://stackoverflow.com/a/4978733/98600
separateBy :: Eq a => a -> [a] -> [[a]]
separateBy chr = unfoldr sep where
sep [] = Nothing
sep l = Just . fmap (drop 1) . break (== chr) $ l
-------------------------------------------------------------------------------
-- Executing GF
@@ -444,7 +394,7 @@ execute command args = do
-- | For parallel RGL module compilation
-- Unfortunately, this has no effect unless compiled with -threaded
parallel_ :: (Foldable t, Monad m) => t (m a) -> m ()
--parallel_ :: (Foldable t, Monad m) => t (m a) -> m ()
parallel_ ms = sequence_ ms
-- do c <- newChan
-- ts <- sequence [ forkIO (m >> writeChan c ()) | m <- ms]