forked from GitHub/gf-rgl
Merge branch 'master' into docker-ci
This commit is contained in:
61
Make.hs
61
Make.hs
@@ -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'
|
||||||
|
|
||||||
|
|||||||
7
Make.sh
7
Make.sh
@@ -3,6 +3,7 @@
|
|||||||
# ---
|
# ---
|
||||||
# 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 } }')
|
||||||
@@ -54,11 +55,6 @@ src="src"
|
|||||||
dist="dist"
|
dist="dist"
|
||||||
gfc="${gf} --batch --quiet"
|
gfc="${gf} --batch --quiet"
|
||||||
|
|
||||||
# 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"
|
||||||
mkdir -p "${dist}/present"
|
mkdir -p "${dist}/present"
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ or an explicit module name (e.g. `ExtraEng.gf`. You don't need to specify to lan
|
|||||||
(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`.
|
||||||
@@ -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:
|
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`
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user