1
0
forked from GitHub/gf-rgl
This commit is contained in:
Krasimir Angelov
2018-08-10 21:45:58 +02:00
4 changed files with 63 additions and 36 deletions

14
.travis.yml Normal file
View File

@@ -0,0 +1,14 @@
sudo: required
language: c
services:
- docker
before_install:
- docker pull odanoburu/haskell-gf:3.9
- mkdir rgl
script:
- docker run --mount src="$(pwd)",target=/home,type=bind odanoburu/haskell-gf:3.9 /bin/bash -c "cd /home/; export GF_LIB_PATH=/home/rgl ; runghc Make.hs build prelude all --verbose ;"
- docker run --mount src="$(pwd)",target=/home,type=bind odanoburu/haskell-gf:3.9 /bin/bash -c "cd /home/; export GF_LIB_PATH=/home/rgl; bash Make.sh --dest=rgl --verbose ;"

61
Make.hs
View File

@@ -125,20 +125,20 @@ getRGLBuildDir info mode = infoBuildDir info </> getRGLBuildSubDir mode
getRGLBuildSubDir :: Mode -> String getRGLBuildSubDir :: Mode -> String
getRGLBuildSubDir mode = getRGLBuildSubDir mode =
case mode of case mode of
AllTenses -> "alltenses"
Present -> "present" Present -> "present"
AllTenses -> "alltenses"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Build modes -- Build modes
data Mode = AllTenses | Present data Mode = Present | AllTenses
deriving (Show,Eq) deriving (Show,Eq)
all_modes :: [String] all_modes :: [String]
all_modes = ["alltenses","present"] all_modes = ["present","alltenses"]
default_modes :: [Mode] default_modes :: [Mode]
default_modes = [AllTenses,Present] default_modes = [Present,AllTenses]
-- | An RGL build command -- | An RGL build command
data RGLCommand = RGLCommand data RGLCommand = RGLCommand
@@ -156,8 +156,9 @@ rglCommands =
createDirectoryIfMissing True prelude_dst_dir createDirectoryIfMissing True prelude_dst_dir
files <- getDirectoryContents prelude_src_dir files <- getDirectoryContents prelude_src_dir
let modules = [prelude_src_dir </> file | file <- files, file /= "." && file /= ".."] let modules = [prelude_src_dir </> file | file <- files, file /= "." && file /= ".."]
putStrLn $ "Building [Prelude] " ++ unwords (map dropSourceDir modules) putStrLn $ "Building [Prelude]"
run_gfc bi ([if infoVerbose bi then "--verbose" else "--quiet", "--gfo-dir="++prelude_dst_dir] ++ modules) when (infoVerbose bi) $ putStrLn (unwords (map dropSourceDir modules))
run_gfc bi (["--gfo-dir="++prelude_dst_dir] ++ modules)
, RGLCommand "all" True $ gfcp [l,s,c,t,sc] , RGLCommand "all" True $ gfcp [l,s,c,t,sc]
, RGLCommand "lang" False $ gfcp [l,s] , RGLCommand "lang" False $ gfcp [l,s]
@@ -174,7 +175,7 @@ rglCommands =
Just mfull -> flip mapM_ modes $ \mode -> do Just mfull -> flip mapM_ modes $ \mode -> do
let dst = getRGLBuildDir bi mode let dst = getRGLBuildDir bi mode
putStrLn $ "Building [" ++ show mode ++ "] " ++ dropSourceDir mfull putStrLn $ "Building [" ++ show mode ++ "] " ++ dropSourceDir mfull
run_gfc bi [if infoVerbose bi then "--verbose" else "--quiet", "--gfo-dir="++dst, mfull] run_gfc bi ["--gfo-dir="++dst, mfull]
] ]
where where
@@ -184,8 +185,12 @@ rglCommands =
gfcp' :: Info -> Mode -> [String] -> [Mode -> [String] -> (LangInfo -> FilePath,[LangInfo] -> [LangInfo])] -> IO () gfcp' :: Info -> Mode -> [String] -> [Mode -> [String] -> (LangInfo -> FilePath,[LangInfo] -> [LangInfo])] -> IO ()
gfcp' bi mode args cs = do gfcp' bi mode args cs = do
langsAll <- loadLangs langsAll <- loadLangs
-- f :: LangInfo -> FilePath
-- as :: [LangInfo] -> [LangInfo]
-- ss :: [String]
-- fss :: [[FilePath]]
let (ss,fss) = unzip [ (summary f langs,map f langs) | c<-cs, let (f,as) = c mode args, let langs = as langsAll] let (ss,fss) = unzip [ (summary f langs,map f langs) | c<-cs, let (f,as) = c mode args, let langs = as langsAll]
gfcn bi mode (unwords ss) (concat fss) gfcn bi mode (unwords (filter (not.null) ss)) (concat fss)
summary :: (LangInfo -> FilePath) -> [LangInfo] -> String summary :: (LangInfo -> FilePath) -> [LangInfo] -> String
summary f langs = unwords (map (dropSourceDir . f) langs) summary f langs = unwords (map (dropSourceDir . f) langs)
@@ -280,21 +285,24 @@ getOptMode args =
-- | List of languages overriding the default definitions -- | List of languages overriding the default definitions
getOptLangs :: [LangInfo] -> [LangInfo] -> [String] -> [LangInfo] getOptLangs :: [LangInfo] -> [LangInfo] -> [String] -> [LangInfo]
getOptLangs langs defaultLangs args = getOptLangs allLangs defaultLangs args =
case [ls | arg <- args, let x = [ ls
let (f,ls) = splitAt (length lang_flag) arg, | arg <- args
f==lang_flag] of , let (f,ls) = splitAt (length lang_flag) arg
('+':ls):_ -> foldr addLang defaultLangs (seps ls) , f == lang_flag
]
in case x of
-- ('+':ls):_ -> foldr addLang defaultLangs (seps ls)
('-':ls):_ -> foldr removeLang defaultLangs (seps ls) ('-':ls):_ -> foldr removeLang defaultLangs (seps ls)
ls:_ -> findLangs langs (seps ls) ls:_ -> findLangs defaultLangs (seps ls)
_ -> defaultLangs _ -> defaultLangs
where where
seps = words . map (\c -> if c==',' then ' ' else c) seps = words . map (\c -> if c==',' then ' ' else c)
findLangs langs ls = [lang | lang <- langs, langCode lang `elem` ls] findLangs langs ls = [lang | lang <- langs, langCode lang `elem` ls]
removeLang l ls = [lang | lang <- ls, langCode lang /= l] removeLang l ls = [lang | lang <- ls, langCode lang /= l]
addLang l ls = if null (findLangs ls [l]) -- addLang l ls = if null (findLangs ls [l])
then findLangs langs [l]++ls -- then findLangs allLangs [l]++ls
else ls -- else ls
-- | Get module names from arguments -- | Get module names from arguments
getOptModules :: [String] -> [FilePath] getOptModules :: [String] -> [FilePath]
@@ -378,26 +386,31 @@ separateBy chr = unfoldr sep where
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Executing GF -- Executing GF
gfc :: Info -> [Mode] -> String -> [String] -> IO () gfc :: Info -> [Mode] -> String -> [FilePath] -> IO ()
gfc bi modes summary files = gfc bi modes summary files =
parallel_ [gfcn bi mode summary files | mode<-modes] parallel_ [gfcn bi mode summary files | mode<-modes]
gfcn :: Info -> Mode -> String -> [String] -> IO () gfcn :: Info -> Mode -> String -> [FilePath] -> IO ()
gfcn _ _ _ [] = die $ "No files specified.\nMake sure the language is in " ++ configFile ++ " and that it supports the modes/modules specified."
gfcn bi mode summary files = do gfcn bi mode summary files = do
let dir = getRGLBuildDir bi mode let dir = getRGLBuildDir bi mode
preproc = case mode of preproc = case mode of
AllTenses -> ""
Present -> "--preproc=mkPresent" Present -> "--preproc=mkPresent"
AllTenses -> ""
createDirectoryIfMissing True dir createDirectoryIfMissing True dir
putStrLn $ "Building [" ++ show mode ++ "] " ++ summary if length files > 0
run_gfc bi ([if infoVerbose bi then "--verbose" else "--quiet", "--no-pmcfg", preproc, "--gfo-dir="++dir] ++ files) then do
putStrLn $ "Building [" ++ show mode ++ "]"
when (infoVerbose bi) (putStrLn summary)
run_gfc bi (["--no-pmcfg", preproc, "--gfo-dir="++dir] ++ files)
else
putStrLn $ "Skipping [" ++ show mode ++ "] (nothing to build)"
-- | Runs the gf executable in compile mode with the given arguments -- | Runs the gf executable in compile mode with the given arguments
run_gfc :: Info -> [String] -> IO () run_gfc :: Info -> [String] -> IO ()
run_gfc bi args = do run_gfc bi args = do
let let
args' = ["--batch","--gf-lib-path="] ++ filter (not . null) args dir = infoBuildDir bi
args' = ["--batch", "--quiet", "--gf-lib-path="++dir] ++ filter (not . null) args
gf = infoGFPath bi gf = infoGFPath bi
execute gf args' execute gf args'

