1
0
forked from GitHub/gf-rgl

Merge branch 'master' into docker-ci

This commit is contained in:
odanoburu
2018-08-09 18:05:56 +00:00
3 changed files with 43 additions and 33 deletions

65
Make.hs
View File

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

View File

@@ -3,6 +3,7 @@
# ---
# Non-Haskell RGL build script for Unix-based machines
# ---
set -e
# Get languages from config
langs=$(tail -n +2 languages.csv | awk -F ',' '{ if ($6 != "n") { print $1 } }')
@@ -54,11 +55,6 @@ src="src"
dist="dist"
gfc="${gf} --batch --quiet"
# Redirect stderr if not verbose
if [ $verbose = false ]; then
exec 2> /dev/null
fi
# Make directories if not present
mkdir -p "${dist}/prelude"
mkdir -p "${dist}/present"
@@ -78,6 +74,7 @@ for lang in $langs; do
if [ $mod == "Try" ] && [[ "$langs_try" != *"$lang"* ]]; then continue; fi
if [ $mod == "Symbolic" ] && [[ "$langs_symbolic" != *"$lang"* ]]; then continue; fi
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
modules_alltenses="${modules_alltenses} ${file}"
done

View File

@@ -90,7 +90,7 @@ or an explicit module name (e.g. `ExtraEng.gf`. You don't need to specify to lan
(default is both).
- `LANG` is a 3-letter language code, e.g. `Eng`, `Swe` etc.
- 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=-...`
- 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`.
@@ -103,7 +103,7 @@ Simply run the script to build the entire RGL and install in the default locatio
You can pass the following flags:
- `--dest=...` to manually specify the install location
- `--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`