From e73d42379c97be2726fc13102e1397b8ab0b0292 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Thu, 9 Aug 2018 09:09:17 +0200 Subject: [PATCH 1/4] Make.hs: specifying `--langs` doesn't ignore module restrictions As a result the `--langs=+...` function is no longer meaningful --- Make.hs | 46 ++++++++++++++++++++++++++++------------------ README.md | 2 +- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Make.hs b/Make.hs index 1118fb39..bae1bade 100644 --- a/Make.hs +++ b/Make.hs @@ -184,8 +184,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 +284,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 +385,29 @@ 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" 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 ++ "] " ++ summary + run_gfc bi ([if infoVerbose bi then "--verbose" else "--quiet", "--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 + args' = ["--batch"] ++ filter (not . null) args gf = infoGFPath bi execute gf args' diff --git a/README.md b/README.md index 960a0847..3c6f862f 100644 --- a/README.md +++ b/README.md @@ -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`. From 60f19691eb985bb80ccaba7886b23b51b7e94951 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Thu, 9 Aug 2018 09:52:41 +0200 Subject: [PATCH 2/4] --verbose flag shows file names, not passed on to GF --- Make.hs | 24 +++++++++++++----------- Make.sh | 5 ----- README.md | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Make.hs b/Make.hs index bae1bade..98e5a540 100644 --- a/Make.hs +++ b/Make.hs @@ -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 @@ -393,13 +394,14 @@ 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 if length files > 0 then do - putStrLn $ "Building [" ++ show mode ++ "] " ++ summary - run_gfc bi ([if infoVerbose bi then "--verbose" else "--quiet", "--no-pmcfg", preproc, "--gfo-dir="++dir] ++ files) + 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)" @@ -407,7 +409,7 @@ gfcn bi mode summary files = do run_gfc :: Info -> [String] -> IO () run_gfc bi args = do let - args' = ["--batch"] ++ filter (not . null) args + args' = ["--batch", "--quiet"] ++ filter (not . null) args gf = infoGFPath bi execute gf args' diff --git a/Make.sh b/Make.sh index 4aa66b7e..ce194b44 100755 --- a/Make.sh +++ b/Make.sh @@ -54,11 +54,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" diff --git a/README.md b/README.md index 3c6f862f..acca5ba7 100644 --- a/README.md +++ b/README.md @@ -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` From 73948e54a63eac456430eae66fc05880466d7203 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Thu, 9 Aug 2018 10:05:10 +0200 Subject: [PATCH 3/4] Make.sh: halt on error, skip non-existant files Was trying to compile src/*/SymbolHeb.gf which doesn't exist --- Make.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Make.sh b/Make.sh index ce194b44..30a8bfc8 100755 --- a/Make.sh +++ b/Make.sh @@ -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 } }') @@ -73,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 From f0566a48dddcbb20b5ca8fecfa8891daf14fd9fc Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Thu, 9 Aug 2018 10:19:48 +0200 Subject: [PATCH 4/4] Re-specify `--gf-lib-path` in Make.hs, seems to be needed sometimes --- Make.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Make.hs b/Make.hs index 98e5a540..e97b7f9d 100644 --- a/Make.hs +++ b/Make.hs @@ -409,7 +409,8 @@ gfcn bi mode summary files = do run_gfc :: Info -> [String] -> IO () run_gfc bi args = do let - args' = ["--batch", "--quiet"] ++ filter (not . null) args + dir = infoBuildDir bi + args' = ["--batch", "--quiet", "--gf-lib-path="++dir] ++ filter (not . null) args gf = infoGFPath bi execute gf args'