11
Make.sh
View File

@@ -1,8 +1,9 @@
#!/bin/sh #!/bin/bash
# --- # ---
# Non-Haskell RGL build script for Unix-based machines # Non-Haskell RGL build script for Unix-based machines
# --- # ---
set -e
# Get languages from config # Get languages from config
langs=$(tail -n +2 languages.csv | awk -F ',' '{ if ($6 != "n") { print $1 } }') langs=$(tail -n +2 languages.csv | awk -F ',' '{ if ($6 != "n") { print $1 } }')
@@ -52,12 +53,7 @@ fi
# A few more definitions before we get started # A few more definitions before we get started
src="src" src="src"
dist="dist" dist="dist"
gfc="${gf} --batch --quiet" gfc="${gf} --batch --quiet --gf-lib-path=${dist}"
# Redirect stderr if not verbose
if [ $verbose = false ]; then
exec 2> /dev/null
fi
# Make directories if not present # Make directories if not present
mkdir -p "${dist}/prelude" mkdir -p "${dist}/prelude"
@@ -78,6 +74,7 @@ for lang in $langs; do
if [ $mod == "Try" ] && [[ "$langs_try" != *"$lang"* ]]; then continue; fi if [ $mod == "Try" ] && [[ "$langs_try" != *"$lang"* ]]; then continue; fi
if [ $mod == "Symbolic" ] && [[ "$langs_symbolic" != *"$lang"* ]]; then continue; fi if [ $mod == "Symbolic" ] && [[ "$langs_symbolic" != *"$lang"* ]]; then continue; fi
for file in "${src}"/*/"${mod}${lang}".gf; do for file in "${src}"/*/"${mod}${lang}".gf; do
if [ ! -f "$file" ]; then continue; fi
if [[ "$langs_present" = *"$lang"* ]]; then modules_present="${modules_present} ${file}"; fi if [[ "$langs_present" = *"$lang"* ]]; then modules_present="${modules_present} ${file}"; fi
modules_alltenses="${modules_alltenses} ${file}" modules_alltenses="${modules_alltenses} ${file}"
done done

View File

@@ -2,6 +2,8 @@
# GF Resource Grammar Library (RGL) # GF Resource Grammar Library (RGL)
[![Build Status](https://travis-ci.org/GrammaticalFramework/gf-rgl.svg?branch=master)](https://travis-ci.org/GrammaticalFramework/gf-rgl)
The GF Resource Grammar Library is the standard library for Grammatical Framework. It covers the morphology and basic syntax of over 30 languages. The GF Resource Grammar Library is the standard library for Grammatical Framework. It covers the morphology and basic syntax of over 30 languages.
For more about the RGL, see the [synopsis page](http://www.grammaticalframework.org/lib/doc/synopsis.html). For more about the RGL, see the [synopsis page](http://www.grammaticalframework.org/lib/doc/synopsis.html).
@@ -77,18 +79,19 @@ clean
- `CMDS` is one or more of: - `CMDS` is one or more of:
`prelude`, `prelude`,
`all` (default), `all`,
`lang`, `lang`,
`api`, `api`,
`compat`, `compat`,
or an explicit module name (e.g. `ExtraEng.gf`. You don't need to specify to language subdirectory, but there is a restriction that the module must exist in a **direct** subdirectory of `src`). or an explicit module name (e.g. `ExtraEng.gf`. You don't need to specify to language subdirectory, but there is a restriction that the module must exist in a **direct** subdirectory of `src`).
If ommitted, the default command is `prelude all`.
- `MODE` is one of: - `MODE` is one of:
`present`, `present`,
`alltenses` `alltenses`
(default is both). (default is both).
- `LANG` is a 3-letter language code, e.g. `Eng`, `Swe` etc. - `LANG` is a 3-letter language code, e.g. `Eng`, `Swe` etc.
- You can _override_ the default language list with `--langs=...` - You can _override_ the default language list with `--langs=...`
- You can _add_ languages to the default list with `--langs=+...` - ~~You can _add_ languages to the default list with `--langs=+...`~~
- You can _remove_ languages from the default list with `langs=-...` - You can _remove_ languages from the default list with `langs=-...`
- The path to GF installed on your system can be specified via the `--gf` flag (default is that the `gf` executable is in the global system path). - The path to GF installed on your system can be specified via the `--gf` flag (default is that the `gf` executable is in the global system path).
- The `--dest` flag can be used to manually specify where the compiled RGL modules should be copied/installed. This is the same place as `GF_LIB_PATH`. - The `--dest` flag can be used to manually specify where the compiled RGL modules should be copied/installed. This is the same place as `GF_LIB_PATH`.
@@ -101,7 +104,7 @@ Simply run the script to build the entire RGL and install in the default locatio
You can pass the following flags: You can pass the following flags:
- `--dest=...` to manually specify the install location - `--dest=...` to manually specify the install location
- `--gf=...` to specify the path to the `gf` executable, if not available on the system path - `--gf=...` to specify the path to the `gf` executable, if not available on the system path
- `--verbose` or `-v` to show all GF warnings and errors - `--verbose` or `-v` to show a list of files being built (errors will always be shown)
## Windows batch file: `Make.bat` ## Windows batch file: `Make.bat`